mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-15 18:28:42 +07:00
Solved ANR when waiting for the list of maps
This commit is contained in:
@ -14,42 +14,52 @@ import com.unciv.ui.worldscreen.mainmenu.DropBox
|
||||
import kotlin.concurrent.thread
|
||||
|
||||
class MapDownloadPopup(loadMapScreen: LoadMapScreen): Popup(loadMapScreen) {
|
||||
val contentTable = Table()
|
||||
init {
|
||||
val folderList: DropBox.FolderList
|
||||
thread(name="LoadMapList") { loadContent() }
|
||||
add(contentTable).row()
|
||||
addCloseButton()
|
||||
}
|
||||
|
||||
fun loadContent() {
|
||||
try {
|
||||
folderList = DropBox().getFolderList("/Maps")
|
||||
val scrollableMapTable = Table().apply { defaults().pad(10f) }
|
||||
for (downloadableMap in folderList.entries) {
|
||||
val downloadMapButton = TextButton(downloadableMap.name, CameraStageBaseScreen.skin)
|
||||
downloadMapButton.onClick {
|
||||
thread(name="MapDownload") {
|
||||
try {
|
||||
val mapJsonGzipped = DropBox().downloadFileAsString(downloadableMap.path_display)
|
||||
val decodedMapJson = Gzip.unzip(mapJsonGzipped)
|
||||
val mapObject = MapSaver().mapFromJson(decodedMapJson)
|
||||
MapSaver().saveMap(downloadableMap.name, mapObject)
|
||||
|
||||
// creating a screen is a GL task
|
||||
Gdx.app.postRunnable { UncivGame.Current.setScreen(MapEditorScreen(mapObject)) }
|
||||
} catch (ex: Exception) {
|
||||
print(ex)
|
||||
|
||||
// Yes, even creating popups.
|
||||
Gdx.app.postRunnable {
|
||||
val couldNotDownloadMapPopup = Popup(screen)
|
||||
couldNotDownloadMapPopup.addGoodSizedLabel("Could not download map!").row()
|
||||
couldNotDownloadMapPopup.addCloseButton()
|
||||
couldNotDownloadMapPopup.open()
|
||||
}
|
||||
}
|
||||
val folderList = DropBox().getFolderList("/Maps")
|
||||
Gdx.app.postRunnable {
|
||||
val scrollableMapTable = Table().apply { defaults().pad(10f) }
|
||||
for (downloadableMap in folderList.entries) {
|
||||
val downloadMapButton = TextButton(downloadableMap.name, CameraStageBaseScreen.skin)
|
||||
downloadMapButton.onClick {
|
||||
thread(name = "MapDownload") { loadMap(downloadableMap) }
|
||||
}
|
||||
scrollableMapTable.add(downloadMapButton).row()
|
||||
}
|
||||
scrollableMapTable.add(downloadMapButton).row()
|
||||
contentTable.add(ScrollPane(scrollableMapTable)).height(screen.stage.height * 2 / 3).row()
|
||||
}
|
||||
add(ScrollPane(scrollableMapTable)).height(screen.stage.height * 2 / 3).row()
|
||||
} catch (ex: Exception) {
|
||||
addGoodSizedLabel("Could not get list of maps!").row()
|
||||
}
|
||||
addCloseButton()
|
||||
}
|
||||
|
||||
fun loadMap(downloadableMap: DropBox.FolderListEntry) {
|
||||
|
||||
try {
|
||||
val mapJsonGzipped = DropBox().downloadFileAsString(downloadableMap.path_display)
|
||||
val decodedMapJson = Gzip.unzip(mapJsonGzipped)
|
||||
val mapObject = MapSaver().mapFromJson(decodedMapJson)
|
||||
MapSaver().saveMap(downloadableMap.name, mapObject)
|
||||
|
||||
// creating a screen is a GL task
|
||||
Gdx.app.postRunnable { UncivGame.Current.setScreen(MapEditorScreen(mapObject)) }
|
||||
} catch (ex: Exception) {
|
||||
print(ex)
|
||||
|
||||
// Yes, even creating popups.
|
||||
Gdx.app.postRunnable {
|
||||
val couldNotDownloadMapPopup = Popup(screen)
|
||||
couldNotDownloadMapPopup.addGoodSizedLabel("Could not download map!").row()
|
||||
couldNotDownloadMapPopup.addCloseButton()
|
||||
couldNotDownloadMapPopup.open()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user