From 0338fa1c07007fc3380f78d62d4d43b1f57e019d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Przemys=C5=82aw=20Pluta?= Date: Tue, 30 Aug 2022 21:22:08 +0200 Subject: [PATCH] [Editor] Add option to preview all layers in map canvas --- .../base/editor/map/canvas/MapCanvas.kt | 9 +++++++++ .../base/editor/map/component/MapPane.kt | 1 + .../base/editor/map/view/editor/MapToolbarView.kt | 15 +++++++-------- .../base/editor/map/viewmodel/EditorStateVM.kt | 3 +++ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/canvas/MapCanvas.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/canvas/MapCanvas.kt index db4e8fbf..df7f87d5 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/canvas/MapCanvas.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/canvas/MapCanvas.kt @@ -75,6 +75,9 @@ class MapCanvas(val map: GameMapVM, private val editorStateVM: EditorStateVM, pr renderUnderlyingLayers(gc) renderCover(gc) renderSelectedLayer(gc) + if (editorStateVM.renderAllLayers) { + renderOverlappingLayers(gc) + } renderGrid(gc) painter.render(gc) } @@ -98,6 +101,12 @@ class MapCanvas(val map: GameMapVM, private val editorStateVM: EditorStateVM, pr } } + private fun renderOverlappingLayers(gc: GraphicsContext) { + for (layer in map.layers.drop(editorStateVM.selectedLayerIndex + 1)) { + dispatchLayerRender(gc, layer) + } + } + private fun dispatchLayerRender(gc: GraphicsContext, layer: Layer) { when (layer) { is TileLayer -> renderTileLayer(gc, layer) diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/component/MapPane.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/component/MapPane.kt index a3718528..bf658ef5 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/component/MapPane.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/component/MapPane.kt @@ -37,6 +37,7 @@ class MapPane( editorStateVM.showGridProperty.addListener { _, _, _ -> render() } editorStateVM.selectedLayerIndexProperty.addListener { _, _, _ -> render() } editorStateVM.coverUnderlyingLayersProperty.addListener { _, _, _ -> render() } + editorStateVM.renderAllLayersProperty.addListener { _, _, _ -> render() } render() } diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/editor/MapToolbarView.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/editor/MapToolbarView.kt index d342cf48..9b079f78 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/editor/MapToolbarView.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/editor/MapToolbarView.kt @@ -40,7 +40,7 @@ class MapToolbarView : View() { { editorStateVM.selectedLayer is AutoTileLayer }, editorStateVM.selectedLayerProperty ) - + private val isObjectLayerSelected = Bindings.createBooleanBinding( { editorStateVM.selectedLayer is ObjectLayer }, editorStateVM.selectedLayerProperty @@ -82,18 +82,17 @@ class MapToolbarView : View() { togglebutton { graphic = FontIcon("fa-window-restore") - - action { - editorStateVM.coverUnderlyingLayers = isSelected - } + editorStateVM.coverUnderlyingLayersProperty.bind(selectedProperty()) } togglebutton { graphic = FontIcon("fa-th") + editorStateVM.showGridProperty.bind(selectedProperty()) + } - action { - editorStateVM.showGrid = isSelected - } + togglebutton { + graphic = FontIcon("fa-clone") + editorStateVM.renderAllLayersProperty.bind(selectedProperty()) } separator() diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/viewmodel/EditorStateVM.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/viewmodel/EditorStateVM.kt index 9cd79882..a47899b4 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/viewmodel/EditorStateVM.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/viewmodel/EditorStateVM.kt @@ -30,4 +30,7 @@ class EditorStateVM : ViewModel() { val cursorColumnProperty = SimpleIntegerProperty(-1) val cursorColumn by cursorColumnProperty + + val renderAllLayersProperty = SimpleBooleanProperty(false) + var renderAllLayers by renderAllLayersProperty } \ No newline at end of file