From ba505dcfdbedf25afe40515879891e10521343e4 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Wed, 23 Jun 2021 10:13:11 +0300 Subject: [PATCH] Deprecated 'download map' - map sharing should be done via Mods --- .../unciv/ui/mapeditor/MapDownloadPopup.kt | 100 ------------------ 1 file changed, 100 deletions(-) delete mode 100644 core/src/com/unciv/ui/mapeditor/MapDownloadPopup.kt diff --git a/core/src/com/unciv/ui/mapeditor/MapDownloadPopup.kt b/core/src/com/unciv/ui/mapeditor/MapDownloadPopup.kt deleted file mode 100644 index 988a0feb6a..0000000000 --- a/core/src/com/unciv/ui/mapeditor/MapDownloadPopup.kt +++ /dev/null @@ -1,100 +0,0 @@ -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.unciv.logic.MapSaver -import com.unciv.ui.saves.Gzip -import com.unciv.ui.utils.* -import com.unciv.ui.worldscreen.mainmenu.DropBox -import kotlin.concurrent.thread -import com.unciv.ui.utils.AutoScrollPane as ScrollPane - -class MapDownloadPopup(loadMapScreen: SaveAndLoadMapScreen): Popup(loadMapScreen) { - private val contentTable = Table() - private val header = Table() - private val listOfMaps = mutableListOf() - private val scrollableMapTable = Table() - private val loadingLabel = "Loading...".toLabel() - - init { - add(header).row() - add(loadingLabel).row() - thread(name="LoadMapList") { loadContent() } - add(contentTable).row() - addCloseButton() - } - - private fun createHeader() { - header.defaults().pad(5f) - header.add("Filter:".toLabel()) - val filter = TextField("", skin) - val listener = TextField.TextFieldListener{ textField: TextField, _: Char -> updateList(textField.text) } - filter.setTextFieldListener(listener) - header.add(filter).row() - keyboardFocus = filter - header.addSeparator().row() - pack() - } - - private fun updateList(filterText : String) { - scrollableMapTable.clear() - listOfMaps.forEach { if (it.text.contains(filterText)) scrollableMapTable.add(it).row() } - contentTable.pack() - } - - private fun loadContent() { - try { - val folderList = DropBox.getFolderList("/Maps") - Gdx.app.postRunnable { - scrollableMapTable.apply { defaults().pad(10f) } - for (downloadableMap in folderList) { - val downloadMapButton = downloadableMap.name.toTextButton() - listOfMaps.add(downloadMapButton) - downloadMapButton.onClick { - thread(name = "MapDownload") { loadMap(downloadableMap) } - } - scrollableMapTable.add(downloadMapButton).row() - } - val scrollPane = ScrollPane(scrollableMapTable) - contentTable.add(scrollPane).height(screen.stage.height * 2 / 3).row() - // the list is loaded and ready to be shown - remove "Loading..." - innerTable.removeActor(loadingLabel) - // create the header with a filter tool - createHeader() - pack() - center(screen.stage) - // Due to some jokers spamming very long names the content would end up way on the right - // scrollPane.scrollPercentX = 0.5f does _not_ work for this! That fun doesn't refer to the center. - // This will bounce in with visual effect, if undesired call updateVisualScroll() - scrollPane.scrollX = scrollPane.maxX / 2 - } - } catch (ex: Exception) { - Gdx.app.postRunnable { addGoodSizedLabel("Could not get list of maps!").row() } - } - } - - private 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 { screen.game.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() - } - } - } -}