From 693cf97849896545aee302498f68b736343bcec4 Mon Sep 17 00:00:00 2001 From: Xander Lenstra <71121390+xlenstra@users.noreply.github.com> Date: Tue, 26 Oct 2021 08:01:00 +0200 Subject: [PATCH] Made some improvements to the religion UI (#5561) * Made some improvements to the religion UI * Added translatable strings * Added some pretty colors - code based on code provided by SomeTroglodyte way back * I hate spaces * Moar colourz --- .../jsons/translations/template.properties | 10 +++ .../logic/civilization/ReligionManager.kt | 13 ++- core/src/com/unciv/models/ruleset/Belief.kt | 6 +- .../overviewscreen/ReligionOverviewTable.kt | 88 ++++++++++++++----- .../ReligiousBeliefsPickerScreen.kt | 21 ++++- 5 files changed, 108 insertions(+), 30 deletions(-) diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index 47df073581..61f1b71517 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -1140,6 +1140,16 @@ Holy City: = Cities following this religion: = Click an icon to see the stats of this religion = Religion: Off = +Minimal faith required for\nthe next [Great Prophet]: = +Religions founded: = +Religious status: = + +None = +Pantheon = +Founding religion = +Religion = +Enhancing religion = +Enhanced religion = # Terrains diff --git a/core/src/com/unciv/logic/civilization/ReligionManager.kt b/core/src/com/unciv/logic/civilization/ReligionManager.kt index bc84e5a22b..e3422f6ad9 100644 --- a/core/src/com/unciv/logic/civilization/ReligionManager.kt +++ b/core/src/com/unciv/logic/civilization/ReligionManager.kt @@ -128,7 +128,7 @@ class ReligionManager { return faithCost.toInt() } - private fun canGenerateProphet(): Boolean { + fun canGenerateProphet(): Boolean { if (!civInfo.gameInfo.isReligionEnabled()) return false // No religion, no prophets if (religion == null || religionState == ReligionState.None) return false // First get a pantheon, then we'll talk about a real religion if (getGreatProphetEquivalent() == null) return false @@ -347,5 +347,14 @@ enum class ReligionState { FoundingReligion, // Great prophet used, but religion has not yet been founded Religion, EnhancingReligion, // Great prophet used, but religion has not yet been enhanced - EnhancedReligion + EnhancedReligion; + + override fun toString(): String { + // Yes, this is the ugliest way to convert camel case to human readable format I've seen as well, but it works. + return super.toString() + .map { letter -> (if (letter.isUpperCase()) " " else "") + letter.lowercase() } + .joinToString("") + .removePrefix(" ") + .replaceFirstChar { it.uppercase() } + } } diff --git a/core/src/com/unciv/models/ruleset/Belief.kt b/core/src/com/unciv/models/ruleset/Belief.kt index dbb6d4e2ae..9499f0f24a 100644 --- a/core/src/com/unciv/models/ruleset/Belief.kt +++ b/core/src/com/unciv/models/ruleset/Belief.kt @@ -22,9 +22,13 @@ class Belief : RulesetObject() { override fun getIconName() = if (type == BeliefType.None) "Religion" else type.name override fun getCivilopediaTextLines(ruleset: Ruleset): List { + return getCivilopediaTextLines(ruleset, false) + } + + fun getCivilopediaTextLines(ruleset: Ruleset, centerType: Boolean): List { val textList = ArrayList() if (type != BeliefType.None) - textList += FormattedLine("{Type}: $type", color = type.color ) + textList += FormattedLine("{Type}: $type", color = type.color, centered = centerType) uniqueObjects.forEach { textList += FormattedLine(it) } diff --git a/core/src/com/unciv/ui/overviewscreen/ReligionOverviewTable.kt b/core/src/com/unciv/ui/overviewscreen/ReligionOverviewTable.kt index 9389f661ff..ea38f9aef1 100644 --- a/core/src/com/unciv/ui/overviewscreen/ReligionOverviewTable.kt +++ b/core/src/com/unciv/ui/overviewscreen/ReligionOverviewTable.kt @@ -3,11 +3,19 @@ package com.unciv.ui.overviewscreen import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.scenes.scene2d.ui.Button import com.badlogic.gdx.scenes.scene2d.ui.Table +import com.badlogic.gdx.utils.Align +import com.unciv.UncivGame import com.unciv.logic.civilization.CivilizationInfo +import com.unciv.logic.civilization.ReligionState import com.unciv.models.Religion import com.unciv.models.ruleset.Belief +import com.unciv.models.translations.fillPlaceholders import com.unciv.models.translations.tr +import com.unciv.ui.civilopedia.CivilopediaScreen +import com.unciv.ui.civilopedia.FormattedLine +import com.unciv.ui.civilopedia.MarkupRenderer import com.unciv.ui.utils.* +import kotlin.math.max import kotlin.math.min class ReligionOverviewTable( @@ -16,6 +24,10 @@ class ReligionOverviewTable( ): Table() { val gameInfo = viewingPlayer.gameInfo + + private val civStatsTable = Table(CameraStageBaseScreen.skin) + + private val religionsTable = Table(CameraStageBaseScreen.skin) private val topButtons = Table(CameraStageBaseScreen.skin) private val topButtonLabel = "Click an icon to see the stats of this religion".toLabel() private val statsTable = Table(CameraStageBaseScreen.skin) @@ -23,13 +35,38 @@ class ReligionOverviewTable( private var selectedReligion: String? = null init { + addCivSpecificStats(civStatsTable) addReligionButtons() + + religionsTable.add(topButtons).pad(5f).row() + religionsTable.add(topButtonLabel).pad(5f) + religionsTable.addSeparator() + religionsTable.add(statsTable).pad(5f).row() + religionsTable.add(beliefsTable).pad(5f) - add(topButtons).pad(5f).row() - add(topButtonLabel).pad(5f) - addSeparator() - add(statsTable).pad(5f).row() - add(beliefsTable).pad(5f) + add(civStatsTable).top().left().padRight(25f) + add(religionsTable) + } + + private fun addCivSpecificStats(statsTable: Table) { + if (viewingPlayer.religionManager.canGenerateProphet()) { + statsTable.add("Minimal faith required for\nthe next [great prophet equivalent]:" + .fillPlaceholders(viewingPlayer.religionManager.getGreatProphetEquivalent()!!) + .toLabel() + ).left() + statsTable.add( + (viewingPlayer.religionManager.faithForNextGreatProphet() + 1) + .toLabel() + ).right().pad(5f).row() + } + + statsTable.add("Religions founded:".toLabel()).left() + + val foundedReligions = viewingPlayer.gameInfo.civilizations.count { it.religionManager.religionState >= ReligionState.Religion } + statsTable.add((viewingPlayer.religionManager.amountOfFoundableReligions() - foundedReligions).toLabel()).right().pad(5f).row() + + statsTable.add("Religious status:".toLabel()).left() + statsTable.add(viewingPlayer.religionManager.religionState.toString().toLabel()).right().pad(5f).row() } private fun addReligionButtons() { @@ -71,43 +108,46 @@ class ReligionOverviewTable( beliefsTable.add(createBeliefDescription(belief)).pad(10f).row() } - statsTable.add("Religion Name:".toLabel()) - statsTable.add(religion.getReligionDisplayName().toLabel()).pad(5f).row() - statsTable.add("Founding Civ:".toLabel()) + statsTable.add("Religion Name:".toLabel()).left() + statsTable.add(religion.getReligionDisplayName().toLabel()).right().pad(5f).row() + statsTable.add("Founding Civ:".toLabel()).left() val foundingCivName = if (viewingPlayer.knows(religion.foundingCivName) || viewingPlayer.civName == religion.foundingCivName) religion.foundingCivName else "???" - statsTable.add(foundingCivName.toLabel()).pad(5f).row() + statsTable.add(foundingCivName.toLabel()).right().pad(5f).row() if (religion.isMajorReligion()) { val holyCity = gameInfo.getCities().firstOrNull { it.religion.religionThisIsTheHolyCityOf == religion.name } if (holyCity != null) { - statsTable.add("Holy City:".toLabel()) + statsTable.add("Holy City:".toLabel()).left() val cityName = if (viewingPlayer.exploredTiles.contains(holyCity.getCenterTile().position)) holyCity.name else "???" - statsTable.add(cityName.toLabel()).pad(5f).row() + statsTable.add(cityName.toLabel()).right().pad(5f).row() } } - statsTable.add("Cities following this religion:".toLabel()) - statsTable.add(gameInfo.getCivilization(religion.foundingCivName).religionManager.numberOfCitiesFollowingThisReligion().toString()).pad(5f).row() + statsTable.add("Cities following this religion:".toLabel()).left() + statsTable.add(gameInfo.getCivilization(religion.foundingCivName).religionManager.numberOfCitiesFollowingThisReligion().toString()).right().pad(5f).row() - val minWidth = min(statsTable.minWidth, beliefsTable.minWidth) + 5f + val minWidth = max(statsTable.minWidth, beliefsTable.minWidth) + 5 statsTable.width = minWidth for (cell in beliefsTable.cells) { cell.minWidth(minWidth) } } - - private fun createBeliefDescription(belief: Belief): Table { - val contentsTable = Table(CameraStageBaseScreen.skin) - contentsTable.add(belief.type.name.toLabel()).row() - contentsTable.add(belief.name.toLabel(fontSize = 24)).row() - contentsTable.add(belief.uniques.joinToString().toLabel()) - contentsTable.background = ImageGetter.getBackground(ImageGetter.getBlue()) - contentsTable.padTop(5f).padBottom(5f) - return contentsTable - } + + private fun createBeliefDescription(belief: Belief) = + MarkupRenderer.render( + belief.run { sequence { + yield(FormattedLine(name, size = 24, centered = true)) + yield(FormattedLine()) + yieldAll(getCivilopediaTextLines(gameInfo.ruleSet, true)) + } }.toList() + ) { + UncivGame.Current.setScreen(CivilopediaScreen(gameInfo.ruleSet, link = it)) + }.apply { + background = ImageGetter.getBackground(ImageGetter.getBlue()) + } } diff --git a/core/src/com/unciv/ui/pickerscreens/ReligiousBeliefsPickerScreen.kt b/core/src/com/unciv/ui/pickerscreens/ReligiousBeliefsPickerScreen.kt index c9048cee12..755a13d2c9 100644 --- a/core/src/com/unciv/ui/pickerscreens/ReligiousBeliefsPickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/ReligiousBeliefsPickerScreen.kt @@ -163,6 +163,8 @@ class ReligiousBeliefsPickerScreen ( for (newBelief in chosenBeliefs.withIndex()) { addChoosableBeliefButton(newBelief, getBeliefTypeFromIndex(newBelief.index)) } + + equalizeAllButtons(leftChosenBeliefs) } private fun loadRightTable(beliefType: BeliefType, leftButtonIndex: Int) { @@ -182,7 +184,20 @@ class ReligiousBeliefsPickerScreen ( updateLeftTable() checkAndEnableRightSideButton() } - rightBeliefsToChoose.add(beliefButton).pad(10f).row() + rightBeliefsToChoose.add(beliefButton).left().pad(10f).row() + } + equalizeAllButtons(rightBeliefsToChoose) + } + + private fun equalizeAllButtons(table: Table) { + val minWidth = table.cells + .filter { it.actor is Button } + .maxOfOrNull { it.actor.width } + ?: return + + for (button in table.cells) { + if (button.actor is Button) + button.minWidth(minWidth) } } @@ -199,9 +214,9 @@ class ReligiousBeliefsPickerScreen ( private fun convertBeliefToButton(belief: Belief): Button { val contentsTable = Table() - contentsTable.add(belief.type.name.toLabel()).row() + contentsTable.add(belief.type.name.toLabel(fontColor = Color.valueOf(belief.type.color))).row() contentsTable.add(belief.name.toLabel(fontSize = 24)).row() - contentsTable.add(belief.uniques.joinToString().toLabel()) + contentsTable.add(belief.uniques.joinToString("\n") { it.tr() }.toLabel()) return Button(contentsTable, skin) }