From 0800dbba51d8962b229bc8b48b825ab6d3ea4f4f Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Fri, 15 Jan 2021 13:28:29 +0200 Subject: [PATCH] Resolved #3533 - Added confirmation popup when saving over existing save --- .../jsons/translations/template.properties | 1 + core/src/com/unciv/ui/saves/SaveGameScreen.kt | 30 +++++++++++-------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index 2ae270a5c3..1af7a61257 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -324,6 +324,7 @@ Upload map = Could not upload map! = Map uploaded successfully! = Saving... = +Overwrite existing file? = It looks like your saved game can't be loaded! = If you could copy your game data ("Copy saved game to clipboard" - = paste into an email to yairm210@hotmail.com) = diff --git a/core/src/com/unciv/ui/saves/SaveGameScreen.kt b/core/src/com/unciv/ui/saves/SaveGameScreen.kt index ac66ef1a8b..a9267eb246 100644 --- a/core/src/com/unciv/ui/saves/SaveGameScreen.kt +++ b/core/src/com/unciv/ui/saves/SaveGameScreen.kt @@ -17,23 +17,23 @@ import com.unciv.ui.utils.AutoScrollPane as ScrollPane class SaveGameScreen : PickerScreen() { - val textField = TextField("", skin) + val gameNameTextField = TextField("", skin) val currentSaves = Table() init { setDefaultCloseAction() - textField.textFieldFilter = TextField.TextFieldFilter { _, char -> char != '\\' && char != '/' } + gameNameTextField.textFieldFilter = TextField.TextFieldFilter { _, char -> char != '\\' && char != '/' } currentSaves.add("Current saves".toLabel()).row() updateShownSaves(false) topTable.add(ScrollPane(currentSaves)).height(stage.height * 2 / 3) val newSave = Table() val defaultSaveName = game.gameInfo.currentPlayer + " - " + game.gameInfo.turns + " turns" - textField.text = defaultSaveName + gameNameTextField.text = defaultSaveName newSave.add("Saved game name".toLabel()).row() - newSave.add(textField).width(300f).pad(10f).row() + newSave.add(gameNameTextField).width(300f).pad(10f).row() val copyJsonButton = "Copy to clipboard".toTextButton() copyJsonButton.onClick { @@ -51,7 +51,7 @@ class SaveGameScreen : PickerScreen() { saveToCustomLocation.setText("Saving...".tr()) saveToCustomLocation.disable() thread(name = "SaveGame") { - GameSaver.saveGameToCustomLocation(UncivGame.Current.gameInfo, textField.text) { e -> + GameSaver.saveGameToCustomLocation(UncivGame.Current.gameInfo, gameNameTextField.text) { e -> if (e == null) { Gdx.app.postRunnable { UncivGame.Current.setWorldScreen() } } else if (e !is CancellationException) { @@ -79,16 +79,22 @@ class SaveGameScreen : PickerScreen() { rightSideButton.setText("Save game".tr()) rightSideButton.onClick { - rightSideButton.setText("Saving...".tr()) - thread(name = "SaveGame") { - GameSaver.saveGame(UncivGame.Current.gameInfo, textField.text) { - Gdx.app.postRunnable { UncivGame.Current.setWorldScreen() } - } - } + if (GameSaver.getSave(gameNameTextField.text).exists()) + YesNoPopup("Overwrite existing file?", { saveGame() }, this).open() + else saveGame() } rightSideButton.enable() } + private fun saveGame() { + rightSideButton.setText("Saving...".tr()) + thread(name = "SaveGame") { + GameSaver.saveGame(UncivGame.Current.gameInfo, gameNameTextField.text) { + Gdx.app.postRunnable { UncivGame.Current.setWorldScreen() } + } + } + } + fun updateShownSaves(showAutosaves: Boolean) { currentSaves.clear() val saves = GameSaver.getSaves() @@ -97,7 +103,7 @@ class SaveGameScreen : PickerScreen() { if (saveGameFile.name().startsWith("Autosave") && !showAutosaves) continue val textButton = saveGameFile.name().toTextButton() textButton.onClick { - textField.text = saveGameFile.name() + gameNameTextField.text = saveGameFile.name() } currentSaves.add(textButton).pad(5f).row() }