public SelectionChangedEventArgs(PointSelection selection) { _selection = selection; }
/// <summary> /// Runs a flood-fill algorithm with the passed co-ordinates of the root. /// Returns an enumerable list of points based on the results. /// </summary> /// <param name="tileset">Tileset to replace with.</param> /// <param name="selection">Tile selection to replace with.</param> /// <param name="x">X co-ordinate of the root tile.</param> /// <param name="y">Y co-ordinate of the root tile.</param> /// <returns>An enumerable list of points.</returns> public List<Point> FillCache(Tileset tileset, PointSelection selection, int x, int y) { if (x < 0 || x > Width - 1 || y < 0 || y > Height - 1) return null; _tileCache = new List<Point>(); _cacheMap = new FillTile[Width, Height]; for (var x2 = 0; x2 < Width; x2++) { for (var y2 = 0; y2 < Height; y2++) { var tile = SelectedLayer.Tiles[x2, y2]; _cacheMap[x2, y2] = new FillTile(tile.Tileset, tile.SrcX, tile.SrcY, tile.Terrain); } } _tileChecked = new bool[Width, Height]; var point = selection.GetTopLeftMostPoint(); var replacementTile = new FillTile(tileset.ID, point.X, point.Y, 0); var currTile = GetFillCacheTile(x, y, replacementTile); var originalFillTile = new FillTile(currTile.Tileset, currTile.X, currTile.Y, currTile.Terrain); FillCacheTiles(originalFillTile, replacementTile, x, y); return _tileCache; }
/// <summary> /// Sets the selection of tiles to the map. /// </summary> /// <param name="tileset">Tileset of the tiles.</param> /// <param name="layer">Layer to set the tiles to.</param> /// <param name="selection">Selection of tiles to place.</param> /// <param name="x">X co-ordinate to place to.</param> /// <param name="y">Y co-orindate to place to.</param> public void SetTiles(Tileset tileset, EditorTileLayer layer, PointSelection selection, int x, int y) { foreach (var point in selection.Points) { var x2 = (x - selection.Offset.X) + point.X; var y2 = (y - selection.Offset.Y) + point.Y; if (x2 < 0 || y2 < 0 || x2 > Width - 1 || y2 > Height - 1) continue; SetTile(tileset, layer, x2, y2, point.X, point.Y); } }
public void Fill(Tileset tileset, PointSelection selection, int x, int y) { if (x < 0 || x > Width - 1 || y < 0 || y > Height - 1) return; using (UndoRedoArea.Start("Fill Tool")) { _tileChecked = new bool[Width, Height]; _tileMap = SelectedLayer.Tiles; _tilesToCache = new List<Point>(); var tile = selection.GetTopLeftMostPoint(); var replacementTile = new FillTile(tileset.ID, tile.X, tile.Y, 0); var currTile = GetFillTile(x, y, replacementTile); var originalFillTile = new FillTile(currTile.Tileset, currTile.SrcX, currTile.SrcY, currTile.Terrain); FillTiles(currTile, originalFillTile, replacementTile); UndoRedoArea.Commit(); } }
/// <summary> /// Handles the SelectionChanged event of the <see cref="TilesetManager"/> class. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="SelectionChangedEventArgs"/> instance containing the event data.</param> private void SelectionChanged(object sender, SelectionChangedEventArgs e) { _selection = e.Selection; BuildTilesetSprites(); }