From 2b15d888ea773eb1b11dd01623e744ee5527d54d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Przemys=C5=82aw=20Pluta?= Date: Sun, 21 Feb 2021 21:14:11 +0100 Subject: [PATCH] [Editor] Replace text fields with spinners where appropriate --- .../map/view/editor/MapSettingsFragment.kt | 15 ++++++---- .../view/wizard/MapCreationBasicDataView.kt | 16 +++++----- .../view/importing/ImportTileSetFragment.kt | 29 ++++--------------- 3 files changed, 23 insertions(+), 37 deletions(-) diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/editor/MapSettingsFragment.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/editor/MapSettingsFragment.kt index 1896c609..70ba2dfa 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/editor/MapSettingsFragment.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/editor/MapSettingsFragment.kt @@ -3,6 +3,7 @@ package com.bartlomiejpluta.base.editor.map.view.editor import com.bartlomiejpluta.base.editor.command.context.UndoableScope import com.bartlomiejpluta.base.editor.command.service.UndoRedoService import com.bartlomiejpluta.base.editor.map.viewmodel.GameMapVM +import com.bartlomiejpluta.base.editor.util.fx.TextFieldUtil import tornadofx.* class MapSettingsFragment : Fragment("Map Settings") { @@ -18,11 +19,12 @@ class MapSettingsFragment : Fragment("Map Settings") { fieldset("Map Settings") { field("Rows") { - textfield(mapVM.rowsProperty) { - stripNonInteger() + spinner(min = 1, max = 100, property = mapVM.rowsProperty, editable = true) { required() + editor.textFormatter = TextFieldUtil.integerFormatter(mapVM.rows) + validator { - when (it?.toIntOrNull()) { + when (it?.toInt()) { in 1..50 -> null in 50..100 -> warning("The map sizes over 50 can impact game performance") else -> error("The map size must be between 1 and 100") @@ -32,11 +34,12 @@ class MapSettingsFragment : Fragment("Map Settings") { } field("Columns") { - textfield(mapVM.columnsProperty) { - stripNonInteger() + spinner(min = 1, max = 100, property = mapVM.columnsProperty, editable = true) { required() + editor.textFormatter = TextFieldUtil.integerFormatter(mapVM.columns) + validator { - when (it?.toIntOrNull()) { + when (it?.toInt()) { in 1..50 -> null in 50..100 -> warning("The map sizes over 50 can impact game performance") else -> error("The map size must be between 1 and 100") diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/wizard/MapCreationBasicDataView.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/wizard/MapCreationBasicDataView.kt index fe61b7d4..6e12eaac 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/wizard/MapCreationBasicDataView.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/wizard/MapCreationBasicDataView.kt @@ -1,6 +1,7 @@ package com.bartlomiejpluta.base.editor.map.view.wizard import com.bartlomiejpluta.base.editor.map.viewmodel.GameMapBuilderVM +import com.bartlomiejpluta.base.editor.util.fx.TextFieldUtil import tornadofx.* class MapCreationBasicDataView : View("Basic Data") { @@ -18,12 +19,12 @@ class MapCreationBasicDataView : View("Basic Data") { } field("Rows") { - - textfield(mapBuilderVM.rowsProperty) { - stripNonInteger() + spinner(min = 1, max = 100, property = mapBuilderVM.rowsProperty, editable = true) { required() + editor.textFormatter = TextFieldUtil.integerFormatter(mapBuilderVM.rows) + validator { - when (it?.toIntOrNull()) { + when (it?.toInt()) { in 1..50 -> null in 50..100 -> warning("The map sizes over 50 can impact game performance") else -> error("The map size must be between 1 and 100") @@ -33,11 +34,12 @@ class MapCreationBasicDataView : View("Basic Data") { } field("Columns") { - textfield(mapBuilderVM.columnsProperty) { - stripNonInteger() + spinner(min = 1, max = 100, property = mapBuilderVM.columnsProperty, editable = true) { required() + editor.textFormatter = TextFieldUtil.integerFormatter(mapBuilderVM.columns) + validator { - when (it?.toIntOrNull()) { + when (it?.toInt()) { in 1..50 -> null in 50..100 -> warning("The map sizes over 50 can impact game performance") else -> error("The map size must be between 1 and 100") diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/tileset/view/importing/ImportTileSetFragment.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/tileset/view/importing/ImportTileSetFragment.kt index bb5a75d7..4c08b34b 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/tileset/view/importing/ImportTileSetFragment.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/tileset/view/importing/ImportTileSetFragment.kt @@ -2,6 +2,7 @@ package com.bartlomiejpluta.base.editor.tileset.view.importing import com.bartlomiejpluta.base.editor.tileset.asset.TileSetAssetData import com.bartlomiejpluta.base.editor.tileset.viewmodel.TileSetAssetDataVM +import com.bartlomiejpluta.base.editor.util.fx.TextFieldUtil import javafx.beans.property.SimpleObjectProperty import javafx.scene.Cursor import javafx.scene.image.Image @@ -68,36 +69,16 @@ class ImportTileSetFragment : Fragment("Import Tile Set") { } field("Tile Set Rows") { - textfield(dataVM.rowsProperty) { - stripNonInteger() + spinner(min = 1, max = Integer.MAX_VALUE, property = dataVM.rowsProperty, editable = true) { required() - trimWhitespace() - - validator { - val value = it?.toIntOrNull() - when { - value == null -> error("This field is required") - value < 1 -> error("The value must not be lower than 1") - else -> null - } - } + editor.textFormatter = TextFieldUtil.integerFormatter(dataVM.rows) } } field("Tile Set Columns") { - textfield(dataVM.columnsProperty) { - stripNonInteger() + spinner(min = 1, max = Integer.MAX_VALUE, property = dataVM.columnsProperty, editable = true) { required() - trimWhitespace() - - validator { - val value = it?.toIntOrNull() - when { - value == null -> error("This field is required") - value < 1 -> error("The value must not be lower than 1") - else -> null - } - } + editor.textFormatter = TextFieldUtil.integerFormatter(dataVM.columns) } } }