Game saves can now always be deleted (#3584)

This commit is contained in:
GGGuenni
2021-02-08 20:54:04 +01:00
committed by GitHub
parent aa0079a5e4
commit 5a4155b372

View File

@ -99,12 +99,9 @@ class MultiplayerScreen(previousScreen: CameraStageBaseScreen) : PickerScreen()
rightSideTable.add(copyGameIdButton).row() rightSideTable.add(copyGameIdButton).row()
editButton.onClick { editButton.onClick {
val gameInfo = multiplayerGames[selectedGameFile] game.setScreen(EditMultiplayerGameInfoScreen(multiplayerGames[selectedGameFile], selectedGameFile.name(), this))
if (gameInfo != null) { //game must be unselected in case the game gets deleted inside the EditScreen
game.setScreen(EditMultiplayerGameInfoScreen(gameInfo, selectedGameFile.name(), this)) unselectGame()
//game must be unselected in case the game gets deleted inside the EditScreen
unselectGame()
}
} }
rightSideTable.add(editButton).row() rightSideTable.add(editButton).row()
@ -226,12 +223,11 @@ class MultiplayerScreen(previousScreen: CameraStageBaseScreen) : PickerScreen()
selectedGameFile = gameSaveFile selectedGameFile = gameSaveFile
if (multiplayerGames[gameSaveFile] != null){ if (multiplayerGames[gameSaveFile] != null){
copyGameIdButton.enable() copyGameIdButton.enable()
editButton.enable()
} else { } else {
copyGameIdButton.disable() copyGameIdButton.disable()
editButton.disable()
} }
editButton.enable()
rightSideButton.enable() rightSideButton.enable()
//get Minutes since last modified //get Minutes since last modified
@ -364,22 +360,23 @@ class MultiplayerScreen(previousScreen: CameraStageBaseScreen) : PickerScreen()
return gameInfo.currentPlayerCiv.playerId == game.settings.userId return gameInfo.currentPlayerCiv.playerId == game.settings.userId
} }
fun removeMultiplayerGame(gameInfo: GameInfo, gameName: String){ fun removeMultiplayerGame(gameInfo: GameInfo?, gameName: String){
val games = multiplayerGames.filterValues { it == gameInfo }.keys val games = multiplayerGames.filterValues { it == gameInfo }.keys
if (games.isNotEmpty()){ try {
try { GameSaver.deleteSave(gameName, true)
GameSaver.deleteSave(gameName, true) if (games.isNotEmpty()){
multiplayerGames.remove(games.first()) multiplayerGames.remove(games.first())
}catch (ex: Exception) {
ToastPopup("Could not delete game!", this)
} }
}catch (ex: Exception) {
ToastPopup("Could not delete game!", this)
} }
} }
} }
//Subscreen of MultiplayerScreen to edit and delete saves //Subscreen of MultiplayerScreen to edit and delete saves
//backScreen is used for getting back to the MultiplayerScreen so it doesn't have to be created over and over again //backScreen is used for getting back to the MultiplayerScreen so it doesn't have to be created over and over again
class EditMultiplayerGameInfoScreen(game: GameInfo, gameName: String, backScreen: MultiplayerScreen): PickerScreen(){ class EditMultiplayerGameInfoScreen(game: GameInfo?, gameName: String, backScreen: MultiplayerScreen): PickerScreen(){
init { init {
val textField = TextField(gameName, skin) val textField = TextField(gameName, skin)
@ -399,7 +396,7 @@ class EditMultiplayerGameInfoScreen(game: GameInfo, gameName: String, backScreen
val giveUpButton = "Resign".toTextButton() val giveUpButton = "Resign".toTextButton()
giveUpButton.onClick { giveUpButton.onClick {
val askPopup = YesNoPopup("Are you sure you want to resign?", { val askPopup = YesNoPopup("Are you sure you want to resign?", {
giveUp(game.gameId, gameName, backScreen) giveUp(game!!.gameId, gameName, backScreen)
}, this) }, this)
askPopup.open() askPopup.open()
} }
@ -416,16 +413,22 @@ class EditMultiplayerGameInfoScreen(game: GameInfo, gameName: String, backScreen
//RightSideButton Setup //RightSideButton Setup
rightSideButton.setText("Save game".tr()) rightSideButton.setText("Save game".tr())
rightSideButton.enable()
rightSideButton.onClick { rightSideButton.onClick {
rightSideButton.setText("Saving...".tr()) rightSideButton.setText("Saving...".tr())
//remove the old game file //remove the old game file
backScreen.removeMultiplayerGame(game, gameName) backScreen.removeMultiplayerGame(game, gameName)
//using addMultiplayerGame will download the game from Dropbox so the descriptionLabel displays the right things //using addMultiplayerGame will download the game from Dropbox so the descriptionLabel displays the right things
backScreen.addMultiplayerGame(game.gameId, textField.text) backScreen.addMultiplayerGame(game!!.gameId, textField.text)
backScreen.game.setScreen(backScreen) backScreen.game.setScreen(backScreen)
backScreen.reloadGameListUI() backScreen.reloadGameListUI()
} }
if (game == null){
textField.isDisabled = true
textField.color = Color.GRAY
rightSideButton.disable()
giveUpButton.disable()
}
} }
/** /**