Resolved #12734 - disabled buttons no longer cause click-through

This commit is contained in:
yairm210
2025-01-02 20:46:49 +02:00
parent 89c6331b45
commit 9fca320574
2 changed files with 4 additions and 7 deletions

View File

@ -33,10 +33,7 @@ import com.unciv.ui.components.extensions.GdxKeyCodeFixes.DEL
import com.unciv.ui.components.extensions.GdxKeyCodeFixes.toString
import com.unciv.ui.components.extensions.GdxKeyCodeFixes.valueOf
import com.unciv.ui.components.fonts.Fonts
import com.unciv.ui.components.input.KeyCharAndCode
import com.unciv.ui.components.input.keyShortcuts
import com.unciv.ui.components.input.onActivation
import com.unciv.ui.components.input.onChange
import com.unciv.ui.components.input.*
import com.unciv.ui.images.IconCircleGroup
import com.unciv.ui.images.ImageGetter
import com.unciv.ui.screens.basescreen.BaseScreen
@ -53,7 +50,8 @@ private class RestorableTextButtonStyle(
//todo ButtonStyle *does* have a `disabled` Drawable, and Button ignores touches in disabled state anyway - all this is a wrong approach
/** Disable a [Button] by setting its [touchable][Button.touchable] and [style][Button.style] properties. */
fun Button.disable() {
touchable = Touchable.disabled
/** We want disabled buttons to "swallow" the click so that things behind aren't activated, so we don't change touchable
The action won't be activated due to [ActorAttachments.activate] checking the isDisabled property */
isDisabled = true
val oldStyle = style
if (oldStyle is RestorableTextButtonStyle) return
@ -67,7 +65,6 @@ fun Button.enable() {
style = oldStyle.restoreStyle
}
isDisabled = false
touchable = Touchable.enabled
}
/** Enable or disable a [Button] by setting its [touchable][Button.touchable] and [style][Button.style] properties,
* or returns the corresponding state.

View File

@ -38,7 +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
if ((actor as? Disableable)?.isDisabled == true) return false // Skip if disabled
return activationActions.activate(type)
}