From ea5f649d876f38f95fa05210a2b8d5a677f15631 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Thu, 13 Jun 2019 12:47:40 +0300 Subject: [PATCH] Added global victory status to victory status screen, so you can see how bad the AI is at actually winning... -_- --- core/src/com/unciv/ui/VictoryScreen.kt | 110 ++++++++++++++++++++++--- 1 file changed, 97 insertions(+), 13 deletions(-) diff --git a/core/src/com/unciv/ui/VictoryScreen.kt b/core/src/com/unciv/ui/VictoryScreen.kt index da9e33d994..cc88e761fa 100644 --- a/core/src/com/unciv/ui/VictoryScreen.kt +++ b/core/src/com/unciv/ui/VictoryScreen.kt @@ -4,30 +4,34 @@ import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.TextButton import com.unciv.UnCivGame +import com.unciv.logic.civilization.CivilizationInfo import com.unciv.models.gamebasics.GameBasics import com.unciv.models.gamebasics.tr import com.unciv.ui.pickerscreens.PickerScreen +import com.unciv.ui.utils.addSeparator import com.unciv.ui.utils.enable import com.unciv.ui.utils.onClick +import com.unciv.ui.utils.toLabel class VictoryScreen : PickerScreen() { val playerCivInfo = UnCivGame.Current.gameInfo.getCurrentPlayerCivilization() + val contentsTable = Table() + init { - topTable.skin=skin - topTable.defaults().pad(10f) - topTable.add("Science victory".tr()) - topTable.add("Cultural victory".tr()) - topTable.add("Conquest victory".tr()) - topTable.row() - topTable.add(scienceVictoryColumn()) - topTable.add(culturalVictoryColumn()) - topTable.add(conquestVictoryColumn()) - topTable.row() - topTable.add("Complete all the spaceship parts\n to win!".tr()) - topTable.add("Complete 4 policy branches\n to win!".tr()) - topTable.add("Destroy all enemies\n to win!".tr()) + val tabsTable = Table().apply { defaults().pad(10f) } + val setMyVictoryButton = TextButton("Our status",skin) + setMyVictoryButton.onClick { setMyVictoryTable() } + tabsTable.add(setMyVictoryButton) + val setGlobalVictoryButton = TextButton("Global status",skin) + setGlobalVictoryButton .onClick { setGlobalVictoryTable() } + tabsTable.add(setGlobalVictoryButton) + topTable.add(tabsTable) + topTable.addSeparator() + topTable.add(contentsTable) + + setMyVictoryTable() rightSideButton.isVisible=false @@ -44,6 +48,7 @@ class VictoryScreen : PickerScreen() { else setDefaultCloseAction() } + fun won(description: String) { descriptionLabel.setText(description.tr()) @@ -59,6 +64,26 @@ class VictoryScreen : PickerScreen() { } } + + fun setMyVictoryTable(){ + val myVictoryStatusTable = Table() + myVictoryStatusTable.defaults().pad(10f) + myVictoryStatusTable.add("Science victory".toLabel()) + myVictoryStatusTable.add("Cultural victory".toLabel()) + myVictoryStatusTable.add("Conquest victory".toLabel()) + myVictoryStatusTable.row() + myVictoryStatusTable.add(scienceVictoryColumn()) + myVictoryStatusTable.add(culturalVictoryColumn()) + myVictoryStatusTable.add(conquestVictoryColumn()) + myVictoryStatusTable.row() + myVictoryStatusTable.add("Complete all the spaceship parts\n to win!".toLabel()) + myVictoryStatusTable.add("Complete 4 policy branches\n to win!".toLabel()) + myVictoryStatusTable.add("Destroy all enemies\n to win!".toLabel()) + + contentsTable.clear() + contentsTable.add(myVictoryStatusTable) + } + fun scienceVictoryColumn():Table{ val t = Table() t.defaults().pad(5f) @@ -104,4 +129,63 @@ class VictoryScreen : PickerScreen() { } + private fun setGlobalVictoryTable() { + val majorCivs = game.gameInfo.civilizations.filter { it.isMajorCiv() } + val globalVictoryTable = Table().apply { defaults().pad(10f) } + + globalVictoryTable.add(getGlobalScientificVictoryColumn(majorCivs)) + globalVictoryTable.add(getGlobalPolicyVictoryColumn(majorCivs)) + globalVictoryTable.add(getGlobalDominationVictoryColumn(majorCivs)) + + contentsTable.clear() + contentsTable.add(globalVictoryTable) + } + + private fun getGlobalDominationVictoryColumn(majorCivs: List): Table { + val dominationVictoryColumn = Table().apply { defaults().pad(10f) } + + dominationVictoryColumn.add("Undefeated civs".toLabel()).row() + dominationVictoryColumn.addSeparator() + + for (civ in majorCivs.filter { !it.isDefeated() }) + dominationVictoryColumn.add(TextButton(civ.civName.tr(), skin).apply { color = Color.GREEN }).row() + + for (civ in majorCivs.filter { it.isDefeated() }) + dominationVictoryColumn.add(TextButton(civ.civName.tr(), skin).apply { color = Color.GRAY }).row() + return dominationVictoryColumn + } + + private fun getGlobalPolicyVictoryColumn(majorCivs: List): Table { + val policyVictoryColumn = Table().apply { defaults().pad(10f) } + policyVictoryColumn.add("Branches completed".toLabel()).row() + policyVictoryColumn.addSeparator() + + data class civToBranchesCompleted(val civ: CivilizationInfo, val branchesCompleted: Int) + + val civsToBranchesCompleted = + majorCivs.map { civToBranchesCompleted(it, it.policies.adoptedPolicies.count { pol -> pol.endsWith("Complete") }) } + .sortedByDescending { it.branchesCompleted } + + for (entry in civsToBranchesCompleted) + policyVictoryColumn.add(TextButton(entry.civ.civName.tr() + " - " + entry.branchesCompleted, skin)).row() + return policyVictoryColumn + } + + private fun getGlobalScientificVictoryColumn(majorCivs: List): Table { + val scientificVictoryColumn = Table().apply { defaults().pad(10f) } + scientificVictoryColumn.add("Spaceship parts remaining".toLabel()).row() + scientificVictoryColumn.addSeparator() + + data class civToSpaceshipPartsRemaining(val civ: CivilizationInfo, val partsRemaining: Int) + + val civsToPartsRemaining = majorCivs.map { + civToSpaceshipPartsRemaining(it, + it.victoryManager.requiredSpaceshipParts.size - it.victoryManager.currentsSpaceshipParts.size) + } + + for (entry in civsToPartsRemaining) + scientificVictoryColumn.add(TextButton(entry.civ.civName.tr() + " - " + entry.partsRemaining, skin)).row() + return scientificVictoryColumn + } + } \ No newline at end of file