[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.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.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 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 openProject = SimpleObjectProperty<Project?>()
|
||||
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() {
|
||||
val map = GameMap(tileset).apply { name = "Unnamed" }
|
||||
val map = GameMap(tileset)
|
||||
val scope = UndoableScope()
|
||||
val vm = GameMapVM(map)
|
||||
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) {
|
||||
openMaps[scope] = map
|
||||
|
||||
@@ -9,8 +9,14 @@ class MainMenuView : View() {
|
||||
override val root = menubar {
|
||||
menu("File") {
|
||||
menu("New") {
|
||||
item("Project...")
|
||||
item("Project...") {
|
||||
action {
|
||||
mainController.createEmptyProject()
|
||||
}
|
||||
}
|
||||
|
||||
item("Map...") {
|
||||
enableWhen(mainController.openProject.isNotNull)
|
||||
action {
|
||||
mainController.createEmptyMap()
|
||||
}
|
||||
|
||||
@@ -11,6 +11,13 @@ class MainView : View("BASE Game Editor") {
|
||||
|
||||
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 {
|
||||
top = mainMenuView.root
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ class MapSettingsFragment : Fragment("Map Settings") {
|
||||
|
||||
private val mapVM = find<GameMapVM>()
|
||||
|
||||
var result: Boolean = false
|
||||
var result = false
|
||||
private set
|
||||
|
||||
override val root = form {
|
||||
@@ -63,20 +63,16 @@ class MapSettingsFragment : Fragment("Map Settings") {
|
||||
shortcut("Enter")
|
||||
|
||||
action {
|
||||
if(mapVM.valid.value) {
|
||||
mapVM.commit {
|
||||
result = true
|
||||
undoRedoService.clear(scope)
|
||||
close()
|
||||
}
|
||||
mapVM.commit {
|
||||
result = true
|
||||
undoRedoService.clear(scope)
|
||||
close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
button("Reset") {
|
||||
action {
|
||||
mapVM.rollback()
|
||||
}
|
||||
action { mapVM.rollback() }
|
||||
}
|
||||
|
||||
button("Cancel") {
|
||||
|
||||
@@ -10,7 +10,6 @@ import com.bartlomiejpluta.base.editor.map.viewmodel.GameMapVM
|
||||
import javafx.scene.control.ToggleGroup
|
||||
import org.kordamp.ikonli.javafx.FontIcon
|
||||
import tornadofx.*
|
||||
import kotlin.math.max
|
||||
|
||||
class MapToolbarView : View() {
|
||||
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 {
|
||||
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