#0 - Oct. 3, 2007, 11:26 a.m.
<Script file="BaudActionTimer.lua"/>
<Frame name="BaudActionTimerTemplate" setAllPoints="true" virtual="true">
<Layers>
<Layer level="OVERLAY">
<FontString name="$parentTextLarge" inherits="MasterFont" font="Fonts\FRIZQT__.TTF">
<FontHeight><AbsValue val="15"/></FontHeight>
<Color r=".8" g=".8" b="0"/>
<Anchors><Anchor point="CENTER"/></Anchors>
</FontString>
<FontString name="$parentTextSmall" inherits="MasterFont" font="Fonts\FRIZQT__.TTF">
<FontHeight><AbsValue val="12"/></FontHeight>
<Color r=".8" g=".8" b="0"/>
<Anchors><Anchor point="CENTER"/></Anchors>
</FontString>
</Layer>
</Layers>
<Scripts>
<OnUpdate>
BaudActionTimer_OnUpdate();
</OnUpdate>
<OnSizeChanged>
BaudActionTimer_OnSizeChanged();
</OnSizeChanged>
</Scripts>
</Frame>
And here is the lua part:
hooksecurefunc("CooldownFrame_SetTimer",function(Cooldown, Start, Duration, Enable)
local Timer = getglobal(Cooldown:GetName().."Time");
if not Timer then
Timer = CreateFrame("Frame",Cooldown:GetName().."Time",Cooldown,"BaudActionTimerTemplate");
end
Timer.Start = Start;
Timer.Duration = Duration;
end);
function BaudActionTimer_OnSizeChanged()
this:SetScale(this:GetParent():GetWidth() / 36);
end
--Note that this will only show as long as the cooldown is shown
function BaudActionTimer_OnUpdate()
if not this.Duration then
return;
end
local Large, Small = getglobal(this:GetName().."TextLarge"), getglobal(this:GetName().."TextSmall");
local Remain = ceil(this.Duration-(GetTime()-this.Start)+1)-1;
if(this.Duration < 4)or(Remain < 0)then
if Large:IsShown()then
Large:Hide();
end
if Small:IsShown()then
Small:Hide();
end
return;
end
if(Remain >= 60)then
if Large:IsShown()then
Large:Hide();
end
Small:SetText(string.format("%d:%.2d",Remain / 60,Remain % 60));
if not Small:IsShown()then
Small:Show();
end
return;
end
if Small:IsShown()then
Small:Hide();
end
Large:SetText(Remain);
if not Large:IsShown()then
Large:Show();
end