[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 mapVM = find<GameMapVM>()
|
||||||
|
|
||||||
private val editorOptionsVM = find<EditorStateVM>()
|
private val editorStateVM = find<EditorStateVM>()
|
||||||
|
|
||||||
private var layersPane = TableView(mapVM.layers).apply {
|
private var layersPane = TableView(mapVM.layers).apply {
|
||||||
column("Layer Name", Layer::nameProperty).makeEditable().setOnEditCommit {
|
column("Layer Name", Layer::nameProperty).makeEditable().setOnEditCommit {
|
||||||
@@ -31,7 +31,7 @@ class MapLayersView : View() {
|
|||||||
undoRedoService.push(command, scope)
|
undoRedoService.push(command, scope)
|
||||||
}
|
}
|
||||||
|
|
||||||
editorOptionsVM.selectedLayerProperty.bind(selectionModel.selectedIndexProperty())
|
editorStateVM.selectedLayerProperty.bind(selectionModel.selectedIndexProperty())
|
||||||
}
|
}
|
||||||
|
|
||||||
override val root = borderpane {
|
override val root = borderpane {
|
||||||
@@ -49,10 +49,10 @@ class MapLayersView : View() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
button(graphic = FontIcon("fa-chevron-up")) {
|
button(graphic = FontIcon("fa-chevron-up")) {
|
||||||
enableWhen(editorOptionsVM.selectedLayerProperty.greaterThan(0))
|
enableWhen(editorStateVM.selectedLayerProperty.greaterThan(0))
|
||||||
action {
|
action {
|
||||||
val newIndex = editorOptionsVM.selectedLayer - 1
|
val newIndex = editorStateVM.selectedLayer - 1
|
||||||
val command = MoveLayerCommand(mapVM.item, editorOptionsVM.selectedLayer, newIndex)
|
val command = MoveLayerCommand(mapVM.item, editorStateVM.selectedLayer, newIndex)
|
||||||
command.execute()
|
command.execute()
|
||||||
layersPane.selectionModel.select(newIndex)
|
layersPane.selectionModel.select(newIndex)
|
||||||
fire(RedrawMapRequestEvent)
|
fire(RedrawMapRequestEvent)
|
||||||
@@ -62,12 +62,12 @@ class MapLayersView : View() {
|
|||||||
|
|
||||||
button(graphic = FontIcon("fa-chevron-down")) {
|
button(graphic = FontIcon("fa-chevron-down")) {
|
||||||
enableWhen(
|
enableWhen(
|
||||||
editorOptionsVM.selectedLayerProperty.lessThan(mapVM.layers.sizeProperty().minus(1))
|
editorStateVM.selectedLayerProperty.lessThan(mapVM.layers.sizeProperty().minus(1))
|
||||||
.and(editorOptionsVM.selectedLayerProperty.greaterThanOrEqualTo(0))
|
.and(editorStateVM.selectedLayerProperty.greaterThanOrEqualTo(0))
|
||||||
)
|
)
|
||||||
action {
|
action {
|
||||||
val newIndex = editorOptionsVM.selectedLayer + 1
|
val newIndex = editorStateVM.selectedLayer + 1
|
||||||
val command = MoveLayerCommand(mapVM.item, editorOptionsVM.selectedLayer, newIndex)
|
val command = MoveLayerCommand(mapVM.item, editorStateVM.selectedLayer, newIndex)
|
||||||
command.execute()
|
command.execute()
|
||||||
layersPane.selectionModel.select(newIndex)
|
layersPane.selectionModel.select(newIndex)
|
||||||
fire(RedrawMapRequestEvent)
|
fire(RedrawMapRequestEvent)
|
||||||
@@ -76,9 +76,9 @@ class MapLayersView : View() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
button(graphic = FontIcon("fa-trash")) {
|
button(graphic = FontIcon("fa-trash")) {
|
||||||
enableWhen(editorOptionsVM.selectedLayerProperty.greaterThanOrEqualTo(0))
|
enableWhen(editorStateVM.selectedLayerProperty.greaterThanOrEqualTo(0))
|
||||||
action {
|
action {
|
||||||
var index = editorOptionsVM.selectedLayer
|
var index = editorStateVM.selectedLayer
|
||||||
val command = RemoveLayerCommand(mapVM.item, index)
|
val command = RemoveLayerCommand(mapVM.item, index)
|
||||||
command.execute()
|
command.execute()
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import tornadofx.*
|
|||||||
|
|
||||||
class MapStatusBarView : View() {
|
class MapStatusBarView : View() {
|
||||||
|
|
||||||
private val editorOptionsVM = find<EditorStateVM>()
|
private val editorStateVM = find<EditorStateVM>()
|
||||||
|
|
||||||
override val root = hbox {
|
override val root = hbox {
|
||||||
spacing = 1.0
|
spacing = 1.0
|
||||||
@@ -16,7 +16,7 @@ class MapStatusBarView : View() {
|
|||||||
this += FontIcon("fa-search-minus")
|
this += FontIcon("fa-search-minus")
|
||||||
|
|
||||||
slider(0.5..5.0) {
|
slider(0.5..5.0) {
|
||||||
bind(editorOptionsVM.zoomProperty)
|
bind(editorStateVM.zoomProperty)
|
||||||
}
|
}
|
||||||
|
|
||||||
this += FontIcon("fa-search-plus")
|
this += FontIcon("fa-search-plus")
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class MapToolbarView : View() {
|
|||||||
|
|
||||||
private val mapVM = find<GameMapVM>()
|
private val mapVM = find<GameMapVM>()
|
||||||
private val brushVM = find<BrushVM>()
|
private val brushVM = find<BrushVM>()
|
||||||
private val editorOptionsVM = find<EditorStateVM>()
|
private val editorStateVM = find<EditorStateVM>()
|
||||||
|
|
||||||
private val brushMode = ToggleGroup().apply {
|
private val brushMode = ToggleGroup().apply {
|
||||||
brushVM.itemProperty.addListener { _, _, brush ->
|
brushVM.itemProperty.addListener { _, _, brush ->
|
||||||
@@ -80,8 +80,7 @@ class MapToolbarView : View() {
|
|||||||
graphic = FontIcon("fa-window-restore")
|
graphic = FontIcon("fa-window-restore")
|
||||||
|
|
||||||
action {
|
action {
|
||||||
editorOptionsVM.coverUnderlyingLayers = isSelected
|
editorStateVM.coverUnderlyingLayers = isSelected
|
||||||
editorOptionsVM.commit()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,8 +88,7 @@ class MapToolbarView : View() {
|
|||||||
graphic = FontIcon("fa-th")
|
graphic = FontIcon("fa-th")
|
||||||
|
|
||||||
action {
|
action {
|
||||||
editorOptionsVM.showGrid = isSelected
|
editorStateVM.showGrid = isSelected
|
||||||
editorOptionsVM.commit()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,13 +25,13 @@ class MapView : View() {
|
|||||||
|
|
||||||
private val brushVM = find<BrushVM>()
|
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 {
|
private val zoom = Scale(1.0, 1.0, 0.0, 0.0).apply {
|
||||||
xProperty().bind(editorOptionsVM.zoomProperty)
|
xProperty().bind(editorStateVM.zoomProperty)
|
||||||
yProperty().bind(editorOptionsVM.zoomProperty)
|
yProperty().bind(editorStateVM.zoomProperty)
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
|||||||
@@ -1,20 +1,22 @@
|
|||||||
package com.bartlomiejpluta.base.editor.viewmodel.map
|
package com.bartlomiejpluta.base.editor.viewmodel.map
|
||||||
|
|
||||||
import com.bartlomiejpluta.base.editor.model.map.editor.EditorState
|
import javafx.beans.property.SimpleBooleanProperty
|
||||||
import javafx.beans.property.DoubleProperty
|
import javafx.beans.property.SimpleDoubleProperty
|
||||||
import javafx.beans.property.IntegerProperty
|
import javafx.beans.property.SimpleIntegerProperty
|
||||||
import tornadofx.*
|
import tornadofx.ViewModel
|
||||||
|
import tornadofx.getValue
|
||||||
|
import tornadofx.setValue
|
||||||
|
|
||||||
class EditorStateVM : ItemViewModel<EditorState>(EditorState()) {
|
class EditorStateVM : ViewModel() {
|
||||||
val selectedLayerProperty = bind(EditorState::selectedLayer) as IntegerProperty
|
val selectedLayerProperty = SimpleIntegerProperty(0)
|
||||||
var selectedLayer by selectedLayerProperty
|
var selectedLayer by selectedLayerProperty
|
||||||
|
|
||||||
val showGridProperty = bind(EditorState::showGrid)
|
val showGridProperty = SimpleBooleanProperty(true)
|
||||||
var showGrid by showGridProperty
|
var showGrid by showGridProperty
|
||||||
|
|
||||||
val coverUnderlyingLayersProperty = bind(EditorState::coverUnderlyingLayers)
|
val coverUnderlyingLayersProperty = SimpleBooleanProperty(true)
|
||||||
var coverUnderlyingLayers by coverUnderlyingLayersProperty
|
var coverUnderlyingLayers by coverUnderlyingLayersProperty
|
||||||
|
|
||||||
val zoomProperty = bind(EditorState::zoom) as DoubleProperty
|
val zoomProperty = SimpleDoubleProperty(1.0)
|
||||||
var zoom by zoomProperty
|
var zoom by zoomProperty
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user