diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/model/map/editor/EditorOptions.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/model/map/editor/EditorOptions.kt index 3f7c6130..0237c398 100755 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/model/map/editor/EditorOptions.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/model/map/editor/EditorOptions.kt @@ -3,6 +3,7 @@ package com.bartlomiejpluta.base.editor.model.map.editor class EditorOptions { var selectedLayer = 0 var showGrid = true + var coverUnderlyingLayers = true } diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/render/canvas/map/MapCanvas.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/render/canvas/map/MapCanvas.kt index dee4fa98..3cd93489 100755 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/render/canvas/map/MapCanvas.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/render/canvas/map/MapCanvas.kt @@ -19,14 +19,30 @@ class MapCanvas(val map: GameMapVM, private val editorOptionsVM: EditorOptionsVM gc.clearRect(0.0, 0.0, gc.canvas.width, gc.canvas.height) renderBackground(gc) + renderUnderlyingLayers(gc) + renderCover(gc) + renderSelectedLayer(gc) + renderGrid(gc) + painter.render(gc) + } - map.layers.forEach { dispatchLayerRender(gc, it) } + private fun renderSelectedLayer(gc: GraphicsContext) { + map.layers.getOrNull(editorOptionsVM.selectedLayer) ?. let { dispatchLayerRender(gc, it) } + } - if (editorOptionsVM.showGrid) { - renderGrid(gc) + private fun renderCover(gc: GraphicsContext) { + if(!editorOptionsVM.coverUnderlyingLayers) { + return } - painter.render(gc) + gc.fill = Color.color(0.0, 0.0, 0.0, 0.4) + gc.fillRect(0.0, 0.0, map.width, map.height) + } + + private fun renderUnderlyingLayers(gc: GraphicsContext) { + for(layer in map.layers.dropLast( map.layers.size - editorOptionsVM.selectedLayer)) { + dispatchLayerRender(gc, layer) + } } private fun dispatchLayerRender(gc: GraphicsContext, layer: Layer) { @@ -55,6 +71,10 @@ class MapCanvas(val map: GameMapVM, private val editorOptionsVM: EditorOptionsVM } private fun renderGrid(gc: GraphicsContext) { + if(!editorOptionsVM.showGrid) { + return + } + gc.lineWidth = 1.5 gc.strokeLine(0.0, 0.0, map.width, 0.0) @@ -73,6 +93,6 @@ class MapCanvas(val map: GameMapVM, private val editorOptionsVM: EditorOptionsVM companion object { private val BACKGROUND_COLOR1 = Color.color(1.0, 1.0, 1.0, 1.0) - private val BACKGROUND_COLOR2 = Color.color(0.95, 0.95, 0.95, 0.95) + private val BACKGROUND_COLOR2 = Color.color(0.8, 0.8, 0.8, 1.0) } } \ No newline at end of file diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/component/map/MapPane.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/component/map/MapPane.kt index 47231d10..af745210 100755 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/component/map/MapPane.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/component/map/MapPane.kt @@ -31,6 +31,8 @@ class MapPane( heightProperty().bind(mapVM.heightProperty) editorOptionsVM.showGridProperty.addListener { _, _, _ -> render() } + editorOptionsVM.selectedLayerProperty.addListener { _, _, _ -> render() } + editorOptionsVM.coverUnderlyingLayersProperty.addListener { _, _, _ -> render() } render() } diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/map/MapToolbarView.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/map/MapToolbarView.kt index 419db54f..f7ea8ac7 100755 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/map/MapToolbarView.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/map/MapToolbarView.kt @@ -78,6 +78,15 @@ class MapToolbarView : View() { } } + togglebutton { + graphic = FontIcon("fa-window-restore") + + action { + editorOptionsVM.coverUnderlyingLayers = isSelected + editorOptionsVM.commit() + } + } + togglebutton { graphic = FontIcon("fa-th") diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/viewmodel/map/EditorOptionsVM.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/viewmodel/map/EditorOptionsVM.kt index ba7e06f5..120e2325 100755 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/viewmodel/map/EditorOptionsVM.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/viewmodel/map/EditorOptionsVM.kt @@ -10,4 +10,7 @@ class EditorOptionsVM : ItemViewModel(EditorOptions()) { val showGridProperty = bind(EditorOptions::showGrid) var showGrid by showGridProperty + + val coverUnderlyingLayersProperty = bind(EditorOptions::coverUnderlyingLayers) + var coverUnderlyingLayers by coverUnderlyingLayersProperty } \ No newline at end of file