private void BtnMapResize_Click(object sender, EventArgs e) { MapSizeInputWindow dialog = new MapSizeInputWindow(Map.Width, Map.Height); dialog.Location = MousePosition; if (dialog.ShowDialog(this) != DialogResult.OK) { return; } if (dialog.NewWidth < Map.Width || dialog.NewHeight < Map.Height) { string oldSizeStr = "(" + Map.Width + "," + Map.Height + ")"; string newSizeStr = "(" + dialog.NewWidth + "," + dialog.NewHeight + ")"; if (!Confirm("The new size " + newSizeStr + " is smaller than the current size " + oldSizeStr + ". This will delete objects that are out of bounds. Are you sure?")) { return; } } Map.Resize(dialog.NewWidth, dialog.NewHeight); MapBox.AdjustSize(); MapBox.InvalidateAllMapPositionsAndRefresh(); }
private void CmbMapLayer_SelectedIndexChanged(object sender, EventArgs e) { MapBox.MapLayer = CmbMapLayer.SelectedIndex; if (MapBox.DrawOnlyCurrentLayer) { MapBox.InvalidateAllMapPositionsAndRefresh(); } }
private void BtnMapFill_Click(object sender, EventArgs e) { if (Confirm("Fill current map layer with selected object?")) { MapBox.CurrentMapLayer.FillObject(CurrentObject); MapBox.InvalidateAllMapPositionsAndRefresh(); } }
private void BtnMapClear_Click(object sender, EventArgs e) { if (Confirm("Clear the current map layer?")) { MapBox.CurrentMapLayer.Clear(); MapBox.InvalidateAllMapPositionsAndRefresh(); } }
private void Map_MouseWheel(object sender, MouseEventArgs e) { if (e.Delta > 0) { MapBox.ZoomIn(); } else if (e.Delta < 0) { MapBox.ZoomOut(); } }
private void MenuSaveScreenshot_Click(object sender, EventArgs e) { SaveFileDialog dialog = new SaveFileDialog(); dialog.InitialDirectory = DataDirectory; dialog.Filter = "PNG image files|*.png"; if (dialog.ShowDialog() != DialogResult.OK) { return; } MapBox.SaveScreenshot(dialog.FileName); Log("Map screenshot saved to file " + dialog.FileName); }
private void DeleteCurrentMapLayer() { int index = CmbMapLayer.SelectedIndex; if (index == 0) { ShowWarning("Layer 0 cannot be deleted"); return; } MapBox.Map.Layers.RemoveAt(index); UpdateMapLayerList(); MapBox.InvalidateAllMapPositionsAndRefresh(); }
private void MenuSetBackgroundImage_Click(object sender, EventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.InitialDirectory = DataDirectory; dialog.Filter = "Image files|*.png"; if (dialog.ShowDialog() != DialogResult.OK) { return; } MapBox.BackgroundImage = Image.FromFile(dialog.FileName); MapBox.InvalidateAllMapPositionsAndRefresh(); }
private void BtnMapBackColor_Click(object sender, EventArgs e) { ColorPicker picker = new ColorPicker(Palette, "Pick map background color"); picker.Location = MousePosition; if (picker.ShowDialog() != DialogResult.OK) { return; } Map.BackColor = picker.SelectedColor; MapBox.InvalidateAllMapPositionsAndRefresh(); UpdateTilePreview(); }
private void MenuSetMapViewport_Click(object sender, EventArgs e) { ViewportConfigWindow dialog = new ViewportConfigWindow(MapBox.ViewportWidth, MapBox.ViewportHeight); dialog.Location = MousePosition; if (dialog.ShowDialog(this) != DialogResult.OK) { return; } MapBox.ViewportWidth = dialog.NewWidth; MapBox.ViewportHeight = dialog.NewHeight; MapBox.Refresh(); }
public void EditSelectedTile() { TileEditor.MainWindow editor = new TileEditor.MainWindow(Tileset, TileIndex); editor.MapEditorWindow = this; editor.ShowDialog(this); TilesetBox.Refresh(); UpdateTilesetPageIndicator(); UpdateTilePreview(); Tileset.Save(TilesetFile); Log("Tileset saved to " + TilesetFile); MapBox.InvalidateAllMapPositionsAndRefresh(); }
private void BtnTilesetClear_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show( "This will load the default tileset. Are you sure?", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (result == DialogResult.OK) { Tileset.Load(DefaultTilesetFile); TileIndex = 0; TilesetBox.Refresh(); UpdateTilesetPageIndicator(); UpdateTilePreview(); MapBox.InvalidateAllMapPositionsAndRefresh(); Log("Tileset imported from file " + DefaultTilesetFile); } }
private void ImportTileset() { OpenFileDialog dialog = new OpenFileDialog(); dialog.InitialDirectory = DataDirectory; dialog.Filter = "Tileset files|*.dat"; if (dialog.ShowDialog() == DialogResult.OK) { Tileset.Load(dialog.FileName); TileIndex = 0; TilesetBox.Refresh(); UpdateTilesetPageIndicator(); UpdateTilePreview(); MapBox.InvalidateAllMapPositionsAndRefresh(); Log("Tileset imported from file " + dialog.FileName); } }
private void LoadMap(string filename) { try { Map.Load(filename); UpdateMapLayerList(false); MapBox.AdjustSize(); MapBox.InvalidateAllMapPositionsAndRefresh(); TxtMapName.Text = Map.Name; UpdateTilePreview(); Log("Map loaded from file " + filename); SetCurrentMapFile(filename); } catch (Exception ex) { ShowError("Error loading map from file " + filename + ":" + Environment.NewLine + Environment.NewLine + ex.Message); } }
public MainWindow() { InitializeComponent(); DataDirectory = Path.Combine(@"C:\Fernando\Proj\Windows\TileStudio\TileStudio\bin\Debug", "data"); TilesetFile = Path.Combine(DataDirectory, "tileset.dat"); DefaultTilesetFile = Path.Combine(DataDirectory, "default_tileset.dat"); PaletteFile = Path.Combine(DataDirectory, "palette.dat"); ClearLog(); ClearStatusBar(); Palette = new Palette(); Palette.Load(PaletteFile); Log("Palette loaded from " + PaletteFile); Tileset = new Tileset(); Tileset.Load(TilesetFile); Log("Tileset loaded from " + TilesetFile); TilesetBox.EditorWindow = this; TilesetBox.Tileset = Tileset; UpdateTilesetPageIndicator(); Map = new Map(); MapBox.SetMap(Map); MapBox.EditorWindow = this; MapBox.Tileset = Tileset; MapBox.Palette = Palette; MouseWheel += Map_MouseWheel; MapBox.MouseWheel += Map_MouseWheel; UpdateMapLayerList(); TileGraphics = new TileGraphics(); TxtMapName.Text = Map.Name; SetCurrentMapFile(null); TxtCommand.Text = ""; }
private void ExecCommand(string[] command) { MapLayer map = MapBox.CurrentMapLayer; command[0] = command[0].Trim().ToLower(); if (command[0] == "set") { int x = int.Parse(command[1]); int y = int.Parse(command[2]); map.SetObject(x, y, CurrentObject); } else if (command[0] == "fill") { map.FillObject(CurrentObject); } else if (command[0] == "clear") { map.Clear(); } else if (command[0] == "rect") { int x = int.Parse(command[1]); int y = int.Parse(command[2]); int w = int.Parse(command[3]); int h = int.Parse(command[4]); for (int py = y; py < y + h; py++) { for (int px = x; px < x + w; px++) { map.SetObject(px, py, CurrentObject); } } } else if (command[0] == "hline") { int x = int.Parse(command[1]); int y = int.Parse(command[2]); int w = int.Parse(command[3]); for (int px = x; px < x + w; px++) { map.SetObject(px, y, CurrentObject); } } else if (command[0] == "vline") { int x = int.Parse(command[1]); int y = int.Parse(command[2]); int h = int.Parse(command[3]); for (int py = y; py < y + h; py++) { map.SetObject(x, py, CurrentObject); } } else if (command[0] == "box") { int x = int.Parse(command[1]); int y = int.Parse(command[2]); int w = int.Parse(command[3]); int h = int.Parse(command[4]); for (int px = x; px < x + w + 1; px++) { map.SetObject(px, y, CurrentObject); map.SetObject(px, y + h, CurrentObject); } for (int py = y; py < y + h; py++) { map.SetObject(x, py, CurrentObject); map.SetObject(x + w, py, CurrentObject); } } else if (command[0].StartsWith("print")) { int x = int.Parse(command[1]); int y = int.Parse(command[2]); int px = x; int py = y; string text = command[3]; if (command.Length > 4) { for (int i = 4; i < command.Length; i++) { text += " " + command[i]; } } foreach (char ch in text) { GameObject o = new GameObject(CurrentObject); o.Bytes.Clear(); o.Graphics.Index = ch; if (ch == '\\') { px = x; py++; } else { map.SetObject(px++, py, o); } } } else if (command[0] == "select") { MapBox.SelectArea( int.Parse(command[1]), int.Parse(command[2]), int.Parse(command[3]), int.Parse(command[4])); MapBox.InvalidateAllMapPositionsAndRefresh(); Log("Area selected: " + MapBox.GetSelectedArea()); } else if (command[0] == "deselect") { MapBox.DeselectArea(); MapBox.InvalidateAllMapPositionsAndRefresh(); Log("Area deselected"); } else if (command[0] == "erase") { MapBox.EraseSelectedArea(); MapBox.InvalidateAllMapPositionsAndRefresh(); Log("Selected area erased"); } else if (command[0] == "copy") { int x = int.Parse(command[1]); int y = int.Parse(command[2]); MapBox.CopySelectedAreaTo(x, y, false); MapBox.InvalidateAllMapPositionsAndRefresh(); Log("Selected area copied to X:" + x + ",Y:" + y); } else if (command[0] == "cut") { int x = int.Parse(command[1]); int y = int.Parse(command[2]); MapBox.CopySelectedAreaTo(x, y, true); MapBox.InvalidateAllMapPositionsAndRefresh(); Log("Selected area cut and pasted to X:" + x + ",Y:" + y); } else if (command[0] == "savesel") { SaveFileDialog dialog = new SaveFileDialog(); dialog.InitialDirectory = DataDirectory; dialog.Filter = "PNG image files|*.png"; if (dialog.ShowDialog() != DialogResult.OK) { return; } MapBox.SaveSelectedAreaAsImage(dialog.FileName); Log("Selected area saved to file:" + dialog.FileName); } MapBox.InvalidateAllMapPositionsAndRefresh(); }
private void MenuShowMapBoundary_Click(object sender, EventArgs e) { MapBox.ShowBoundary = MenuShowMapBoundary.Checked; MapBox.InvalidateAllMapPositionsAndRefresh(); }
private void MenuRemoveBackgroundImage_Click(object sender, EventArgs e) { MapBox.BackgroundImage = null; MapBox.InvalidateAllMapPositionsAndRefresh(); }
private void BtnMapShowCurLayerOnly_Click(object sender, EventArgs e) { MapBox.DrawOnlyCurrentLayer = BtnMapShowCurLayerOnly.Checked; MapBox.InvalidateAllMapPositionsAndRefresh(); }
private void MenuShowMapViewport_Click(object sender, EventArgs e) { MapBox.ShowViewport = MenuShowMapViewport.Checked; MapBox.Refresh(); }
private void MenuShowMapGrid_Click(object sender, EventArgs e) { MapBox.ShowGrid = MenuShowMapGrid.Checked; MapBox.Refresh(); }
private void BtnMapZoomOut_Click(object sender, EventArgs e) { MapBox.ZoomOut(); }
public void UpdateTileViews() { TilesetBox.Refresh(); MapBox.InvalidateAllMapPositionsAndRefresh(); UpdateTilePreview(); }