Skip to content

Commit

Permalink
Cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
ntowle committed Jun 28, 2024
1 parent 76aedd5 commit d0c7ad3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 35 deletions.
52 changes: 25 additions & 27 deletions HideButtonGlow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ local CreateFrame, GetActionInfo, DEFAULT_CHAT_FRAME, Settings = CreateFrame, Ge
-- TWW uses C_Spell, compatibility code for older clients
local GetSpellName = C_Spell and C_Spell.GetSpellName or GetSpellInfo

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

function eventFrame:PLAYER_LOGIN()
function eventFrame:PLAYER_LOGIN(event)
if not HideButtonGlowDB then
HideButtonGlowDB = {}
HideButtonGlowDB.hideAll = false
Expand All @@ -24,13 +24,14 @@ function eventFrame:PLAYER_LOGIN()
-- upgrade db for v3
HideButtonGlowDB.allowedSpells = {}
end
self:UnregisterEvent(event)
end

function eventFrame:ADDON_LOADED(loadedAddon)
function eventFrame:ADDON_LOADED(event, loadedAddon)
if loadedAddon ~= addonName then
return
end
self:UnregisterEvent("ADDON_LOADED")
self:UnregisterEvent(event)
SlashCmdList.HideButtonGlow = function()
Settings.OpenToCategory(addonName)
end
Expand All @@ -43,33 +44,33 @@ function addon:AddMessage(message)
end

function addon:ShouldHideGlow(spellId)
-- check if the 'hide all' option is set
-- check if the "hide all" option is set
if HideButtonGlowDB.hideAll then
for _, spellToAllow in ipairs(HideButtonGlowDB.allowedSpells) do
if spellId == spellToAllow then
for i = 1, #HideButtonGlowDB.allowedSpells do
if spellId == HideButtonGlowDB.allowedSpells[i] then
if HideButtonGlowDB.debugMode then
addon:AddMessage(("Found in allow list, allowing spell glow for %s (ID %d)."):format(GetSpellName(spellId), spellId))
self:AddMessage(("Found in allow list, allowing spell glow for %s (ID %d)."):format(GetSpellName(spellId), spellId))
end
return false
end
end
if HideButtonGlowDB.debugMode then
addon:AddMessage(("Hide All is checked, hiding spell glow for %s (ID %d)."):format(GetSpellName(spellId), spellId))
self:AddMessage(("Hide All is checked, hiding spell glow for %s (ID %d)."):format(GetSpellName(spellId), spellId))
end
return true
end
-- else iterate through filter list
for _, spellToFilter in ipairs(HideButtonGlowDB.spells) do
if spellId == spellToFilter then
for i = 1, #HideButtonGlowDB.spells do
if spellId == HideButtonGlowDB.spells[i] then
if HideButtonGlowDB.debugMode then
addon:AddMessage(("Filter matched, hiding spell glow for %s (ID %d)."):format(GetSpellName(spellId), spellId))
self:AddMessage(("Filter matched, hiding spell glow for %s (ID %d)."):format(GetSpellName(spellId), spellId))
end
return true
end
end
-- else show the glow
if HideButtonGlowDB.debugMode then
addon:AddMessage(("No filters matched, allowing spell glow for %s (ID %d)."):format(GetSpellName(spellId), spellId))
self:AddMessage(("No filters matched, allowing spell glow for %s (ID %d)."):format(GetSpellName(spellId), spellId))
end
return false
end
Expand All @@ -82,10 +83,9 @@ do
local OriginalShowOverlayGlow = LibButtonGlow.ShowOverlayGlow
function LibButtonGlow.ShowOverlayGlow(self)
local spellId = self:GetSpellId()
if spellId and addon:ShouldHideGlow(spellId) then
return
if not spellId or not addon:ShouldHideGlow(spellId) then
return OriginalShowOverlayGlow(self)
end
return OriginalShowOverlayGlow(self)
end
end
end
Expand All @@ -100,10 +100,9 @@ if ElvUI then
local OriginalShowOverlayGlow = LibCustomGlow.ShowOverlayGlow
function LibCustomGlow.ShowOverlayGlow(self)
local spellId = self.GetSpellId and self:GetSpellId()
if spellId and addon:ShouldHideGlow(spellId) then
return
if not spellId or not addon:ShouldHideGlow(spellId) then
return OriginalShowOverlayGlow(self)
end
return OriginalShowOverlayGlow(self)
end
end
end
Expand All @@ -128,19 +127,18 @@ end

-- Blizzard Bars

local function PreventGlow(actionButton)
hooksecurefunc("ActionButton_ShowOverlayGlow", function(actionButton)
if actionButton and actionButton.action then
local spellType, id = GetActionInfo(actionButton.action)
-- only check spell and macro glows
if id and (spellType == "spell" or spellType == "macro") and addon:ShouldHideGlow(id) then
if actionButton.SpellActivationAlert then
-- dragonflight, post 10.0.2
-- Retail, post 10.0.2
actionButton.SpellActivationAlert:Hide()
elseif actionButton.overlay then
-- classic, pre 10.0.2
-- Cata Classic, pre 10.0.2
actionButton.overlay:Hide()
end
end
end
end
hooksecurefunc('ActionButton_ShowOverlayGlow', PreventGlow)
end)
14 changes: 6 additions & 8 deletions options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ local GetSpellInfo = C_Spell and C_Spell.GetSpellInfo or function(spellIdentifie
}
end

local function GetOptions()
LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable(addonName, function()
return {
order = 1,
type = "group",
Expand Down Expand Up @@ -123,8 +123,8 @@ local function GetOptions()
end,
values = function()
local spellNames = {}
for _, spellID in ipairs(HideButtonGlowDB.spells) do
local name = GetSpellName(spellID)
for i = 1, #HideButtonGlowDB.spells do
local name = GetSpellName(HideButtonGlowDB.spells[i])
tinsert(spellNames, name)
end
return spellNames
Expand Down Expand Up @@ -206,8 +206,8 @@ local function GetOptions()
end,
values = function()
local spellNames = {}
for _, spellID in ipairs(HideButtonGlowDB.allowedSpells) do
local name = GetSpellName(spellID)
for i = 1, #HideButtonGlowDB.allowedSpells do
local name = GetSpellName(HideButtonGlowDB.allowedSpells[i])
tinsert(spellNames, name)
end
return spellNames
Expand All @@ -223,7 +223,5 @@ local function GetOptions()
}
}
}
end

LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable(addonName, GetOptions)
end)
LibStub("AceConfigDialog-3.0"):AddToBlizOptions(addonName, nil, nil, "general")

0 comments on commit d0c7ad3

Please sign in to comment.