So, I'm currently trying to make a button that cancels aura on right mouse button and here's what I've got atm
Lua Code:
local button = CreateFrame("Button", nil, UIParent, "SecureHandlerClickTemplate");
button:RegisterEvent("PLAYER_ENTERING_WORLD");
button:RegisterUnitEvent("UNIT_AURA", "player");
button:RegisterForClicks("RightButtonUp");
button:SetSize(50, 50);
button:SetPoint("TOP", 0, -150);
button:SetScript("OnEvent", function(self, event, ...)
if event == "PLAYER_ENTERING_WORLD" or event == "UNIT_AURA" then
if event == "PLAYER_ENTERING_WORLD" then
self:UnregisterEvent("PLAYER_ENTERING_WORLD");
end
local spellName = GetSpellInfo(self.spellID);
local _, _, _, count, _, duration, expires = UnitBuff("player", spellName);
local cd = self.cd;
if duration and duration > 0 then
cd:SetCooldown(expires - duration, duration);
cd:Show();
self.icon:SetDesaturated(false);
self.duration = duration;
else
cd:Hide();
self.icon:SetDesaturated(true);
self.duration = nil;
end
self.count:SetText((count and count > 1) and count or "");
end
end);
button:SetAttribute("_onclick", [=[
if button == "RightButton" and not down then
local name = self:GetAttribute("spellName");
local cd = self:GetFrameRef("cd");
if cd:IsShown() then
CancelUnitBuff("player", name);
end
end
]=]);
button.spellID = 241846;
button:SetAttribute("spellName", GetSpellInfo(button.spellID));
local cd = CreateFrame("Cooldown", nil, button, "CooldownFrameTemplate");
cd:SetAllPoints(button);
cd:SetReverse(true);
cd:SetDrawEdge(true);
cd:SetHideCountdownNumbers(false);
button:SetFrameRef("cd", cd);
It currently fails at L#42 where I check cd's visibility.
Would that be because cd itself is not a SecureHandler template object?