[Editor] Restore map zooming support
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
package com.bartlomiejpluta.base.editor.model.map.editor
|
||||
|
||||
class EditorOptions {
|
||||
class EditorState {
|
||||
var selectedLayer = 0
|
||||
var showGrid = true
|
||||
var coverUnderlyingLayers = true
|
||||
var zoom = 1.0
|
||||
}
|
||||
|
||||
|
||||
@@ -3,13 +3,13 @@ package com.bartlomiejpluta.base.editor.render.canvas.map
|
||||
import com.bartlomiejpluta.base.editor.model.map.layer.Layer
|
||||
import com.bartlomiejpluta.base.editor.model.map.layer.TileLayer
|
||||
import com.bartlomiejpluta.base.editor.render.model.Renderable
|
||||
import com.bartlomiejpluta.base.editor.viewmodel.map.EditorOptionsVM
|
||||
import com.bartlomiejpluta.base.editor.viewmodel.map.EditorStateVM
|
||||
import com.bartlomiejpluta.base.editor.viewmodel.map.GameMapVM
|
||||
import javafx.scene.canvas.GraphicsContext
|
||||
import javafx.scene.paint.Color
|
||||
|
||||
|
||||
class MapCanvas(val map: GameMapVM, private val editorOptionsVM: EditorOptionsVM, private val painter: MapPainter) : Renderable {
|
||||
class MapCanvas(val map: GameMapVM, private val editorStateVM: EditorStateVM, private val painter: MapPainter) : Renderable {
|
||||
var tileSet = map.tileSet
|
||||
private var tileWidth = map.tileWidth
|
||||
private var tileHeight = map.tileHeight
|
||||
@@ -27,11 +27,11 @@ class MapCanvas(val map: GameMapVM, private val editorOptionsVM: EditorOptionsVM
|
||||
}
|
||||
|
||||
private fun renderSelectedLayer(gc: GraphicsContext) {
|
||||
map.layers.getOrNull(editorOptionsVM.selectedLayer) ?. let { dispatchLayerRender(gc, it) }
|
||||
map.layers.getOrNull(editorStateVM.selectedLayer) ?. let { dispatchLayerRender(gc, it) }
|
||||
}
|
||||
|
||||
private fun renderCover(gc: GraphicsContext) {
|
||||
if(!editorOptionsVM.coverUnderlyingLayers) {
|
||||
if(!editorStateVM.coverUnderlyingLayers) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class MapCanvas(val map: GameMapVM, private val editorOptionsVM: EditorOptionsVM
|
||||
}
|
||||
|
||||
private fun renderUnderlyingLayers(gc: GraphicsContext) {
|
||||
for(layer in map.layers.dropLast( map.layers.size - editorOptionsVM.selectedLayer)) {
|
||||
for(layer in map.layers.dropLast( map.layers.size - editorStateVM.selectedLayer)) {
|
||||
dispatchLayerRender(gc, layer)
|
||||
}
|
||||
}
|
||||
@@ -71,7 +71,7 @@ class MapCanvas(val map: GameMapVM, private val editorOptionsVM: EditorOptionsVM
|
||||
}
|
||||
|
||||
private fun renderGrid(gc: GraphicsContext) {
|
||||
if(!editorOptionsVM.showGrid) {
|
||||
if(!editorStateVM.showGrid) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.bartlomiejpluta.base.editor.render.canvas.input.MapMouseEvent
|
||||
import com.bartlomiejpluta.base.editor.render.canvas.input.MapMouseEventHandler
|
||||
import com.bartlomiejpluta.base.editor.render.model.Renderable
|
||||
import com.bartlomiejpluta.base.editor.viewmodel.map.BrushVM
|
||||
import com.bartlomiejpluta.base.editor.viewmodel.map.EditorOptionsVM
|
||||
import com.bartlomiejpluta.base.editor.viewmodel.map.EditorStateVM
|
||||
import com.bartlomiejpluta.base.editor.viewmodel.map.GameMapVM
|
||||
import javafx.scene.canvas.GraphicsContext
|
||||
import javafx.scene.input.MouseButton
|
||||
@@ -15,7 +15,7 @@ import javafx.scene.paint.Color
|
||||
class MapPainter(
|
||||
private val mapVM: GameMapVM,
|
||||
private val brushVM: BrushVM,
|
||||
private val editorOptionsVM: EditorOptionsVM,
|
||||
private val editorStateVM: EditorStateVM,
|
||||
private val paintingCallback: (MapPaintingTrace) -> Unit
|
||||
) : Renderable, MapMouseEventHandler {
|
||||
private val tileWidth = mapVM.tileSet.tileWidth.toDouble()
|
||||
@@ -67,10 +67,10 @@ class MapPainter(
|
||||
}
|
||||
|
||||
private fun beginTrace(event: MapMouseEvent) {
|
||||
if (event.button == MouseButton.PRIMARY && editorOptionsVM.selectedLayer >= 0) {
|
||||
if (event.button == MouseButton.PRIMARY && editorStateVM.selectedLayer >= 0) {
|
||||
currentTrace = MapPaintingTrace(mapVM, "Paint trace").apply {
|
||||
brushVM.forEach { row, column, centerRow, centerColumn, tile ->
|
||||
paint(editorOptionsVM.selectedLayer, mouseRow - centerRow + row, mouseColumn - centerColumn + column, tile)
|
||||
paint(editorStateVM.selectedLayer, mouseRow - centerRow + row, mouseColumn - centerColumn + column, tile)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,7 +80,7 @@ class MapPainter(
|
||||
if (event.button == MouseButton.PRIMARY) {
|
||||
currentTrace?.apply {
|
||||
brushVM.forEach { row, column, centerRow, centerColumn, tile ->
|
||||
paint(editorOptionsVM.selectedLayer, mouseRow - centerRow + row, mouseColumn - centerColumn + column, tile)
|
||||
paint(editorStateVM.selectedLayer, mouseRow - centerRow + row, mouseColumn - centerColumn + column, tile)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.bartlomiejpluta.base.editor.render.canvas.map.MapCanvas
|
||||
import com.bartlomiejpluta.base.editor.render.canvas.map.MapPainter
|
||||
import com.bartlomiejpluta.base.editor.render.canvas.map.MapPaintingTrace
|
||||
import com.bartlomiejpluta.base.editor.viewmodel.map.BrushVM
|
||||
import com.bartlomiejpluta.base.editor.viewmodel.map.EditorOptionsVM
|
||||
import com.bartlomiejpluta.base.editor.viewmodel.map.EditorStateVM
|
||||
import com.bartlomiejpluta.base.editor.viewmodel.map.GameMapVM
|
||||
import javafx.event.EventHandler
|
||||
import javafx.scene.canvas.Canvas
|
||||
@@ -15,11 +15,11 @@ import javafx.scene.input.MouseEvent
|
||||
class MapPane(
|
||||
private val mapVM: GameMapVM,
|
||||
brushVM: BrushVM,
|
||||
editorOptionsVM: EditorOptionsVM,
|
||||
editorStateVM: EditorStateVM,
|
||||
paintingCallback: (MapPaintingTrace) -> Unit
|
||||
) : Canvas(), EventHandler<MouseEvent> {
|
||||
private val painter = MapPainter(mapVM, brushVM, editorOptionsVM, paintingCallback)
|
||||
private val mapCanvas = MapCanvas(mapVM, editorOptionsVM, painter)
|
||||
private val painter = MapPainter(mapVM, brushVM, editorStateVM, paintingCallback)
|
||||
private val mapCanvas = MapCanvas(mapVM, editorStateVM, painter)
|
||||
|
||||
init {
|
||||
onMouseMoved = this
|
||||
@@ -30,9 +30,9 @@ class MapPane(
|
||||
widthProperty().bind(mapVM.widthProperty)
|
||||
heightProperty().bind(mapVM.heightProperty)
|
||||
|
||||
editorOptionsVM.showGridProperty.addListener { _, _, _ -> render() }
|
||||
editorOptionsVM.selectedLayerProperty.addListener { _, _, _ -> render() }
|
||||
editorOptionsVM.coverUnderlyingLayersProperty.addListener { _, _, _ -> render() }
|
||||
editorStateVM.showGridProperty.addListener { _, _, _ -> render() }
|
||||
editorStateVM.selectedLayerProperty.addListener { _, _, _ -> render() }
|
||||
editorStateVM.coverUnderlyingLayersProperty.addListener { _, _, _ -> render() }
|
||||
|
||||
render()
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ class MapFragment : Fragment() {
|
||||
private val layersView = find<MapLayersView>()
|
||||
private val tileSetView = find<TileSetView>()
|
||||
private val toolbarView = find<MapToolbarView>()
|
||||
private val statusBarView = find<MapStatusBarView>()
|
||||
|
||||
|
||||
override val root = borderpane {
|
||||
@@ -35,5 +36,7 @@ class MapFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bottom = statusBarView.root
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import com.bartlomiejpluta.base.editor.command.service.UndoRedoService
|
||||
import com.bartlomiejpluta.base.editor.event.RedrawMapRequestEvent
|
||||
import com.bartlomiejpluta.base.editor.model.map.layer.Layer
|
||||
import com.bartlomiejpluta.base.editor.model.map.layer.TileLayer
|
||||
import com.bartlomiejpluta.base.editor.viewmodel.map.EditorOptionsVM
|
||||
import com.bartlomiejpluta.base.editor.viewmodel.map.EditorStateVM
|
||||
import com.bartlomiejpluta.base.editor.viewmodel.map.GameMapVM
|
||||
import javafx.scene.control.TableView
|
||||
import org.kordamp.ikonli.javafx.FontIcon
|
||||
@@ -22,7 +22,7 @@ class MapLayersView : View() {
|
||||
|
||||
private val mapVM = find<GameMapVM>()
|
||||
|
||||
private val editorOptionsVM = find<EditorOptionsVM>()
|
||||
private val editorOptionsVM = find<EditorStateVM>()
|
||||
|
||||
private var layersPane = TableView(mapVM.layers).apply {
|
||||
column("Layer Name", Layer::nameProperty).makeEditable().setOnEditCommit {
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.bartlomiejpluta.base.editor.view.map
|
||||
|
||||
import com.bartlomiejpluta.base.editor.viewmodel.map.EditorStateVM
|
||||
import javafx.beans.binding.Bindings
|
||||
import org.kordamp.ikonli.javafx.FontIcon
|
||||
import tornadofx.*
|
||||
|
||||
class MapStatusBarView : View() {
|
||||
|
||||
private val editorOptionsVM = find<EditorStateVM>()
|
||||
|
||||
override val root = hbox {
|
||||
spacing = 1.0
|
||||
paddingAll = 5.0
|
||||
|
||||
this += FontIcon("fa-search-minus")
|
||||
|
||||
slider(0.5..5.0) {
|
||||
bind(editorOptionsVM.zoomProperty)
|
||||
}
|
||||
|
||||
this += FontIcon("fa-search-plus")
|
||||
}
|
||||
}
|
||||
@@ -5,13 +5,11 @@ import com.bartlomiejpluta.base.editor.command.service.UndoRedoService
|
||||
import com.bartlomiejpluta.base.editor.event.RedrawMapRequestEvent
|
||||
import com.bartlomiejpluta.base.editor.model.map.brush.BrushMode
|
||||
import com.bartlomiejpluta.base.editor.viewmodel.map.BrushVM
|
||||
import com.bartlomiejpluta.base.editor.viewmodel.map.EditorOptionsVM
|
||||
import com.bartlomiejpluta.base.editor.viewmodel.map.EditorStateVM
|
||||
import com.bartlomiejpluta.base.editor.viewmodel.map.GameMapVM
|
||||
import javafx.scene.control.ToggleGroup
|
||||
import org.kordamp.ikonli.javafx.FontIcon
|
||||
import org.slf4j.LoggerFactory
|
||||
import tornadofx.*
|
||||
import java.util.*
|
||||
import kotlin.math.max
|
||||
|
||||
class MapToolbarView : View() {
|
||||
@@ -21,7 +19,7 @@ class MapToolbarView : View() {
|
||||
|
||||
private val mapVM = find<GameMapVM>()
|
||||
private val brushVM = find<BrushVM>()
|
||||
private val editorOptionsVM = find<EditorOptionsVM>()
|
||||
private val editorOptionsVM = find<EditorStateVM>()
|
||||
|
||||
private val brushMode = ToggleGroup().apply {
|
||||
brushVM.itemProperty.addListener { _, _, brush ->
|
||||
|
||||
@@ -5,9 +5,8 @@ import com.bartlomiejpluta.base.editor.command.service.UndoRedoService
|
||||
import com.bartlomiejpluta.base.editor.event.RedrawMapRequestEvent
|
||||
import com.bartlomiejpluta.base.editor.view.component.map.MapPane
|
||||
import com.bartlomiejpluta.base.editor.viewmodel.map.BrushVM
|
||||
import com.bartlomiejpluta.base.editor.viewmodel.map.EditorOptionsVM
|
||||
import com.bartlomiejpluta.base.editor.viewmodel.map.EditorStateVM
|
||||
import com.bartlomiejpluta.base.editor.viewmodel.map.GameMapVM
|
||||
import javafx.beans.property.SimpleDoubleProperty
|
||||
import javafx.scene.input.MouseButton
|
||||
import javafx.scene.input.MouseEvent
|
||||
import javafx.scene.transform.Scale
|
||||
@@ -22,21 +21,19 @@ class MapView : View() {
|
||||
|
||||
override val scope = super.scope as UndoableScope
|
||||
|
||||
val zoomProperty = SimpleDoubleProperty(1.0)
|
||||
|
||||
private val zoom = Scale(1.0, 1.0, 0.0, 0.0).apply {
|
||||
xProperty().bind(zoomProperty)
|
||||
yProperty().bind(zoomProperty)
|
||||
}
|
||||
|
||||
private val mapVM = find<GameMapVM>()
|
||||
|
||||
private val brushVM = find<BrushVM>()
|
||||
|
||||
private val editorOptionsVM = find<EditorOptionsVM>()
|
||||
private val editorOptionsVM = find<EditorStateVM>()
|
||||
|
||||
private val mapPane = MapPane(mapVM, brushVM, editorOptionsVM) { undoRedoService.push(it, scope) }
|
||||
|
||||
private val zoom = Scale(1.0, 1.0, 0.0, 0.0).apply {
|
||||
xProperty().bind(editorOptionsVM.zoomProperty)
|
||||
yProperty().bind(editorOptionsVM.zoomProperty)
|
||||
}
|
||||
|
||||
init {
|
||||
brushVM.item = mapVM.tileSet.baseBrush
|
||||
brushVM.commit()
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.bartlomiejpluta.base.editor.viewmodel.map
|
||||
|
||||
import com.bartlomiejpluta.base.editor.model.map.editor.EditorOptions
|
||||
import javafx.beans.property.IntegerProperty
|
||||
import tornadofx.*
|
||||
|
||||
class EditorOptionsVM : ItemViewModel<EditorOptions>(EditorOptions()) {
|
||||
val selectedLayerProperty = bind(EditorOptions::selectedLayer) as IntegerProperty
|
||||
var selectedLayer by selectedLayerProperty
|
||||
|
||||
val showGridProperty = bind(EditorOptions::showGrid)
|
||||
var showGrid by showGridProperty
|
||||
|
||||
val coverUnderlyingLayersProperty = bind(EditorOptions::coverUnderlyingLayers)
|
||||
var coverUnderlyingLayers by coverUnderlyingLayersProperty
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.bartlomiejpluta.base.editor.viewmodel.map
|
||||
|
||||
import com.bartlomiejpluta.base.editor.model.map.editor.EditorState
|
||||
import javafx.beans.property.DoubleProperty
|
||||
import javafx.beans.property.IntegerProperty
|
||||
import tornadofx.*
|
||||
|
||||
class EditorStateVM : ItemViewModel<EditorState>(EditorState()) {
|
||||
val selectedLayerProperty = bind(EditorState::selectedLayer) as IntegerProperty
|
||||
var selectedLayer by selectedLayerProperty
|
||||
|
||||
val showGridProperty = bind(EditorState::showGrid)
|
||||
var showGrid by showGridProperty
|
||||
|
||||
val coverUnderlyingLayersProperty = bind(EditorState::coverUnderlyingLayers)
|
||||
var coverUnderlyingLayers by coverUnderlyingLayersProperty
|
||||
|
||||
val zoomProperty = bind(EditorState::zoom) as DoubleProperty
|
||||
var zoom by zoomProperty
|
||||
}
|
||||
Reference in New Issue
Block a user