From 17f41a549eed6b4aeadffe49119b0681213fbed4 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sun, 25 Aug 2019 17:16:36 +0300 Subject: [PATCH] "Upload map" now deals with failures properly Maps for downloading now scrollable --- .../ui/mapeditor/MapEditorOptionsTable.kt | 47 ++++++++++++++----- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/core/src/com/unciv/ui/mapeditor/MapEditorOptionsTable.kt b/core/src/com/unciv/ui/mapeditor/MapEditorOptionsTable.kt index 3941d80b..1ffd9650 100644 --- a/core/src/com/unciv/ui/mapeditor/MapEditorOptionsTable.kt +++ b/core/src/com/unciv/ui/mapeditor/MapEditorOptionsTable.kt @@ -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() } } \ No newline at end of file