Skip to content

Commit

Permalink
Fix flatten tiles and control points not refreshing.
Browse files Browse the repository at this point in the history
Two main fixes in this one: 1) The flatten tile wouldn't work with a negative selection width or height. A lot of other methods had if logic to handle, so I fixed at the source (where width and height are set) and then removed the logic in all of the other places. No need to remember to cut and paste that logic any more. 2) When selecting a new tile it would not always clear the control points from the old tiles. I added a control point clear on selection of a new tile, so now the control point will move to the newly selected tile right away (no need to re-click or toggle vertex mode or anything).
  • Loading branch information
NetherNarwhal authored Dec 22, 2018
1 parent 8cc989c commit 66d0d88
Showing 1 changed file with 17 additions and 202 deletions.
219 changes: 17 additions & 202 deletions DelvEdit/src/com/interrupt/dungeoneer/editor/EditorFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import com.interrupt.managers.EntityManager;
import com.interrupt.managers.StringManager;
import com.noise.PerlinNoise;
import com.badlogic.gdx.math.MathUtils;

import javax.swing.*;
import java.util.HashMap;
Expand Down Expand Up @@ -507,6 +508,11 @@ public void render() {
Vector3 intersectNormal = new Vector3();
Vector3 intersectTemp = new Vector3();
Array<Entity> selectedEntities = new Array<Entity>();

// Track the starting point of the selection area.
int selStartX = 0;
int selStartY = 0;

public void draw() {
GL20 gl = renderer.getGL();
GlRenderer.clearBoundTexture();
Expand Down Expand Up @@ -755,6 +761,9 @@ public void draw() {
if(selectionY >= level.height) selectionY = level.height - 1;

selectionWidth = selectionHeight = 1;
selStartX = selectionX;
selStartY = selectionY;
controlPoints.clear();
}
else if(editorInput.isButtonPressed(Input.Buttons.LEFT)) {
if(Gdx.input.isKeyPressed(Keys.ALT_LEFT)) {
Expand All @@ -778,17 +787,15 @@ else if(pickedSurface.tileSurface == TileSurface.Ceiling) {
// don't modify selection area!
movingControlPoint = true;
} else {
// 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);

float selectXMod = 0.8f;
float selectYMod = 0.8f;
if (intpos.x < selectionX) selectXMod *= -1f;
if (intpos.z < selectionY) selectYMod *= -1f;

selectionWidth = ((int) (intpos.x + selectXMod) - selectionX);
selectionHeight = ((int) (intpos.z + selectYMod) - selectionY);

if (selectionWidth == 0) selectionWidth = 1;
if (selectionHeight == 0) selectionHeight = 1;
selectionWidth = Math.abs(selStartX - newX) + 1;
selectionHeight = 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);

controlPoints.clear();
}
Expand Down Expand Up @@ -917,17 +924,6 @@ else if (dragMode == DragMode.Y)
int selWidth = selectionWidth;
int selHeight = selectionHeight;

if(selWidth < 0) {
selX = selX + selWidth;
selWidth *= -1;
selX += 1;
}
if(selHeight < 0) {
selY = selY + selHeight;
selHeight *= -1;
selY += 1;
}

Tile startTile = level.getTile(selectionX, selectionY);

// init the control point list if needed
Expand Down Expand Up @@ -1086,17 +1082,6 @@ else if (dragMode == DragMode.Y)
int selWidth = selectionWidth;
int selHeight = selectionHeight;

if(selWidth < 0) {
selX = selX + selWidth;
selWidth *= -1;
selX += 1;
}
if(selHeight < 0) {
selY = selY + selHeight;
selHeight *= -1;
selY += 1;
}

for(int x = selX; x < selX + selWidth; x++) {
for(int y = selY; y < selY + selHeight; y++) {
Tile t = level.getTileOrNull(x,y);
Expand Down Expand Up @@ -1855,17 +1840,6 @@ private void drawSlopeLines(int num, boolean edge) {
int selWidth = selectionWidth;
int selHeight = selectionHeight;

if(selWidth < 0) {
selX = selX + selWidth;
selWidth *= -1;
selX += 1;
}
if(selHeight < 0) {
selY = selY + selHeight;
selHeight *= -1;
selY += 1;
}

for(int x = selX; x < selX + selWidth; x++) {
for(int y = selY; y < selY + selHeight; y++) {
Tile t = level.getTileOrNull(x,y);
Expand Down Expand Up @@ -2214,22 +2188,6 @@ else if(turnDown) {
player.ya += (zm * Math.cos(rotX) - xm * Math.sin(rotX)) * 0.025f * Math.min(player.friction * 1.4f, 1f);
}

int selX = selectionX;
int selY = selectionY;
int selWidth = selectionWidth;
int selHeight = selectionHeight;

if(selWidth < 0) {
selX = selX + selWidth;
selWidth *= -1;
selX += 1;
}
if(selHeight < 0) {
selY = selY + selHeight;
selHeight *= -1;
selY += 1;
}

// Tile editing mode?
if(pickedEntity == null) {
if(Gdx.input.isKeyPressed(Keys.NUM_1)) {
Expand Down Expand Up @@ -2847,17 +2805,6 @@ public void addEntityMarker(Markers selectedItem) {
int selWidth = selectionWidth;
int selHeight = selectionHeight;

if(selWidth < 0) {
selX = selX + selWidth;
selWidth *= -1;
selX += 1;
}
if(selHeight < 0) {
selY = selY + selHeight;
selHeight *= -1;
selY += 1;
}

clearSelectedMarkers();

if(selectedItem != Markers.none) {
Expand All @@ -2880,17 +2827,6 @@ public boolean selectionHasEntityMarker() {
int selWidth = selectionWidth;
int selHeight = selectionHeight;

if(selWidth < 0) {
selX = selX + selWidth;
selWidth *= -1;
selX += 1;
}
if(selHeight < 0) {
selY = selY + selHeight;
selHeight *= -1;
selY += 1;
}

for(EditorMarker marker : level.editorMarkers) {
if(marker.x >= selX && marker.x < selX + selWidth && marker.y >= selY && marker.y < selY + selHeight) return true;
}
Expand Down Expand Up @@ -2926,17 +2862,6 @@ public void clearSelectedMarkers() {
int selWidth = selectionWidth;
int selHeight = selectionHeight;

if(selWidth < 0) {
selX = selX + selWidth;
selWidth *= -1;
selX += 1;
}
if(selHeight < 0) {
selY = selY + selHeight;
selHeight *= -1;
selY += 1;
}

for(int x = selX; x < selX + selWidth; x++) {
for(int y = selY; y < selY + selHeight; y++) {
if(level.editorMarkers != null && level.editorMarkers.size > 0) {
Expand Down Expand Up @@ -2995,17 +2920,6 @@ public void setTile(Tile tocopy) {
int selWidth = selectionWidth;
int selHeight = selectionHeight;

if(selWidth < 0) {
selX = selX + selWidth;
selWidth *= -1;
selX += 1;
}
if(selHeight < 0) {
selY = selY + selHeight;
selHeight *= -1;
selY += 1;
}

Tile selected = level.getTile(selectionX, selectionY);

for(int x = selX; x < selX + selWidth; x++) {
Expand Down Expand Up @@ -3108,17 +3022,6 @@ public void paintTile(Tile tocopy) {
int selWidth = selectionWidth;
int selHeight = selectionHeight;

if(selWidth < 0) {
selX = selX + selWidth;
selWidth *= -1;
selX += 1;
}
if(selHeight < 0) {
selY = selY + selHeight;
selHeight *= -1;
selY += 1;
}

for(int x = selX; x < selX + selWidth; x++) {
for(int y = selY; y < selY + selHeight; y++) {
Tile t = level.getTileOrNull(x, y);
Expand Down Expand Up @@ -3241,17 +3144,6 @@ public void clearTiles() {
int selWidth = selectionWidth;
int selHeight = selectionHeight;

if(selWidth < 0) {
selX = selX + selWidth;
selWidth *= -1;
selX += 1;
}
if(selHeight < 0) {
selY = selY + selHeight;
selHeight *= -1;
selY += 1;
}

for(int x = selX; x < selX + selWidth; x++) {
for(int y = selY; y < selY + selHeight; y++) {
Tile n = level.getTile(x, y - 1);
Expand Down Expand Up @@ -3284,17 +3176,6 @@ public void rotateFloorTex(int value) {
int selWidth = selectionWidth;
int selHeight = selectionHeight;

if(selWidth < 0) {
selX = selX + selWidth;
selWidth *= -1;
selX += 1;
}
if(selHeight < 0) {
selY = selY + selHeight;
selHeight *= -1;
selY += 1;
}

for(int x = selX; x < selX + selWidth; x++) {
for(int y = selY; y < selY + selHeight; y++) {
Tile t = level.getTileOrNull(x,y);
Expand Down Expand Up @@ -3341,17 +3222,6 @@ public void copy() {
int selWidth = selectionWidth;
int selHeight = selectionHeight;

if(selWidth < 0) {
selX = selX + selWidth;
selWidth *= -1;
selX += 1;
}
if(selHeight < 0) {
selY = selY + selHeight;
selHeight *= -1;
selY += 1;
}

if(pickedEntity == null) {
clipboard.tiles = new Tile[selWidth][selHeight];
clipboard.selWidth = selWidth;
Expand All @@ -3377,17 +3247,6 @@ public void paste() {
if(clipboard != null) {
int selX = selectionX;
int selY = selectionY;
int selWidth = selectionWidth;
int selHeight = selectionHeight;

if(selWidth < 0) {
selX = selX + selWidth;
selX += 1;
}
if(selHeight < 0) {
selY = selY + selHeight;
selY += 1;
}

for(int x = 0; x < clipboard.selWidth; x++) {
for(int y = 0; y < clipboard.selHeight; y++) {
Expand Down Expand Up @@ -3429,17 +3288,6 @@ public void rotateAngle() {
int selWidth = selectionWidth;
int selHeight = selectionHeight;

if(selWidth < 0) {
selX = selX + selWidth;
selWidth *= -1;
selX += 1;
}
if(selHeight < 0) {
selY = selY + selHeight;
selHeight *= -1;
selY += 1;
}

for(int x = selX; x < selX + selWidth; x++) {
for(int y = selY; y < selY + selHeight; y++) {
Tile t = level.getTileOrNull(x,y);
Expand All @@ -3462,17 +3310,6 @@ public void rotateCeilTex(int value) {
int selWidth = selectionWidth;
int selHeight = selectionHeight;

if(selWidth < 0) {
selX = selX + selWidth;
selWidth *= -1;
selX += 1;
}
if(selHeight < 0) {
selY = selY + selHeight;
selHeight *= -1;
selY += 1;
}

for(int x = selX; x < selX + selWidth; x++) {
for(int y = selY; y < selY + selHeight; y++) {
Tile t = level.getTileOrNull(x,y);
Expand All @@ -3492,17 +3329,6 @@ public void moveFloor(int value) {
int selWidth = selectionWidth;
int selHeight = selectionHeight;

if(selWidth < 0) {
selX = selX + selWidth;
selWidth *= -1;
selX += 1;
}
if(selHeight < 0) {
selY = selY + selHeight;
selHeight *= -1;
selY += 1;
}

for(int x = selX; x < selX + selWidth; x++) {
for(int y = selY; y < selY + selHeight; y++) {
Tile t = level.getTileOrNull(x,y);
Expand All @@ -3520,17 +3346,6 @@ public void moveCeiling(int value) {
int selWidth = selectionWidth;
int selHeight = selectionHeight;

if(selWidth < 0) {
selX = selX + selWidth;
selWidth *= -1;
selX += 1;
}
if(selHeight < 0) {
selY = selY + selHeight;
selHeight *= -1;
selY += 1;
}

for(int x = selX; x < selX + selWidth; x++) {
for(int y = selY; y < selY + selHeight; y++) {
Tile t = level.getTileOrNull(x,y);
Expand Down

0 comments on commit 66d0d88

Please sign in to comment.