Beispiel #1
0
 public override void Copy()
 {
     LevelDisplayControl.PickupSelectionGrid();
     if (LevelDisplayControl.SelectionGrid != null)
     {
         clipboard = LevelDisplayControl.SelectionGrid.Duplicate();
     }
 }
Beispiel #2
0
 public override void Deselect()
 {
     selectedEventTile = null;
     selectedTile      = null;
     LevelDisplayControl.DeselectTiles();
     LevelDisplayControl.DeselectSelectionGrid();
     EditorControl.PropertyGrid.CloseProperties();
 }
Beispiel #3
0
 public override void Paste()
 {
     if (clipboard != null)
     {
         LevelDisplayControl.DeselectSelectionGrid();
         LevelDisplayControl.SetSelectionGrid(
             clipboard.Duplicate(), Point2I.Zero, EditorControl.Level);
     }
 }
Beispiel #4
0
        public override void OnMouseDragMove(MouseEventArgs e)
        {
            Point2I mousePos     = new Point2I(e.X, e.Y);
            Point2I pointInLevel = LevelDisplayControl.SampleLevelPixelPosition(mousePos);

            // Update selection box.
            if (e.Button == MouseButtons.Left && isCreatingSelectionBox)
            {
                Point2I     tileCoord = LevelDisplayControl.SampleLevelTileCoordinates(mousePos);
                Level       level     = EditorControl.Level;
                Rectangle2I selectionBox;

                if (System.Windows.Forms.Control.ModifierKeys.HasFlag(KEYMOD_ROOM_MODE))
                {
                    Point2I roomCoord1   = level.GetRoomLocation((LevelTileCoord)dragBeginTileCoord);
                    Point2I roomCoord2   = level.GetRoomLocation((LevelTileCoord)tileCoord);
                    Point2I roomCoordMin = GMath.Min(roomCoord1, roomCoord2);
                    Point2I roomCoordMax = GMath.Max(roomCoord1, roomCoord2);

                    Rectangle2I levelDimensions = new Rectangle2I(Point2I.Zero, level.Dimensions);
                    selectionBox        = new Rectangle2I(roomCoordMin, roomCoordMax - roomCoordMin + Point2I.One);
                    selectionBox        = Rectangle2I.Intersect(selectionBox, levelDimensions);
                    selectionBox.Point *= level.RoomSize;
                    selectionBox.Size  *= level.RoomSize;
                }
                else
                {
                    Point2I minCoord = GMath.Min(dragBeginTileCoord, tileCoord);
                    Point2I maxCoord = GMath.Max(dragBeginTileCoord, tileCoord);

                    Rectangle2I levelBounds = new Rectangle2I(Point2I.Zero, level.RoomSize * level.Dimensions);
                    selectionBox = new Rectangle2I(minCoord, maxCoord - minCoord + Point2I.One);
                    //selectionBox = Rectangle2I.Intersect(selectionBox, levelBounds);
                }

                LevelDisplayControl.SetSelectionGridArea(selectionBox, level);
            }
            else if (e.Button == MouseButtons.Left && isMovingSelectionBox)
            {
                Point2I moveAmount;

                if (System.Windows.Forms.Control.ModifierKeys.HasFlag(KEYMOD_ROOM_MODE))
                {
                    moveAmount  = pointInLevel - dragBeginPoint;
                    moveAmount  = (Point2I)GMath.Round((Vector2F)moveAmount / (editorControl.Level.RoomSize * GameSettings.TILE_SIZE));
                    moveAmount *= editorControl.Level.RoomSize;
                }
                else
                {
                    moveAmount = pointInLevel - dragBeginPoint;
                    moveAmount = (Point2I)GMath.Round((Vector2F)moveAmount / GameSettings.TILE_SIZE);
                }

                Point2I selectionBoxPoint = selectionBoxBeginPoint + moveAmount;
                LevelDisplayControl.MoveSelectionGridArea(selectionBoxPoint);
            }
        }
