public MainForm() { currentUndo = null; selectedTile = null; undoBuffer = new Stack<UndoState>(); redoBuffer = new Stack<UndoState>(); selectedTool = ToolType.SELECTOR; InitializeComponent(); UpdateUndoRedoItems(); attributePaletteForm = new AttributePalette(); attributePaletteForm.Owner = this; createRoomDialog = new CreateRoomDialog(); createRoomDialog.Owner = this; GDIUtils.SetDoubleBuffered(this); this.tileSetPanel1.TileSelected += new TileSetPanel.TileSelectedHandler(HandleTileSelection); var toolButtons = this.toolStrip.Items; foreach (ToolStripItem item in toolButtons) { item.Click += new EventHandler(HandleToolStripItemClick); } SetShowAttributes(false); }
private void StartUndo() { redoBuffer.Clear(); currentUndo = new UndoState(); }
private void ApplyUndo(UndoState state, bool redo) { MapPanel mapPanel = null; foreach (TileChange change in state.Changes) { int x = change.X; int y = change.Y; int changeValue = redo ? change.ToIndex : change.FromIndex; var room = change.Room; if (x < 0 || x >= room.Width || y < 0 || y >= room.Height) { continue; } var linearTileOffset = (y * room.Width) + x; var tiles = room.TileIndicies; var attrs = room.TileAttrbutes; if (change.Nature == TileChange.Type.Tile) { tiles[linearTileOffset] = changeValue; } else if (change.Nature == TileChange.Type.Attribute) { attrs[linearTileOffset] = (Tile.Attribute)changeValue; } foreach (Control control in this.gridPanel.Controls) { mapPanel = control as MapPanel; if (mapPanel != null) { // Find the panel that hold the room we edited... if (mapPanel.Room == room) { mapPanel.RedrawTileAtIndex(x, y); break; } } } } if (mapPanel != null) { mapPanel.Invalidate(); } }