This creates a SavedVariable and a simple options panel.
Be sure to add this to your ToC to flag your SavedVariable for saving.
Code:
## SavedVariables: BuffOff_Options
Lua Code:
local AddOn_Name=...;-- Grab our AddOn's name passed in from the loading process (This is basically our folder's name)
local AddOn_Title=select(2,GetAddOnInfo(AddOn_Name)) or AddOn_Name;-- Attempt to retrieve our "Title" tag from our ToC if it's set
BuffOff_Options={-- Declare our SavedVariable
TargetFrameBuffs=false;
FocusFrameBuffs=false;
};
-- Options Panel Layout
local OptionsPanel=CreateFrame("Frame");
local TitleText=OptionsPanel:CreateFontString(nil,"OVERLAY","GameFontNormal");
TitleText:SetPoint("TOP",0,-32);
TitleText:SetText(AddOn_Title);
local TargetFrame_HideBuffs=CreateFrame("CheckButton",nil,OptionsPanel,"UICheckButtonTemplate");
TargetFrame_HideBuffs:SetPoint("TOPLEFT",24,-48);
TargetFrame_HideBuffs.text:SetText("Hide TargetFrame Buffs");
TargetFrame_HideBuffs:SetScript("OnClick",function(self)-- Fire on user click (Toggles check status)
BuffOff_Options.TargetFrameBuffs=self:GetChecked();-- Update SavedVariable
TargetFrame_UpdateAuras(TargetFrame);-- Trigger aura update
end);
local FocusFrame_HideBuffs=CreateFrame("CheckButton",nil,OptionsPanel,"UICheckButtonTemplate");
FocusFrame_HideBuffs:SetPoint("TOPLEFT",24,-72);
FocusFrame_HideBuffs.text:SetText("Hide FocusFrame Buffs");
FocusFrame_HideBuffs:SetScript("OnClick",function(self)-- Fire on user click (Toggles check status)
BuffOff_Options.FocusFrameBuffs=self:GetChecked();-- Update SavedVariable
TargetFrame_UpdateAuras(FocusFrame);-- Trigger aura update
end);
-- Options Panel Registration & Callbacks
OptionsPanel.name=AddOn_Title;-- Category name
OptionsPanel.refresh=function()-- Runs when our Options Panel is shown
TargetFrame_HideBuffs:SetChecked(BuffOff_Options.TargetFrameBuffs or false);
FocusFrame_HideBuffs:SetChecked(BuffOff_Options.FocusFrameBuffs or false);
end;
InterfaceOptions_AddCategory(OptionsPanel);-- Register our Options Panel
-- Hook
hooksecurefunc("TargetFrame_UpdateAuras",function(self)
if self~=TargetFrame and self~=FocusFrame then return; end-- Filter for these two frames
local framename=self:GetName();
if not BuffOff_Options[framename.."Buffs"] then return; end-- Read from our SavedVariable
for index=1,MAX_TARGET_BUFFS do
local buff=_G[framename.."Buff"..index];
if buff then
buff:Hide();
else break; end
end
for index=1,MAX_TARGET_DEBUFFS do
local debuff=_G[framename.."Debuff"..index];
if debuff then
debuff:Hide();
else break; end
end
end)