mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-04 23:40:01 +07:00
Make City-state boni display respect hidden from users flags (#10786)
This commit is contained in:
@ -701,7 +701,7 @@ class CityStateFunctions(val civInfo: Civilization) {
|
||||
}
|
||||
|
||||
|
||||
fun getCityStateBonuses(cityStateType: CityStateType, relationshipLevel: RelationshipLevel, uniqueType:UniqueType?=null): Sequence<Unique> {
|
||||
fun getCityStateBonuses(cityStateType: CityStateType, relationshipLevel: RelationshipLevel, uniqueType: UniqueType? = null): Sequence<Unique> {
|
||||
val cityStateUniqueMap = when (relationshipLevel) {
|
||||
RelationshipLevel.Ally -> cityStateType.allyBonusUniqueMap
|
||||
RelationshipLevel.Friend -> cityStateType.friendBonusUniqueMap
|
||||
|
@ -5,6 +5,7 @@ import com.unciv.Constants
|
||||
import com.unciv.logic.MultiFilter
|
||||
import com.unciv.models.ruleset.Ruleset
|
||||
import com.unciv.models.ruleset.RulesetObject
|
||||
import com.unciv.models.ruleset.unique.UniqueMap
|
||||
import com.unciv.models.ruleset.unique.UniqueTarget
|
||||
import com.unciv.models.ruleset.unique.UniqueType
|
||||
import com.unciv.models.translations.squareBraceRegex
|
||||
@ -154,25 +155,21 @@ class Nation : RulesetObject() {
|
||||
|
||||
var showResources = false
|
||||
|
||||
val friendBonus = cityStateType.friendBonusUniqueMap
|
||||
if (friendBonus.isNotEmpty()) {
|
||||
fun addBonusLines(header: String, uniqueMap: UniqueMap) {
|
||||
// Note: Using getCityStateBonuses would be nice, but it's bound to a CityStateFunctions instance without even using `this`.
|
||||
// Too convoluted to reuse that here - but feel free to refactor that into a static.
|
||||
val boni = uniqueMap.getAllUniques().filterNot { it.isHiddenToUsers() }
|
||||
if (boni.none()) return
|
||||
textList += FormattedLine()
|
||||
textList += FormattedLine("{When Friends:} ")
|
||||
friendBonus.getAllUniques().forEach {
|
||||
textList += FormattedLine(it, indent = 1)
|
||||
if (it.text == "Provides a unique luxury") showResources = true
|
||||
textList += FormattedLine("{$header:} ")
|
||||
for (unique in boni) {
|
||||
textList += FormattedLine(unique, indent = 1)
|
||||
if (unique.isOfType(UniqueType.CityStateUniqueLuxury)) showResources = true
|
||||
}
|
||||
}
|
||||
|
||||
val allyBonus = cityStateType.allyBonusUniqueMap
|
||||
if (allyBonus.isNotEmpty()) {
|
||||
textList += FormattedLine()
|
||||
textList += FormattedLine("{When Allies:} ")
|
||||
allyBonus.getAllUniques().forEach {
|
||||
textList += FormattedLine(it, indent = 1)
|
||||
if (it.text == "Provides a unique luxury") showResources = true
|
||||
}
|
||||
}
|
||||
addBonusLines("When Friends:", cityStateType.friendBonusUniqueMap)
|
||||
addBonusLines("When Allies:", cityStateType.allyBonusUniqueMap)
|
||||
|
||||
if (showResources) {
|
||||
val allMercantileResources = ruleset.tileResources.values
|
||||
|
@ -167,14 +167,6 @@ class CityStateDiplomacyTable(private val diplomacyScreen: DiplomacyScreen) {
|
||||
}
|
||||
diplomacyTable.row().padTop(15f)
|
||||
|
||||
var friendBonusText = "When Friends:".tr()+"\n"
|
||||
val friendBonusObjects = viewingCiv.cityStateFunctions.getCityStateBonuses(otherCiv.cityStateType, RelationshipLevel.Friend)
|
||||
friendBonusText += friendBonusObjects.joinToString(separator = "\n") { it.text.tr() }
|
||||
|
||||
var allyBonusText = "When Allies:".tr()+"\n"
|
||||
val allyBonusObjects = viewingCiv.cityStateFunctions.getCityStateBonuses(otherCiv.cityStateType, RelationshipLevel.Ally)
|
||||
allyBonusText += allyBonusObjects.joinToString(separator = "\n") { it.text.tr() }
|
||||
|
||||
val relationLevel = otherCivDiplomacyManager.relationshipIgnoreAfraid()
|
||||
if (relationLevel >= RelationshipLevel.Friend) {
|
||||
// RelationshipChange = Ally -> Friend or Friend -> Favorable
|
||||
@ -184,15 +176,21 @@ class CityStateDiplomacyTable(private val diplomacyScreen: DiplomacyScreen) {
|
||||
.row()
|
||||
}
|
||||
|
||||
val friendBonusLabelColor = if (relationLevel == RelationshipLevel.Friend) Color.GREEN else Color.GRAY
|
||||
val friendBonusLabel = ColorMarkupLabel(friendBonusText, friendBonusLabelColor)
|
||||
.apply { setAlignment(Align.center) }
|
||||
diplomacyTable.add(friendBonusLabel).row()
|
||||
|
||||
val allyBonusLabelColor = if (relationLevel == RelationshipLevel.Ally) Color.GREEN else Color.GRAY
|
||||
val allyBonusLabel = ColorMarkupLabel(allyBonusText, allyBonusLabelColor)
|
||||
.apply { setAlignment(Align.center) }
|
||||
diplomacyTable.add(allyBonusLabel).row()
|
||||
fun getBonusText(header: String, level: RelationshipLevel): String {
|
||||
val boni = viewingCiv.cityStateFunctions
|
||||
.getCityStateBonuses(otherCiv.cityStateType, level)
|
||||
.filterNot { it.isHiddenToUsers() }
|
||||
if (boni.none()) return ""
|
||||
return (sequenceOf(header) + boni.map { it.text }).joinToString(separator = "\n") { it.tr() }
|
||||
}
|
||||
fun addBonusLabel(header: String, bonusLevel: RelationshipLevel, relationLevel: RelationshipLevel) {
|
||||
val bonusLabelColor = if (relationLevel == bonusLevel) Color.GREEN else Color.GRAY
|
||||
val bonusLabel = ColorMarkupLabel(getBonusText(header, bonusLevel), bonusLabelColor)
|
||||
.apply { setAlignment(Align.center) }
|
||||
diplomacyTable.add(bonusLabel).row()
|
||||
}
|
||||
addBonusLabel("When Friends:", RelationshipLevel.Friend, relationLevel)
|
||||
addBonusLabel("When Allies:", RelationshipLevel.Ally, relationLevel)
|
||||
|
||||
if (otherCiv.cityStateUniqueUnit != null) {
|
||||
val unitName = otherCiv.cityStateUniqueUnit
|
||||
|
Reference in New Issue
Block a user