3 local CreateFrame = CreateFrame;
4 local UnitAura = UnitAura;
5 local GameTooltip = GameTooltip;
6 local GetTime = GetTime;
7 local CTimerAfter = C_Timer.After;
9 local auraFilters = {"HELPFUL", "HARMFUL"};
15 local function updateTooltip(frame)
16 if GameTooltip:IsOwned(frame) then
17 GameTooltip:SetUnitAura(frame.unit, frame.index, frame.filter);
19 frame:SetScript("OnUpdate", nil);
23 local function showTooltip(frame)
24 -- tooltip handling from FrameXML/TargetFrame.xml
25 GameTooltip:SetOwner(frame, "ANCHOR_BOTTOMRIGHT", 15, -25);
26 GameTooltip:SetUnitAura(frame.unit, frame.index, frame.filter);
27 frame:SetScript("OnUpdate", updateTooltip);
30 local function hideTooltip(frame)
32 frame:SetScript("OnUpdate", nil);
35 local function createAura(parent, prev, anchor, name, unit)
36 local aura = CreateFrame("Frame", name, parent);
37 aura:SetPoint("TOPLEFT", prev, anchor);
40 aura.icon = aura:CreateTexture(nil, "ARTWORK");
41 aura.icon:SetAllPoints();
42 aura.stack = aura:CreateFontString(nil, "OVERLAY", "NumberFontNormalSmall");
43 aura.stack:SetPoint("BOTTOMRIGHT");
44 aura.cd = CreateFrame("Cooldown", name.."CD", aura, "CooldownFrameTemplate");
45 aura.cd:SetReverse(true);
46 aura.cd:SetHideCountdownNumbers(true);
47 aura.cd:SetAllPoints();
49 aura:SetScript("OnEnter", showTooltip);
50 aura:SetScript("OnLeave", hideTooltip);
55 function M.CreateAuraFrame(parent, unit)
56 local name = parent:GetName().."Auras";
57 parent.auras = CreateFrame("Frame", name, parent);
58 parent.auras:SetPoint("TOPLEFT", parent, "BOTTOMLEFT", 0, -8);
59 parent.auras:SetWidth(10);
60 parent.auras:SetHeight(10);
64 local auraName = name..i;
66 parent.auras[i] = createAura(parent.auras, parent.auras, "TOPLEFT", auraName, unit);
68 parent.auras[i] = createAura(parent.auras, parent.auras[i-1], "TOPRIGHT", auraName, unit);
75 local auraName = name..i;
76 parent.auras[i] = createAura(parent.auras, parent.auras[y*10+x], "BOTTOMLEFT", auraName, unit);
81 parent.throttle = function()
82 parent.throttled = nil;
83 if UnitExists(unit) then
84 return updateAuras(parent, unit);
89 function M.UpdateAuras(frame, unit)
90 local current = GetTime();
91 if frame.throttled then
93 elseif frame.prevUpdate and current - frame.prevUpdate < 0.2 then
94 frame.throttled = true;
95 return CTimerAfter(0.1, frame.throttle); -- faster timer here to reduce the delay, gets called twice
98 frame.prevUpdate = current;
99 local auras = frame.auras;
100 local icon, count, duration, expires, caster, id;
102 for _, filter in ipairs(auraFilters) do
105 _, _, icon, count, _, duration, expires, caster, _, _, id = UnitAura(unit, i, filter);
106 if not id or not auras[pos] then break end
107 local aura = auras[pos];
108 aura.icon:SetTexture(icon);
110 aura.filter = filter;
112 aura.stack:SetText(count);
118 aura.cd:SetCooldown(expires - duration, duration);
129 if not auras[pos]:IsShown() then return end
134 updateAuras = M.UpdateAuras;