"Upload map" now deals with failures properly

Maps for downloading now scrollable
This commit is contained in:
Yair Morgenstern 2019-08-25 17:16:36 +03:00
parent 60257c6d64
commit 17f41a549e

View file

@ -1,6 +1,7 @@
package com.unciv.ui.mapeditor
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
import com.badlogic.gdx.scenes.scene2d.ui.TextField
import com.badlogic.gdx.utils.Json
@ -10,6 +11,7 @@ import com.unciv.logic.MapSaver
import com.unciv.logic.map.RoadStatus
import com.unciv.models.gamebasics.tr
import com.unciv.ui.saves.Gzip
import com.unciv.ui.utils.CameraStageBaseScreen
import com.unciv.ui.utils.onClick
import com.unciv.ui.worldscreen.optionstable.DropBox
import com.unciv.ui.worldscreen.optionstable.PopupTable
@ -59,13 +61,31 @@ class MapEditorOptionsTable(mapEditorScreen: MapEditorScreen): PopupTable(mapEdi
val uploadMapButton = TextButton("Upload".tr(), skin)
uploadMapButton.onClick {
val gzippedMap = Gzip.zip(Json().toJson(mapEditorScreen.tileMap))
DropBox().uploadFile("/Maps/"+mapEditorScreen.mapName,gzippedMap)
try {
val gzippedMap = Gzip.zip(Json().toJson(mapEditorScreen.tileMap))
DropBox().uploadFile("/Maps/" + mapEditorScreen.mapName, gzippedMap)
remove()
val uploadedSuccessfully = PopupTable(screen)
uploadedSuccessfully.addGoodSizedLabel("Map uploaded successfully!").row()
uploadedSuccessfully.addButton("Close") { uploadedSuccessfully.remove() }
uploadedSuccessfully.open()
}
catch(ex:Exception){
remove()
val couldNotUpload = PopupTable(screen)
couldNotUpload.addGoodSizedLabel("Could not upload map!").row()
couldNotUpload.addButton("Close") { couldNotUpload.remove() }
couldNotUpload.open()
}
}
add(uploadMapButton).row()
val downloadMapButton = TextButton("Download".tr(), skin)
downloadMapButton.onClick { MapDownloadTable(mapEditorScreen); remove() }
downloadMapButton.onClick {
remove()
MapDownloadTable(mapEditorScreen)
}
add(downloadMapButton).row()
val exitMapEditorButton = TextButton("Exit map editor".tr(), skin)
@ -80,25 +100,28 @@ class MapEditorOptionsTable(mapEditorScreen: MapEditorScreen): PopupTable(mapEdi
}
}
class MapDownloadTable(mapEditorScreen: MapEditorScreen):PopupTable(mapEditorScreen){
init{
class MapDownloadTable(mapEditorScreen: MapEditorScreen):PopupTable(mapEditorScreen) {
init {
val folderList: DropBox.FolderList
try{
try {
folderList = DropBox().getFolderList("/Maps")
for(downloadableMap in folderList.entries){
addButton(downloadableMap.name){
val scrollableMapTable = Table()
for (downloadableMap in folderList.entries) {
val downloadMapButton = TextButton(downloadableMap.name, CameraStageBaseScreen.skin)
downloadMapButton.onClick {
val mapJsonGzipped = DropBox().downloadFile(downloadableMap.path_display)
val decodedMapJson = Gzip.unzip(mapJsonGzipped)
val mapObject = MapSaver().mapFromJson(decodedMapJson)
MapSaver().saveMap(downloadableMap.name, mapObject)
UnCivGame.Current.screen = MapEditorScreen(mapObject)
}
scrollableMapTable.add(downloadMapButton).row()
}
add(scrollableMapTable).height(mapEditorScreen.stage.height * 2 / 3).row()
} catch (ex: Exception) {
addGoodSizedLabel("Could not get list of maps!").row()
}
catch (ex:Exception){
addGoodSizedLabel("Could not get list of maps!")
}
addButton("Close"){remove()}
addButton("Close") { remove() }
open()
}
}