Skip to content

Commit 1a4ca51

Browse files
authored
Deselect chunks In rectangle if all selected (#1014)
* Deselect Chunks In Rectangle If All Selected * update license date
1 parent 0f6b182 commit 1a4ca51

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

chunky/src/java/se/llbit/chunky/ui/ChunkMap.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,12 @@ protected synchronized void selectWithinRect() {
256256
int x1 = Math.max(cp0.x, cp1.x);
257257
int z0 = Math.min(cp0.z, cp1.z);
258258
int z1 = Math.max(cp0.z, cp1.z);
259-
if (ctrlModifier) {
259+
260+
// If ctrlModifier to deselect, then do deselect
261+
// If no ctrlModifier, select chunks
262+
// but if they are all already selected, then deselect.
263+
if (ctrlModifier || !chunkSelection.selectChunks(mapLoader.getWorld(), x0, z0, x1, z1))
260264
chunkSelection.deselectChunks(x0, z0, x1, z1);
261-
} else {
262-
chunkSelection.selectChunks(mapLoader.getWorld(), x0, z0, x1, z1);
263-
}
264265
}
265266
}
266267

chunky/src/java/se/llbit/chunky/world/ChunkSelectionTracker.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/* Copyright (c) 2012 Jesper Öqvist <jesper@llbit.se>
1+
/* Copyright (c) 2012-2021 Jesper Öqvist <jesper@llbit.se>
2+
* Copyright (c) 2012-2021 Chunky contributors
23
*
34
* This file is part of Chunky.
45
*
@@ -140,8 +141,9 @@ public synchronized void selectRegion(World world, int cx, int cz) {
140141

141142
/**
142143
* Select chunks within rectangle.
144+
* @return true if anything was changed, false if no chunks were selected.
143145
*/
144-
public synchronized void selectChunks(World world, int cx0, int cz0, int cx1, int cz1) {
146+
public synchronized boolean selectChunks(World world, int cx0, int cz0, int cx1, int cz1) {
145147
boolean selectionChanged = false;
146148
for (int cx = cx0; cx <= cx1; ++cx) {
147149
for (int cz = cz0; cz <= cz1; ++cz) {
@@ -156,12 +158,14 @@ public synchronized void selectChunks(World world, int cx0, int cz0, int cx1, in
156158
if (selectionChanged) {
157159
notifyChunkSelectionChange();
158160
}
161+
return selectionChanged;
159162
}
160163

161164
/**
162165
* Deselect chunks within rectangle.
166+
* @return true if anything was changed, false if no chunks were deselected.
163167
*/
164-
public synchronized void deselectChunks(int cx0, int cz0, int cx1, int cz1) {
168+
public synchronized boolean deselectChunks(int cx0, int cz0, int cx1, int cz1) {
165169
boolean selectionChanged = false;
166170
for (int cx = cx0; cx <= cx1; ++cx) {
167171
for (int cz = cz0; cz <= cz1; ++cz) {
@@ -176,6 +180,7 @@ public synchronized void deselectChunks(int cx0, int cz0, int cx1, int cz1) {
176180
if (selectionChanged) {
177181
notifyChunkSelectionChange();
178182
}
183+
return selectionChanged;
179184
}
180185

181186
/**

0 commit comments

Comments
 (0)