Beispiel #5
0
        public override void SelectAll()
        {
            isCreatingSelectionBox = false;
            isMovingSelectionBox   = false;

            Level       level = EditorControl.Level;
            Rectangle2I area  = new Rectangle2I(Point2I.Zero, level.Dimensions * level.RoomSize);

            LevelDisplayControl.SetSelectionGridArea(area, level);
        }
Beispiel #6
0
        //-----------------------------------------------------------------------------
        // Selection
        //-----------------------------------------------------------------------------

        public override void Cut()
        {
            LevelDisplayControl.PickupSelectionGrid();
            if (LevelDisplayControl.SelectionGrid != null)
            {
                clipboard = LevelDisplayControl.SelectionGrid;
                LevelDisplayControl.SelectionGrid = null;
                LevelDisplayControl.DeselectSelectionGrid();
            }
        }
Beispiel #7
0
        public override void OnMouseDragMove(MouseEventArgs e)
        {
            Point2I mousePos  = new Point2I(e.X, e.Y);
            Room    room      = LevelDisplayControl.SampleRoom(mousePos);
            Point2I tileCoord = LevelDisplayControl.SampleTileCoordinates(mousePos);

            if (room != null)
            {
                ActivateTile(e.Button, room, tileCoord);
            }
        }
Beispiel #8
0
 public override void OnMouseDragBegin(MouseEventArgs e)
 {
     // Draw a new selecion box.
     if (e.Button == MouseButtons.Left)
     {
         isCreatingSelectionBox = true;
         Point2I mousePos = new Point2I(e.X, e.Y);
         dragBeginTileCoord = LevelDisplayControl.SampleLevelTileCoordinates(mousePos);
         LevelDisplayControl.SetSelectionBox(dragBeginTileCoord, Point2I.One);
     }
 }
Beispiel #9
0
 public override void OnMouseDragMove(MouseEventArgs e)
 {
     // Update selection box.
     if (e.Button == MouseButtons.Left && isCreatingSelectionBox)
     {
         Point2I mousePos  = new Point2I(e.X, e.Y);
         Point2I tileCoord = LevelDisplayControl.SampleLevelTileCoordinates(mousePos);
         Point2I minCoord  = GMath.Min(dragBeginTileCoord, tileCoord);
         Point2I maxCoord  = GMath.Max(dragBeginTileCoord, tileCoord);
         LevelDisplayControl.SetSelectionBox(minCoord, maxCoord - minCoord + Point2I.One);
     }
 }
Beispiel #10
0
        public override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            Point2I mousePos = new Point2I(e.X, e.Y);

            // Sample the tile at the mouse position.
            BaseTileDataInstance baseTile = null;

            if (editorControl.EventMode)
            {
                baseTile = LevelDisplayControl.SampleEventTile(mousePos);
            }
            else
            {
                baseTile = LevelDisplayControl.SampleTile(mousePos, editorControl.CurrentLayer);
            }

            // Select or deselect the tile.
            if (e.Button == MouseButtons.Left)
            {
                /*if (FormsControl.ModifierKeys == Keys.Control) {
                 *      if (baseTile != null) {
                 *              // Add or remove tiles from selection.
                 *              if (!LevelDisplayControl.IsTileInSelection(baseTile)) {
                 *                      LevelDisplayControl.AddTileToSelection(baseTile);
                 *                      EditorControl.PropertyGrid.OpenProperties(baseTile);
                 *              }
                 *              else {
                 *                      LevelDisplayControl.RemoveTileFromSelection(baseTile);
                 *              }
                 *      }
                 * }
                 * else */{
                    // Select a new tile, deselecting others.
                    LevelDisplayControl.DeselectTiles();
                    if (baseTile != null)
                    {
                        LevelDisplayControl.AddTileToSelection(baseTile);
                        EditorControl.PropertyGrid.OpenProperties(baseTile);
                    }
                    else
                    {
                        EditorControl.PropertyGrid.CloseProperties();
                    }
                }
            }
        }
