diff --git a/android/build.gradle b/android/build.gradle index 1826a779e0..55b77702b3 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -21,8 +21,8 @@ android { applicationId "com.unciv.app" minSdkVersion 14 targetSdkVersion 28 - versionCode 287 - versionName "2.19.6" + versionCode 288 + versionName "2.19.7" } // Had to add this crap for Travis to build, it wanted to sign the app diff --git a/core/src/com/unciv/ui/saves/LoadScreen.kt b/core/src/com/unciv/ui/saves/LoadGameScreen.kt similarity index 68% rename from core/src/com/unciv/ui/saves/LoadScreen.kt rename to core/src/com/unciv/ui/saves/LoadGameScreen.kt index 15bd472091..a4054db915 100644 --- a/core/src/com/unciv/ui/saves/LoadScreen.kt +++ b/core/src/com/unciv/ui/saves/LoadGameScreen.kt @@ -2,9 +2,12 @@ package com.unciv.ui.saves import com.badlogic.gdx.Gdx import com.badlogic.gdx.graphics.Color +import com.badlogic.gdx.scenes.scene2d.Actor +import com.badlogic.gdx.scenes.scene2d.ui.CheckBox import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.TextButton +import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener import com.unciv.UnCivGame import com.unciv.logic.GameInfo import com.unciv.logic.GameSaver @@ -15,49 +18,24 @@ import com.unciv.ui.worldscreen.optionstable.PopupTable import java.text.SimpleDateFormat import java.util.* -class LoadScreen : PickerScreen() { +class LoadGameScreen : PickerScreen() { lateinit var selectedSave:String val copySavedGameToClipboardButton = TextButton("Copy saved game to clipboard",skin) + val saveTable = Table() init { setDefaultCloseAction() - val saveTable = Table() val deleteSaveButton = TextButton("Delete save".tr(), skin) deleteSaveButton .onClick { GameSaver().deleteSave(selectedSave) - UnCivGame.Current.screen = LoadScreen() + UnCivGame.Current.screen = LoadGameScreen() } deleteSaveButton.disable() - val saves = GameSaver().getSaves() rightSideButton.setText("Load game".tr()) - for (save in saves.sortedByDescending { GameSaver().getSave(it).lastModified() }) { - val textButton = TextButton(save,skin) - textButton.onClick { - selectedSave=save - copySavedGameToClipboardButton.enable() - var textToSet = save - - val savedAt = Date(GameSaver().getSave(save).lastModified()) - textToSet+="\n{Saved at}: ".tr()+ SimpleDateFormat("dd-MM-yy HH.mm").format(savedAt) - try{ - val game = GameSaver().loadGame(save) - val playerCivNames = game.civilizations.filter { it.isPlayerCivilization() }.joinToString{it.civName.tr()} - textToSet+="\n"+playerCivNames+ - ", "+game.difficulty.tr()+", {Turn} ".tr()+game.turns - }catch (ex:Exception){ - textToSet+="\n{Could not load game}!".tr() - } - descriptionLabel.setText(textToSet) - rightSideButton.setText("Load [$save]".tr()) - rightSideButton.enable() - deleteSaveButton.enable() - deleteSaveButton.color= Color.RED - } - saveTable.add(textButton).pad(5f).row() - } + updateLoadableGames(deleteSaveButton,false) topTable.add(ScrollPane(saveTable)).height(stage.height*2/3) val rightSideTable = Table() @@ -82,13 +60,24 @@ class LoadScreen : PickerScreen() { rightSideTable.add(errorLabel).row() rightSideTable.add(deleteSaveButton).row() + copySavedGameToClipboardButton.disable() copySavedGameToClipboardButton.onClick { val gameText = GameSaver().getSave(selectedSave).readString() val gzippedGameText = Gzip.zip(gameText) Gdx.app.clipboard.contents = gzippedGameText } - rightSideTable.add(copySavedGameToClipboardButton) + rightSideTable.add(copySavedGameToClipboardButton).row() + + + val showAutosavesCheckbox = CheckBox("Show autosaves".tr(), skin) + showAutosavesCheckbox.isChecked = false + showAutosavesCheckbox.addListener(object : ChangeListener() { + override fun changed(event: ChangeEvent?, actor: Actor?) { + updateLoadableGames(deleteSaveButton,showAutosavesCheckbox.isChecked) + } + }) + rightSideTable.add(showAutosavesCheckbox).row() topTable.add(rightSideTable) @@ -109,4 +98,34 @@ class LoadScreen : PickerScreen() { } + private fun updateLoadableGames(deleteSaveButton: TextButton, showAutosaves:Boolean) { + saveTable.clear() + for (save in GameSaver().getSaves().sortedByDescending { GameSaver().getSave(it).lastModified() }) { + if(save.startsWith("Autosave") && !showAutosaves) continue + val textButton = TextButton(save, skin) + textButton.onClick { + selectedSave = save + copySavedGameToClipboardButton.enable() + var textToSet = save + + val savedAt = Date(GameSaver().getSave(save).lastModified()) + textToSet += "\n{Saved at}: ".tr() + SimpleDateFormat("dd-MM-yy HH.mm").format(savedAt) + try { + val game = GameSaver().loadGame(save) + val playerCivNames = game.civilizations.filter { it.isPlayerCivilization() }.joinToString { it.civName.tr() } + textToSet += "\n" + playerCivNames + + ", " + game.difficulty.tr() + ", {Turn} ".tr() + game.turns + } catch (ex: Exception) { + textToSet += "\n{Could not load game}!".tr() + } + descriptionLabel.setText(textToSet) + rightSideButton.setText("Load [$save]".tr()) + rightSideButton.enable() + deleteSaveButton.enable() + deleteSaveButton.color = Color.RED + } + saveTable.add(textButton).pad(5f).row() + } + } + } \ No newline at end of file diff --git a/core/src/com/unciv/ui/saves/SaveScreen.kt b/core/src/com/unciv/ui/saves/SaveGameScreen.kt similarity index 57% rename from core/src/com/unciv/ui/saves/SaveScreen.kt rename to core/src/com/unciv/ui/saves/SaveGameScreen.kt index 6fb9784e64..9387348006 100644 --- a/core/src/com/unciv/ui/saves/SaveScreen.kt +++ b/core/src/com/unciv/ui/saves/SaveGameScreen.kt @@ -1,10 +1,9 @@ package com.unciv.ui.saves import com.badlogic.gdx.Gdx -import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane -import com.badlogic.gdx.scenes.scene2d.ui.Table -import com.badlogic.gdx.scenes.scene2d.ui.TextButton -import com.badlogic.gdx.scenes.scene2d.ui.TextField +import com.badlogic.gdx.scenes.scene2d.Actor +import com.badlogic.gdx.scenes.scene2d.ui.* +import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener import com.badlogic.gdx.utils.Json import com.unciv.UnCivGame import com.unciv.logic.GameSaver @@ -15,26 +14,17 @@ import com.unciv.ui.utils.onClick import com.unciv.ui.utils.toLabel -class SaveScreen : PickerScreen() { +class SaveGameScreen : PickerScreen() { val textField = TextField("", skin) + val currentSaves = Table() init { setDefaultCloseAction() - val currentSaves = Table() currentSaves.add("Current saves".toLabel()).row() - val saves = GameSaver().getSaves().sortedByDescending { GameSaver().getSave(it).lastModified() } - saves.forEach { - val textButton = TextButton(it, skin) - textButton.onClick { - textField.text = it - } - currentSaves.add(textButton).pad(5f).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 @@ -48,7 +38,17 @@ class SaveScreen : PickerScreen() { val base64Gzip = Gzip.zip(json) Gdx.app.clipboard.contents = base64Gzip } - newSave.add(copyJsonButton) + newSave.add(copyJsonButton).row() + + + val showAutosavesCheckbox = CheckBox("Show autosaves".tr(), skin) + showAutosavesCheckbox.isChecked = false + showAutosavesCheckbox.addListener(object : ChangeListener() { + override fun changed(event: ChangeEvent?, actor: Actor?) { + updateShownSaves(showAutosavesCheckbox.isChecked) + } + }) + newSave.add(showAutosavesCheckbox).row() topTable.add(newSave) topTable.pack() @@ -61,6 +61,20 @@ class SaveScreen : PickerScreen() { rightSideButton.enable() } + fun updateShownSaves(showAutosaves:Boolean){ + currentSaves.clear() + val saves = GameSaver().getSaves() + .sortedByDescending { GameSaver().getSave(it).lastModified() } + for (saveGameName in saves) { + if(saveGameName.startsWith("Autosave") && !showAutosaves) continue + val textButton = TextButton(saveGameName, skin) + textButton.onClick { + textField.text = saveGameName + } + currentSaves.add(textButton).pad(5f).row() + } + } + } diff --git a/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenMenuTable.kt b/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenMenuTable.kt index 7672dd07d7..4d8de0dffc 100644 --- a/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenMenuTable.kt +++ b/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenMenuTable.kt @@ -9,8 +9,8 @@ import com.unciv.ui.newgamescreen.NewGameScreen import com.unciv.ui.VictoryScreen import com.unciv.ui.mapeditor.MapEditorScreen import com.unciv.ui.pickerscreens.PolicyPickerScreen -import com.unciv.ui.saves.LoadScreen -import com.unciv.ui.saves.SaveScreen +import com.unciv.ui.saves.LoadGameScreen +import com.unciv.ui.saves.SaveGameScreen import com.unciv.ui.worldscreen.WorldScreen class WorldScreenMenuTable(val worldScreen: WorldScreen) : PopupTable(worldScreen) { @@ -37,12 +37,12 @@ class WorldScreenMenuTable(val worldScreen: WorldScreen) : PopupTable(worldScree } addButton("Load game".tr()){ - UnCivGame.Current.screen = LoadScreen() + UnCivGame.Current.screen = LoadGameScreen() remove() } addButton("Save game".tr()) { - UnCivGame.Current.screen = SaveScreen() + UnCivGame.Current.screen = SaveGameScreen() remove() }