mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-10 07:48:31 +07:00
Spectators can now see the diplomacy screen of the civ that they have selected (#10969)
This commit is contained in:
@ -13,6 +13,7 @@ import com.unciv.models.Spy
|
|||||||
import com.unciv.models.SpyAction
|
import com.unciv.models.SpyAction
|
||||||
import com.unciv.models.translations.tr
|
import com.unciv.models.translations.tr
|
||||||
import com.unciv.ui.components.extensions.addSeparatorVertical
|
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.setSize
|
||||||
import com.unciv.ui.components.extensions.toLabel
|
import com.unciv.ui.components.extensions.toLabel
|
||||||
import com.unciv.ui.components.extensions.toTextButton
|
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.components.widgets.AutoScrollPane
|
||||||
import com.unciv.ui.images.ImageGetter
|
import com.unciv.ui.images.ImageGetter
|
||||||
import com.unciv.ui.screens.pickerscreens.PickerScreen
|
import com.unciv.ui.screens.pickerscreens.PickerScreen
|
||||||
|
import com.unciv.ui.screens.worldscreen.WorldScreen
|
||||||
|
|
||||||
/** Screen used for moving spies between cities */
|
/** 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 collator = UncivGame.Current.settings.getCollatorFromLocale()
|
||||||
|
|
||||||
private val spySelectionTable = Table(skin)
|
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()
|
spySelectionTable.add(moveSpyButton).pad(5f, 10f, 5f, 20f).row()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,9 @@ import com.unciv.models.UncivSound
|
|||||||
import com.unciv.models.translations.tr
|
import com.unciv.models.translations.tr
|
||||||
import com.unciv.ui.components.extensions.colorFromRGB
|
import com.unciv.ui.components.extensions.colorFromRGB
|
||||||
import com.unciv.ui.components.extensions.disable
|
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.toLabel
|
||||||
|
import com.unciv.ui.components.extensions.toTextButton
|
||||||
import com.unciv.ui.components.fonts.Fonts
|
import com.unciv.ui.components.fonts.Fonts
|
||||||
import com.unciv.ui.components.input.KeyboardBinding
|
import com.unciv.ui.components.input.KeyboardBinding
|
||||||
import com.unciv.ui.components.input.onActivation
|
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 */
|
/** 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) {
|
class TechPolicyDiplomacyButtons(val worldScreen: WorldScreen) : Table(BaseScreen.skin) {
|
||||||
|
private val fogOfWarButtonHolder = Container<Button?>()
|
||||||
|
private val fogOfWarButton = "Fog of War".toTextButton()
|
||||||
|
|
||||||
private val techButtonHolder = Container<Table?>()
|
private val techButtonHolder = Container<Table?>()
|
||||||
private val pickTechButton = Table(skin)
|
private val pickTechButton = Table(skin)
|
||||||
private val pickTechLabel = "".toLabel(Color.WHITE, 30)
|
private val pickTechLabel = "".toLabel(Color.WHITE, 30)
|
||||||
@ -44,6 +49,7 @@ class TechPolicyDiplomacyButtons(val worldScreen: WorldScreen) : Table(BaseScree
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
defaults().left()
|
defaults().left()
|
||||||
|
add(fogOfWarButtonHolder).colspan(4).row()
|
||||||
add(techButtonHolder).colspan(4).row()
|
add(techButtonHolder).colspan(4).row()
|
||||||
add(policyButtonHolder).padTop(10f).padRight(10f)
|
add(policyButtonHolder).padTop(10f).padRight(10f)
|
||||||
add(diplomacyButtonHolder).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(undoButtonHolder).padTop(10f).padRight(10f)
|
||||||
add().growX() // Allows Policy and Diplo buttons to keep to the left
|
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.background = BaseScreen.skinStrings.getUiBackground("WorldScreen/PickTechButton", BaseScreen.skinStrings.roundedEdgeRectangleShape, colorFromRGB(7, 46, 43))
|
||||||
pickTechButton.defaults().pad(20f)
|
pickTechButton.defaults().pad(20f)
|
||||||
pickTechButton.add(pickTechLabel)
|
pickTechButton.add(pickTechLabel)
|
||||||
@ -76,14 +90,15 @@ class TechPolicyDiplomacyButtons(val worldScreen: WorldScreen) : Table(BaseScree
|
|||||||
if (game.gameInfo!!.isEspionageEnabled()) {
|
if (game.gameInfo!!.isEspionageEnabled()) {
|
||||||
espionageButton.add(ImageGetter.getImage("OtherIcons/Spy_White")).size(30f).pad(15f)
|
espionageButton.add(ImageGetter.getImage("OtherIcons/Spy_White")).size(30f).pad(15f)
|
||||||
espionageButtonHolder.onActivation(binding = KeyboardBinding.Espionage) {
|
espionageButtonHolder.onActivation(binding = KeyboardBinding.Espionage) {
|
||||||
game.pushScreen(EspionageOverviewScreen(viewingCiv))
|
game.pushScreen(EspionageOverviewScreen(worldScreen.selectedCiv, worldScreen))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun update(): Boolean {
|
fun update(): Boolean {
|
||||||
updateUndoButton()
|
updateFogOfWarButton()
|
||||||
updateTechButton()
|
updateTechButton()
|
||||||
|
updateUndoButton()
|
||||||
updatePolicyButton()
|
updatePolicyButton()
|
||||||
val result = updateDiplomacyButton()
|
val result = updateDiplomacyButton()
|
||||||
if (game.gameInfo!!.isEspionageEnabled())
|
if (game.gameInfo!!.isEspionageEnabled())
|
||||||
@ -93,6 +108,16 @@ class TechPolicyDiplomacyButtons(val worldScreen: WorldScreen) : Table(BaseScree
|
|||||||
return result
|
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() {
|
private fun updateTechButton() {
|
||||||
techButtonHolder.touchable = Touchable.disabled
|
techButtonHolder.touchable = Touchable.disabled
|
||||||
techButtonHolder.actor = null
|
techButtonHolder.actor = null
|
||||||
@ -154,7 +179,7 @@ class TechPolicyDiplomacyButtons(val worldScreen: WorldScreen) : Table(BaseScree
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun updateEspionageButton() {
|
private fun updateEspionageButton() {
|
||||||
if (viewingCiv.espionageManager.spyList.isEmpty()) {
|
if (worldScreen.selectedCiv.espionageManager.spyList.isEmpty()) {
|
||||||
espionageButtonHolder.touchable = Touchable.disabled
|
espionageButtonHolder.touchable = Touchable.disabled
|
||||||
espionageButtonHolder.actor = null
|
espionageButtonHolder.actor = null
|
||||||
} else {
|
} else {
|
||||||
|
@ -98,7 +98,6 @@ class WorldScreen(
|
|||||||
var selectedCiv = viewingCiv
|
var selectedCiv = viewingCiv
|
||||||
|
|
||||||
var fogOfWar = true
|
var fogOfWar = true
|
||||||
private set
|
|
||||||
|
|
||||||
/** `true` when it's the player's turn unless he is a spectator */
|
/** `true` when it's the player's turn unless he is a spectator */
|
||||||
val canChangeState
|
val canChangeState
|
||||||
@ -112,7 +111,6 @@ class WorldScreen(
|
|||||||
// Floating Widgets going counter-clockwise
|
// Floating Widgets going counter-clockwise
|
||||||
val topBar = WorldScreenTopBar(this)
|
val topBar = WorldScreenTopBar(this)
|
||||||
private val techPolicyAndDiplomacy = TechPolicyDiplomacyButtons(this)
|
private val techPolicyAndDiplomacy = TechPolicyDiplomacyButtons(this)
|
||||||
private val fogOfWarButton = createFogOfWarButton()
|
|
||||||
private val unitActionsTable = UnitActionsTable(this)
|
private val unitActionsTable = UnitActionsTable(this)
|
||||||
/** Bottom left widget holding information about a selected unit or city */
|
/** Bottom left widget holding information about a selected unit or city */
|
||||||
val bottomUnitTable = UnitTable(this)
|
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)
|
// resume music (in case choices from the menu lead to instantiation of a new WorldScreen)
|
||||||
UncivGame.Current.musicController.resume()
|
UncivGame.Current.musicController.resume()
|
||||||
|
|
||||||
fogOfWarButton.isVisible = viewingCiv.isSpectator()
|
|
||||||
|
|
||||||
stage.addActor(mapHolder)
|
stage.addActor(mapHolder)
|
||||||
stage.scrollFocus = 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
|
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)
|
stage.addActor(zoomController)
|
||||||
zoomController.isVisible = UncivGame.Current.settings.showZoomButtons
|
zoomController.isVisible = UncivGame.Current.settings.showZoomButtons
|
||||||
|
|
||||||
stage.addActor(fogOfWarButton)
|
|
||||||
stage.addActor(bottomUnitTable)
|
stage.addActor(bottomUnitTable)
|
||||||
stage.addActor(bottomTileInfoTable)
|
stage.addActor(bottomTileInfoTable)
|
||||||
battleTable.width = stage.width / 3
|
battleTable.width = stage.width / 3
|
||||||
@ -306,7 +301,6 @@ class WorldScreen(
|
|||||||
minimapWrapper.isVisible = uiEnabled
|
minimapWrapper.isVisible = uiEnabled
|
||||||
bottomUnitTable.isVisible = uiEnabled
|
bottomUnitTable.isVisible = uiEnabled
|
||||||
if (uiEnabled) battleTable.update() else battleTable.isVisible = false
|
if (uiEnabled) battleTable.update() else battleTable.isVisible = false
|
||||||
fogOfWarButton.isVisible = uiEnabled && viewingCiv.isSpectator()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addKeyboardListener() {
|
private fun addKeyboardListener() {
|
||||||
@ -409,9 +403,6 @@ class WorldScreen(
|
|||||||
if (techPolicyAndDiplomacy.update())
|
if (techPolicyAndDiplomacy.update())
|
||||||
displayTutorial(TutorialTrigger.OtherCivEncountered)
|
displayTutorial(TutorialTrigger.OtherCivEncountered)
|
||||||
|
|
||||||
fogOfWarButton.isEnabled = !selectedCiv.isSpectator()
|
|
||||||
fogOfWarButton.setPosition(10f, topBar.y - fogOfWarButton.height - 10f)
|
|
||||||
|
|
||||||
// If the game has ended, lets stop AutoPlay
|
// If the game has ended, lets stop AutoPlay
|
||||||
if (game.settings.autoPlay.isAutoPlaying()
|
if (game.settings.autoPlay.isAutoPlaying()
|
||||||
&& !gameInfo.oneMoreTurnMode && (viewingCiv.isDefeated() || gameInfo.checkForVictory())) {
|
&& !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(
|
class RestoreState(
|
||||||
mapHolder: WorldMapHolder,
|
mapHolder: WorldMapHolder,
|
||||||
val selectedCivName: String,
|
val selectedCivName: String,
|
||||||
|
Reference in New Issue
Block a user