mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-14 01:39:40 +07:00
Load Map screen now includes Download, and can handle large map names
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
package com.unciv.ui.saves
|
||||
package com.unciv.ui.mapeditor
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
@ -9,12 +9,12 @@ import com.unciv.UncivGame
|
||||
import com.unciv.logic.MapSaver
|
||||
import com.unciv.logic.map.TileMap
|
||||
import com.unciv.models.gamebasics.tr
|
||||
import com.unciv.ui.mapeditor.MapEditorScreen
|
||||
import com.unciv.ui.pickerscreens.PickerScreen
|
||||
import com.unciv.ui.saves.Gzip
|
||||
import com.unciv.ui.utils.*
|
||||
import com.unciv.ui.worldscreen.optionstable.YesNoPopupTable
|
||||
|
||||
class LoadMapScreen(previousMap: TileMap) : PickerScreen(){
|
||||
class LoadMapScreen(previousMap: TileMap?) : PickerScreen(){
|
||||
var chosenMap = ""
|
||||
val deleteMapButton = TextButton("Delete map",skin)
|
||||
|
||||
@ -37,8 +37,19 @@ class LoadMapScreen(previousMap: TileMap) : PickerScreen(){
|
||||
mapsTable.add(loadMapButton).row()
|
||||
}
|
||||
topTable.add(ScrollPane(mapsTable)).height(stage.height * 2 / 3)
|
||||
.maxWidth(stage.width/2)
|
||||
|
||||
val rightSideTable = Table().apply { defaults().pad(10f) }
|
||||
|
||||
val downloadMapButton = TextButton("Download map".tr(), skin)
|
||||
downloadMapButton.onClick {
|
||||
MapDownloadTable(this)
|
||||
}
|
||||
rightSideTable.add(downloadMapButton).row()
|
||||
|
||||
rightSideTable.addSeparator()
|
||||
|
||||
|
||||
val loadFromClipboardButton = TextButton("Load copied data".tr(), skin)
|
||||
val couldNotLoadMapLabel = "Could not load map!".toLabel(Color.RED).apply { isVisible=false }
|
||||
loadFromClipboardButton.onClick {
|
||||
@ -66,6 +77,9 @@ class LoadMapScreen(previousMap: TileMap) : PickerScreen(){
|
||||
rightSideTable.add(deleteMapButton).row()
|
||||
|
||||
topTable.add(rightSideTable)
|
||||
closeButton.onClick { UncivGame.Current.setScreen(MapEditorScreen(previousMap)) }
|
||||
if(previousMap==null) closeButton.isVisible=false
|
||||
else closeButton.onClick { UncivGame.Current.setScreen(MapEditorScreen(previousMap)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
45
core/src/com/unciv/ui/mapeditor/MapDownloadTable.kt
Normal file
45
core/src/com/unciv/ui/mapeditor/MapDownloadTable.kt
Normal file
@ -0,0 +1,45 @@
|
||||
package com.unciv.ui.mapeditor
|
||||
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.MapSaver
|
||||
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
|
||||
|
||||
class MapDownloadTable(loadMapScreen: LoadMapScreen): PopupTable(loadMapScreen) {
|
||||
init {
|
||||
val folderList: DropBox.FolderList
|
||||
try {
|
||||
folderList = DropBox().getFolderList("/Maps")
|
||||
val scrollableMapTable = Table().apply { defaults().pad(10f) }
|
||||
for (downloadableMap in folderList.entries) {
|
||||
val downloadMapButton = TextButton(downloadableMap.name, CameraStageBaseScreen.skin)
|
||||
downloadMapButton.onClick {
|
||||
try{
|
||||
val mapJsonGzipped = DropBox().downloadFileAsString(downloadableMap.path_display)
|
||||
val decodedMapJson = Gzip.unzip(mapJsonGzipped)
|
||||
val mapObject = MapSaver().mapFromJson(decodedMapJson)
|
||||
MapSaver().saveMap(downloadableMap.name, mapObject)
|
||||
UncivGame.Current.setScreen(MapEditorScreen(mapObject))
|
||||
}
|
||||
catch(ex:Exception){
|
||||
val couldNotDownloadMapPopup = PopupTable(screen)
|
||||
couldNotDownloadMapPopup.addGoodSizedLabel("Could not download map!").row()
|
||||
couldNotDownloadMapPopup.addCloseButton()
|
||||
}
|
||||
}
|
||||
scrollableMapTable.add(downloadMapButton).row()
|
||||
}
|
||||
add(ScrollPane(scrollableMapTable)).height(screen.stage.height * 2 / 3).row()
|
||||
} catch (ex: Exception) {
|
||||
addGoodSizedLabel("Could not get list of maps!").row()
|
||||
}
|
||||
addCloseButton()
|
||||
open()
|
||||
}
|
||||
}
|
@ -1,8 +1,6 @@
|
||||
package com.unciv.ui.mapeditor
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
|
||||
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
|
||||
@ -13,8 +11,6 @@ import com.unciv.logic.map.MapType
|
||||
import com.unciv.logic.map.RoadStatus
|
||||
import com.unciv.models.gamebasics.tr
|
||||
import com.unciv.ui.saves.Gzip
|
||||
import com.unciv.ui.saves.LoadMapScreen
|
||||
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
|
||||
@ -88,12 +84,6 @@ class MapEditorMenuPopup(mapEditorScreen: MapEditorScreen): PopupTable(mapEditor
|
||||
}
|
||||
add(uploadMapButton).row()
|
||||
|
||||
val downloadMapButton = TextButton("Download map".tr(), skin)
|
||||
downloadMapButton.onClick {
|
||||
remove()
|
||||
MapDownloadTable(mapEditorScreen)
|
||||
}
|
||||
add(downloadMapButton).row()
|
||||
|
||||
val exitMapEditorButton = TextButton("Exit map editor".tr(), skin)
|
||||
exitMapEditorButton.onClick { UncivGame.Current.setWorldScreen(); mapEditorScreen.dispose() }
|
||||
@ -106,36 +96,3 @@ class MapEditorMenuPopup(mapEditorScreen: MapEditorScreen): PopupTable(mapEditor
|
||||
open()
|
||||
}
|
||||
}
|
||||
|
||||
class MapDownloadTable(mapEditorScreen: MapEditorScreen):PopupTable(mapEditorScreen) {
|
||||
init {
|
||||
val folderList: DropBox.FolderList
|
||||
try {
|
||||
folderList = DropBox().getFolderList("/Maps")
|
||||
val scrollableMapTable = Table().apply { defaults().pad(10f) }
|
||||
for (downloadableMap in folderList.entries) {
|
||||
val downloadMapButton = TextButton(downloadableMap.name, CameraStageBaseScreen.skin)
|
||||
downloadMapButton.onClick {
|
||||
try{
|
||||
val mapJsonGzipped = DropBox().downloadFileAsString(downloadableMap.path_display)
|
||||
val decodedMapJson = Gzip.unzip(mapJsonGzipped)
|
||||
val mapObject = MapSaver().mapFromJson(decodedMapJson)
|
||||
MapSaver().saveMap(downloadableMap.name, mapObject)
|
||||
UncivGame.Current.setScreen(MapEditorScreen(mapObject))
|
||||
}
|
||||
catch(ex:Exception){
|
||||
val couldNotDownloadMapPopup = PopupTable(screen)
|
||||
couldNotDownloadMapPopup.addGoodSizedLabel("Could not download map!").row()
|
||||
couldNotDownloadMapPopup.addCloseButton()
|
||||
}
|
||||
}
|
||||
scrollableMapTable.add(downloadMapButton).row()
|
||||
}
|
||||
add(ScrollPane(scrollableMapTable)).height(mapEditorScreen.stage.height * 2 / 3).row()
|
||||
} catch (ex: Exception) {
|
||||
addGoodSizedLabel("Could not get list of maps!").row()
|
||||
}
|
||||
addCloseButton()
|
||||
open()
|
||||
}
|
||||
}
|
@ -31,7 +31,7 @@ class NewGameScreen: PickerScreen(){
|
||||
setDefaultCloseAction()
|
||||
|
||||
val playerPickerTable = PlayerPickerTable(this, newGameParameters)
|
||||
topTable.add(NewGameScreenOptionsTable(newGameParameters,mapParameters, ruleSet) { playerPickerTable.update() })
|
||||
topTable.add(NewGameScreenOptionsTable(this) { playerPickerTable.update() })
|
||||
topTable.add(playerPickerTable).pad(10f)
|
||||
topTable.pack()
|
||||
topTable.setFillParent(true)
|
||||
|
@ -8,21 +8,22 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener
|
||||
import com.badlogic.gdx.utils.Array
|
||||
import com.unciv.logic.MapSaver
|
||||
import com.unciv.logic.map.MapParameters
|
||||
import com.unciv.models.gamebasics.Ruleset
|
||||
import com.unciv.models.gamebasics.VictoryType
|
||||
import com.unciv.models.gamebasics.tech.TechEra
|
||||
import com.unciv.models.gamebasics.tr
|
||||
import com.unciv.models.metadata.GameParameters
|
||||
import com.unciv.models.metadata.GameSpeed
|
||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||
import com.unciv.ui.utils.toLabel
|
||||
|
||||
class NewGameScreenOptionsTable(val newGameParameters: GameParameters,
|
||||
val mapParameters: MapParameters,
|
||||
val ruleset: Ruleset, val onMultiplayerToggled:()->Unit)
|
||||
: Table(CameraStageBaseScreen.skin){
|
||||
init{
|
||||
class NewGameScreenOptionsTable(val newGameScreen: NewGameScreen, val onMultiplayerToggled:()->Unit)
|
||||
: Table(CameraStageBaseScreen.skin) {
|
||||
val newGameParameters = newGameScreen.newGameParameters
|
||||
val mapParameters = newGameScreen.mapParameters
|
||||
val ruleset = newGameScreen.ruleSet
|
||||
|
||||
init {
|
||||
|
||||
add("Map options".toLabel(fontSize = 24)).colspan(2).row()
|
||||
addMapTypeSelection()
|
||||
|
||||
@ -44,7 +45,7 @@ class NewGameScreenOptionsTable(val newGameParameters: GameParameters,
|
||||
private fun addMapTypeSelection() {
|
||||
add("{Map type}:".toLabel())
|
||||
val mapTypes = arrayListOf("Generated")
|
||||
if(MapSaver().getMaps().isNotEmpty()) mapTypes.add("Existing")
|
||||
if (MapSaver().getMaps().isNotEmpty()) mapTypes.add("Existing")
|
||||
|
||||
val mapFileLabel = "{Map file}:".toLabel()
|
||||
val mapFileSelectBox = getMapFileSelectBox()
|
||||
@ -55,7 +56,7 @@ class NewGameScreenOptionsTable(val newGameParameters: GameParameters,
|
||||
|
||||
val mapParameterTable = MapParametersTable(mapParameters)
|
||||
|
||||
fun updateOnMapTypeChange(){
|
||||
fun updateOnMapTypeChange() {
|
||||
mapParameters.type = mapTypeSelectBox.selected.value
|
||||
if (mapParameters.type == "Existing") {
|
||||
mapParameterTable.isVisible = false
|
||||
@ -82,7 +83,8 @@ class NewGameScreenOptionsTable(val newGameParameters: GameParameters,
|
||||
add(mapParameterTable).colspan(2).row()
|
||||
|
||||
add(mapFileLabel)
|
||||
add(mapFileSelectBox).pad(10f).row()
|
||||
add(mapFileSelectBox).maxWidth(newGameScreen.stage.width / 2) // because SOME people gotta give the hugest names to their maps
|
||||
.pad(10f).row()
|
||||
}
|
||||
|
||||
|
||||
@ -179,10 +181,10 @@ class NewGameScreenOptionsTable(val newGameParameters: GameParameters,
|
||||
add("{Starting Era}:".tr())
|
||||
// The eras enum values are "Medieval" etc. but are shown to the player as "Medieval era".tr()
|
||||
// because in other languages "Medieval era" is one word
|
||||
val eraSelectBox = TranslatedSelectBox(TechEra.values().map { it.name+" era" }, newGameParameters.startingEra.name+" era", CameraStageBaseScreen.skin)
|
||||
val eraSelectBox = TranslatedSelectBox(TechEra.values().map { it.name + " era" }, newGameParameters.startingEra.name + " era", CameraStageBaseScreen.skin)
|
||||
eraSelectBox.addListener(object : ChangeListener() {
|
||||
override fun changed(event: ChangeEvent?, actor: Actor?) {
|
||||
newGameParameters.startingEra = TechEra.valueOf(eraSelectBox.selected.value.replace(" era",""))
|
||||
newGameParameters.startingEra = TechEra.valueOf(eraSelectBox.selected.value.replace(" era", ""))
|
||||
}
|
||||
})
|
||||
add(eraSelectBox).pad(10f).row()
|
||||
@ -217,8 +219,7 @@ class NewGameScreenOptionsTable(val newGameParameters: GameParameters,
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun addModCheckboxes(){
|
||||
fun addModCheckboxes() {
|
||||
|
||||
add("{Victory conditions}:".tr()).colspan(2).row()
|
||||
|
||||
@ -227,14 +228,15 @@ class NewGameScreenOptionsTable(val newGameParameters: GameParameters,
|
||||
|
||||
val mods = Gdx.files.local("mods")
|
||||
|
||||
for(modFolder in mods.list()){
|
||||
if(modFolder.list().any { it.name()=="jsons" }) {
|
||||
val ruleSet = Ruleset(false)
|
||||
for (modFolder in mods.list()) {
|
||||
if (modFolder.list().any { it.name() == "jsons" }) {
|
||||
val ruleSet = Ruleset(false)
|
||||
|
||||
try {
|
||||
val modRuleset = ruleSet.load(modFolder.path() + "/jsons")
|
||||
try {
|
||||
val modRuleset = ruleSet.load(modFolder.path() + "/jsons")
|
||||
|
||||
}catch (ex:Exception){}
|
||||
} catch (ex: Exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user