From 980f0f4611060ae2402933db729c411018830e49 Mon Sep 17 00:00:00 2001 From: Xander Lenstra <71121390+xlenstra@users.noreply.github.com> Date: Sun, 5 Sep 2021 11:05:54 +0200 Subject: [PATCH] Fixed crash when viewing the name of a religion (#5092) --- core/src/com/unciv/logic/map/MapUnit.kt | 2 +- core/src/com/unciv/models/Religion.kt | 5 ++++- core/src/com/unciv/ui/cityscreen/CityStatsTable.kt | 4 ++-- .../src/com/unciv/ui/overviewscreen/ReligionOverviewTable.kt | 4 ++-- .../unciv/ui/pickerscreens/ReligiousBeliefsPickerScreen.kt | 2 +- core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt | 2 +- 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index 8f07f311b7..c83b4a76bd 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -973,7 +973,7 @@ class MapUnit { fun getReligionDisplayName(): String? { if (religion == null) return null - return civInfo.gameInfo.religions[religion]!!.displayName ?: religion + return civInfo.gameInfo.religions[religion]!!.getReligionDisplayName() } fun religiousActionsUnitCanDo(): Sequence { diff --git a/core/src/com/unciv/models/Religion.kt b/core/src/com/unciv/models/Religion.kt index ed92a39498..fbac76df3d 100644 --- a/core/src/com/unciv/models/Religion.kt +++ b/core/src/com/unciv/models/Religion.kt @@ -21,7 +21,6 @@ class Religion() : INamed { constructor(name: String, gameInfo: GameInfo, foundingCivName: String) : this() { this.name = name - this.displayName = name this.foundingCivName = foundingCivName this.gameInfo = gameInfo } @@ -42,6 +41,10 @@ class Religion() : INamed { if (isPantheon()) "Pantheon" else name + fun getReligionDisplayName() = + if (displayName != null) displayName!! + else name + private fun mapToExistingBeliefs(beliefs: HashSet): List { val rulesetBeliefs = gameInfo.ruleSet.beliefs return beliefs.mapNotNull { diff --git a/core/src/com/unciv/ui/cityscreen/CityStatsTable.kt b/core/src/com/unciv/ui/cityscreen/CityStatsTable.kt index c1efdd7d72..0b7a78e442 100644 --- a/core/src/com/unciv/ui/cityscreen/CityStatsTable.kt +++ b/core/src/com/unciv/ui/cityscreen/CityStatsTable.kt @@ -83,7 +83,7 @@ class CityStatsTable(val cityScreen: CityScreen): Table() { } private fun addReligionInfo() { - val label = cityInfo.religion.getMajorityReligion()?.displayName + val label = cityInfo.religion.getMajorityReligion()?.getReligionDisplayName() ?: "None" val icon = if (label == "None") "Religion" @@ -107,7 +107,7 @@ class CityStatsTable(val cityScreen: CityScreen): Table() { // I want this to be centered, but `.center()` doesn't seem to do anything, // regardless of where I place it :( it.add( - "Holy city of: [${cityInfo.civInfo.gameInfo.religions[cityInfo.religion.religionThisIsTheHolyCityOf!!]!!.displayName}]".toLabel() + "Holy city of: [${cityInfo.civInfo.gameInfo.religions[cityInfo.religion.religionThisIsTheHolyCityOf!!]!!.getReligionDisplayName()}]".toLabel() ).center().colspan(2).pad(5f).row() } it.add(getReligionsTable()).colspan(2).pad(5f) diff --git a/core/src/com/unciv/ui/overviewscreen/ReligionOverviewTable.kt b/core/src/com/unciv/ui/overviewscreen/ReligionOverviewTable.kt index c33fc3a6e0..9389f661ff 100644 --- a/core/src/com/unciv/ui/overviewscreen/ReligionOverviewTable.kt +++ b/core/src/com/unciv/ui/overviewscreen/ReligionOverviewTable.kt @@ -66,13 +66,13 @@ class ReligionOverviewTable( private fun loadReligion(religion: Religion) { statsTable.clear() beliefsTable.clear() - topButtonLabel.setText(religion.displayName!!.tr()) + topButtonLabel.setText(religion.getReligionDisplayName().tr()) for (belief in religion.getAllBeliefsOrdered()) { beliefsTable.add(createBeliefDescription(belief)).pad(10f).row() } statsTable.add("Religion Name:".toLabel()) - statsTable.add(religion.displayName!!.toLabel()).pad(5f).row() + statsTable.add(religion.getReligionDisplayName().toLabel()).pad(5f).row() statsTable.add("Founding Civ:".toLabel()) val foundingCivName = if (viewingPlayer.knows(religion.foundingCivName) || viewingPlayer.civName == religion.foundingCivName) diff --git a/core/src/com/unciv/ui/pickerscreens/ReligiousBeliefsPickerScreen.kt b/core/src/com/unciv/ui/pickerscreens/ReligiousBeliefsPickerScreen.kt index 04801d4670..e89a04ece4 100644 --- a/core/src/com/unciv/ui/pickerscreens/ReligiousBeliefsPickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/ReligiousBeliefsPickerScreen.kt @@ -50,7 +50,7 @@ class ReligiousBeliefsPickerScreen ( topTable.add(middlePanes) if (pickIconAndName) rightSideButton.label = "Choose a religion".toLabel() - else rightSideButton.label = "Enhance [${choosingCiv.religionManager.religion!!.displayName}]".toLabel() + else rightSideButton.label = "Enhance [${choosingCiv.religionManager.religion!!.getReligionDisplayName()}]".toLabel() rightSideButton.onClick(UncivSound.Choir) { choosingCiv.religionManager.chooseBeliefs(displayName, religionName, beliefsContainer.chosenBeliefs.map { it!! }) UncivGame.Current.setWorldScreen() diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt index b4f887fdf7..56b05348f7 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt @@ -503,7 +503,7 @@ object UnitActions { if (!unit.hasUnique("May enhance a religion")) return if (!unit.civInfo.religionManager.mayEnhanceReligionAtAll(unit)) return actionList += UnitAction(UnitActionType.EnhanceReligion, - title = "Enhance [${unit.civInfo.religionManager.religion!!.displayName}]", + title = "Enhance [${unit.civInfo.religionManager.religion!!.getReligionDisplayName()}]", action = getEnhanceReligionAction(unit).takeIf { unit.civInfo.religionManager.mayEnhanceReligionNow(unit) } ) }