Skip to content

Commit ecd3806

Browse files
committed
Editor: Arrow keys move selected tiles / entities
1 parent 61870ae commit ecd3806

File tree

3 files changed

+118
-7
lines changed

3 files changed

+118
-7
lines changed

DelvEdit/src/com/interrupt/dungeoneer/editor/Editor.java

+33
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public enum EditorMode { Carve, Paint };
5858
public ActionListener copyAction;
5959
public ActionListener pasteAction;
6060

61+
public ActionListener moveTileNorthAction;
62+
public ActionListener moveTileSouthAction;
63+
public ActionListener moveTileEastAction;
64+
public ActionListener moveTileWestAction;
65+
6166
public ActionListener raiseFloorAction;
6267
public ActionListener lowerFloorAction;
6368
public ActionListener raiseCeilingAction;
@@ -485,6 +490,34 @@ public void actionPerformed(ActionEvent actionEvent) {
485490
}
486491
};
487492

493+
moveTileNorthAction = new ActionListener() {
494+
@Override
495+
public void actionPerformed(ActionEvent actionEvent) {
496+
editorFrame.moveTiles(0, 1);
497+
}
498+
};
499+
500+
moveTileSouthAction = new ActionListener() {
501+
@Override
502+
public void actionPerformed(ActionEvent actionEvent) {
503+
editorFrame.moveTiles(0, -1);
504+
}
505+
};
506+
507+
moveTileEastAction = new ActionListener() {
508+
@Override
509+
public void actionPerformed(ActionEvent actionEvent) {
510+
editorFrame.moveTiles(1, 0);
511+
}
512+
};
513+
514+
moveTileWestAction = new ActionListener() {
515+
@Override
516+
public void actionPerformed(ActionEvent actionEvent) {
517+
editorFrame.moveTiles(-1, 0);
518+
}
519+
};
520+
488521
toggleSimulation = new ActionListener() {
489522
@Override
490523
public void actionPerformed(ActionEvent actionEvent) {

DelvEdit/src/com/interrupt/dungeoneer/editor/EditorFrame.java

+81-7
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,10 @@ public boolean isWestFloor() {
234234

235235
float camX = 7.5f;
236236
float camY = 8;
237-
float camZ = 4.5f;
237+
float camZ = 6.5f;
238238

239-
float rotX = 0;
240-
float rotY = 20f;
239+
float rotX = 3.14159f;
240+
float rotY = 1.4f;
241241
double rota = 0;
242242
double rotya = 0;
243243
float rotYClamp = 1.571f;
@@ -668,6 +668,11 @@ public void draw() {
668668
shouldDrawBox = true;
669669
}
670670

671+
// don't draw the box when freelooking
672+
if(shouldDrawBox && !selected && Gdx.input.isCursorCatched()) {
673+
shouldDrawBox = false;
674+
}
675+
671676
if(pickedEntity == null && hoveredEntity == null || tileDragging) {
672677
if(!selected || (!(pickedControlPoint != null || movingControlPoint) &&
673678
editorInput.isButtonPressed(Input.Buttons.LEFT) && Gdx.input.justTouched())) {
@@ -2020,10 +2025,10 @@ else if(pickedEntity != null && pickedEntity == hoveredEntity || additionalSelec
20202025
}
20212026
if(pickedEntity == null) movingEntity = false;
20222027

2023-
boolean turnLeft = editorInput.isKeyPressed(Keys.LEFT) || (Gdx.input.getDeltaX() < 0 && Gdx.input.isButtonPressed(Buttons.MIDDLE));
2024-
boolean turnRight = editorInput.isKeyPressed(Keys.RIGHT) || (Gdx.input.getDeltaX() > 0 && Gdx.input.isButtonPressed(Buttons.MIDDLE));
2025-
boolean turnUp = editorInput.isKeyPressed(Keys.UP) || (Gdx.input.getDeltaY() > 0 && Gdx.input.isButtonPressed(Buttons.MIDDLE));
2026-
boolean turnDown = editorInput.isKeyPressed(Keys.DOWN) || (Gdx.input.getDeltaY() < 0 && Gdx.input.isButtonPressed(Buttons.MIDDLE));
2028+
boolean turnLeft = editorInput.isKeyPressed(Keys.Q) || (Gdx.input.getDeltaX() < 0 && Gdx.input.isButtonPressed(Buttons.MIDDLE));
2029+
boolean turnRight = editorInput.isKeyPressed(Keys.E) || (Gdx.input.getDeltaX() > 0 && Gdx.input.isButtonPressed(Buttons.MIDDLE));
2030+
boolean turnUp = (Gdx.input.getDeltaY() > 0 && Gdx.input.isButtonPressed(Buttons.MIDDLE));
2031+
boolean turnDown = (Gdx.input.getDeltaY() < 0 && Gdx.input.isButtonPressed(Buttons.MIDDLE));
20272032

20282033
if(turnLeft) {
20292034
rota += rotSpeed;
@@ -4044,6 +4049,75 @@ public Decal getDecal() {
40444049
return sd;
40454050
}
40464051

4052+
public void moveTiles(int moveX, int moveY) {
4053+
int selX = selectionX;
4054+
int selY = selectionY;
4055+
int selWidth = selectionWidth;
4056+
int selHeight = selectionHeight;
4057+
4058+
// Move Tiles
4059+
if(selected) {
4060+
Tile[] moving = new Tile[selWidth * selHeight];
4061+
4062+
for (int x = 0; x < selWidth; x++) {
4063+
for (int y = 0; y < selHeight; y++) {
4064+
int tileX = selX + x;
4065+
int tileY = selY + y;
4066+
4067+
Tile t = level.getTileOrNull(tileX, tileY);
4068+
moving[x + y * selectionWidth] = t;
4069+
4070+
level.setTile(tileX, tileY, null);
4071+
markWorldAsDirty(tileX, tileY, 1);
4072+
}
4073+
}
4074+
4075+
for (int x = 0; x < selWidth; x++) {
4076+
for (int y = 0; y < selHeight; y++) {
4077+
int tileX = selX + x + moveX;
4078+
int tileY = selY + y + moveY;
4079+
4080+
level.setTile(tileX, tileY, moving[x + y * selectionWidth]);
4081+
markWorldAsDirty(tileX, tileY, 1);
4082+
}
4083+
}
4084+
4085+
// Move Markers
4086+
for(int x = selX; x < selX + selWidth; x++) {
4087+
for(int y = selY; y < selY + selHeight; y++) {
4088+
if(level.editorMarkers != null && level.editorMarkers.size > 0) {
4089+
for(int i = 0; i < level.editorMarkers.size; i++) {
4090+
EditorMarker m = level.editorMarkers.get(i);
4091+
if(m.x == x && m.y == y) {
4092+
m.x += moveX;
4093+
m.y += moveY;
4094+
}
4095+
}
4096+
}
4097+
}
4098+
}
4099+
4100+
selectionX += moveX;
4101+
selectionY += moveY;
4102+
controlPoints.clear();
4103+
}
4104+
4105+
// Move Entities
4106+
Array<Entity> allSelected = new Array<Entity>();
4107+
if(pickedEntity != null) {
4108+
allSelected.add(pickedEntity);
4109+
}
4110+
allSelected.addAll(additionalSelected);
4111+
4112+
for(Entity e : allSelected) {
4113+
e.x += moveX;
4114+
e.y += moveY;
4115+
markWorldAsDirty((int)e.x, (int)e.y, 1);
4116+
}
4117+
4118+
history.saveState(level);
4119+
}
4120+
40474121
private void vizualizePicking() {
40484122
if(pickViz == null)
40494123
pickViz = new SpriteBatch();

DelvEdit/src/com/interrupt/dungeoneer/editor/ui/EditorUi.java

+4
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,10 @@ public void actionPerformed(ActionEvent event) {
254254
.addItem(new MenuItem("Lower Floor", smallSkin, editor.lowerFloorAction).setAccelerator(new MenuAccelerator(Keys.NUM_3, false, true)))
255255
.addItem(new MenuItem("Raise Ceiling", smallSkin, editor.raiseCeilingAction).setAccelerator(new MenuAccelerator(Keys.NUM_4, false, false)))
256256
.addItem(new MenuItem("Lower Ceiling", smallSkin, editor.lowerCeilingAction).setAccelerator(new MenuAccelerator(Keys.NUM_4, false, true)))
257+
.addItem(new MenuItem("Move North", smallSkin, editor.moveTileNorthAction).setAccelerator(new MenuAccelerator(Keys.UP, false, false)))
258+
.addItem(new MenuItem("Move South", smallSkin, editor.moveTileSouthAction).setAccelerator(new MenuAccelerator(Keys.DOWN, false, false)))
259+
.addItem(new MenuItem("Move East", smallSkin, editor.moveTileEastAction).setAccelerator(new MenuAccelerator(Keys.LEFT, false, false)))
260+
.addItem(new MenuItem("Move West", smallSkin, editor.moveTileWestAction).setAccelerator(new MenuAccelerator(Keys.RIGHT, false, false)))
257261
)
258262
.addItem(new MenuItem("Rotate Wall Angle", smallSkin, editor.rotateWallAngle).setAccelerator(new MenuAccelerator(Keys.U, false, false)))
259263
.addItem(new MenuItem("Flatten", smallSkin)

0 commit comments

Comments
 (0)