Skip to content

Commit 41492ea

Browse files
authored
Use y-clipping settings from the map view when creating a new scene or loading chunks from it (#1770)
* Use y-clipping settings from the map view when creating a new scene or loading chunks from it and fix requiring two reloads after changing the y-clipping settings of a scene. * Remove debug output. * Do not ignore scene loaded as reset reason for the scene and update outdated getResetReason javadoc. * Fix changing the map y clip sliders resetting the scene y clip sliders. * Don't change the scene's y clipping at all when changing the map y clipping. * Add a hint to the map y clip sliders to avoid confusion when it doesn't get applied to the current scene. * Change spelling of Y-level and Y-clip in the UI.
1 parent 0d030a6 commit 41492ea

File tree

7 files changed

+35
-22
lines changed

7 files changed

+35
-22
lines changed

chunky/src/java/se/llbit/chunky/renderer/scene/Scene.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3148,17 +3148,15 @@ public Collection<ChunkPosition> getChunks() {
31483148
}
31493149

31503150
/**
3151-
* Clears the reset reason and returns the previous reason.
3151+
* Get the reset reason.
31523152
* @return the current reset reason
31533153
*/
3154-
public synchronized ResetReason getResetReason() {
3154+
public ResetReason getResetReason() {
31553155
return resetReason;
31563156
}
31573157

31583158
public void setResetReason(ResetReason resetReason) {
3159-
if (this.resetReason != ResetReason.SCENE_LOADED) {
3160-
this.resetReason = resetReason;
3161-
}
3159+
this.resetReason = resetReason;
31623160
}
31633161

31643162
public void importMaterials() {

chunky/src/java/se/llbit/chunky/renderer/scene/SynchronousSceneManager.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,14 @@ public void saveScene(SceneIOProvider ioContext, Scene scene) throws Interrupted
237237

238238
@Override public void loadFreshChunks(World world, Map<RegionPosition, List<ChunkPosition>> chunksToLoadByRegion) {
239239
synchronized (scene) {
240+
int yClipMin = scene.getYClipMin();
241+
int yClipMax = scene.getYClipMax();
240242
scene.clear();
241-
scene.loadChunks(taskTracker, world, chunksToLoadByRegion);
242243
scene.resetScene(null, context.getChunky().getSceneFactory());
244+
scene.setYClipMin(yClipMin);
245+
scene.setYClipMax(yClipMax);
243246
context.setSceneDirectory(new File(context.getChunky().options.sceneDir, scene.name));
247+
scene.loadChunks(taskTracker, world, chunksToLoadByRegion);
244248
scene.refresh();
245249
scene.setResetReason(ResetReason.SCENE_LOADED);
246250
scene.setRenderMode(RenderMode.PREVIEW);
@@ -255,19 +259,19 @@ public void saveScene(SceneIOProvider ioContext, Scene scene) throws Interrupted
255259
if (prevChunkCount == 0) {
256260
scene.moveCameraToCenter();
257261
}
258-
scene.refresh();
259262
scene.setResetReason(ResetReason.SCENE_LOADED);
260263
scene.setRenderMode(RenderMode.PREVIEW);
264+
scene.refresh();
261265
}
262266
onChunksLoaded.run();
263267
}
264268

265269
@Override public void reloadChunks() {
266270
synchronized (scene) {
267271
scene.reloadChunks(taskTracker);
268-
scene.refresh();
269272
scene.setResetReason(ResetReason.SCENE_LOADED);
270273
scene.setRenderMode(RenderMode.PREVIEW);
274+
scene.refresh();
271275
}
272276
onChunksLoaded.run();
273277
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ public ChunkMap(WorldMapLoader loader, ChunkyFxController controller,
153153
newScene.setGraphic(new ImageView(Icon.sky.fxImage()));
154154
newScene.setOnAction(event -> {
155155
SceneManager sceneManager = controller.getRenderController().getSceneManager();
156+
sceneManager.getSceneProvider().withEditSceneProtected(scene -> {
157+
scene.setYClipMin(mapView.getYMin());
158+
scene.setYClipMax(mapView.getYMax());
159+
});
156160
sceneManager
157161
.loadFreshChunks(mapLoader.getWorld(), controller.getChunkSelection().getSelectionByRegion());
158162
});
@@ -161,6 +165,10 @@ public ChunkMap(WorldMapLoader loader, ChunkyFxController controller,
161165
MenuItem loadSelection = new MenuItem("Load selected chunks");
162166
loadSelection.setOnAction(event -> {
163167
SceneManager sceneManager = controller.getRenderController().getSceneManager();
168+
sceneManager.getSceneProvider().withEditSceneProtected(scene -> {
169+
scene.setYClipMin(mapView.getYMin());
170+
scene.setYClipMax(mapView.getYMax());
171+
});
164172
sceneManager
165173
.loadChunks(mapLoader.getWorld(), controller.getChunkSelection().getSelectionByRegion());
166174
});

chunky/src/java/se/llbit/chunky/ui/controller/ChunkyFxController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,8 @@ public File getSceneFile(String fileName) {
462462
map = new ChunkMap(mapLoader, this, mapView, chunkSelection,
463463
mapCanvas, mapOverlay);
464464

465-
yMin.setTooltip("Minimum Y level displayed in the map view.");
466-
yMax.setTooltip("Maximum Y level displayed in the map view.");
465+
yMin.setTooltip("Minimum Y-level displayed in the map view.");
466+
yMax.setTooltip("Maximum Y-level displayed in the map view.");
467467

468468
AtomicBoolean ignoreYUpdate = new AtomicBoolean(false); // used to not trigger a world reload after changing the world, see #926
469469
mapLoader.addWorldLoadListener(

chunky/src/java/se/llbit/chunky/ui/render/tabs/GeneralTab.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ public GeneralTab() throws IOException {
195195
canvasSizeInput.setSize(scene.canvasConfig.getCropWidth(), scene.canvasConfig.getCropHeight());
196196
}
197197

198+
@Override
199+
public void onChunksLoaded() {
200+
yMin.set(scene.getYClipMin());
201+
yMax.set(scene.getYClipMax());
202+
}
203+
198204
@Override public String getTabTitle() {
199205
return "Scene";
200206
}
@@ -588,14 +594,10 @@ private void updateCanvasCrop() {
588594
private void updateYClipSlidersRanges(World world) {
589595
if (world != null && world.getVersionId() >= World.VERSION_21W06A) {
590596
yMin.setRange(-64, 320);
591-
yMin.set(-64);
592597
yMax.setRange(-64, 320);
593-
yMax.set(320);
594598
} else {
595599
yMin.setRange(0, 256);
596-
yMin.set(0);
597600
yMax.setRange(0, 256);
598-
yMax.set(256);
599601
}
600602
}
601603
}

chunky/src/res/se/llbit/chunky/ui/Chunky.fxml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,19 @@
125125
<PositiveIntegerAdjuster fx:id="scale" name="Scale"/>
126126
</VBox>
127127
<Separator/>
128-
<Label text="Map Y clip:">
128+
<Label text="Map Y-clip:">
129129
<font>
130130
<Font name="System Bold" size="12.0" />
131131
</font>
132132
</Label>
133133
<VBox alignment="CENTER_LEFT">
134-
<IntegerAdjuster fx:id="yMin" name="Min Y level"/>
134+
<IntegerAdjuster fx:id="yMin" name="Min Y-level"/>
135135
</VBox>
136136
<VBox alignment="CENTER_LEFT">
137-
<IntegerAdjuster fx:id="yMax" name="Max Y level"/>
137+
<IntegerAdjuster fx:id="yMax" name="Max Y-level"/>
138138
</VBox>
139-
<Text fx:id="yClipInvalid" styleClass="invalid" managed="false" visible="false">Min Y level must be smaller than Max Y level.</Text>
139+
<Text fx:id="yClipInvalid" styleClass="invalid" managed="false" visible="false">Min Y-level must be smaller than Max Y-level.</Text>
140+
<Label wrapText="true">The map Y-clip also applies to new scenes. To change the Y-clip of the current scene, use the sliders in the Scene panel and then reload the chunks.</Label>
140141
<Separator/>
141142
<HBox spacing="10.0">
142143
<Label text="Show Players"/>

chunky/src/res/se/llbit/chunky/ui/render/tabs/GeneralTab.fxml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@
5151
<Button fx:id="loadSelectedChunks" mnemonicParsing="false" text="Load selected chunks" />
5252
<Button fx:id="reloadChunks" mnemonicParsing="false" text="Reload chunks" />
5353
</HBox>
54-
<TitledPane animated="false" text="Scene Y clip">
54+
<TitledPane animated="false" text="Scene Y-clip">
5555
<VBox spacing="10.0">
5656
<HBox alignment="CENTER_LEFT" spacing="10.0">
57-
<IntegerAdjuster fx:id="yMin" name="Min Y level" />
57+
<IntegerAdjuster fx:id="yMin" name="Min Y-level" />
5858
</HBox>
5959
<HBox alignment="CENTER_LEFT" spacing="10.0">
60-
<IntegerAdjuster fx:id="yMax" name="Max Y level" />
60+
<IntegerAdjuster fx:id="yMax" name="Max Y-level" />
6161
</HBox>
62-
<Text fx:id="yClipInvalid" styleClass="invalid" managed="false" visible="false">Min Y level must be smaller than Max Y level.</Text>
62+
<Text fx:id="yClipInvalid" styleClass="invalid" managed="false" visible="false">Min Y-level must be smaller than Max Y-level.</Text>
6363
</VBox>
6464
</TitledPane>
6565
<Accordion>

0 commit comments

Comments
 (0)