Mods with no policy branches don't crash when clicking on culture icon

This commit is contained in:
Yair Morgenstern 2024-02-27 23:37:54 +02:00
parent 9054d84626
commit ce8a7e9e3e

View File

@ -51,10 +51,11 @@ internal class WorldScreenTopBarStats(topbar: WorldScreenTopBar) : ScalingTableW
isTransform = false isTransform = false
fun addStat(label: Label, icon: String, isLast: Boolean = false, screenFactory: ()-> BaseScreen) { fun addStat(label: Label, icon: String, isLast: Boolean = false, screenFactory: ()-> BaseScreen?) {
val image = ImageGetter.getStatIcon(icon) val image = ImageGetter.getStatIcon(icon)
val action = { val action = {
worldScreen.game.pushScreen(screenFactory()) val screen = screenFactory()
if (screen != null) worldScreen.game.pushScreen(screen)
} }
label.onClick(action) label.onClick(action)
image.onClick(action) image.onClick(action)
@ -79,7 +80,10 @@ internal class WorldScreenTopBarStats(topbar: WorldScreenTopBar) : ScalingTableW
happinessContainer.onClick(invokeResourcesPage) happinessContainer.onClick(invokeResourcesPage)
happinessLabel.onClick(invokeResourcesPage) happinessLabel.onClick(invokeResourcesPage)
addStat(cultureLabel, "Culture") { PolicyPickerScreen(worldScreen.selectedCiv, worldScreen.canChangeState) } addStat(cultureLabel, "Culture") {
if (worldScreen.gameInfo.ruleset.policyBranches.isEmpty()) null
else PolicyPickerScreen(worldScreen.selectedCiv, worldScreen.canChangeState)
}
if (worldScreen.gameInfo.isReligionEnabled()) { if (worldScreen.gameInfo.isReligionEnabled()) {
addStat(faithLabel, "Faith", EmpireOverviewCategories.Religion, isLast = true) addStat(faithLabel, "Faith", EmpireOverviewCategories.Religion, isLast = true)
} else { } else {