[Editor] Create map creation wizard scaffolding
This commit is contained in:
@@ -2,7 +2,8 @@ package com.bartlomiejpluta.base.editor.main.controller
|
||||
|
||||
import com.bartlomiejpluta.base.editor.command.context.UndoableScope
|
||||
import com.bartlomiejpluta.base.editor.map.model.map.GameMap
|
||||
import com.bartlomiejpluta.base.editor.map.view.MapSettingsFragment
|
||||
import com.bartlomiejpluta.base.editor.map.view.MapCreationWizard
|
||||
import com.bartlomiejpluta.base.editor.map.viewmodel.GameMapBuilderVM
|
||||
import com.bartlomiejpluta.base.editor.map.viewmodel.GameMapVM
|
||||
import com.bartlomiejpluta.base.editor.project.manager.ProjectManager
|
||||
import com.bartlomiejpluta.base.editor.project.model.Project
|
||||
@@ -38,15 +39,16 @@ class MainController : Controller() {
|
||||
}
|
||||
|
||||
fun createEmptyMap() {
|
||||
val map = GameMap(tileset)
|
||||
val scope = UndoableScope()
|
||||
val vm = GameMapVM(map)
|
||||
val vm = GameMapBuilderVM()
|
||||
setInScope(vm, scope)
|
||||
|
||||
val modal = find<MapSettingsFragment>(scope).apply { openModal(block = true, resizable = false) }
|
||||
|
||||
if (modal.result) {
|
||||
openMaps[scope] = map
|
||||
find<MapCreationWizard>(scope).apply {
|
||||
onComplete {
|
||||
openMaps[scope] = vm.item.build()
|
||||
}
|
||||
|
||||
openModal(block = true)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.bartlomiejpluta.base.editor.main.view
|
||||
|
||||
import com.bartlomiejpluta.base.editor.main.controller.MainController
|
||||
import com.bartlomiejpluta.base.editor.map.view.MapFragment
|
||||
import com.bartlomiejpluta.base.editor.map.viewmodel.GameMapVM
|
||||
import javafx.scene.control.Tab
|
||||
import tornadofx.*
|
||||
|
||||
@@ -24,6 +25,8 @@ class MainView : View("BASE Game Editor") {
|
||||
center = tabpane {
|
||||
tabs.bind(mainController.openMaps) { scope, map ->
|
||||
Tab().apply {
|
||||
val vm = GameMapVM(map)
|
||||
setInScope(vm, scope)
|
||||
textProperty().bindBidirectional(map.nameProperty)
|
||||
content = find<MapFragment>(scope).root
|
||||
setOnClosed { mainController.openMaps.remove(scope) }
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.bartlomiejpluta.base.editor.map.model.map
|
||||
|
||||
import com.bartlomiejpluta.base.editor.tileset.model.TileSet
|
||||
import javafx.beans.property.SimpleIntegerProperty
|
||||
import javafx.beans.property.SimpleObjectProperty
|
||||
import javafx.beans.property.SimpleStringProperty
|
||||
import tornadofx.*
|
||||
|
||||
class GameMapBuilder {
|
||||
val tileSetProperty = SimpleObjectProperty(TILESET)
|
||||
var tileSet by tileSetProperty
|
||||
|
||||
val nameProperty = SimpleStringProperty("")
|
||||
var name by nameProperty
|
||||
|
||||
val rowsProperty = SimpleIntegerProperty(1)
|
||||
var rows by rowsProperty
|
||||
|
||||
val columnsProperty = SimpleIntegerProperty(1)
|
||||
var columns by columnsProperty
|
||||
|
||||
fun build() = GameMap(tileSet).apply {
|
||||
name = this@GameMapBuilder.name
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,9 @@ package com.bartlomiejpluta.base.editor.map.view
|
||||
import com.bartlomiejpluta.base.editor.command.context.UndoableScope
|
||||
import com.bartlomiejpluta.base.editor.command.service.UndoRedoService
|
||||
import com.bartlomiejpluta.base.editor.map.viewmodel.GameMapVM
|
||||
import org.kordamp.ikonli.javafx.FontIcon
|
||||
import tornadofx.*
|
||||
|
||||
class MapSettingsFragment : Fragment("Map Settings") {
|
||||
class MapBasicDataSettingsFragment : Fragment("Map Settings") {
|
||||
override val scope = super.scope as UndoableScope
|
||||
private val undoRedoService: UndoRedoService by di()
|
||||
|
||||
@@ -16,8 +15,6 @@ class MapSettingsFragment : Fragment("Map Settings") {
|
||||
private set
|
||||
|
||||
override val root = form {
|
||||
icon = FontIcon("fa-map-o")
|
||||
|
||||
fieldset("Map Settings") {
|
||||
field("Map name") {
|
||||
textfield(mapVM.nameProperty) {
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.bartlomiejpluta.base.editor.map.view
|
||||
|
||||
import com.bartlomiejpluta.base.editor.map.viewmodel.GameMapBuilderVM
|
||||
import tornadofx.*
|
||||
|
||||
class MapCreationBasicDataView : View("Basic Data") {
|
||||
private val mapBuilderVM = find<GameMapBuilderVM>()
|
||||
|
||||
override val complete = mapBuilderVM.valid(mapBuilderVM.nameProperty, mapBuilderVM.rowsProperty, mapBuilderVM.columnsProperty)
|
||||
|
||||
override val root = form {
|
||||
fieldset("Map Settings") {
|
||||
field("Map name") {
|
||||
textfield(mapBuilderVM.nameProperty) {
|
||||
required()
|
||||
whenDocked { requestFocus() }
|
||||
}
|
||||
}
|
||||
|
||||
field("Rows") {
|
||||
|
||||
textfield(mapBuilderVM.rowsProperty) {
|
||||
stripNonInteger()
|
||||
required()
|
||||
validator {
|
||||
when (it?.toIntOrNull()) {
|
||||
in 1..50 -> null
|
||||
in 50..100 -> warning("The map sizes over 50 can impact game performance")
|
||||
else -> error("The map size must be between 1 and 100")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
field("Columns") {
|
||||
textfield(mapBuilderVM.columnsProperty) {
|
||||
stripNonInteger()
|
||||
required()
|
||||
validator {
|
||||
when (it?.toIntOrNull()) {
|
||||
in 1..50 -> null
|
||||
in 50..100 -> warning("The map sizes over 50 can impact game performance")
|
||||
else -> error("The map size must be between 1 and 100")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.bartlomiejpluta.base.editor.map.view
|
||||
|
||||
import com.bartlomiejpluta.base.editor.map.viewmodel.GameMapBuilderVM
|
||||
import org.kordamp.ikonli.javafx.FontIcon
|
||||
import tornadofx.Wizard
|
||||
|
||||
class MapCreationWizard : Wizard("New Map", "Provide map information") {
|
||||
private val mapBuilderVM = find<GameMapBuilderVM>()
|
||||
|
||||
init {
|
||||
graphic = FontIcon("fa-map").apply {
|
||||
iconSize = 40
|
||||
}
|
||||
|
||||
add(MapCreationBasicDataView::class)
|
||||
add(MapTileSetSelectionView::class)
|
||||
}
|
||||
|
||||
override fun onSave() {
|
||||
if(mapBuilderVM.commit()) {
|
||||
super.onSave()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.bartlomiejpluta.base.editor.map.view
|
||||
|
||||
import tornadofx.View
|
||||
import tornadofx.hbox
|
||||
import tornadofx.listview
|
||||
|
||||
class MapTileSetSelectionView : View("Tile Set") {
|
||||
|
||||
// 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")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -98,7 +98,7 @@ class MapToolbarView : View() {
|
||||
|
||||
button(graphic = FontIcon("fa-sliders")) {
|
||||
action {
|
||||
find<MapSettingsFragment>().openModal(block = true, resizable = false)
|
||||
find<MapBasicDataSettingsFragment>().openModal(block = true, resizable = false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.bartlomiejpluta.base.editor.map.viewmodel
|
||||
|
||||
import com.bartlomiejpluta.base.editor.map.model.map.GameMapBuilder
|
||||
import tornadofx.ItemViewModel
|
||||
import tornadofx.getValue
|
||||
import tornadofx.setValue
|
||||
|
||||
class GameMapBuilderVM : ItemViewModel<GameMapBuilder>(GameMapBuilder()) {
|
||||
val tileSetProperty = bind(GameMapBuilder::tileSetProperty, autocommit = true)
|
||||
var tileSet by tileSetProperty
|
||||
|
||||
val nameProperty = bind(GameMapBuilder::nameProperty, autocommit = true)
|
||||
var name by nameProperty
|
||||
|
||||
val rowsProperty = bind(GameMapBuilder::rowsProperty, autocommit = true)
|
||||
var rows by rowsProperty
|
||||
|
||||
val columnsProperty = bind(GameMapBuilder::columnsProperty, autocommit = true)
|
||||
var columns by columnsProperty
|
||||
}
|
||||
Reference in New Issue
Block a user