From ecd38062023a80f82e67d390566bbd294a68860f Mon Sep 17 00:00:00 2001 From: Chad Cuddigan Date: Mon, 7 Jan 2019 18:36:17 -0800 Subject: [PATCH] Editor: Arrow keys move selected tiles / entities --- .../interrupt/dungeoneer/editor/Editor.java | 33 +++++++ .../dungeoneer/editor/EditorFrame.java | 88 +++++++++++++++++-- .../dungeoneer/editor/ui/EditorUi.java | 4 + 3 files changed, 118 insertions(+), 7 deletions(-) diff --git a/DelvEdit/src/com/interrupt/dungeoneer/editor/Editor.java b/DelvEdit/src/com/interrupt/dungeoneer/editor/Editor.java index 4a0cd182..4938c54f 100644 --- a/DelvEdit/src/com/interrupt/dungeoneer/editor/Editor.java +++ b/DelvEdit/src/com/interrupt/dungeoneer/editor/Editor.java @@ -58,6 +58,11 @@ public enum EditorMode { Carve, Paint }; public ActionListener copyAction; public ActionListener pasteAction; + public ActionListener moveTileNorthAction; + public ActionListener moveTileSouthAction; + public ActionListener moveTileEastAction; + public ActionListener moveTileWestAction; + public ActionListener raiseFloorAction; public ActionListener lowerFloorAction; public ActionListener raiseCeilingAction; @@ -485,6 +490,34 @@ public void actionPerformed(ActionEvent actionEvent) { } }; + moveTileNorthAction = new ActionListener() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + editorFrame.moveTiles(0, 1); + } + }; + + moveTileSouthAction = new ActionListener() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + editorFrame.moveTiles(0, -1); + } + }; + + moveTileEastAction = new ActionListener() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + editorFrame.moveTiles(1, 0); + } + }; + + moveTileWestAction = new ActionListener() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + editorFrame.moveTiles(-1, 0); + } + }; + toggleSimulation = new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { diff --git a/DelvEdit/src/com/interrupt/dungeoneer/editor/EditorFrame.java b/DelvEdit/src/com/interrupt/dungeoneer/editor/EditorFrame.java index 7b64f887..d80e2f33 100644 --- a/DelvEdit/src/com/interrupt/dungeoneer/editor/EditorFrame.java +++ b/DelvEdit/src/com/interrupt/dungeoneer/editor/EditorFrame.java @@ -234,10 +234,10 @@ public boolean isWestFloor() { float camX = 7.5f; float camY = 8; - float camZ = 4.5f; + float camZ = 6.5f; - float rotX = 0; - float rotY = 20f; + float rotX = 3.14159f; + float rotY = 1.4f; double rota = 0; double rotya = 0; float rotYClamp = 1.571f; @@ -668,6 +668,11 @@ public void draw() { shouldDrawBox = true; } + // don't draw the box when freelooking + if(shouldDrawBox && !selected && Gdx.input.isCursorCatched()) { + shouldDrawBox = false; + } + if(pickedEntity == null && hoveredEntity == null || tileDragging) { if(!selected || (!(pickedControlPoint != null || movingControlPoint) && editorInput.isButtonPressed(Input.Buttons.LEFT) && Gdx.input.justTouched())) { @@ -2020,10 +2025,10 @@ else if(pickedEntity != null && pickedEntity == hoveredEntity || additionalSelec } if(pickedEntity == null) movingEntity = false; - boolean turnLeft = editorInput.isKeyPressed(Keys.LEFT) || (Gdx.input.getDeltaX() < 0 && Gdx.input.isButtonPressed(Buttons.MIDDLE)); - boolean turnRight = editorInput.isKeyPressed(Keys.RIGHT) || (Gdx.input.getDeltaX() > 0 && Gdx.input.isButtonPressed(Buttons.MIDDLE)); - boolean turnUp = editorInput.isKeyPressed(Keys.UP) || (Gdx.input.getDeltaY() > 0 && Gdx.input.isButtonPressed(Buttons.MIDDLE)); - boolean turnDown = editorInput.isKeyPressed(Keys.DOWN) || (Gdx.input.getDeltaY() < 0 && Gdx.input.isButtonPressed(Buttons.MIDDLE)); + boolean turnLeft = editorInput.isKeyPressed(Keys.Q) || (Gdx.input.getDeltaX() < 0 && Gdx.input.isButtonPressed(Buttons.MIDDLE)); + boolean turnRight = editorInput.isKeyPressed(Keys.E) || (Gdx.input.getDeltaX() > 0 && Gdx.input.isButtonPressed(Buttons.MIDDLE)); + boolean turnUp = (Gdx.input.getDeltaY() > 0 && Gdx.input.isButtonPressed(Buttons.MIDDLE)); + boolean turnDown = (Gdx.input.getDeltaY() < 0 && Gdx.input.isButtonPressed(Buttons.MIDDLE)); if(turnLeft) { rota += rotSpeed; @@ -4044,6 +4049,75 @@ public Decal getDecal() { return sd; } + public void moveTiles(int moveX, int moveY) { + int selX = selectionX; + int selY = selectionY; + int selWidth = selectionWidth; + int selHeight = selectionHeight; + + // Move Tiles + if(selected) { + Tile[] moving = new Tile[selWidth * selHeight]; + + for (int x = 0; x < selWidth; x++) { + for (int y = 0; y < selHeight; y++) { + int tileX = selX + x; + int tileY = selY + y; + + Tile t = level.getTileOrNull(tileX, tileY); + moving[x + y * selectionWidth] = t; + + level.setTile(tileX, tileY, null); + markWorldAsDirty(tileX, tileY, 1); + } + } + + for (int x = 0; x < selWidth; x++) { + for (int y = 0; y < selHeight; y++) { + int tileX = selX + x + moveX; + int tileY = selY + y + moveY; + + level.setTile(tileX, tileY, moving[x + y * selectionWidth]); + markWorldAsDirty(tileX, tileY, 1); + } + } + + // Move Markers + for(int x = selX; x < selX + selWidth; x++) { + for(int y = selY; y < selY + selHeight; y++) { + if(level.editorMarkers != null && level.editorMarkers.size > 0) { + for(int i = 0; i < level.editorMarkers.size; i++) { + EditorMarker m = level.editorMarkers.get(i); + if(m.x == x && m.y == y) { + m.x += moveX; + m.y += moveY; + } + } + } + } + } + + selectionX += moveX; + selectionY += moveY; + controlPoints.clear(); + } + + // Move Entities + Array allSelected = new Array(); + if(pickedEntity != null) { + allSelected.add(pickedEntity); + } + allSelected.addAll(additionalSelected); + + for(Entity e : allSelected) { + e.x += moveX; + e.y += moveY; + markWorldAsDirty((int)e.x, (int)e.y, 1); + } + + history.saveState(level); + } + private void vizualizePicking() { if(pickViz == null) pickViz = new SpriteBatch(); diff --git a/DelvEdit/src/com/interrupt/dungeoneer/editor/ui/EditorUi.java b/DelvEdit/src/com/interrupt/dungeoneer/editor/ui/EditorUi.java index 5a7579e1..47baa7b1 100644 --- a/DelvEdit/src/com/interrupt/dungeoneer/editor/ui/EditorUi.java +++ b/DelvEdit/src/com/interrupt/dungeoneer/editor/ui/EditorUi.java @@ -254,6 +254,10 @@ public void actionPerformed(ActionEvent event) { .addItem(new MenuItem("Lower Floor", smallSkin, editor.lowerFloorAction).setAccelerator(new MenuAccelerator(Keys.NUM_3, false, true))) .addItem(new MenuItem("Raise Ceiling", smallSkin, editor.raiseCeilingAction).setAccelerator(new MenuAccelerator(Keys.NUM_4, false, false))) .addItem(new MenuItem("Lower Ceiling", smallSkin, editor.lowerCeilingAction).setAccelerator(new MenuAccelerator(Keys.NUM_4, false, true))) + .addItem(new MenuItem("Move North", smallSkin, editor.moveTileNorthAction).setAccelerator(new MenuAccelerator(Keys.UP, false, false))) + .addItem(new MenuItem("Move South", smallSkin, editor.moveTileSouthAction).setAccelerator(new MenuAccelerator(Keys.DOWN, false, false))) + .addItem(new MenuItem("Move East", smallSkin, editor.moveTileEastAction).setAccelerator(new MenuAccelerator(Keys.LEFT, false, false))) + .addItem(new MenuItem("Move West", smallSkin, editor.moveTileWestAction).setAccelerator(new MenuAccelerator(Keys.RIGHT, false, false))) ) .addItem(new MenuItem("Rotate Wall Angle", smallSkin, editor.rotateWallAngle).setAccelerator(new MenuAccelerator(Keys.U, false, false))) .addItem(new MenuItem("Flatten", smallSkin)