-- Upvalue variables
local _G = getfenv(0);
local GetSpecialization = _G.GetSpecialization;
local GetSpellInfo = _G.GetSpellInfo;
local ReloadUI = _G.ReloadUI;
-- Local variables
local size = 40;
local point = {"CENTER", UIParent, "CENTER", 0, -110};
local gap = 2;
local max = 6;
local buffIDList = {
["WARLOCK"] = {
[3] = { -- Destruction
235156,
215165,
119899,
},
},
};
-- Local functions
local InitObjects;
-- AuraTrack
local AuraTrack = CreateFrame("Frame");
AuraTrack:RegisterEvent("ADDON_LOADED");
AuraTrack:RegisterEvent("PLAYER_ENTERING_WORLD");
AuraTrack:SetScript("OnEvent", function(self, event, ...)
self[event](self, ...);
end);
function AuraTrack:ADDON_LOADED(...)
if ... == "MyAuraTracker" then
InitObjects();
self:UnregisterEvent("ADDON_LOADED");
end
end
function AuraTrack:PLAYER_ENTERING_WORLD()
local holder = self.holder;
holder:RegisterUnitEvent("UNIT_AURA", "player");
holder:SetScript("OnEvent", function(self, event, ...)
AuraTrack[event](AuraTrack, ...);
end);
self:UnregisterEvent("PLAYER_ENTERING_WORLD");
end
function AuraTrack:UNIT_AURA(...)
local holder = self.holder;
-- Get player's class and spec to access buffIDList table
local _, class = UnitClass(...);
local spec = GetSpecialization();
-- For each button, check if they are already assigned with aura
for i = 1, #holder.button do
local button = holder.button[i];
-- If the button is assigned with aura and that aura is on-going, update its duration and so on
-- Otherwise, remove id from button and hide
if button.spellID then
local spellName = GetSpellInfo(button.spellID);
local _, _, icon, count, _, duration, expires = UnitAura(..., spellName);
if duration and duration > 0 then
button.cd:SetCooldown(expires - duration, duration);
button.icon:SetTexture(icon);
button.count:SetText((count and count > 0) and count or "");
button:Show();
else
button.spellID = nil;
button:Hide();
end
end
end
-- For each buff, check if they are activated
for i = 1, #buffIDList[class][spec] do
local spellName = GetSpellInfo(buffIDList[class][spec][i]);
local _, _, icon, count, _, duration, expires = UnitAura(..., spellName);
-- If the buff is activated, see if that buff is already assigned to a button
if duration and duration > 0 then
local assigned = false;
for j = 1, #holder.button do
if holder.button[j].spellID == buffIDList[class][spec][i] then
assigned = true;
end
end
-- If buff is not assigned to any of buttons,
-- assign the id and update its duration and so on
if not assigned then
for j = 1, #holder.button do
local button = holder.button[j];
if not button.spellID then
button.spellID = buffIDList[class][spec][i];
button.cd:SetCooldown(expires - duration, duration);
button.icon:SetTexture(icon);
button.count:SetText((count and count > 0) and count or "");
button:Show();
break;
end
end
end
end
end
end
function InitObjects()
local holder = CreateFrame("Frame", "AuraTrackerHolder", UIParent);
holder:SetPoint(unpack(point));
holder:SetSize((size + gap) * max - gap, size);
holder.button = {};
for i = 1, max do
local button = CreateFrame("Frame", "$parentButton" .. i, holder);
button:Hide();
if i == 1 then
button:SetPoint("LEFT");
else
button:SetPoint("LEFT", holder.button[i - 1], "RIGHT", gap, 0);
end
button:SetSize(size, size);
local cd = CreateFrame("Cooldown", "$parentCooldown", button, "CooldownFrameTemplate");
cd:SetAllPoints(button);
local icon = button:CreateTexture(nil, "BORDER");
icon:SetAllPoints(button);
local count = button:CreateFontString(nil, "OVERLAY");
count:SetFontObject(NumberFontNormal);
count:SetPoint("TOP", button, "BOTTOM", 0, -2);
holder.button[i] = button;
button.cd = cd;
button.icon = icon;
button.count = count;
end
AuraTrack.holder = holder;
end