Fix unit action/selection overlay not being closed when performing an action with a new unit (#7184)

This commit is contained in:
Timo T 2022-06-16 20:07:59 +02:00 committed by GitHub
parent e2b7891248
commit 4fb2ad8fab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,6 +12,7 @@ import com.unciv.ui.utils.KeyCharAndCode
import com.unciv.ui.utils.UncivTooltip.Companion.addTooltip import com.unciv.ui.utils.UncivTooltip.Companion.addTooltip
import com.unciv.ui.utils.extensions.disable import com.unciv.ui.utils.extensions.disable
import com.unciv.ui.utils.extensions.keyShortcuts 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.utils.extensions.onClick
import com.unciv.ui.worldscreen.WorldScreen import com.unciv.ui.worldscreen.WorldScreen
import com.unciv.utils.concurrency.Concurrency import com.unciv.utils.concurrency.Concurrency
@ -37,21 +38,17 @@ class UnitActionsTable(val worldScreen: WorldScreen) : Table() {
val actionButton = IconTextButton(unitAction.title, icon, fontColor = fontColor) val actionButton = IconTextButton(unitAction.title, icon, fontColor = fontColor)
actionButton.addTooltip(key) actionButton.addTooltip(key)
actionButton.pack() actionButton.pack()
val action = { if (unitAction.action == null) {
unitAction.action?.invoke() actionButton.disable()
UncivGame.Current.worldScreen!!.shouldUpdate = true } else {
} actionButton.onActivation(unitAction.uncivSound) {
if (unitAction.action == null) actionButton.disable() unitAction.action.invoke()
else { UncivGame.Current.worldScreen!!.shouldUpdate = true
actionButton.onClick(unitAction.uncivSound, action) // We keep the unit action/selection overlay from the previous unit open even when already selecting another unit
if (key != KeyCharAndCode.UNKNOWN) // so you need less clicks/touches to do things, but once we do an action with the new unit, we want to close this
actionButton.keyShortcuts.add(key) { // overlay, since the user definitely wants to interact with the new unit.
Concurrency.run("UnitSound") { SoundPlayer.play(unitAction.uncivSound) } worldScreen.mapHolder.removeUnitActionOverlay()
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()
}
} }
return actionButton return actionButton