diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/main/controller/MainController.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/main/controller/MainController.kt index af39c0b5..b6f3183f 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/main/controller/MainController.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/main/controller/MainController.kt @@ -8,7 +8,6 @@ import com.bartlomiejpluta.base.editor.project.manager.ProjectManager import com.bartlomiejpluta.base.editor.project.model.Project import com.bartlomiejpluta.base.editor.project.view.ProjectSettingsFragment import com.bartlomiejpluta.base.editor.project.viewmodel.ProjectVM -import com.bartlomiejpluta.base.editor.tileset.model.TileSet import javafx.beans.property.SimpleObjectProperty import javafx.stage.FileChooser import org.springframework.stereotype.Component @@ -17,8 +16,6 @@ import kotlin.collections.set @Component class MainController : Controller() { - // In the future it'll be pulled from TileSetService or something like that - private val tileset = TileSet(resources.image("/textures/tileset.png"), 160, 8) private val projectManager: ProjectManager by di() val openProject = SimpleObjectProperty() diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/model/map/GameMapBuilder.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/model/map/GameMapBuilder.kt index dcbc280c..0ae249fe 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/model/map/GameMapBuilder.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/model/map/GameMapBuilder.kt @@ -7,16 +7,16 @@ import javafx.beans.property.SimpleStringProperty import tornadofx.* class GameMapBuilder { - val tileSetProperty = SimpleObjectProperty(TILESET) + val tileSetProperty = SimpleObjectProperty() var tileSet by tileSetProperty val nameProperty = SimpleStringProperty("") var name by nameProperty - val rowsProperty = SimpleIntegerProperty(1) + val rowsProperty = SimpleIntegerProperty(20) var rows by rowsProperty - val columnsProperty = SimpleIntegerProperty(1) + val columnsProperty = SimpleIntegerProperty(20) var columns by columnsProperty fun build() = GameMap(tileSet).apply { @@ -24,9 +24,4 @@ class GameMapBuilder { rows = this@GameMapBuilder.rows columns = this@GameMapBuilder.columns } - - companion object { - // TODO(Hardcoded tileset here - to remove when tileset is choosable from map creation wizard) - private val TILESET = TileSet(ResourceLookup(this).image("/textures/tileset.png"), 160, 8) - } } \ No newline at end of file diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/serial/ProtobufMapDeserializer.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/serial/ProtobufMapDeserializer.kt index 0f60a96c..4f267f37 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/serial/ProtobufMapDeserializer.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/serial/ProtobufMapDeserializer.kt @@ -13,7 +13,7 @@ import java.io.InputStream @Component class ProtobufMapDeserializer : MapDeserializer { private val resources = ResourceLookup(this) - private val tileset = TileSet(resources.image("/textures/tileset.png"), 160, 8) + private val tileset = TileSet("Test TileSet", resources.image("/textures/tileset.png"), 160, 8) override fun deserialize(input: InputStream): GameMap { val map = GameMap(tileset) diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/wizard/MapCreationWizard.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/wizard/MapCreationWizard.kt index 15efaa3c..675a2909 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/wizard/MapCreationWizard.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/wizard/MapCreationWizard.kt @@ -15,10 +15,4 @@ class MapCreationWizard : Wizard("New Map", "Provide map information") { add(MapCreationBasicDataView::class) add(MapTileSetSelectionView::class) } - - override fun onSave() { - if(mapBuilderVM.commit()) { - super.onSave() - } - } } \ No newline at end of file diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/wizard/MapTileSetSelectionView.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/wizard/MapTileSetSelectionView.kt index 35df3240..23b59869 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/wizard/MapTileSetSelectionView.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/wizard/MapTileSetSelectionView.kt @@ -1,25 +1,42 @@ package com.bartlomiejpluta.base.editor.map.view.wizard -import tornadofx.View -import tornadofx.hbox -import tornadofx.listview +import com.bartlomiejpluta.base.editor.map.viewmodel.GameMapBuilderVM +import com.bartlomiejpluta.base.editor.tileset.model.TileSet +import javafx.scene.control.ListView +import tornadofx.* class MapTileSetSelectionView : View("Tile Set") { + private val mapBuilderVM = find() + + private var tileSetsListView: ListView by singleAssign() + + // TODO(Fetch it from project assets) + private val tileSets = listOf( + TileSet("Big TileSet", resources.image("/textures/tileset.png"), 160, 8), + TileSet("Mage City", resources.image("/textures/magecity.png"), 44, 8) + ).asObservable() + + + // FIXME + // It's kind of ugly solution because for some reason + // the custom validator on tileSetsListView does not work here. + // Desired solution should use mapBuilderVM.valid(mapBuilderVM.tileSetProperty) + // as in the previous step of the wizard as well as the feedback for user + // saying, that tile set field is required. + override val complete = mapBuilderVM.tileSetProperty.isNotNull - // TODO(Implement tileset selection) override val root = hbox { - listview { - items.add("TileSet 1") - items.add("TileSet 2") - items.add("TileSet 3") - items.add("TileSet 4") - items.add("TileSet 5") - items.add("TileSet 6") - items.add("TileSet 7") - items.add("TileSet 8") - items.add("TileSet 9") - items.add("TileSet 10") - items.add("TileSet 11") + prefWidth = 640.0 + + tileSetsListView = listview(tileSets) { + cellFormat { text = it.name } + bindSelected(mapBuilderVM.tileSetProperty) + } + + scrollpane { + prefWidthProperty().bind(mapBuilderVM.tileSetProperty.select { it.widthProperty }) + prefHeightProperty().bind(tileSetsListView.heightProperty()) + imageview(mapBuilderVM.tileSetProperty.select { it.imageProperty }) } } } \ No newline at end of file diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/tileset/model/TileSet.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/tileset/model/TileSet.kt index 813409b3..8917caa7 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/tileset/model/TileSet.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/tileset/model/TileSet.kt @@ -2,6 +2,8 @@ package com.bartlomiejpluta.base.editor.tileset.model import com.bartlomiejpluta.base.editor.map.model.brush.Brush import javafx.beans.property.SimpleIntegerProperty +import javafx.beans.property.SimpleObjectProperty +import javafx.beans.property.SimpleStringProperty import javafx.scene.image.Image import javafx.scene.image.PixelFormat import javafx.scene.image.WritableImage @@ -10,7 +12,13 @@ import tornadofx.toObservable import java.nio.ByteBuffer -class TileSet(private val image: Image, rows: Int, columns: Int) { +class TileSet(name: String, image: Image, rows: Int, columns: Int) { + val nameProperty = SimpleStringProperty(name) + val name by nameProperty + + val imageProperty = SimpleObjectProperty(image) + val image by imageProperty + val rowsProperty = SimpleIntegerProperty(rows) val rows by rowsProperty