Beispiel #11
0
        //-----------------------------------------------------------------------------
        // Internal methods
        //-----------------------------------------------------------------------------

        private void ActivateTile(MouseEventArgs e)
        {
            Point2I mousePos       = new Point2I(e.X, e.Y);
            Point2I levelTileCoord = LevelDisplayControl.SampleLevelTileCoordinates(mousePos);

            // Limit tiles to the selection box if there is one.
            if (LevelDisplayControl.SelectionGridArea.IsEmpty ||
                LevelDisplayControl.SelectionGridArea.Contains(levelTileCoord))
            {
                Room room = LevelDisplayControl.Level.GetRoom((LevelTileCoord)levelTileCoord);
                if (room != null)
                {
                    Point2I tileLocation = LevelDisplayControl.Level.GetTileLocation((LevelTileCoord)levelTileCoord);
                    ActivateTile(e.Button, room, tileLocation);
                }
            }
        }
Beispiel #12
0
        public override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            Point2I mousePos = new Point2I(e.X, e.Y);

            if (!editorControl.EventMode)
            {
                // Highlight tiles.
                TileDataInstance tile = LevelDisplayControl.SampleTile(mousePos, editorControl.CurrentLayer);
                EditorControl.HighlightMouseTile = (tile != null);
            }
            else
            {
                // Highlight event tiles.
                EventTileDataInstance eventTile = LevelDisplayControl.SampleEventTile(mousePos);
                EditorControl.HighlightMouseTile = (eventTile != null);
            }
        }
Beispiel #13
0
 public override void OnMouseDragEnd(MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left && isCreatingSelectionBox)
     {
         isCreatingSelectionBox = false;
         Point2I mousePos  = new Point2I(e.X, e.Y);
         Point2I tileCoord = LevelDisplayControl.SampleLevelTileCoordinates(mousePos);
         Point2I minCoord  = GMath.Min(dragBeginTileCoord, tileCoord);
         Point2I maxCoord  = GMath.Max(dragBeginTileCoord, tileCoord);
         Point2I totalSize = editorControl.Level.Dimensions * editorControl.Level.RoomSize;
         for (int x = minCoord.X; x <= maxCoord.X && x < totalSize.X; x++)
         {
             for (int y = minCoord.Y; y <= maxCoord.Y && y < totalSize.Y; y++)
             {
                 ActivateTile(e.Button, new Point2I(x, y));
             }
         }
         LevelDisplayControl.ClearSelectionBox();
     }
 }
Beispiel #14
0
        public override void OnMouseDoubleClick(MouseEventArgs e)
        {
            base.OnMouseDoubleClick(e);

            Point2I mousePos   = new Point2I(e.X, e.Y);
            Point2I levelPoint = LevelDisplayControl.SampleLevelPixelPosition(mousePos);

            // Open the object properties form when double clicking on a tile.
            foreach (BaseTileDataInstance tile in LevelDisplayControl.SelectedTiles)
            {
                Rectangle2I bounds = tile.GetBounds();
                bounds.Point += tile.Room.Location * tile.Room.Size * GameSettings.TILE_SIZE;

                if (bounds.Contains(levelPoint))
                {
                    EditorControl.EditorForm.OpenObjectPropertiesEditor(tile);
                    break;
                }
            }
        }
Beispiel #15
0
        public override void OnMouseMove(MouseEventArgs e)
        {
            // Check if mouse is over selection.
            Point2I point     = new Point2I(e.X, e.Y);
            Point2I tileCoord = LevelDisplayControl.SampleLevelTileCoordinates(point) * GameSettings.TILE_SIZE;

            if (!isCreatingSelectionBox &&
                EditorControl.Level == LevelDisplayControl.SelectionGridLevel &&
                LevelDisplayControl.SelectionBox.Contains(tileCoord))
            {
                MouseCursor = Cursors.SizeAll;
                editorControl.HighlightMouseTile = false;
            }
            else
            {
                MouseCursor = Cursors.Default;
                editorControl.HighlightMouseTile = true;
            }

            base.OnMouseMove(e);
        }
