From d86672b0c063982775f9749eee7cda658b49a920 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Fri, 12 Apr 2019 16:59:56 +0300 Subject: [PATCH] Organized new game screen functions --- core/src/com/unciv/UnCivGame.kt | 2 +- core/src/com/unciv/ui/NewGameScreen.kt | 59 +++++++++++++++----------- 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/core/src/com/unciv/UnCivGame.kt b/core/src/com/unciv/UnCivGame.kt index d7b447782c..971f3f36c2 100644 --- a/core/src/com/unciv/UnCivGame.kt +++ b/core/src/com/unciv/UnCivGame.kt @@ -20,7 +20,7 @@ class UnCivGame(val version: String) : Game() { val viewEntireMapForDebug = false // For when you need to test something in an advanced game and don't have time to faff around - val superchargedForDebug = true + val superchargedForDebug = false lateinit var worldScreen: WorldScreen diff --git a/core/src/com/unciv/ui/NewGameScreen.kt b/core/src/com/unciv/ui/NewGameScreen.kt index b278a6a54a..4e5a18d205 100644 --- a/core/src/com/unciv/ui/NewGameScreen.kt +++ b/core/src/com/unciv/ui/NewGameScreen.kt @@ -74,17 +74,40 @@ class NewGameScreen: PickerScreen(){ val newGameOptionsTable = Table() newGameOptionsTable.skin = skin + addMapTypeSizeAndFile(newGameOptionsTable) + + addNumberOfHumansAndEnemies(newGameOptionsTable) + + addDifficultySelectBox(newGameOptionsTable) + + rightSideButton.enable() + rightSideButton.setText("Start game!".tr()) + rightSideButton.onClick { + Gdx.input.inputProcessor = null // remove input processing - nothing will be clicked! + rightSideButton.disable() + rightSideButton.setText("Working...".tr()) + + thread { // Creating a new game can take a while and we don't want ANRs + newGame = GameStarter().startNewGame(newGameParameters) + } + } + + newGameOptionsTable.pack() + return newGameOptionsTable + } + + private fun addMapTypeSizeAndFile(newGameOptionsTable: Table) { newGameOptionsTable.add("{Map type}:".tr()) val mapTypes = LinkedHashMap() for (type in MapType.values()) { - if(type==MapType.File && GameSaver().getMaps().isEmpty()) continue + if (type == MapType.File && GameSaver().getMaps().isEmpty()) continue mapTypes[type.toString()] = type } val mapFileLabel = "{Map file}:".toLabel() val mapFileSelectBox = getMapFileSelectBox() - mapFileLabel.isVisible=false - mapFileSelectBox.isVisible=false + mapFileLabel.isVisible = false + mapFileSelectBox.isVisible = false val mapTypeSelectBox = TranslatedSelectBox(mapTypes.keys, newGameParameters.mapType.toString(), skin) @@ -98,13 +121,13 @@ class NewGameScreen: PickerScreen(){ worldSizeSelectBox.isVisible = false worldSizeLabel.isVisible = false mapFileSelectBox.isVisible = true - mapFileLabel.isVisible=true + mapFileLabel.isVisible = true newGameParameters.mapFileName = mapFileSelectBox.selected } else { worldSizeSelectBox.isVisible = true worldSizeLabel.isVisible = true mapFileSelectBox.isVisible = false - mapFileLabel.isVisible=false + mapFileLabel.isVisible = false newGameParameters.mapFileName = null } } @@ -117,8 +140,9 @@ class NewGameScreen: PickerScreen(){ newGameOptionsTable.add(mapFileLabel) newGameOptionsTable.add(mapFileSelectBox).pad(10f).row() + } - + private fun addNumberOfHumansAndEnemies(newGameOptionsTable: Table) { newGameOptionsTable.add("{Number of human players}:".tr()) val humanPlayers = SelectBox(skin) val humanPlayersArray = Array() @@ -131,7 +155,7 @@ class NewGameScreen: PickerScreen(){ newGameOptionsTable.add("{Number of enemies}:".tr()) val enemiesSelectBox = SelectBox(skin) val enemiesArray = Array() - (0..GameBasics.Nations.size-1).forEach { enemiesArray.add(it) } + (0..GameBasics.Nations.size - 1).forEach { enemiesArray.add(it) } enemiesSelectBox.items = enemiesArray enemiesSelectBox.selected = newGameParameters.numberOfEnemies newGameOptionsTable.add(enemiesSelectBox).pad(10f).row() @@ -153,32 +177,17 @@ class NewGameScreen: PickerScreen(){ removeExtraHumanNations(humanPlayers) } }) + } + private fun addDifficultySelectBox(newGameOptionsTable: Table) { newGameOptionsTable.add("{Difficulty}:".tr()) - val difficultySelectBox = TranslatedSelectBox(GameBasics.Difficulties.keys, newGameParameters.difficulty , skin) + val difficultySelectBox = TranslatedSelectBox(GameBasics.Difficulties.keys, newGameParameters.difficulty, skin) difficultySelectBox.addListener(object : ChangeListener() { override fun changed(event: ChangeEvent?, actor: Actor?) { newGameParameters.difficulty = difficultySelectBox.selected.value } }) newGameOptionsTable.add(difficultySelectBox).pad(10f).row() - - - rightSideButton.enable() - rightSideButton.setText("Start game!".tr()) - rightSideButton.onClick { - Gdx.input.inputProcessor = null // remove input processing - nothing will be clicked! - rightSideButton.disable() - rightSideButton.setText("Working...".tr()) - - thread { - // Creating a new game can tke a while and we don't want ANRs - newGame = GameStarter().startNewGame(newGameParameters) - } - } - - newGameOptionsTable.pack() - return newGameOptionsTable } private fun getMapFileSelectBox(): SelectBox {