------------------------------
-- Upvalue variable
------------------------------
local StringLower = string.lower;
local CreateFrame = CreateFrame;
local UIParent = UIParent;
local unpack = unpack;
local Mixin = Mixin;
local ObjectPoolMixin = ObjectPoolMixin;
local NumberFontNormal = NumberFontNormal;
local GetSpecialization = GetSpecialization;
local pairs = pairs;
local UnitBuff = UnitBuff;
local UnitDebuff = UnitDebuff;
------------------------------
-- Get addon
------------------------------
local CAA = LibStub("AceAddon-3.0"):GetAddon("CombatAssist");
------------------------------
-- Module initialization
------------------------------
local AM = CAA:NewModule("Aura");
------------------------------
-- Function definition
------------------------------
function string.ends(String, End)
return End == "" or string.sub(String, -string.len(End)) == End;
end
function AM:OnInitialize()
HolderInitialize();
end
function AM:OnEnable()
local holder = self.holder;
holder:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED");
holder:RegisterEvent("PLAYER_TARGET_CHANGED");
holder:RegisterUnitEvent("UNIT_AURA", "player", "target");
holder:SetScript("OnEvent", function(self, event, ...)
AM[event](AM, ...);
end)
self:ACTIVE_TALENT_GROUP_CHANGED();
self:UNIT_AURA();
end
function AM:UNIT_AURA()
local db = CAA.db.global.module.aura;
local holder = self.holder;
if db.buff.enable then
BuffUpdate();
end
end
function AM:ACTIVE_TALENT_GROUP_CHANGED()
local holder = self.holder;
local spec = GetSpecialization();
holder.auraIDList = CAA.db.char.aura.auraIDList[spec];
end
function AM:PLAYER_TARGET_CHANGED()
end
function AM:OnDisable()
local holder = self.holder;
holder:UnregisterAllEvents();
end
function HolderInitialize()
local db = CAA.db.global.module.aura;
local holder = CreateFrame("Frame");
if db.buff.enable then
local buff = CreateFrame("Frame", AM:GetName() .. "Buff", UIParent);
buff:SetPoint(unpack(db.buff.position));
buff.numObjects = 0;
Mixin(buff, ObjectPoolMixin);
buff:OnLoad(ButtonCreate, ButtonReset);
holder.buff = buff;
end
AM.holder = holder;
end
function BuffUpdate()
local db = CAA.db.global.module.aura.buff;
local buff = AM.holder.buff;
local auraIDList = AM.holder.auraIDList;
buff:ReleaseAll();
local prevButton;
for buffID, info in pairs(auraIDList.buff) do
local icon, count, duration, expires, spellID;
local index;
for j = 1, index or 40 do
local unit = info.unit or "player";
local filter = info.filter and "PLAYER|" .. info.filter or "PLAYER";
_, _, icon, count, _, duration, expires, _, _, _, spellID = UnitBuff(unit, j, filter);
if spellID and spellID == buffID then
local button = buff:Acquire();
local cd = button.cd;
if duration and duration > 0 then
print(spellID);
cd:SetCooldown(expires - duration, duration);
cd:Show();
else
cd:Hide();
end
button.icon:SetTexture(icon);
button.count:SetText((count and count > 1) and count or "");
button:Show();
if prevButton then
button:SetPoint("LEFT", prevButton, "RIGHT", db.gap, 0);
else
button:SetPoint("LEFT");
end
prevButton = button;
break;
elseif not spellID then
index = j;
break;
end
end
end
buff:SetSize(buff.numActiveObjects > 0 and ((db.size + db.gap) * buff.numActiveObjects) - db.gap or 0, db.size);
end
function ButtonCreate(self)
local size = CAA.db.global.module.aura.buff.size;
self.numObjects = self.numObjects + 1;
local id = self.numObjects;
local button = CreateFrame("Frame", "$parentButton" .. id, self);
button:SetSize(size, size);
button:SetTemplate(1);
button:Hide();
local cd = CreateFrame("Cooldown", "$parentCooldown", button, "CooldownFrameTemplate");
cd:SetAllPoints(button);
local icon = button:CreateTexture(nil, "BORDER");
icon:SetAllPoints(button);
icon:CutOffEdges();
local count = button:CreateFontString(nil, "OVERLAY");
count:SetFontObject(NumberFontNormal);
count:SetPoint("TOP", button, "BOTTOM", 0, -2);
button.cd = cd;
button.icon = icon;
button.count = count;
return button;
end
function ButtonReset(self, button)
button:ClearAllPoints();
button:Hide();
end