diff --git a/android/build.gradle b/android/build.gradle index 55b77702b3..03397e45c3 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -21,8 +21,8 @@ android { applicationId "com.unciv.app" minSdkVersion 14 targetSdkVersion 28 - versionCode 288 - versionName "2.19.7" + versionCode 289 + versionName "2.19.8" } // Had to add this crap for Travis to build, it wanted to sign the app diff --git a/core/src/com/unciv/logic/GameSaver.kt b/core/src/com/unciv/logic/GameSaver.kt index 7915b3b447..00fe3b1665 100644 --- a/core/src/com/unciv/logic/GameSaver.kt +++ b/core/src/com/unciv/logic/GameSaver.kt @@ -63,8 +63,14 @@ class GameSaver { saveGame(gameInfoClone, "Autosave") // keep auto-saves for the last 10 turns for debugging purposes - // eg turn 238 is saved as "Autosave-8" - getSave("Autosave").copyTo(Gdx.files.local(saveFilesFolder + File.separator + "Autosave-${gameInfoClone.turns%10}")) + val newAutosaveFilename = saveFilesFolder + File.separator + "Autosave-${gameInfo.currentPlayer}-${gameInfoClone.turns}" + getSave("Autosave").copyTo(Gdx.files.local(newAutosaveFilename)) + + val autosaves = getSaves().filter { it.startsWith("Autosave") } + while(autosaves.size>10){ + val saveToDelete = autosaves.minBy { getSave(it).lastModified() }!! + deleteSave(saveToDelete) + } // do this on main thread Gdx.app.postRunnable { diff --git a/core/src/com/unciv/logic/MapSaver.kt b/core/src/com/unciv/logic/MapSaver.kt index 925709129f..c7e48f582b 100644 --- a/core/src/com/unciv/logic/MapSaver.kt +++ b/core/src/com/unciv/logic/MapSaver.kt @@ -17,6 +17,7 @@ class MapSaver(){ val unzippedJson = Gzip.unzip(gzippedString) return json().fromJson(TileMap::class.java, unzippedJson) } + fun deleteMap(mapName: String) = getMap(mapName).delete() fun getMaps() = Gdx.files.local(mapsFolder).list().map { it.name() } diff --git a/core/src/com/unciv/ui/mapeditor/MapEditorOptionsTable.kt b/core/src/com/unciv/ui/mapeditor/MapEditorOptionsTable.kt index 1ffd965036..bb63f64d5b 100644 --- a/core/src/com/unciv/ui/mapeditor/MapEditorOptionsTable.kt +++ b/core/src/com/unciv/ui/mapeditor/MapEditorOptionsTable.kt @@ -1,6 +1,7 @@ package com.unciv.ui.mapeditor 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 @@ -11,6 +12,7 @@ import com.unciv.logic.MapSaver import com.unciv.logic.map.RoadStatus import com.unciv.models.gamebasics.tr import com.unciv.ui.saves.Gzip +import com.unciv.ui.saves.LoadMapScreen import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.onClick import com.unciv.ui.worldscreen.optionstable.DropBox @@ -56,7 +58,9 @@ class MapEditorOptionsTable(mapEditorScreen: MapEditorScreen): PopupTable(mapEdi add(copyMapAsTextButton).row() val loadMapButton = TextButton("Load".tr(), skin) - loadMapButton.onClick { MapScreenLoadTable(mapEditorScreen); remove() } + loadMapButton.onClick { + UnCivGame.Current.screen = LoadMapScreen(mapEditorScreen.tileMap) + } add(loadMapButton).row() val uploadMapButton = TextButton("Upload".tr(), skin) @@ -105,7 +109,7 @@ class MapDownloadTable(mapEditorScreen: MapEditorScreen):PopupTable(mapEditorScr val folderList: DropBox.FolderList try { folderList = DropBox().getFolderList("/Maps") - val scrollableMapTable = Table() + val scrollableMapTable = Table().apply { defaults().pad(10f) } for (downloadableMap in folderList.entries) { val downloadMapButton = TextButton(downloadableMap.name, CameraStageBaseScreen.skin) downloadMapButton.onClick { @@ -117,7 +121,7 @@ class MapDownloadTable(mapEditorScreen: MapEditorScreen):PopupTable(mapEditorScr } scrollableMapTable.add(downloadMapButton).row() } - add(scrollableMapTable).height(mapEditorScreen.stage.height * 2 / 3).row() + add(ScrollPane(scrollableMapTable)).height(mapEditorScreen.stage.height * 2 / 3).row() } catch (ex: Exception) { addGoodSizedLabel("Could not get list of maps!").row() } diff --git a/core/src/com/unciv/ui/mapeditor/MapScreenLoadTable.kt b/core/src/com/unciv/ui/mapeditor/MapScreenLoadTable.kt deleted file mode 100644 index 425ebf4f87..0000000000 --- a/core/src/com/unciv/ui/mapeditor/MapScreenLoadTable.kt +++ /dev/null @@ -1,44 +0,0 @@ -package com.unciv.ui.mapeditor - -import com.badlogic.gdx.Gdx -import com.badlogic.gdx.scenes.scene2d.ui.SelectBox -import com.badlogic.gdx.scenes.scene2d.ui.TextButton -import com.badlogic.gdx.utils.Array -import com.unciv.UnCivGame -import com.unciv.logic.MapSaver -import com.unciv.models.gamebasics.tr -import com.unciv.ui.saves.Gzip -import com.unciv.ui.utils.CameraStageBaseScreen -import com.unciv.ui.utils.onClick -import com.unciv.ui.worldscreen.optionstable.PopupTable - -class MapScreenLoadTable(mapEditorScreen: MapEditorScreen): PopupTable(mapEditorScreen){ - init{ - val mapFileSelectBox = SelectBox(CameraStageBaseScreen.skin) - val mapNames = Array() - for (mapName in MapSaver().getMaps()) mapNames.add(mapName) - mapFileSelectBox.items = mapNames - add(mapFileSelectBox).row() - - val loadMapButton = TextButton("Load".tr(), CameraStageBaseScreen.skin) - loadMapButton.onClick { - UnCivGame.Current.screen = MapEditorScreen(mapFileSelectBox.selected) - } - add(loadMapButton).row() - - val loadFromClipboardButton = TextButton("Load copied data".tr(), CameraStageBaseScreen.skin) - loadFromClipboardButton .onClick { - val clipboardContentsString = Gdx.app.clipboard.contents.trim() - val decoded = Gzip.unzip(clipboardContentsString) - val loadedMap = MapSaver().mapFromJson(decoded) - UnCivGame.Current.screen = MapEditorScreen(loadedMap) - } - add(loadFromClipboardButton).row() - - val closeOptionsButton = TextButton("Close".tr(), CameraStageBaseScreen.skin) - closeOptionsButton.onClick { remove() } - add(closeOptionsButton).row() - - open() - } -} \ No newline at end of file diff --git a/core/src/com/unciv/ui/saves/LoadGameScreen.kt b/core/src/com/unciv/ui/saves/LoadGameScreen.kt index a4054db915..eda487e50d 100644 --- a/core/src/com/unciv/ui/saves/LoadGameScreen.kt +++ b/core/src/com/unciv/ui/saves/LoadGameScreen.kt @@ -22,62 +22,16 @@ class LoadGameScreen : PickerScreen() { lateinit var selectedSave:String val copySavedGameToClipboardButton = TextButton("Copy saved game to clipboard",skin) val saveTable = Table() + val deleteSaveButton = TextButton("Delete save".tr(), skin) init { setDefaultCloseAction() - val deleteSaveButton = TextButton("Delete save".tr(), skin) - deleteSaveButton .onClick { - GameSaver().deleteSave(selectedSave) - UnCivGame.Current.screen = LoadGameScreen() - } - deleteSaveButton.disable() - - rightSideButton.setText("Load game".tr()) - updateLoadableGames(deleteSaveButton,false) + updateLoadableGames(false) topTable.add(ScrollPane(saveTable)).height(stage.height*2/3) - val rightSideTable = Table() - - val errorLabel = "".toLabel().setFontColor(Color.RED) - - val loadFromClipboardButton = TextButton("Load copied data".tr(),skin) - loadFromClipboardButton.onClick { - try{ - val clipboardContentsString = Gdx.app.clipboard.contents.trim() - val decoded = Gzip.unzip(clipboardContentsString) - val loadedGame = GameSaver().json().fromJson(GameInfo::class.java, decoded) - loadedGame.setTransients() - UnCivGame.Current.loadGame(loadedGame) - }catch (ex:Exception){ - errorLabel.setText("Could not load game from clipboard!".tr()) - ex.printStackTrace() - } - } - - rightSideTable.add(loadFromClipboardButton).row() - 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).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() + val rightSideTable = getRightSideTable() topTable.add(rightSideTable) @@ -98,7 +52,55 @@ class LoadGameScreen : PickerScreen() { } - private fun updateLoadableGames(deleteSaveButton: TextButton, showAutosaves:Boolean) { + private fun getRightSideTable(): Table { + val rightSideTable = Table() + + val errorLabel = "".toLabel().setFontColor(Color.RED) + val loadFromClipboardButton = TextButton("Load copied data".tr(), skin) + loadFromClipboardButton.onClick { + try { + val clipboardContentsString = Gdx.app.clipboard.contents.trim() + val decoded = Gzip.unzip(clipboardContentsString) + val loadedGame = GameSaver().json().fromJson(GameInfo::class.java, decoded) + loadedGame.setTransients() + UnCivGame.Current.loadGame(loadedGame) + } catch (ex: Exception) { + errorLabel.setText("Could not load game from clipboard!".tr()) + ex.printStackTrace() + } + } + rightSideTable.add(loadFromClipboardButton).row() + rightSideTable.add(errorLabel).row() + + deleteSaveButton.onClick { + GameSaver().deleteSave(selectedSave) + UnCivGame.Current.screen = LoadGameScreen() + } + deleteSaveButton.disable() + 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).row() + + + val showAutosavesCheckbox = CheckBox("Show autosaves".tr(), skin) + showAutosavesCheckbox.isChecked = false + showAutosavesCheckbox.addListener(object : ChangeListener() { + override fun changed(event: ChangeEvent?, actor: Actor?) { + updateLoadableGames(showAutosavesCheckbox.isChecked) + } + }) + rightSideTable.add(showAutosavesCheckbox).row() + return rightSideTable + } + + private fun updateLoadableGames(showAutosaves:Boolean) { saveTable.clear() for (save in GameSaver().getSaves().sortedByDescending { GameSaver().getSave(it).lastModified() }) { if(save.startsWith("Autosave") && !showAutosaves) continue @@ -128,4 +130,5 @@ class LoadGameScreen : PickerScreen() { } } -} \ No newline at end of file +} + diff --git a/core/src/com/unciv/ui/saves/LoadMapScreen.kt b/core/src/com/unciv/ui/saves/LoadMapScreen.kt new file mode 100644 index 0000000000..b95c91bf28 --- /dev/null +++ b/core/src/com/unciv/ui/saves/LoadMapScreen.kt @@ -0,0 +1,63 @@ +package com.unciv.ui.saves + +import com.badlogic.gdx.Gdx +import com.badlogic.gdx.graphics.Color +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.unciv.UnCivGame +import com.unciv.logic.MapSaver +import com.unciv.logic.map.TileMap +import com.unciv.models.gamebasics.tr +import com.unciv.ui.mapeditor.MapEditorScreen +import com.unciv.ui.pickerscreens.PickerScreen +import com.unciv.ui.utils.disable +import com.unciv.ui.utils.enable +import com.unciv.ui.utils.onClick + +class LoadMapScreen(previousMap: TileMap) : PickerScreen(){ + var chosenMap = "" + val deleteMapButton = TextButton("Delete map",skin) + + init { + rightSideButton.setText("Load map") + rightSideButton.onClick { + UnCivGame.Current.screen = MapEditorScreen(chosenMap) + dispose() + } + + val mapsTable = Table().apply { defaults().pad(10f) } + for (map in MapSaver().getMaps()) { + val loadMapButton = TextButton(map, skin) + loadMapButton.onClick { + rightSideButton.enable() + chosenMap = map + deleteMapButton.enable() + deleteMapButton.color = Color.RED + } + mapsTable.add(loadMapButton).row() + } + topTable.add(ScrollPane(mapsTable)).height(stage.height * 2 / 3) + + val rightSideTable = Table().apply { defaults().pad(10f) } + val loadFromClipboardButton = TextButton("Load copied data".tr(), skin) + loadFromClipboardButton .onClick { + val clipboardContentsString = Gdx.app.clipboard.contents.trim() + val decoded = Gzip.unzip(clipboardContentsString) + val loadedMap = MapSaver().mapFromJson(decoded) + UnCivGame.Current.screen = MapEditorScreen(loadedMap) + } + rightSideTable.add(loadFromClipboardButton).row() + + deleteMapButton.onClick { + MapSaver().deleteMap(chosenMap) + UnCivGame.Current.screen = LoadMapScreen(previousMap) + } + deleteMapButton.disable() + deleteMapButton.color = Color.RED + rightSideTable.add(deleteMapButton).row() + + topTable.add(rightSideTable) + closeButton.onClick { UnCivGame.Current.screen = MapEditorScreen(previousMap) } + } +} \ No newline at end of file