Skip to content

Commit

Permalink
Use y-clipping settings from the map view when creating a new scene o…
Browse files Browse the repository at this point in the history
…r loading chunks from it and fix requiring two reloads after changing the y-clipping settings of a scene.
  • Loading branch information
leMaik committed Sep 23, 2024
1 parent 16b409c commit 48d2c8f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,21 @@ public void saveScene(SceneIOProvider ioContext, Scene scene) throws Interrupted

@Override public void loadFreshChunks(World world, Collection<ChunkPosition> chunksToLoad) {
synchronized (scene) {
int yClipMin = scene.getYClipMin();
int yClipMax = scene.getYClipMax();
scene.clear();
scene.loadChunks(taskTracker, world, chunksToLoad);
scene.resetScene(null, context.getChunky().getSceneFactory());
scene.setYClipMin(yClipMin);
scene.setYClipMax(yClipMax);
context.setSceneDirectory(new File(context.getChunky().options.sceneDir, scene.name));
scene.loadChunks(taskTracker, world, chunksToLoad);
scene.refresh();
scene.setResetReason(ResetReason.SCENE_LOADED);
scene.setRenderMode(RenderMode.PREVIEW);
}
System.out.println(scene.getYClipMin()+" min, 2 max "+scene.getYClipMax());
onSceneLoaded.run();
System.out.println(scene.getYClipMin()+" min, 3 max "+scene.getYClipMax());
}

@Override public void loadChunks(World world, Collection<ChunkPosition> chunksToLoad) {
Expand All @@ -253,19 +259,19 @@ public void saveScene(SceneIOProvider ioContext, Scene scene) throws Interrupted
if (prevChunkCount == 0) {
scene.moveCameraToCenter();
}
scene.refresh();
scene.setResetReason(ResetReason.SCENE_LOADED);
scene.setRenderMode(RenderMode.PREVIEW);
scene.refresh();
}
onChunksLoaded.run();
}

@Override public void reloadChunks() {
synchronized (scene) {
scene.reloadChunks(taskTracker);
scene.refresh();
scene.setResetReason(ResetReason.SCENE_LOADED);
scene.setRenderMode(RenderMode.PREVIEW);
scene.refresh();
}
onChunksLoaded.run();
}
Expand Down
14 changes: 10 additions & 4 deletions chunky/src/java/se/llbit/chunky/ui/ChunkMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,22 @@ public ChunkMap(WorldMapLoader loader, ChunkyFxController controller,
newScene.setGraphic(new ImageView(Icon.sky.fxImage()));
newScene.setOnAction(event -> {
SceneManager sceneManager = controller.getRenderController().getSceneManager();
sceneManager
.loadFreshChunks(mapLoader.getWorld(), controller.getChunkSelection().getSelection());
sceneManager.getSceneProvider().withEditSceneProtected(scene -> {
scene.setYClipMin(mapView.getYMin());
scene.setYClipMax(mapView.getYMax());
});
sceneManager.loadFreshChunks(mapLoader.getWorld(), controller.getChunkSelection().getSelection());
});
newScene.setDisable(chunkSelection.isEmpty());

MenuItem loadSelection = new MenuItem("Load selected chunks");
loadSelection.setOnAction(event -> {
SceneManager sceneManager = controller.getRenderController().getSceneManager();
sceneManager
.loadChunks(mapLoader.getWorld(), controller.getChunkSelection().getSelection());
sceneManager.getSceneProvider().withEditSceneProtected(scene -> {
scene.setYClipMin(mapView.getYMin());
scene.setYClipMax(mapView.getYMax());
});
sceneManager.loadChunks(mapLoader.getWorld(), controller.getChunkSelection().getSelection());
});
loadSelection.setDisable(chunkSelection.isEmpty());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ public GeneralTab() throws IOException {
canvasSizeInput.setSize(scene.canvasConfig.getCropWidth(), scene.canvasConfig.getCropHeight());
}

@Override
public void onChunksLoaded() {
yMin.set(scene.getYClipMin());
yMax.set(scene.getYClipMax());
}

@Override public String getTabTitle() {
return "Scene";
}
Expand Down

0 comments on commit 48d2c8f

Please sign in to comment.