From 54bbd5d8a21716118a343774e00537d5ed2067c6 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Mon, 9 Dec 2019 22:48:54 +0200 Subject: [PATCH] New game screen clearly split into "Map options" and "Game options" --- .../NewGame,SaveGame,LoadGame,Options.json | 12 +- .../unciv/ui/mapeditor/MapEditorMenuPopup.kt | 3 + .../ui/newgamescreen/MapParametersTable.kt | 71 ++++++++ .../NewGameScreenOptionsTable.kt | 163 +++++++----------- 4 files changed, 150 insertions(+), 99 deletions(-) create mode 100644 core/src/com/unciv/ui/newgamescreen/MapParametersTable.kt diff --git a/android/assets/jsons/Translations/NewGame,SaveGame,LoadGame,Options.json b/android/assets/jsons/Translations/NewGame,SaveGame,LoadGame,Options.json index 71fe98a2..04de8433 100644 --- a/android/assets/jsons/Translations/NewGame,SaveGame,LoadGame,Options.json +++ b/android/assets/jsons/Translations/NewGame,SaveGame,LoadGame,Options.json @@ -53,6 +53,12 @@ Ukrainian:"Почати!" } + "Map options":{ + } + + "Game options":{ + } + "Map type":{ Italian:"Tipo di mappa" Russian:"Тип карты" @@ -68,7 +74,11 @@ Korean:"지도 유형" Czech:"Typ mapy" Ukrainian:"Тип мапи" -} + } + + "Map generation type": { + + } "Number of city-states":{ Italian:"Numero di Città-Stato" diff --git a/core/src/com/unciv/ui/mapeditor/MapEditorMenuPopup.kt b/core/src/com/unciv/ui/mapeditor/MapEditorMenuPopup.kt index b9a64a70..271f96a2 100644 --- a/core/src/com/unciv/ui/mapeditor/MapEditorMenuPopup.kt +++ b/core/src/com/unciv/ui/mapeditor/MapEditorMenuPopup.kt @@ -9,6 +9,7 @@ import com.badlogic.gdx.utils.Json import com.unciv.Constants import com.unciv.UncivGame import com.unciv.logic.MapSaver +import com.unciv.logic.map.MapType import com.unciv.logic.map.RoadStatus import com.unciv.models.gamebasics.tr import com.unciv.ui.saves.Gzip @@ -44,6 +45,8 @@ class MapEditorMenuPopup(mapEditorScreen: MapEditorScreen): PopupTable(mapEditor val saveMapButton = TextButton("Save map".tr(), skin) saveMapButton.onClick { + mapEditorScreen.tileMap.mapParameters.name=mapEditorScreen.mapName + mapEditorScreen.tileMap.mapParameters.type=MapType.custom MapSaver().saveMap(mapEditorScreen.mapName,mapEditorScreen.tileMap) UncivGame.Current.setWorldScreen() } diff --git a/core/src/com/unciv/ui/newgamescreen/MapParametersTable.kt b/core/src/com/unciv/ui/newgamescreen/MapParametersTable.kt new file mode 100644 index 00000000..5f2ddee3 --- /dev/null +++ b/core/src/com/unciv/ui/newgamescreen/MapParametersTable.kt @@ -0,0 +1,71 @@ +package com.unciv.ui.newgamescreen + +import com.badlogic.gdx.scenes.scene2d.Actor +import com.badlogic.gdx.scenes.scene2d.ui.CheckBox +import com.badlogic.gdx.scenes.scene2d.ui.Table +import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener +import com.unciv.logic.map.MapParameters +import com.unciv.logic.map.MapType +import com.unciv.models.gamebasics.tr +import com.unciv.ui.utils.CameraStageBaseScreen +import com.unciv.ui.utils.toLabel + +// This is a separate class, because it should be in use both in the New Game screen and the Map Editor screen +class MapParametersTable(val mapParameters: MapParameters): Table(){ + + init { + addMapTypeSelectBox() + addWorldSizeSelectBox() + addNoRuinsCheckbox() + } + + private fun addMapTypeSelectBox() { + add("{Map generation type}:".toLabel()) + + val mapTypes = listOf(MapType.default, MapType.pangaea, MapType.continents, MapType.perlin) + val mapTypeSelectBox = TranslatedSelectBox(mapTypes, mapParameters.type, CameraStageBaseScreen.skin) + + mapTypeSelectBox.addListener(object : ChangeListener() { + override fun changed(event: ChangeEvent?, actor: Actor?) { + mapParameters.type=mapTypeSelectBox.selected.value + } + }) + add(mapTypeSelectBox).row() + } + + + private fun addWorldSizeSelectBox(){ + + val worldSizeLabel = "{World size}:".toLabel() + val worldSizeToRadius = LinkedHashMap() + worldSizeToRadius["Tiny"] = 10 + worldSizeToRadius["Small"] = 15 + worldSizeToRadius["Medium"] = 20 + worldSizeToRadius["Large"] = 30 + worldSizeToRadius["Huge"] = 40 + + val currentWorldSizeName = worldSizeToRadius.entries + .first { it.value == mapParameters.radius }.key + val worldSizeSelectBox = TranslatedSelectBox(worldSizeToRadius.keys, currentWorldSizeName, CameraStageBaseScreen.skin) + + worldSizeSelectBox.addListener(object : ChangeListener() { + override fun changed(event: ChangeEvent?, actor: Actor?) { + mapParameters.radius = worldSizeToRadius[worldSizeSelectBox.selected.value]!! + } + }) + + add(worldSizeLabel) + add(worldSizeSelectBox).pad(10f).row() + } + + private fun addNoRuinsCheckbox() { + val noRuinsCheckbox = CheckBox("No ancient ruins".tr(), CameraStageBaseScreen.skin) + noRuinsCheckbox.isChecked = mapParameters.noRuins + noRuinsCheckbox.addListener(object : ChangeListener() { + override fun changed(event: ChangeEvent?, actor: Actor?) { + mapParameters.noRuins = noRuinsCheckbox.isChecked + } + }) + add(noRuinsCheckbox).colspan(2).row() + } +} \ No newline at end of file diff --git a/core/src/com/unciv/ui/newgamescreen/NewGameScreenOptionsTable.kt b/core/src/com/unciv/ui/newgamescreen/NewGameScreenOptionsTable.kt index b7e1e428..d9116dd7 100644 --- a/core/src/com/unciv/ui/newgamescreen/NewGameScreenOptionsTable.kt +++ b/core/src/com/unciv/ui/newgamescreen/NewGameScreenOptionsTable.kt @@ -9,7 +9,6 @@ import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener import com.badlogic.gdx.utils.Array import com.unciv.logic.MapSaver import com.unciv.logic.map.MapParameters -import com.unciv.logic.map.MapType import com.unciv.models.gamebasics.Ruleset import com.unciv.models.gamebasics.VictoryType import com.unciv.models.gamebasics.tech.TechEra @@ -24,7 +23,10 @@ class NewGameScreenOptionsTable(val newGameParameters: GameParameters, val ruleset: Ruleset, val onMultiplayerToggled:()->Unit) : Table(CameraStageBaseScreen.skin){ init{ - addMapTypeSizeAndFile() + add("Map options".toLabel(fontSize = 24)).colspan(2).row() + addMapTypeSelection() + + add("Game options".toLabel(fontSize = 24)).padTop(20f).colspan(2).row() addDifficultySelectBox() addGameSpeedSelectBox() addEraSelectBox() @@ -32,7 +34,6 @@ class NewGameScreenOptionsTable(val newGameParameters: GameParameters, addVictoryTypeCheckboxes() addBarbariansCheckbox() addOneCityChallengeCheckbox() - addNoRuinsCheckbox() addIsOnlineMultiplayerCheckbox() // addModCheckboxes() @@ -40,6 +41,67 @@ class NewGameScreenOptionsTable(val newGameParameters: GameParameters, pack() } + private fun addMapTypeSelection() { + add("{Map type}:".toLabel()) + val mapTypes = arrayListOf("Generated") + if(MapSaver().getMaps().isNotEmpty()) mapTypes.add("Existing") + + val mapFileLabel = "{Map file}:".toLabel() + val mapFileSelectBox = getMapFileSelectBox() + mapFileLabel.isVisible = false + mapFileSelectBox.isVisible = false + + val mapTypeSelectBox = TranslatedSelectBox(mapTypes, "Generated", CameraStageBaseScreen.skin) + + val mapParameterTable = MapParametersTable(mapParameters) + + fun updateOnMapTypeChange(){ + mapParameters.type = mapTypeSelectBox.selected.value + if (mapParameters.type == "Existing") { + mapParameterTable.isVisible = false + mapFileSelectBox.isVisible = true + mapFileLabel.isVisible = true + mapParameters.name = mapFileSelectBox.selected + } else { + mapParameterTable.isVisible = true + mapFileSelectBox.isVisible = false + mapFileLabel.isVisible = false + mapParameters.name = "" + } + } + + updateOnMapTypeChange() // activate once, so when we had a file map before we'll have the right things set for another one + + mapTypeSelectBox.addListener(object : ChangeListener() { + override fun changed(event: ChangeEvent?, actor: Actor?) { + updateOnMapTypeChange() + } + }) + + add(mapTypeSelectBox).pad(10f).row() + add(mapParameterTable).colspan(2).row() + + add(mapFileLabel) + add(mapFileSelectBox).pad(10f).row() + } + + + private fun getMapFileSelectBox(): SelectBox { + val mapFileSelectBox = SelectBox(CameraStageBaseScreen.skin) + val mapNames = Array() + for (mapName in MapSaver().getMaps()) mapNames.add(mapName) + mapFileSelectBox.items = mapNames + if (mapParameters.name in mapNames) mapFileSelectBox.selected = mapParameters.name + + mapFileSelectBox.addListener(object : ChangeListener() { + override fun changed(event: ChangeEvent?, actor: Actor?) { + mapParameters.name = mapFileSelectBox.selected!! + } + }) + return mapFileSelectBox + } + + private fun addBarbariansCheckbox() { val noBarbariansCheckbox = CheckBox("No barbarians".tr(), CameraStageBaseScreen.skin) noBarbariansCheckbox.isChecked = newGameParameters.noBarbarians @@ -62,17 +124,6 @@ class NewGameScreenOptionsTable(val newGameParameters: GameParameters, add(oneCityChallengeCheckbox).colspan(2).row() } - private fun addNoRuinsCheckbox() { - val noRuinsCheckbox = CheckBox("No ancient ruins".tr(), CameraStageBaseScreen.skin) - noRuinsCheckbox.isChecked = mapParameters.noRuins - noRuinsCheckbox.addListener(object : ChangeListener() { - override fun changed(event: ChangeEvent?, actor: Actor?) { - mapParameters.noRuins = noRuinsCheckbox.isChecked - } - }) - add(noRuinsCheckbox).colspan(2).row() - } - private fun addIsOnlineMultiplayerCheckbox() { val isOnlineMultiplayerCheckbox = CheckBox("Online Multiplayer".tr(), CameraStageBaseScreen.skin) @@ -86,56 +137,6 @@ class NewGameScreenOptionsTable(val newGameParameters: GameParameters, add(isOnlineMultiplayerCheckbox).colspan(2).row() } - private fun addMapTypeSizeAndFile() { - add("{Map type}:".tr()) - val mapTypes = arrayListOf(MapType.default,MapType.continents,MapType.perlin,MapType.pangaea) - if(MapSaver().getMaps().isNotEmpty()) mapTypes.add(MapType.custom) - - val mapFileLabel = "{Map file}:".toLabel() - val mapFileSelectBox = getMapFileSelectBox() - mapFileLabel.isVisible = false - mapFileSelectBox.isVisible = false - - val mapTypeSelectBox = TranslatedSelectBox(mapTypes, mapParameters.type, CameraStageBaseScreen.skin) - - val worldSizeSelectBox = getWorldSizeSelectBox() - val worldSizeLabel = "{World size}:".toLabel() - - fun updateOnMapTypeChange(){ - mapParameters.type = mapTypeSelectBox.selected.value - if (mapParameters.type == MapType.custom) { - worldSizeSelectBox.isVisible = false - worldSizeLabel.isVisible = false - mapFileSelectBox.isVisible = true - mapFileLabel.isVisible = true - mapParameters.name = mapFileSelectBox.selected - } else { - worldSizeSelectBox.isVisible = true - worldSizeLabel.isVisible = true - mapFileSelectBox.isVisible = false - mapFileLabel.isVisible = false - mapParameters.name = "" - } - } - - updateOnMapTypeChange() // activate once, so when we had a file map before we'll have the right things set for another one - - mapTypeSelectBox.addListener(object : ChangeListener() { - override fun changed(event: ChangeEvent?, actor: Actor?) { - updateOnMapTypeChange() - } - }) - - add(mapTypeSelectBox).pad(10f).row() - - - add(worldSizeLabel) - add(worldSizeSelectBox).pad(10f).row() - - add(mapFileLabel) - add(mapFileSelectBox).pad(10f).row() - } - private fun addCityStatesSelectBox() { add("{Number of city-states}:".tr()) val cityStatesSelectBox = SelectBox(CameraStageBaseScreen.skin) @@ -215,40 +216,6 @@ class NewGameScreenOptionsTable(val newGameParameters: GameParameters, add(victoryConditionsTable).colspan(2).row() } - private fun getMapFileSelectBox(): SelectBox { - val mapFileSelectBox = SelectBox(CameraStageBaseScreen.skin) - val mapNames = Array() - for (mapName in MapSaver().getMaps()) mapNames.add(mapName) - mapFileSelectBox.items = mapNames - if (mapParameters.name in mapNames) mapFileSelectBox.selected = mapParameters.name - - mapFileSelectBox.addListener(object : ChangeListener() { - override fun changed(event: ChangeEvent?, actor: Actor?) { - mapParameters.name = mapFileSelectBox.selected!! - } - }) - return mapFileSelectBox - } - - private fun getWorldSizeSelectBox(): TranslatedSelectBox { - val worldSizeToRadius = LinkedHashMap() - worldSizeToRadius["Tiny"] = 10 - worldSizeToRadius["Small"] = 15 - worldSizeToRadius["Medium"] = 20 - worldSizeToRadius["Large"] = 30 - worldSizeToRadius["Huge"] = 40 - - val currentWorldSizeName = worldSizeToRadius.entries - .first { it.value == mapParameters.radius }.key - val worldSizeSelectBox = TranslatedSelectBox(worldSizeToRadius.keys, currentWorldSizeName, CameraStageBaseScreen.skin) - - worldSizeSelectBox.addListener(object : ChangeListener() { - override fun changed(event: ChangeEvent?, actor: Actor?) { - mapParameters.radius = worldSizeToRadius[worldSizeSelectBox.selected.value]!! - } - }) - return worldSizeSelectBox - } fun addModCheckboxes(){