mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-24 06:39:16 +07:00
"Upload map" now deals with failures properly
Maps for downloading now scrollable
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
package com.unciv.ui.mapeditor
|
package com.unciv.ui.mapeditor
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx
|
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.TextButton
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextField
|
import com.badlogic.gdx.scenes.scene2d.ui.TextField
|
||||||
import com.badlogic.gdx.utils.Json
|
import com.badlogic.gdx.utils.Json
|
||||||
@ -10,6 +11,7 @@ import com.unciv.logic.MapSaver
|
|||||||
import com.unciv.logic.map.RoadStatus
|
import com.unciv.logic.map.RoadStatus
|
||||||
import com.unciv.models.gamebasics.tr
|
import com.unciv.models.gamebasics.tr
|
||||||
import com.unciv.ui.saves.Gzip
|
import com.unciv.ui.saves.Gzip
|
||||||
|
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
|
||||||
@ -59,13 +61,31 @@ class MapEditorOptionsTable(mapEditorScreen: MapEditorScreen): PopupTable(mapEdi
|
|||||||
|
|
||||||
val uploadMapButton = TextButton("Upload".tr(), skin)
|
val uploadMapButton = TextButton("Upload".tr(), skin)
|
||||||
uploadMapButton.onClick {
|
uploadMapButton.onClick {
|
||||||
|
try {
|
||||||
val gzippedMap = Gzip.zip(Json().toJson(mapEditorScreen.tileMap))
|
val gzippedMap = Gzip.zip(Json().toJson(mapEditorScreen.tileMap))
|
||||||
DropBox().uploadFile("/Maps/"+mapEditorScreen.mapName,gzippedMap)
|
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()
|
add(uploadMapButton).row()
|
||||||
|
|
||||||
val downloadMapButton = TextButton("Download".tr(), skin)
|
val downloadMapButton = TextButton("Download".tr(), skin)
|
||||||
downloadMapButton.onClick { MapDownloadTable(mapEditorScreen); remove() }
|
downloadMapButton.onClick {
|
||||||
|
remove()
|
||||||
|
MapDownloadTable(mapEditorScreen)
|
||||||
|
}
|
||||||
add(downloadMapButton).row()
|
add(downloadMapButton).row()
|
||||||
|
|
||||||
val exitMapEditorButton = TextButton("Exit map editor".tr(), skin)
|
val exitMapEditorButton = TextButton("Exit map editor".tr(), skin)
|
||||||
@ -80,25 +100,28 @@ class MapEditorOptionsTable(mapEditorScreen: MapEditorScreen): PopupTable(mapEdi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MapDownloadTable(mapEditorScreen: MapEditorScreen):PopupTable(mapEditorScreen){
|
class MapDownloadTable(mapEditorScreen: MapEditorScreen):PopupTable(mapEditorScreen) {
|
||||||
init{
|
init {
|
||||||
val folderList: DropBox.FolderList
|
val folderList: DropBox.FolderList
|
||||||
try{
|
try {
|
||||||
folderList = DropBox().getFolderList("/Maps")
|
folderList = DropBox().getFolderList("/Maps")
|
||||||
for(downloadableMap in folderList.entries){
|
val scrollableMapTable = Table()
|
||||||
addButton(downloadableMap.name){
|
for (downloadableMap in folderList.entries) {
|
||||||
|
val downloadMapButton = TextButton(downloadableMap.name, CameraStageBaseScreen.skin)
|
||||||
|
downloadMapButton.onClick {
|
||||||
val mapJsonGzipped = DropBox().downloadFile(downloadableMap.path_display)
|
val mapJsonGzipped = DropBox().downloadFile(downloadableMap.path_display)
|
||||||
val decodedMapJson = Gzip.unzip(mapJsonGzipped)
|
val decodedMapJson = Gzip.unzip(mapJsonGzipped)
|
||||||
val mapObject = MapSaver().mapFromJson(decodedMapJson)
|
val mapObject = MapSaver().mapFromJson(decodedMapJson)
|
||||||
MapSaver().saveMap(downloadableMap.name, mapObject)
|
MapSaver().saveMap(downloadableMap.name, mapObject)
|
||||||
UnCivGame.Current.screen = MapEditorScreen(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){
|
addButton("Close") { remove() }
|
||||||
addGoodSizedLabel("Could not get list of maps!")
|
|
||||||
}
|
|
||||||
addButton("Close"){remove()}
|
|
||||||
open()
|
open()
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user