[Editor] Map resizability - attempt II

This commit is contained in:
2021-02-06 12:47:59 +01:00
parent 2bd7687088
commit df53527230
3 changed files with 41 additions and 5 deletions

View File

@@ -3,6 +3,8 @@ package com.bartlomiejpluta.base.editor.model.map.map
import com.bartlomiejpluta.base.editor.model.map.layer.Layer
import com.bartlomiejpluta.base.editor.model.tileset.TileSet
import javafx.beans.property.ReadOnlyDoubleWrapper
import javafx.beans.property.ReadOnlyFloatProperty
import javafx.beans.property.SimpleDoubleProperty
import javafx.beans.property.SimpleIntegerProperty
import tornadofx.*
@@ -11,9 +13,31 @@ class GameMap(val tileSet: TileSet, initialColumns: Int, initialRows: Int) {
val layers = observableListOf<Layer>()
val mapProperties = observableListOf<MapProperty>()
val tileWidth = tileSet.tileWidth.toDouble()
val tileHeight = tileSet.tileHeight.toDouble()
val rowsProperty = SimpleIntegerProperty(initialRows)
val rows by rowsProperty
val columnsProperty = SimpleIntegerProperty(initialColumns)
val columns by columnsProperty
val widthProperty = SimpleDoubleProperty(initialColumns * tileWidth)
var width by widthProperty
private set
val heightProperty = SimpleDoubleProperty(initialRows * tileHeight)
var height by heightProperty
private set
init {
rowsProperty.addListener { _, _, newValue ->
height = newValue.toInt() * tileWidth
}
columnsProperty.addListener { _, _, newValue ->
width = newValue.toInt() * tileWidth
}
}
}

View File

@@ -11,13 +11,13 @@ import org.slf4j.LoggerFactory
class MapCanvas(val map: GameMapVM, private val painter: MapPainter) : Renderable {
var tileSet = map.tileSet
private var tileWidth = tileSet.tileWidth.toDouble()
private var tileHeight = tileSet.tileHeight.toDouble()
private var tileWidth = map.tileWidth
private var tileHeight = map.tileHeight
override fun render(gc: GraphicsContext) {
log.debug("vm.dim = ${map.rows}x${map.columns} | map.dim = ${map.item.rows}x${map.item.columns}")
// log.debug("vm.size = ${map.width}x${map.height} | map.size = ${map.item.width}x${map.item.height}")
log.debug("vm.size = ${map.width}x${map.height} | map.size = ${map.item.width}x${map.item.height}")
gc.clearRect(0.0, 0.0, gc.canvas.width, gc.canvas.height)
renderBackground(gc)

View File

@@ -3,6 +3,7 @@ package com.bartlomiejpluta.base.editor.viewmodel.map
import com.bartlomiejpluta.base.editor.model.map.layer.Layer
import com.bartlomiejpluta.base.editor.model.map.map.GameMap
import com.bartlomiejpluta.base.editor.model.map.map.MapProperty
import com.bartlomiejpluta.base.editor.model.tileset.TileSet
import javafx.beans.property.ReadOnlyDoubleWrapper
import javafx.beans.property.SimpleIntegerProperty
import javafx.beans.property.SimpleListProperty
@@ -21,11 +22,22 @@ class GameMapVM : ItemViewModel<GameMap>() {
val columnsProperty = bind(GameMap::columnsProperty)
var columns by columnsProperty
val widthProperty = ReadOnlyDoubleWrapper().apply { bind(columnsProperty.multiply(32.0)) }
val tileWidthProperty = bind(GameMap::tileWidth)
val tileWidth by tileWidthProperty
val tileHeightProperty = bind(GameMap::tileHeight)
val tileHeight by tileHeightProperty
val widthProperty = bind(GameMap::widthProperty)
val width by widthProperty
val heightProperty = ReadOnlyDoubleWrapper().apply { bind(rowsProperty.multiply(32.0)) }
val heightProperty = bind(GameMap::heightProperty)
val height by heightProperty
// val widthProperty = ReadOnlyDoubleWrapper().apply { bind(tileSetProperty.getProperty(TileSet::tileWidthProperty)) }
// val width by widthProperty
//
// val heightProperty = ReadOnlyDoubleWrapper().apply { bind(rowsProperty.multiply(32.0)) }
// val height by heightProperty
val selectedLayerProperty = SimpleIntegerProperty(0)
val selectedLayer by selectedLayerProperty