From 3e59a03ce98887699f15010c2229d86c79b7181f Mon Sep 17 00:00:00 2001 From: Sumsebrum Date: Tue, 15 Feb 2022 22:59:21 +0100 Subject: [PATCH] disable options for disabled module + (un)register messages when enabled/disabled --- Modules/ArenaCountDown.lua | 18 +++++++++++++++--- Modules/BuffsDebuffs.lua | 37 +++++++++++++++++++++++++++++------- Modules/Castbar.lua | 16 ++++++++++++++-- Modules/Classicon.lua | 20 ++++++++++++++++--- Modules/CombatIndicator.lua | 13 ++++++++++++- Modules/Diminishings.lua | 5 ++++- Modules/Pets.lua | 25 +++++++++++++++++++----- Modules/Powerbar.lua | 30 +++++++++++++++++++++++++---- Modules/Racial.lua | 19 +++++++++++++++--- Modules/RangeCheck.lua | 20 ++++++++++++++++--- Modules/ShadowsightTimer.lua | 14 +++++++++++++- Modules/Trinket.lua | 21 +++++++++++++------- 12 files changed, 198 insertions(+), 40 deletions(-) diff --git a/Modules/ArenaCountDown.lua b/Modules/ArenaCountDown.lua index 6218064..4f7e5df 100644 --- a/Modules/ArenaCountDown.lua +++ b/Modules/ArenaCountDown.lua @@ -47,13 +47,22 @@ function ACDFrame:Initialize() ACDNumOne:SetPoint("CENTER", ACDNumFrame, "CENTER", 0, 0) self.ACDNumOne = ACDNumOne - self:RegisterMessage("JOINED_ARENA") - self:RegisterMessage("ENEMY_SPOTTED") - self:RegisterMessage("UNIT_SPEC") + if Gladdy.db.countdown then + self:RegisterMessage("JOINED_ARENA") + self:RegisterMessage("ENEMY_SPOTTED") + self:RegisterMessage("UNIT_SPEC") + end self.faction = UnitFactionGroup("player") end function ACDFrame:UpdateFrameOnce() + if Gladdy.db.countdown then + self:RegisterMessage("JOINED_ARENA") + self:RegisterMessage("ENEMY_SPOTTED") + self:RegisterMessage("UNIT_SPEC") + else + self:UnregisterAllMessages() + end self.ACDNumFrame:SetFrameStrata(Gladdy.db.arenaCountdownFrameStrata) self.ACDNumFrame:SetFrameLevel(Gladdy.db.arenaCountdownFrameLevel) end @@ -189,6 +198,7 @@ function ACDFrame:GetOptions() max = 512, step = 16, width = "full", + disabled = function() return not Gladdy.db.countdown end, }), headerAuraLevel = { type = "header", @@ -201,6 +211,7 @@ function ACDFrame:GetOptions() order = 6, values = Gladdy.frameStrata, sorting = Gladdy.frameStrataSorting, + disabled = function() return not Gladdy.db.countdown end, }), arenaCountdownFrameLevel = Gladdy:option({ type = "range", @@ -210,6 +221,7 @@ function ACDFrame:GetOptions() step = 1, order = 7, width = "full", + disabled = function() return not Gladdy.db.countdown end, }), } end diff --git a/Modules/BuffsDebuffs.lua b/Modules/BuffsDebuffs.lua index 1574c54..a61fb95 100644 --- a/Modules/BuffsDebuffs.lua +++ b/Modules/BuffsDebuffs.lua @@ -76,13 +76,16 @@ function BuffsDebuffs:Initialize() self.icons = {} self.trackedCC = {} self.framePool = {} - self:RegisterMessage("JOINED_ARENA") - self:RegisterMessage("UNIT_DESTROYED") - self:RegisterMessage("UNIT_DEATH") - self:RegisterMessage("AURA_FADE") - self:RegisterMessage("AURA_GAIN") - self:RegisterMessage("AURA_GAIN_LIMIT") - self:SetScript("OnEvent", BuffsDebuffs.OnEvent) + if Gladdy.db.buffsEnabled then + self:RegisterMessages( + "JOINED_ARENA", + "UNIT_DESTROYED", + "UNIT_DEATH", + "AURA_FADE", + "AURA_GAIN", + "AURA_GAIN_LIMIT") + self:SetScript("OnEvent", BuffsDebuffs.OnEvent) + end spellSchoolToOptionValueTable = { curse = Gladdy.db.buffsBorderColorCurse, magic = Gladdy.db.buffsBorderColorMagic, @@ -290,6 +293,22 @@ local function styleIcon(aura, auraType) aura.stacks:SetTextColor(Gladdy.db.buffsFontColor.r, Gladdy.db.buffsFontColor.g, Gladdy.db.buffsFontColor.b, 1) end +function BuffsDebuffs:UpdateFrameOnce() + if Gladdy.db.buffsEnabled then + self:RegisterMessages( + "JOINED_ARENA", + "UNIT_DESTROYED", + "UNIT_DEATH", + "AURA_FADE", + "AURA_GAIN", + "AURA_GAIN_LIMIT") + self:SetScript("OnEvent", BuffsDebuffs.OnEvent) + else + self:UnregisterAllMessages() + self:SetScript("OnEvent", nil) + end +end + function BuffsDebuffs:UpdateFrame(unit) --DEBUFFS self.frames[unit].debuffFrame:SetHeight(Gladdy.db.buffsIconSize) @@ -485,12 +504,14 @@ function BuffsDebuffs:GetOptions() name = L["Show CC"], desc = L["Shows all debuffs, which are displayed on the ClassIcon as well"], order = 4, + disabled = function() return not Gladdy.db.buffsEnabled end, }), group = { type = "group", childGroups = "tree", name = L["Frame"], order = 5, + disabled = function() return not Gladdy.db.buffsEnabled end, args = { buffs = { type = "group", @@ -919,6 +940,7 @@ function BuffsDebuffs:GetOptions() name = L["Debuff Lists"], type = "group", order = 11, + disabled = function() return not Gladdy.db.buffsEnabled end, childGroups = "tree", args = select(1, Gladdy:GetAuras(AURA_TYPE_DEBUFF)), set = function(info, state) @@ -934,6 +956,7 @@ function BuffsDebuffs:GetOptions() name = L["Buff Lists"], type = "group", order = 12, + disabled = function() return not Gladdy.db.buffsEnabled end, childGroups = "tree", args = select(1, Gladdy:GetAuras(AURA_TYPE_BUFF)), set = function(info, state) diff --git a/Modules/Castbar.lua b/Modules/Castbar.lua index 38f0ff0..24fc6a7 100644 --- a/Modules/Castbar.lua +++ b/Modules/Castbar.lua @@ -48,8 +48,10 @@ local Castbar = Gladdy:NewModule("Cast Bar", 70, { function Castbar:Initialize() self.frames = {} - self:RegisterMessage("UNIT_DEATH") - self:RegisterMessage("JOINED_ARENA") + if Gladdy.db.castBarEnabled then + self:RegisterMessage("UNIT_DEATH") + self:RegisterMessage("JOINED_ARENA") + end end --------------------------- @@ -133,6 +135,15 @@ function Castbar:CreateFrame(unit) self:ResetUnit(unit) end +function Castbar:UpdateFrameOnce() + if Gladdy.db.castBarEnabled then + self:RegisterMessage("UNIT_DEATH") + self:RegisterMessage("JOINED_ARENA") + else + self:UnregisterAllMessages() + end +end + function Castbar:UpdateFrame(unit) local castBar = self.frames[unit] if (not castBar) then @@ -584,6 +595,7 @@ function Castbar:GetOptions() childGroups = "tree", name = L["Frame"], order = 4, + disabled = function() return not Gladdy.db.castBarEnabled end, args = { barFrame = { type = "group", diff --git a/Modules/Classicon.lua b/Modules/Classicon.lua index c419ab8..e20ce46 100644 --- a/Modules/Classicon.lua +++ b/Modules/Classicon.lua @@ -82,9 +82,21 @@ local specIcons = { function Classicon:Initialize() self.frames = {} - self:RegisterMessage("ENEMY_SPOTTED") - self:RegisterMessage("UNIT_DEATH") - self:RegisterMessage("UNIT_SPEC") + if Gladdy.db.classIconEnabled then + self:RegisterMessage("ENEMY_SPOTTED") + self:RegisterMessage("UNIT_DEATH") + self:RegisterMessage("UNIT_SPEC") + end +end + +function Classicon:UpdateFrameOnce() + if Gladdy.db.classIconEnabled then + self:RegisterMessage("ENEMY_SPOTTED") + self:RegisterMessage("UNIT_DEATH") + self:RegisterMessage("UNIT_SPEC") + else + self:UnregisterAllMessages() + end end function Classicon:CreateFrame(unit) @@ -191,6 +203,7 @@ function Classicon:GetOptions() name = L["Show Spec Icon"], desc = L["Shows Spec Icon once spec is detected"], order = 4, + disabled = function() return not Gladdy.db.classIconEnabled end, get = function() return Gladdy.db.classIconSpecIcon end, set = function(_, value) Gladdy.db.classIconSpecIcon = value @@ -210,6 +223,7 @@ function Classicon:GetOptions() childGroups = "tree", name = L["Frame"], order = 4, + disabled = function() return not Gladdy.db.classIconEnabled end, args = { size = { type = "group", diff --git a/Modules/CombatIndicator.lua b/Modules/CombatIndicator.lua index 4ac51ee..276bcaf 100644 --- a/Modules/CombatIndicator.lua +++ b/Modules/CombatIndicator.lua @@ -20,7 +20,9 @@ local CombatIndicator = Gladdy:NewModule("Combat Indicator", nil, { function CombatIndicator:Initialize() self.frames = {} - self:RegisterMessage("JOINED_ARENA") + if Gladdy.db.ciEnabled then + self:RegisterMessage("JOINED_ARENA") + end self.updateInterval = 0.05 self.combatIndicatorIcon = select(3, GetSpellInfo(674)) end @@ -57,6 +59,14 @@ function CombatIndicator:CreateFrame(unit) button.ciFrame = ciFrame end +function CombatIndicator:UpdateFrameOnce() + if Gladdy.db.ciEnabled then + self:RegisterMessage("JOINED_ARENA") + else + self:UnregisterAllMessages() + end +end + function CombatIndicator:UpdateFrame(unit) local button = Gladdy.buttons[unit] local ciFrame = self.frames[unit] @@ -133,6 +143,7 @@ function CombatIndicator:GetOptions() childGroups = "tree", name = L["Frame"], order = 4, + disabled = function() return not Gladdy.db.ciEnabled end, args = { general = { type = "group", diff --git a/Modules/Diminishings.lua b/Modules/Diminishings.lua index a9836bd..32337ef 100644 --- a/Modules/Diminishings.lua +++ b/Modules/Diminishings.lua @@ -79,7 +79,7 @@ end function Diminishings:Initialize() self.frames = {} - self:RegisterMessage("UNIT_DEATH", "ResetUnit", "AURA_FADE", "UNIT_DESTROYED") + self:RegisterMessage("UNIT_DESTROYED") end function Diminishings:CreateFrame(unit) @@ -434,6 +434,7 @@ function Diminishings:GetOptions() name = L["DR Duration"], desc = L["Change the DR Duration in seconds (DR is dynamic between 15-20s)"], order = 4, + disabled = function() return not Gladdy.db.drEnabled end, min = 15, max = 20, step = .1, @@ -443,6 +444,7 @@ function Diminishings:GetOptions() childGroups = "tree", name = L["Frame"], order = 5, + disabled = function() return not Gladdy.db.drEnabled end, args = { icon = { type = "group", @@ -781,6 +783,7 @@ function Diminishings:GetOptions() type = "group", name = L["Categories"], order = 6, + disabled = function() return not Gladdy.db.drEnabled end, args = Diminishings:CategoryOptions(), }, } diff --git a/Modules/Pets.lua b/Modules/Pets.lua index fc703b0..5a7eca1 100644 --- a/Modules/Pets.lua +++ b/Modules/Pets.lua @@ -31,11 +31,25 @@ local Pets = Gladdy:NewModule("Pets", nil, { function Pets:Initialize() self.frames = {} - self:RegisterMessage("JOINED_ARENA") - self:RegisterMessage("PET_SPOTTED") - self:RegisterMessage("PET_DESTROYED") - self:RegisterMessage("PET_STEALTH") - self:RegisterMessage("ENEMY_SPOTTED") + if Gladdy.db.petEnabled then + self:RegisterMessage("JOINED_ARENA") + self:RegisterMessage("PET_SPOTTED") + self:RegisterMessage("PET_DESTROYED") + self:RegisterMessage("PET_STEALTH") + self:RegisterMessage("ENEMY_SPOTTED") + end +end + +function Pets:UpdateFrameOnce() + if Gladdy.db.petEnabled then + self:RegisterMessage("JOINED_ARENA") + self:RegisterMessage("PET_SPOTTED") + self:RegisterMessage("PET_DESTROYED") + self:RegisterMessage("PET_STEALTH") + self:RegisterMessage("ENEMY_SPOTTED") + else + self:UnregisterAllMessages() + end end function Pets:JOINED_ARENA() @@ -380,6 +394,7 @@ function Pets:GetOptions() childGroups = "tree", name = L["Frame"], order = 3, + disabled = function() return not Gladdy.db.petEnabled end, args = { general = { type = "group", diff --git a/Modules/Powerbar.lua b/Modules/Powerbar.lua index 4e99810..5f48021 100644 --- a/Modules/Powerbar.lua +++ b/Modules/Powerbar.lua @@ -29,10 +29,23 @@ local Powerbar = Gladdy:NewModule("Power Bar", 90, { function Powerbar:Initialize() self.frames = {} - self:RegisterMessage("ENEMY_SPOTTED") - self:RegisterMessage("UNIT_SPEC") - self:RegisterMessage("UNIT_DEATH") - self:RegisterMessage("UNIT_DESTROYED") + if Gladdy.db.powerBarEnabled then + self:RegisterMessage("ENEMY_SPOTTED") + self:RegisterMessage("UNIT_SPEC") + self:RegisterMessage("UNIT_DEATH") + self:RegisterMessage("UNIT_DESTROYED") + end +end + +function Powerbar:UpdateFrameOnce() + if Gladdy.db.powerBarEnabled then + self:RegisterMessage("ENEMY_SPOTTED") + self:RegisterMessage("UNIT_SPEC") + self:RegisterMessage("UNIT_DEATH") + self:RegisterMessage("UNIT_DESTROYED") + else + self:UnregisterAllMessages() + end end function Powerbar:CreateFrame(unit) @@ -147,8 +160,16 @@ function Powerbar:UpdateFrame(unit) if not Gladdy.db.powerBarEnabled then powerBar:Hide() + powerBar:UnregisterEvent("UNIT_POWER_UPDATE") + powerBar:UnregisterEvent("UNIT_MAXPOWER") + powerBar:UnregisterEvent("UNIT_DISPLAYPOWER") + powerBar:SetScript("OnEvent", nil) return else + powerBar:RegisterUnitEvent("UNIT_POWER_UPDATE", unit) + powerBar:RegisterUnitEvent("UNIT_MAXPOWER", unit) + powerBar:RegisterUnitEvent("UNIT_DISPLAYPOWER", unit) + powerBar:SetScript("OnEvent", Powerbar.OnEvent) powerBar:Show() end powerBar.bg:SetTexture(Gladdy:SMFetch("statusbar", "powerBarTexture")) @@ -351,6 +372,7 @@ function Powerbar:GetOptions() childGroups = "tree", name = L["Frame"], order = 4, + disabled = function() return not Gladdy.db.powerBarEnabled end, args = { general = { type = "group", diff --git a/Modules/Racial.lua b/Modules/Racial.lua index ec5e237..e9dff61 100644 --- a/Modules/Racial.lua +++ b/Modules/Racial.lua @@ -26,9 +26,21 @@ local Racial = Gladdy:NewModule("Racial", 79, { function Racial:Initialize() self.frames = {} - self:RegisterMessage("JOINED_ARENA") - self:RegisterMessage("ENEMY_SPOTTED") - self:RegisterMessage("RACIAL_USED") + if Gladdy.db.racialEnabled then + self:RegisterMessage("JOINED_ARENA") + self:RegisterMessage("ENEMY_SPOTTED") + self:RegisterMessage("RACIAL_USED") + end +end + +function Racial:UpdateFrameOnce() + if Gladdy.db.racialEnabled then + self:RegisterMessage("JOINED_ARENA") + self:RegisterMessage("ENEMY_SPOTTED") + self:RegisterMessage("RACIAL_USED") + else + self:UnregisterAllMessages() + end end local function iconTimer(self,elapsed) @@ -235,6 +247,7 @@ function Racial:GetOptions() childGroups = "tree", name = L["Frame"], order = 4, + disabled = function() return not Gladdy.db.racialEnabled end, args = { general = { type = "group", diff --git a/Modules/RangeCheck.lua b/Modules/RangeCheck.lua index 3e95600..36cdcfc 100644 --- a/Modules/RangeCheck.lua +++ b/Modules/RangeCheck.lua @@ -52,12 +52,24 @@ local RangeCheck = Gladdy:NewModule("Range Check", nil, { }) function RangeCheck:Initialize() - self:RegisterMessage("JOINED_ARENA") - self:RegisterMessage("ENEMY_STEALTH") - self:RegisterMessage("ENEMY_SPOTTED") + if Gladdy.db.rangeCheckEnabled then + self:RegisterMessage("JOINED_ARENA") + self:RegisterMessage("ENEMY_STEALTH") + self:RegisterMessage("ENEMY_SPOTTED") + end self.playerClass = select(2, UnitClass("player")) end +function RangeCheck:UpdateFrameOnce() + if Gladdy.db.rangeCheckEnabled then + self:RegisterMessage("JOINED_ARENA") + self:RegisterMessage("ENEMY_STEALTH") + self:RegisterMessage("ENEMY_SPOTTED") + else + self:UnregisterAllMessages() + end +end + function RangeCheck:Reset() self.test = nil end @@ -268,6 +280,7 @@ function RangeCheck:GetOptions() childGroups = "tree", name = L["General"], order = 5, + disabled = function() return not Gladdy.db.rangeCheckEnabled end, args = { general = { type = "group", @@ -340,6 +353,7 @@ function RangeCheck:GetOptions() childGroups = "tree", name = L["Spells"], order = 5, + disabled = function() return not Gladdy.db.rangeCheckEnabled end, args = RangeCheck:GetSpells(), }, } diff --git a/Modules/ShadowsightTimer.lua b/Modules/ShadowsightTimer.lua index 8843cc2..9606f86 100644 --- a/Modules/ShadowsightTimer.lua +++ b/Modules/ShadowsightTimer.lua @@ -34,8 +34,10 @@ end function ShadowsightTimer:Initialize() self.locale = Gladdy:GetArenaTimer() - self:RegisterMessage("JOINED_ARENA") self:CreateAnchor() + if Gladdy.db.shadowsightTimerEnabled then + self:RegisterMessage("JOINED_ARENA") + end end function ShadowsightTimer:Reset() @@ -106,6 +108,12 @@ function ShadowsightTimer:CreateAnchor() end function ShadowsightTimer:UpdateFrameOnce() + if Gladdy.db.shadowsightTimerEnabled then + self:RegisterMessage("JOINED_ARENA") + else + self:UnregisterAllMessages() + end + self.anchor:EnableMouse(not Gladdy.db.shadowsightTimerLocked) self.anchor:SetFrameStrata(Gladdy.db.shadowsightTimerFrameStrata) @@ -299,23 +307,27 @@ function ShadowsightTimer:GetOptions() name = L["Locked"], --desc = L["Turns countdown before the start of an arena match on/off."], order = 4, + disabled = function() return not Gladdy.db.shadowsightTimerEnabled end, }), shadowsightTimerShowTwoTimer = Gladdy:option({ type = "toggle", name = L["Show two timers"], order = 5, + disabled = function() return not Gladdy.db.shadowsightTimerEnabled end, }), shadowsightAnnounce = Gladdy:option({ type = "toggle", name = L["Announce"], --desc = L["Turns countdown before the start of an arena match on/off."], order = 6, + disabled = function() return not Gladdy.db.shadowsightTimerEnabled end, }), group = { type = "group", childGroups = "tree", name = L["Frame"], order = 7, + disabled = function() return not Gladdy.db.shadowsightTimerEnabled end, args = { general = { type = "group", diff --git a/Modules/Trinket.lua b/Modules/Trinket.lua index 0c316e1..13f7f49 100644 --- a/Modules/Trinket.lua +++ b/Modules/Trinket.lua @@ -29,8 +29,17 @@ local Trinket = Gladdy:NewModule("Trinket", 80, { function Trinket:Initialize() self.frames = {} + if Gladdy.db.trinketEnabled then + self:RegisterMessage("JOINED_ARENA") + end +end - self:RegisterMessage("JOINED_ARENA") +function Trinket:UpdateFrameOnce() + if Gladdy.db.trinketEnabled then + self:RegisterMessage("JOINED_ARENA") + else + self:UnregisterAllMessages() + end end local function iconTimer(self, elapsed) @@ -272,6 +281,7 @@ function Trinket:GetOptions() name = L["Colored trinket"], desc = L["Shows a solid colored icon when off/off CD."], order = 4, + disabled = function() return not Gladdy.db.trinketEnabled end, }), trinketColoredCd = Gladdy:colorOption({ type = "color", @@ -279,9 +289,7 @@ function Trinket:GetOptions() desc = L["Color of the border"], order = 5, hasAlpha = true, - disabled = function() - return not Gladdy.db.trinketColored - end, + disabled = function() return not Gladdy.db.trinketEnabled end, }), trinketColoredNoCd = Gladdy:colorOption({ type = "color", @@ -289,15 +297,14 @@ function Trinket:GetOptions() desc = L["Color of the border"], order = 6, hasAlpha = true, - disabled = function() - return not Gladdy.db.trinketColored - end, + disabled = function() return not Gladdy.db.trinketEnabled end, }), group = { type = "group", childGroups = "tree", name = L["Frame"], order = 5, + disabled = function() return not Gladdy.db.trinketEnabled end, args = { general = { type = "group",