mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 14:24:43 -04:00
Save and load game screens now hide autosaves by default
This commit is contained in:
parent
0a777e5b59
commit
60257c6d64
@ -21,8 +21,8 @@ android {
|
|||||||
applicationId "com.unciv.app"
|
applicationId "com.unciv.app"
|
||||||
minSdkVersion 14
|
minSdkVersion 14
|
||||||
targetSdkVersion 28
|
targetSdkVersion 28
|
||||||
versionCode 287
|
versionCode 288
|
||||||
versionName "2.19.6"
|
versionName "2.19.7"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Had to add this crap for Travis to build, it wanted to sign the app
|
// Had to add this crap for Travis to build, it wanted to sign the app
|
||||||
|
@ -2,9 +2,12 @@ package com.unciv.ui.saves
|
|||||||
|
|
||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
import com.badlogic.gdx.graphics.Color
|
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.ScrollPane
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener
|
||||||
import com.unciv.UnCivGame
|
import com.unciv.UnCivGame
|
||||||
import com.unciv.logic.GameInfo
|
import com.unciv.logic.GameInfo
|
||||||
import com.unciv.logic.GameSaver
|
import com.unciv.logic.GameSaver
|
||||||
@ -15,49 +18,24 @@ import com.unciv.ui.worldscreen.optionstable.PopupTable
|
|||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class LoadScreen : PickerScreen() {
|
class LoadGameScreen : PickerScreen() {
|
||||||
lateinit var selectedSave:String
|
lateinit var selectedSave:String
|
||||||
val copySavedGameToClipboardButton = TextButton("Copy saved game to clipboard",skin)
|
val copySavedGameToClipboardButton = TextButton("Copy saved game to clipboard",skin)
|
||||||
|
val saveTable = Table()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
setDefaultCloseAction()
|
setDefaultCloseAction()
|
||||||
val saveTable = Table()
|
|
||||||
|
|
||||||
val deleteSaveButton = TextButton("Delete save".tr(), skin)
|
val deleteSaveButton = TextButton("Delete save".tr(), skin)
|
||||||
deleteSaveButton .onClick {
|
deleteSaveButton .onClick {
|
||||||
GameSaver().deleteSave(selectedSave)
|
GameSaver().deleteSave(selectedSave)
|
||||||
UnCivGame.Current.screen = LoadScreen()
|
UnCivGame.Current.screen = LoadGameScreen()
|
||||||
}
|
}
|
||||||
deleteSaveButton.disable()
|
deleteSaveButton.disable()
|
||||||
|
|
||||||
|
|
||||||
val saves = GameSaver().getSaves()
|
|
||||||
rightSideButton.setText("Load game".tr())
|
rightSideButton.setText("Load game".tr())
|
||||||
for (save in saves.sortedByDescending { GameSaver().getSave(it).lastModified() }) {
|
updateLoadableGames(deleteSaveButton,false)
|
||||||
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()
|
|
||||||
}
|
|
||||||
topTable.add(ScrollPane(saveTable)).height(stage.height*2/3)
|
topTable.add(ScrollPane(saveTable)).height(stage.height*2/3)
|
||||||
|
|
||||||
val rightSideTable = Table()
|
val rightSideTable = Table()
|
||||||
@ -82,13 +60,24 @@ class LoadScreen : PickerScreen() {
|
|||||||
rightSideTable.add(errorLabel).row()
|
rightSideTable.add(errorLabel).row()
|
||||||
rightSideTable.add(deleteSaveButton).row()
|
rightSideTable.add(deleteSaveButton).row()
|
||||||
|
|
||||||
|
|
||||||
copySavedGameToClipboardButton.disable()
|
copySavedGameToClipboardButton.disable()
|
||||||
copySavedGameToClipboardButton.onClick {
|
copySavedGameToClipboardButton.onClick {
|
||||||
val gameText = GameSaver().getSave(selectedSave).readString()
|
val gameText = GameSaver().getSave(selectedSave).readString()
|
||||||
val gzippedGameText = Gzip.zip(gameText)
|
val gzippedGameText = Gzip.zip(gameText)
|
||||||
Gdx.app.clipboard.contents = gzippedGameText
|
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)
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,10 +1,9 @@
|
|||||||
package com.unciv.ui.saves
|
package com.unciv.ui.saves
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
|
import com.badlogic.gdx.scenes.scene2d.Actor
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
import com.badlogic.gdx.scenes.scene2d.ui.*
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextField
|
|
||||||
import com.badlogic.gdx.utils.Json
|
import com.badlogic.gdx.utils.Json
|
||||||
import com.unciv.UnCivGame
|
import com.unciv.UnCivGame
|
||||||
import com.unciv.logic.GameSaver
|
import com.unciv.logic.GameSaver
|
||||||
@ -15,26 +14,17 @@ import com.unciv.ui.utils.onClick
|
|||||||
import com.unciv.ui.utils.toLabel
|
import com.unciv.ui.utils.toLabel
|
||||||
|
|
||||||
|
|
||||||
class SaveScreen : PickerScreen() {
|
class SaveGameScreen : PickerScreen() {
|
||||||
val textField = TextField("", skin)
|
val textField = TextField("", skin)
|
||||||
|
val currentSaves = Table()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
setDefaultCloseAction()
|
setDefaultCloseAction()
|
||||||
val currentSaves = Table()
|
|
||||||
|
|
||||||
currentSaves.add("Current saves".toLabel()).row()
|
currentSaves.add("Current saves".toLabel()).row()
|
||||||
val saves = GameSaver().getSaves().sortedByDescending { GameSaver().getSave(it).lastModified() }
|
updateShownSaves(false)
|
||||||
saves.forEach {
|
|
||||||
val textButton = TextButton(it, skin)
|
|
||||||
textButton.onClick {
|
|
||||||
textField.text = it
|
|
||||||
}
|
|
||||||
currentSaves.add(textButton).pad(5f).row()
|
|
||||||
|
|
||||||
}
|
|
||||||
topTable.add(ScrollPane(currentSaves)).height(stage.height*2/3)
|
topTable.add(ScrollPane(currentSaves)).height(stage.height*2/3)
|
||||||
|
|
||||||
|
|
||||||
val newSave = Table()
|
val newSave = Table()
|
||||||
val defaultSaveName = game.gameInfo.currentPlayer+" - "+game.gameInfo.turns+" turns"
|
val defaultSaveName = game.gameInfo.currentPlayer+" - "+game.gameInfo.turns+" turns"
|
||||||
textField.text = defaultSaveName
|
textField.text = defaultSaveName
|
||||||
@ -48,7 +38,17 @@ class SaveScreen : PickerScreen() {
|
|||||||
val base64Gzip = Gzip.zip(json)
|
val base64Gzip = Gzip.zip(json)
|
||||||
Gdx.app.clipboard.contents = base64Gzip
|
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.add(newSave)
|
||||||
topTable.pack()
|
topTable.pack()
|
||||||
@ -61,6 +61,20 @@ class SaveScreen : PickerScreen() {
|
|||||||
rightSideButton.enable()
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -9,8 +9,8 @@ import com.unciv.ui.newgamescreen.NewGameScreen
|
|||||||
import com.unciv.ui.VictoryScreen
|
import com.unciv.ui.VictoryScreen
|
||||||
import com.unciv.ui.mapeditor.MapEditorScreen
|
import com.unciv.ui.mapeditor.MapEditorScreen
|
||||||
import com.unciv.ui.pickerscreens.PolicyPickerScreen
|
import com.unciv.ui.pickerscreens.PolicyPickerScreen
|
||||||
import com.unciv.ui.saves.LoadScreen
|
import com.unciv.ui.saves.LoadGameScreen
|
||||||
import com.unciv.ui.saves.SaveScreen
|
import com.unciv.ui.saves.SaveGameScreen
|
||||||
import com.unciv.ui.worldscreen.WorldScreen
|
import com.unciv.ui.worldscreen.WorldScreen
|
||||||
|
|
||||||
class WorldScreenMenuTable(val worldScreen: WorldScreen) : PopupTable(worldScreen) {
|
class WorldScreenMenuTable(val worldScreen: WorldScreen) : PopupTable(worldScreen) {
|
||||||
@ -37,12 +37,12 @@ class WorldScreenMenuTable(val worldScreen: WorldScreen) : PopupTable(worldScree
|
|||||||
}
|
}
|
||||||
|
|
||||||
addButton("Load game".tr()){
|
addButton("Load game".tr()){
|
||||||
UnCivGame.Current.screen = LoadScreen()
|
UnCivGame.Current.screen = LoadGameScreen()
|
||||||
remove()
|
remove()
|
||||||
}
|
}
|
||||||
|
|
||||||
addButton("Save game".tr()) {
|
addButton("Save game".tr()) {
|
||||||
UnCivGame.Current.screen = SaveScreen()
|
UnCivGame.Current.screen = SaveGameScreen()
|
||||||
remove()
|
remove()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user