예제 #1
0
        //-------------------------------------------------------------------------


        public void ParseMouse()
        {
            _mousePos = MouseInput.LastPos;
            bool inToolbar = (_mousePos.Y > 0 && _mousePos.Y < 100) && (_mousePos.X > 0 && _mousePos.Y < Game1.Width);

            if (MouseInput.CheckLeftPressed())
            {
                if (_mousePos.X > 0 && _mousePos.X < Game1.Width)
                {
                    if (inToolbar)
                    {
                        for (int i = 0; i < CurrentMap.TextureMap.GetTilesPerRow(); i++)
                        {
                            Vector2 pos = new Vector2(((i * 32) * _toolBarZoom), 20);
                            pos.X += (Game1.Width - _toolbarPos.X) - Game1.Width;
                            Vector2 bottomRight = new Vector2(pos.X + (CurrentMap.TextureMap.TileWidth * _toolBarZoom), pos.Y + (CurrentMap.TextureMap.TileHeight * _toolBarZoom));
                            if (_mousePos.X > pos.X && _mousePos.X < bottomRight.X && _mousePos.Y > pos.Y && _mousePos.Y < bottomRight.Y)
                            {
                                _tileSelectionID       = i;
                                CurrentTileSelectionID = _tileSelectionID + (CurrentMap.TextureMap.GetTilesPerRow() * CurrentEditorRow);
                            }
                        }
                    }
                }

                if (_mousePos.Y > 100 && _mousePos.Y < Game1.Height)
                {
                    if (_toolsSelectedTool == SelectedTool.RECTANGLE) //-------------------------
                    {
                        if (EditorDraw.FirstRectFillTileSelected)
                        {
                            EditorDraw.ExecuteRectangleFill(CurrentTileSelectionID, _selectionX, _selectionY);
                            EditorDraw.ClearToolsRectSelection();
                        }
                        else
                        {
                            EditorDraw.SelectTile(_selectionX, _selectionY);
                        }
                    }
                }
            }
            else if (MouseInput.CheckLeftDown())
            {
                if (_isToolbarScrolling)
                {
                    _toolbarScrollPos.X = MouseInput.LastPos.X - (_toolbarScrollWidth / 2);

                    if (_toolbarScrollPos.X < 0)
                    {
                        _toolbarScrollPos.X = 0;
                    }
                    else if (_toolbarScrollPos.X > Game1.Width - _toolbarScrollWidth)
                    {
                        _toolbarScrollPos.X = Game1.Width - (_toolbarScrollWidth);
                    }


                    float posRatio = _toolbarScrollPos.X / Game1.Width;
                    _toolbarPos.X = posRatio * Game1.Width * _toolBarZoom * 1.6f;
                }
                else if (inToolbar)
                {
                    if (_mousePos.Y < 16)
                    {
                        _isToolbarScrolling = true;
                    }
                }
                else if (_mousePos.Y > 100 && _mousePos.Y < Game1.Height)
                {
                    if (_toolsSelectedTool == SelectedTool.FILL_BUCKET)
                    {
                        EditorDraw.FillTile(CurrentTileSelectionID, _selectionX, _selectionY, ShowCollision);
                    }
                    else if (_toolsSelectedTool != SelectedTool.RECTANGLE)
                    {
                        EditorDraw.PlaceTile(CurrentTileSelectionID, _selectionX, _selectionY, ShowCollision);
                    }
                }
            }
            else if (MouseInput.CheckRightDown())
            {
                if (_mousePos.Y > 100 && _mousePos.Y < Game1.Height)
                {
                    EditorDraw.PlaceTile(0, _selectionX, _selectionY);
                }
            }
            else
            {
                if (_isToolbarScrolling)
                {
                    _isToolbarScrolling = false;
                }
            }

            int currentScroll = MouseInput.ScrollValue;
            int scrollDif     = currentScroll - _lastScroll;

            if (inToolbar)
            {
                if (scrollDif < 0)
                {
                    if (CurrentEditorRow < CurrentMap.TextureMap.GetTilesPerColumn() - 1)
                    {
                        CurrentTileSelectionID += CurrentMap.TextureMap.GetTilesPerRow();
                        CurrentEditorRow++;
                    }
                }
                else if (scrollDif > 0)
                {
                    if (CurrentEditorRow > 0)
                    {
                        CurrentEditorRow--;
                        CurrentTileSelectionID -= CurrentMap.TextureMap.GetTilesPerRow();
                    }
                }
            }
            else
            {
                if (scrollDif < 0)
                {
                    _zoom -= 0.1f;
                    if (_zoom <= 0f)
                    {
                        _zoom = 0.1f;
                    }
                }
                else if (scrollDif > 0)
                {
                    _zoom += 0.1f;
                }
            }


            _lastScroll = currentScroll;
        }
예제 #2
0
        //---------------------------------------------
        //private void Undo()
        //{
        //    //_undoManager.Undo();
        //}

        private void ParseKeys()
        {
            KeyboardState state = Keyboard.GetState();

            // Control is Down
            if (state.IsKeyDown(Keys.LeftControl))
            {
                if (state.IsKeyDown(Keys.T))
                {
                    SwitchTextures();
                }

                if (state.IsKeyDown(Keys.A))
                {
                    ChangeMapDimensions();
                }

                if (state.IsKeyDown(Keys.O))
                {
                    OpenMap();
                }

                if (state.IsKeyDown(Keys.S))
                {
                    SaveMap();
                }

                if (state.IsKeyDown(Keys.N))
                {
                    NewMap();
                }

                //---------| UNDO |
                //if (state.IsKeyDown(Keys.Z))
                //{
                //}
            }
            else
            {
                float speed = (_mapMovementReverse ? -1 : 1) * _speed;
                if (state.IsKeyDown(Keys.A))
                {
                    _mapPosition.X  -= speed;
                    _selectionPos.X -= (int)speed;
                }
                if (state.IsKeyDown(Keys.D))
                {
                    _mapPosition.X  += speed;
                    _selectionPos.X += (int)speed;
                }
                if (state.IsKeyDown(Keys.W))
                {
                    _mapPosition.Y  -= speed;
                    _selectionPos.Y -= (int)speed;
                }
                if (state.IsKeyDown(Keys.S))
                {
                    _mapPosition.Y  += speed;
                    _selectionPos.Y += (int)speed;
                }
                if (state.IsKeyDown(Keys.OemTilde))
                {
                    EditorDraw.PlaceTile(_tileSelectionID, _selectionX, _selectionY, ShowCollision);
                }
                if (state.IsKeyDown(Keys.R))
                {
                    _zoom        = 1f;
                    _mapPosition = Vector2.Zero;
                }
                if (KeyboardInput.CheckIsPressed(Keys.P))
                {
                    ShowCollision = !ShowCollision;
                }
                if (KeyboardInput.CheckIsPressed(Keys.O))
                {
                    ShowTriggers = !ShowTriggers;
                }

                if (KeyboardInput.CheckIsPressed(Keys.Q))
                {
                    if (_tileSelectionID > 0)
                    {
                        _tileSelectionID--;
                        CurrentTileSelectionID--;
                    }
                }
                if (KeyboardInput.CheckIsPressed(Keys.E))
                {
                    if (_tileSelectionID < CurrentMap.TextureMap.GetTilesPerRow() - 1)
                    {
                        _tileSelectionID++;
                        CurrentTileSelectionID++;
                    }
                }
            }
        }