[Editor] Create working base for creating map dialog
This commit is contained in:
@@ -0,0 +1,34 @@
|
|||||||
|
package com.bartlomiejpluta.base.editor.controller.main
|
||||||
|
|
||||||
|
import com.bartlomiejpluta.base.editor.command.context.UndoableScope
|
||||||
|
import com.bartlomiejpluta.base.editor.model.map.map.GameMap
|
||||||
|
import com.bartlomiejpluta.base.editor.model.tileset.TileSet
|
||||||
|
import com.bartlomiejpluta.base.editor.view.map.MapSettingsFragment
|
||||||
|
import com.bartlomiejpluta.base.editor.viewmodel.map.GameMapVM
|
||||||
|
import org.springframework.stereotype.Component
|
||||||
|
import tornadofx.Controller
|
||||||
|
import tornadofx.Scope
|
||||||
|
import tornadofx.find
|
||||||
|
import tornadofx.observableMapOf
|
||||||
|
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)
|
||||||
|
|
||||||
|
val openMaps = observableMapOf<Scope, GameMap>()
|
||||||
|
|
||||||
|
fun createEmptyMap() {
|
||||||
|
val map = GameMap(tileset).apply { name = "Unnamed" }
|
||||||
|
val scope = UndoableScope()
|
||||||
|
val vm = GameMapVM(map)
|
||||||
|
setInScope(vm, scope)
|
||||||
|
|
||||||
|
val modal = find<MapSettingsFragment>(scope).apply { openModal(block = true, resizable = false) }
|
||||||
|
|
||||||
|
if (modal.result) {
|
||||||
|
openMaps[scope] = map
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
package com.bartlomiejpluta.base.editor.controller.map
|
|
||||||
|
|
||||||
import com.bartlomiejpluta.base.editor.controller.tileset.TileSetController
|
|
||||||
import com.bartlomiejpluta.base.editor.model.map.map.GameMap
|
|
||||||
import com.bartlomiejpluta.base.editor.model.tileset.TileSet
|
|
||||||
import org.springframework.stereotype.Component
|
|
||||||
import tornadofx.Controller
|
|
||||||
|
|
||||||
@Component
|
|
||||||
class MapController : Controller() {
|
|
||||||
private val tileSetController: TileSetController by inject()
|
|
||||||
|
|
||||||
fun createMap(tileSet: TileSet, rows: Int, columns: Int) = GameMap(tileSet, rows, columns)
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package com.bartlomiejpluta.base.editor.controller.tileset
|
|
||||||
|
|
||||||
import com.bartlomiejpluta.base.editor.model.tileset.TileSet
|
|
||||||
import org.springframework.stereotype.Component
|
|
||||||
import tornadofx.Controller
|
|
||||||
|
|
||||||
@Component
|
|
||||||
class TileSetController : Controller() {
|
|
||||||
val tileset = TileSet(resources.image("/textures/tileset.png"), 160, 8)
|
|
||||||
}
|
|
||||||
@@ -4,28 +4,32 @@ import com.bartlomiejpluta.base.editor.model.map.layer.Layer
|
|||||||
import com.bartlomiejpluta.base.editor.model.tileset.TileSet
|
import com.bartlomiejpluta.base.editor.model.tileset.TileSet
|
||||||
import javafx.beans.property.SimpleDoubleProperty
|
import javafx.beans.property.SimpleDoubleProperty
|
||||||
import javafx.beans.property.SimpleIntegerProperty
|
import javafx.beans.property.SimpleIntegerProperty
|
||||||
|
import javafx.beans.property.SimpleStringProperty
|
||||||
import tornadofx.getValue
|
import tornadofx.getValue
|
||||||
import tornadofx.observableListOf
|
import tornadofx.observableListOf
|
||||||
import tornadofx.setValue
|
import tornadofx.setValue
|
||||||
|
|
||||||
|
|
||||||
class GameMap(val tileSet: TileSet, initialColumns: Int, initialRows: Int) {
|
class GameMap(val tileSet: TileSet) {
|
||||||
val layers = observableListOf<Layer>()
|
val layers = observableListOf<Layer>()
|
||||||
|
|
||||||
|
val nameProperty = SimpleStringProperty()
|
||||||
|
var name by nameProperty
|
||||||
|
|
||||||
val tileWidth = tileSet.tileWidth.toDouble()
|
val tileWidth = tileSet.tileWidth.toDouble()
|
||||||
val tileHeight = tileSet.tileHeight.toDouble()
|
val tileHeight = tileSet.tileHeight.toDouble()
|
||||||
|
|
||||||
val rowsProperty = SimpleIntegerProperty(initialRows)
|
val rowsProperty = SimpleIntegerProperty(INITIAL_ROWS)
|
||||||
val rows by rowsProperty
|
val rows by rowsProperty
|
||||||
|
|
||||||
val columnsProperty = SimpleIntegerProperty(initialColumns)
|
val columnsProperty = SimpleIntegerProperty(INITIAL_COLUMNS)
|
||||||
val columns by columnsProperty
|
val columns by columnsProperty
|
||||||
|
|
||||||
val widthProperty = SimpleDoubleProperty(initialColumns * tileWidth)
|
val widthProperty = SimpleDoubleProperty(INITIAL_COLUMNS * tileWidth)
|
||||||
var width by widthProperty
|
var width by widthProperty
|
||||||
private set
|
private set
|
||||||
|
|
||||||
val heightProperty = SimpleDoubleProperty(initialRows * tileHeight)
|
val heightProperty = SimpleDoubleProperty(INITIAL_ROWS * tileHeight)
|
||||||
var height by heightProperty
|
var height by heightProperty
|
||||||
private set
|
private set
|
||||||
|
|
||||||
@@ -42,4 +46,9 @@ class GameMap(val tileSet: TileSet, initialColumns: Int, initialRows: Int) {
|
|||||||
layers.forEach { it.resize(rows, newColumns) }
|
layers.forEach { it.resize(rows, newColumns) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val INITIAL_ROWS = 20
|
||||||
|
private const val INITIAL_COLUMNS = 20
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.bartlomiejpluta.base.editor.view.main
|
||||||
|
|
||||||
|
import com.bartlomiejpluta.base.editor.controller.main.MainController
|
||||||
|
import com.bartlomiejpluta.base.editor.view.map.MapSettingsFragment
|
||||||
|
import tornadofx.*
|
||||||
|
|
||||||
|
class MainMenuView : View() {
|
||||||
|
private val mainController: MainController by di()
|
||||||
|
|
||||||
|
override val root = menubar {
|
||||||
|
menu("File") {
|
||||||
|
menu("New") {
|
||||||
|
item("Project...")
|
||||||
|
item("Map...") {
|
||||||
|
action {
|
||||||
|
mainController.createEmptyMap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
menu("Edit") {
|
||||||
|
item("Undo")
|
||||||
|
item("Redo")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,32 +1,25 @@
|
|||||||
package com.bartlomiejpluta.base.editor.view.main
|
package com.bartlomiejpluta.base.editor.view.main
|
||||||
|
|
||||||
import com.bartlomiejpluta.base.editor.command.context.UndoableScope
|
import com.bartlomiejpluta.base.editor.controller.main.MainController
|
||||||
import com.bartlomiejpluta.base.editor.controller.map.MapController
|
|
||||||
import com.bartlomiejpluta.base.editor.controller.tileset.TileSetController
|
|
||||||
import com.bartlomiejpluta.base.editor.view.map.MapFragment
|
import com.bartlomiejpluta.base.editor.view.map.MapFragment
|
||||||
import javafx.scene.control.TabPane
|
import javafx.scene.control.Tab
|
||||||
import org.kordamp.ikonli.javafx.FontIcon
|
|
||||||
import tornadofx.*
|
import tornadofx.*
|
||||||
|
|
||||||
|
|
||||||
class MainView : View() {
|
class MainView : View("BASE Game Editor") {
|
||||||
private val mapController: MapController by di()
|
private val mainController: MainController by di()
|
||||||
private val tileSetController: TileSetController by di()
|
|
||||||
private val tabPane = TabPane()
|
private val mainMenuView = find<MainMenuView>()
|
||||||
|
|
||||||
override val root = borderpane {
|
override val root = borderpane {
|
||||||
top = toolbar {
|
top = mainMenuView.root
|
||||||
button(graphic = FontIcon("fa-file-o")) {
|
|
||||||
action {
|
center = tabpane {
|
||||||
val tileSet = tileSetController.tileset
|
tabs.bind(mainController.openMaps) { scope, map ->
|
||||||
val map = mapController.createMap(tileSet, 5, 5)
|
Tab(map.name, find<MapFragment>(scope).root).apply {
|
||||||
tabPane += find<MapFragment>(UndoableScope(), MapFragment::map to map).apply {
|
setOnClosed { mainController.openMaps.remove(scope) }
|
||||||
title = "Map 1"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
center = tabPane
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,25 +1,18 @@
|
|||||||
package com.bartlomiejpluta.base.editor.view.map
|
package com.bartlomiejpluta.base.editor.view.map
|
||||||
|
|
||||||
import com.bartlomiejpluta.base.editor.command.context.UndoableScope
|
import com.bartlomiejpluta.base.editor.command.context.UndoableScope
|
||||||
import com.bartlomiejpluta.base.editor.model.map.map.GameMap
|
|
||||||
import com.bartlomiejpluta.base.editor.viewmodel.map.GameMapVM
|
|
||||||
import tornadofx.*
|
import tornadofx.*
|
||||||
|
|
||||||
|
|
||||||
class MapFragment : Fragment() {
|
class MapFragment : Fragment() {
|
||||||
override val scope = super.scope as UndoableScope
|
override val scope = super.scope as UndoableScope
|
||||||
|
|
||||||
val map: GameMap by param()
|
|
||||||
|
|
||||||
private val mapVM = find<GameMapVM>().apply { item = map }
|
|
||||||
|
|
||||||
private val mapView = find<MapView>()
|
private val mapView = find<MapView>()
|
||||||
private val layersView = find<MapLayersView>()
|
private val layersView = find<MapLayersView>()
|
||||||
private val tileSetView = find<TileSetView>()
|
private val tileSetView = find<TileSetView>()
|
||||||
private val toolbarView = find<MapToolbarView>()
|
private val toolbarView = find<MapToolbarView>()
|
||||||
private val statusBarView = find<MapStatusBarView>()
|
private val statusBarView = find<MapStatusBarView>()
|
||||||
|
|
||||||
|
|
||||||
override val root = borderpane {
|
override val root = borderpane {
|
||||||
top = toolbarView.root
|
top = toolbarView.root
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package com.bartlomiejpluta.base.editor.view.map
|
||||||
|
|
||||||
|
import com.bartlomiejpluta.base.editor.viewmodel.map.GameMapVM
|
||||||
|
import org.kordamp.ikonli.javafx.FontIcon
|
||||||
|
import tornadofx.*
|
||||||
|
|
||||||
|
class MapSettingsFragment : Fragment("Map Settings") {
|
||||||
|
private val mapVM = find<GameMapVM>()
|
||||||
|
|
||||||
|
var result: Boolean = false
|
||||||
|
private set
|
||||||
|
|
||||||
|
override val root = form {
|
||||||
|
icon = FontIcon("fa-map-o")
|
||||||
|
|
||||||
|
fieldset("Map Settings") {
|
||||||
|
field("Map name") {
|
||||||
|
textfield(mapVM.nameProperty) {
|
||||||
|
required()
|
||||||
|
whenDocked { requestFocus() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
field("Rows") {
|
||||||
|
|
||||||
|
textfield(mapVM.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(mapVM.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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buttonbar {
|
||||||
|
button("Ok") {
|
||||||
|
shortcut("Enter")
|
||||||
|
|
||||||
|
action {
|
||||||
|
mapVM.commit {
|
||||||
|
result = true
|
||||||
|
close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
button("Reset") {
|
||||||
|
action {
|
||||||
|
mapVM.rollback()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
button("Cancel") {
|
||||||
|
action { close() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,9 +8,12 @@ import tornadofx.ItemViewModel
|
|||||||
import tornadofx.getValue
|
import tornadofx.getValue
|
||||||
import tornadofx.setValue
|
import tornadofx.setValue
|
||||||
|
|
||||||
class GameMapVM : ItemViewModel<GameMap>() {
|
class GameMapVM(map: GameMap) : ItemViewModel<GameMap>(map) {
|
||||||
val layers: SimpleListProperty<Layer> = bind(GameMap::layers)
|
val layers: SimpleListProperty<Layer> = bind(GameMap::layers)
|
||||||
|
|
||||||
|
val nameProperty = bind(GameMap::nameProperty)
|
||||||
|
var name by nameProperty
|
||||||
|
|
||||||
val tileSetProperty = bind(GameMap::tileSet)
|
val tileSetProperty = bind(GameMap::tileSet)
|
||||||
val tileSet by tileSetProperty
|
val tileSet by tileSetProperty
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user