Skip to content

Commit

Permalink
Editor: Arrow keys move selected tiles / entities
Browse files Browse the repository at this point in the history
  • Loading branch information
Interrupt committed Jan 8, 2019
1 parent 61870ae commit ecd3806
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 7 deletions.
33 changes: 33 additions & 0 deletions DelvEdit/src/com/interrupt/dungeoneer/editor/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
88 changes: 81 additions & 7 deletions DelvEdit/src/com/interrupt/dungeoneer/editor/EditorFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<Entity> allSelected = new Array<Entity>();
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();
Expand Down
4 changes: 4 additions & 0 deletions DelvEdit/src/com/interrupt/dungeoneer/editor/ui/EditorUi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ecd3806

Please sign in to comment.