From 4ae95483898a9177bf4c1d164c19a640408ae1a9 Mon Sep 17 00:00:00 2001 From: avitasia Date: Wed, 18 Mar 2026 08:19:38 -0700 Subject: [PATCH] avoid saving/restoring some of the event options toggled by other addons --- Localization.lua | 4 +++ helper.lua | 31 +++++++++++++++++++ settings.lua | 79 +++++++++++++++++++++++++++++++----------------- 3 files changed, 86 insertions(+), 28 deletions(-) diff --git a/Localization.lua b/Localization.lua index 34a370b..287fa19 100644 --- a/Localization.lua +++ b/Localization.lua @@ -69,6 +69,8 @@ L:RegisterTranslations("enUS", function() ["Advanced options"] = true, ["Collection of various advanced options"] = true, + ["Spell Events"] = true, + ["Controls optional spell and combat event CVars."] = true, ["Double Cast to End Channel Early"] = true, ["Whether to allow double casting a spell within 350ms to end channeling on the next tick. Takes into account your ChannelLatencyReductionPercentage."] = true, @@ -249,6 +251,8 @@ L:RegisterTranslations("zhCN", function() ["Advanced options"] = "高级选项", ["Collection of various advanced options"] = "各类高级选项集合", + ["Spell Events"] = "法术事件", + ["Controls optional spell and combat event CVars."] = "控制可选的法术和战斗事件 CVar。", ["Double Cast to End Channel Early"] = "双重施法提前结束引导", ["Whether to allow double casting a spell within 350ms to end channeling on the next tick. Takes into account your ChannelLatencyReductionPercentage."] = "是否允许350毫秒内双重施法以在下一个伤害周期提前结束引导。受引导延迟削减比例影响。", diff --git a/helper.lua b/helper.lua index ed7d350..6f6a050 100644 --- a/helper.lua +++ b/helper.lua @@ -96,6 +96,18 @@ function PrintBuffs(unit) end end +function PrintAuras(unit) + local auras = GetUnitField(unit, "aura") + local applications = GetUnitField(unit, "auraApplications") + if not auras then return end + for i, auraId in ipairs(auras) do + local stacks = (applications[i] or 0) + 1 + if auraId > 0 then + print(tostring(i) .. " " .. tostring(auraId) .. " x" .. tostring(stacks)) + end + end +end + function PrintUnitData(unit) local data = GetUnitData(unit) if data then @@ -916,3 +928,22 @@ end --Nampower:RegisterEvent("SPELL_DISPEL_BY_SELF", onSpellDispel) --Nampower:RegisterEvent("SPELL_DISPEL_BY_OTHER", onSpellDispel) + +-- PrintSpellRange(rangeIndex) +-- Prints the SpellRange DBC record for the given index using GetSpellRangeData. +-- GetSpellRangeData returns: minRange, maxRange, flags, name +function PrintSpellRange(rangeIndex) + if not GetSpellRangeData then + print("GetSpellRangeData is not available") + return + end + local minRange, maxRange, flags, name = GetSpellRangeData(rangeIndex) + if minRange == nil then + print(string.format("PrintSpellRange(%d): no record found", rangeIndex)) + return + end + print(string.format( + "SpellRange[%d]: name=%q min=%.2f max=%.2f flags=0x%08X", + rangeIndex, tostring(name), minRange, maxRange, flags + )) +end diff --git a/settings.lua b/settings.lua index 76df103..416a2e4 100644 --- a/settings.lua +++ b/settings.lua @@ -18,6 +18,30 @@ Nampower:RegisterDefaults("profile", { }) Nampower.frame = CreateFrame("Frame", "Nampower", UIParent) +local DISPLAY_ONLY_SETTINGS = { + NP_EnableAuraCastEvents = true, + NP_EnableAutoAttackEvents = true, + NP_EnableSpellStartEvents = true, + NP_EnableSpellGoEvents = true, + NP_EnableSpellHealEvents = true, + NP_EnableSpellEnergizeEvents = true, + NP_EnableUnitEventsPet = true, + NP_EnableUnitEventsParty = true, + NP_EnableUnitEventsRaid = true, + NP_EnableUnitEventsMouseover = true, + NP_EnableUnitEventsGuid = true, +} + +local function isProfileManagedSetting(settingKey) + return string.find(settingKey, "NP_") == 1 and not DISPLAY_ONLY_SETTINGS[settingKey] +end + +local function clearDisplayOnlyProfileSettings() + for settingKey in pairs(DISPLAY_ONLY_SETTINGS) do + Nampower.db.profile[settingKey] = nil + end +end + function Nampower:HasMinimumVersion(major, minor, patch) if GetNampowerVersion then local installedMajor, installedMinor, installedPatch = GetNampowerVersion() @@ -116,33 +140,33 @@ end -- used when turning on per character settings function Nampower:SavePerCharacterSettings() for settingKey, settingData in pairs(Nampower.cmdtable.args) do - if string.find(settingKey, "NP_") == 1 then + if isProfileManagedSetting(settingKey) then settingData.set(settingData.get()) -- trigger the set function for each setting with the current value end end for settingKey, settingData in pairs(Nampower.cmdtable.args.queue_windows.args) do - if string.find(settingKey, "NP_") == 1 then + if isProfileManagedSetting(settingKey) then settingData.set(settingData.get()) -- trigger the set function for each setting with the current value end end for settingKey, settingData in pairs(Nampower.cmdtable.args.advanced_options.args) do - if string.find(settingKey, "NP_") == 1 then + if isProfileManagedSetting(settingKey) then settingData.set(settingData.get()) -- trigger the set function for each setting with the current value end end if Nampower.cmdtable.args.advanced_options.args.unit_events then for settingKey, settingData in pairs(Nampower.cmdtable.args.advanced_options.args.unit_events.args) do - if string.find(settingKey, "NP_") == 1 then + if isProfileManagedSetting(settingKey) then settingData.set(settingData.get()) -- trigger the set function for each setting with the current value end end end for settingKey, settingData in pairs(Nampower.cmdtable.args.qol_options.args) do - if string.find(settingKey, "NP_") == 1 then + if isProfileManagedSetting(settingKey) then settingData.set(settingData.get()) -- trigger the set function for each setting with the current value end end @@ -159,7 +183,7 @@ end function Nampower:ApplySavedSettings() for settingKey, settingData in pairs(Nampower.cmdtable.args) do -- only apply settings that are prefixed with NP_ - if string.find(settingKey, "NP_") == 1 then + if isProfileManagedSetting(settingKey) then if Nampower.db.profile[settingKey]~= nil then settingData.set(Nampower.db.profile[settingKey]) end @@ -168,7 +192,7 @@ function Nampower:ApplySavedSettings() for settingKey, settingData in pairs(Nampower.cmdtable.args.queue_windows.args) do -- only apply settings that are prefixed with NP_ - if string.find(settingKey, "NP_") == 1 then + if isProfileManagedSetting(settingKey) then if Nampower.db.profile[settingKey]~= nil then settingData.set(Nampower.db.profile[settingKey]) end @@ -177,7 +201,7 @@ function Nampower:ApplySavedSettings() for settingKey, settingData in pairs(Nampower.cmdtable.args.advanced_options.args) do -- only apply settings that are prefixed with NP_ - if string.find(settingKey, "NP_") == 1 then + if isProfileManagedSetting(settingKey) then if Nampower.db.profile[settingKey]~= nil then settingData.set(Nampower.db.profile[settingKey]) end @@ -187,7 +211,7 @@ function Nampower:ApplySavedSettings() if Nampower.cmdtable.args.advanced_options.args.unit_events then for settingKey, settingData in pairs(Nampower.cmdtable.args.advanced_options.args.unit_events.args) do -- only apply settings that are prefixed with NP_ - if string.find(settingKey, "NP_") == 1 then + if isProfileManagedSetting(settingKey) then if Nampower.db.profile[settingKey]~= nil then settingData.set(Nampower.db.profile[settingKey]) end @@ -197,7 +221,7 @@ function Nampower:ApplySavedSettings() for settingKey, settingData in pairs(Nampower.cmdtable.args.qol_options.args) do -- only apply settings that are prefixed with NP_ - if string.find(settingKey, "NP_") == 1 then + if isProfileManagedSetting(settingKey) then if Nampower.db.profile[settingKey]~= nil then settingData.set(Nampower.db.profile[settingKey]) end @@ -214,6 +238,8 @@ function Nampower:ApplySavedSettings() end function Nampower:OnEnable() + clearDisplayOnlyProfileSettings() + Nampower.queued_spell:EnableMouse(Nampower.db.profile.queued_spell_enable_mouse) -- set scale @@ -662,7 +688,15 @@ Nampower.cmdtable = { Nampower.db.profile.NP_ChannelLatencyReductionPercentage = v SetCVar("NP_ChannelLatencyReductionPercentage", v) end, - } + }, + spell_events = { + type = "group", + name = L["Spell Events"], + desc = L["Controls optional spell and combat event CVars."], + order = 150, + args = { + }, + }, }, }, spacerc = { @@ -870,7 +904,7 @@ if Nampower:HasMinimumVersion(2, 20, 0) then end, } - Nampower.cmdtable.args.advanced_options.args.NP_EnableAuraCastEvents = { + Nampower.cmdtable.args.advanced_options.args.spell_events.args.NP_EnableAuraCastEvents = { type = "toggle", name = L["Enable Aura Cast Events"], desc = L["Whether to enable AURA_CAST_ON_SELF and AURA_CAST_ON_OTHER events."], @@ -879,7 +913,6 @@ if Nampower:HasMinimumVersion(2, 20, 0) then return GetCVar("NP_EnableAuraCastEvents") == "1" end, set = function(v) - Nampower.db.profile.NP_EnableAuraCastEvents = v if v == true then SetCVar("NP_EnableAuraCastEvents", "1") else @@ -890,7 +923,7 @@ if Nampower:HasMinimumVersion(2, 20, 0) then end if Nampower:HasMinimumVersion(2, 24, 0) then - Nampower.cmdtable.args.advanced_options.args.NP_EnableAutoAttackEvents = { + Nampower.cmdtable.args.advanced_options.args.spell_events.args.NP_EnableAutoAttackEvents = { type = "toggle", name = L["Enable Auto Attack Events"], desc = L["Whether to enable AUTO_ATTACK_SELF and AUTO_ATTACK_OTHER events."], @@ -899,7 +932,6 @@ if Nampower:HasMinimumVersion(2, 24, 0) then return GetCVar("NP_EnableAutoAttackEvents") == "1" end, set = function(v) - Nampower.db.profile.NP_EnableAutoAttackEvents = v if v == true then SetCVar("NP_EnableAutoAttackEvents", "1") else @@ -910,7 +942,7 @@ if Nampower:HasMinimumVersion(2, 24, 0) then end if Nampower:HasMinimumVersion(2, 25, 0) then - Nampower.cmdtable.args.advanced_options.args.NP_EnableSpellStartEvents = { + Nampower.cmdtable.args.advanced_options.args.spell_events.args.NP_EnableSpellStartEvents = { type = "toggle", name = L["Enable Spell Start Events"], desc = L["Whether to enable SPELL_START_SELF and SPELL_START_OTHER events."], @@ -919,7 +951,6 @@ if Nampower:HasMinimumVersion(2, 25, 0) then return GetCVar("NP_EnableSpellStartEvents") == "1" end, set = function(v) - Nampower.db.profile.NP_EnableSpellStartEvents = v if v == true then SetCVar("NP_EnableSpellStartEvents", "1") else @@ -928,7 +959,7 @@ if Nampower:HasMinimumVersion(2, 25, 0) then end, } - Nampower.cmdtable.args.advanced_options.args.NP_EnableSpellGoEvents = { + Nampower.cmdtable.args.advanced_options.args.spell_events.args.NP_EnableSpellGoEvents = { type = "toggle", name = L["Enable Spell Go Events"], desc = L["Whether to enable SPELL_GO_SELF and SPELL_GO_OTHER events."], @@ -937,7 +968,6 @@ if Nampower:HasMinimumVersion(2, 25, 0) then return GetCVar("NP_EnableSpellGoEvents") == "1" end, set = function(v) - Nampower.db.profile.NP_EnableSpellGoEvents = v if v == true then SetCVar("NP_EnableSpellGoEvents", "1") else @@ -948,7 +978,7 @@ if Nampower:HasMinimumVersion(2, 25, 0) then end if Nampower:HasMinimumVersion(2, 26, 0) then - Nampower.cmdtable.args.advanced_options.args.NP_EnableSpellHealEvents = { + Nampower.cmdtable.args.advanced_options.args.spell_events.args.NP_EnableSpellHealEvents = { type = "toggle", name = L["Enable Spell Heal Events"], desc = L["Whether to enable SPELL_HEAL_BY_SELF, SPELL_HEAL_BY_OTHER, and SPELL_HEAL_ON_SELF events."], @@ -957,7 +987,6 @@ if Nampower:HasMinimumVersion(2, 26, 0) then return GetCVar("NP_EnableSpellHealEvents") == "1" end, set = function(v) - Nampower.db.profile.NP_EnableSpellHealEvents = v if v == true then SetCVar("NP_EnableSpellHealEvents", "1") else @@ -966,7 +995,7 @@ if Nampower:HasMinimumVersion(2, 26, 0) then end, } - Nampower.cmdtable.args.advanced_options.args.NP_EnableSpellEnergizeEvents = { + Nampower.cmdtable.args.advanced_options.args.spell_events.args.NP_EnableSpellEnergizeEvents = { type = "toggle", name = L["Enable Spell Energize Events"], desc = L["Whether to enable SPELL_ENERGIZE_BY_SELF, SPELL_ENERGIZE_BY_OTHER, and SPELL_ENERGIZE_ON_SELF events."], @@ -975,7 +1004,6 @@ if Nampower:HasMinimumVersion(2, 26, 0) then return GetCVar("NP_EnableSpellEnergizeEvents") == "1" end, set = function(v) - Nampower.db.profile.NP_EnableSpellEnergizeEvents = v if v == true then SetCVar("NP_EnableSpellEnergizeEvents", "1") else @@ -1001,7 +1029,6 @@ if Nampower:HasMinimumVersion(2, 39, 0) then return GetCVar("NP_EnableUnitEventsPet") == "1" end, set = function(v) - Nampower.db.profile.NP_EnableUnitEventsPet = v if v == true then SetCVar("NP_EnableUnitEventsPet", "1") else @@ -1018,7 +1045,6 @@ if Nampower:HasMinimumVersion(2, 39, 0) then return GetCVar("NP_EnableUnitEventsParty") == "1" end, set = function(v) - Nampower.db.profile.NP_EnableUnitEventsParty = v if v == true then SetCVar("NP_EnableUnitEventsParty", "1") else @@ -1035,7 +1061,6 @@ if Nampower:HasMinimumVersion(2, 39, 0) then return GetCVar("NP_EnableUnitEventsRaid") == "1" end, set = function(v) - Nampower.db.profile.NP_EnableUnitEventsRaid = v if v == true then SetCVar("NP_EnableUnitEventsRaid", "1") else @@ -1052,7 +1077,6 @@ if Nampower:HasMinimumVersion(2, 39, 0) then return GetCVar("NP_EnableUnitEventsMouseover") == "1" end, set = function(v) - Nampower.db.profile.NP_EnableUnitEventsMouseover = v if v == true then SetCVar("NP_EnableUnitEventsMouseover", "1") else @@ -1069,7 +1093,6 @@ if Nampower:HasMinimumVersion(2, 39, 0) then return GetCVar("NP_EnableUnitEventsGuid") == "1" end, set = function(v) - Nampower.db.profile.NP_EnableUnitEventsGuid = v if v == true then SetCVar("NP_EnableUnitEventsGuid", "1") else