From fe111edf30ed28059ce87e1c08e995bb557c66fc Mon Sep 17 00:00:00 2001 From: Oskar Niesen Date: Sun, 21 Jan 2024 11:13:46 -0600 Subject: [PATCH] Spectators can now see the diplomacy screen of the civ that they have selected (#10969) --- .../overviewscreen/EspionageOverviewScreen.kt | 8 ++++- .../worldscreen/TechPolicyDiplomacyButtons.kt | 31 +++++++++++++++++-- .../ui/screens/worldscreen/WorldScreen.kt | 22 ------------- 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/core/src/com/unciv/ui/screens/overviewscreen/EspionageOverviewScreen.kt b/core/src/com/unciv/ui/screens/overviewscreen/EspionageOverviewScreen.kt index 88d968e312..47f0f3d431 100644 --- a/core/src/com/unciv/ui/screens/overviewscreen/EspionageOverviewScreen.kt +++ b/core/src/com/unciv/ui/screens/overviewscreen/EspionageOverviewScreen.kt @@ -13,6 +13,7 @@ import com.unciv.models.Spy import com.unciv.models.SpyAction import com.unciv.models.translations.tr import com.unciv.ui.components.extensions.addSeparatorVertical +import com.unciv.ui.components.extensions.disable import com.unciv.ui.components.extensions.setSize import com.unciv.ui.components.extensions.toLabel import com.unciv.ui.components.extensions.toTextButton @@ -24,9 +25,10 @@ import com.unciv.ui.components.input.onClick import com.unciv.ui.components.widgets.AutoScrollPane import com.unciv.ui.images.ImageGetter import com.unciv.ui.screens.pickerscreens.PickerScreen +import com.unciv.ui.screens.worldscreen.WorldScreen /** Screen used for moving spies between cities */ -class EspionageOverviewScreen(val civInfo: Civilization) : PickerScreen(true) { +class EspionageOverviewScreen(val civInfo: Civilization, val worldScreen: WorldScreen) : PickerScreen(true) { private val collator = UncivGame.Current.settings.getCollatorFromLocale() private val spySelectionTable = Table(skin) @@ -103,6 +105,10 @@ class EspionageOverviewScreen(val civInfo: Civilization) : PickerScreen(true) { ) } } + if (worldScreen.viewingCiv != civInfo) { + // Spectators aren't allowed to move the spies of the Civs they are viewing + moveSpyButton.disable() + } spySelectionTable.add(moveSpyButton).pad(5f, 10f, 5f, 20f).row() } } diff --git a/core/src/com/unciv/ui/screens/worldscreen/TechPolicyDiplomacyButtons.kt b/core/src/com/unciv/ui/screens/worldscreen/TechPolicyDiplomacyButtons.kt index 08286273b4..b0baf7f383 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/TechPolicyDiplomacyButtons.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/TechPolicyDiplomacyButtons.kt @@ -9,7 +9,9 @@ import com.unciv.models.UncivSound import com.unciv.models.translations.tr import com.unciv.ui.components.extensions.colorFromRGB import com.unciv.ui.components.extensions.disable +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.components.fonts.Fonts import com.unciv.ui.components.input.KeyboardBinding import com.unciv.ui.components.input.onActivation @@ -26,6 +28,9 @@ import com.unciv.ui.screens.worldscreen.UndoHandler.Companion.restoreUndoCheckpo /** A holder for Tech, Policies and Diplomacy buttons going in the top left of the WorldScreen just under WorldScreenTopBar */ class TechPolicyDiplomacyButtons(val worldScreen: WorldScreen) : Table(BaseScreen.skin) { + private val fogOfWarButtonHolder = Container() + private val fogOfWarButton = "Fog of War".toTextButton() + private val techButtonHolder = Container() private val pickTechButton = Table(skin) private val pickTechLabel = "".toLabel(Color.WHITE, 30) @@ -44,6 +49,7 @@ class TechPolicyDiplomacyButtons(val worldScreen: WorldScreen) : Table(BaseScree init { defaults().left() + add(fogOfWarButtonHolder).colspan(4).row() add(techButtonHolder).colspan(4).row() add(policyButtonHolder).padTop(10f).padRight(10f) add(diplomacyButtonHolder).padTop(10f).padRight(10f) @@ -51,6 +57,14 @@ class TechPolicyDiplomacyButtons(val worldScreen: WorldScreen) : Table(BaseScree add(undoButtonHolder).padTop(10f).padRight(10f) add().growX() // Allows Policy and Diplo buttons to keep to the left + fogOfWarButton.label.setFontSize(30) + fogOfWarButton.labelCell.pad(10f) + fogOfWarButton.pack() + fogOfWarButtonHolder.onActivation(UncivSound.Paper, KeyboardBinding.TechnologyTree) { + worldScreen.fogOfWar = !worldScreen.fogOfWar + worldScreen.shouldUpdate = true + } + pickTechButton.background = BaseScreen.skinStrings.getUiBackground("WorldScreen/PickTechButton", BaseScreen.skinStrings.roundedEdgeRectangleShape, colorFromRGB(7, 46, 43)) pickTechButton.defaults().pad(20f) pickTechButton.add(pickTechLabel) @@ -76,14 +90,15 @@ class TechPolicyDiplomacyButtons(val worldScreen: WorldScreen) : Table(BaseScree if (game.gameInfo!!.isEspionageEnabled()) { espionageButton.add(ImageGetter.getImage("OtherIcons/Spy_White")).size(30f).pad(15f) espionageButtonHolder.onActivation(binding = KeyboardBinding.Espionage) { - game.pushScreen(EspionageOverviewScreen(viewingCiv)) + game.pushScreen(EspionageOverviewScreen(worldScreen.selectedCiv, worldScreen)) } } } fun update(): Boolean { - updateUndoButton() + updateFogOfWarButton() updateTechButton() + updateUndoButton() updatePolicyButton() val result = updateDiplomacyButton() if (game.gameInfo!!.isEspionageEnabled()) @@ -93,6 +108,16 @@ class TechPolicyDiplomacyButtons(val worldScreen: WorldScreen) : Table(BaseScree return result } + private fun updateFogOfWarButton() { + if (viewingCiv.isSpectator()) { + fogOfWarButtonHolder.actor = fogOfWarButton + fogOfWarButtonHolder.touchable = Touchable.enabled + } else { + fogOfWarButtonHolder.touchable = Touchable.disabled + fogOfWarButtonHolder.actor = null + } + } + private fun updateTechButton() { techButtonHolder.touchable = Touchable.disabled techButtonHolder.actor = null @@ -154,7 +179,7 @@ class TechPolicyDiplomacyButtons(val worldScreen: WorldScreen) : Table(BaseScree } private fun updateEspionageButton() { - if (viewingCiv.espionageManager.spyList.isEmpty()) { + if (worldScreen.selectedCiv.espionageManager.spyList.isEmpty()) { espionageButtonHolder.touchable = Touchable.disabled espionageButtonHolder.actor = null } else { diff --git a/core/src/com/unciv/ui/screens/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/screens/worldscreen/WorldScreen.kt index 6a9b70bbcb..2439cc22f7 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/WorldScreen.kt @@ -98,7 +98,6 @@ class WorldScreen( var selectedCiv = viewingCiv var fogOfWar = true - private set /** `true` when it's the player's turn unless he is a spectator */ val canChangeState @@ -112,7 +111,6 @@ class WorldScreen( // Floating Widgets going counter-clockwise val topBar = WorldScreenTopBar(this) private val techPolicyAndDiplomacy = TechPolicyDiplomacyButtons(this) - private val fogOfWarButton = createFogOfWarButton() private val unitActionsTable = UnitActionsTable(this) /** Bottom left widget holding information about a selected unit or city */ val bottomUnitTable = UnitTable(this) @@ -148,8 +146,6 @@ class WorldScreen( // resume music (in case choices from the menu lead to instantiation of a new WorldScreen) UncivGame.Current.musicController.resume() - fogOfWarButton.isVisible = viewingCiv.isSpectator() - stage.addActor(mapHolder) stage.scrollFocus = mapHolder stage.addActor(notificationsScroll) // very low in z-order, so we're free to let it extend _below_ tile info and minimap if we want @@ -162,7 +158,6 @@ class WorldScreen( stage.addActor(zoomController) zoomController.isVisible = UncivGame.Current.settings.showZoomButtons - stage.addActor(fogOfWarButton) stage.addActor(bottomUnitTable) stage.addActor(bottomTileInfoTable) battleTable.width = stage.width / 3 @@ -306,7 +301,6 @@ class WorldScreen( minimapWrapper.isVisible = uiEnabled bottomUnitTable.isVisible = uiEnabled if (uiEnabled) battleTable.update() else battleTable.isVisible = false - fogOfWarButton.isVisible = uiEnabled && viewingCiv.isSpectator() } private fun addKeyboardListener() { @@ -409,9 +403,6 @@ class WorldScreen( if (techPolicyAndDiplomacy.update()) displayTutorial(TutorialTrigger.OtherCivEncountered) - fogOfWarButton.isEnabled = !selectedCiv.isSpectator() - fogOfWarButton.setPosition(10f, topBar.y - fogOfWarButton.height - 10f) - // If the game has ended, lets stop AutoPlay if (game.settings.autoPlay.isAutoPlaying() && !gameInfo.oneMoreTurnMode && (viewingCiv.isDefeated() || gameInfo.checkForVictory())) { @@ -557,19 +548,6 @@ class WorldScreen( } } - private fun createFogOfWarButton(): TextButton { - val fogOfWarButton = "Fog of War".toTextButton() - fogOfWarButton.label.setFontSize(30) - fogOfWarButton.labelCell.pad(10f) - fogOfWarButton.pack() - fogOfWarButton.onClick { - fogOfWar = !fogOfWar - shouldUpdate = true - } - return fogOfWarButton - - } - class RestoreState( mapHolder: WorldMapHolder, val selectedCivName: String,