mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 22:06:05 -04:00
Deprecated 'download map' - map sharing should be done via Mods
This commit is contained in:
parent
5b730fbc56
commit
ba505dcfdb
@ -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<TextButton>()
|
|
||||||
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()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user