Give pfUI its own EventRegistry and move event-only frames onto it

pfUI.events was a bare CallbackRegistry for pfUI's custom events. Build it
from ClassicAPI's EventRegistry instead, so the same object also takes game
events through RegisterFrameEventAndCallback, sharing one frame for all of
them.

Move the frames that existed only to listen for a few events onto it:
libspell, focus, pixelperfect, innervatecall, loothistory, unusable,
equipmentmanager (bank + window refresh), the actionbar grid, updatenotify,
turtle-wow's steady shot, nampower's spell queue, superwow's group tracking
and unitxp's notifications, plus newitem and mapreveal, which used the
global EventRegistry. Handlers take their payload as arguments instead of
the event/arg globals, and the per-frame PLAYER_LOGOUT teardown goes away,
since the registry unregisters its frame on logout.
This commit is contained in:
Brues
2026-10-30 12:37:56 -05:00
parent b0f9b7b993
commit f37ea00226
16 changed files with 101 additions and 166 deletions
+33 -36
View File
@@ -12,44 +12,41 @@ pfUI:RegisterModule("updatenotify", function ()
local localbranch = "main"
local versionmsg = "VERSION:" .. localversion .. ":" .. localbranch
pfUI.updater = CreateFrame("Frame")
pfUI.updater:RegisterEvent("CHAT_MSG_ADDON")
pfUI.updater:RegisterEvent("PLAYER_ENTERING_WORLD")
pfUI.updater:RegisterEvent("PARTY_MEMBERS_CHANGED")
pfUI.updater:SetScript("OnEvent", function()
if event == "CHAT_MSG_ADDON" and arg1 == ADDON_PREFIX then
local v, rv, branch = pfUI.api.strsplit(":", arg2)
rv = tonumber(rv)
-- only process VERSION messages from the same branch
-- messages without a branch tag (old versions) are ignored
if v == "VERSION" and rv and branch == localbranch then
if rv > localversion then
pfUI_init.updateavailable = rv
end
end
end
pfUI.events:RegisterFrameEventAndCallback("CHAT_MSG_ADDON", function(_, prefix, message)
if prefix ~= ADDON_PREFIX then return end
if event == "PARTY_MEMBERS_CHANGED" then
local groupsize = IsInRaid() and GetNumRaidMembers() or IsInGroup() and GetNumPartyMembers() or 0
if ( this.group or 0 ) < groupsize then
for _, chan in pairs(groupchannels) do
SendAddonMessage(ADDON_PREFIX, versionmsg, chan)
end
end
this.group = groupsize
end
if event == "PLAYER_ENTERING_WORLD" then
if not alreadyshown and localversion < remoteversion then
DEFAULT_CHAT_FRAME:AddMessage(string.format(T["|cff33ffccpf|rUI: New version available! Get it at %s"], GetAddOnMetadata(pfUI.name, "X-Website") .. "/releases"))
DEFAULT_CHAT_FRAME:AddMessage(T["|cffddddddIt's always safe to upgrade |cff33ffccpf|rUI. |cffddddddYou won't lose any of your configuration."])
pfUI_init.updateavailable = localversion
alreadyshown = true
end
for _, chan in pairs(loginchannels) do
SendAddonMessage(ADDON_PREFIX, versionmsg, chan)
local v, rv, branch = pfUI.api.strsplit(":", message)
rv = tonumber(rv)
-- only process VERSION messages from the same branch
-- messages without a branch tag (old versions) are ignored
if v == "VERSION" and rv and branch == localbranch then
if rv > localversion then
pfUI_init.updateavailable = rv
end
end
end)
local group = 0
pfUI.events:RegisterFrameEventAndCallback("PARTY_MEMBERS_CHANGED", function()
local groupsize = IsInRaid() and GetNumRaidMembers() or IsInGroup() and GetNumPartyMembers() or 0
if group < groupsize then
for _, chan in pairs(groupchannels) do
SendAddonMessage(ADDON_PREFIX, versionmsg, chan)
end
end
group = groupsize
end)
pfUI.events:RegisterFrameEventAndCallback("PLAYER_ENTERING_WORLD", function()
if not alreadyshown and localversion < remoteversion then
DEFAULT_CHAT_FRAME:AddMessage(string.format(T["|cff33ffccpf|rUI: New version available! Get it at %s"], GetAddOnMetadata(pfUI.name, "X-Website") .. "/releases"))
DEFAULT_CHAT_FRAME:AddMessage(T["|cffddddddIt's always safe to upgrade |cff33ffccpf|rUI. |cffddddddYou won't lose any of your configuration."])
pfUI_init.updateavailable = localversion
alreadyshown = true
end
for _, chan in pairs(loginchannels) do
SendAddonMessage(ADDON_PREFIX, versionmsg, chan)
end
end)
end)