Make so Citizen Management buttons don't work if Spectator (#6954)

This commit is contained in:
itanasi 2022-05-26 05:24:55 -07:00 committed by GitHub
parent ea03b97639
commit e7a90f2ad0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 21 deletions

View File

@ -34,7 +34,8 @@ class CitizenManagementTable(val cityScreen: CityScreen) : Table() {
val avoidCell = Table() val avoidCell = Table()
avoidCell.touchable = Touchable.enabled avoidCell.touchable = Touchable.enabled
avoidCell.add(avoidLabel).pad(5f) avoidCell.add(avoidLabel).pad(5f)
avoidCell.onClick { city.avoidGrowth = !city.avoidGrowth; city.reassignPopulation(); cityScreen.update() } if (cityScreen.canChangeState)
avoidCell.onClick { city.avoidGrowth = !city.avoidGrowth; city.reassignPopulation(); cityScreen.update() }
avoidCell.background = ImageGetter.getBackground(if (city.avoidGrowth) colorSelected else colorButton) avoidCell.background = ImageGetter.getBackground(if (city.avoidGrowth) colorSelected else colorButton)
innerTable.add(avoidCell).colspan(2).growX().pad(3f) innerTable.add(avoidCell).colspan(2).growX().pad(3f)
@ -47,7 +48,8 @@ class CitizenManagementTable(val cityScreen: CityScreen) : Table() {
val cell = Table() val cell = Table()
cell.touchable = Touchable.enabled cell.touchable = Touchable.enabled
cell.add(label).pad(5f) cell.add(label).pad(5f)
cell.onClick { city.cityAIFocus = focus; city.reassignPopulation(); cityScreen.update() } if (cityScreen.canChangeState)
cell.onClick { city.cityAIFocus = focus; city.reassignPopulation(); cityScreen.update() }
cell.background = ImageGetter.getBackground(if (city.cityAIFocus == focus) colorSelected else colorButton) cell.background = ImageGetter.getBackground(if (city.cityAIFocus == focus) colorSelected else colorButton)
innerTable.add(cell).growX().pad(3f) innerTable.add(cell).growX().pad(3f)

View File

@ -123,6 +123,7 @@ class CityScreen(
resetCitizensButton.onClick { city.reassignPopulation(resetLocked = true); update() } resetCitizensButton.onClick { city.reassignPopulation(resetLocked = true); update() }
resetCitizensButtonHolder.add(resetCitizensButton) resetCitizensButtonHolder.add(resetCitizensButton)
resetCitizensButtonHolder.pack() resetCitizensButtonHolder.pack()
if (!canChangeState) resetCitizensButton.disable()
stage.addActor(resetCitizensButtonHolder) stage.addActor(resetCitizensButtonHolder)
val citizenManagementButton = "Citizen Management".toTextButton() val citizenManagementButton = "Citizen Management".toTextButton()
citizenManagementButton.labelCell.pad(5f) citizenManagementButton.labelCell.pad(5f)
@ -131,6 +132,7 @@ class CityScreen(
citizenManagementVisible = true citizenManagementVisible = true
update() update()
} }
if (!canChangeState) citizenManagementButton.disable()
citizenManagementButtonHolder.add(citizenManagementButton) citizenManagementButtonHolder.add(citizenManagementButton)
citizenManagementButtonHolder.pack() citizenManagementButtonHolder.pack()
stage.addActor(citizenManagementButtonHolder) stage.addActor(citizenManagementButtonHolder)
@ -193,7 +195,7 @@ class CityScreen(
citizenManagementButtonHolder.isVisible = !citizenManagementVisible citizenManagementButtonHolder.isVisible = !citizenManagementVisible
citizenManagementButtonHolder.setPosition(stage.width - posFromEdge, citizenManagementButtonHolder.setPosition(stage.width - posFromEdge,
posFromEdge + resetCitizensButtonHolder.y + resetCitizensButtonHolder.height + 10f, Align.bottomRight) posFromEdge + resetCitizensButtonHolder.y + resetCitizensButtonHolder.height + 10f, Align.bottomRight)
// In portrait mode only: calculate already occupied horizontal space // In portrait mode only: calculate already occupied horizontal space
val rightMargin = when { val rightMargin = when {
!isPortrait() -> 0f !isPortrait() -> 0f

View File

@ -42,16 +42,18 @@ class CityStatsTable(val cityScreen: CityScreen): Table() {
val icon = Table() val icon = Table()
if (cityInfo.cityAIFocus.stat == stat) { if (cityInfo.cityAIFocus.stat == stat) {
icon.add(ImageGetter.getStatIcon(stat.name).surroundWithCircle(27f, false, color = selected)) icon.add(ImageGetter.getStatIcon(stat.name).surroundWithCircle(27f, false, color = selected))
icon.onClick { if (cityScreen.canChangeState)
cityInfo.cityAIFocus = CityFocus.NoFocus icon.onClick {
cityInfo.reassignPopulation(); cityScreen.update() cityInfo.cityAIFocus = CityFocus.NoFocus
} cityInfo.reassignPopulation(); cityScreen.update()
}
} else { } else {
icon.add(ImageGetter.getStatIcon(stat.name).surroundWithCircle(27f, false, color = Color.CLEAR)) icon.add(ImageGetter.getStatIcon(stat.name).surroundWithCircle(27f, false, color = Color.CLEAR))
icon.onClick { if (cityScreen.canChangeState)
cityInfo.cityAIFocus = cityInfo.cityAIFocus.safeValueOf(stat) icon.onClick {
cityInfo.reassignPopulation(); cityScreen.update() cityInfo.cityAIFocus = cityInfo.cityAIFocus.safeValueOf(stat)
} cityInfo.reassignPopulation(); cityScreen.update()
}
} }
miniStatsTable.add(icon).size(27f).padRight(5f) miniStatsTable.add(icon).size(27f).padRight(5f)
val valueToDisplay = if (stat == Stat.Happiness) cityInfo.cityStats.happinessList.values.sum() else amount val valueToDisplay = if (stat == Stat.Happiness) cityInfo.cityStats.happinessList.values.sum() else amount
@ -74,7 +76,8 @@ class CityStatsTable(val cityScreen: CityScreen): Table() {
val unassignedPopString = "{Unassigned population}: ".tr() + val unassignedPopString = "{Unassigned population}: ".tr() +
cityInfo.population.getFreePopulation().toString() + "/" + cityInfo.population.population cityInfo.population.getFreePopulation().toString() + "/" + cityInfo.population.population
val unassignedPopLabel = unassignedPopString.toLabel() val unassignedPopLabel = unassignedPopString.toLabel()
unassignedPopLabel.onClick { cityInfo.reassignPopulation(); cityScreen.update() } if (cityScreen.canChangeState)
unassignedPopLabel.onClick { cityInfo.reassignPopulation(); cityScreen.update() }
var turnsToExpansionString = var turnsToExpansionString =
if (cityInfo.cityStats.currentCityStats.culture > 0 && cityInfo.expansion.getChoosableTiles().any()) { if (cityInfo.cityStats.currentCityStats.culture > 0 && cityInfo.expansion.getChoosableTiles().any()) {

View File

@ -18,15 +18,21 @@ class SpecialistAllocationTable(val cityScreen: CityScreen) : Table(BaseScreen.s
// Auto/Manual Specialists Toggle // Auto/Manual Specialists Toggle
// Color of "color" coming from Skin.json that's loaded into BaseScreen // Color of "color" coming from Skin.json that's loaded into BaseScreen
// 5 columns: unassignButton, AllocationTable, assignButton, SeparatorVertical, SpecialistsStatsTabe // 5 columns: unassignButton, AllocationTable, assignButton, SeparatorVertical, SpecialistsStatsTabe
if (cityInfo.manualSpecialists) { if (cityScreen.canChangeState)
val manualSpecialists = "Manual Specialists".toLabel().addBorder(5f, BaseScreen.skin.get("color", Color::class.java)) if (cityInfo.manualSpecialists) {
manualSpecialists.onClick { cityInfo.manualSpecialists = false; cityInfo.reassignPopulation(); cityScreen.update() } val manualSpecialists = "Manual Specialists".toLabel()
add(manualSpecialists).colspan(5).row() .addBorder(5f, BaseScreen.skin.get("color", Color::class.java))
} else { manualSpecialists.onClick {
val autoSpecialists = "Auto Specialists".toLabel().addBorder(5f, BaseScreen.skin.get("color", Color::class.java)) cityInfo.manualSpecialists = false
autoSpecialists.onClick { cityInfo.manualSpecialists = true; update() } cityInfo.reassignPopulation(); cityScreen.update()
add(autoSpecialists).colspan(5).row() }
} add(manualSpecialists).colspan(5).row()
} else {
val autoSpecialists = "Auto Specialists".toLabel()
.addBorder(5f, BaseScreen.skin.get("color", Color::class.java))
autoSpecialists.onClick { cityInfo.manualSpecialists = true; update() }
add(autoSpecialists).colspan(5).row()
}
for ((specialistName, maxSpecialists) in cityInfo.population.getMaxSpecialists()) { for ((specialistName, maxSpecialists) in cityInfo.population.getMaxSpecialists()) {
if (!cityInfo.getRuleset().specialists.containsKey(specialistName)) // specialist doesn't exist in this ruleset, probably a mod if (!cityInfo.getRuleset().specialists.containsKey(specialistName)) // specialist doesn't exist in this ruleset, probably a mod
continue continue