Skip to content

Commit

Permalink
upvalues, add debug mode, addMessage function
Browse files Browse the repository at this point in the history
  • Loading branch information
ntowle committed Dec 6, 2020
1 parent df515da commit 6bc9313
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 27 deletions.
36 changes: 24 additions & 12 deletions HideButtonGlow.lua
Original file line number Diff line number Diff line change
@@ -1,38 +1,50 @@
local addon = CreateFrame('Frame')
addon.name = "HideButtonGlow"
addon:SetScript('OnEvent', function(self, event, ...)
local addonName, addon = ...

-- globals
local CreateFrame, GetSpellInfo = CreateFrame, GetSpellInfo

local addonFrame = CreateFrame('Frame')
addonFrame:SetScript('OnEvent', function(self, event, ...)
if self[event] then return self[event](...) end
end)
addon:RegisterEvent('PLAYER_LOGIN')
addonFrame:RegisterEvent('PLAYER_LOGIN')

function addon:PLAYER_LOGIN()
function addonFrame:PLAYER_LOGIN()
if not HideButtonGlowDB then
HideButtonGlowDB = {}
HideButtonGlowDB.hideAll = false
HideButtonGlowDB.debugMode = false
HideButtonGlowDB.spells = {}
end
end

function addon:addMessage(message, debugOnly)
if not debugOnly or HideButtonGlowDB.debugMode then
DEFAULT_CHAT_FRAME:AddMessage(message)
end
end

local glowLib = LibStub("LibButtonGlow-1.0", true)
local showGlow = glowLib.ShowOverlayGlow
function glowLib.ShowOverlayGlow(self)
local spellId = self:GetSpellId()
local spellName = GetSpellInfo(spellId)

-- check if the 'hide all' option is set
if HideButtonGlowDB.hideAll then
--print("hiding all")
addon:addMessage("Hide All is checked, hiding spell glow for "..spellName.." (ID"..spellId..").", true)
return
end

-- else iterate through filter list
for _, spellToFilter in ipairs(HideButtonGlowDB.spells) do
--print("checking filter value " .. spellToFilter)
if self:GetSpellId() == spellToFilter then
--print("filter match")
if spellId == spellToFilter then
addon:addMessage("Filter matched, hiding spell glow for "..spellName.." (ID "..spellId..").", true)
return
end
--print("filter didn't match spell id: " .. self:GetSpellId())
end

-- else show the glow
--print("showing glow for spell id: " .. self:GetSpellId())
showGlow(self)
addon:addMessage("No filters matched, allowing spell glow for "..spellName.." (ID "..spellId..").", true)
return showGlow(self)
end
2 changes: 1 addition & 1 deletion HideButtonGlow.toc
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

libs\AceConfig-3.0\AceConfig-3.0.xml

options.lua
HideButtonGlow.lua
options.lua
46 changes: 32 additions & 14 deletions options.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
local addonName = "HideButtonGlow"
local addonName, addon = ...

-- globals
local GetSpellInfo, tinsert, tremove, tContains, tonumber = GetSpellInfo, tinsert, tremove, tContains, tonumber

function GetOptions()
return {
Expand All @@ -11,7 +14,11 @@ function GetOptions()
type = "group",
name = "Options",
args = {
spacer = {order = 1, type = "description", name = ""},
spacer = {
order = 1,
type = "description",
name = ""
},
hideAll = {
order = 2,
type = "toggle",
Expand All @@ -21,17 +28,28 @@ function GetOptions()
return HideButtonGlowDB.hideAll
end,
set = function()
local hide = not HideButtonGlowDB.hideAll
HideButtonGlowDB.hideAll = hide
HideButtonGlowDB.hideAll = not HideButtonGlowDB.hideAll
end
},
header = {
debugMode = {
order = 3,
type = "toggle",
name = "Debug mode",
desc = "Prints all filtered/unfiltered spells to chat. Useful for finding spell IDs, or checking how your settings work.",
get = function()
return HideButtonGlowDB.debugMode
end,
set = function()
HideButtonGlowDB.debugMode = not HideButtonGlowDB.debugMode
end
},
header = {
order = 4,
type = "header",
name = "Filtered Spells"
},
hiddenSpellAdd = {
order = 4,
order = 5,
type = "input",
width = "full",
name = "Add",
Expand All @@ -43,31 +61,31 @@ function GetOptions()
local name = GetSpellInfo(spellId)
if name then
if tContains(HideButtonGlowDB.spells, spellId) then
print(spellId.." already filtered as spell "..name..".")
addon:addMessage("ID "..spellId.." already filtered as spell "..name..".")
else
print("Filtering button glow for spell "..name.." with ID "..spellId..".")
addon:addMessage("Filtering button glow for spell "..name.." with ID "..spellId..".")
tinsert(HideButtonGlowDB.spells, spellId)
end
else
print("Invalid spell ID: "..value)
addon:addMessage("Invalid spell ID: "..value)
end
else
local name, _, _, _, _, _, spellId = GetSpellInfo(value)
if spellId then
if tContains(HideButtonGlowDB.spells, spellId) then
print("\""..value.."\" already filtered as spell "..name.." with ID "..spellId..".")
addon:addMessage("\""..value.."\" already filtered as spell "..name.." with ID "..spellId..".")
else
print("Filtering button glow for \""..value.."\" as spell "..name.." with ID "..spellId..".")
addon:addMessage("Filtering button glow for \""..value.."\" as spell "..name.." with ID "..spellId..".")
tinsert(HideButtonGlowDB.spells, spellId)
end
else
print("Invalid spell name: "..value)
addon:addMessage("Invalid spell name: "..value)
end
end
end
},
hiddenSpellDelete = {
order = 5,
order = 6,
type = "select",
width = "full",
name = "Delete",
Expand All @@ -76,7 +94,7 @@ function GetOptions()
set = function(info, index)
local spellId = HideButtonGlowDB.spells[index]
local name = GetSpellInfo(spellId)
print("Removing button glow filter for spell "..name.." with ID "..spellId..".")
addon:addMessage("Removing button glow filter for spell "..name.." with ID "..spellId..".")
tremove(HideButtonGlowDB.spells, index)
end,
values = function()
Expand Down

0 comments on commit 6bc9313

Please sign in to comment.