diff --git a/data/images/ui/button_top_blink.png b/data/images/ui/button_top_blink.png new file mode 100644 index 00000000..9a669278 Binary files /dev/null and b/data/images/ui/button_top_blink.png differ diff --git a/data/styles/20-topmenu.otui b/data/styles/20-topmenu.otui index 26db4951..5c6e24c7 100644 --- a/data/styles/20-topmenu.otui +++ b/data/styles/20-topmenu.otui @@ -6,6 +6,9 @@ TopButton < UIButton image-color: #ffffffff icon-color: #ffffffff + $on: + image-source: /images/ui/button_top_blink + $hover !disabled: image-color: #ffffff99 image-clip: 26 0 26 26 @@ -46,4 +49,4 @@ TopMenuPanel < Panel TopMenuFrameCounterLabel < FrameCounterLabel color: white margin-top: 4 - margin-left: 5 \ No newline at end of file + margin-left: 5 diff --git a/modules/corelib/globals.lua b/modules/corelib/globals.lua index 52882794..cdbd161d 100644 --- a/modules/corelib/globals.lua +++ b/modules/corelib/globals.lua @@ -25,8 +25,8 @@ function addEvent(callback, front) return event end -function cycleEvent(callback, front) - local event = g_dispatcher.cycleEvent(callback, front) +function cycleEvent(callback, interval) + local event = g_dispatcher.cycleEvent(callback, interval) -- must hold a reference to the callback, otherwise it would be collected event._callback = callback return event diff --git a/modules/corelib/ui/effects.lua b/modules/corelib/ui/effects.lua index ff77f61d..16325b5e 100644 --- a/modules/corelib/ui/effects.lua +++ b/modules/corelib/ui/effects.lua @@ -35,3 +35,33 @@ function g_effects.cancelFade(widget) removeEvent(widget.fadeEvent) widget.fadeEvent = nil end + +function g_effects.startBlink(widget, duration, interval, clickCancel) + duration = duration or 0 -- until stop is called + interval = interval or 500 + clickCancel = clickCancel or true + + removeEvent(widget.blinkEvent) + removeEvent(widget.blinkStopEvent) + + widget.blinkEvent = cycleEvent(function() + widget:setOn(not widget:isOn()) + end, interval) + + if duration > 0 then + widget.blinkStopEvent = scheduleEvent(function() + g_effects.stopBlink(widget) + end, duration) + end + + connect(widget, { onClick = g_effects.stopBlink }) +end + +function g_effects.stopBlink(widget) + disconnect(widget, { onClick = g_effects.stopBlink }) + removeEvent(widget.blinkEvent) + removeEvent(widget.blinkStopEvent) + widget.blinkEvent = nil + widget.blinkStopEvent = nil + widget:setOn(false) +end