//--------------------------------------------------------------------------------------------------------------------------------------------------- // // Copyright (C)2007 DarkWynter Studios. All rights reserved. // //--------------------------------------------------------------------------------------------------------------------------------------------------- // {Contact : darkwynter.com for licensing information //--------------------------------------------------------------------------------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; using Microsoft.Xna; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using DarkWynter.Engine.Globals; using DarkWynter.Engine.Utilities; using DarkWynter.Engine.GameObjects; using DarkWynter.Engine.Controllers; using Color = System.Drawing.Color; using Point = System.Drawing.Point; namespace DarkWynter.App { public partial class TerrainModControl : UserControl { // New Bitmap Bitmap bmp; Color currentColor = Color.Red; int brushSize = 50; Texture2D saveTexture; Vector4[] saveData; bool draw = false; static Enums_Engine.TerrainModType terrainModType = Enums_Engine.TerrainModType.EQUALTO; public TerrainModControl() { InitializeComponent(); this.Dock = DockStyle.Fill; // New Bitmap // bmp = new Bitmap("c:/images/image.gif"); bmp = new Bitmap(128,128); pictureBoxMapView.Image = bmp; //saveTexture = new Texture2D(GraphicsDevice, bmp.Width, bmp.Height, 0, TextureUsage.AutoGenerateMipMap, SurfaceFormat.Vector4); saveData = new Vector4[bmp.Width * bmp.Height]; //getTMLoc.Hide(); // Init TerrainMod values amountBox.Text = "5"; radiusBox.Text = "2"; positionBox1.Text = "21"; positionBox2.Text = "0"; positionBox3.Text = "45"; } private static void TerrainModInterface(float amount, int radius, int timer, ref Vector3 position, ref Vector3 position2) { TerrainModRequest request = new TerrainModRequest(timer, amount, position, position2, radius, terrainModType); DarkWynter.Engine.Controllers.GameController.NonControllerBasedTerrainMod(request); } private void Enter_Click(object sender, EventArgs e) { // Validate Input if (positionBox1.Text == "") { positionBox1.Text = "0"; } if (positionBox2.Text == "") { positionBox2.Text = "0"; } if (positionBox3.Text == "") { positionBox3.Text = "0"; } if (end1.Text == "") { end1.Text = "0"; } if (end2.Text == "") { end2.Text = "0"; } if (end3.Text == "") { end3.Text = "0"; } // Terrain Mod Panel float amount = float.Parse(amountBox.Text); int radius = int.Parse(radiusBox.Text); int timer = 100; Vector3 position = new Vector3(float.Parse(positionBox1.Text), float.Parse(positionBox2.Text), float.Parse(positionBox3.Text)); Vector3 position2 = new Vector3(float.Parse(end1.Text), float.Parse(end2.Text), float.Parse(end3.Text)); TerrainModInterface(amount, radius, timer, ref position, ref position2); } #region Level Edit private void pictureBoxMapView_MouseDown(object sender, MouseEventArgs me) { draw = true; } private void pictureBoxMapView_MouseUp(object sender, MouseEventArgs me) { draw = false; } private void pictureBoxMapView_MouseMove(object sender, MouseEventArgs me) { //MouseEventArgs me = e as MouseEventArgs;//or MouseEventArgs em = (MouseEventArgs)e; brushSize = (int) numericUpDownBrushSize.Value; if (draw) { // Paint the 2D bitmap using brushsize for (int i = -brushSize; i < brushSize; i++) { for (int j = -brushSize; j < brushSize; j++) { // Find x & y relative to center of brush int x = me.X + i; int y = me.Y + j; // If within the bmp bounds if (0 < x && x < bmp.Width && 0 < y && y < bmp.Height) { // Call " Brush-Tip" Function here bmp.SetPixel(x, y, currentColor); } } } // Redraw pictureBoxMapView.Refresh(); // TerrainMod the 3D space using brushsize float amount = float.Parse(numericUpDownTerrainHeight.Text); int radius = int.Parse(numericUpDownBrushSize.Text); int timer = 100; Vector3 position = new Vector3(me.X, 0.0f, me.Y); Vector3 position2 = new Vector3(me.X, 0.0f, me.Y) + Vector3.One; TerrainModInterface(amount, radius, timer, ref position, ref position2); } } private void colorSelectionButton_Click(object sender, EventArgs e) { // Color Dialog Selection ColorDialog colorDlg = new ColorDialog(); colorDlg.ShowDialog(); currentColor = colorDlg.Color; this.colorSelectionButton.BackColor = currentColor; } private void numericUpDownGreyScaleValue_ValueChanged(object sender, EventArgs e) { // Grey Scale selection //int color = (int)this.numericUpDownGreyScaleValue.Value; //currentColor = Color.FromArgb(255, color, color, color); //this.colorSelectionButton.BackColor = currentColor; } #endregion public void SaveHeightMap() { for (int x = 0; x < saveTexture.Width; x++) { for (int y = 0; y < saveTexture.Height; y++) { Color pixelColor = bmp.GetPixel(x, y); saveData[x + y * saveTexture.Width] = new Vector4(pixelColor.R, pixelColor.G, pixelColor.B, pixelColor.A); } } saveTexture.SetData(saveData); saveTexture.Save("heightMap.dds", ImageFileFormat.Dds); } private void TerrainModControl_Load(object sender, EventArgs e) { } private void checkBoxAdditive_CheckedChanged(object sender, EventArgs e) { if (checkBoxAdditive.Checked) { terrainModType = Enums_Engine.TerrainModType.ADDITIVE; } else { terrainModType = Enums_Engine.TerrainModType.EQUALTO; } } } }