Compare with Previous |
Blame |
View Log
Shimmering = class(Turbine.UI.Window);
function Shimmering:Constructor()
Turbine.UI.Window.Constructor(self);
self.controls = {};
self.updateTime = 0;
self.theta = 0;
end
function Shimmering:Add(control)
if (not self.controls[control]) then
local color = control:GetForeColor();
self.controls[control] = { color.A, color.R, color.G, color.B };
-- Hijack further calls to the control's SetForeColor() function to save the new color
control._SetForeColor = control.SetForeColor;
control.SetForeColor = function(ctl, color)
self.controls[ctl] = { color.A, color.R, color.G, color.B };
ctl._SetForeColor(ctl, color);
end
end
end
function Shimmering:Remove(control)
local color = self.controls[control];
if (color) then
local color = Turbine.UI.Color(unpack(color));
-- Un-hijack the control's SetForeColor() function
control.SetForeColor = nil; -- restore inherited function
control._SetForeColor = nil;
control:SetForeColor(color);
self.controls[control] = nil;
end
end
function Shimmering:Update()
local gameTime = Turbine.Engine.GetGameTime();
local elapsedTime = (gameTime - self.updateTime) * 5;
self.theta = self.theta + elapsedTime;
local stage, progress = math.modf(self.theta % 2);
if (stage == 1) then
progress = 1 - progress;
end
local R = 0.5 + 0.5 * progress;
local G = 0.5 + 0.5 * progress;
local B = 0.5 - 0.5 * progress;
local color = Turbine.UI.Color(1, R, G, B);
for ctl, info in pairs(self.controls) do
ctl:_SetForeColor(color);
end
self.updateTime = gameTime;
end
Compare with Previous |
Blame
All times are GMT -5. The time now is 07:34 AM.