mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-26 05:14:32 -04:00
Prevent activation of disabled actors via key shortcuts (#9736)
Avoid activation concurrent modification problems
This commit is contained in:
parent
8263d972ff
commit
fb3064dd4b
@ -43,6 +43,7 @@ private class RestorableTextButtonStyle(
|
||||
/** Disable a [Button] by setting its [touchable][Button.touchable] and [style][Button.style] properties. */
|
||||
fun Button.disable() {
|
||||
touchable = Touchable.disabled
|
||||
isDisabled = true
|
||||
val oldStyle = style
|
||||
if (oldStyle is RestorableTextButtonStyle) return
|
||||
val disabledStyle = BaseScreen.skin.get("disabled", TextButtonStyle::class.java)
|
||||
@ -54,6 +55,7 @@ fun Button.enable() {
|
||||
if (oldStyle is RestorableTextButtonStyle) {
|
||||
style = oldStyle.restoreStyle
|
||||
}
|
||||
isDisabled = false
|
||||
touchable = Touchable.enabled
|
||||
}
|
||||
/** Enable or disable a [Button] by setting its [touchable][Button.touchable] and [style][Button.style] properties,
|
||||
|
@ -51,7 +51,8 @@ internal class ActivationActionMap : MutableMap<ActivationTypes, ActivationActio
|
||||
if (actions.isEmpty()) return false
|
||||
if (actions.sound != UncivSound.Silent)
|
||||
Concurrency.runOnGLThread("Sound") { SoundPlayer.play(actions.sound) }
|
||||
for (action in actions)
|
||||
// We can't know an activation handler won't redefine activations, so better iterate over a copy
|
||||
for (action in actions.toList())
|
||||
action.invoke()
|
||||
return true
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.unciv.ui.components.input
|
||||
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.Disableable
|
||||
import com.unciv.models.UncivSound
|
||||
|
||||
internal class ActorAttachments private constructor(actor: Actor) {
|
||||
@ -37,6 +38,7 @@ internal class ActorAttachments private constructor(actor: Actor) {
|
||||
|
||||
fun activate(type: ActivationTypes): Boolean {
|
||||
if (!this::activationActions.isInitialized) return false
|
||||
if ((actor as? Disableable)?.isDisabled == true) return false // Skip if disabled - could reach here through key shortcuts
|
||||
return activationActions.activate(type)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user