From 4fb2ad8fab6b3a833d8daec828d737d40e79e218 Mon Sep 17 00:00:00 2001 From: Timo T Date: Thu, 16 Jun 2022 20:07:59 +0200 Subject: [PATCH] Fix unit action/selection overlay not being closed when performing an action with a new unit (#7184) --- .../ui/worldscreen/unit/UnitActionsTable.kt | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitActionsTable.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitActionsTable.kt index fc1f0071f0..686d821495 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitActionsTable.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitActionsTable.kt @@ -12,6 +12,7 @@ import com.unciv.ui.utils.KeyCharAndCode import com.unciv.ui.utils.UncivTooltip.Companion.addTooltip import com.unciv.ui.utils.extensions.disable import com.unciv.ui.utils.extensions.keyShortcuts +import com.unciv.ui.utils.extensions.onActivation import com.unciv.ui.utils.extensions.onClick import com.unciv.ui.worldscreen.WorldScreen import com.unciv.utils.concurrency.Concurrency @@ -37,21 +38,17 @@ class UnitActionsTable(val worldScreen: WorldScreen) : Table() { val actionButton = IconTextButton(unitAction.title, icon, fontColor = fontColor) actionButton.addTooltip(key) actionButton.pack() - val action = { - unitAction.action?.invoke() - UncivGame.Current.worldScreen!!.shouldUpdate = true - } - if (unitAction.action == null) actionButton.disable() - else { - actionButton.onClick(unitAction.uncivSound, action) - if (key != KeyCharAndCode.UNKNOWN) - actionButton.keyShortcuts.add(key) { - Concurrency.run("UnitSound") { SoundPlayer.play(unitAction.uncivSound) } - action() - // FIXME: Why do we need it here, but not when clicking? Otherwise - // could have merged the two callbacks into an "activation" handler. - worldScreen.mapHolder.removeUnitActionOverlay() - } + if (unitAction.action == null) { + actionButton.disable() + } else { + actionButton.onActivation(unitAction.uncivSound) { + unitAction.action.invoke() + UncivGame.Current.worldScreen!!.shouldUpdate = true + // We keep the unit action/selection overlay from the previous unit open even when already selecting another unit + // so you need less clicks/touches to do things, but once we do an action with the new unit, we want to close this + // overlay, since the user definitely wants to interact with the new unit. + worldScreen.mapHolder.removeUnitActionOverlay() + } } return actionButton