mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 13:55:54 -04:00
Fix unit action/selection overlay not being closed when performing an action with a new unit (#7184)
This commit is contained in:
parent
e2b7891248
commit
4fb2ad8fab
@ -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,19 +38,15 @@ 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()
|
||||||
|
} else {
|
||||||
|
actionButton.onActivation(unitAction.uncivSound) {
|
||||||
|
unitAction.action.invoke()
|
||||||
UncivGame.Current.worldScreen!!.shouldUpdate = true
|
UncivGame.Current.worldScreen!!.shouldUpdate = true
|
||||||
}
|
// We keep the unit action/selection overlay from the previous unit open even when already selecting another unit
|
||||||
if (unitAction.action == null) actionButton.disable()
|
// so you need less clicks/touches to do things, but once we do an action with the new unit, we want to close this
|
||||||
else {
|
// overlay, since the user definitely wants to interact with the new unit.
|
||||||
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()
|
worldScreen.mapHolder.removeUnitActionOverlay()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user