Skip to content

Commit

Permalink
Hiding Selection Outline When Out-Of-Bounds (#87)
Browse files Browse the repository at this point in the history
* Hiding selection outline when out of bounds

* Refactoring tile selection inside level bounds logic

* Fixing incorrect bounds

* Using simpler approach for bounding
  • Loading branch information
Felix Siebeneicker authored and Evrim Öztamur committed Sep 30, 2020
1 parent 2aa7b68 commit 52a2629
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
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.TileSelection;
import com.interrupt.dungeoneer.editor.selection.TileSelectionInfo;
import com.interrupt.dungeoneer.editor.ui.EditorUi;
import com.interrupt.dungeoneer.editor.ui.SaveChangesDialog;
Expand Down Expand Up @@ -317,6 +318,8 @@ protected Decal newObject () {

private LiveReload liveReload;

private TileSelection entireLevelSelection;

public EditorApplication() {
frame = new JFrame("DelvEdit");

Expand Down Expand Up @@ -413,6 +416,7 @@ public void init(){

public void createEmptyLevel(int width, int height) {
level = new Level(width, height);
entireLevelSelection = TileSelection.Rect(0, 0, level.width, level.height);
refresh();

history = new EditorHistory();
Expand Down Expand Up @@ -746,17 +750,11 @@ else if(e == Editor.selection.hovered) {

end = ray.getEndPoint(rayOutVector, distance + 0.005f);

// Tile selection bounding
Editor.selection.tiles.x = (int)end.x;
Editor.selection.tiles.y = (int)end.z;

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(Editor.selection.tiles.y < 0) Editor.selection.tiles.y = 0;
if(Editor.selection.tiles.y >= level.height) Editor.selection.tiles.y = level.height - 1;
// Tile selection bounding
Editor.selection.tiles.x = Math.min(level.width - 1, Math.max(0, (int)end.x));
Editor.selection.tiles.y = Math.min(level.height - 1, Math.max(0, (int)end.z));
shouldDrawBox &= entireLevelSelection.contains((int)end.x, (int)end.z);

Editor.selection.tiles.width = Editor.selection.tiles.height = 1;
selStartX = Editor.selection.tiles.x;
selStartY = Editor.selection.tiles.y;
controlPoints.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ public Iterator<AdjacentTileSelectionInfo> iterator() {
};
}

public static TileSelection Rect(int x, int y, int width, int height) {
TileSelection tileSelection = new TileSelection();

tileSelection.x = x;
tileSelection.y = y;
tileSelection.width = width;
tileSelection.height = height;

return tileSelection;
}

public void clear() {
x = 0;
y = 0;
Expand Down

0 comments on commit 52a2629

Please sign in to comment.