[Editor] Use SelectGraphicAssetView in MapCreationWizard (tileset selection step)

This commit is contained in:
2021-02-19 20:49:52 +01:00
parent 668cde7eec
commit d2bb1b99f6
4 changed files with 19 additions and 44 deletions

View File

@@ -44,10 +44,10 @@ class MainController : Controller() {
find<MapCreationWizard>(scope).apply {
onComplete {
vm.item.build().let { map ->
projectContext.importMap(vm.name, map)
openMaps[scope] = map
}
val tileSet = projectContext.loadTileSet(vm.tileSetAsset.uid)
val map = GameMap(tileSet)
projectContext.importMap(vm.name, map)
openMaps[scope] = map
}
openModal(block = true, resizable = false)

View File

@@ -1,14 +1,15 @@
package com.bartlomiejpluta.base.editor.map.model.map
import com.bartlomiejpluta.base.editor.tileset.model.TileSet
import com.bartlomiejpluta.base.editor.tileset.asset.TileSetAsset
import javafx.beans.property.SimpleIntegerProperty
import javafx.beans.property.SimpleObjectProperty
import javafx.beans.property.SimpleStringProperty
import tornadofx.*
import tornadofx.getValue
import tornadofx.setValue
class GameMapBuilder {
val tileSetProperty = SimpleObjectProperty<TileSet>()
var tileSet by tileSetProperty
val tileSetAssetProperty = SimpleObjectProperty<TileSetAsset>()
var tileSetAsset by tileSetAssetProperty
val nameProperty = SimpleStringProperty("")
var name by nameProperty
@@ -18,9 +19,4 @@ class GameMapBuilder {
val columnsProperty = SimpleIntegerProperty(20)
var columns by columnsProperty
fun build() = GameMap(tileSet).apply {
this.rows = this@GameMapBuilder.rows
this.columns = this@GameMapBuilder.columns
}
}

View File

@@ -1,27 +1,19 @@
package com.bartlomiejpluta.base.editor.map.view.wizard
import com.bartlomiejpluta.base.editor.asset.model.Asset
import com.bartlomiejpluta.base.editor.asset.view.select.SelectGraphicAssetView
import com.bartlomiejpluta.base.editor.map.viewmodel.GameMapBuilderVM
import com.bartlomiejpluta.base.editor.project.context.ProjectContext
import com.bartlomiejpluta.base.editor.tileset.model.TileSet
import javafx.scene.control.ListView
import tornadofx.*
import tornadofx.View
class MapTileSetSelectionView : View("Tile Set") {
private val mapBuilderVM = find<GameMapBuilderVM>()
private var tileSetsListView: ListView<TileSet> by singleAssign()
private val projectContext: ProjectContext by di()
// FIXME
// Because of loading all the images at once and storing them in cache
// this solution is not best efficient. It could be better to store images
// in the local cache, scoped to this view.
private val tileSets =
projectContext.project?.tileSets?.map(Asset::uid)?.map(projectContext::loadTileSet)?.asObservable()
?: throw IllegalStateException("There is no open project in the context")
private val selectGraphicAssetView = find<SelectGraphicAssetView>(
SelectGraphicAssetView::assets to projectContext.project!!.tileSets,
SelectGraphicAssetView::asset to mapBuilderVM.tileSetAssetProperty
)
// FIXME
// It's kind of ugly solution because for some reason
@@ -29,20 +21,7 @@ class MapTileSetSelectionView : View("Tile Set") {
// 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
override val complete = mapBuilderVM.tileSetAssetProperty.isNotNull
override val root = hbox {
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 })
}
}
override val root = selectGraphicAssetView.root
}

View File

@@ -6,8 +6,8 @@ import tornadofx.getValue
import tornadofx.setValue
class GameMapBuilderVM : ItemViewModel<GameMapBuilder>(GameMapBuilder()) {
val tileSetProperty = bind(GameMapBuilder::tileSetProperty, autocommit = true)
var tileSet by tileSetProperty
val tileSetAssetProperty = bind(GameMapBuilder::tileSetAssetProperty, autocommit = true)
var tileSetAsset by tileSetAssetProperty
val nameProperty = bind(GameMapBuilder::nameProperty, autocommit = true)
var name by nameProperty