Beispiel #16
0
        public override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            Point2I mousePos  = new Point2I(e.X, e.Y);
            Room    room      = LevelDisplayControl.SampleRoom(mousePos);
            Point2I tileCoord = LevelDisplayControl.SampleTileCoordinates(mousePos);
            Point2I target    = LevelDisplayControl.SampleLevelTileCoordinates(mousePos);

            if (!EditorControl.EventMode)
            {
                if (e.Button == MouseButtons.Middle)
                {
                    // Select/sample tiles.
                    TileDataInstance selectedTile = room.GetTile(tileCoord, editorControl.CurrentLayer);

                    if (selectedTile != null)
                    {
                        Point2I levelTileCoord = LevelDisplayControl.ToLevelTileCoordinates(room, tileCoord);
                        EditorControl.PropertyGrid.OpenProperties(selectedTile.Properties, selectedTile);
                        editorControl.SelectedTilesetTile     = -Point2I.One;
                        editorControl.SelectedTilesetTileData = selectedTile.TileData;
                    }
                    else
                    {
                        EditorControl.PropertyGrid.CloseProperties();
                    }
                }
                else if (editorControl.CurrentLayer == 0 || GetTileAt(target) != null)
                {
                    // Fill tiles.
                    TileData fillData = editorControl.SelectedTilesetTileData as TileData;
                    if (fillData != null)
                    {
                        if (e.Button == MouseButtons.Right)
                        {
                            fillData = null;
                        }
                        Fill(target, fillData);
                    }
                }
            }
            else
            {
                if (e.Button == MouseButtons.Middle)
                {
                    // Select events.
                    EventTileDataInstance selectedEventTile = LevelDisplayControl.SampleEventTile(mousePos);

                    if (selectedEventTile != null)
                    {
                        Point2I levelTileCoord = LevelDisplayControl.ToLevelTileCoordinates(room, tileCoord);
                        EditorControl.PropertyGrid.OpenProperties(selectedEventTile.Properties, selectedEventTile);
                    }
                    else
                    {
                        EditorControl.PropertyGrid.CloseProperties();
                    }
                }
            }
        }
Beispiel #17
0
 public override void Deselect()
 {
     isCreatingSelectionBox = false;
     LevelDisplayControl.ClearSelectionBox();
 }
Beispiel #18
0
 public override void SelectAll()
 {
     isCreatingSelectionBox = false;
     LevelDisplayControl.SetSelectionBox(Point2I.Zero,
                                         EditorControl.Level.RoomSize * EditorControl.Level.Dimensions);
 }
Beispiel #19
0
 public override void Deselect()
 {
     isCreatingSelectionBox = false;
     isMovingSelectionBox   = false;
     LevelDisplayControl.DeselectSelectionGrid();
 }
Beispiel #20
0
 public override void Delete()
 {
     LevelDisplayControl.DeleteSelectionGrid();
 }
