From 286ef707c2830f5ae0ba4cc9f963d51062d1fec2 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Wed, 22 Apr 2020 17:16:24 +0300 Subject: [PATCH] Can start a new game from within a game, to copy over the game's parameters --- core/src/com/unciv/MenuScreen.kt | 4 +- .../unciv/ui/newgamescreen/NewGameScreen.kt | 70 ++++++++++--------- .../mainmenu/WorldScreenMenuPopup.kt | 7 ++ 3 files changed, 47 insertions(+), 34 deletions(-) diff --git a/core/src/com/unciv/MenuScreen.kt b/core/src/com/unciv/MenuScreen.kt index 0c48d477af..4b6dc4fc23 100644 --- a/core/src/com/unciv/MenuScreen.kt +++ b/core/src/com/unciv/MenuScreen.kt @@ -84,7 +84,9 @@ class MenuScreen: CameraStageBaseScreen() { val quickstartTable = getTableBlock("Quickstart","OtherIcons/Quickstart") { startNewGame() } table.add(quickstartTable).row() - val newGameButton = getTableBlock("Start new game","OtherIcons/New") { game.setScreen(NewGameScreen(this)) } + val newGameButton = getTableBlock("Start new game","OtherIcons/New") { + game.setScreen(NewGameScreen(this)) + } table.add(newGameButton).row() if (GameSaver.getSaves(false).any()) { diff --git a/core/src/com/unciv/ui/newgamescreen/NewGameScreen.kt b/core/src/com/unciv/ui/newgamescreen/NewGameScreen.kt index 290a747da0..49344658e1 100644 --- a/core/src/com/unciv/ui/newgamescreen/NewGameScreen.kt +++ b/core/src/com/unciv/ui/newgamescreen/NewGameScreen.kt @@ -69,43 +69,47 @@ class NewGameScreen(previousScreen:CameraStageBaseScreen, currentGame:GameInfo?= thread(name="NewGame") { // Creating a new game can take a while and we don't want ANRs - try { - newGame = GameStarter.startNewGame(newGameParameters,mapParameters) - if (newGameParameters.isOnlineMultiplayer) { - newGame!!.isUpToDate=true // So we don't try to download it from dropbox the second after we upload it - the file is not yet ready for loading! - try { - OnlineMultiplayer().tryUploadGame(newGame!!) - GameSaver.autoSave(newGame!!){} - - //Saved as Multiplayer game to show up in the session browser - GameSaver.saveGame(newGame!!, newGame!!.gameId,true) - //Save gameId to clipboard because you have to do it anyway. - Gdx.app.clipboard.contents = newGame!!.gameId - //Popup to notify the User that the gameID got copied to the clipboard - ResponsePopup("gameID copied to clipboard".tr(), UncivGame.Current.worldScreen, 2500) - } catch (ex: Exception) { - val cantUploadNewGamePopup = Popup(this) - cantUploadNewGamePopup.addGoodSizedLabel("Could not upload game!") - cantUploadNewGamePopup.addCloseButton() - cantUploadNewGamePopup.open() - newGame = null - } - } - } catch (exception: Exception) { - val cantMakeThatMapPopup = Popup(this) - cantMakeThatMapPopup.addGoodSizedLabel("It looks like we can't make a map with the parameters you requested!".tr()).row() - cantMakeThatMapPopup.addGoodSizedLabel("Maybe you put too many players into too small a map?".tr()).row() - cantMakeThatMapPopup.addCloseButton() - cantMakeThatMapPopup.open() - Gdx.input.inputProcessor = stage - rightSideButton.enable() - rightSideButton.setText("Start game!".tr()) - } - Gdx.graphics.requestRendering() + newGameThread() } } } + private fun newGameThread() { + try { + newGame = GameStarter.startNewGame(newGameParameters, mapParameters) + if (newGameParameters.isOnlineMultiplayer) { + newGame!!.isUpToDate = true // So we don't try to download it from dropbox the second after we upload it - the file is not yet ready for loading! + try { + OnlineMultiplayer().tryUploadGame(newGame!!) + GameSaver.autoSave(newGame!!) {} + + //Saved as Multiplayer game to show up in the session browser + GameSaver.saveGame(newGame!!, newGame!!.gameId, true) + //Save gameId to clipboard because you have to do it anyway. + Gdx.app.clipboard.contents = newGame!!.gameId + //Popup to notify the User that the gameID got copied to the clipboard + ResponsePopup("gameID copied to clipboard".tr(), UncivGame.Current.worldScreen, 2500) + } catch (ex: Exception) { + val cantUploadNewGamePopup = Popup(this) + cantUploadNewGamePopup.addGoodSizedLabel("Could not upload game!") + cantUploadNewGamePopup.addCloseButton() + cantUploadNewGamePopup.open() + newGame = null + } + } + } catch (exception: Exception) { + val cantMakeThatMapPopup = Popup(this) + cantMakeThatMapPopup.addGoodSizedLabel("It looks like we can't make a map with the parameters you requested!".tr()).row() + cantMakeThatMapPopup.addGoodSizedLabel("Maybe you put too many players into too small a map?".tr()).row() + cantMakeThatMapPopup.addCloseButton() + cantMakeThatMapPopup.open() + Gdx.input.inputProcessor = stage + rightSideButton.enable() + rightSideButton.setText("Start game!".tr()) + } + Gdx.graphics.requestRendering() + } + fun setNewGameButtonEnabled(bool:Boolean){ if(bool) rightSideButton.enable() else rightSideButton.disable() diff --git a/core/src/com/unciv/ui/worldscreen/mainmenu/WorldScreenMenuPopup.kt b/core/src/com/unciv/ui/worldscreen/mainmenu/WorldScreenMenuPopup.kt index 108312ff9c..65ba2b6516 100644 --- a/core/src/com/unciv/ui/worldscreen/mainmenu/WorldScreenMenuPopup.kt +++ b/core/src/com/unciv/ui/worldscreen/mainmenu/WorldScreenMenuPopup.kt @@ -41,6 +41,13 @@ class WorldScreenMenuPopup(val worldScreen: WorldScreen) : Popup(worldScreen) { }.size(width,height) addSeparator() + + addSquareButton("Start new game".tr()){ + worldScreen.game.setScreen(NewGameScreen(worldScreen, worldScreen.gameInfo)) + close() + }.size(width,height) + addSeparator() + addSquareButton("Victory status".tr()){ worldScreen.game.setScreen(VictoryScreen(worldScreen)) close()