Added a NewGameScreen option to choose the base ruleset - it works, which means G&K and Vanilla games can coexist well!

We're ready to start making changes! =D
This commit is contained in:
Yair Morgenstern
2020-07-04 23:53:46 +03:00
parent 81f88087fe
commit d7cc0868fb
3 changed files with 28 additions and 15 deletions

View File

@ -40,6 +40,7 @@ class GameParameters { // Default values are the default new game
parameters.victoryTypes = ArrayList(victoryTypes)
parameters.startingEra = startingEra
parameters.isOnlineMultiplayer = isOnlineMultiplayer
parameters.baseRuleset = baseRuleset
parameters.mods = LinkedHashSet(mods)
return parameters
}

View File

@ -4,6 +4,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.CheckBox
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.models.metadata.BaseRuleset
import com.unciv.models.metadata.GameSpeed
import com.unciv.models.ruleset.RulesetCache
import com.unciv.models.ruleset.VictoryType
@ -32,6 +33,7 @@ class GameOptionsTable(previousScreen: IPreviousScreen, val updatePlayerPickerTa
add("Game Options".toLabel(fontSize = 24)).padTop(0f).padBottom(20f).colspan(2).row()
add(Table().apply {
defaults().pad(5f)
//addBaseRulesetSelectBox()
addDifficultySelectBox()
addGameSpeedSelectBox()
addEraSelectBox()
@ -107,6 +109,14 @@ class GameOptionsTable(previousScreen: IPreviousScreen, val updatePlayerPickerTa
{ gameParameters.difficulty = it }
}
private fun Table.addBaseRulesetSelectBox() {
addSelectBox("{Base Ruleset}:", BaseRuleset.values().map { it.fullName }, gameParameters.baseRuleset.fullName)
{
gameParameters.baseRuleset = BaseRuleset.values().first { br -> br.fullName == it }
reloadRuleset()
}
}
private fun Table.addGameSpeedSelectBox() {
addSelectBox("{Game Speed}:", GameSpeed.values().map { it.name }, gameParameters.gameSpeed.name)
{ gameParameters.gameSpeed = GameSpeed.valueOf(it) }
@ -145,21 +155,21 @@ class GameOptionsTable(previousScreen: IPreviousScreen, val updatePlayerPickerTa
add(victoryConditionsTable).colspan(2).row()
}
fun reloadRuleset() {
ruleset.clear()
val newRuleset = RulesetCache.getComplexRuleset(gameParameters)
ruleset.add(newRuleset)
ruleset.mods += gameParameters.mods
ruleset.modOptions = newRuleset.modOptions
ImageGetter.ruleset = ruleset
ImageGetter.setTextureRegionDrawables()
}
fun Table.addModCheckboxes() {
val modRulesets = RulesetCache.filter { it.key != "" }.values
if (modRulesets.isEmpty()) return
fun reloadMods() {
ruleset.clear()
val newRuleset = RulesetCache.getComplexRuleset(gameParameters)
ruleset.add(newRuleset)
ruleset.mods += gameParameters.mods
ruleset.modOptions = newRuleset.modOptions
ImageGetter.ruleset = ruleset
ImageGetter.setTextureRegionDrawables()
}
add("Mods:".toLabel(fontSize = 24)).padTop(16f).colspan(2).row()
val modCheckboxTable = Table().apply { defaults().pad(5f) }
@ -170,7 +180,7 @@ class GameOptionsTable(previousScreen: IPreviousScreen, val updatePlayerPickerTa
checkBox.onChange {
if (checkBox.isChecked) gameParameters.mods.add(mod.name)
else gameParameters.mods.remove(mod.name)
reloadMods()
reloadRuleset()
var desiredCiv = ""
if (checkBox.isChecked) {
val modNations = RulesetCache[mod.name]?.nations

View File

@ -31,8 +31,9 @@ class GameSetupInfo(var gameId:String, var gameParameters: GameParameters, var m
class NewGameScreen(previousScreen:CameraStageBaseScreen, _gameSetupInfo: GameSetupInfo?=null): IPreviousScreen, PickerScreen() {
override val gameSetupInfo = _gameSetupInfo ?: GameSetupInfo()
override val ruleset = RulesetCache.getComplexRuleset(gameSetupInfo.gameParameters)
var playerPickerTable = PlayerPickerTable(this, gameSetupInfo.gameParameters)
var newGameOptionsTable = GameOptionsTable(this) { desiredCiv: String -> playerPickerTable.update(desiredCiv) }
// Has to be defined before the mapOptionsTable, since the mapOptionsTable refers to it on init
var playerPickerTable = PlayerPickerTable(this, gameSetupInfo.gameParameters)
var mapOptionsTable = MapOptionsTable(this)
@ -40,13 +41,14 @@ class NewGameScreen(previousScreen:CameraStageBaseScreen, _gameSetupInfo: GameSe
setDefaultCloseAction(previousScreen)
scrollPane.setScrollingDisabled(true, true)
topTable.add(ScrollPane(newGameOptionsTable).apply { setOverscroll(false, false) })
.maxHeight(topTable.parent.height).width(stage.width / 3).padTop(20f).top()
topTable.addSeparatorVertical()
topTable.add(ScrollPane(mapOptionsTable).apply { setOverscroll(false, false) })
.maxHeight(topTable.parent.height).width(stage.width / 3).padTop(20f).top()
topTable.addSeparatorVertical()
topTable.add(playerPickerTable).maxHeight(topTable.parent.height).width(stage.width / 3).padTop(20f).top()
topTable.addSeparatorVertical()
topTable.add(ScrollPane(newGameOptionsTable).apply { setOverscroll(false, false) })
.maxHeight(topTable.parent.height).width(stage.width / 3).padTop(20f).top()
topTable.pack()
topTable.setFillParent(true)