Beispiel #21
0
        public override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            Point2I mousePos  = new Point2I(e.X, e.Y);
            Room    room      = LevelDisplayControl.SampleRoom(mousePos);
            Point2I tileCoord = LevelDisplayControl.SampleTileCoordinates(mousePos);

            if (editorControl.EventMode)
            {
                if (EditorControl.EventMode && e.Button == MouseButtons.Left)
                {
                    EventTileData eventTile = editorControl.SelectedTilesetTileData as EventTileData;

                    if (room != null && eventTile != null)
                    {
                        Point2I roomPos = LevelDisplayControl.GetRoomDrawPosition(room);
                        Point2I pos     = (mousePos - roomPos) / 8;
                        pos *= 8;
                        //Point2I tileCoord = LevelDisplayControl.SampleTileCoordinates(mousePos);
                        room.CreateEventTile(eventTile, pos);
                    }
                }
                else if (EditorControl.EventMode && e.Button == MouseButtons.Right)
                {
                    EventTileDataInstance eventTile = LevelDisplayControl.SampleEventTile(new Point2I(e.X, e.Y));
                    if (eventTile != null)
                    {
                        eventTile.Room.RemoveEventTile(eventTile);
                        editorControl.OnDeleteObject(eventTile);
                    }
                }
                else if (e.Button == MouseButtons.Middle)
                {
                    // Select events.
                    EventTileDataInstance selectedEventTile = LevelDisplayControl.SampleEventTile(mousePos);

                    if (selectedEventTile != null)
                    {
                        Point2I levelTileCoord = LevelDisplayControl.ToLevelTileCoordinates(room, tileCoord);
                        EditorControl.PropertyGrid.OpenProperties(selectedEventTile.Properties, selectedEventTile);
                    }
                    else
                    {
                        EditorControl.PropertyGrid.CloseProperties();
                    }
                }
            }
            else
            {
                if (e.Button == MouseButtons.Middle)
                {
                    // Select tiles.
                    TileDataInstance selectedTile = room.GetTile(tileCoord, editorControl.CurrentLayer);

                    if (selectedTile != null)
                    {
                        Point2I levelTileCoord = LevelDisplayControl.ToLevelTileCoordinates(room, tileCoord);
                        EditorControl.PropertyGrid.OpenProperties(selectedTile.Properties, selectedTile);
                    }
                    else
                    {
                        EditorControl.PropertyGrid.CloseProperties();
                    }
                }
            }
        }
Beispiel #22
0
        public override void OnMouseDragBegin(MouseEventArgs e)
        {
            Point2I mousePos  = new Point2I(e.X, e.Y);
            Point2I tileCoord = LevelDisplayControl.SampleLevelTileCoordinates(mousePos);
            Point2I point     = LevelDisplayControl.SampleLevelPixelPosition(mousePos);

            if (isCreatingSelectionBox || isMovingSelectionBox)
            {
                return;
            }

            // Draw a new selecion box.
            if (e.Button == MouseButtons.Left)
            {
                if (EditorControl.Level == LevelDisplayControl.SelectionGridLevel &&
                    LevelDisplayControl.SelectionBox.Contains(point))
                {
                    // Begin moving the selection box.
                    isMovingSelectionBox   = true;
                    dragBeginPoint         = point;
                    dragBeginTileCoord     = tileCoord;
                    selectionBoxBeginPoint = LevelDisplayControl.SelectionGridArea.Point;
                    //LevelDisplayControl.PickupSelectionGrid();

                    // Duplicate selection if holding Ctrl.
                    if (System.Windows.Forms.Control.ModifierKeys.HasFlag(KEYMOD_DUPLICATE))
                    {
                        LevelDisplayControl.DuplicateSelectionGrid();
                    }
                }
                else
                {
                    LevelDisplayControl.PlaceSelectionGrid();

                    // Create a new selection box.
                    isCreatingSelectionBox = true;
                    dragBeginPoint         = point;
                    dragBeginTileCoord     = tileCoord;

                    Rectangle2I selectionBox;
                    Level       level = EditorControl.Level;

                    if (System.Windows.Forms.Control.ModifierKeys.HasFlag(KEYMOD_ROOM_MODE))
                    {
                        selectionBox = new Rectangle2I(level.GetRoomLocation(
                                                           (LevelTileCoord)dragBeginTileCoord), Point2I.One);
                        Rectangle2I levelBounds = new Rectangle2I(Point2I.Zero, level.Dimensions);
                        selectionBox        = Rectangle2I.Intersect(selectionBox, levelBounds);
                        selectionBox.Point *= level.RoomSize;
                        selectionBox.Size  *= level.RoomSize;
                    }
                    else
                    {
                        selectionBox = new Rectangle2I(dragBeginTileCoord, Point2I.One);
                        Rectangle2I levelBounds = new Rectangle2I(Point2I.Zero, level.RoomSize * level.Dimensions);
                        selectionBox = Rectangle2I.Intersect(selectionBox, levelBounds);
                    }

                    LevelDisplayControl.SetSelectionGridArea(selectionBox, level);
                }
            }
        }
Beispiel #23
0
 public override void OnEnd()
 {
     LevelDisplayControl.PlaceSelectionGrid();
 }