[Editor] Remove unnecessary backing object of EditorStateVM
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ class MapLayersView : View() {
|
||||
|
||||
private val mapVM = find<GameMapVM>()
|
||||
|
||||
private val editorOptionsVM = find<EditorStateVM>()
|
||||
private val editorStateVM = find<EditorStateVM>()
|
||||
|
||||
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()
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import tornadofx.*
|
||||
|
||||
class MapStatusBarView : View() {
|
||||
|
||||
private val editorOptionsVM = find<EditorStateVM>()
|
||||
private val editorStateVM = find<EditorStateVM>()
|
||||
|
||||
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")
|
||||
|
||||
@@ -19,7 +19,7 @@ class MapToolbarView : View() {
|
||||
|
||||
private val mapVM = find<GameMapVM>()
|
||||
private val brushVM = find<BrushVM>()
|
||||
private val editorOptionsVM = find<EditorStateVM>()
|
||||
private val editorStateVM = find<EditorStateVM>()
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,13 +25,13 @@ class MapView : View() {
|
||||
|
||||
private val brushVM = find<BrushVM>()
|
||||
|
||||
private val editorOptionsVM = find<EditorStateVM>()
|
||||
private val editorStateVM = find<EditorStateVM>()
|
||||
|
||||
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 {
|
||||
|
||||
@@ -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>(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
|
||||
}
|
||||
Reference in New Issue
Block a user