mirror of
https://github.com/yairm210/Unciv.git
synced 2025-03-12 19:10:12 +07:00
Solved ANR when loading game to display its metadata
This commit is contained in:
parent
c756014fec
commit
3a2b8453d5
@ -13,6 +13,7 @@ import com.unciv.ui.pickerscreens.PickerScreen
|
|||||||
import com.unciv.ui.utils.*
|
import com.unciv.ui.utils.*
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import kotlin.concurrent.thread
|
||||||
import com.unciv.ui.utils.AutoScrollPane as ScrollPane
|
import com.unciv.ui.utils.AutoScrollPane as ScrollPane
|
||||||
|
|
||||||
class LoadGameScreen(previousScreen:CameraStageBaseScreen) : PickerScreen() {
|
class LoadGameScreen(previousScreen:CameraStageBaseScreen) : PickerScreen() {
|
||||||
@ -122,20 +123,26 @@ class LoadGameScreen(previousScreen:CameraStageBaseScreen) : PickerScreen() {
|
|||||||
var textToSet = save
|
var textToSet = save
|
||||||
|
|
||||||
val savedAt = Date(GameSaver.getSave(save).lastModified())
|
val savedAt = Date(GameSaver.getSave(save).lastModified())
|
||||||
|
descriptionLabel.setText("Loading...".tr())
|
||||||
textToSet += "\n{Saved at}: ".tr() + SimpleDateFormat("yyyy-MM-dd HH:mm").format(savedAt)
|
textToSet += "\n{Saved at}: ".tr() + SimpleDateFormat("yyyy-MM-dd HH:mm").format(savedAt)
|
||||||
try {
|
thread { // Even loading the game to get its metadata can take a long time on older phones
|
||||||
val game = GameSaver.loadGameByName(save)
|
try {
|
||||||
val playerCivNames = game.civilizations.filter { it.isPlayerCivilization() }.joinToString { it.civName.tr() }
|
val game = GameSaver.loadGameByName(save)
|
||||||
textToSet += "\n" + playerCivNames +
|
val playerCivNames = game.civilizations.filter { it.isPlayerCivilization() }.joinToString { it.civName.tr() }
|
||||||
", " + game.difficulty.tr() + ", {Turn} ".tr() + game.turns
|
textToSet += "\n" + playerCivNames +
|
||||||
} catch (ex: Exception) {
|
", " + game.difficulty.tr() + ", {Turn} ".tr() + game.turns
|
||||||
textToSet += "\n{Could not load game}!".tr()
|
} catch (ex: Exception) {
|
||||||
|
textToSet += "\n{Could not load game}!".tr()
|
||||||
|
}
|
||||||
|
|
||||||
|
Gdx.app.postRunnable {
|
||||||
|
descriptionLabel.setText(textToSet)
|
||||||
|
rightSideButton.setText("Load [$save]".tr())
|
||||||
|
rightSideButton.enable()
|
||||||
|
deleteSaveButton.enable()
|
||||||
|
deleteSaveButton.color = Color.RED
|
||||||
|
}
|
||||||
}
|
}
|
||||||
descriptionLabel.setText(textToSet)
|
|
||||||
rightSideButton.setText("Load [$save]".tr())
|
|
||||||
rightSideButton.enable()
|
|
||||||
deleteSaveButton.enable()
|
|
||||||
deleteSaveButton.color = Color.RED
|
|
||||||
}
|
}
|
||||||
saveTable.add(textButton).pad(5f).row()
|
saveTable.add(textButton).pad(5f).row()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user