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 54c35678..0f49c72d 100755 --- 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,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() val openMaps = observableMapOf() + fun createEmptyProject() { + val project = Project() + val vm = ProjectVM(project) + + setInScope(vm) + val modal = find().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(scope).apply { openModal(block = true, resizable = false) } + val modal = find(scope).apply { openModal(block = true, resizable = false) } if (modal.result) { openMaps[scope] = map diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/main/view/MainMenuView.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/main/view/MainMenuView.kt index 03f99dc5..b624f2a9 100755 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/main/view/MainMenuView.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/main/view/MainMenuView.kt @@ -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() } 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 da9c3ed8..35bbc738 100755 --- 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 @@ -11,6 +11,13 @@ class MainView : View("BASE Game Editor") { private val mainMenuView = find() + init { + mainController.openProject.addListener { _, _, project -> + val projectName = project?.let { " :: ${it.name}" } ?: "" + title = "BASE Game Editor$projectName" + } + } + override val root = borderpane { top = mainMenuView.root 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/MapSettingsFragment.kt index a34a4417..c3067800 100755 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/MapSettingsFragment.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/MapSettingsFragment.kt @@ -12,7 +12,7 @@ class MapSettingsFragment : Fragment("Map Settings") { private val mapVM = find() - 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") { 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 669b8801..d4d60011 100755 --- 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 @@ -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") diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/model/Project.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/model/Project.kt new file mode 100755 index 00000000..2b9e4145 --- /dev/null +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/model/Project.kt @@ -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 +} \ No newline at end of file diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/view/ProjectSettingsFragment.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/view/ProjectSettingsFragment.kt new file mode 100755 index 00000000..8c68a2f5 --- /dev/null +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/view/ProjectSettingsFragment.kt @@ -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(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() } + } + } + } +} \ No newline at end of file diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/viewmodel/ProjectVM.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/viewmodel/ProjectVM.kt new file mode 100755 index 00000000..95aa26ad --- /dev/null +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/viewmodel/ProjectVM.kt @@ -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) { + val nameProperty = bind(Project::nameProperty) + var name by nameProperty +} \ No newline at end of file