Organized checkboxes in game parameters table

This commit is contained in:
Yair Morgenstern 2020-05-12 21:46:31 +03:00
parent c84550fc2c
commit b393498c1a

View file

@ -28,45 +28,42 @@ class NewGameParametersTable(newGameScreen: NewGameScreen, val updatePlayerPicke
addEraSelectBox() addEraSelectBox()
addCityStatesSelectBox() addCityStatesSelectBox()
addVictoryTypeCheckboxes() addVictoryTypeCheckboxes()
addBarbariansCheckbox()
addOneCityChallengeCheckbox() val checkboxTable = Table().apply { defaults().pad(5f) }
addNuclearWeaponsCheckbox() checkboxTable.addBarbariansCheckbox()
addIsOnlineMultiplayerCheckbox() checkboxTable.addOneCityChallengeCheckbox()
addModCheckboxes() checkboxTable.addNuclearWeaponsCheckbox()
checkboxTable.addIsOnlineMultiplayerCheckbox()
checkboxTable.addModCheckboxes()
add(checkboxTable).colspan(2).row()
pack() pack()
} }
private fun addCheckbox(text: String, initialState: Boolean, onChange: (newValue: Boolean) -> Unit) { private fun Table.addCheckbox(text: String, initialState: Boolean, onChange: (newValue: Boolean) -> Unit) {
val checkbox = CheckBox(text.tr(), CameraStageBaseScreen.skin) val checkbox = CheckBox(text.tr(), CameraStageBaseScreen.skin)
checkbox.isChecked = initialState checkbox.isChecked = initialState
checkbox.onChange { onChange(checkbox.isChecked) } checkbox.onChange { onChange(checkbox.isChecked) }
add(checkbox).colspan(2).row() add(checkbox).colspan(2).left().row()
} }
private fun addBarbariansCheckbox() = private fun Table.addBarbariansCheckbox() =
addCheckbox("No barbarians", newGameParameters.noBarbarians) addCheckbox("No barbarians", newGameParameters.noBarbarians)
{ newGameParameters.noBarbarians = it } { newGameParameters.noBarbarians = it }
private fun addOneCityChallengeCheckbox() = private fun Table.addOneCityChallengeCheckbox() =
addCheckbox("One City Challenge", newGameParameters.oneCityChallenge) addCheckbox("One City Challenge", newGameParameters.oneCityChallenge)
{ newGameParameters.oneCityChallenge = it } { newGameParameters.oneCityChallenge = it }
private fun addNuclearWeaponsCheckbox() = private fun Table.addNuclearWeaponsCheckbox() =
addCheckbox("Enable nuclear weapons", newGameParameters.nuclearWeaponsEnabled) addCheckbox("Enable nuclear weapons", newGameParameters.nuclearWeaponsEnabled)
{ newGameParameters.nuclearWeaponsEnabled = it } { newGameParameters.nuclearWeaponsEnabled = it }
private fun addIsOnlineMultiplayerCheckbox() { private fun Table.addIsOnlineMultiplayerCheckbox() =
addCheckbox("Online Multiplayer", newGameParameters.isOnlineMultiplayer)
val isOnlineMultiplayerCheckbox = CheckBox("Online Multiplayer".tr(), CameraStageBaseScreen.skin) {newGameParameters.isOnlineMultiplayer = it
isOnlineMultiplayerCheckbox.isChecked = newGameParameters.isOnlineMultiplayer updatePlayerPickerTable("") }
isOnlineMultiplayerCheckbox.onChange {
newGameParameters.isOnlineMultiplayer = isOnlineMultiplayerCheckbox.isChecked
updatePlayerPickerTable("")
}
add(isOnlineMultiplayerCheckbox).colspan(2).row()
}
private fun addCityStatesSelectBox() { private fun addCityStatesSelectBox() {
add("{Number of city-states}:".toLabel()) add("{Number of city-states}:".toLabel())
@ -135,7 +132,7 @@ class NewGameParametersTable(newGameScreen: NewGameScreen, val updatePlayerPicke
} }
fun addModCheckboxes() { fun Table.addModCheckboxes() {
val modRulesets = RulesetCache.filter { it.key != "" }.values val modRulesets = RulesetCache.filter { it.key != "" }.values
if (modRulesets.isEmpty()) return if (modRulesets.isEmpty()) return