mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-29 06:51:30 -04:00
Fixed ANR caused by too many saved games
This commit is contained in:
parent
4578994adf
commit
ab548dda54
@ -1,10 +1,13 @@
|
|||||||
package com.unciv.ui.saves
|
package com.unciv.ui.saves
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
|
import com.badlogic.gdx.files.FileHandle
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.actions.Actions
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.CheckBox
|
import com.badlogic.gdx.scenes.scene2d.ui.CheckBox
|
||||||
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.utils.Align
|
||||||
import com.unciv.UncivGame
|
import com.unciv.UncivGame
|
||||||
import com.unciv.logic.GameSaver
|
import com.unciv.logic.GameSaver
|
||||||
import com.unciv.logic.UncivShowableException
|
import com.unciv.logic.UncivShowableException
|
||||||
@ -129,10 +132,31 @@ class LoadGameScreen(previousScreen:CameraStageBaseScreen) : PickerScreen() {
|
|||||||
|
|
||||||
private fun updateLoadableGames(showAutosaves:Boolean) {
|
private fun updateLoadableGames(showAutosaves:Boolean) {
|
||||||
saveTable.clear()
|
saveTable.clear()
|
||||||
for (save in GameSaver.getSaves().sortedByDescending { it.lastModified() }) {
|
|
||||||
|
val loadImage =ImageGetter.getImage("OtherIcons/Load")
|
||||||
|
loadImage.setSize(50f,50f) // So the origin sets correctly
|
||||||
|
loadImage.setOrigin(Align.center)
|
||||||
|
loadImage.addAction(Actions.rotateBy(360f, 2f))
|
||||||
|
saveTable.add(loadImage).size(50f)
|
||||||
|
|
||||||
|
thread { // Apparently, even jut getting the list of saves can cause ANRs -
|
||||||
|
// not sure how many saves these guys had but Google Play reports this to have happened hundreds of times
|
||||||
|
// .toList() because otherwise the lastModified will only be checked inside the postRunnable
|
||||||
|
val saves = GameSaver.getSaves().sortedByDescending { it.lastModified() }.toList()
|
||||||
|
|
||||||
|
Gdx.app.postRunnable {
|
||||||
|
saveTable.clear()
|
||||||
|
for (save in saves) {
|
||||||
if (save.name().startsWith("Autosave") && !showAutosaves) continue
|
if (save.name().startsWith("Autosave") && !showAutosaves) continue
|
||||||
val textButton = TextButton(save.name(), skin)
|
val textButton = TextButton(save.name(), skin)
|
||||||
textButton.onClick {
|
textButton.onClick { onSaveSelected(save) }
|
||||||
|
saveTable.add(textButton).pad(5f).row()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onSaveSelected(save: FileHandle) {
|
||||||
selectedSave = save.name()
|
selectedSave = save.name()
|
||||||
copySavedGameToClipboardButton.enable()
|
copySavedGameToClipboardButton.enable()
|
||||||
var textToSet = save.name()
|
var textToSet = save.name()
|
||||||
@ -159,9 +183,6 @@ class LoadGameScreen(previousScreen:CameraStageBaseScreen) : PickerScreen() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
saveTable.add(textButton).pad(5f).row()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ object ImageGetter {
|
|||||||
// These are from the mods
|
// These are from the mods
|
||||||
for (mod in ruleset.mods) {
|
for (mod in ruleset.mods) {
|
||||||
val modAtlasFile = Gdx.files.local("mods/$mod/game.atlas")
|
val modAtlasFile = Gdx.files.local("mods/$mod/game.atlas")
|
||||||
if (modAtlasFile.exists()) {
|
if (!modAtlasFile.exists()) continue
|
||||||
val modAtlas = TextureAtlas(modAtlasFile)
|
val modAtlas = TextureAtlas(modAtlasFile)
|
||||||
for (region in modAtlas.regions) {
|
for (region in modAtlas.regions) {
|
||||||
val drawable = TextureRegionDrawable(region)
|
val drawable = TextureRegionDrawable(region)
|
||||||
@ -85,7 +85,6 @@ object ImageGetter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -142,12 +141,6 @@ object ImageGetter {
|
|||||||
return layerList
|
return layerList
|
||||||
}
|
}
|
||||||
|
|
||||||
/*fun refreshAtlas() {
|
|
||||||
atlas.dispose() // To avoid OutOfMemory exceptions
|
|
||||||
atlas = TextureAtlas("game.atlas")
|
|
||||||
setTextureRegionDrawables()
|
|
||||||
}*/
|
|
||||||
|
|
||||||
fun getWhiteDot() = getImage(whiteDotLocation)
|
fun getWhiteDot() = getImage(whiteDotLocation)
|
||||||
fun getDot(dotColor: Color) = getWhiteDot().apply { color = dotColor }
|
fun getDot(dotColor: Color) = getWhiteDot().apply { color = dotColor }
|
||||||
|
|
||||||
@ -192,8 +185,7 @@ object ImageGetter {
|
|||||||
cityStateIcon.color = nation.getInnerColor()
|
cityStateIcon.color = nation.getInnerColor()
|
||||||
return cityStateIcon.surroundWithCircle(size * 0.9f).apply { circle.color = nation.getOuterColor() }
|
return cityStateIcon.surroundWithCircle(size * 0.9f).apply { circle.color = nation.getOuterColor() }
|
||||||
.surroundWithCircle(size, false).apply { circle.color = nation.getInnerColor() }
|
.surroundWithCircle(size, false).apply { circle.color = nation.getInnerColor() }
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
return getCircle().apply { color = nation.getOuterColor() }
|
return getCircle().apply { color = nation.getOuterColor() }
|
||||||
.surroundWithCircle(size).apply { circle.color = nation.getInnerColor() }
|
.surroundWithCircle(size).apply { circle.color = nation.getInnerColor() }
|
||||||
|
|
||||||
@ -385,4 +377,3 @@ object ImageGetter {
|
|||||||
return specialist
|
return specialist
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user