diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/model/map/editor/EditorState.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/model/map/editor/EditorState.kt deleted file mode 100755 index ab9b5ee6..00000000 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/model/map/editor/EditorState.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.bartlomiejpluta.base.editor.model.map.editor - -class EditorState { - var selectedLayer = 0 - var showGrid = true - var coverUnderlyingLayers = true - var zoom = 1.0 -} - - diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/map/MapLayersView.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/map/MapLayersView.kt index 0140b318..f54ccb26 100755 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/map/MapLayersView.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/map/MapLayersView.kt @@ -22,7 +22,7 @@ class MapLayersView : View() { private val mapVM = find() - private val editorOptionsVM = find() + private val editorStateVM = find() private var layersPane = TableView(mapVM.layers).apply { column("Layer Name", Layer::nameProperty).makeEditable().setOnEditCommit { @@ -31,7 +31,7 @@ class MapLayersView : View() { undoRedoService.push(command, scope) } - editorOptionsVM.selectedLayerProperty.bind(selectionModel.selectedIndexProperty()) + editorStateVM.selectedLayerProperty.bind(selectionModel.selectedIndexProperty()) } override val root = borderpane { @@ -49,10 +49,10 @@ class MapLayersView : View() { } button(graphic = FontIcon("fa-chevron-up")) { - enableWhen(editorOptionsVM.selectedLayerProperty.greaterThan(0)) + enableWhen(editorStateVM.selectedLayerProperty.greaterThan(0)) action { - val newIndex = editorOptionsVM.selectedLayer - 1 - val command = MoveLayerCommand(mapVM.item, editorOptionsVM.selectedLayer, newIndex) + val newIndex = editorStateVM.selectedLayer - 1 + val command = MoveLayerCommand(mapVM.item, editorStateVM.selectedLayer, newIndex) command.execute() layersPane.selectionModel.select(newIndex) fire(RedrawMapRequestEvent) @@ -62,12 +62,12 @@ class MapLayersView : View() { button(graphic = FontIcon("fa-chevron-down")) { enableWhen( - editorOptionsVM.selectedLayerProperty.lessThan(mapVM.layers.sizeProperty().minus(1)) - .and(editorOptionsVM.selectedLayerProperty.greaterThanOrEqualTo(0)) + editorStateVM.selectedLayerProperty.lessThan(mapVM.layers.sizeProperty().minus(1)) + .and(editorStateVM.selectedLayerProperty.greaterThanOrEqualTo(0)) ) action { - val newIndex = editorOptionsVM.selectedLayer + 1 - val command = MoveLayerCommand(mapVM.item, editorOptionsVM.selectedLayer, newIndex) + val newIndex = editorStateVM.selectedLayer + 1 + val command = MoveLayerCommand(mapVM.item, editorStateVM.selectedLayer, newIndex) command.execute() layersPane.selectionModel.select(newIndex) fire(RedrawMapRequestEvent) @@ -76,9 +76,9 @@ class MapLayersView : View() { } button(graphic = FontIcon("fa-trash")) { - enableWhen(editorOptionsVM.selectedLayerProperty.greaterThanOrEqualTo(0)) + enableWhen(editorStateVM.selectedLayerProperty.greaterThanOrEqualTo(0)) action { - var index = editorOptionsVM.selectedLayer + var index = editorStateVM.selectedLayer val command = RemoveLayerCommand(mapVM.item, index) command.execute() diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/map/MapStatusBarView.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/map/MapStatusBarView.kt index 3a815828..a39bcf15 100755 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/map/MapStatusBarView.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/map/MapStatusBarView.kt @@ -7,7 +7,7 @@ import tornadofx.* class MapStatusBarView : View() { - private val editorOptionsVM = find() + private val editorStateVM = find() override val root = hbox { spacing = 1.0 @@ -16,7 +16,7 @@ class MapStatusBarView : View() { this += FontIcon("fa-search-minus") slider(0.5..5.0) { - bind(editorOptionsVM.zoomProperty) + bind(editorStateVM.zoomProperty) } this += FontIcon("fa-search-plus") diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/map/MapToolbarView.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/map/MapToolbarView.kt index 567b5a97..15a86378 100755 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/map/MapToolbarView.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/map/MapToolbarView.kt @@ -19,7 +19,7 @@ class MapToolbarView : View() { private val mapVM = find() private val brushVM = find() - private val editorOptionsVM = find() + private val editorStateVM = find() private val brushMode = ToggleGroup().apply { brushVM.itemProperty.addListener { _, _, brush -> @@ -80,8 +80,7 @@ class MapToolbarView : View() { graphic = FontIcon("fa-window-restore") action { - editorOptionsVM.coverUnderlyingLayers = isSelected - editorOptionsVM.commit() + editorStateVM.coverUnderlyingLayers = isSelected } } @@ -89,8 +88,7 @@ class MapToolbarView : View() { graphic = FontIcon("fa-th") action { - editorOptionsVM.showGrid = isSelected - editorOptionsVM.commit() + editorStateVM.showGrid = isSelected } } diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/map/MapView.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/map/MapView.kt index 5de551ad..ed82297a 100755 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/map/MapView.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/view/map/MapView.kt @@ -25,13 +25,13 @@ class MapView : View() { private val brushVM = find() - private val editorOptionsVM = find() + private val editorStateVM = find() - private val mapPane = MapPane(mapVM, brushVM, editorOptionsVM) { undoRedoService.push(it, scope) } + private val mapPane = MapPane(mapVM, brushVM, editorStateVM) { undoRedoService.push(it, scope) } private val zoom = Scale(1.0, 1.0, 0.0, 0.0).apply { - xProperty().bind(editorOptionsVM.zoomProperty) - yProperty().bind(editorOptionsVM.zoomProperty) + xProperty().bind(editorStateVM.zoomProperty) + yProperty().bind(editorStateVM.zoomProperty) } init { diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/viewmodel/map/EditorStateVM.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/viewmodel/map/EditorStateVM.kt index 89aa917d..fd621cd8 100755 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/viewmodel/map/EditorStateVM.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/viewmodel/map/EditorStateVM.kt @@ -1,20 +1,22 @@ package com.bartlomiejpluta.base.editor.viewmodel.map -import com.bartlomiejpluta.base.editor.model.map.editor.EditorState -import javafx.beans.property.DoubleProperty -import javafx.beans.property.IntegerProperty -import tornadofx.* +import javafx.beans.property.SimpleBooleanProperty +import javafx.beans.property.SimpleDoubleProperty +import javafx.beans.property.SimpleIntegerProperty +import tornadofx.ViewModel +import tornadofx.getValue +import tornadofx.setValue -class EditorStateVM : ItemViewModel(EditorState()) { - val selectedLayerProperty = bind(EditorState::selectedLayer) as IntegerProperty +class EditorStateVM : ViewModel() { + val selectedLayerProperty = SimpleIntegerProperty(0) var selectedLayer by selectedLayerProperty - val showGridProperty = bind(EditorState::showGrid) + val showGridProperty = SimpleBooleanProperty(true) var showGrid by showGridProperty - val coverUnderlyingLayersProperty = bind(EditorState::coverUnderlyingLayers) + val coverUnderlyingLayersProperty = SimpleBooleanProperty(true) var coverUnderlyingLayers by coverUnderlyingLayersProperty - val zoomProperty = bind(EditorState::zoom) as DoubleProperty + val zoomProperty = SimpleDoubleProperty(1.0) var zoom by zoomProperty } \ No newline at end of file