diff --git a/korge/src/common/korlibs/korge/ui/UIButton.kt b/korge/src/common/korlibs/korge/ui/UIButton.kt index 4371f473cb..4b14997560 100644 --- a/korge/src/common/korlibs/korge/ui/UIButton.kt +++ b/korge/src/common/korlibs/korge/ui/UIButton.kt @@ -99,6 +99,15 @@ open class UIButton( setInitialState() } + override var enabled: Boolean + get() = super.enabled + set(value) { + if (value == mouseEnabled) return + + mouseEnabled = value + updatedUIButton(enable = value) + } + //protected val rect: NinePatchEx = ninePatch(null, width, height) //protected val background = roundRect( // width, height, radiusWidth(width), radiusHeight(height), bgColorOut) @@ -256,61 +265,27 @@ open class UIButton( touch.simulateTapAt(views, localToGlobal(Point(width * 0.5f, height * 0.5f))) } - open fun updatedUIButton(down: Boolean? = null, over: Boolean? = null, pos: Point = Point.ZERO, immediate: Boolean = false) { - val button = this - if (!button.enabled) { - //button.animStateManager.set( - // AnimState( - // button::bgcolor[button.bgColorDisabled] - //)) - //button.animatorEffects.cancel() - background.bgColor = button.bgColorDisabled - button.invalidateRender() - return - } - //println("UPDATED: down=$down, over=$over, px=$px, py=$py") - if (down == true) { - //button.animStateManager.set( - // AnimState( - // button::highlightRadius[0.0, 1.0], - // button::highlightAlpha[1.0], - // button::highlightPos[Point(px / button.width, py / button.height), Point(px / button.width, py / button.height)], - // )) - background.addHighlight(pos) - /* - button.highlightPos.setTo(px / button.width, py / button.height) - button.animatorEffects.tween( - button::highlightRadius[0.0, 1.0], - button::highlightColor[Colors.WHITE.withAd(0.5), Colors.WHITE.withAd(0.5)], - time = 0.5.seconds, easing = Easing.EASE_IN - ) - */ - } - if (down == false) { - //button.animStateManager.set( - // AnimState(button::highlightAlpha[0.0]) - //) - background.removeHighlights() - //button.animatorEffects.tween(button::highlightColor[Colors.TRANSPARENT_BLACK], time = 0.2.seconds) - } - if (over != null) { - val bgcolor = when { - !button.enabled -> button.bgColorDisabled - over -> button.bgColorOver - selected -> button.bgColorSelected - else -> button.bgColorOut - } - //button.animStateManager.set( - // AnimState( - // button::bgcolor[bgcolor] - // ) - //) - if (immediate) { - background.bgColor = bgcolor + open fun updatedUIButton(down: Boolean? = null, over: Boolean? = null, enable: Boolean? = null, pos: Point = Point.ZERO, immediate: Boolean = false) { + if (enabled && down != null) { + if (down) { + background.addHighlight(pos) } else { - button.animator.tween(background::bgColor[bgcolor], time = 0.25.seconds) + background.removeHighlights() } } + + val bgColor = when { + enable == false || !enabled -> bgColorDisabled + over == true -> bgColorOver + selected -> bgColorSelected + else -> bgColorOut + } + + if (immediate) { + background.bgColor = bgColor + } else { + animator.tween(background::bgColor[bgColor], time = 0.25.seconds) + } } var selected: Boolean = false