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.pickerscreens.PickerScreen
import com.unciv.ui.saves.Gzip import com.unciv.ui.saves.Gzip
import com.unciv.ui.utils.* import com.unciv.ui.utils.*
import kotlin.concurrent.thread
import com.unciv.ui.utils.AutoScrollPane as ScrollPane import com.unciv.ui.utils.AutoScrollPane as ScrollPane
class LoadMapScreen(previousMap: TileMap?) : PickerScreen(){ class LoadMapScreen(previousMap: TileMap?) : PickerScreen(){
@ -36,10 +37,21 @@ class LoadMapScreen(previousMap: TileMap?) : PickerScreen(){
rightSideButton.setText("Load map".tr()) rightSideButton.setText("Load map".tr())
rightSideButton.onClick { rightSideButton.onClick {
val mapEditorScreen = if (scenarioMap) MapEditorScreen(MapSaver.loadScenario(chosenMap!!), chosenMap!!.name()) thread {
else MapEditorScreen(chosenMap!!) if (scenarioMap) {
UncivGame.Current.setScreen(mapEditorScreen) val scenario = MapSaver.loadScenario(chosenMap!!)
dispose() 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) topTable.add(ScrollPane(mapsTable)).height(stage.height * 2 / 3)

View File

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