[Editor] Create scaffolding for project management
This commit is contained in:
@@ -2,28 +2,47 @@ package com.bartlomiejpluta.base.editor.main.controller
|
|||||||
|
|
||||||
import com.bartlomiejpluta.base.editor.command.context.UndoableScope
|
import com.bartlomiejpluta.base.editor.command.context.UndoableScope
|
||||||
import com.bartlomiejpluta.base.editor.map.model.map.GameMap
|
import com.bartlomiejpluta.base.editor.map.model.map.GameMap
|
||||||
import com.bartlomiejpluta.base.editor.tileset.model.TileSet
|
|
||||||
import com.bartlomiejpluta.base.editor.map.view.MapSettingsFragment
|
import com.bartlomiejpluta.base.editor.map.view.MapSettingsFragment
|
||||||
import com.bartlomiejpluta.base.editor.map.viewmodel.GameMapVM
|
import com.bartlomiejpluta.base.editor.map.viewmodel.GameMapVM
|
||||||
|
import com.bartlomiejpluta.base.editor.project.model.Project
|
||||||
|
import com.bartlomiejpluta.base.editor.project.view.ProjectSettingsFragment
|
||||||
|
import com.bartlomiejpluta.base.editor.project.viewmodel.ProjectVM
|
||||||
|
import com.bartlomiejpluta.base.editor.tileset.model.TileSet
|
||||||
|
import javafx.beans.property.SimpleObjectProperty
|
||||||
import org.springframework.stereotype.Component
|
import org.springframework.stereotype.Component
|
||||||
import tornadofx.Controller
|
import tornadofx.Controller
|
||||||
import tornadofx.Scope
|
import tornadofx.Scope
|
||||||
|
import tornadofx.find
|
||||||
import tornadofx.observableMapOf
|
import tornadofx.observableMapOf
|
||||||
|
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
|
// 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 tileset = TileSet(resources.image("/textures/tileset.png"), 160, 8)
|
||||||
|
|
||||||
|
val openProject = SimpleObjectProperty<Project?>()
|
||||||
val openMaps = observableMapOf<Scope, GameMap>()
|
val openMaps = observableMapOf<Scope, GameMap>()
|
||||||
|
|
||||||
|
fun createEmptyProject() {
|
||||||
|
val project = Project()
|
||||||
|
val vm = ProjectVM(project)
|
||||||
|
|
||||||
|
setInScope(vm)
|
||||||
|
val modal = find<ProjectSettingsFragment>().apply { openModal(block = true, resizable = false) }
|
||||||
|
|
||||||
|
if(modal.result) {
|
||||||
|
openProject.value = project
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun createEmptyMap() {
|
fun createEmptyMap() {
|
||||||
val map = GameMap(tileset).apply { name = "Unnamed" }
|
val map = GameMap(tileset)
|
||||||
val scope = UndoableScope()
|
val scope = UndoableScope()
|
||||||
val vm = GameMapVM(map)
|
val vm = GameMapVM(map)
|
||||||
setInScope(vm, scope)
|
setInScope(vm, scope)
|
||||||
|
|
||||||
val modal = tornadofx.find<MapSettingsFragment>(scope).apply { openModal(block = true, resizable = false) }
|
val modal = find<MapSettingsFragment>(scope).apply { openModal(block = true, resizable = false) }
|
||||||
|
|
||||||
if (modal.result) {
|
if (modal.result) {
|
||||||
openMaps[scope] = map
|
openMaps[scope] = map
|
||||||
|
|||||||
@@ -9,8 +9,14 @@ class MainMenuView : View() {
|
|||||||
override val root = menubar {
|
override val root = menubar {
|
||||||
menu("File") {
|
menu("File") {
|
||||||
menu("New") {
|
menu("New") {
|
||||||
item("Project...")
|
item("Project...") {
|
||||||
|
action {
|
||||||
|
mainController.createEmptyProject()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
item("Map...") {
|
item("Map...") {
|
||||||
|
enableWhen(mainController.openProject.isNotNull)
|
||||||
action {
|
action {
|
||||||
mainController.createEmptyMap()
|
mainController.createEmptyMap()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,13 @@ class MainView : View("BASE Game Editor") {
|
|||||||
|
|
||||||
private val mainMenuView = find<MainMenuView>()
|
private val mainMenuView = find<MainMenuView>()
|
||||||
|
|
||||||
|
init {
|
||||||
|
mainController.openProject.addListener { _, _, project ->
|
||||||
|
val projectName = project?.let { " :: ${it.name}" } ?: ""
|
||||||
|
title = "BASE Game Editor$projectName"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override val root = borderpane {
|
override val root = borderpane {
|
||||||
top = mainMenuView.root
|
top = mainMenuView.root
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class MapSettingsFragment : Fragment("Map Settings") {
|
|||||||
|
|
||||||
private val mapVM = find<GameMapVM>()
|
private val mapVM = find<GameMapVM>()
|
||||||
|
|
||||||
var result: Boolean = false
|
var result = false
|
||||||
private set
|
private set
|
||||||
|
|
||||||
override val root = form {
|
override val root = form {
|
||||||
@@ -63,7 +63,6 @@ class MapSettingsFragment : Fragment("Map Settings") {
|
|||||||
shortcut("Enter")
|
shortcut("Enter")
|
||||||
|
|
||||||
action {
|
action {
|
||||||
if(mapVM.valid.value) {
|
|
||||||
mapVM.commit {
|
mapVM.commit {
|
||||||
result = true
|
result = true
|
||||||
undoRedoService.clear(scope)
|
undoRedoService.clear(scope)
|
||||||
@@ -71,12 +70,9 @@ class MapSettingsFragment : Fragment("Map Settings") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
button("Reset") {
|
button("Reset") {
|
||||||
action {
|
action { mapVM.rollback() }
|
||||||
mapVM.rollback()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
button("Cancel") {
|
button("Cancel") {
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import com.bartlomiejpluta.base.editor.map.viewmodel.GameMapVM
|
|||||||
import javafx.scene.control.ToggleGroup
|
import javafx.scene.control.ToggleGroup
|
||||||
import org.kordamp.ikonli.javafx.FontIcon
|
import org.kordamp.ikonli.javafx.FontIcon
|
||||||
import tornadofx.*
|
import tornadofx.*
|
||||||
import kotlin.math.max
|
|
||||||
|
|
||||||
class MapToolbarView : View() {
|
class MapToolbarView : View() {
|
||||||
private val undoRedoService: UndoRedoService by di()
|
private val undoRedoService: UndoRedoService by di()
|
||||||
@@ -44,38 +43,6 @@ class MapToolbarView : View() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
button(text = "Rows", graphic = FontIcon("fa-minus")) {
|
|
||||||
action {
|
|
||||||
mapVM.rows = max(mapVM.rows - 1, 1)
|
|
||||||
mapVM.commit()
|
|
||||||
fire(RedrawMapRequestEvent)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
button(text = "Columns", graphic = FontIcon("fa-minus")) {
|
|
||||||
action {
|
|
||||||
mapVM.columns = max(mapVM.columns - 1, 1)
|
|
||||||
mapVM.commit()
|
|
||||||
fire(RedrawMapRequestEvent)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
button(text = "Rows", graphic = FontIcon("fa-plus")) {
|
|
||||||
action {
|
|
||||||
++mapVM.rows
|
|
||||||
mapVM.commit()
|
|
||||||
fire(RedrawMapRequestEvent)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
button(text = "Columns", graphic = FontIcon("fa-plus")) {
|
|
||||||
action {
|
|
||||||
++mapVM.columns
|
|
||||||
mapVM.commit()
|
|
||||||
fire(RedrawMapRequestEvent)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
togglebutton {
|
togglebutton {
|
||||||
graphic = FontIcon("fa-window-restore")
|
graphic = FontIcon("fa-window-restore")
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.bartlomiejpluta.base.editor.project.model
|
||||||
|
|
||||||
|
import javafx.beans.property.SimpleStringProperty
|
||||||
|
import tornadofx.*
|
||||||
|
|
||||||
|
class Project {
|
||||||
|
val nameProperty = SimpleStringProperty()
|
||||||
|
var name by nameProperty
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package com.bartlomiejpluta.base.editor.project.view
|
||||||
|
|
||||||
|
import com.bartlomiejpluta.base.editor.project.viewmodel.ProjectVM
|
||||||
|
import tornadofx.*
|
||||||
|
|
||||||
|
class ProjectSettingsFragment : Fragment("Project Settings") {
|
||||||
|
private val projectVM = find<ProjectVM>(FX.defaultScope)
|
||||||
|
|
||||||
|
var result = false
|
||||||
|
private set
|
||||||
|
|
||||||
|
override val root = form {
|
||||||
|
fieldset("Project Settings") {
|
||||||
|
field("Project Name") {
|
||||||
|
textfield(projectVM.nameProperty) {
|
||||||
|
required()
|
||||||
|
whenDocked { requestFocus() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buttonbar {
|
||||||
|
button("Ok") {
|
||||||
|
action {
|
||||||
|
projectVM.commit {
|
||||||
|
result = true
|
||||||
|
close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
shortcut("Enter")
|
||||||
|
}
|
||||||
|
|
||||||
|
button("Reset") {
|
||||||
|
action { projectVM.rollback() }
|
||||||
|
}
|
||||||
|
|
||||||
|
button("Cancel") {
|
||||||
|
action { close() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.bartlomiejpluta.base.editor.project.viewmodel
|
||||||
|
|
||||||
|
import com.bartlomiejpluta.base.editor.project.model.Project
|
||||||
|
import tornadofx.ItemViewModel
|
||||||
|
import tornadofx.getValue
|
||||||
|
import tornadofx.setValue
|
||||||
|
|
||||||
|
class ProjectVM(project: Project) : ItemViewModel<Project>(project) {
|
||||||
|
val nameProperty = bind(Project::nameProperty)
|
||||||
|
var name by nameProperty
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user