Exemple #1
0
        protected override void LoadContent()
        {
            editor = new Level.Editor(GraphicsDevice.Viewport, Content, width, height);
            inputHandler = new Systems.InputHandler();

            spriteBatch = new SpriteBatch(GraphicsDevice);

            editor.LoadContent(Content);
        }
Exemple #2
0
        private void layerChecker(InputHandler inputHandler)
        {
            if (inputHandler.scrollwheelMoved() < 0)
                Layer--;
            else if (inputHandler.scrollwheelMoved() > 0)
                Layer++;

            if (Layer < 1)
                Layer = 1;
            else if (Layer > 3)
                Layer = 3;
        }
Exemple #3
0
        public void update(ContentManager content, InputHandler inputHandler)
        {
            /* Changing modes */
            if (inputHandler.keyReleased(Keys.Tab))
                changeMode(false);
            if (inputHandler.keyReleased(Keys.F1))
                changeMode(true);

            /* Changing Layers */
            layerChecker(inputHandler);

            /* Change top text*/
            TopBox.setHeaderText("Editor   -   Layer: " + Layer);

            /* Moving camera and updating mouse texture/position + HUD position*/
            if (inputHandler.keyDown(Keys.Space))
            {
                editorCamera.moveCamera(inputHandler.mouseMoved());
                changeCursorTexture(content, true);
            }
            else if (inputHandler.keyReleased(Keys.Space))
                changeCursorTexture(content, false);

            CursorPosition = Vector2.Transform(inputHandler.mousePosition(), editorCamera.getInverseTransform());

            CoordBox.setHeaderText("X: " + CursorPosition.X + " Y: " + CursorPosition.Y);

            updateHudPosition();

            switch (mode)
            {
                case Modes.Edit:
                    CursorTilePosition = inputHandler.mousePosition();
                    CursorTilePosition = Vector2.Transform(CursorTilePosition, editorCamera.getInverseTransform());

                    float overX = CursorTilePosition.X % 32;
                    float overY = CursorTilePosition.Y % 32;

                    CursorTilePosition -= new Vector2(overX, overY);

                    /* Editing tilemap */
                    if (clickOnHud(inputHandler.mousePosition()))
                    {
                        #region Choosing tiles and other HUD stuff
                        if (inputHandler.leftClicked())
                        {
                            // The tilesheet is located at (1010, 70).
                            //  ((640 + 370), (360 - 290))
                            //  THERE ARE WAY TOO MANY NUMBERS HERE.
                            //  GET THIS SHIT IN ORDER
                            if (((inputHandler.mousePosition().X > 1010) && (inputHandler.mousePosition().X < (1010 + Tilesheet.SheetWidth)))
                                && ((inputHandler.mousePosition().Y > 70) && (inputHandler.mousePosition().Y < (70 + Tilesheet.SheetHeight))))
                            {
                                tileSelect = new Vector2(   ((inputHandler.mousePosition().X - ((inputHandler.mousePosition().X - 1010) % 32)) - 1010),
                                                                    ((inputHandler.mousePosition().Y - ((inputHandler.mousePosition().Y - 70) % 32)) - 70));

                                SelectionRectPosition = Tilesheet.Position + tileSelect;

                                SelectedTile = Tilesheet.getTile(((int)tileSelect.X / Tilesheet.TileSize), ((int)tileSelect.Y / Tilesheet.TileSize));
                            }
                        }
                        #endregion
                    }
                    else
                    {
                        #region Placing and removing tiles
                        // Adding tiles:
                        if (inputHandler.leftClicked())
                        {
                            if (SelectedTile != null)
                            {
                                SelectedTile.setPosition(CursorTilePosition);
                                currentLevel.placeTile(SelectedTile, CursorTilePosition, Layer);

                                SelectedTile = null;
                            }

                            if (SelectedTile == null)
                            {
                                SelectedTile = Tilesheet.getTile(((int)tileSelect.X / Tilesheet.TileSize), ((int)tileSelect.Y / Tilesheet.TileSize));
                            }
                        }

                        // Removing tiles:
                        if (inputHandler.rightClicked())
                        {
                            currentLevel.removeTileCheck(CursorTilePosition, Layer);
                        }
                        #endregion
                    }
                    break;
                case Modes.View:
                    break;
                case Modes.Help:
                    break;
            }
            if (mode == Modes.Edit)
            {

            }
        }