//-----------------------------------------------------------------------------
 // Selection
 //-----------------------------------------------------------------------------
 public override void Cut()
 {
     LevelDisplayControl.PickupSelectionGrid();
     if (LevelDisplayControl.SelectionGrid != null) {
         clipboard = LevelDisplayControl.SelectionGrid;
         LevelDisplayControl.SelectionGrid = null;
         LevelDisplayControl.DeselectSelectionGrid();
     }
 }
示例#2
0
        // 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);
        }
示例#3
0
        // 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);
                    }
                }
            }
        }
示例#4
0
        // 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);
                    }
                }
            }
        }
示例#5
0
        // 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;
        }
示例#6
0
        //-----------------------------------------------------------------------------
        // 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;
        }
示例#7
0
 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);
 }
示例#8
0
 public void PlaceSelectionGrid()
 {
     if (selectionGrid != null) {
         selectionGridLevel.PlaceTileGrid(
             selectionGrid, (LevelTileCoord) selectionGridArea.Point);
         selectionGrid = null;
         Console.WriteLine("Placed selection grid");
     }
 }
示例#9
0
 public void PickupSelectionGrid()
 {
     if (selectionGrid == null && !selectionGridArea.IsEmpty) {
         selectionGrid = Level.CreateTileGrid(selectionGridArea);
         Console.WriteLine("Picked up selection grid");
     }
 }
示例#10
0
 public void DuplicateSelectionGrid()
 {
     PickupSelectionGrid();
     if (selectionGrid != null) {
         TileGrid oldGrid = selectionGrid;
         selectionGrid = selectionGrid.Duplicate();
         selectionGridLevel.PlaceTileGrid(
             oldGrid, (LevelTileCoord) selectionGridArea.Point);
         Console.WriteLine("Duplicated Selection grid");
     }
 }
示例#11
0
 public void DeleteSelectionGrid()
 {
     PickupSelectionGrid();
     if (selectionGrid != null) {
         selectionGrid = null;
     }
 }
示例#12
0
 public override void Copy()
 {
     LevelDisplayControl.PickupSelectionGrid();
     if (LevelDisplayControl.SelectionGrid != null)
         clipboard = LevelDisplayControl.SelectionGrid.Duplicate();
 }
示例#13
0
 //-----------------------------------------------------------------------------
 // Constructor
 //-----------------------------------------------------------------------------
 public ToolSelection()
 {
     name = "Selection Tool";
     clipboard = null;
 }
示例#14
0
        // 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;
        }