From de8239c38cafb7bff9bf2a3bf0435fdd925dd160 Mon Sep 17 00:00:00 2001 From: Joshua Skelton Date: Sat, 25 Apr 2020 09:46:15 -0700 Subject: [PATCH] Initial TileSelection class implementation --- .../dungeoneer/editor/EditorApplication.java | 824 +++++++----------- .../selection/AdjacentTileSelectionInfo.java | 24 + .../editor/selection/EditorSelection.java | 5 +- .../editor/selection/TileSelection.java | 99 ++- .../editor/selection/TileSelectionInfo.java | 15 + 5 files changed, 472 insertions(+), 495 deletions(-) create mode 100644 DelvEdit/src/com/interrupt/dungeoneer/editor/selection/AdjacentTileSelectionInfo.java create mode 100644 DelvEdit/src/com/interrupt/dungeoneer/editor/selection/TileSelectionInfo.java diff --git a/DelvEdit/src/com/interrupt/dungeoneer/editor/EditorApplication.java b/DelvEdit/src/com/interrupt/dungeoneer/editor/EditorApplication.java index f7e7ae9c..8e48b459 100644 --- a/DelvEdit/src/com/interrupt/dungeoneer/editor/EditorApplication.java +++ b/DelvEdit/src/com/interrupt/dungeoneer/editor/EditorApplication.java @@ -37,6 +37,8 @@ import com.interrupt.dungeoneer.editor.gizmos.Gizmo; import com.interrupt.dungeoneer.editor.gizmos.GizmoProvider; import com.interrupt.dungeoneer.editor.history.EditorHistory; +import com.interrupt.dungeoneer.editor.selection.AdjacentTileSelectionInfo; +import com.interrupt.dungeoneer.editor.selection.TileSelectionInfo; import com.interrupt.dungeoneer.editor.ui.EditorUi; import com.interrupt.dungeoneer.editor.ui.TextureRegionPicker; import com.interrupt.dungeoneer.entities.*; @@ -266,10 +268,7 @@ public boolean isWestFloor() { private boolean selected = false; private boolean tileDragging = false; - private int selectionX = 0; - private int selectionY = 0; - private int selectionWidth = 1; - private int selectionHeight = 1; + private Vector2 selectionHeights = new Vector2(); private boolean vertexSelectionMode = false; @@ -289,7 +288,7 @@ public boolean isWestFloor() { protected Pool decalPool = new Pool(128) { @Override protected Decal newObject () { - return Decal.newDecal(1, 1, editorSprites[0]); + return Decal.newDecal(1, 1, editorSprites[0]); } }; protected Array usedDecals = new Array(256); @@ -714,22 +713,23 @@ else if(e == Editor.selection.hovered) { Ray ray = camera.getPickRay(Gdx.input.getX(), Gdx.input.getY()); Vector3 start = tempVec1.set(ray.origin); Vector3 end = tempVec2.set(intpos.x, intpos.y, intpos.z); - Float distance = start.sub(end).len(); + float distance = start.sub(end).len(); end = ray.getEndPoint(rayOutVector, distance + 0.005f); - selectionX = (int)end.x; - selectionY = (int)end.z; + // TODO: Tile selection bounding + Editor.selection.tiles.x = (int)end.x; + Editor.selection.tiles.y = (int)end.z; - if(selectionX < 0) selectionX = 0; - if(selectionX >= level.width) selectionX = level.width - 1; + if(Editor.selection.tiles.x < 0) Editor.selection.tiles.x = 0; + if(Editor.selection.tiles.x >= level.width) Editor.selection.tiles.x = level.width - 1; - if(selectionY < 0) selectionY = 0; - if(selectionY >= level.height) selectionY = level.height - 1; + if(Editor.selection.tiles.y < 0) Editor.selection.tiles.y = 0; + if(Editor.selection.tiles.y >= level.height) Editor.selection.tiles.y = level.height - 1; - selectionWidth = selectionHeight = 1; - selStartX = selectionX; - selStartY = selectionY; + Editor.selection.tiles.width = Editor.selection.tiles.height = 1; + selStartX = Editor.selection.tiles.x; + selStartY = Editor.selection.tiles.y; controlPoints.clear(); } else if(editorInput.isButtonPressed(Input.Buttons.LEFT)) { @@ -747,22 +747,22 @@ else if(pickedSurface.tileSurface == TileSurface.Ceiling) { movingControlPoint = true; } else { - Intersector.intersectRayPlane(camera.getPickRay(Gdx.input.getX(), Gdx.input.getY()), p, intpos); if (pickedControlPoint != null || movingControlPoint) { // don't modify selection area! movingControlPoint = true; } else { + // TODO: Updating tile selection // The user is dragging the selection area to set its size. Update the selection area based on their mouse position. int newX = MathUtils.clamp((int) intpos.x, 0, level.width - 1); int newY = MathUtils.clamp((int) intpos.z, 0, level.height - 1); - selectionWidth = Math.abs(selStartX - newX) + 1; - selectionHeight = Math.abs(selStartY - newY) + 1; + Editor.selection.tiles.width = Math.abs(selStartX - newX) + 1; + Editor.selection.tiles.height = Math.abs(selStartY - newY) + 1; // Always make this the lowest corner so that the selection size, which is relative to this, is positive. - selectionX = Math.min(newX, selStartX); - selectionY = Math.min(newY, selStartY); + Editor.selection.tiles.x = Math.min(newX, selStartX); + Editor.selection.tiles.y = Math.min(newY, selStartY); controlPoints.clear(); } @@ -780,10 +780,10 @@ else if(pickedSurface.tileSurface == TileSurface.Ceiling) { GlRenderer.bindTexture(selectionTex); - int scaleWidth = selectionWidth; - int scaleHeight = selectionHeight; - int selX = selectionX; - int selY = selectionY; + int scaleWidth = Editor.selection.tiles.width; + int scaleHeight = Editor.selection.tiles.height; + int selX = Editor.selection.tiles.x; + int selY = Editor.selection.tiles.y; Tile t = level.getTileOrNull(selX,selY); if(t!= null && !t.renderSolid) { @@ -894,12 +894,12 @@ else if (dragMode == DragMode.Y) // drag tile if(selected && (!readLeftClick || movingControlPoint)) { - int selX = selectionX; - int selY = selectionY; - int selWidth = selectionWidth; - int selHeight = selectionHeight; + int selX = Editor.selection.tiles.x; + int selY = Editor.selection.tiles.y; + int selWidth = Editor.selection.tiles.width; + int selHeight = Editor.selection.tiles.height; - Tile startTile = level.getTile(selectionX, selectionY); + Tile startTile = Editor.selection.tiles.first(); // init the control point list if needed if(controlPoints.size == 0) { @@ -932,31 +932,29 @@ else if (dragMode == DragMode.Y) controlPoints.add(new ControlPoint(eastEdgeFloor, ControlPointType.eastFloor)); } else { - for(int xx = selX; xx < selX + selWidth; xx++) { - for(int yy = selY; yy < selY + selHeight; yy++) { - Tile current = level.getTileOrNull(xx, yy); - - if(current != null && !current.renderSolid) { - if(current.tileSpaceType != TileSpaceType.OPEN_SE) { - controlPoints.add(new ControlPoint(new Vector3(xx, current.ceilHeight + current.ceilSlopeNE, yy), new ControlPointVertex(current,ControlVertex.ceilNE))); - controlPoints.add(new ControlPoint(new Vector3(xx, current.floorHeight + current.slopeNE, yy), new ControlPointVertex(current,ControlVertex.slopeNE))); - } - - if(current.tileSpaceType != TileSpaceType.OPEN_SW) { - controlPoints.add(new ControlPoint(new Vector3(xx + 1, current.ceilHeight + current.ceilSlopeNW, yy), new ControlPointVertex(current,ControlVertex.ceilNW))); - controlPoints.add(new ControlPoint(new Vector3(xx + 1, current.floorHeight + current.slopeNW, yy), new ControlPointVertex(current,ControlVertex.slopeNW))); - } - - if(current.tileSpaceType != TileSpaceType.OPEN_NE) { - controlPoints.add(new ControlPoint(new Vector3(xx, current.ceilHeight + current.ceilSlopeSE, yy + 1), new ControlPointVertex(current,ControlVertex.ceilSE))); - controlPoints.add(new ControlPoint(new Vector3(xx, current.floorHeight + current.slopeSE, yy + 1), new ControlPointVertex(current,ControlVertex.slopeSE))); - } - - if(current.tileSpaceType != TileSpaceType.OPEN_NW) { - controlPoints.add(new ControlPoint(new Vector3(xx + 1, current.ceilHeight + current.ceilSlopeSW, yy + 1), new ControlPointVertex(current,ControlVertex.ceilSW))); - controlPoints.add(new ControlPoint(new Vector3(xx + 1, current.floorHeight + current.slopeSW, yy + 1), new ControlPointVertex(current,ControlVertex.slopeSW))); - } - } + for (TileSelectionInfo info : Editor.selection.tiles) { + Tile current = info.tile; + + if(current != null && !current.renderSolid) { + if(current.tileSpaceType != TileSpaceType.OPEN_SE) { + controlPoints.add(new ControlPoint(new Vector3(info.x, current.ceilHeight + current.ceilSlopeNE, info.y), new ControlPointVertex(current,ControlVertex.ceilNE))); + controlPoints.add(new ControlPoint(new Vector3(info.x, current.floorHeight + current.slopeNE, info.y), new ControlPointVertex(current,ControlVertex.slopeNE))); + } + + if(current.tileSpaceType != TileSpaceType.OPEN_SW) { + controlPoints.add(new ControlPoint(new Vector3(info.x + 1, current.ceilHeight + current.ceilSlopeNW, info.y), new ControlPointVertex(current,ControlVertex.ceilNW))); + controlPoints.add(new ControlPoint(new Vector3(info.x + 1, current.floorHeight + current.slopeNW, info.y), new ControlPointVertex(current,ControlVertex.slopeNW))); + } + + if(current.tileSpaceType != TileSpaceType.OPEN_NE) { + controlPoints.add(new ControlPoint(new Vector3(info.x, current.ceilHeight + current.ceilSlopeSE, info.y + 1), new ControlPointVertex(current,ControlVertex.ceilSE))); + controlPoints.add(new ControlPoint(new Vector3(info.x, current.floorHeight + current.slopeSE, info.y + 1), new ControlPointVertex(current,ControlVertex.slopeSE))); + } + + if(current.tileSpaceType != TileSpaceType.OPEN_NW) { + controlPoints.add(new ControlPoint(new Vector3(info.x + 1, current.ceilHeight + current.ceilSlopeSW, info.y + 1), new ControlPointVertex(current,ControlVertex.ceilSW))); + controlPoints.add(new ControlPoint(new Vector3(info.x + 1, current.floorHeight + current.slopeSW, info.y + 1), new ControlPointVertex(current,ControlVertex.slopeSW))); + } } } @@ -1052,11 +1050,13 @@ else if (dragMode == DragMode.Y) dragOffset = tempVec2.set(dragStart.x - intpos.x,dragStart.y - intpos.y,dragStart.z - intpos.z); - int selX = selectionX; - int selY = selectionY; - int selWidth = selectionWidth; - int selHeight = selectionHeight; + int selX = Editor.selection.tiles.x; + int selY = Editor.selection.tiles.y; + int selWidth = Editor.selection.tiles.width; + int selHeight = Editor.selection.tiles.height; + // TODO: Tile selection iteration + // TODO: This uses the selection dimensions for(int x = selX; x < selX + selWidth; x++) { for(int y = selY; y < selY + selHeight; y++) { Tile t = level.getTileOrNull(x,y); @@ -1790,55 +1790,50 @@ else if(e instanceof BasicTrigger) { } private void drawSlopeLines(int num, boolean edge) { - if(!selected) return; - int selX = selectionX; - int selY = selectionY; - int selWidth = selectionWidth; - int selHeight = selectionHeight; - - for(int x = selX; x < selX + selWidth; x++) { - for(int y = selY; y < selY + selHeight; y++) { - Tile t = level.getTileOrNull(x,y); - if(t != null) { - if(edge) { - if(num == 0) - drawLine(tempVec1.set(x, t.getNEFloorHeight(), y), tempVec2.set(x + 1, t.getNWFloorHeight(), y), 4f, Color.WHITE); - else if(num == 1) - drawLine(tempVec1.set(x, t.getNEFloorHeight(), y), tempVec2.set(x, t.getSEFloorHeight(), y + 1), 4f, Color.WHITE); - else if(num == 2) - drawLine(tempVec1.set(x, t.getSEFloorHeight(), y + 1), tempVec2.set(x + 1, t.getSWFloorHeight(), y + 1), 4f, Color.WHITE); - else if(num == 3) - drawLine(tempVec1.set(x + 1, t.getSWFloorHeight(), y + 1), tempVec2.set(x + 1, t.getNWFloorHeight(), y), 4f, Color.WHITE); - else if(num == 4) - drawLine(tempVec1.set(x, t.getNECeilHeight(), y), tempVec2.set(x + 1, t.getNWCeilHeight(), y), 4f, Color.WHITE); - else if(num == 5) - drawLine(tempVec1.set(x, t.getNECeilHeight(), y), tempVec2.set(x, t.getSECeilHeight(), y + 1), 4f, Color.WHITE); - else if(num == 6) - drawLine(tempVec1.set(x, t.getSECeilHeight(), y + 1), tempVec2.set(x + 1, t.getSWCeilHeight(), y + 1), 4f, Color.WHITE); - else - drawLine(tempVec1.set(x + 1, t.getSWCeilHeight(), y + 1), tempVec2.set(x + 1, t.getNWCeilHeight(), y), 4f, Color.WHITE); - } - else { - if(num == 1) - drawPoint(tempVec1.set(x, t.getNEFloorHeight(), y), 6f, Color.WHITE); - else if(num == 0) - drawPoint(tempVec1.set(x + 1, t.getNWFloorHeight(), y), 6f, Color.WHITE); - else if(num == 2) - drawPoint(tempVec1.set(x, t.getSEFloorHeight(), y + 1), 6f, Color.WHITE); - else if(num == 3) - drawPoint(tempVec1.set(x + 1, t.getSWFloorHeight(), y + 1), 6f, Color.WHITE); - else if(num == 4) - drawPoint(tempVec1.set(x + 1, t.getNECeilHeight(), y), 6f, Color.WHITE); - else if(num == 5) - drawPoint(tempVec1.set(x, t.getNWCeilHeight(), y), 6f, Color.WHITE); - else if(num == 6) - drawPoint(tempVec1.set(x, t.getSECeilHeight(), y + 1), 6f, Color.WHITE); - else - drawPoint(tempVec1.set(x + 1, t.getSWCeilHeight(), y + 1), 6f, Color.WHITE); - } - } + for (TileSelectionInfo info : Editor.selection.tiles) { + Tile t = info.tile; + int x = info.x; + int y = info.y; + + if (t != null) { + if(edge) { + if(num == 0) + drawLine(tempVec1.set(x, t.getNEFloorHeight(), y), tempVec2.set(x + 1, t.getNWFloorHeight(), y), 4f, Color.WHITE); + else if(num == 1) + drawLine(tempVec1.set(x, t.getNEFloorHeight(), y), tempVec2.set(x, t.getSEFloorHeight(), y + 1), 4f, Color.WHITE); + else if(num == 2) + drawLine(tempVec1.set(x, t.getSEFloorHeight(), y + 1), tempVec2.set(x + 1, t.getSWFloorHeight(), y + 1), 4f, Color.WHITE); + else if(num == 3) + drawLine(tempVec1.set(x + 1, t.getSWFloorHeight(), y + 1), tempVec2.set(x + 1, t.getNWFloorHeight(), y), 4f, Color.WHITE); + else if(num == 4) + drawLine(tempVec1.set(x, t.getNECeilHeight(), y), tempVec2.set(x + 1, t.getNWCeilHeight(), y), 4f, Color.WHITE); + else if(num == 5) + drawLine(tempVec1.set(x, t.getNECeilHeight(), y), tempVec2.set(x, t.getSECeilHeight(), y + 1), 4f, Color.WHITE); + else if(num == 6) + drawLine(tempVec1.set(x, t.getSECeilHeight(), y + 1), tempVec2.set(x + 1, t.getSWCeilHeight(), y + 1), 4f, Color.WHITE); + else + drawLine(tempVec1.set(x + 1, t.getSWCeilHeight(), y + 1), tempVec2.set(x + 1, t.getNWCeilHeight(), y), 4f, Color.WHITE); + } + else { + if(num == 1) + drawPoint(tempVec1.set(x, t.getNEFloorHeight(), y), 6f, Color.WHITE); + else if(num == 0) + drawPoint(tempVec1.set(x + 1, t.getNWFloorHeight(), y), 6f, Color.WHITE); + else if(num == 2) + drawPoint(tempVec1.set(x, t.getSEFloorHeight(), y + 1), 6f, Color.WHITE); + else if(num == 3) + drawPoint(tempVec1.set(x + 1, t.getSWFloorHeight(), y + 1), 6f, Color.WHITE); + else if(num == 4) + drawPoint(tempVec1.set(x + 1, t.getNECeilHeight(), y), 6f, Color.WHITE); + else if(num == 5) + drawPoint(tempVec1.set(x, t.getNWCeilHeight(), y), 6f, Color.WHITE); + else if(num == 6) + drawPoint(tempVec1.set(x, t.getSECeilHeight(), y + 1), 6f, Color.WHITE); + else + drawPoint(tempVec1.set(x + 1, t.getSWCeilHeight(), y + 1), 6f, Color.WHITE); + } } } } @@ -1933,7 +1928,7 @@ public void create() { Tile t = new Tile(); t.floorHeight = -0.5f; t.ceilHeight = 0.5f; - level.setTile(7, 7, t); + //level.setTile(0, 1, t); gridMesh = genGrid(level.width,level.height); } @@ -2088,8 +2083,7 @@ public void tick() { } if(Gdx.input.isKeyJustPressed(Keys.TAB)) { - Editor.selection.picked = null; - Editor.selection.hovered = null; + Editor.selection.clear(); } // Try to pick an entity @@ -2166,7 +2160,7 @@ else if(turnDown) { } rotY += rotya; - + if (rotY < -rotYClamp) rotY = -rotYClamp; if (rotY > rotYClamp) rotY = rotYClamp; @@ -2354,7 +2348,7 @@ public void clearSelection() { else { clearEntitySelection(); } - + if (ui.isShowingContextMenu()) { ui.hideContextMenu(); } @@ -2849,20 +2843,13 @@ private Color getColor(int r, int g, int b, int a) { } public void addEntityMarker(Markers selectedItem) { - int selX = selectionX; - int selY = selectionY; - int selWidth = selectionWidth; - int selHeight = selectionHeight; - clearSelectedMarkers(); if(selectedItem != Markers.none) { - for(int x = selX; x < selX + selWidth; x++) { - for(int y = selY; y < selY + selHeight; y++) { - EditorMarker eM = new EditorMarker(selectedItem, x, y); - level.editorMarkers.add(eM); - markWorldAsDirty(x, y, 4); - } + for (TileSelectionInfo info : Editor.selection.tiles) { + EditorMarker eM = new EditorMarker(selectedItem, info.x, info.y); + level.editorMarkers.add(eM); + markWorldAsDirty(info.x, info.y, 4); } } @@ -2870,13 +2857,8 @@ public void addEntityMarker(Markers selectedItem) { } public boolean selectionHasEntityMarker() { - int selX = selectionX; - int selY = selectionY; - int selWidth = selectionWidth; - int selHeight = selectionHeight; - for(EditorMarker marker : level.editorMarkers) { - if(marker.x >= selX && marker.x < selX + selWidth && marker.y >= selY && marker.y < selY + selHeight) return true; + if (Editor.selection.tiles.contains(marker.x, marker.y)) return true; } return false; @@ -2888,33 +2870,28 @@ public void addEntity(Entity e) { markWorldAsDirty((int)e.x, (int)e.y, 4); } - public void clearSelectedMarkers() { - int selX = selectionX; - int selY = selectionY; - int selWidth = selectionWidth; - int selHeight = selectionHeight; - - for(int x = selX; x < selX + selWidth; x++) { - for(int y = selY; y < selY + selHeight; y++) { - if(level.editorMarkers != null && level.editorMarkers.size > 0) { - Array toDelete = new Array(); + public void clearSelectedMarkers() { + if (level.editorMarkers == null || level.editorMarkers.size == 0) { + return; + } - for(int i = 0; i < level.editorMarkers.size; i++) { - EditorMarker m = level.editorMarkers.get(i); - if(m.x == x && m.y == y) toDelete.add(m); - } + for (TileSelectionInfo info : Editor.selection.tiles) { + Array toDelete = new Array(); + for (EditorMarker m : level.editorMarkers) { + if (m.x == info.x && m.y == info.y) { + toDelete.add(m); + } + } - if(toDelete.size > 0) { - markWorldAsDirty(x, y, 4); - } + if (toDelete.size > 0) { + markWorldAsDirty(info.x, info.y, 4); + } - for(EditorMarker m : toDelete) { - level.editorMarkers.removeValue(m, true); - } - } - } - } - } + for (EditorMarker m : toDelete) { + level.editorMarkers.removeValue(m, true); + } + } + } public void refresh() { gridMesh.dispose(); @@ -2972,254 +2949,156 @@ else if(entity instanceof ProjectedDecal) { } public void setTile(Tile tocopy) { - int selX = selectionX; - int selY = selectionY; - int selWidth = selectionWidth; - int selHeight = selectionHeight; - - Tile selected = level.getTile(selectionX, selectionY); - - for(int x = selX; x < selX + selWidth; x++) { - for(int y = selY; y < selY + selHeight; y++) { - Tile t = level.getTileOrNull(x, y); - - if(t == null) { - t = new Tile(); - } + // Selected tiles. + for (TileSelectionInfo info : Editor.selection.tiles) { + Tile t = info.tile; + if (t == null) { + t = new Tile(); + } - Tile.copy(tocopy, t); - level.setTile(x, y, t); + Tile.copy(tocopy, t); + level.setTile(info.x, info.y, t); - t.eastTex = t.westTex = t.northTex = t.southTex = null; - t.bottomEastTex = t.bottomWestTex = t.bottomNorthTex = t.bottomSouthTex = null; + t.eastTex = t.westTex = t.northTex = t.southTex = null; + t.bottomEastTex = t.bottomWestTex = t.bottomNorthTex = t.bottomSouthTex = null; - markWorldAsDirty(x, y, 1); - } - } + markWorldAsDirty(info.x, info.y, 1); + } - // Paint directional tiless - if(paintAdjacent.isChecked()) { - if (selY - 1 >= 0) { - for (int x = selX; x < selX + selWidth; x++) { - int y = selY - 1; - Tile t = level.getTileOrNull(x, y); + if(!paintAdjacent.isChecked()) { + return; + } - if (t == null) { - t = new Tile(); - t.blockMotion = true; - t.renderSolid = true; - level.setTile(x, y, t); - } - t.southTex = tocopy.wallTex; - t.southTexAtlas = tocopy.wallTexAtlas; - t.bottomSouthTex = tocopy.wallBottomTex; - t.bottomSouthTexAtlas = tocopy.wallBottomTexAtlas; - } + // Adjacent tiles. + for (AdjacentTileSelectionInfo info : Editor.selection.tiles.adjacent) { + Tile t = info.tile; + if (t == null) { + t = new Tile(); + t.blockMotion = true; + t.renderSolid = true; + level.setTile(info.x, info.y, t); } - if (selY + selHeight < level.height) { - for (int x = selX; x < selX + selWidth; x++) { - int y = selY + selHeight; - Tile t = level.getTileOrNull(x, y); - - if (t == null) { - t = new Tile(); - t.blockMotion = true; - t.renderSolid = true; - level.setTile(x, y, t); - } + switch (info.dir) { + case NORTH: t.northTex = tocopy.wallTex; t.northTexAtlas = tocopy.wallTexAtlas; t.bottomNorthTex = tocopy.wallBottomTex; t.bottomNorthTexAtlas = tocopy.wallBottomTexAtlas; - } - } - - if (selX - 1 >= 0) { - for (int y = selY; y < selY + selHeight; y++) { - int x = selX - 1; - Tile t = level.getTileOrNull(x, y); + break; - if (t == null) { - t = new Tile(); - t.blockMotion = true; - t.renderSolid = true; - level.setTile(x, y, t); - } - t.westTex = tocopy.wallTex; - t.westTexAtlas = tocopy.wallTexAtlas; - t.bottomWestTex = tocopy.wallBottomTex; - t.bottomWestTexAtlas = tocopy.wallBottomTexAtlas; - } - } - - if (selX + selWidth < level.width) { - for (int y = selY; y < selY + selHeight; y++) { - int x = selX + selWidth; - Tile t = level.getTileOrNull(x, y); + case SOUTH: + t.southTex = tocopy.wallTex; + t.southTexAtlas = tocopy.wallTexAtlas; + t.bottomSouthTex = tocopy.wallBottomTex; + t.bottomSouthTexAtlas = tocopy.wallBottomTexAtlas; + break; - if (t == null) { - t = new Tile(); - t.blockMotion = true; - t.renderSolid = true; - level.setTile(x, y, t); - } + case EAST: t.eastTex = tocopy.wallTex; t.eastTexAtlas = tocopy.wallTexAtlas; t.bottomEastTex = tocopy.wallBottomTex; t.bottomEastTexAtlas = tocopy.wallBottomTexAtlas; - } + break; + + case WEST: + t.westTex = tocopy.wallTex; + t.westTexAtlas = tocopy.wallTexAtlas; + t.bottomWestTex = tocopy.wallBottomTex; + t.bottomWestTexAtlas = tocopy.wallBottomTexAtlas; + break; } } } public void paintTile(Tile tocopy) { - int selX = selectionX; - int selY = selectionY; - int selWidth = selectionWidth; - int selHeight = selectionHeight; - - for(int x = selX; x < selX + selWidth; x++) { - for(int y = selY; y < selY + selHeight; y++) { - Tile t = level.getTileOrNull(x, y); - - if(t != null) { - t.wallTex = tocopy.wallTex; - t.floorTex = tocopy.floorTex; - t.ceilTex = tocopy.ceilTex; - t.wallBottomTex = tocopy.wallBottomTex; - t.wallTexAtlas = tocopy.wallTexAtlas; - t.wallBottomTexAtlas = tocopy.wallBottomTexAtlas; - t.floorTexAtlas = tocopy.floorTexAtlas; - t.ceilTexAtlas = tocopy.ceilTexAtlas; - } - else { - t = new Tile(); - t.wallTex = tocopy.wallTex; - t.wallBottomTex = tocopy.wallBottomTex; - t.floorTex = tocopy.floorTex; - t.ceilTex = tocopy.ceilTex; - t.wallTexAtlas = tocopy.wallTexAtlas; - t.wallBottomTexAtlas = tocopy.wallBottomTexAtlas; - t.floorTexAtlas = tocopy.floorTexAtlas; - t.ceilTexAtlas = tocopy.ceilTexAtlas; - t.blockMotion = true; - t.renderSolid = true; - level.setTile(x, y, t); - } - - t.eastTex = t.westTex = t.northTex = t.southTex = null; - t.eastTexAtlas = t.westTexAtlas = t.northTexAtlas = t.southTexAtlas = null; + for (TileSelectionInfo info : Editor.selection.tiles) { + Tile t = info.tile; + if (t == null) { + t = new Tile(); + t.blockMotion = true; + t.renderSolid = true; + level.setTile(info.x, info.y, t); + } - t.bottomEastTex = t.bottomWestTex = t.bottomNorthTex = t.bottomSouthTex = null; - t.bottomEastTexAtlas = t.bottomWestTexAtlas = t.bottomNorthTexAtlas = t.bottomSouthTexAtlas = null; + t.wallTexAtlas = tocopy.wallTexAtlas; + t.wallTex = tocopy.wallTex; + t.wallBottomTexAtlas = tocopy.wallBottomTexAtlas; + t.wallBottomTex = tocopy.wallBottomTex; + t.floorTex = tocopy.floorTex; + t.floorTexAtlas = tocopy.floorTexAtlas; + t.ceilTex = tocopy.ceilTex; + t.ceilTexAtlas = tocopy.ceilTexAtlas; + t.eastTex = t.westTex = t.northTex = t.southTex = null; + t.eastTexAtlas = t.westTexAtlas = t.northTexAtlas = t.southTexAtlas = null; + t.bottomEastTex = t.bottomWestTex = t.bottomNorthTex = t.bottomSouthTex = null; + t.bottomEastTexAtlas = t.bottomWestTexAtlas = t.bottomNorthTexAtlas = t.bottomSouthTexAtlas = null; - t.init(Source.EDITOR); + t.init(Source.EDITOR); - markWorldAsDirty(x, y, 1); - } + markWorldAsDirty(info.x, info.y, 1); } - if(paintAdjacent.isChecked()) { - if (selY - 1 >= 0) { - for (int x = selX; x < selX + selWidth; x++) { - int y = selY - 1; - Tile t = level.getTileOrNull(x, y); + if(!paintAdjacent.isChecked()) { + return; + } - if (t == null) { - t = new Tile(); - t.blockMotion = true; - t.renderSolid = true; - level.setTile(x, y, t); - } - t.southTex = tocopy.wallTex; - t.southTexAtlas = tocopy.wallTexAtlas; - t.bottomSouthTex = tocopy.wallBottomTex; - t.bottomSouthTexAtlas = tocopy.wallBottomTexAtlas; - } + for (AdjacentTileSelectionInfo info : Editor.selection.tiles.adjacent) { + Tile t = info.tile; + if (t == null) { + t = new Tile(); + t.blockMotion = true; + t.renderSolid = true; + level.setTile(info.x, info.y, t); } - if (selY + selHeight < level.height) { - for (int x = selX; x < selX + selWidth; x++) { - int y = selY + selHeight; - Tile t = level.getTileOrNull(x, y); - - if (t == null) { - t = new Tile(); - t.blockMotion = true; - t.renderSolid = true; - level.setTile(x, y, t); - } + switch (info.dir) { + case NORTH: t.northTex = tocopy.wallTex; t.northTexAtlas = tocopy.wallTexAtlas; t.bottomNorthTex = tocopy.wallBottomTex; t.bottomNorthTexAtlas = tocopy.wallBottomTexAtlas; - } - } - - if (selX - 1 >= 0) { - for (int y = selY; y < selY + selHeight; y++) { - int x = selX - 1; - Tile t = level.getTileOrNull(x, y); - - if (t == null) { - t = new Tile(); - t.blockMotion = true; - t.renderSolid = true; - level.setTile(x, y, t); - } - t.westTex = tocopy.wallTex; - t.westTexAtlas = tocopy.wallTexAtlas; - t.bottomWestTex = tocopy.wallBottomTex; - t.bottomWestTexAtlas = tocopy.wallBottomTexAtlas; - } - } - - if (selX + selWidth < level.width) { - for (int y = selY; y < selY + selHeight; y++) { - int x = selX + selWidth; - Tile t = level.getTileOrNull(x, y); - - if (t == null) { - t = new Tile(); - t.blockMotion = true; - t.renderSolid = true; - level.setTile(x, y, t); - } + break; + case SOUTH: + t.southTex = tocopy.wallTex; + t.southTexAtlas = tocopy.wallTexAtlas; + t.bottomSouthTex = tocopy.wallBottomTex; + t.bottomSouthTexAtlas = tocopy.wallBottomTexAtlas; + break; + case EAST: t.eastTex = tocopy.wallTex; t.eastTexAtlas = tocopy.wallTexAtlas; t.bottomEastTex = tocopy.wallBottomTex; t.bottomEastTexAtlas = tocopy.wallBottomTexAtlas; - } + break; + case WEST: + t.westTex = tocopy.wallTex; + t.westTexAtlas = tocopy.wallTexAtlas; + t.bottomWestTex = tocopy.wallBottomTex; + t.bottomWestTexAtlas = tocopy.wallBottomTexAtlas; + break; } } } public void clearTiles() { - int selX = selectionX; - int selY = selectionY; - int selWidth = selectionWidth; - int selHeight = selectionHeight; - - for(int x = selX; x < selX + selWidth; x++) { - for(int y = selY; y < selY + selHeight; y++) { - Tile n = level.getTile(x, y - 1); - Tile s = level.getTile(x, y + 1); - Tile e = level.getTile(x - 1, y); - Tile w = level.getTile(x + 1, y); - - if(n.blockMotion && s.blockMotion && e.blockMotion && w.blockMotion) { - level.setTile(x, y, null); - } - else { - Tile t = Tile.NewSolidTile(); - t.wallTex = (byte)pickedWallTexture; - t.wallTexAtlas = pickedWallTextureAtlas; - level.setTile(x, y, t); - } + for (TileSelectionInfo info : Editor.selection.tiles) { + Tile n = level.getTile(info.x, info.y - 1); + Tile s = level.getTile(info.x, info.y + 1); + Tile e = level.getTile(info.x - 1, info.y); + Tile w = level.getTile(info.x + 1, info.y); + + if(n.blockMotion && s.blockMotion && e.blockMotion && w.blockMotion) { + level.setTile(info.x, info.y, null); + } + else { + Tile t = Tile.NewSolidTile(); + t.wallTex = (byte)pickedWallTexture; + t.wallTexAtlas = pickedWallTextureAtlas; + level.setTile(info.x, info.y, t); + } - markWorldAsDirty(x, y, 1); - } + markWorldAsDirty(info.x, info.y, 1); } clearSelectedMarkers(); @@ -3228,21 +3107,14 @@ public void clearTiles() { public void rotateFloorTex(int value) { if(Editor.selection.picked != null) return; - int selX = selectionX; - int selY = selectionY; - int selWidth = selectionWidth; - int selHeight = selectionHeight; - - for(int x = selX; x < selX + selWidth; x++) { - for(int y = selY; y < selY + selHeight; y++) { - Tile t = level.getTileOrNull(x,y); - if(t != null) { - t.floorTexRot += value; - t.floorTexRot %= 4; - } + for (TileSelectionInfo info : Editor.selection.tiles) { + Tile t = info.tile; + if (t != null) { + t.floorTexRot += value; + t.floorTexRot %= 4; + } - markWorldAsDirty(x, y, 1); - } + markWorldAsDirty(info.x, info.y, 1); } } @@ -3274,10 +3146,11 @@ public void copy() { } } - int selX = selectionX; - int selY = selectionY; - int selWidth = selectionWidth; - int selHeight = selectionHeight; + // TODO: Clipboard support? + int selX = Editor.selection.tiles.x; + int selY = Editor.selection.tiles.y; + int selWidth = Editor.selection.tiles.width; + int selHeight = Editor.selection.tiles.height; if(Editor.selection.picked == null) { clipboard.tiles = new Tile[selWidth][selHeight]; @@ -3285,13 +3158,12 @@ public void copy() { clipboard.selHeight = selHeight; clipboard.offset = new Vector3(selX, selY, 0); - for (int x = selX; x < selX + selWidth; x++) { - for (int y = selY; y < selY + selHeight; y++) { - Tile t = level.getTileOrNull(x, y); - - if(t != null) t = (Tile) KryoSerializer.copyObject(t); - clipboard.tiles[x - selX][y - selY] = t; + for (TileSelectionInfo info : Editor.selection.tiles) { + Tile t = info.tile; + if (t != null) { + t = (Tile) KryoSerializer.copyObject(t); } + clipboard.tiles[info.x - selX][info.y - selY] = t; } } else { @@ -3313,9 +3185,10 @@ public void paste() { catch (Exception ignored) {} if(clipboard != null) { - int selX = selectionX; - int selY = selectionY; + int selX = Editor.selection.tiles.x; + int selY = Editor.selection.tiles.y; + // TODO: Update clipboard to have a TileSelection? for(int x = 0; x < clipboard.selWidth; x++) { for(int y = 0; y < clipboard.selHeight; y++) { if(clipboard.tiles[x][y] == null) @@ -3351,78 +3224,56 @@ public void paste() { public void rotateAngle() { if(Editor.selection.picked != null) return; - int selX = selectionX; - int selY = selectionY; - int selWidth = selectionWidth; - int selHeight = selectionHeight; - - for(int x = selX; x < selX + selWidth; x++) { - for(int y = selY; y < selY + selHeight; y++) { - Tile t = level.getTileOrNull(x,y); - if(t != null) { - t.blockMotion = false; - t.renderSolid = false; - t.tileSpaceType = TileSpaceType.values()[(t.tileSpaceType.ordinal() + 1) % TileSpaceType.values().length]; - } + for (TileSelectionInfo info : Editor.selection.tiles) { + Tile t = info.tile; + if (t != null) { + t.blockMotion = false; + t.renderSolid = false; + t.tileSpaceType = TileSpaceType.values()[(t.tileSpaceType.ordinal() + 1) % TileSpaceType.values().length]; + } - markWorldAsDirty(x, y, 1); - } + markWorldAsDirty(info.x, info.y, 1); } } - public void rotateCeilTex(int value) { - if(Editor.selection.picked != null) return; - - int selX = selectionX; - int selY = selectionY; - int selWidth = selectionWidth; - int selHeight = selectionHeight; + public void rotateCeilTex(int value) { + if(Editor.selection.picked != null) return; - for(int x = selX; x < selX + selWidth; x++) { - for(int y = selY; y < selY + selHeight; y++) { - Tile t = level.getTileOrNull(x,y); - if(t != null) { - t.ceilTexRot += value; - t.ceilTexRot %= 4; - } + for (TileSelectionInfo info : Editor.selection.tiles) { + Tile t = info.tile; + if (t != null) { + t.ceilTexRot += value; + t.ceilTexRot %= 4; + } - markWorldAsDirty(x, y, 1); - } - } - } + markWorldAsDirty(info.x, info.y, 1); + } + } public void moveFloor(int value) { - int selX = selectionX; - int selY = selectionY; - int selWidth = selectionWidth; - int selHeight = selectionHeight; - - for(int x = selX; x < selX + selWidth; x++) { - for(int y = selY; y < selY + selHeight; y++) { - Tile t = level.getTileOrNull(x,y); - if(t != null) - t.floorHeight += (value * 0.0625f); - - markWorldAsDirty(x, y, 1); - } - } + if(Editor.selection.picked != null) return; + + for (TileSelectionInfo info : Editor.selection.tiles) { + Tile t = info.tile; + if (t != null) { + t.floorHeight += (value * 0.0625f); + } + + markWorldAsDirty(info.x, info.y, 1); + } } public void moveCeiling(int value) { - int selX = selectionX; - int selY = selectionY; - int selWidth = selectionWidth; - int selHeight = selectionHeight; - - for(int x = selX; x < selX + selWidth; x++) { - for(int y = selY; y < selY + selHeight; y++) { - Tile t = level.getTileOrNull(x,y); - if(t != null) - t.ceilHeight += (value * 0.0625f); - - markWorldAsDirty(x, y, 1); - } - } + if(Editor.selection.picked != null) return; + + for (TileSelectionInfo info : Editor.selection.tiles) { + Tile t = info.tile; + if (t != null) { + t.ceilHeight += (value * 0.0625f); + } + + markWorldAsDirty(info.x, info.y, 1); + } } public void doFloorMoveUp() { @@ -3464,10 +3315,7 @@ public void updatePickedSurface() { pickedSurface.position.set(t_pickerVector); pickedSurface.isPicked = true; - Tile t = level.getTileOrNull((int)pickedSurface.position.x, (int)pickedSurface.position.z); - if(t == null) { - t = Tile.solidWall; - } + Tile t = level.getTile((int)pickedSurface.position.x, (int)pickedSurface.position.z); float floorHeight = t.getFloorHeight(pickedSurface.position.x, pickedSurface.position.z); float ceilHeight = t.getCeilHeight(pickedSurface.position.x, pickedSurface.position.z); @@ -3942,7 +3790,7 @@ public void doCarve() { t.tileSpaceType = TileSpaceType.EMPTY; t.renderSolid = t.blockMotion; - Tile selectedTile = level.getTile(selectionX, selectionY); + Tile selectedTile = Editor.selection.tiles.first(); t.floorHeight = selectedTile.floorHeight; t.ceilHeight = selectedTile.ceilHeight; @@ -3976,7 +3824,7 @@ public void doPaint() { t.tileSpaceType = TileSpaceType.EMPTY; t.renderSolid = t.blockMotion; - Tile selectedTile = level.getTile(selectionX, selectionY); + Tile selectedTile = Editor.selection.tiles.first(); t.floorHeight = selectedTile.floorHeight; t.ceilHeight = selectedTile.ceilHeight; @@ -4012,7 +3860,7 @@ public void doDelete() { } public void doPick() { - Tile t = level.getTile(selectionX, selectionY); + Tile t = Editor.selection.tiles.first(); if(t != null) { setPickedWallTexture(t.wallTex, t.wallTexAtlas); setPickedCeilingTexture(t.ceilTex, t.ceilTexAtlas); @@ -4022,42 +3870,32 @@ public void doPick() { } public void flattenFloor() { - int selX = selectionX; - int selY = selectionY; - int selWidth = selectionWidth; - int selHeight = selectionHeight; - - float matchFloorHeight = level.getTile(selectionX, selectionY).floorHeight; - for(int x = selX; x < selX + selWidth; x++) { - for(int y = selY; y < selY + selHeight; y++) { - Tile t = level.getTileOrNull(x, y); - if(t != null) { - t.floorHeight = matchFloorHeight; - t.slopeNE = t.slopeNW = t.slopeSE = t.slopeSW = 0; - } + if(Editor.selection.picked != null) return; - markWorldAsDirty(x, y, 1); + float matchFloorHeight = Editor.selection.tiles.first().floorHeight; + for (TileSelectionInfo info : Editor.selection.tiles) { + Tile t = info.tile; + if (t != null) { + t.floorHeight = matchFloorHeight; + t.slopeNE = t.slopeNW = t.slopeSE = t.slopeSW = 0; } + + markWorldAsDirty(info.x, info.y, 1); } } public void flattenCeiling() { - int selX = selectionX; - int selY = selectionY; - int selWidth = selectionWidth; - int selHeight = selectionHeight; - - float matchCeilHeight = level.getTile(selectionX, selectionY).ceilHeight; - for(int x = selX; x < selX + selWidth; x++) { - for(int y = selY; y < selY + selHeight; y++) { - Tile t = level.getTileOrNull(x, y); - if(t != null) { - t.ceilHeight = matchCeilHeight; - t.ceilSlopeNE = t.ceilSlopeNW = t.ceilSlopeSE = t.ceilSlopeSW = 0; - } + if(Editor.selection.picked != null) return; - markWorldAsDirty(x, y, 1); + float matchCeilHeight = Editor.selection.tiles.first().ceilHeight; + for (TileSelectionInfo info : Editor.selection.tiles) { + Tile t = info.tile; + if (t != null) { + t.ceilHeight = matchCeilHeight; + t.ceilSlopeNE = t.ceilSlopeNW = t.ceilSlopeSE = t.ceilSlopeSW = 0; } + + markWorldAsDirty(info.x, info.y, 1); } } @@ -4098,10 +3936,11 @@ else if (selected) { float floor = selectionHeights.y; float tileHeight = ceiling - floor; - Vector3 size = new Vector3(selectionWidth, tileHeight, selectionHeight); + // TODO: Selection bounds + Vector3 size = new Vector3(Editor.selection.tiles.width, tileHeight, Editor.selection.tiles.height); orbitDistance = size.len(); - selectedPosition.set(selectionX + (selectionWidth / 2f), selectionY + (selectionWidth / 2f), floor + tileHeight / 2f); + selectedPosition.set(Editor.selection.tiles.x + (Editor.selection.tiles.width / 2f), Editor.selection.tiles.y + (Editor.selection.tiles.width / 2f), floor + tileHeight / 2f); } Vector3 cameraOffset = new Vector3(camera.direction.x,camera.direction.z,camera.direction.y).scl(orbitDistance); @@ -4157,8 +3996,8 @@ public void clearEntitySelection() { selected = false; tileDragging = false; - selectionHeight = 1; - selectionWidth = 1; + Editor.selection.tiles.height = 1; + Editor.selection.tiles.width = 1; Editor.selection.picked = null; Editor.selection.selected.clear(); @@ -4183,18 +4022,18 @@ public void pickAdditionalEntity(Entity entity) { public Level getLevel() { return level; } public int getSelectionX() { - return selectionX; + return Editor.selection.tiles.x; } public int getSelectionY() { - return selectionY; + return Editor.selection.tiles.y; } public Vector3 getIntersection() { if(pickedSurface.isPicked) return new Vector3(intpos); - float floorPos = level.getTile(selectionX, selectionY).floorHeight; + float floorPos = Editor.selection.tiles.first().floorHeight; return new Vector3(getSelectionX(), floorPos, getSelectionY()); } @@ -4261,10 +4100,11 @@ public Decal getDecal() { } public void moveTiles(int moveX, int moveY, float moveZ) { - int selX = selectionX; - int selY = selectionY; - int selWidth = selectionWidth; - int selHeight = selectionHeight; + // TODO: Possibly refactor here? + int selX = Editor.selection.tiles.x; + int selY = Editor.selection.tiles.y; + int selWidth = Editor.selection.tiles.width; + int selHeight = Editor.selection.tiles.height; // Move Tiles if(selected) { @@ -4276,7 +4116,7 @@ public void moveTiles(int moveX, int moveY, float moveZ) { int tileY = selY + y; Tile t = level.getTileOrNull(tileX, tileY); - moving[x + y * selectionWidth] = t; + moving[x + y * Editor.selection.tiles.width] = t; level.setTile(tileX, tileY, null); markWorldAsDirty(tileX, tileY, 1); @@ -4288,7 +4128,7 @@ public void moveTiles(int moveX, int moveY, float moveZ) { int tileX = selX + x + moveX; int tileY = selY + y + moveY; - Tile t = moving[x + y * selectionWidth]; + Tile t = moving[x + y * Editor.selection.tiles.width]; if(moveZ != 0 && t != null) { t.floorHeight += moveZ; @@ -4316,8 +4156,8 @@ public void moveTiles(int moveX, int moveY, float moveZ) { } } - selectionX += moveX; - selectionY += moveY; + Editor.selection.tiles.x += moveX; + Editor.selection.tiles.y += moveY; selectionHeights.add(moveZ, moveZ); controlPoints.clear(); diff --git a/DelvEdit/src/com/interrupt/dungeoneer/editor/selection/AdjacentTileSelectionInfo.java b/DelvEdit/src/com/interrupt/dungeoneer/editor/selection/AdjacentTileSelectionInfo.java new file mode 100644 index 00000000..50c7874b --- /dev/null +++ b/DelvEdit/src/com/interrupt/dungeoneer/editor/selection/AdjacentTileSelectionInfo.java @@ -0,0 +1,24 @@ +package com.interrupt.dungeoneer.editor.selection; + +import com.interrupt.dungeoneer.tiles.Tile; + +public class AdjacentTileSelectionInfo { + public enum AdjacencyDirection { + NORTH, + SOUTH, + EAST, + WEST + } + + public int x; + public int y; + public Tile tile; + public AdjacencyDirection dir; + + public AdjacentTileSelectionInfo(int x, int y, Tile tile, AdjacencyDirection direction) { + this.x = x; + this.y = y; + this.tile = tile; + this.dir = direction; + } +} diff --git a/DelvEdit/src/com/interrupt/dungeoneer/editor/selection/EditorSelection.java b/DelvEdit/src/com/interrupt/dungeoneer/editor/selection/EditorSelection.java index de1307d0..aeebb724 100644 --- a/DelvEdit/src/com/interrupt/dungeoneer/editor/selection/EditorSelection.java +++ b/DelvEdit/src/com/interrupt/dungeoneer/editor/selection/EditorSelection.java @@ -8,19 +8,20 @@ public class EditorSelection { public Entity hovered; public Entity picked; public Array selected; - //public TileSelection tiles; + public TileSelection tiles; public EditorSelection() { hovered = null; picked = null; selected = new Array(); - //tiles = new TileSelection(); + tiles = new TileSelection(); } public void clear() { hovered = null; picked = null; selected.clear(); + tiles.clear(); } public boolean isSelected(Entity e) { diff --git a/DelvEdit/src/com/interrupt/dungeoneer/editor/selection/TileSelection.java b/DelvEdit/src/com/interrupt/dungeoneer/editor/selection/TileSelection.java index 98137c1e..b171526c 100644 --- a/DelvEdit/src/com/interrupt/dungeoneer/editor/selection/TileSelection.java +++ b/DelvEdit/src/com/interrupt/dungeoneer/editor/selection/TileSelection.java @@ -1,4 +1,101 @@ package com.interrupt.dungeoneer.editor.selection; -public class TileSelection { +import com.badlogic.gdx.utils.Array; +import com.interrupt.dungeoneer.editor.Editor; +import com.interrupt.dungeoneer.game.Level; +import com.interrupt.dungeoneer.tiles.Tile; + +import java.util.Iterator; + +/** Class representing a collection of Tile objects. */ +public class TileSelection implements Iterable{ + public int x; + public int y; + public int width; + public int height; + + /** A collection of tiles that are adjacent to the selection. */ + public Iterable adjacent; + + public TileSelection() { + clear(); + + final TileSelection self = this; + adjacent = new Iterable() { + @Override + public Iterator iterator() { + Level level = Editor.app.getLevel(); + + Array result = new Array(); + + // South + if (self.y - 1 >= 0) { + int j = self.y - 1; + for (int i = self.x; i < self.x + self.width; i++) { + Tile t = level.getTileOrNull(i, j); + result.add(new AdjacentTileSelectionInfo(i, j, t, AdjacentTileSelectionInfo.AdjacencyDirection.SOUTH)); + } + } + + // North + if (self.y + self.height < level.height) { + int j = self.y + self.height; + for (int i = self.x; i < self.x + self.width; i++) { + Tile t = level.getTileOrNull(i, j); + result.add(new AdjacentTileSelectionInfo(i, j, t, AdjacentTileSelectionInfo.AdjacencyDirection.NORTH)); + } + } + + // West + if (self.x - 1 >= 0) { + int i = self.x - 1; + for (int j = self.y; j < self.y + self.height; j++) { + Tile t = level.getTileOrNull(i, j); + result.add(new AdjacentTileSelectionInfo(i, j, t, AdjacentTileSelectionInfo.AdjacencyDirection.WEST)); + } + } + + // East + if (self.x + self.width < level.width) { + int i = self.x + self.width; + for (int j = self.y; j < self.y + self.height; j++) { + Tile t = level.getTileOrNull(i, j); + result.add(new AdjacentTileSelectionInfo(i, j, t, AdjacentTileSelectionInfo.AdjacencyDirection.EAST)); + } + } + + return result.iterator(); + } + }; + } + + public void clear() { + x = 0; + y = 0; + width = 1; + height = 1; + } + + /** Initial tile of selection. */ + public Tile first() { + return Editor.app.getLevel().getTile(x, y); + } + + public boolean contains(int x, int y) { + return x >= this.x && x < this.x + width && y >= this.y && y < this.y + height; + } + + @Override + public Iterator iterator() { + Array result = new Array(); + + for (int i = x; i < x + width; i++) { + for (int j = y; j < y + height; j++) { + Tile t = Editor.app.getLevel().getTileOrNull(i, j); + result.add(new TileSelectionInfo(i, j, t)); + } + } + + return result.iterator(); + } } diff --git a/DelvEdit/src/com/interrupt/dungeoneer/editor/selection/TileSelectionInfo.java b/DelvEdit/src/com/interrupt/dungeoneer/editor/selection/TileSelectionInfo.java new file mode 100644 index 00000000..62d8f92f --- /dev/null +++ b/DelvEdit/src/com/interrupt/dungeoneer/editor/selection/TileSelectionInfo.java @@ -0,0 +1,15 @@ +package com.interrupt.dungeoneer.editor.selection; + +import com.interrupt.dungeoneer.tiles.Tile; + +public class TileSelectionInfo { + public int x; + public int y; + public Tile tile; + + public TileSelectionInfo(int x, int y, Tile tile) { + this.x = x; + this.y = y; + this.tile = tile; + } +}