Solved Application Not Responding when downloading map
This commit is contained in:
parent
fc4eb01be8
commit
e82cdd42fa
1 changed files with 21 additions and 11 deletions
|
@ -1,5 +1,6 @@
|
||||||
package com.unciv.ui.mapeditor
|
package com.unciv.ui.mapeditor
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Gdx
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
|
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
|
||||||
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
|
||||||
|
@ -10,6 +11,7 @@ import com.unciv.ui.utils.CameraStageBaseScreen
|
||||||
import com.unciv.ui.utils.onClick
|
import com.unciv.ui.utils.onClick
|
||||||
import com.unciv.ui.worldscreen.optionstable.DropBox
|
import com.unciv.ui.worldscreen.optionstable.DropBox
|
||||||
import com.unciv.ui.worldscreen.optionstable.PopupTable
|
import com.unciv.ui.worldscreen.optionstable.PopupTable
|
||||||
|
import kotlin.concurrent.thread
|
||||||
|
|
||||||
class MapDownloadTable(loadMapScreen: LoadMapScreen): PopupTable(loadMapScreen) {
|
class MapDownloadTable(loadMapScreen: LoadMapScreen): PopupTable(loadMapScreen) {
|
||||||
init {
|
init {
|
||||||
|
@ -20,17 +22,25 @@ class MapDownloadTable(loadMapScreen: LoadMapScreen): PopupTable(loadMapScreen)
|
||||||
for (downloadableMap in folderList.entries) {
|
for (downloadableMap in folderList.entries) {
|
||||||
val downloadMapButton = TextButton(downloadableMap.name, CameraStageBaseScreen.skin)
|
val downloadMapButton = TextButton(downloadableMap.name, CameraStageBaseScreen.skin)
|
||||||
downloadMapButton.onClick {
|
downloadMapButton.onClick {
|
||||||
try{
|
thread {
|
||||||
val mapJsonGzipped = DropBox().downloadFileAsString(downloadableMap.path_display)
|
try {
|
||||||
val decodedMapJson = Gzip.unzip(mapJsonGzipped)
|
val mapJsonGzipped = DropBox().downloadFileAsString(downloadableMap.path_display)
|
||||||
val mapObject = MapSaver().mapFromJson(decodedMapJson)
|
val decodedMapJson = Gzip.unzip(mapJsonGzipped)
|
||||||
MapSaver().saveMap(downloadableMap.name, mapObject)
|
val mapObject = MapSaver().mapFromJson(decodedMapJson)
|
||||||
UncivGame.Current.setScreen(MapEditorScreen(mapObject))
|
MapSaver().saveMap(downloadableMap.name, mapObject)
|
||||||
}
|
|
||||||
catch(ex:Exception){
|
// creating a screen is a GL task
|
||||||
val couldNotDownloadMapPopup = PopupTable(screen)
|
Gdx.app.postRunnable { UncivGame.Current.setScreen(MapEditorScreen(mapObject)) }
|
||||||
couldNotDownloadMapPopup.addGoodSizedLabel("Could not download map!").row()
|
} catch (ex: Exception) {
|
||||||
couldNotDownloadMapPopup.addCloseButton()
|
print(ex)
|
||||||
|
|
||||||
|
// Yes, even creating popups.
|
||||||
|
Gdx.app.postRunnable {
|
||||||
|
val couldNotDownloadMapPopup = PopupTable(screen)
|
||||||
|
couldNotDownloadMapPopup.addGoodSizedLabel("Could not download map!").row()
|
||||||
|
couldNotDownloadMapPopup.addCloseButton()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
scrollableMapTable.add(downloadMapButton).row()
|
scrollableMapTable.add(downloadMapButton).row()
|
||||||
|
|
Loading…
Reference in a new issue