Continue work on Scenario functionality (#2726)

* Hide all scenarios functionality behind switch in Unciv class.

* Refactoring:
1) abstract class changed to interface
2) rulset added to GameSetupInfo class

Fixed screen bug during map editing

* Added Load/Edit/Delete buttons for scenario functionality.

* Hide recently added scenario buttons behind debugSwitch.
This commit is contained in:
Alexander Korolyov 2020-06-15 13:12:29 -04:00 committed by GitHub
parent 46dd66d343
commit 9547b82054
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 263 additions and 90 deletions

View file

@ -15,10 +15,7 @@ import com.unciv.logic.map.MapSize
import com.unciv.logic.map.MapType
import com.unciv.models.ruleset.RulesetCache
import com.unciv.ui.MultiplayerScreen
import com.unciv.ui.mapeditor.EditorMapHolder
import com.unciv.ui.mapeditor.LoadMapScreen
import com.unciv.ui.mapeditor.MapEditorScreen
import com.unciv.ui.mapeditor.NewMapScreen
import com.unciv.ui.mapeditor.*
import com.unciv.ui.newgamescreen.GameSetupInfo
import com.unciv.ui.newgamescreen.NewGameScreen
import com.unciv.ui.saves.LoadGameScreen
@ -130,9 +127,25 @@ class MainMenuScreen: CameraStageBaseScreen() {
}
game.setScreen(loadMapScreen)
}
loadMapButton.background = tableBackground
mapEditorPopup.add(loadMapButton).row()
if (UncivGame.Current.scenarioDebugSwitch) {
val loadScenarioButton = getTableBlock("Load scenario", "OtherIcons/Load") {
val loadScenarioScreen = LoadScenarioScreen(null)
loadScenarioScreen.closeButton.isVisible = true
loadScenarioScreen.closeButton.onClick {
game.setScreen(MainMenuScreen())
loadScenarioScreen.dispose()
}
game.setScreen(loadScenarioScreen)
}
loadScenarioButton.background = tableBackground
mapEditorPopup.add(loadScenarioButton).row()
}
mapEditorPopup.add(getTableBlock("Close", "OtherIcons/Close") { mapEditorPopup.close() }
.apply { background=tableBackground })

View file

@ -36,10 +36,11 @@ object MapSaver {
fun deleteMap(mapName: String) = getMap(mapName).delete()
fun deleteScenario(scenarioName: String) = getScenario(scenarioName).delete()
fun getMaps() = Gdx.files.local(mapsFolder).list().map { it.name() }
fun getScenarios() = Gdx.files.local(scenariosFolder).list().map { it.name() }
fun mapFromJson(json:String): TileMap = json().fromJson(TileMap::class.java, json)
}

View file

@ -31,7 +31,7 @@ class EditorMapHolder(internal val mapEditorScreen: MapEditorScreen, internal va
// This is a hack to make the unit icons render correctly on the game, even though the map isn't part of a game
// and the units aren't assigned to any "real" CivInfo
tileGroup.tileInfo.getUnits().forEach { it.civInfo= CivilizationInfo()
.apply { nation=mapEditorScreen.ruleset.nations[it.owner]!! } }
.apply { nation=mapEditorScreen.gameSetupInfo.ruleset.nations[it.owner]!! } }
tileGroup.showEntireMap = true
tileGroup.update()

View file

