diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/event/RedrawMapRequestEvent.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/event/RedrawMapRequestEvent.kt index bc8c5179..1e63929f 100755 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/event/RedrawMapRequestEvent.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/event/RedrawMapRequestEvent.kt @@ -1,6 +1,7 @@ package com.bartlomiejpluta.base.editor.event +import tornadofx.EventBus.RunOn.ApplicationThread import tornadofx.EventBus.RunOn.BackgroundThread import tornadofx.FXEvent -object RedrawMapRequestEvent : FXEvent(BackgroundThread) \ No newline at end of file +object RedrawMapRequestEvent : FXEvent(ApplicationThread) \ No newline at end of file diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/model/map/map/GameMap.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/model/map/map/GameMap.kt index 0a977f3e..548fdc58 100755 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/model/map/map/GameMap.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/model/map/map/GameMap.kt @@ -2,13 +2,18 @@ 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 tornadofx.observableListOf +import javafx.beans.property.ReadOnlyDoubleWrapper +import javafx.beans.property.SimpleIntegerProperty +import tornadofx.* -class GameMap(val tileSet: TileSet, val rows: Int, val columns: Int) { +class GameMap(val tileSet: TileSet, initialColumns: Int, initialRows: Int) { val layers = observableListOf() + val mapProperties = observableListOf() - val width = columns * tileSet.tileWidth + val rowsProperty = SimpleIntegerProperty(initialRows) + val rows by rowsProperty - val height = columns * tileSet.tileWidth + val columnsProperty = SimpleIntegerProperty(initialColumns) + val columns by columnsProperty } diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/model/map/map/MapProperty.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/model/map/map/MapProperty.kt new file mode 100755 index 00000000..87c3eb22 --- /dev/null +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/model/map/map/MapProperty.kt @@ -0,0 +1,13 @@ +package com.bartlomiejpluta.base.editor.model.map.map + +import javafx.beans.property.SimpleIntegerProperty +import javafx.beans.property.SimpleStringProperty +import tornadofx.* + +class MapProperty(key: String, value: Int) { + val keyProperty = SimpleStringProperty(key) + val key by keyProperty + + val valueProperty = SimpleIntegerProperty(value) + val value by valueProperty +} \ No newline at end of file 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 936a8c95..2df1f86c 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 @@ -6,25 +6,23 @@ import com.bartlomiejpluta.base.editor.render.model.Renderable import com.bartlomiejpluta.base.editor.viewmodel.map.GameMapVM import javafx.scene.canvas.GraphicsContext import javafx.scene.paint.Color +import org.slf4j.LoggerFactory class MapCanvas(val map: GameMapVM, private val painter: MapPainter) : Renderable { var tileSet = map.tileSet - private var layers = map.layers - private var rows = map.rows - private var columns = map.columns private var tileWidth = tileSet.tileWidth.toDouble() private var tileHeight = tileSet.tileHeight.toDouble() - private var mapWidth = map.width.toDouble() - private var mapHeight = map.height.toDouble() 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}") gc.clearRect(0.0, 0.0, gc.canvas.width, gc.canvas.height) - renderBackground(gc) + renderBackground(gc) - layers.forEach { dispatchLayerRender(gc, it) } + map.layers.forEach { dispatchLayerRender(gc, it) } renderGrid(gc) @@ -38,8 +36,8 @@ class MapCanvas(val map: GameMapVM, private val painter: MapPainter) : Renderabl } private fun renderBackground(gc: GraphicsContext) { - for (row in 0 until rows) { - for (column in 0 until columns) { + for (row in 0 until map.rows) { + for (column in 0 until map.columns) { gc.fill = if ((row + column) % 2 == 0) BACKGROUND_COLOR1 else BACKGROUND_COLOR2 gc.fillRect(column * tileWidth, row * tileHeight, tileWidth, tileHeight) } @@ -59,21 +57,22 @@ class MapCanvas(val map: GameMapVM, private val painter: MapPainter) : Renderabl private fun renderGrid(gc: GraphicsContext) { gc.lineWidth = 1.5 - gc.strokeLine(0.0, 0.0, mapWidth, 0.0) - gc.strokeLine(0.0, 0.0, 0.0, mapHeight) - gc.strokeLine(mapWidth, 0.0, mapWidth, mapHeight) - gc.strokeLine(0.0, mapHeight, mapWidth, mapHeight) + gc.strokeLine(0.0, 0.0, map.width, 0.0) + gc.strokeLine(0.0, 0.0, 0.0, map.height) + gc.strokeLine(map.width, 0.0, map.width, map.height) + gc.strokeLine(0.0, map.height, map.width, map.height) - for (row in 0 until rows) { - gc.strokeLine(0.0, row * tileHeight, mapWidth, row * tileHeight) + for (row in 0 until map.rows) { + gc.strokeLine(0.0, row * tileHeight, map.width, row * tileHeight) } - for (column in 0 until columns) { - gc.strokeLine(column * tileWidth, 0.0, column * tileWidth, mapHeight) + for (column in 0 until map.columns) { + gc.strokeLine(column * tileWidth, 0.0, column * tileWidth, map.height) } } companion object { + private val log = LoggerFactory.getLogger(MapCanvas::class.java) 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) } 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 fadabf97..e8b4d9d3 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 @@ -24,8 +24,8 @@ class MapPane(private val mapVM: GameMapVM, onMousePressed = this onMouseReleased = this - width = mapVM.width.toDouble() - height = mapVM.height.toDouble() + widthProperty().bind(mapVM.widthProperty) + heightProperty().bind(mapVM.heightProperty) render() } diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/main/MainView.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/main/MainView.kt index e6182236..55ad6908 100755 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/main/MainView.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/main/MainView.kt @@ -19,7 +19,7 @@ class MainView : View() { button(graphic = FontIcon("fa-file-o")) { action { val tileSet = tileSetController.tileset - val map = mapController.createMap(tileSet, 25, 25) + val map = mapController.createMap(tileSet, 5, 5) tabPane += find(UndoableScope(), MapFragment::map to map).apply { title = "Map 1" } diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/map/MapFragment.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/map/MapFragment.kt index eda2c03b..6e0bebf4 100755 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/map/MapFragment.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/map/MapFragment.kt @@ -38,6 +38,22 @@ class MapFragment : Fragment() { fire(RedrawMapRequestEvent) } } + + button(graphic = FontIcon("fa-plus")) { + action { + mapVM.rows = mapVM.rows + 1 + mapVM.commit() + fire(RedrawMapRequestEvent) + } + } + + button(graphic = FontIcon("fa-plus")) { + action { + mapVM.columns = mapVM.columns + 1 + mapVM.commit() + fire(RedrawMapRequestEvent) + } + } } center = mapView.root diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/map/MapPropertiesView.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/map/MapPropertiesView.kt new file mode 100755 index 00000000..cf0cea85 --- /dev/null +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/map/MapPropertiesView.kt @@ -0,0 +1,14 @@ +package com.bartlomiejpluta.base.editor.view.map + +import com.bartlomiejpluta.base.editor.model.map.map.MapProperty +import com.bartlomiejpluta.base.editor.viewmodel.map.GameMapVM +import tornadofx.* + +class MapPropertiesView : View() { + private val mapVM = find() + + override val root = tableview(mapVM.mapProperties) { + column("Key", MapProperty::keyProperty) + column("Value", MapProperty::valueProperty) + } +} \ No newline at end of file diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/viewmodel/map/GameMapVM.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/viewmodel/map/GameMapVM.kt index 1db1ba0c..034d38a5 100755 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/viewmodel/map/GameMapVM.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/viewmodel/map/GameMapVM.kt @@ -2,27 +2,29 @@ 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 javafx.beans.property.ReadOnlyDoubleWrapper import javafx.beans.property.SimpleIntegerProperty import javafx.beans.property.SimpleListProperty -import tornadofx.ItemViewModel -import tornadofx.getValue +import tornadofx.* class GameMapVM : ItemViewModel() { val layers: SimpleListProperty = bind(GameMap::layers) + val mapProperties: SimpleListProperty = bind(GameMap::mapProperties) val tileSetProperty = bind(GameMap::tileSet) val tileSet by tileSetProperty - val rowsProperty = bind(GameMap::rows) - val rows by rowsProperty + val rowsProperty = bind(GameMap::rowsProperty) + var rows by rowsProperty - val columnsProperty = bind(GameMap::columns) - val columns by columnsProperty + val columnsProperty = bind(GameMap::columnsProperty) + var columns by columnsProperty - val widthProperty = bind(GameMap::width) + val widthProperty = ReadOnlyDoubleWrapper().apply { bind(columnsProperty.multiply(32.0)) } val width by widthProperty - val heightProperty = bind(GameMap::height) + val heightProperty = ReadOnlyDoubleWrapper().apply { bind(rowsProperty.multiply(32.0)) } val height by heightProperty val selectedLayerProperty = SimpleIntegerProperty(0)