Can start a new game from within a game, to copy over the game's parameters

This commit is contained in:
Yair Morgenstern 2020-04-22 17:16:24 +03:00
parent b59cc8ab4f
commit 286ef707c2
3 changed files with 47 additions and 34 deletions

View file

@ -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()) {

View file

@ -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()

View file

@ -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()