Game handles 'picking a scenario based on a custom ruleset' well

This commit is contained in:
Yair Morgenstern 2020-08-10 22:59:48 +03:00
parent 0c4947a03e
commit 2e0d73cf75
2 changed files with 10 additions and 1 deletions

View File

@ -61,6 +61,7 @@ class MapOptionsTable(val newGameScreen: NewGameScreen): Table() {
val scenario = MapSaver.loadScenario(mapParameters.name) val scenario = MapSaver.loadScenario(mapParameters.name)
newGameScreen.gameSetupInfo.gameParameters = scenario.gameParameters newGameScreen.gameSetupInfo.gameParameters = scenario.gameParameters
newGameScreen.gameSetupInfo.mapParameters = mapParameters newGameScreen.gameSetupInfo.mapParameters = mapParameters
newGameScreen.updateRuleset()
// update PlayerTable and GameOptionsTable // update PlayerTable and GameOptionsTable
newGameScreen.lockTables() newGameScreen.lockTables()
newGameScreen.updateTables() newGameScreen.updateTables()

View File

@ -10,6 +10,7 @@ import com.unciv.logic.*
import com.unciv.logic.civilization.PlayerType import com.unciv.logic.civilization.PlayerType
import com.unciv.logic.map.MapParameters import com.unciv.logic.map.MapParameters
import com.unciv.models.metadata.GameParameters import com.unciv.models.metadata.GameParameters
import com.unciv.models.ruleset.Ruleset
import com.unciv.models.ruleset.RulesetCache import com.unciv.models.ruleset.RulesetCache
import com.unciv.models.translations.tr import com.unciv.models.translations.tr
import com.unciv.ui.pickerscreens.PickerScreen import com.unciv.ui.pickerscreens.PickerScreen
@ -35,7 +36,7 @@ class GameSetupInfo(var gameId:String, var gameParameters: GameParameters, var m
class NewGameScreen(previousScreen:CameraStageBaseScreen, _gameSetupInfo: GameSetupInfo?=null): IPreviousScreen, PickerScreen() { class NewGameScreen(previousScreen:CameraStageBaseScreen, _gameSetupInfo: GameSetupInfo?=null): IPreviousScreen, PickerScreen() {
override val gameSetupInfo = _gameSetupInfo ?: GameSetupInfo() override val gameSetupInfo = _gameSetupInfo ?: GameSetupInfo()
override val ruleset = RulesetCache.getComplexRuleset(gameSetupInfo.gameParameters) override var ruleset = RulesetCache.getComplexRuleset(gameSetupInfo.gameParameters) // needs to be set because the gameoptionstable etc. depend on this
var newGameOptionsTable = GameOptionsTable(this) { desiredCiv: String -> playerPickerTable.update(desiredCiv) } var newGameOptionsTable = GameOptionsTable(this) { desiredCiv: String -> playerPickerTable.update(desiredCiv) }
// Has to be defined before the mapOptionsTable, since the mapOptionsTable refers to it on init // Has to be defined before the mapOptionsTable, since the mapOptionsTable refers to it on init
var playerPickerTable = PlayerPickerTable(this, gameSetupInfo.gameParameters) var playerPickerTable = PlayerPickerTable(this, gameSetupInfo.gameParameters)
@ -57,6 +58,8 @@ class NewGameScreen(previousScreen:CameraStageBaseScreen, _gameSetupInfo: GameSe
topTable.pack() topTable.pack()
topTable.setFillParent(true) topTable.setFillParent(true)
updateRuleset()
rightSideButton.enable() rightSideButton.enable()
rightSideButton.setText("Start game!".tr()) rightSideButton.setText("Start game!".tr())
rightSideButton.onClick { rightSideButton.onClick {
@ -135,6 +138,11 @@ class NewGameScreen(previousScreen:CameraStageBaseScreen, _gameSetupInfo: GameSe
Gdx.graphics.requestRendering() Gdx.graphics.requestRendering()
} }
fun updateRuleset(){
ruleset.clear()
ruleset.add(RulesetCache.getComplexRuleset(gameSetupInfo.gameParameters))
}
fun lockTables() { fun lockTables() {
playerPickerTable.locked = true playerPickerTable.locked = true
newGameOptionsTable.locked = true newGameOptionsTable.locked = true