From 9371ff5035b557832ad8a837c90eafab234e232c Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Mon, 20 Feb 2023 18:37:48 +0200 Subject: [PATCH] Cleanup of policy screen --- .../cityscreen/ConstructionInfoTable.kt | 11 ++-- .../pickerscreens/PolicyPickerScreen.kt | 61 ++++++++----------- .../worldscreen/TechPolicyDiplomacyButtons.kt | 4 +- .../ui/screens/worldscreen/WorldScreen.kt | 6 +- .../screens/worldscreen/WorldScreenTopBar.kt | 18 +++--- .../worldscreen/status/NextTurnButton.kt | 25 ++++---- 6 files changed, 57 insertions(+), 68 deletions(-) diff --git a/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt b/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt index 24566c933f..c8ed665be8 100644 --- a/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt +++ b/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt @@ -14,16 +14,16 @@ import com.unciv.models.ruleset.Building import com.unciv.models.ruleset.IRulesetObject import com.unciv.models.ruleset.unit.BaseUnit import com.unciv.models.translations.tr -import com.unciv.ui.screens.civilopediascreen.CivilopediaScreen -import com.unciv.ui.images.ImageGetter -import com.unciv.ui.popups.ConfirmPopup -import com.unciv.ui.popups.closeAllPopups -import com.unciv.ui.screens.basescreen.BaseScreen import com.unciv.ui.components.Fonts import com.unciv.ui.components.extensions.darken import com.unciv.ui.components.extensions.disable import com.unciv.ui.components.extensions.onClick import com.unciv.ui.components.extensions.toTextButton +import com.unciv.ui.images.ImageGetter +import com.unciv.ui.popups.ConfirmPopup +import com.unciv.ui.popups.closeAllPopups +import com.unciv.ui.screens.basescreen.BaseScreen +import com.unciv.ui.screens.civilopediascreen.CivilopediaScreen class ConstructionInfoTable(val cityScreen: CityScreen): Table() { private val selectedConstructionTable = Table() @@ -117,6 +117,7 @@ class ConstructionInfoTable(val cityScreen: CityScreen): Table() { cityScreen.update() }.open() } + if (cityScreen.city.hasSoldBuildingThisTurn && !cityScreen.city.civ.gameInfo.gameParameters.godMode || cityScreen.city.isPuppet || !GUI.isMyTurn() || !GUI.isAllowedChangeState()) diff --git a/core/src/com/unciv/ui/screens/pickerscreens/PolicyPickerScreen.kt b/core/src/com/unciv/ui/screens/pickerscreens/PolicyPickerScreen.kt index 25e509d0f6..be9d547f82 100644 --- a/core/src/com/unciv/ui/screens/pickerscreens/PolicyPickerScreen.kt +++ b/core/src/com/unciv/ui/screens/pickerscreens/PolicyPickerScreen.kt @@ -8,7 +8,6 @@ import com.badlogic.gdx.scenes.scene2d.ui.Cell import com.badlogic.gdx.scenes.scene2d.ui.Image import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.utils.Align -import com.unciv.GUI import com.unciv.logic.civilization.Civilization import com.unciv.models.TutorialTrigger import com.unciv.models.UncivSound @@ -34,7 +33,6 @@ import com.unciv.ui.images.ImageGetter import com.unciv.ui.popups.ConfirmPopup import com.unciv.ui.screens.basescreen.BaseScreen import com.unciv.ui.screens.basescreen.RecreateOnResize -import com.unciv.ui.screens.worldscreen.WorldScreen import java.lang.Integer.max import kotlin.math.abs import kotlin.math.min @@ -50,8 +48,9 @@ private object PolicyColors { val branchAdopted = colorFromRGB(100, 90, 10).darken(0.5f) } -fun Policy.isPickable(viewingCiv: Civilization) : Boolean { +fun Policy.isPickable(viewingCiv: Civilization, canChangeState: Boolean) : Boolean { if (!viewingCiv.isCurrentPlayer() + || !canChangeState || viewingCiv.isDefeated() || viewingCiv.policies.isAdopted(this.name) || this.policyBranchType == PolicyBranchType.BranchComplete @@ -62,7 +61,7 @@ fun Policy.isPickable(viewingCiv: Civilization) : Boolean { return true } -class PolicyButton(val viewingCiv: Civilization, val policy: Policy, size: Float = 30f) : BorderedTable( +class PolicyButton(viewingCiv: Civilization, canChangeState: Boolean, val policy: Policy, size: Float = 30f) : BorderedTable( path = "PolicyScreen/PolicyButton", defaultBgBorder = BaseScreen.skinStrings.roundedEdgeRectangleSmallShape, defaultBgShape = BaseScreen.skinStrings.roundedEdgeRectangleSmallShape, @@ -70,6 +69,9 @@ class PolicyButton(val viewingCiv: Civilization, val policy: Policy, size: Float val icon = ImageGetter.getImage("PolicyIcons/" + policy.name) + val isPickable = policy.isPickable(viewingCiv, canChangeState) + val isAdopted = viewingCiv.policies.isAdopted(policy.name) + var isSelected = false set(value) { field = value @@ -77,7 +79,6 @@ class PolicyButton(val viewingCiv: Civilization, val policy: Policy, size: Float } init { - borderSize = 2f icon.setSize(size*0.7f, size*0.7f) @@ -102,11 +103,7 @@ class PolicyButton(val viewingCiv: Civilization, val policy: Policy, size: Float private fun updateState() { - val isPickable = policy.isPickable(viewingCiv) - val isAdopted = GUI.getSelectedPlayer().policies.isAdopted(policy.name) - when { - isSelected && isPickable -> { bgColor = PolicyColors.policySelected } @@ -124,15 +121,12 @@ class PolicyButton(val viewingCiv: Civilization, val policy: Policy, size: Float icon.color.a = 0.2f bgColor = PolicyColors.policyNotPickable } - } - } - } -class PolicyPickerScreen(val worldScreen: WorldScreen, val viewingCiv: Civilization = worldScreen.selectedCiv) +class PolicyPickerScreen(val viewingCiv: Civilization, val canChangeState: Boolean) : PickerScreen(), RecreateOnResize { object Sizes { @@ -168,7 +162,7 @@ class PolicyPickerScreen(val worldScreen: WorldScreen, val viewingCiv: Civilizat confirmAction() } - if (!worldScreen.canChangeState) + if (!canChangeState) rightSideButton.disable() topTable.row() @@ -230,7 +224,7 @@ class PolicyPickerScreen(val worldScreen: WorldScreen, val viewingCiv: Civilizat val policy = button.policy rightSideButton.isVisible = !viewingCiv.policies.isAdopted(policy.name) - if (!policy.isPickable(viewingCiv)) { + if (!policy.isPickable(viewingCiv, canChangeState)) { rightSideButton.disable() } else { rightSideButton.enable() @@ -540,7 +534,7 @@ class PolicyPickerScreen(val worldScreen: WorldScreen, val viewingCiv: Civilizat private fun getTopButton(branch: PolicyBranch): Table { val text: String - val isPickable = branch.isPickable(viewingCiv) + val isPickable = branch.isPickable(viewingCiv, canChangeState) var isAdoptedBranch = false var percentage = 0f @@ -616,18 +610,13 @@ class PolicyPickerScreen(val worldScreen: WorldScreen, val viewingCiv: Civilizat lockIcon.setPosition(table.width, table.height / 2 - lockIcon.height/2) table.onClick { - if (branch.isPickable(viewingCiv)) + if (branch.isPickable(viewingCiv, canChangeState)) ConfirmPopup( this, "Are you sure you want to adopt [${branch.name}]?", "Adopt", true, action = { viewingCiv.policies.adopt(branch, false) - - val policyScreen = PolicyPickerScreen(worldScreen) - policyScreen.scrollPane.scrollPercentX = scrollPane.scrollPercentX - policyScreen.scrollPane.scrollPercentY = scrollPane.scrollPercentY - policyScreen.scrollPane.updateVisualScroll() - game.replaceCurrentScreen(policyScreen) + game.replaceCurrentScreen(recreate()) } ).open(force = true) } @@ -636,9 +625,9 @@ class PolicyPickerScreen(val worldScreen: WorldScreen, val viewingCiv: Civilizat } private fun getPolicyButton(policy: Policy, size: Float = 30f): PolicyButton { - val button = PolicyButton(viewingCiv, policy, size = size) + val button = PolicyButton(viewingCiv, canChangeState, policy, size = size) button.onClick { pickPolicy(button = button) } - if (policy.isPickable(viewingCiv)) + if (policy.isPickable(viewingCiv, canChangeState)) button.onDoubleClick(UncivSound.Policy) { confirmAction() } return button } @@ -647,21 +636,21 @@ class PolicyPickerScreen(val worldScreen: WorldScreen, val viewingCiv: Civilizat val policy = selectedPolicyButton!!.policy // Evil people clicking on buttons too fast to confuse the screen - #4977 - if (!policy.isPickable(viewingCiv)) return + if (!policy.isPickable(viewingCiv, canChangeState)) return viewingCiv.policies.adopt(policy) // If we've moved to another screen in the meantime (great person pick, victory screen) ignore this - if (game.screen !is PolicyPickerScreen) { - game.popScreen() - } else { - val policyScreen = PolicyPickerScreen(worldScreen) - policyScreen.scrollPane.scrollPercentX = scrollPane.scrollPercentX - policyScreen.scrollPane.scrollPercentY = scrollPane.scrollPercentY - policyScreen.scrollPane.updateVisualScroll() - game.replaceCurrentScreen(policyScreen) // update policies - } + // update policies + if (game.screen !is PolicyPickerScreen) game.popScreen() + else game.replaceCurrentScreen(recreate()) } - override fun recreate(): BaseScreen = PolicyPickerScreen(worldScreen, viewingCiv) + override fun recreate(): BaseScreen { + val newScreen = PolicyPickerScreen(viewingCiv, canChangeState) + newScreen.scrollPane.scrollPercentX = scrollPane.scrollPercentX + newScreen.scrollPane.scrollPercentY = scrollPane.scrollPercentY + newScreen.scrollPane.updateVisualScroll() + return newScreen + } } diff --git a/core/src/com/unciv/ui/screens/worldscreen/TechPolicyDiplomacyButtons.kt b/core/src/com/unciv/ui/screens/worldscreen/TechPolicyDiplomacyButtons.kt index d388b6a80f..7bed981297 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/TechPolicyDiplomacyButtons.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/TechPolicyDiplomacyButtons.kt @@ -7,12 +7,12 @@ import com.badlogic.gdx.scenes.scene2d.ui.Container import com.badlogic.gdx.scenes.scene2d.ui.Table import com.unciv.models.UncivSound import com.unciv.models.translations.tr -import com.unciv.ui.screens.basescreen.BaseScreen import com.unciv.ui.components.Fonts import com.unciv.ui.components.extensions.colorFromRGB import com.unciv.ui.components.extensions.onClick import com.unciv.ui.components.extensions.toLabel import com.unciv.ui.images.ImageGetter +import com.unciv.ui.screens.basescreen.BaseScreen import com.unciv.ui.screens.diplomacyscreen.DiplomacyScreen import com.unciv.ui.screens.overviewscreen.EspionageOverviewScreen import com.unciv.ui.screens.pickerscreens.PolicyPickerScreen @@ -66,7 +66,7 @@ class TechPolicyDiplomacyButtons(val worldScreen: WorldScreen) : Table(BaseScree policyScreenButton.add(ImageGetter.getImage("PolicyIcons/Constitution")).size(30f).pad(15f) policyButtonHolder.onClick { - game.pushScreen(PolicyPickerScreen(worldScreen)) + game.pushScreen(PolicyPickerScreen(worldScreen.selectedCiv, worldScreen.canChangeState)) } diplomacyButton.add(ImageGetter.getImage("OtherIcons/DiplomacyW")).size(30f).pad(15f) diff --git a/core/src/com/unciv/ui/screens/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/screens/worldscreen/WorldScreen.kt index 3583f160f2..09ec8c0e2e 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/WorldScreen.kt @@ -124,7 +124,7 @@ class WorldScreen( private val events = EventBus.EventReceiver() - var uiEnabled = true + private var uiEnabled = true var preActionGameInfo = gameInfo @@ -228,7 +228,7 @@ class WorldScreen( globalShortcuts.add(Input.Keys.F2) { game.pushScreen(EmpireOverviewScreen(selectedCiv, "Trades")) } // Economic info globalShortcuts.add(Input.Keys.F3) { game.pushScreen(EmpireOverviewScreen(selectedCiv, "Units")) } // Military info globalShortcuts.add(Input.Keys.F4) { game.pushScreen(EmpireOverviewScreen(selectedCiv, "Politics")) } // Diplomacy info - globalShortcuts.add(Input.Keys.F5) { game.pushScreen(PolicyPickerScreen(this, selectedCiv)) } // Social Policies Screen + globalShortcuts.add(Input.Keys.F5) { game.pushScreen(PolicyPickerScreen(selectedCiv, canChangeState)) } // Social Policies Screen globalShortcuts.add(Input.Keys.F6) { game.pushScreen(TechPickerScreen(viewingCiv)) } // Tech Screen globalShortcuts.add(Input.Keys.F7) { game.pushScreen(EmpireOverviewScreen(selectedCiv, "Cities")) } // originally Notification Log globalShortcuts.add(Input.Keys.F8) { game.pushScreen(VictoryScreen(this)) } // Victory Progress @@ -551,7 +551,7 @@ class WorldScreen( tutorialTaskTable.pack() tutorialTaskTable.centerX(stage) tutorialTaskTable.y = topBar.y - tutorialTaskTable.height - tutorialTaskTable.onClick() { + tutorialTaskTable.onClick { UncivGame.Current.isTutorialTaskCollapsed = !UncivGame.Current.isTutorialTaskCollapsed displayTutorialTaskOnUpdate() } diff --git a/core/src/com/unciv/ui/screens/worldscreen/WorldScreenTopBar.kt b/core/src/com/unciv/ui/screens/worldscreen/WorldScreenTopBar.kt index 147b46d3f0..c24623a766 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/WorldScreenTopBar.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/WorldScreenTopBar.kt @@ -14,14 +14,6 @@ import com.unciv.models.ruleset.tile.ResourceType import com.unciv.models.ruleset.tile.TileResource import com.unciv.models.stats.Stats import com.unciv.models.translations.tr -import com.unciv.ui.screens.civilopediascreen.CivilopediaCategories -import com.unciv.ui.screens.civilopediascreen.CivilopediaScreen -import com.unciv.ui.images.ImageGetter -import com.unciv.ui.screens.overviewscreen.EmpireOverviewScreen -import com.unciv.ui.screens.pickerscreens.PolicyPickerScreen -import com.unciv.ui.screens.pickerscreens.TechPickerScreen -import com.unciv.ui.popups.popups -import com.unciv.ui.screens.basescreen.BaseScreen import com.unciv.ui.components.Fonts import com.unciv.ui.components.MayaCalendar import com.unciv.ui.components.UncivTooltip.Companion.addTooltip @@ -32,6 +24,14 @@ import com.unciv.ui.components.extensions.setFontColor import com.unciv.ui.components.extensions.setFontSize import com.unciv.ui.components.extensions.toLabel import com.unciv.ui.components.extensions.toTextButton +import com.unciv.ui.images.ImageGetter +import com.unciv.ui.popups.popups +import com.unciv.ui.screens.basescreen.BaseScreen +import com.unciv.ui.screens.civilopediascreen.CivilopediaCategories +import com.unciv.ui.screens.civilopediascreen.CivilopediaScreen +import com.unciv.ui.screens.overviewscreen.EmpireOverviewScreen +import com.unciv.ui.screens.pickerscreens.PolicyPickerScreen +import com.unciv.ui.screens.pickerscreens.TechPickerScreen import com.unciv.ui.screens.victoryscreen.VictoryScreen import com.unciv.ui.screens.worldscreen.mainmenu.WorldScreenMenuPopup import kotlin.math.abs @@ -118,7 +118,7 @@ class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() { happinessImage.onClick(invokeResourcesPage) happinessLabel.onClick(invokeResourcesPage) - addStat(cultureLabel, "Culture") { PolicyPickerScreen(worldScreen, worldScreen.selectedCiv) } + addStat(cultureLabel, "Culture") { PolicyPickerScreen(worldScreen.selectedCiv, worldScreen.canChangeState) } if (worldScreen.gameInfo.isReligionEnabled()) { addStat(faithLabel, "Faith", "Religion", isLast = true) } else { diff --git a/core/src/com/unciv/ui/screens/worldscreen/status/NextTurnButton.kt b/core/src/com/unciv/ui/screens/worldscreen/status/NextTurnButton.kt index b1f82d36c3..57b8cd8d4e 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/status/NextTurnButton.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/status/NextTurnButton.kt @@ -6,16 +6,6 @@ import com.unciv.Constants import com.unciv.logic.civilization.managers.ReligionState import com.unciv.models.ruleset.BeliefType import com.unciv.models.translations.tr -import com.unciv.ui.screens.cityscreen.CityScreen -import com.unciv.ui.images.IconTextButton -import com.unciv.ui.images.ImageGetter -import com.unciv.ui.screens.pickerscreens.DiplomaticVotePickerScreen -import com.unciv.ui.screens.pickerscreens.PantheonPickerScreen -import com.unciv.ui.screens.pickerscreens.PolicyPickerScreen -import com.unciv.ui.screens.pickerscreens.ReligiousBeliefsPickerScreen -import com.unciv.ui.screens.pickerscreens.TechPickerScreen -import com.unciv.ui.popups.ConfirmPopup -import com.unciv.ui.popups.hasOpenPopups import com.unciv.ui.components.KeyCharAndCode import com.unciv.ui.components.KeyShortcut import com.unciv.ui.components.extensions.disable @@ -24,12 +14,21 @@ import com.unciv.ui.components.extensions.isEnabled import com.unciv.ui.components.extensions.keyShortcuts import com.unciv.ui.components.extensions.onActivation import com.unciv.ui.components.extensions.setSize +import com.unciv.ui.images.IconTextButton +import com.unciv.ui.images.ImageGetter +import com.unciv.ui.popups.ConfirmPopup +import com.unciv.ui.popups.hasOpenPopups +import com.unciv.ui.screens.cityscreen.CityScreen +import com.unciv.ui.screens.pickerscreens.DiplomaticVotePickerScreen +import com.unciv.ui.screens.pickerscreens.PantheonPickerScreen +import com.unciv.ui.screens.pickerscreens.PolicyPickerScreen +import com.unciv.ui.screens.pickerscreens.ReligiousBeliefsPickerScreen +import com.unciv.ui.screens.pickerscreens.TechPickerScreen import com.unciv.ui.screens.worldscreen.WorldScreen import com.unciv.utils.concurrency.Concurrency import com.unciv.utils.concurrency.launchOnGLThread -class NextTurnButton( -) : IconTextButton("", null, 30) { +class NextTurnButton : IconTextButton("", null, 30) { private var nextTurnAction = NextTurnAction("", Color.BLACK) {} init { @@ -94,7 +93,7 @@ class NextTurnButton( worldScreen.viewingCiv.policies.shouldOpenPolicyPicker || worldScreen.viewingCiv.policies.freePolicies > 0 && worldScreen.viewingCiv.policies.canAdoptPolicy() -> NextTurnAction("Pick a policy", Color.VIOLET, "NotificationIcons/PickPolicy") { - worldScreen.game.pushScreen(PolicyPickerScreen(worldScreen)) + worldScreen.game.pushScreen(PolicyPickerScreen(worldScreen.selectedCiv, worldScreen.canChangeState)) worldScreen.viewingCiv.policies.shouldOpenPolicyPicker = false }