tibia-client/modules/corelib/ui/effects.lua

38 lines
1001 B
Lua
Raw Normal View History

2012-06-26 00:13:30 +02:00
-- @docclass
g_effects = {}
2012-06-26 00:13:30 +02:00
function g_effects.fadeIn(widget, time, elapsed)
if not elapsed then elapsed = 0 end
2012-03-26 20:33:00 +02:00
if not time then time = 300 end
widget:setOpacity(math.min(elapsed/time, 1))
2012-03-26 20:33:00 +02:00
removeEvent(widget.fadeEvent)
if elapsed < time then
removeEvent(widget.fadeEvent)
widget.fadeEvent = scheduleEvent(function()
2012-06-26 00:13:30 +02:00
g_effects.fadeIn(widget, time, elapsed + 30)
end, 30)
else
widget.fadeEvent = nil
end
end
2012-06-26 00:13:30 +02:00
function g_effects.fadeOut(widget, time, elapsed)
if not elapsed then elapsed = 0 end
2012-03-26 20:33:00 +02:00
if not time then time = 300 end
elapsed = math.max((1 - widget:getOpacity()) * time, elapsed)
removeEvent(widget.fadeEvent)
widget:setOpacity(math.max((time - elapsed)/time, 0))
if elapsed < time then
widget.fadeEvent = scheduleEvent(function()
2012-06-26 00:13:30 +02:00
g_effects.fadeOut(widget, time, elapsed + 30)
end, 30)
else
widget.fadeEvent = nil
end
end
2012-06-26 00:13:30 +02:00
function g_effects.cancelFade(widget)
removeEvent(widget.fadeEvent)
2012-03-26 20:33:00 +02:00
widget.fadeEvent = nil
end