diff --git a/core/src/com/unciv/models/Spy.kt b/core/src/com/unciv/models/Spy.kt index 575bc31fbe..19ba814a3f 100644 --- a/core/src/com/unciv/models/Spy.kt +++ b/core/src/com/unciv/models/Spy.kt @@ -25,7 +25,7 @@ enum class SpyAction(val displayString: String, val hasTurns: Boolean, internal RiggingElections("Rigging Elections", false, true) { override fun isDoingWork(spy: Spy) = !spy.civInfo.isAtWarWith(spy.getCity().civ) }, - CounterIntelligence("Conducting Counter-intelligence", false, true) { + CounterIntelligence("Counter-intelligence", false, true) { override fun isDoingWork(spy: Spy) = spy.turnsRemainingForAction > 0 }, Dead("Dead", true, false), diff --git a/core/src/com/unciv/ui/screens/overviewscreen/EspionageOverviewScreen.kt b/core/src/com/unciv/ui/screens/overviewscreen/EspionageOverviewScreen.kt index b3efe6a540..f2758006c2 100644 --- a/core/src/com/unciv/ui/screens/overviewscreen/EspionageOverviewScreen.kt +++ b/core/src/com/unciv/ui/screens/overviewscreen/EspionageOverviewScreen.kt @@ -42,6 +42,7 @@ class EspionageOverviewScreen(val civInfo: Civilization, val worldScreen: WorldS // if the value == null, this means the Spy Hideout. private var moveSpyHereButtons = hashMapOf() + private var moveSpyButtons = hashMapOf() /** Readability shortcut */ private val manager get() = civInfo.espionageManager @@ -72,6 +73,7 @@ class EspionageOverviewScreen(val civInfo: Civilization, val worldScreen: WorldS private fun updateSpyList() { spySelectionTable.clear() + moveSpyButtons.clear() spySelectionTable.add("Spy".toLabel()) spySelectionTable.add("Rank".toLabel()) spySelectionTable.add("Location".toLabel()) @@ -86,30 +88,14 @@ class EspionageOverviewScreen(val civInfo: Civilization, val worldScreen: WorldS val moveSpyButton = "Move".toTextButton() moveSpyButton.onClick { - if (selectedSpyButton == moveSpyButton) { - resetSelection() - return@onClick - } - resetSelection() - selectedSpyButton = moveSpyButton - selectedSpy = spy - selectedSpyButton!!.label.setText(Constants.cancel.tr()) - for ((button, city) in moveSpyHereButtons) { - if (city == spy.getCityOrNull()) { - button.isVisible = true - button.setDirection(Align.right) - } else { - button.isVisible = city == null // hideout - || !city.espionage.hasSpyOf(civInfo) - button.setDirection(Align.left) - } - } + onSpyClicked(moveSpyButton, spy) } if (!worldScreen.canChangeState || !spy.isAlive()) { // 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() + moveSpyButtons[spy] = moveSpyButton } } @@ -181,6 +167,10 @@ class EspionageOverviewScreen(val civInfo: Civilization, val worldScreen: WorldS starTable.add(star).size(8f).pad(1f).row() } add(starTable).center().padLeft(-4f) + + onClick { + onSpyClicked(moveSpyButtons[spy]!!, spy) + } } private fun getSpyIcons(spies: Iterable) = Table().apply { @@ -212,6 +202,27 @@ class EspionageOverviewScreen(val civInfo: Civilization, val worldScreen: WorldS } } + private fun onSpyClicked(moveSpyButton: TextButton, spy: Spy) { + if (selectedSpyButton == moveSpyButton) { + resetSelection() + return + } + resetSelection() + selectedSpyButton = moveSpyButton + selectedSpy = spy + selectedSpyButton!!.label.setText(Constants.cancel.tr()) + for ((button, city) in moveSpyHereButtons) { + if (city == spy.getCityOrNull()) { + button.isVisible = true + button.setDirection(Align.right) + } else { + button.isVisible = city == null // hideout + || !city.espionage.hasSpyOf(civInfo) + button.setDirection(Align.left) + } + } + } + private fun resetSelection() { selectedSpy = null selectedSpyButton?.label?.setText("Move".tr())