mirror of
https://github.com/edubart/otclient.git
synced 2025-10-15 03:54:54 +02:00
Add blink effect
This commit is contained in:
@@ -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
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user