Politics overview no longer discloses random number of players (#9466)

* Linting

* Hide player count in politics overview diagram legend if randomized

* Comment on getKnownCivs
This commit is contained in:
SomeTroglodyte
2023-05-31 13:52:05 +02:00
committed by GitHub
parent 2c1d413b6c
commit de09eda043
4 changed files with 38 additions and 20 deletions

View File

@ -313,7 +313,12 @@ class Civilization : IsPartOfGameInfoSerialization {
@Suppress("MemberVisibilityCanBePrivate") // same visibility for overloads @Suppress("MemberVisibilityCanBePrivate") // same visibility for overloads
fun getProximity(civName: String) = proximity[civName] ?: Proximity.None fun getProximity(civName: String) = proximity[civName] ?: Proximity.None
/** Returns only undefeated civs, aka the ones we care about */ /** Returns only undefeated civs, aka the ones we care about
*
* Note: Currently the implementation of `updateAllyCivForCityState` will cause the diplomacy map of
* city-states to contain the barbarians. Therefore, [getKnownCivs] will **not** list the barbarians
* for major civs, but **will** do so for city-states after some gameplay.
*/
fun getKnownCivs() = diplomacy.values.asSequence().map { it.otherCiv() }.filter { !it.isDefeated() } fun getKnownCivs() = diplomacy.values.asSequence().map { it.otherCiv() }.filter { !it.isDefeated() }
fun knows(otherCivName: String) = diplomacy.containsKey(otherCivName) fun knows(otherCivName: String) = diplomacy.containsKey(otherCivName)
fun knows(otherCiv: Civilization) = knows(otherCiv.civName) fun knows(otherCiv: Civilization) = knows(otherCiv.civName)

View File

@ -13,7 +13,7 @@ import com.unciv.models.stats.Stat
import com.unciv.models.stats.Stats import com.unciv.models.stats.Stats
import com.unciv.models.translations.tr import com.unciv.models.translations.tr
class DiplomacyFunctions(val civInfo:Civilization){ class DiplomacyFunctions(val civInfo: Civilization){
/** A sorted Sequence of all other civs we know (excluding barbarians and spectators) */ /** A sorted Sequence of all other civs we know (excluding barbarians and spectators) */
fun getKnownCivsSorted(includeCityStates: Boolean = true, includeDefeated: Boolean = false) = fun getKnownCivsSorted(includeCityStates: Boolean = true, includeDefeated: Boolean = false) =
@ -59,7 +59,7 @@ class DiplomacyFunctions(val civInfo:Civilization){
// For now, it might be overkill though. // For now, it might be overkill though.
var meetString = "[${civInfo.civName}] has given us [${giftAmount}] as a token of goodwill for meeting us" var meetString = "[${civInfo.civName}] has given us [${giftAmount}] as a token of goodwill for meeting us"
val religionMeetString = "[${civInfo.civName}] has also given us [${faithAmount}]" val religionMeetString = "[${civInfo.civName}] has also given us [${faithAmount}]"
if (civInfo.diplomacy.filter { it.value.otherCiv().isMajorCiv() }.size == 1) { if (civInfo.diplomacy.count { it.value.otherCiv().isMajorCiv() } == 1) {
giftAmount.timesInPlace(2f) giftAmount.timesInPlace(2f)
meetString = "[${civInfo.civName}] has given us [${giftAmount}] as we are the first major civ to meet them" meetString = "[${civInfo.civName}] has given us [${giftAmount}] as we are the first major civ to meet them"
} }

View File

@ -44,6 +44,7 @@ enum class EmpireOverviewCategories(
Politics("OtherIcons/Politics", 'P', Align.top) { Politics("OtherIcons/Politics", 'P', Align.top) {
override fun createTab(viewingPlayer: Civilization, overviewScreen: EmpireOverviewScreen, persistedData: EmpireOverviewTabPersistableData?) = override fun createTab(viewingPlayer: Civilization, overviewScreen: EmpireOverviewScreen, persistedData: EmpireOverviewTabPersistableData?) =
GlobalPoliticsOverviewTable(viewingPlayer, overviewScreen, persistedData) GlobalPoliticsOverviewTable(viewingPlayer, overviewScreen, persistedData)
override fun showDisabled(viewingPlayer: Civilization) = viewingPlayer.diplomacy.isEmpty()
}, },
Resources("StatIcons/Happiness", 'R', Align.topLeft) { Resources("StatIcons/Happiness", 'R', Align.topLeft) {
override fun createTab(viewingPlayer: Civilization, overviewScreen: EmpireOverviewScreen, persistedData: EmpireOverviewTabPersistableData?) = override fun createTab(viewingPlayer: Civilization, overviewScreen: EmpireOverviewScreen, persistedData: EmpireOverviewTabPersistableData?) =

View File

@ -15,6 +15,7 @@ import com.unciv.logic.civilization.diplomacy.DiplomaticStatus
import com.unciv.logic.civilization.diplomacy.RelationshipLevel import com.unciv.logic.civilization.diplomacy.RelationshipLevel
import com.unciv.logic.map.HexMath import com.unciv.logic.map.HexMath
import com.unciv.models.ruleset.Policy.PolicyBranchType import com.unciv.models.ruleset.Policy.PolicyBranchType
import com.unciv.models.ruleset.unique.UniqueType
import com.unciv.ui.components.AutoScrollPane import com.unciv.ui.components.AutoScrollPane
import com.unciv.ui.components.ColorMarkupLabel import com.unciv.ui.components.ColorMarkupLabel
import com.unciv.ui.components.Fonts import com.unciv.ui.components.Fonts
@ -38,9 +39,10 @@ class GlobalPoliticsOverviewTable (
) : EmpireOverviewTab(viewingPlayer, overviewScreen) { ) : EmpireOverviewTab(viewingPlayer, overviewScreen) {
class DiplomacyTabPersistableData( class DiplomacyTabPersistableData(
var showDiagram: Boolean = false,
var includeCityStates: Boolean = false var includeCityStates: Boolean = false
) : EmpireOverviewTabPersistableData() { ) : EmpireOverviewTabPersistableData() {
override fun isEmpty() = !includeCityStates override fun isEmpty() = !showDiagram && !includeCityStates
} }
override val persistableData = (persistedData as? DiplomacyTabPersistableData) ?: DiplomacyTabPersistableData() override val persistableData = (persistedData as? DiplomacyTabPersistableData) ?: DiplomacyTabPersistableData()
@ -58,18 +60,20 @@ class GlobalPoliticsOverviewTable (
private var undefeatedCivs = sequenceOf<Civilization>() private var undefeatedCivs = sequenceOf<Civilization>()
private var defeatedCivs = sequenceOf<Civilization>() private var defeatedCivs = sequenceOf<Civilization>()
private var relevantCivsCount = 0 // includes unknown civs private var relevantCivsCount = "?" // includes unknown civs if player allowed to know
private var showDiplomacyGroup = false private var showDiplomacyGroup = false
private var portraitMode = false private var portraitMode = false
init { init {
updatePoliticsTable() if (persistableData.showDiagram) updateDiagram()
else updatePoliticsTable()
} }
private fun updatePoliticsTable() { private fun updatePoliticsTable() {
persistableData.showDiagram = false
clear() clear()
getFixedContent().clear() fixedContent.clear()
val diagramButton = "Show diagram".toTextButton().onClick(::updateDiagram) val diagramButton = "Show diagram".toTextButton().onClick(::updateDiagram)
@ -85,18 +89,14 @@ class GlobalPoliticsOverviewTable (
add("Relations".toLabel()).row() add("Relations".toLabel()).row()
add(diagramButton).pad(10f) add(diagramButton).pad(10f)
}) })
row()
addSeparator(Color.GRAY)
createGlobalPoliticsTable() createGlobalPoliticsTable()
} }
private fun createGlobalPoliticsTable() { private fun createGlobalPoliticsTable() {
val civilizations = mutableListOf<Civilization>() for (civ in viewingPlayer.diplomacyFunctions.getKnownCivsSorted(includeCityStates = false)) {
civilizations.add(viewingPlayer) addSeparator(Color.GRAY)
civilizations.addAll(viewingPlayer.getKnownCivs())
civilizations.removeAll(civilizations.filter { it.isBarbarian() || it.isCityState() || it.isSpectator() })
for (civ in civilizations) {
// civ image // civ image
add(ImageGetter.getNationPortrait(civ.nation, 100f)).pad(20f) add(ImageGetter.getNationPortrait(civ.nation, 100f)).pad(20f)
@ -119,9 +119,6 @@ class GlobalPoliticsOverviewTable (
//politics //politics
add(getPoliticsOfCivTable(civ)).pad(20f) add(getPoliticsOfCivTable(civ)).pad(20f)
if (civilizations.indexOf(civ) != civilizations.lastIndex)
addSeparator(Color.GRAY)
} }
} }
@ -227,6 +224,7 @@ class GlobalPoliticsOverviewTable (
// Refresh content and determine landscape/portrait layout // Refresh content and determine landscape/portrait layout
private fun updateDiagram() { private fun updateDiagram() {
persistableData.showDiagram = true
val politicsButton = "Show global politics".toTextButton().onClick(::updatePoliticsTable) val politicsButton = "Show global politics".toTextButton().onClick(::updatePoliticsTable)
val toggleCityStatesButton: TextButton = Constants.cityStates.toTextButton().apply { val toggleCityStatesButton: TextButton = Constants.cityStates.toTextButton().apply {
@ -245,9 +243,12 @@ class GlobalPoliticsOverviewTable (
add(civTableScroll.addBorder(2f, Color.WHITE)).pad(10f) add(civTableScroll.addBorder(2f, Color.WHITE)).pad(10f)
} }
relevantCivsCount = gameInfo.civilizations.count { val hideCivsCount = viewingPlayer.hideCivCount() ||
!it.isSpectator() && !it.isBarbarian() && (persistableData.includeCityStates || !it.isCityState()) persistableData.includeCityStates && viewingPlayer.hideCityStateCount()
} relevantCivsCount = if (hideCivsCount) "?"
else gameInfo.civilizations.count {
!it.isSpectator() && !it.isBarbarian() && (persistableData.includeCityStates || !it.isCityState())
}.toString()
undefeatedCivs = sequenceOf(viewingPlayer) + undefeatedCivs = sequenceOf(viewingPlayer) +
viewingPlayer.diplomacyFunctions.getKnownCivsSorted(persistableData.includeCityStates) viewingPlayer.diplomacyFunctions.getKnownCivsSorted(persistableData.includeCityStates)
defeatedCivs = viewingPlayer.diplomacyFunctions.getKnownCivsSorted(persistableData.includeCityStates, true) defeatedCivs = viewingPlayer.diplomacyFunctions.getKnownCivsSorted(persistableData.includeCityStates, true)
@ -289,6 +290,15 @@ class GlobalPoliticsOverviewTable (
civTableScroll.setScrollingDisabled(portraitMode, portraitMode) civTableScroll.setScrollingDisabled(portraitMode, portraitMode)
} }
/** Same as [Civilization.hideCivCount] but for City-States instead of Major Civs */
private fun Civilization.hideCityStateCount(): Boolean {
if (!gameInfo.gameParameters.randomNumberOfCityStates) return false
val knownCivs = 1 + getKnownCivs().count { it.isCityState() }
if (knownCivs >= gameInfo.gameParameters.maxNumberOfCityStates) return false
if (hasUnique(UniqueType.OneTimeRevealEntireMap)) return false
return true
}
private fun updateCivTable(columns: Int) = civTable.apply { private fun updateCivTable(columns: Int) = civTable.apply {
clear() clear()
addTitleInfo(columns) addTitleInfo(columns)
@ -325,6 +335,7 @@ class GlobalPoliticsOverviewTable (
.pad(5f).colspan(columns).row() .pad(5f).colspan(columns).row()
if (count == 0) return if (count == 0) return
addSeparator() addSeparator()
var currentColumn = 0 var currentColumn = 0
var lastCivWasMajor = false var lastCivWasMajor = false
fun advanceCols(delta: Int) { fun advanceCols(delta: Int) {
@ -335,6 +346,7 @@ class GlobalPoliticsOverviewTable (
} }
lastCivWasMajor = delta == 2 lastCivWasMajor = delta == 2
} }
for (civ in civs) { for (civ in civs) {
if (lastCivWasMajor && civ.isCityState()) if (lastCivWasMajor && civ.isCityState())
advanceCols(columns) advanceCols(columns)