Example #1
0
        private void d2dMapEditor_KeyDown(object sender, KeyEventArgs e)
        {
            if (lbLayers.SelectedItem == null)
            {
                return;
            }

            int index = lbLayers.SelectedIndex;

            EditingTool.KeyboardShortCut(this, _map, _map_info, _history, index, e);
        }
Example #2
0
        private void mapPicBox_MouseMove(object sender, MouseEventArgs e)
        {   // mouse move over map
            if (lbLayers.SelectedItem == null)
            {
                return;
            }

            int index = lbLayers.SelectedIndex;

            Point myMouse  = PointToClient(MousePosition);
            int   clickedX = myMouse.X - pnlDesign.Location.X - pbMap.Location.X + pnlDesign.AutoScrollPosition.X - 4;
            int   clickedY = myMouse.Y - pnlDesign.Location.Y - pbMap.Location.Y + pnlDesign.AutoScrollPosition.Y - 22;

            InputHelper.MapPosition.X = clickedX / _map.TileWidth;
            InputHelper.MapPosition.Y = clickedY / _map.TileHeight;

            if (_map_info.SelectedTool != ToolType.selection && !_map.IsWithinArea(index))
            {
                return;
            }

            _map.ForceWithinArea(index);

            this.lblMapCoordinate.Text = "Map Coordinate: " + InputHelper.MapPosition.X + ", " + InputHelper.MapPosition.Y;
            this.lblMouse.Text         = "Mouse Position: " + clickedX + ", " + clickedY;

            if (e.Button == MouseButtons.Left)
            {
                if (_map_info.SelectedTool == ToolType.selection)
                {   // selection tool
                    EditingTool.Selection(this, _map, _map_info, index, SelectionState.Dragging);
                }
                else if (_map_info.SelectedTool == ToolType.brush)
                {   // brush tool
                    mapPicBox_MouseDown(sender, e);
                }
                else if (_map_info.SelectedTool == ToolType.selectTile)
                {   // select color tool
                    mapPicBox_MouseDown(sender, e);
                }
                else if (_map_info.SelectedTool == ToolType.eraser)
                {   // eraser tool
                    mapPicBox_MouseDown(sender, e);
                }
            }

            InputHelper.TrackMouse.X = myMouse.X;
            InputHelper.TrackMouse.Y = myMouse.Y;
        }
Example #3
0
 private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (tctrlDesign.SelectedTab == tpgDesign)
     {
         int index = lbLayers.SelectedIndex;
         if (index < 0)
         {
             return;
         }
         EditingTool.Selection(this, _map, _map_info, index, SelectionState.SelectAll);
     }
     else if (tctrlDesign.SelectedTab == tpgCode)
     {
         tbCode.Focus();
         tbCode.SelectAll();
     }
 }
Example #4
0
        private void mapPicBox_MouseUp(object sender, MouseEventArgs e)
        {   // mouse release over map
            if (lbLayers.SelectedItem == null)
            {
                return;
            }

            int index = lbLayers.SelectedIndex;

            Point myMouse  = PointToClient(MousePosition);
            int   clickedX = myMouse.X - pnlDesign.Location.X - pbMap.Location.X + pnlDesign.AutoScrollPosition.X - 5;
            int   clickedY = myMouse.Y - pnlDesign.Location.Y - pbMap.Location.Y + pnlDesign.AutoScrollPosition.Y - 22;

            InputHelper.MapPosition.X = clickedX / _map.TileWidth;
            InputHelper.MapPosition.Y = clickedY / _map.TileHeight;

            _map.ForceWithinArea(index);

            if (_map_info.SelectedTool == ToolType.selection && _map_info.Selection.IsDragging)
            {   // selection tool
                EditingTool.Selection(this, _map, _map_info, index, SelectionState.EndSelection);
            }
        }
Example #5
0
        private void mapPicBox_MouseDown(object sender, MouseEventArgs e)
        {   // mouse click over map
            if (lbLayers.SelectedItem == null)
            {
                return;
            }

            int index = lbLayers.SelectedIndex;

            Point myMouse  = PointToClient(MousePosition);
            int   clickedX = myMouse.X - pnlDesign.Location.X - pbMap.Location.X + pnlDesign.AutoScrollPosition.X - 4;
            int   clickedY = myMouse.Y - pnlDesign.Location.Y - pbMap.Location.Y + pnlDesign.AutoScrollPosition.Y - 22;
            int   oldX     = InputHelper.TrackMouse.X - pnlDesign.Location.X - pbMap.Location.X + pnlDesign.AutoScrollPosition.X - 4;
            int   oldY     = InputHelper.TrackMouse.Y - pnlDesign.Location.Y - pbMap.Location.Y + pnlDesign.AutoScrollPosition.Y - 22;

            InputHelper.MapPosition    = new Point(clickedX / _map.TileWidth, clickedY / _map.TileHeight);
            InputHelper.OldMapPosition = new Point(oldX / _map.TileWidth, oldY / _map.TileHeight);

            if (!_map.IsWithinArea(index))
            {
                return;
            }

            this.lblMapCoordinate.Text = "Map Coordinate: " + InputHelper.MapPosition.X + ", " + InputHelper.MapPosition.Y;
            this.lblMouse.Text         = "Mouse Position: " + clickedX + ", " + clickedY;

            if (e.Button == MouseButtons.Left)
            {
                if (_map_info.SelectedTool == ToolType.selection)
                {   // selection tool
                    EditingTool.Selection(this, _map, _map_info, index, SelectionState.StartSelection);
                }
                else if (_map_info.SelectedTool == ToolType.brush)
                {   // brush tool
                    if (pnlTileLibrary.Controls.ContainsKey(pbSelectedTile.Name) == true)
                    {
                        EditingTool.Brush(this, _map, _history, index, Convert.ToInt32(pbSelectedTile.Name));
                    }
                }
                else if (_map_info.SelectedTool == ToolType.fill)
                {   // fill tool
                    if (pnlTileLibrary.Controls.ContainsKey(pbSelectedTile.Name) == true)
                    {
                        EditingTool.Fill(_map, _map_info, _history, index, Convert.ToInt32(pbSelectedTile.Name));
                    }
                }
                else if (_map_info.SelectedTool == ToolType.selectTile)
                {   // select color tool
                    if (_map.Layers[index].LayerData[InputHelper.MapPosition.X, InputHelper.MapPosition.Y] > -1)
                    {
                        Tile selectedTile = _tile_library[_map.Layers[index].LayerData[InputHelper.MapPosition.X, InputHelper.MapPosition.Y]];

                        _map_info.SelectedTile   = selectedTile.TilePictureBox;
                        lblTileIDValue.Text      = _map_info.SelectedTile.Name;
                        tbTileName.Text          = selectedTile.TileName;
                        cbTileWalkable.Checked   = selectedTile.TileWalkable;
                        pbSelectedTile.Image     = _map_info.SelectedTile.Image;
                        pbSelectedTile.Name      = _map_info.SelectedTile.Name;
                        gbTileProperties.Enabled = true;
                    }
                    else
                    {
                        ClearSelectedTile();
                    }
                }
                else if (_map_info.SelectedTool == ToolType.eraser)
                {   // eraser tool
                    EditingTool.Eraser(_map, _map_info, _history, index);
                }

                RenderMap();
            }
            else if (e.Button == MouseButtons.Right)
            {
                _map_info.Selection = new SelectionTool();
                RenderMap();
            }

            if (_history.Undo.Count > 0)
            {
                undoToolStripMenuItem.Enabled = true;
            }
            else
            {
                undoToolStripMenuItem.Enabled = false;
            }
        }