47f7fb2 - Bestow Faith support
[wowui.git] / OmaTMW / Bres.lua
1 -- Bres.lua
2 local _;
3 local min, ceil = math.min, math.ceil;
4 local GetSpellCharges = GetSpellCharges;
5 local GetTime = GetTime;
6 local CTimerAfter = C_Timer.After;
7
8 local frame = CreateFrame("Frame", "OmaBres", UIParent);
9
10 local function tick()
11     local charges, maxCharges, start, duration = GetSpellCharges(20484); -- Rebirth
12     if charges then
13         frame:Show();
14         local remain = duration - (GetTime() - start);
15         if remain < 0 then
16             frame:Hide();
17             CTimerAfter(5, tick);
18             return;
19         end
20         frame.charge:SetText(charges);
21         frame.cd:SetCooldown(start, duration);
22         CTimerAfter(min(ceil(remain), 5), tick);
23     else
24         frame:Hide();
25         CTimerAfter(5, tick);
26     end
27 end
28
29 local function bres()
30     frame:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", 580, 0);
31     frame:SetWidth(48);
32     frame:SetHeight(48);
33     frame.base = frame:CreateTexture(nil, "BACKGROUND");
34     frame.base:SetAllPoints();
35     frame.base:SetColorTexture(0, 0, 0, 0.5);
36     frame.icon = frame:CreateTexture(nil, "BORDER");
37     frame.icon:SetPoint("TOPLEFT", frame.base, "TOPLEFT", 1, -1);
38     frame.icon:SetPoint("BOTTOMRIGHT", frame.base, "BOTTOMRIGHT", -1, 1);
39     frame.icon:SetTexCoord(0.07, 0.93, 0.07, 0.93);
40     frame.icon:SetTexture(136080); -- Rebirth
41     frame.charge = frame:CreateFontString(nil, "OVERLAY", "NumberFontNormalLarge");
42     frame.charge:SetPoint("BOTTOMRIGHT");
43     frame.cd = CreateFrame("Cooldown", "OmaBresCD", frame, "CooldownFrameTemplate");
44     frame.cd:SetAllPoints();
45     frame:UnregisterAllEvents();
46     tick();
47 end
48
49 frame:SetScript("OnEvent", function(self, event)
50     return bres();
51 end);
52 frame:RegisterEvent("PLAYER_LOGIN");