//----------------------------------------------------------------------------- // Selection //----------------------------------------------------------------------------- public override void Cut() { LevelDisplayControl.PickupSelectionGrid(); if (LevelDisplayControl.SelectionGrid != null) { clipboard = LevelDisplayControl.SelectionGrid; LevelDisplayControl.SelectionGrid = null; LevelDisplayControl.DeselectSelectionGrid(); } }
// Take tiles from the level (or duplicate them) and put them into a tile grid. public TileGrid CreateTileGrid(Rectangle2I area, bool duplicate) { TileGrid tileGrid = new TileGrid(area.Size, roomLayerCount); BaseTileDataInstance[] tiles = GetTilesInArea(area).ToArray(); foreach (BaseTileDataInstance baseTileOriginal in tiles) { // Duplicate the tile if specified, else remove the original. BaseTileDataInstance baseTile; if (duplicate) { baseTile = baseTileOriginal.Duplicate(); } else { baseTile = baseTileOriginal; baseTileOriginal.Room.Remove(baseTileOriginal); } // Add the tile to the tile grid. if (baseTile is TileDataInstance) { TileDataInstance tile = (TileDataInstance)baseTile; tile.Location += tile.Room.Location * roomSize; tile.Location -= area.Point; tileGrid.PlaceTile(tile, tile.Location, tile.Layer); } else if (baseTile is EventTileDataInstance) { EventTileDataInstance eventTile = (EventTileDataInstance)baseTile; eventTile.Position += eventTile.Room.Location * roomSize * GameSettings.TILE_SIZE; eventTile.Position -= area.Point * GameSettings.TILE_SIZE; tileGrid.AddEventTile(eventTile); } } return(tileGrid); }
// Place the tiles in a tile grid starting at the given location. public void PlaceTileGrid(TileGrid tileGrid, LevelTileCoord location) { // Remove tiles. Rectangle2I area = new Rectangle2I((Point2I)location, tileGrid.Size); RemoveArea(area); // Place tiles. foreach (BaseTileDataInstance baseTile in tileGrid.GetTiles()) { if (baseTile is TileDataInstance) { TileDataInstance tile = (TileDataInstance)baseTile; LevelTileCoord coord = (LevelTileCoord)((Point2I)location + tile.Location); Room room = GetRoom(coord); if (room != null) { tile.Location = GetTileLocation(coord); room.PlaceTile(tile, tile.Location, tile.Layer); } } else if (baseTile is EventTileDataInstance) { EventTileDataInstance eventTile = (EventTileDataInstance)baseTile; eventTile.Position += (Point2I)location * GameSettings.TILE_SIZE; Point2I roomLocation = eventTile.Position / (roomSize * GameSettings.TILE_SIZE); Room room = GetRoomAt(roomLocation); if (room != null) { eventTile.Position -= roomLocation * roomSize * GameSettings.TILE_SIZE; room.AddEventTile(eventTile); } } } }
// Place the tiles in a tile grid starting at the given location. public void PlaceTileGrid(TileGrid tileGrid, LevelTileCoord location) { // Remove tiles. Rectangle2I area = new Rectangle2I((Point2I) location, tileGrid.Size); RemoveArea(area); // Place tiles. foreach (BaseTileDataInstance baseTile in tileGrid.GetTiles()) { if (baseTile is TileDataInstance) { TileDataInstance tile = (TileDataInstance) baseTile; LevelTileCoord coord = (LevelTileCoord) ((Point2I) location + tile.Location); Room room = GetRoom(coord); if (room != null) { tile.Location = GetTileLocation(coord); room.PlaceTile(tile, tile.Location, tile.Layer); } } else if (baseTile is EventTileDataInstance) { EventTileDataInstance eventTile = (EventTileDataInstance) baseTile; eventTile.Position += (Point2I) location * GameSettings.TILE_SIZE; Point2I roomLocation = eventTile.Position / (roomSize * GameSettings.TILE_SIZE); Room room = GetRoomAt(roomLocation); if (room != null) { eventTile.Position -= roomLocation * roomSize * GameSettings.TILE_SIZE; room.AddEventTile(eventTile); } } } }
// Take tiles from the level (or duplicate them) and put them into a tile grid. public TileGrid CreateTileGrid(Rectangle2I area, bool duplicate) { TileGrid tileGrid = new TileGrid(area.Size, roomLayerCount); BaseTileDataInstance[] tiles = GetTilesInArea(area).ToArray(); foreach (BaseTileDataInstance baseTileOriginal in tiles) { // Duplicate the tile if specified, else remove the original. BaseTileDataInstance baseTile; if (duplicate) { baseTile = baseTileOriginal.Duplicate(); } else { baseTile = baseTileOriginal; baseTileOriginal.Room.Remove(baseTileOriginal); } // Add the tile to the tile grid. if (baseTile is TileDataInstance) { TileDataInstance tile = (TileDataInstance) baseTile; tile.Location += tile.Room.Location * roomSize; tile.Location -= area.Point; tileGrid.PlaceTile(tile, tile.Location, tile.Layer); } else if (baseTile is EventTileDataInstance) { EventTileDataInstance eventTile = (EventTileDataInstance) baseTile; eventTile.Position += eventTile.Room.Location * roomSize * GameSettings.TILE_SIZE; eventTile.Position -= area.Point * GameSettings.TILE_SIZE; tileGrid.AddEventTile(eventTile); } } return tileGrid; }
//----------------------------------------------------------------------------- // Constructors //----------------------------------------------------------------------------- protected override void Initialize() { content = new ContentManager(Services, "Content"); spriteBatch = new Microsoft.Xna.Framework.Graphics.SpriteBatch(GraphicsDevice); selectedRoom = null; selectedTiles = new HashSet<BaseTileDataInstance>(); selectionGrid = null; editorControl.Initialize(content, GraphicsDevice); //this.ContextMenuStrip = editorControl.EditorForm.ContextMenuStripTileInLevel; /*levelRenderTarget = new Microsoft.Xna.Framework.Graphics.RenderTarget2D( GraphicsDevice, 2048, 2048, false, Microsoft.Xna.Framework.Graphics.SurfaceFormat.Color, Microsoft.Xna.Framework.Graphics.DepthFormat.None, 0, Microsoft.Xna.Framework.Graphics.RenderTargetUsage.PreserveContents);*/ // Wire the events. MouseMove += OnMouseMove; MouseDown += OnMouseDown; MouseUp += OnMouseUp; MouseLeave += OnMouseLeave; MouseDoubleClick += OnMouseDoubleClick; this.ResizeRedraw = true; // Start the timer to refresh the panel. Application.Idle += delegate { Invalidate(); }; // TEMP: Open this world file upon starting the editor. if (File.Exists("./temp_world.zwd")) editorControl.OpenFile("temp_world.zwd"); else if (File.Exists("../../../../WorldFiles/temp_world.zwd")) editorControl.OpenFile("../../../../WorldFiles/temp_world.zwd"); //editorControl.OpenFile("temp_world.zwd"); UpdateLevel(); this.highlightedRoom = -Point2I.One; this.highlightedTile = -Point2I.One; }
public void SetSelectionGrid(TileGrid tileGrid, Point2I location, Level level) { PlaceSelectionGrid(); selectionGridArea = new Rectangle2I(location, tileGrid.Size); selectionGridLevel = level; selectionGrid = tileGrid; SetSelectionBox(selectionGridArea.Point * GameSettings.TILE_SIZE, selectionGridArea.Size * GameSettings.TILE_SIZE); }
public void PlaceSelectionGrid() { if (selectionGrid != null) { selectionGridLevel.PlaceTileGrid( selectionGrid, (LevelTileCoord) selectionGridArea.Point); selectionGrid = null; Console.WriteLine("Placed selection grid"); } }
public void PickupSelectionGrid() { if (selectionGrid == null && !selectionGridArea.IsEmpty) { selectionGrid = Level.CreateTileGrid(selectionGridArea); Console.WriteLine("Picked up selection grid"); } }
public void DuplicateSelectionGrid() { PickupSelectionGrid(); if (selectionGrid != null) { TileGrid oldGrid = selectionGrid; selectionGrid = selectionGrid.Duplicate(); selectionGridLevel.PlaceTileGrid( oldGrid, (LevelTileCoord) selectionGridArea.Point); Console.WriteLine("Duplicated Selection grid"); } }
public void DeleteSelectionGrid() { PickupSelectionGrid(); if (selectionGrid != null) { selectionGrid = null; } }
public override void Copy() { LevelDisplayControl.PickupSelectionGrid(); if (LevelDisplayControl.SelectionGrid != null) clipboard = LevelDisplayControl.SelectionGrid.Duplicate(); }
//----------------------------------------------------------------------------- // Constructor //----------------------------------------------------------------------------- public ToolSelection() { name = "Selection Tool"; clipboard = null; }
// Return a copy of this tile grid. public TileGrid Duplicate() { TileGrid duplicate = new TileGrid(size, layerCount); // Duplicate tiles. for (int x = 0; x < size.X; x++) { for (int y = 0; y < size.Y; y++) { for (int i = 0; i < layerCount; i++) { TileGridTile tile = tiles[x, y, i]; if (tile.Tile != null && tile.Location == new Point2I(x, y)) { TileDataInstance tileCopy = new TileDataInstance(); tileCopy.Clone(tile.Tile); duplicate.PlaceTile(tileCopy, x, y, i); } } } } // Duplicate event tiles. foreach (EventTileDataInstance eventTile in eventTiles) { EventTileDataInstance copy = new EventTileDataInstance(); copy.Clone(eventTile); duplicate.AddEventTile(copy); } return duplicate; }