@ -0,0 +1,83 @@
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.*
class LoadScenarioScreen(previousMap: TileMap?): PickerScreen(){
var chosenScenario = ""
val deleteScenarioButton = "Delete scenario".toTextButton()
init {
rightSideButton.setText("Load scenario".tr())
rightSideButton.onClick {
UncivGame.Current.setScreen(MapEditorScreen(MapSaver.loadScenario(chosenScenario)).apply { scenarioName = chosenScenario })
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.isVisible=false
else closeButton.onClick { UncivGame.Current.setScreen(MapEditorScreen(previousMap)) }
}
}

View file

@ -19,44 +19,65 @@ import com.unciv.ui.utils.*
import com.unciv.ui.worldscreen.mainmenu.DropBox
import kotlin.concurrent.thread
class MapEditorMenuPopup(mapEditorScreen: MapEditorScreen): Popup(mapEditorScreen){
class MapEditorMenuPopup(var mapEditorScreen: MapEditorScreen): Popup(mapEditorScreen){
private val mapNameEditor: TextField = TextField(mapEditorScreen.mapName, skin)
init{
val mapNameEditor = TextField(mapEditorScreen.mapName, skin)
add(mapNameEditor).fillX().row()
mapNameEditor.selectAll()
mapNameEditor.maxLength = 240 // A few under max for most filesystems
mapEditorScreen.stage.keyboardFocus = mapNameEditor
addNewMapButton()
addClearCurrentMapButton()
addSaveMapButton()
addCopyMapAsTextButton()
addLoadMapButton()
addUploadMapButton()
if (UncivGame.Current.scenarioDebugSwitch) {
addScenarioButton()
addLoadScenarioButton()
}
addExitMapEditorButton()
addCloseOptionsButton()
}
private fun Popup.addNewMapButton() {
val newMapButton = "New map".toTextButton()
newMapButton.onClick {
UncivGame.Current.setScreen(NewMapScreen())
}
add(newMapButton).row()
}
private fun Popup.addClearCurrentMapButton() {
val clearCurrentMapButton = "Clear current map".toTextButton()
clearCurrentMapButton.onClick {
for(tileGroup in mapEditorScreen.mapHolder.tileGroups.values)
{
for (tileGroup in mapEditorScreen.mapHolder.tileGroups.values) {
val tile = tileGroup.tileInfo
tile.baseTerrain=Constants.ocean
tile.terrainFeature=null
tile.naturalWonder=null
tile.resource=null
tile.improvement=null
tile.improvementInProgress=null
tile.roadStatus=RoadStatus.None
tile.baseTerrain = Constants.ocean
tile.terrainFeature = null
tile.naturalWonder = null
tile.resource = null
tile.improvement = null
tile.improvementInProgress = null
tile.roadStatus = RoadStatus.None
tile.setTransients()
tileGroup.update()
}
}
add(clearCurrentMapButton).row()
}
private fun Popup.addSaveMapButton() {
val saveMapButton = "Save map".toTextButton()
saveMapButton.onClick {
mapEditorScreen.tileMap.mapParameters.name=mapEditorScreen.mapName
mapEditorScreen.tileMap.mapParameters.type=MapType.custom
thread ( name = "SaveMap" ) {
mapEditorScreen.tileMap.mapParameters.name = mapEditorScreen.mapName
mapEditorScreen.tileMap.mapParameters.type = MapType.custom
thread(name = "SaveMap") {
try {
MapSaver.saveMap(mapEditorScreen.mapName, mapEditorScreen.tileMap)
close()
@ -81,24 +102,30 @@ class MapEditorMenuPopup(mapEditorScreen: MapEditorScreen): Popup(mapEditorScree
saveMapButton.isEnabled = mapNameEditor.text.isNotEmpty()
true
}
}
private fun Popup.addCopyMapAsTextButton() {
val copyMapAsTextButton = "Copy to clipboard".toTextButton()
copyMapAsTextButton.onClick {
val json = Json().toJson(mapEditorScreen.tileMap)
val base64Gzip = Gzip.zip(json)
Gdx.app.clipboard.contents = base64Gzip
Gdx.app.clipboard.contents = base64Gzip
}
add(copyMapAsTextButton).row()
}
private fun Popup.addLoadMapButton() {
val loadMapButton = "Load map".toTextButton()
loadMapButton.onClick {
UncivGame.Current.setScreen(LoadMapScreen(mapEditorScreen.tileMap))
}
add(loadMapButton).row()
}
private fun Popup.addUploadMapButton() {
val uploadMapButton = "Upload map".toTextButton()
uploadMapButton.onClick {
thread(name="MapUpload") {
thread(name = "MapUpload") {
try {
val gzippedMap = Gzip.zip(Json().toJson(mapEditorScreen.tileMap))
DropBox.uploadFile("/Maps/" + mapEditorScreen.mapName, gzippedMap)
@ -122,44 +149,69 @@ class MapEditorMenuPopup(mapEditorScreen: MapEditorScreen): Popup(mapEditorScree
}
}
add(uploadMapButton).row()
}
if (UncivGame.Current.scenarioDebugSwitch) {
val createScenarioButton = "Create scenario".toTextButton()
add(createScenarioButton).row()
createScenarioButton.onClick {
remove()
mapEditorScreen.gameSetupInfo.gameParameters.players = getPlayersFromMap(mapEditorScreen.tileMap) // update players list from tileMap starting locations
val gameParametersPopup = Popup(screen)
val playerPickerTable = PlayerPickerTable(mapEditorScreen, mapEditorScreen.gameSetupInfo.gameParameters)
val gameOptionsTable = GameOptionsTable(mapEditorScreen) {desiredCiv: String -> playerPickerTable.update(desiredCiv)}
val scenarioNameEditor = TextField(mapEditorScreen.mapName, skin)
gameParametersPopup.add(playerPickerTable)
gameParametersPopup.addSeparatorVertical()
gameParametersPopup.add(gameOptionsTable).row()
gameParametersPopup.add(scenarioNameEditor)
gameParametersPopup.addButton("Save scenario"){
mapEditorScreen.tileMap.mapParameters.type=MapType.scenario
MapSaver.saveScenario(scenarioNameEditor.text, Scenario(mapEditorScreen.tileMap, mapEditorScreen.gameSetupInfo.gameParameters))
ResponsePopup("Scenario saved", mapEditorScreen)
gameParametersPopup.close()
}.row()
gameParametersPopup.addCloseButton().row()
gameParametersPopup.open()
}
private fun Popup.addScenarioButton() {
var scenarioButton = "".toTextButton()
if (mapEditorScreen.scenario != null) {
scenarioButton.setText("Edit scenario")
} else {
scenarioButton.setText("Create scenario")
}
add(scenarioButton).row()
scenarioButton.onClick {
remove()
// update players list from tileMap starting locations
if (mapEditorScreen.scenario == null) {
mapEditorScreen.gameSetupInfo.gameParameters.players = getPlayersFromMap(mapEditorScreen.tileMap)
}
val gameParametersPopup = Popup(screen)
val playerPickerTable = PlayerPickerTable(mapEditorScreen, mapEditorScreen.gameSetupInfo.gameParameters)
val gameOptionsTable = GameOptionsTable(mapEditorScreen) { desiredCiv: String -> playerPickerTable.update(desiredCiv) }
val scenarioNameEditor = TextField(mapEditorScreen.scenarioName, skin)
gameParametersPopup.add(playerPickerTable)
gameParametersPopup.addSeparatorVertical()
gameParametersPopup.add(gameOptionsTable).row()
gameParametersPopup.add(scenarioNameEditor)
gameParametersPopup.addButton("Save scenario") {
mapEditorScreen.tileMap.mapParameters.type = MapType.scenario
mapEditorScreen.scenario = Scenario(mapEditorScreen.tileMap, mapEditorScreen.gameSetupInfo.gameParameters)
mapEditorScreen.scenarioName = scenarioNameEditor.text
MapSaver.saveScenario(scenarioNameEditor.text, mapEditorScreen.scenario!!)
ResponsePopup("Scenario saved", mapEditorScreen)
gameParametersPopup.close()
}.row()
gameParametersPopup.addCloseButton().row()
gameParametersPopup.open()
}
}
private fun Popup.addLoadScenarioButton() {
val loadScenarioButton = "Load scenario".toTextButton()
loadScenarioButton.onClick {
UncivGame.Current.setScreen(LoadScenarioScreen(mapEditorScreen.tileMap))
}
add(loadScenarioButton).row()
}
private fun Popup.addExitMapEditorButton() {
val exitMapEditorButton = "Exit map editor".toTextButton()
add(exitMapEditorButton ).row()
add(exitMapEditorButton).row()
exitMapEditorButton.onClick { mapEditorScreen.game.setScreen(MainMenuScreen()); mapEditorScreen.dispose() }
}
private fun Popup.addCloseOptionsButton() {
val closeOptionsButton = Constants.close.toTextButton()
closeOptionsButton.onClick { close() }
add(closeOptionsButton).row()
}
}
private fun getPlayersFromMap(tileMap: TileMap): ArrayList<Player> {
val tilesWithStartingLocations = tileMap.values
.filter { it.improvement != null && it.improvement!!.startsWith("StartingLocation ") }

View file

@ -1,5 +1,6 @@
package com.unciv.ui.mapeditor
import com.badlogic.gdx.Game
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.math.Vector2
import com.badlogic.gdx.scenes.scene2d.InputEvent
@ -9,19 +10,23 @@ import com.badlogic.gdx.scenes.scene2d.ui.SelectBox
import com.badlogic.gdx.scenes.scene2d.ui.Skin
import com.badlogic.gdx.utils.Array
import com.unciv.logic.MapSaver
import com.unciv.logic.map.Scenario
import com.unciv.logic.map.TileInfo
import com.unciv.logic.map.TileMap
import com.unciv.models.ruleset.RulesetCache
import com.unciv.models.translations.tr
import com.unciv.ui.newgamescreen.GameParametersPreviousScreen
import com.unciv.ui.newgamescreen.GameSetupInfo
import com.unciv.ui.newgamescreen.PreviousScreenInterface
import com.unciv.ui.utils.*
class MapEditorScreen(): GameParametersPreviousScreen() {
override val ruleset = RulesetCache.getBaseRuleset()
var mapName = ""
class MapEditorScreen(): PreviousScreenInterface, CameraStageBaseScreen() {
// need for compatibility with NewGameScreen: PickerScreen
override fun setRightSideButtonEnabled(boolean: Boolean) {}
var mapName = ""
var tileMap = TileMap()
var scenarioName = ""
var scenario: Scenario? = null
override var gameSetupInfo = GameSetupInfo()
lateinit var mapHolder: EditorMapHolder
@ -51,8 +56,15 @@ class MapEditorScreen(): GameParametersPreviousScreen() {
initialize()
}
constructor(scenario: Scenario) : this() {
tileMap = scenario.tileMap
this.scenario = scenario
gameSetupInfo.gameParameters = scenario.gameParameters
initialize()
}
fun initialize() {
tileMap.setTransients(ruleset,false)
tileMap.setTransients(gameSetupInfo.ruleset,false)
mapHolder = EditorMapHolder(this, tileMap)
mapHolder.addTiles(stage.width)

View file

@ -31,7 +31,7 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
var brushSize = 1
private var currentHex: Actor = Group()
private val ruleset = mapEditorScreen.ruleset
private val ruleset = mapEditorScreen.gameSetupInfo.ruleset
private val scrollPanelHeight = mapEditorScreen.stage.height*0.7f - 100f // -100 reserved for currentHex table
@ -258,7 +258,7 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
// for the tile image
val tileInfo = TileInfo()
tileInfo.ruleset = mapEditorScreen.ruleset
tileInfo.ruleset = mapEditorScreen.gameSetupInfo.ruleset
val terrain = resource.terrainsCanBeFoundOn.first()
val terrainObject = ruleset.terrains[terrain]!!
if (terrainObject.type == TerrainType.TerrainFeature) {
@ -351,7 +351,7 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
}
private fun makeTileGroup(tileInfo: TileInfo): TileGroup {
tileInfo.ruleset = mapEditorScreen.ruleset
tileInfo.ruleset = mapEditorScreen.gameSetupInfo.ruleset
tileInfo.setTerrainTransients()
val group = TileGroup(tileInfo, TileSetStrings())
group.showEntireMap = true

View file

@ -10,10 +10,10 @@ import com.unciv.models.ruleset.VictoryType
import com.unciv.models.translations.tr
import com.unciv.ui.utils.*
class GameOptionsTable(previousScreen: GameParametersPreviousScreen, val updatePlayerPickerTable:(desiredCiv:String)->Unit)
class GameOptionsTable(previousScreen: PreviousScreenInterface, val updatePlayerPickerTable:(desiredCiv:String)->Unit)
: Table(CameraStageBaseScreen.skin) {
var gameParameters = previousScreen.gameSetupInfo.gameParameters
val ruleset = previousScreen.ruleset
val ruleset = previousScreen.gameSetupInfo.ruleset
var locked = false
init {

View file

@ -1,11 +0,0 @@
package com.unciv.ui.newgamescreen
import com.badlogic.gdx.scenes.scene2d.Stage
import com.unciv.models.ruleset.Ruleset
import com.unciv.ui.pickerscreens.PickerScreen
import com.unciv.ui.utils.CameraStageBaseScreen
abstract class GameParametersPreviousScreen: PickerScreen() {
abstract var gameSetupInfo: GameSetupInfo
abstract val ruleset: Ruleset
}

View file

@ -3,6 +3,7 @@ package com.unciv.ui.newgamescreen
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.utils.Array
import com.unciv.UncivGame
import com.unciv.logic.MapSaver
import com.unciv.logic.map.MapType
import com.unciv.ui.utils.CameraStageBaseScreen
@ -28,7 +29,7 @@ class MapOptionsTable(val newGameScreen: NewGameScreen): Table() {
add("{Map Type}:".toLabel())
val mapTypes = arrayListOf("Generated")
if (MapSaver.getMaps().isNotEmpty()) mapTypes.add(MapType.custom)
if (MapSaver.getScenarios().isNotEmpty()) mapTypes.add(MapType.scenario)
if (MapSaver.getScenarios().isNotEmpty() && UncivGame.Current.scenarioDebugSwitch) mapTypes.add(MapType.scenario)
val mapTypeSelectBox = TranslatedSelectBox(mapTypes, "Generated", CameraStageBaseScreen.skin)
val mapFileSelectBox = getMapFileSelectBox()

View file

@ -2,7 +2,6 @@ package com.unciv.ui.newgamescreen
import com.unciv.ui.utils.AutoScrollPane as ScrollPane
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.scenes.scene2d.ui.CheckBox
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox
import com.badlogic.gdx.scenes.scene2d.ui.Skin
import com.badlogic.gdx.utils.Array
@ -10,10 +9,10 @@ import com.unciv.UncivGame
import com.unciv.logic.*
import com.unciv.logic.civilization.PlayerType
import com.unciv.logic.map.MapParameters
import com.unciv.logic.map.MapType
import com.unciv.models.metadata.GameParameters
import com.unciv.models.ruleset.RulesetCache
import com.unciv.models.translations.tr
import com.unciv.ui.pickerscreens.PickerScreen
import com.unciv.ui.utils.*
import com.unciv.ui.worldscreen.mainmenu.OnlineMultiplayer
import java.util.*
@ -21,14 +20,15 @@ import kotlin.concurrent.thread
class GameSetupInfo(var gameId:String, var gameParameters: GameParameters, var mapParameters: MapParameters) {
var ruleset = RulesetCache.getComplexRuleset(gameParameters.mods)
constructor() : this("", GameParameters(), MapParameters())
constructor(gameInfo: GameInfo) : this("", gameInfo.gameParameters.clone(), gameInfo.tileMap.mapParameters)
constructor(gameParameters: GameParameters, mapParameters: MapParameters) : this("", gameParameters, mapParameters)
}
class NewGameScreen(previousScreen:CameraStageBaseScreen, _gameSetupInfo: GameSetupInfo?=null): GameParametersPreviousScreen() {
class NewGameScreen(previousScreen:CameraStageBaseScreen, _gameSetupInfo: GameSetupInfo?=null): PreviousScreenInterface, PickerScreen() {
override var gameSetupInfo: GameSetupInfo = _gameSetupInfo ?: GameSetupInfo()
override val ruleset = RulesetCache.getComplexRuleset(gameSetupInfo.gameParameters.mods)
var playerPickerTable = PlayerPickerTable(this, gameSetupInfo.gameParameters)
var newGameOptionsTable = GameOptionsTable(this) { desiredCiv: String -> playerPickerTable.update(desiredCiv) }
var mapOptionsTable = MapOptionsTable(this)
@ -37,8 +37,6 @@ class NewGameScreen(previousScreen:CameraStageBaseScreen, _gameSetupInfo: GameSe
setDefaultCloseAction(previousScreen)
scrollPane.setScrollingDisabled(true, true)
// val playerPickerTable = PlayerPickerTable(this, gameSetupInfo.gameParameters)
// val newGameOptionsTable = GameOptionsTable(this) { desiredCiv: String -> playerPickerTable.update(desiredCiv) }
topTable.add(ScrollPane(mapOptionsTable).apply { setOverscroll(false, false) })
.maxHeight(topTable.parent.height).width(stage.width / 3).padTop(20f).top()
topTable.addSeparatorVertical()

View file

@ -14,12 +14,11 @@ import com.unciv.logic.IdChecker
import com.unciv.logic.civilization.PlayerType
import com.unciv.models.metadata.GameParameters
import com.unciv.models.metadata.Player
import com.unciv.models.ruleset.Ruleset
import com.unciv.models.translations.tr
import com.unciv.ui.utils.*
import java.util.*
class PlayerPickerTable(val previousScreen: GameParametersPreviousScreen, var gameParameters: GameParameters): Table() {
class PlayerPickerTable(val previousScreen: PreviousScreenInterface, var gameParameters: GameParameters): Table() {
val playerListTable = Table()
val nationsPopupWidth = previousScreen.stage.width / 2f
val civBlocksWidth = previousScreen.stage.width / 3
@ -35,18 +34,18 @@ class PlayerPickerTable(val previousScreen: GameParametersPreviousScreen, var ga
fun update(desiredCiv: String = "") {
playerListTable.clear()
val gameBasics = previousScreen.ruleset // the mod picking changes this ruleset
val ruleset = previousScreen.gameSetupInfo.ruleset // the mod picking changes this ruleset
reassignRemovedModReferences()
val newRulesetPlayableCivs = previousScreen.ruleset.nations.count { it.key != Constants.barbarians }
val newRulesetPlayableCivs = previousScreen.gameSetupInfo.ruleset.nations.count { it.key != Constants.barbarians }
if (gameParameters.players.size > newRulesetPlayableCivs)
gameParameters.players = ArrayList(gameParameters.players.subList(0, newRulesetPlayableCivs))
if (desiredCiv.isNotEmpty()) assignDesiredCiv(desiredCiv)
for (player in gameParameters.players) {
playerListTable.add(getPlayerTable(player, gameBasics)).width(civBlocksWidth).padBottom(20f).row()
playerListTable.add(getPlayerTable(player)).width(civBlocksWidth).padBottom(20f).row()
}
if (gameParameters.players.count() < gameBasics.nations.values.count { it.isMajorCiv() }
if (gameParameters.players.count() < ruleset.nations.values.count { it.isMajorCiv() }
&& !locked) {
playerListTable.add("+".toLabel(Color.BLACK, 30).apply { this.setAlignment(Align.center) }
.surroundWithCircle(50f).onClick { gameParameters.players.add(Player()); update() }).pad(10f)
@ -56,7 +55,7 @@ class PlayerPickerTable(val previousScreen: GameParametersPreviousScreen, var ga
private fun reassignRemovedModReferences() {
for (player in gameParameters.players) {
if (!previousScreen.ruleset.nations.containsKey(player.chosenCiv))
if (!previousScreen.gameSetupInfo.ruleset.nations.containsKey(player.chosenCiv))
player.chosenCiv = "Random"
}
}
@ -68,7 +67,7 @@ class PlayerPickerTable(val previousScreen: GameParametersPreviousScreen, var ga
gameParameters.players.firstOrNull { it.chosenCiv == "Random" && it.playerType == PlayerType.Human }?.chosenCiv = desiredCiv
}
fun getPlayerTable(player: Player, ruleset: Ruleset): Table {
fun getPlayerTable(player: Player): Table {
val playerTable = Table()
playerTable.pad(5f)
playerTable.background = ImageGetter.getBackground(ImageGetter.getBlue().lerp(Color.BLACK, 0.8f))
@ -134,7 +133,7 @@ class PlayerPickerTable(val previousScreen: GameParametersPreviousScreen, var ga
.apply { this.setAlignment(Align.center) }
.surroundWithCircle(36f).apply { circle.color = Color.BLACK }
.surroundWithCircle(40f, false).apply { circle.color = Color.WHITE }
else ImageGetter.getNationIndicator(previousScreen.ruleset.nations[player.chosenCiv]!!, 40f)
else ImageGetter.getNationIndicator(previousScreen.gameSetupInfo.ruleset.nations[player.chosenCiv]!!, 40f)
nationTable.add(nationImage).pad(5f)
nationTable.add(player.chosenCiv.toLabel()).pad(5f)
nationTable.touchable = Touchable.enabled
@ -145,7 +144,7 @@ class PlayerPickerTable(val previousScreen: GameParametersPreviousScreen, var ga
}
private fun popupNationPicker(player: Player) {
val nationsPopup = Popup(previousScreen)
val nationsPopup = Popup(previousScreen as CameraStageBaseScreen)
val nationListTable = Table()
val randomPlayerTable = Table()
@ -165,12 +164,12 @@ class PlayerPickerTable(val previousScreen: GameParametersPreviousScreen, var ga
nationListTable.add(randomPlayerTable).pad(10f).width(nationsPopupWidth).row()
for (nation in previousScreen.ruleset.nations.values
for (nation in previousScreen.gameSetupInfo.ruleset.nations.values
.filter { !it.isCityState() && it.name != Constants.barbarians }) {
if (player.chosenCiv != nation.name && gameParameters.players.any { it.chosenCiv == nation.name })
continue
nationListTable.add(NationTable(nation, nationsPopupWidth, previousScreen.ruleset).onClick {
nationListTable.add(NationTable(nation, nationsPopupWidth, previousScreen.gameSetupInfo.ruleset).onClick {
player.chosenCiv = nation.name
nationsPopup.close()
update()

View file

@ -0,0 +1,25 @@
package com.unciv.ui.newgamescreen
import com.badlogic.gdx.scenes.scene2d.Stage
import com.unciv.models.ruleset.Ruleset
import com.unciv.ui.pickerscreens.PickerScreen
import com.unciv.ui.utils.CameraStageBaseScreen
/**
* Interface to use as a previous screen for GameOptionsTable and PlayerPickerTable
* It should be a child of the PickerScreen class during new game creation
* or CameraBackStageScreen class for map editing
*/
interface PreviousScreenInterface {
var gameSetupInfo: GameSetupInfo
var stage: Stage
// added for compatibility with NewGameScreen: PickerScreen
fun setRightSideButtonEnabled(boolean: Boolean)
}
//abstract class GameParametersPreviousScreen: PickerScreen() {
// abstract var gameSetupInfo: GameSetupInfo
// abstract val ruleset: Ruleset
//}