mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-16 02:40:41 +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.Gdx
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
@ -9,12 +9,12 @@ import com.unciv.UncivGame
|
|||||||
import com.unciv.logic.MapSaver
|
import com.unciv.logic.MapSaver
|
||||||
import com.unciv.logic.map.TileMap
|
import com.unciv.logic.map.TileMap
|
||||||
import com.unciv.models.gamebasics.tr
|
import com.unciv.models.gamebasics.tr
|
||||||
import com.unciv.ui.mapeditor.MapEditorScreen
|
|
||||||
import com.unciv.ui.pickerscreens.PickerScreen
|
import com.unciv.ui.pickerscreens.PickerScreen
|
||||||
|
import com.unciv.ui.saves.Gzip
|
||||||
import com.unciv.ui.utils.*
|
import com.unciv.ui.utils.*
|
||||||
import com.unciv.ui.worldscreen.optionstable.YesNoPopupTable
|
import com.unciv.ui.worldscreen.optionstable.YesNoPopupTable
|
||||||
|
|
||||||
class LoadMapScreen(previousMap: TileMap) : PickerScreen(){
|
class LoadMapScreen(previousMap: TileMap?) : PickerScreen(){
|
||||||
var chosenMap = ""
|
var chosenMap = ""
|
||||||
val deleteMapButton = TextButton("Delete map",skin)
|
val deleteMapButton = TextButton("Delete map",skin)
|
||||||
|
|
||||||
@ -37,8 +37,19 @@ class LoadMapScreen(previousMap: TileMap) : PickerScreen(){
|
|||||||
mapsTable.add(loadMapButton).row()
|
mapsTable.add(loadMapButton).row()
|
||||||
}
|
}
|
||||||
topTable.add(ScrollPane(mapsTable)).height(stage.height * 2 / 3)
|
topTable.add(ScrollPane(mapsTable)).height(stage.height * 2 / 3)
|
||||||
|
.maxWidth(stage.width/2)
|
||||||
|
|
||||||
val rightSideTable = Table().apply { defaults().pad(10f) }
|
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 loadFromClipboardButton = TextButton("Load copied data".tr(), skin)
|
||||||
val couldNotLoadMapLabel = "Could not load map!".toLabel(Color.RED).apply { isVisible=false }
|
val couldNotLoadMapLabel = "Could not load map!".toLabel(Color.RED).apply { isVisible=false }
|
||||||
loadFromClipboardButton.onClick {
|
loadFromClipboardButton.onClick {
|
||||||
@ -66,6 +77,9 @@ class LoadMapScreen(previousMap: TileMap) : PickerScreen(){
|
|||||||
rightSideTable.add(deleteMapButton).row()
|
rightSideTable.add(deleteMapButton).row()
|
||||||
|
|
||||||
topTable.add(rightSideTable)
|
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
|
package com.unciv.ui.mapeditor
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx
|
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.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
|
||||||
@ -13,8 +11,6 @@ import com.unciv.logic.map.MapType
|
|||||||
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.saves.LoadMapScreen
|
|
||||||
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
|
||||||
@ -88,12 +84,6 @@ class MapEditorMenuPopup(mapEditorScreen: MapEditorScreen): PopupTable(mapEditor
|
|||||||
}
|
}
|
||||||
add(uploadMapButton).row()
|
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)
|
val exitMapEditorButton = TextButton("Exit map editor".tr(), skin)
|
||||||
exitMapEditorButton.onClick { UncivGame.Current.setWorldScreen(); mapEditorScreen.dispose() }
|
exitMapEditorButton.onClick { UncivGame.Current.setWorldScreen(); mapEditorScreen.dispose() }
|
||||||
@ -106,36 +96,3 @@ class MapEditorMenuPopup(mapEditorScreen: MapEditorScreen): PopupTable(mapEditor
|
|||||||
open()
|
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()
|
setDefaultCloseAction()
|
||||||
|
|
||||||
val playerPickerTable = PlayerPickerTable(this, newGameParameters)
|
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.add(playerPickerTable).pad(10f)
|
||||||
topTable.pack()
|
topTable.pack()
|
||||||
topTable.setFillParent(true)
|
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.scenes.scene2d.utils.ChangeListener
|
||||||
import com.badlogic.gdx.utils.Array
|
import com.badlogic.gdx.utils.Array
|
||||||
import com.unciv.logic.MapSaver
|
import com.unciv.logic.MapSaver
|
||||||
import com.unciv.logic.map.MapParameters
|
|
||||||
import com.unciv.models.gamebasics.Ruleset
|
import com.unciv.models.gamebasics.Ruleset
|
||||||
import com.unciv.models.gamebasics.VictoryType
|
import com.unciv.models.gamebasics.VictoryType
|
||||||
import com.unciv.models.gamebasics.tech.TechEra
|
import com.unciv.models.gamebasics.tech.TechEra
|
||||||
import com.unciv.models.gamebasics.tr
|
import com.unciv.models.gamebasics.tr
|
||||||
import com.unciv.models.metadata.GameParameters
|
|
||||||
import com.unciv.models.metadata.GameSpeed
|
import com.unciv.models.metadata.GameSpeed
|
||||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||||
import com.unciv.ui.utils.toLabel
|
import com.unciv.ui.utils.toLabel
|
||||||
|
|
||||||
class NewGameScreenOptionsTable(val newGameParameters: GameParameters,
|
class NewGameScreenOptionsTable(val newGameScreen: NewGameScreen, val onMultiplayerToggled:()->Unit)
|
||||||
val mapParameters: MapParameters,
|
|
||||||
val ruleset: Ruleset, val onMultiplayerToggled:()->Unit)
|
|
||||||
: Table(CameraStageBaseScreen.skin) {
|
: Table(CameraStageBaseScreen.skin) {
|
||||||
|
val newGameParameters = newGameScreen.newGameParameters
|
||||||
|
val mapParameters = newGameScreen.mapParameters
|
||||||
|
val ruleset = newGameScreen.ruleSet
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
|
||||||
add("Map options".toLabel(fontSize = 24)).colspan(2).row()
|
add("Map options".toLabel(fontSize = 24)).colspan(2).row()
|
||||||
addMapTypeSelection()
|
addMapTypeSelection()
|
||||||
|
|
||||||
@ -82,7 +83,8 @@ class NewGameScreenOptionsTable(val newGameParameters: GameParameters,
|
|||||||
add(mapParameterTable).colspan(2).row()
|
add(mapParameterTable).colspan(2).row()
|
||||||
|
|
||||||
add(mapFileLabel)
|
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()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -217,7 +219,6 @@ class NewGameScreenOptionsTable(val newGameParameters: GameParameters,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fun addModCheckboxes() {
|
fun addModCheckboxes() {
|
||||||
|
|
||||||
add("{Victory conditions}:".tr()).colspan(2).row()
|
add("{Victory conditions}:".tr()).colspan(2).row()
|
||||||
@ -234,7 +235,8 @@ class NewGameScreenOptionsTable(val newGameParameters: GameParameters,
|
|||||||
try {
|
try {
|
||||||
val modRuleset = ruleSet.load(modFolder.path() + "/jsons")
|
val modRuleset = ruleSet.load(modFolder.path() + "/jsons")
|
||||||
|
|
||||||
}catch (ex:Exception){}
|
} catch (ex: Exception) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user