mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-08 23:08:35 +07:00
Improve diplomatic vote result screen (#11386)
* Fix wrong winner displayed for UN vote results * Display number of received votes in DiplomaticVoteResultScreen
This commit is contained in:
@ -81,13 +81,14 @@ class VictoryManager : IsPartOfGameInfoSerialization {
|
|||||||
return (results.none { it != bestCiv && it.value == bestCiv.value })
|
return (results.none { it != bestCiv && it.value == bestCiv.value })
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getDiplomaticVictoryVoteBreakdown(): String {
|
data class DiplomaticVictoryVoteBreakdown(val results: Counter<String>, val winnerText: String)
|
||||||
|
fun getDiplomaticVictoryVoteBreakdown(): DiplomaticVictoryVoteBreakdown {
|
||||||
val results = calculateDiplomaticVotingResults(civInfo.gameInfo.diplomaticVictoryVotesCast)
|
val results = calculateDiplomaticVotingResults(civInfo.gameInfo.diplomaticVictoryVotesCast)
|
||||||
val (voteCount, winnerList) = results.asSequence()
|
val (voteCount, winnerList) = results.asSequence()
|
||||||
.groupBy({ it.value }, { it.key }).asSequence()
|
.groupBy({ it.value }, { it.key }).asSequence()
|
||||||
.sortedByDescending { it.key } // key is vote count here
|
.sortedByDescending { it.key } // key is vote count here
|
||||||
.firstOrNull()
|
.firstOrNull()
|
||||||
?: return "No valid votes were cast."
|
?: return DiplomaticVictoryVoteBreakdown(results, "No valid votes were cast.")
|
||||||
|
|
||||||
val lines = arrayListOf<String>()
|
val lines = arrayListOf<String>()
|
||||||
val minVotes = votesNeededForDiplomaticVictory()
|
val minVotes = votesNeededForDiplomaticVictory()
|
||||||
@ -99,9 +100,9 @@ class VictoryManager : IsPartOfGameInfoSerialization {
|
|||||||
lines += when {
|
lines += when {
|
||||||
lines.isNotEmpty() -> "No world leader was elected."
|
lines.isNotEmpty() -> "No world leader was elected."
|
||||||
winnerCiv == civInfo -> "You have been elected world leader!"
|
winnerCiv == civInfo -> "You have been elected world leader!"
|
||||||
else -> "${civInfo.nation.getLeaderDisplayName()} has been elected world leader!"
|
else -> "${winnerCiv.nation.getLeaderDisplayName()} has been elected world leader!"
|
||||||
}
|
}
|
||||||
return lines.joinToString("\n") { "{$it}" }
|
return DiplomaticVictoryVoteBreakdown(results, lines.joinToString("\n") { "{$it}" })
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getVictoryTypeAchieved(): String? {
|
fun getVictoryTypeAchieved(): String? {
|
||||||
|
@ -22,17 +22,20 @@ class DiplomaticVoteResultScreen(
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
closeButton.remove()
|
closeButton.remove()
|
||||||
|
topTable.pad(10f)
|
||||||
|
topTable.defaults().space(15f)
|
||||||
|
|
||||||
val findUN = viewingCiv.victoryManager.getUNBuildingAndOwnerNames()
|
val findUN = viewingCiv.victoryManager.getUNBuildingAndOwnerNames()
|
||||||
constructionNameUN = findUN.first
|
constructionNameUN = findUN.first
|
||||||
civOwningUN = findUN.second
|
civOwningUN = findUN.second
|
||||||
|
|
||||||
val orderedCivs = gameInfo.getCivsSorted(civToSortFirst = viewingCiv)
|
val (results, winnerText) = viewingCiv.victoryManager.getDiplomaticVictoryVoteBreakdown()
|
||||||
for (civ in orderedCivs) addVote(civ)
|
|
||||||
|
val orderedCivs = gameInfo.getCivsSorted(civToSortFirst = viewingCiv)
|
||||||
|
for (civ in orderedCivs) addVote(civ, results[civ.civName])
|
||||||
|
|
||||||
val result = viewingCiv.victoryManager.getDiplomaticVictoryVoteBreakdown()
|
|
||||||
descriptionLabel.setAlignment(Align.center)
|
descriptionLabel.setAlignment(Align.center)
|
||||||
descriptionLabel.setText(result.tr())
|
descriptionLabel.setText(winnerText.tr())
|
||||||
|
|
||||||
rightSideButton.onActivation(UncivSound.Click) {
|
rightSideButton.onActivation(UncivSound.Click) {
|
||||||
viewingCiv.addFlag(CivFlags.ShowDiplomaticVotingResults.name, -1)
|
viewingCiv.addFlag(CivFlags.ShowDiplomaticVotingResults.name, -1)
|
||||||
@ -45,15 +48,16 @@ class DiplomaticVoteResultScreen(
|
|||||||
bottomTable.cells[0].minWidth(rightSideButton.prefWidth + 20f) // center descriptionLabel
|
bottomTable.cells[0].minWidth(rightSideButton.prefWidth + 20f) // center descriptionLabel
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addVote(civ: Civilization) {
|
private fun addVote(civ: Civilization, votesReceived: Int) {
|
||||||
val civName = civ.civName
|
val civName = civ.civName
|
||||||
|
|
||||||
topTable.add(ImageGetter.getNationPortrait(civ.nation, 30f)).pad(10f)
|
if (civ.isMajorCiv()) topTable.add(votesReceived.toLabel()) else topTable.add()
|
||||||
topTable.add(civName.toLabel(hideIcons = true)).pad(20f)
|
|
||||||
|
topTable.add(ImageGetter.getNationPortrait(civ.nation, 30f))
|
||||||
|
topTable.add(civName.toLabel(hideIcons = true)).padLeft(20f).padRight(20f)
|
||||||
|
|
||||||
if (civName == civOwningUN && constructionNameUN != null) {
|
if (civName == civOwningUN && constructionNameUN != null) {
|
||||||
topTable.add(ImageGetter.getConstructionPortrait(constructionNameUN, 30f))
|
topTable.add(ImageGetter.getConstructionPortrait(constructionNameUN, 30f))
|
||||||
.pad(10f)
|
|
||||||
topTable.add("[2] votes".toLabel())
|
topTable.add("[2] votes".toLabel())
|
||||||
} else {
|
} else {
|
||||||
topTable.add("[1] vote".toLabel()).colspan(2)
|
topTable.add("[1] vote".toLabel()).colspan(2)
|
||||||
@ -66,8 +70,8 @@ class DiplomaticVoteResultScreen(
|
|||||||
val votedCiv = gameInfo.getCivilization(votedCivName)
|
val votedCiv = gameInfo.getCivilization(votedCivName)
|
||||||
if (votedCiv.isDefeated()) return abstained()
|
if (votedCiv.isDefeated()) return abstained()
|
||||||
|
|
||||||
topTable.add("Voted for".toLabel()).pad(20f).padRight(0f)
|
topTable.add("Voted for".toLabel()).padLeft(20f)
|
||||||
topTable.add(ImageGetter.getNationPortrait(votedCiv.nation, 30f)).pad(10f)
|
topTable.add(ImageGetter.getNationPortrait(votedCiv.nation, 30f))
|
||||||
topTable.add(votedCiv.civName.toLabel(hideIcons = true))
|
topTable.add(votedCiv.civName.toLabel(hideIcons = true))
|
||||||
topTable.row()
|
topTable.row()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user