public static UndoRedoInfo TilePlacement_Redo(List <Tile>[] layerTiles, int mapWidth) { UndoRedoInfo undoRedoInfo = new LevelEditor.UndoRedoInfo(); undoRedoInfo.success = false; // If there is nothing to redo, return if (_Redo_TilePlacement.Count <= 0) { return(undoRedoInfo); } Tile tile = _Redo_TilePlacement.Pop(); // Push the current tile onto the Undo stack in the case where the user wants to revert forwards again Tile originalTile = new Tile(); originalTile.SetPosition(tile.position.x, tile.position.y); originalTile.canvasIdx = tile.canvasIdx; originalTile.tileMapIdx = layerTiles[originalTile.canvasIdx][originalTile.position.x + originalTile.position.y * mapWidth].tileMapIdx; originalTile.spriteSheetIdx = layerTiles[originalTile.canvasIdx][originalTile.position.x + originalTile.position.y * mapWidth].spriteSheetIdx; _Undo_TilePlacement.Push(originalTile); undoRedoInfo.success = true; undoRedoInfo.tile = tile; return(undoRedoInfo); }
// Add the tile to the Undo stack so when undo // is pressed the tile will revert back to its previous state public static void TilePlacement_Add(Tile tile) { Tile newTile = new Tile(); newTile.canvasIdx = tile.canvasIdx; newTile.SetPosition(tile.position.x, tile.position.y); newTile.tileMapIdx = tile.tileMapIdx; newTile.spriteSheetIdx = tile.spriteSheetIdx; _Undo_TilePlacement.Push(newTile); }
public void Initialise(string tileSheetPath) { // Initialise the game properties if (_level.generalGameProperties == null) { _level.generalGameProperties = new GeneralGameProperties(); } // Initialise each sprite sheet _level.tileSheetPath = tileSheetPath; for (int i = 0; i < _spriteSheets.Length; i++) { _spriteSheets[i] = new List <CroppedBitmap>(); } InitialiseSpriteSheet(_level.tileSheetPath, 0); InitialiseSpriteSheet(".../.../images/sheetEnemies.png", 1); InitialiseSpriteSheet(".../.../images/sheetOther.png", 2); // Set the layer width and height for every layer int width = _level.mapWidth * _tileRenderXY; int height = _level.mapHeight * _tileRenderXY; _Layer0.Width = width; _Layer0.Height = height; _Layer1.Width = width; _Layer1.Height = height; _Layer2.Width = width; _Layer2.Height = height; _Layer3.Width = width; _Layer3.Height = height; _LayerGrid.Width = width; _LayerGrid.Height = height; // Clear all of the tiles from every layer _Layer0.Children.Clear(); _Layer1.Children.Clear(); _Layer2.Children.Clear(); _Layer3.Children.Clear(); _LayerGrid.Children.Clear(); _LayerDraw.Children.Clear(); // Clear the layer tile information stored for (int i = 0; i < _layerTiles.Length; i++) { _layerTiles[i] = new List <Tile>(); } // Fill each layer with empty tiles.. int x = 0, y = 0; for (int i = 0; i < _level.mapWidth * _level.mapHeight; i++, x++) { if (x == _level.mapWidth) { x = 0; y++; } Thickness marginThickness = new Thickness(x * _tileRenderXY, y * _tileRenderXY, 0, 0); _Layer0.Children.Add(CreateTileRect(new SolidColorBrush(Colors.White), marginThickness)); _Layer1.Children.Add(CreateTileRect(new SolidColorBrush(Colors.Transparent), marginThickness)); _Layer2.Children.Add(CreateTileRect(new SolidColorBrush(Colors.Transparent), marginThickness)); _Layer3.Children.Add(CreateTileRect(new SolidColorBrush(Colors.Transparent), marginThickness)); _LayerDraw.Children.Add(CreateTileRect(new SolidColorBrush(Colors.Transparent), marginThickness)); // Add the tile information to each layerTile layer for (int layer = 0; layer < _layerTiles.Length; layer++) { Tile newTile = new Tile(); newTile.tileMapIdx = -1; newTile.SetPosition(x, y); newTile.canvasIdx = layer; newTile.spriteSheetIdx = -1; _layerTiles[layer].Add(newTile); } } InitialiseGrid(); // Reset the undo and redo stacks UndoRedo.Reset(); }