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 248a5cfe..89c53305 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 @@ -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(scope).apply { openModal(block = true, resizable = false) } - - if (modal.result) { - openMaps[scope] = map + find(scope).apply { + onComplete { + openMaps[scope] = vm.item.build() + } + + openModal(block = true) } } diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/main/view/MainView.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/main/view/MainView.kt index a49718b2..e7437687 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/main/view/MainView.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/main/view/MainView.kt @@ -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(scope).root setOnClosed { mainController.openMaps.remove(scope) } 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 new file mode 100644 index 00000000..dcbc280c --- /dev/null +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/model/map/GameMapBuilder.kt @@ -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) + } +} \ No newline at end of file diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/MapSettingsFragment.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/MapBasicDataSettingsFragment.kt similarity index 94% rename from editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/MapSettingsFragment.kt rename to editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/MapBasicDataSettingsFragment.kt index 1001376d..ea101f25 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/MapSettingsFragment.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/MapBasicDataSettingsFragment.kt @@ -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) { diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/MapCreationBasicDataView.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/MapCreationBasicDataView.kt new file mode 100644 index 00000000..70a5c40a --- /dev/null +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/MapCreationBasicDataView.kt @@ -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() + + 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") + } + } + } + } + } + } +} \ No newline at end of file diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/MapCreationWizard.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/MapCreationWizard.kt new file mode 100644 index 00000000..176056a1 --- /dev/null +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/MapCreationWizard.kt @@ -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() + + init { + graphic = FontIcon("fa-map").apply { + iconSize = 40 + } + + 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/MapTileSetSelectionView.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/MapTileSetSelectionView.kt new file mode 100644 index 00000000..23712884 --- /dev/null +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/MapTileSetSelectionView.kt @@ -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 { + 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") + } + } +} \ No newline at end of file diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/MapToolbarView.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/MapToolbarView.kt index 347de2bb..683f72ef 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/MapToolbarView.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/MapToolbarView.kt @@ -98,7 +98,7 @@ class MapToolbarView : View() { button(graphic = FontIcon("fa-sliders")) { action { - find().openModal(block = true, resizable = false) + find().openModal(block = true, resizable = false) } } } diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/viewmodel/GameMapBuilderVM.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/viewmodel/GameMapBuilderVM.kt new file mode 100644 index 00000000..3a2c6061 --- /dev/null +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/viewmodel/GameMapBuilderVM.kt @@ -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()) { + 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 +} \ No newline at end of file