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

37 lines
976 B
Lua
Raw Normal View History

2011-12-07 01:31:55 +01:00
Effects = {}
2011-12-07 01:31:55 +01:00
function 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()
Effects.fadeIn(widget, time, elapsed + 30)
end, 30)
else
widget.fadeEvent = nil
end
end
2011-12-07 01:31:55 +01:00
function 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()
Effects.fadeOut(widget, time, elapsed + 30)
end, 30)
else
widget.fadeEvent = nil
end
end
function Effects.cancelFade(widget)
removeEvent(widget.fadeEvent)
2012-03-26 20:33:00 +02:00
widget.fadeEvent = nil
end