[Editor] Implement TileSet selection in map creation wizard
This commit is contained in:
@@ -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<Project?>()
|
||||
|
||||
@@ -7,16 +7,16 @@ import javafx.beans.property.SimpleStringProperty
|
||||
import tornadofx.*
|
||||
|
||||
class GameMapBuilder {
|
||||
val tileSetProperty = SimpleObjectProperty(TILESET)
|
||||
val tileSetProperty = SimpleObjectProperty<TileSet>()
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<GameMapBuilderVM>()
|
||||
|
||||
private var tileSetsListView: ListView<TileSet> 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<String> {
|
||||
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 })
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user