Solved ANRs when loading big maps in editor screen

This commit is contained in:
Yair Morgenstern 2021-01-01 13:40:31 +02:00
parent 26c817a4a1
commit 908cae1881
2 changed files with 17 additions and 5 deletions

View File

@ -14,6 +14,7 @@ import com.unciv.models.translations.tr
import com.unciv.ui.pickerscreens.PickerScreen
import com.unciv.ui.saves.Gzip
import com.unciv.ui.utils.*
import kotlin.concurrent.thread
import com.unciv.ui.utils.AutoScrollPane as ScrollPane
class LoadMapScreen(previousMap: TileMap?) : PickerScreen(){
@ -36,11 +37,22 @@ class LoadMapScreen(previousMap: TileMap?) : PickerScreen(){
rightSideButton.setText("Load map".tr())
rightSideButton.onClick {
val mapEditorScreen = if (scenarioMap) MapEditorScreen(MapSaver.loadScenario(chosenMap!!), chosenMap!!.name())
else MapEditorScreen(chosenMap!!)
UncivGame.Current.setScreen(mapEditorScreen)
thread {
if (scenarioMap) {
val scenario = MapSaver.loadScenario(chosenMap!!)
Gdx.app.postRunnable {
UncivGame.Current.setScreen(MapEditorScreen(scenario, chosenMap!!.name()))
dispose()
}
} else {
val map = MapSaver.loadMap(chosenMap!!)
Gdx.app.postRunnable {
UncivGame.Current.setScreen(MapEditorScreen(map))
dispose()
}
}
}
}
topTable.add(ScrollPane(mapsTable)).height(stage.height * 2 / 3)
.maxWidth(stage.width / 2)

View File

@ -51,7 +51,7 @@ class MapEditorScreen(): CameraStageBaseScreen() {
initialize()
}
constructor(mapFile:FileHandle):this(MapSaver.loadMap(mapFile))
constructor(mapFile:FileHandle):this()
constructor(map: TileMap) : this() {
tileMap = map