[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.model.Project
|
||||||
import com.bartlomiejpluta.base.editor.project.view.ProjectSettingsFragment
|
import com.bartlomiejpluta.base.editor.project.view.ProjectSettingsFragment
|
||||||
import com.bartlomiejpluta.base.editor.project.viewmodel.ProjectVM
|
import com.bartlomiejpluta.base.editor.project.viewmodel.ProjectVM
|
||||||
import com.bartlomiejpluta.base.editor.tileset.model.TileSet
|
|
||||||
import javafx.beans.property.SimpleObjectProperty
|
import javafx.beans.property.SimpleObjectProperty
|
||||||
import javafx.stage.FileChooser
|
import javafx.stage.FileChooser
|
||||||
import org.springframework.stereotype.Component
|
import org.springframework.stereotype.Component
|
||||||
@@ -17,8 +16,6 @@ import kotlin.collections.set
|
|||||||
|
|
||||||
@Component
|
@Component
|
||||||
class MainController : Controller() {
|
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()
|
private val projectManager: ProjectManager by di()
|
||||||
|
|
||||||
val openProject = SimpleObjectProperty<Project?>()
|
val openProject = SimpleObjectProperty<Project?>()
|
||||||
|
|||||||
@@ -7,16 +7,16 @@ import javafx.beans.property.SimpleStringProperty
|
|||||||
import tornadofx.*
|
import tornadofx.*
|
||||||
|
|
||||||
class GameMapBuilder {
|
class GameMapBuilder {
|
||||||
val tileSetProperty = SimpleObjectProperty(TILESET)
|
val tileSetProperty = SimpleObjectProperty<TileSet>()
|
||||||
var tileSet by tileSetProperty
|
var tileSet by tileSetProperty
|
||||||
|
|
||||||
val nameProperty = SimpleStringProperty("")
|
val nameProperty = SimpleStringProperty("")
|
||||||
var name by nameProperty
|
var name by nameProperty
|
||||||
|
|
||||||
val rowsProperty = SimpleIntegerProperty(1)
|
val rowsProperty = SimpleIntegerProperty(20)
|
||||||
var rows by rowsProperty
|
var rows by rowsProperty
|
||||||
|
|
||||||
val columnsProperty = SimpleIntegerProperty(1)
|
val columnsProperty = SimpleIntegerProperty(20)
|
||||||
var columns by columnsProperty
|
var columns by columnsProperty
|
||||||
|
|
||||||
fun build() = GameMap(tileSet).apply {
|
fun build() = GameMap(tileSet).apply {
|
||||||
@@ -24,9 +24,4 @@ class GameMapBuilder {
|
|||||||
rows = this@GameMapBuilder.rows
|
rows = this@GameMapBuilder.rows
|
||||||
columns = this@GameMapBuilder.columns
|
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
|
@Component
|
||||||
class ProtobufMapDeserializer : MapDeserializer {
|
class ProtobufMapDeserializer : MapDeserializer {
|
||||||
private val resources = ResourceLookup(this)
|
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 {
|
override fun deserialize(input: InputStream): GameMap {
|
||||||
val map = GameMap(tileset)
|
val map = GameMap(tileset)
|
||||||
|
|||||||
@@ -15,10 +15,4 @@ class MapCreationWizard : Wizard("New Map", "Provide map information") {
|
|||||||
add(MapCreationBasicDataView::class)
|
add(MapCreationBasicDataView::class)
|
||||||
add(MapTileSetSelectionView::class)
|
add(MapTileSetSelectionView::class)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSave() {
|
|
||||||
if(mapBuilderVM.commit()) {
|
|
||||||
super.onSave()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,25 +1,42 @@
|
|||||||
package com.bartlomiejpluta.base.editor.map.view.wizard
|
package com.bartlomiejpluta.base.editor.map.view.wizard
|
||||||
|
|
||||||
import tornadofx.View
|
import com.bartlomiejpluta.base.editor.map.viewmodel.GameMapBuilderVM
|
||||||
import tornadofx.hbox
|
import com.bartlomiejpluta.base.editor.tileset.model.TileSet
|
||||||
import tornadofx.listview
|
import javafx.scene.control.ListView
|
||||||
|
import tornadofx.*
|
||||||
|
|
||||||
class MapTileSetSelectionView : View("Tile Set") {
|
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 {
|
override val root = hbox {
|
||||||
listview<String> {
|
prefWidth = 640.0
|
||||||
items.add("TileSet 1")
|
|
||||||
items.add("TileSet 2")
|
tileSetsListView = listview(tileSets) {
|
||||||
items.add("TileSet 3")
|
cellFormat { text = it.name }
|
||||||
items.add("TileSet 4")
|
bindSelected(mapBuilderVM.tileSetProperty)
|
||||||
items.add("TileSet 5")
|
}
|
||||||
items.add("TileSet 6")
|
|
||||||
items.add("TileSet 7")
|
scrollpane {
|
||||||
items.add("TileSet 8")
|
prefWidthProperty().bind(mapBuilderVM.tileSetProperty.select { it.widthProperty })
|
||||||
items.add("TileSet 9")
|
prefHeightProperty().bind(tileSetsListView.heightProperty())
|
||||||
items.add("TileSet 10")
|
imageview(mapBuilderVM.tileSetProperty.select { it.imageProperty })
|
||||||
items.add("TileSet 11")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,8 @@ package com.bartlomiejpluta.base.editor.tileset.model
|
|||||||
|
|
||||||
import com.bartlomiejpluta.base.editor.map.model.brush.Brush
|
import com.bartlomiejpluta.base.editor.map.model.brush.Brush
|
||||||
import javafx.beans.property.SimpleIntegerProperty
|
import javafx.beans.property.SimpleIntegerProperty
|
||||||
|
import javafx.beans.property.SimpleObjectProperty
|
||||||
|
import javafx.beans.property.SimpleStringProperty
|
||||||
import javafx.scene.image.Image
|
import javafx.scene.image.Image
|
||||||
import javafx.scene.image.PixelFormat
|
import javafx.scene.image.PixelFormat
|
||||||
import javafx.scene.image.WritableImage
|
import javafx.scene.image.WritableImage
|
||||||
@@ -10,7 +12,13 @@ import tornadofx.toObservable
|
|||||||
import java.nio.ByteBuffer
|
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 rowsProperty = SimpleIntegerProperty(rows)
|
||||||
val rows by rowsProperty
|
val rows by rowsProperty
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user