mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-29 15:01:09 -04:00
Merged "load map" and "load scenario map" to the same screen - they're basically the same thing anyway
This commit is contained in:
parent
6ebc4ebf6f
commit
795599207f
@ -146,22 +146,6 @@ class MainMenuScreen: CameraStageBaseScreen() {
|
|||||||
loadMapButton.background = tableBackground
|
loadMapButton.background = tableBackground
|
||||||
add(loadMapButton).row()
|
add(loadMapButton).row()
|
||||||
|
|
||||||
if (UncivGame.Current.settings.extendedMapEditor) {
|
|
||||||
val loadScenarioButton = screen.getTableBlock("Load scenario map", "OtherIcons/Scenario") {
|
|
||||||
val loadScenarioScreen = LoadScenarioScreen(null)
|
|
||||||
loadScenarioScreen.closeButton.isVisible = true
|
|
||||||
loadScenarioScreen.closeButton.onClick {
|
|
||||||
screen.game.setScreen(MainMenuScreen())
|
|
||||||
loadScenarioScreen.dispose()
|
|
||||||
}
|
|
||||||
screen.game.setScreen(loadScenarioScreen)
|
|
||||||
screen.dispose()
|
|
||||||
}
|
|
||||||
|
|
||||||
loadScenarioButton.background = tableBackground
|
|
||||||
add(loadScenarioButton).row()
|
|
||||||
}
|
|
||||||
|
|
||||||
add(screen.getTableBlock("Close", "OtherIcons/Close") { close() }
|
add(screen.getTableBlock("Close", "OtherIcons/Close") { close() }
|
||||||
.apply { background=tableBackground })
|
.apply { background=tableBackground })
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import com.badlogic.gdx.Gdx
|
|||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
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.utils.Align
|
||||||
import com.unciv.UncivGame
|
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
|
||||||
@ -15,28 +16,32 @@ import com.unciv.ui.utils.AutoScrollPane as ScrollPane
|
|||||||
|
|
||||||
class LoadMapScreen(previousMap: TileMap?) : PickerScreen(){
|
class LoadMapScreen(previousMap: TileMap?) : PickerScreen(){
|
||||||
var chosenMap = ""
|
var chosenMap = ""
|
||||||
val deleteMapButton = "Delete map".toTextButton()
|
val deleteButton = "Delete map".toTextButton()
|
||||||
|
var scenarioMap = false
|
||||||
|
val mapsTable = Table().apply { defaults().pad(10f) }
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
if(UncivGame.Current.settings.extendedMapEditor) {
|
||||||
|
val toggleButton = "Toggle Scenario Map".toTextButton()
|
||||||
|
toggleButton.onClick {
|
||||||
|
scenarioMap = !scenarioMap
|
||||||
|
update()
|
||||||
|
}
|
||||||
|
toggleButton.centerX(stage)
|
||||||
|
toggleButton.setY(stage.height - 10f, Align.top)
|
||||||
|
stage.addActor(toggleButton)
|
||||||
|
}
|
||||||
|
|
||||||
rightSideButton.setText("Load map".tr())
|
rightSideButton.setText("Load map".tr())
|
||||||
rightSideButton.onClick {
|
rightSideButton.onClick {
|
||||||
UncivGame.Current.setScreen(MapEditorScreen(chosenMap))
|
val mapEditorScreen = if (scenarioMap) MapEditorScreen(MapSaver.loadScenario(chosenMap), chosenMap)
|
||||||
|
else MapEditorScreen(chosenMap)
|
||||||
|
UncivGame.Current.setScreen(mapEditorScreen)
|
||||||
dispose()
|
dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
val mapsTable = Table().apply { defaults().pad(10f) }
|
|
||||||
for (map in MapSaver.getMaps()) {
|
|
||||||
val loadMapButton = TextButton(map, skin)
|
|
||||||
loadMapButton.onClick {
|
|
||||||
rightSideButton.enable()
|
|
||||||
chosenMap = map
|
|
||||||
deleteMapButton.enable()
|
|
||||||
deleteMapButton.color = Color.RED
|
|
||||||
}
|
|
||||||
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)
|
.maxWidth(stage.width / 2)
|
||||||
|
|
||||||
val rightSideTable = Table().apply { defaults().pad(10f) }
|
val rightSideTable = Table().apply { defaults().pad(10f) }
|
||||||
|
|
||||||
@ -50,33 +55,72 @@ class LoadMapScreen(previousMap: TileMap?) : PickerScreen(){
|
|||||||
|
|
||||||
|
|
||||||
val loadFromClipboardButton = "Load copied data".toTextButton()
|
val loadFromClipboardButton = "Load copied data".toTextButton()
|
||||||
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 {
|
||||||
try {
|
try {
|
||||||
val clipboardContentsString = Gdx.app.clipboard.contents.trim()
|
val clipboardContentsString = Gdx.app.clipboard.contents.trim()
|
||||||
val decoded = Gzip.unzip(clipboardContentsString)
|
val decoded = Gzip.unzip(clipboardContentsString)
|
||||||
val loadedMap = MapSaver.mapFromJson(decoded)
|
val loadedMap = MapSaver.mapFromJson(decoded)
|
||||||
UncivGame.Current.setScreen(MapEditorScreen(loadedMap))
|
UncivGame.Current.setScreen(MapEditorScreen(loadedMap))
|
||||||
}
|
} catch (ex: Exception) {
|
||||||
catch (ex:Exception){
|
couldNotLoadMapLabel.isVisible = true
|
||||||
couldNotLoadMapLabel.isVisible=true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rightSideTable.add(loadFromClipboardButton).row()
|
rightSideTable.add(loadFromClipboardButton).row()
|
||||||
rightSideTable.add(couldNotLoadMapLabel).row()
|
rightSideTable.add(couldNotLoadMapLabel).row()
|
||||||
|
|
||||||
deleteMapButton.onClick {
|
deleteButton.onClick {
|
||||||
YesNoPopup("Are you sure you want to delete this map?", {
|
YesNoPopup("Are you sure you want to delete this map?", {
|
||||||
MapSaver.deleteMap(chosenMap)
|
if (scenarioMap) MapSaver.deleteScenario(chosenMap)
|
||||||
|
else MapSaver.deleteMap(chosenMap)
|
||||||
UncivGame.Current.setScreen(LoadMapScreen(previousMap))
|
UncivGame.Current.setScreen(LoadMapScreen(previousMap))
|
||||||
}, this).open()
|
}, this).open()
|
||||||
}
|
}
|
||||||
deleteMapButton.disable()
|
rightSideTable.add(deleteButton).row()
|
||||||
deleteMapButton.color = Color.RED
|
|
||||||
rightSideTable.add(deleteMapButton).row()
|
|
||||||
|
|
||||||
topTable.add(rightSideTable)
|
topTable.add(rightSideTable)
|
||||||
if(previousMap!=null) closeButton.onClick { UncivGame.Current.setScreen(MapEditorScreen(previousMap)) }
|
if (previousMap != null)
|
||||||
|
closeButton.onClick { UncivGame.Current.setScreen(MapEditorScreen(previousMap)) }
|
||||||
|
|
||||||
|
update()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun update() {
|
||||||
|
chosenMap = ""
|
||||||
|
deleteButton.disable()
|
||||||
|
deleteButton.color = Color.RED
|
||||||
|
|
||||||
|
if (scenarioMap) {
|
||||||
|
deleteButton.setText("Delete Scenario Map")
|
||||||
|
rightSideButton.setText("Load Scenario Map")
|
||||||
|
|
||||||
|
mapsTable.clear()
|
||||||
|
for (scenario in MapSaver.getScenarios()) {
|
||||||
|
val loadScenarioButton = TextButton(scenario, skin)
|
||||||
|
loadScenarioButton.onClick {
|
||||||
|
rightSideButton.enable()
|
||||||
|
chosenMap = scenario
|
||||||
|
deleteButton.enable()
|
||||||
|
deleteButton.color = Color.RED
|
||||||
|
}
|
||||||
|
mapsTable.add(loadScenarioButton).row()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
deleteButton.setText("Delete map")
|
||||||
|
rightSideButton.setText("Load map")
|
||||||
|
|
||||||
|
mapsTable.clear()
|
||||||
|
for (map in MapSaver.getMaps()) {
|
||||||
|
val loadMapButton = TextButton(map, skin)
|
||||||
|
loadMapButton.onClick {
|
||||||
|
rightSideButton.enable()
|
||||||
|
chosenMap = map
|
||||||
|
deleteButton.enable()
|
||||||
|
deleteButton.color = Color.RED
|
||||||
|
}
|
||||||
|
mapsTable.add(loadMapButton).row()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,88 +0,0 @@
|
|||||||
package com.unciv.ui.mapeditor
|
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx
|
|
||||||
import com.badlogic.gdx.graphics.Color
|
|
||||||
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.logic.map.Scenario
|
|
||||||
import com.unciv.logic.map.TileMap
|
|
||||||
import com.unciv.models.translations.tr
|
|
||||||
import com.unciv.ui.pickerscreens.PickerScreen
|
|
||||||
import com.unciv.ui.saves.Gzip
|
|
||||||
import com.unciv.ui.utils.*
|
|
||||||
|
|
||||||
/**
|
|
||||||
* [PickerScreen] used for simple load/delete scenario. Called from [MapEditorScreen]
|
|
||||||
* and returns to that [Screen] type.
|
|
||||||
* @param previousMap [TileMap] to return when no scenario chosen
|
|
||||||
*/
|
|
||||||
class LoadScenarioScreen(previousMap: TileMap?): PickerScreen(){
|
|
||||||
var chosenScenario = ""
|
|
||||||
val deleteScenarioButton = "Delete scenario".toTextButton()
|
|
||||||
|
|
||||||
init {
|
|
||||||
rightSideButton.setText("Load scenario map".tr())
|
|
||||||
rightSideButton.onClick {
|
|
||||||
val mapEditorScreen = MapEditorScreen(MapSaver.loadScenario(chosenScenario), chosenScenario)
|
|
||||||
UncivGame.Current.setScreen(mapEditorScreen)
|
|
||||||
dispose()
|
|
||||||
}
|
|
||||||
|
|
||||||
val scenariosTable = Table().apply { defaults().pad(10f) }
|
|
||||||
for (scenario in MapSaver.getScenarios()) {
|
|
||||||
val loadScenarioButton = TextButton(scenario, skin)
|
|
||||||
loadScenarioButton.onClick {
|
|
||||||
rightSideButton.enable()
|
|
||||||
chosenScenario = scenario
|
|
||||||
deleteScenarioButton.enable()
|
|
||||||
deleteScenarioButton.color = Color.RED
|
|
||||||
}
|
|
||||||
scenariosTable.add(loadScenarioButton).row()
|
|
||||||
}
|
|
||||||
topTable.add(AutoScrollPane(scenariosTable)).height(stage.height * 2 / 3)
|
|
||||||
.maxWidth(stage.width/2)
|
|
||||||
|
|
||||||
val rightSideTable = Table().apply { defaults().pad(10f) }
|
|
||||||
|
|
||||||
// val downloadMapButton = "Download map".toTextButton()
|
|
||||||
// downloadMapButton.onClick {
|
|
||||||
// MapDownloadPopup(this).open()
|
|
||||||
// }
|
|
||||||
// rightSideTable.add(downloadMapButton).row()
|
|
||||||
//
|
|
||||||
// rightSideTable.addSeparator()
|
|
||||||
|
|
||||||
|
|
||||||
// val loadFromClipboardButton = "Load copied data".toTextButton()
|
|
||||||
// val couldNotLoadMapLabel = "Could not load map!".toLabel(Color.RED).apply { isVisible=false }
|
|
||||||
// loadFromClipboardButton.onClick {
|
|
||||||
// try {
|
|
||||||
// val clipboardContentsString = Gdx.app.clipboard.contents.trim()
|
|
||||||
// val decoded = Gzip.unzip(clipboardContentsString)
|
|
||||||
// val loadedMap = MapSaver.mapFromJson(decoded)
|
|
||||||
// UncivGame.Current.setScreen(MapEditorScreen(loadedMap))
|
|
||||||
// }
|
|
||||||
// catch (ex:Exception){
|
|
||||||
// couldNotLoadMapLabel.isVisible=true
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// rightSideTable.add(loadFromClipboardButton).row()
|
|
||||||
// rightSideTable.add(couldNotLoadMapLabel).row()
|
|
||||||
|
|
||||||
deleteScenarioButton.onClick {
|
|
||||||
YesNoPopup("Are you sure you want to delete this scenario?", {
|
|
||||||
MapSaver.deleteScenario(chosenScenario)
|
|
||||||
UncivGame.Current.setScreen(LoadScenarioScreen(previousMap))
|
|
||||||
}, this).open()
|
|
||||||
}
|
|
||||||
deleteScenarioButton.disable()
|
|
||||||
deleteScenarioButton.color = Color.RED
|
|
||||||
rightSideTable.add(deleteScenarioButton).row()
|
|
||||||
|
|
||||||
topTable.add(rightSideTable)
|
|
||||||
if(previousMap!=null) closeButton.onClick { UncivGame.Current.setScreen(MapEditorScreen(previousMap)) }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -36,7 +36,6 @@ class MapEditorMenuPopup(var mapEditorScreen: MapEditorScreen): Popup(mapEditorS
|
|||||||
if (UncivGame.Current.settings.extendedMapEditor) {
|
if (UncivGame.Current.settings.extendedMapEditor) {
|
||||||
addScenarioButton()
|
addScenarioButton()
|
||||||
addSaveScenarioButton()
|
addSaveScenarioButton()
|
||||||
addLoadScenarioButton()
|
|
||||||
}
|
}
|
||||||
addExitMapEditorButton()
|
addExitMapEditorButton()
|
||||||
addCloseOptionsButton()
|
addCloseOptionsButton()
|
||||||
@ -207,14 +206,6 @@ class MapEditorMenuPopup(var mapEditorScreen: MapEditorScreen): Popup(mapEditorS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Popup.addLoadScenarioButton() {
|
|
||||||
val loadScenarioButton = "Load scenario map".toTextButton()
|
|
||||||
loadScenarioButton.onClick {
|
|
||||||
UncivGame.Current.setScreen(LoadScenarioScreen(mapEditorScreen.tileMap))
|
|
||||||
}
|
|
||||||
add(loadScenarioButton).row()
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun Popup.addExitMapEditorButton() {
|
private fun Popup.addExitMapEditorButton() {
|
||||||
val exitMapEditorButton = "Exit map editor".toTextButton()
|
val exitMapEditorButton = "Exit map editor".toTextButton()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user