mirror of
https://github.com/brues-code/pfUI.git
synced 2026-09-28 10:26:02 +00:00
Filter unit events with RegisterUnitEvent
ClassicAPI's RegisterUnitEvent registers for an event but only delivers it when arg1 is one of the given units, so a handler for one unit stops waking for every other one in the world. Convert the 26 registrations whose unit set is fixed and known at registration time. The rule throughout is register the superset and keep the handler's own check: the filter narrows what arrives, it does not decide what to act on. castbar is the case that matters -- the player's own casts only ever fire arg1=="player", never "target"/"focus", so the target and focus bars must register "player" too, and their UnitIsUnit test is what still rejects a "player" event while you are targeting a mob. Two that are not one-line swaps: actionbar's two unit events are keys in tables that also drive dispatch, so they cannot leave the tables -- and they cannot be plain-registered first, because a registration keeps its kind and RegisterUnitEvent over a plain one stays plain. They route through a small event_units map instead. swingtimer's UNIT_DIED carries a GUID, not a token. The filter is a plain case-insensitive string compare with no GUID resolution, so the player's own GUID -- fixed for the session -- filters it exactly. Guards that are now unreachable stay put: the filter applies only when arg1 is a string, so an event that ever fires with a number or no argument is delivered as if plainly registered, and the handler's own test is what still rejects it. Left alone: api/unitframes.lua (the frame's unit changes at runtime and the handler also matches on GUID), nameplates' six nameplateN events, libdebuff and libpredict's UNIT_HEALTH (genuinely any unit), and raid.lua's UNIT_PET (any raid member can own the pet).
This commit is contained in:
+2
-2
@@ -10,8 +10,8 @@ local libhealth = CreateFrame("Frame")
|
||||
libhealth.enabled = true
|
||||
libhealth.reqhit = 4
|
||||
libhealth.reqdmg = 5
|
||||
libhealth:RegisterEvent("UNIT_HEALTH")
|
||||
libhealth:RegisterEvent("UNIT_COMBAT")
|
||||
libhealth:RegisterUnitEvent("UNIT_HEALTH", "target")
|
||||
libhealth:RegisterUnitEvent("UNIT_COMBAT", "target")
|
||||
libhealth:RegisterEvent("PLAYER_TARGET_CHANGED")
|
||||
libhealth:RegisterEvent("PLAYER_ENTERING_WORLD")
|
||||
libhealth:SetScript("OnEvent", function()
|
||||
|
||||
+1
-1
@@ -1134,7 +1134,7 @@ libpredict.sender:RegisterEvent("SPELL_HEAL_BY_SELF")
|
||||
libpredict.sender:RegisterEvent("SPELL_HEAL_BY_OTHER") -- populates foreignCache for other healers
|
||||
|
||||
-- force cache updates
|
||||
libpredict.sender:RegisterEvent("UNIT_INVENTORY_CHANGED")
|
||||
libpredict.sender:RegisterUnitEvent("UNIT_INVENTORY_CHANGED", "player")
|
||||
libpredict.sender:RegisterEvent("SKILL_LINES_CHANGED")
|
||||
|
||||
-- Shared cleanup helper for failed/interrupted casts
|
||||
|
||||
+22
-4
@@ -807,10 +807,28 @@ pfUI:RegisterModule("actionbar", function ()
|
||||
|
||||
-- create the main event and update handler for pfUI actionbars
|
||||
local bars = CreateFrame("Frame", "pfActionBar", UIParent)
|
||||
for event in pairs(special_events) do bars:RegisterEvent(event) end
|
||||
for event in pairs(global_events) do bars:RegisterEvent(event) end
|
||||
for event in pairs(aura_events) do bars:RegisterEvent(event) end
|
||||
for event in pairs(pet_events) do bars:RegisterEvent(event) end
|
||||
|
||||
-- The only unit events in the tables above; both concern the player alone.
|
||||
-- A registration keeps its kind, so these have to go in unit-filtered from
|
||||
-- the start -- RegisterUnitEvent over a plain registration stays plain.
|
||||
local event_units = {
|
||||
["UNIT_INVENTORY_CHANGED"] = "player",
|
||||
["UNIT_PET"] = "player",
|
||||
}
|
||||
|
||||
local function RegisterBarEvent(event)
|
||||
local unit = event_units[event]
|
||||
if unit then
|
||||
bars:RegisterUnitEvent(event, unit)
|
||||
else
|
||||
bars:RegisterEvent(event)
|
||||
end
|
||||
end
|
||||
|
||||
for event in pairs(special_events) do RegisterBarEvent(event) end
|
||||
for event in pairs(global_events) do RegisterBarEvent(event) end
|
||||
for event in pairs(aura_events) do RegisterBarEvent(event) end
|
||||
for event in pairs(pet_events) do RegisterBarEvent(event) end
|
||||
|
||||
-- refresh actionbar buttons on event
|
||||
bars:SetScript("OnEvent", BarsEvent)
|
||||
|
||||
+1
-1
@@ -164,7 +164,7 @@ pfUI:RegisterModule("buff", function ()
|
||||
pfUI.buff = CreateFrame("Frame", "pfGlobalBuffFrame", UIParent)
|
||||
pfUI.buff:RegisterEvent("PLAYER_AURAS_CHANGED")
|
||||
pfUI.buff:RegisterEvent("PLAYER_EQUIPMENT_CHANGED")
|
||||
pfUI.buff:RegisterEvent("UNIT_MODEL_CHANGED")
|
||||
pfUI.buff:RegisterUnitEvent("UNIT_MODEL_CHANGED", "player")
|
||||
pfUI.buff:RegisterEvent("BUFF_UPDATE_DURATION_SELF")
|
||||
pfUI.buff:RegisterEvent("DEBUFF_UPDATE_DURATION_SELF")
|
||||
pfUI.buff:SetScript("OnEvent", function()
|
||||
|
||||
+15
-9
@@ -322,15 +322,21 @@ pfUI:RegisterModule("castbar", function ()
|
||||
-- casts only ever fire arg1=="player" -- when the bar's unit resolves to the
|
||||
-- player (target=self). PLAYER_TARGET/FOCUS_CHANGED re-polls so a unit
|
||||
-- already mid-cast when it becomes the target/focus still shows.
|
||||
cb:RegisterEvent("UNIT_SPELLCAST_START")
|
||||
cb:RegisterEvent("UNIT_SPELLCAST_STOP")
|
||||
cb:RegisterEvent("UNIT_SPELLCAST_FAILED")
|
||||
cb:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED")
|
||||
cb:RegisterEvent("UNIT_SPELLCAST_DELAYED")
|
||||
cb:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
|
||||
cb:RegisterEvent("UNIT_SPELLCAST_CHANNEL_START")
|
||||
cb:RegisterEvent("UNIT_SPELLCAST_CHANNEL_STOP")
|
||||
cb:RegisterEvent("UNIT_SPELLCAST_CHANNEL_UPDATE")
|
||||
-- Filter to this bar's unit, plus "player" for the target/focus bars: the
|
||||
-- player's own casts only ever fire arg1=="player", so a self-targeted cast
|
||||
-- has to reach them too (nil for the player bar itself, which the filter
|
||||
-- skips). This only narrows what arrives -- the arg1/UnitIsUnit test below
|
||||
-- still decides whether the bar acts on it.
|
||||
local selfunit = unitstr ~= "player" and "player" or nil
|
||||
cb:RegisterUnitEvent("UNIT_SPELLCAST_START", unitstr, selfunit)
|
||||
cb:RegisterUnitEvent("UNIT_SPELLCAST_STOP", unitstr, selfunit)
|
||||
cb:RegisterUnitEvent("UNIT_SPELLCAST_FAILED", unitstr, selfunit)
|
||||
cb:RegisterUnitEvent("UNIT_SPELLCAST_INTERRUPTED", unitstr, selfunit)
|
||||
cb:RegisterUnitEvent("UNIT_SPELLCAST_DELAYED", unitstr, selfunit)
|
||||
cb:RegisterUnitEvent("UNIT_SPELLCAST_SUCCEEDED", unitstr, selfunit)
|
||||
cb:RegisterUnitEvent("UNIT_SPELLCAST_CHANNEL_START", unitstr, selfunit)
|
||||
cb:RegisterUnitEvent("UNIT_SPELLCAST_CHANNEL_STOP", unitstr, selfunit)
|
||||
cb:RegisterUnitEvent("UNIT_SPELLCAST_CHANNEL_UPDATE", unitstr, selfunit)
|
||||
if unitstr == "target" then
|
||||
cb:RegisterEvent("PLAYER_TARGET_CHANGED")
|
||||
elseif unitstr == "focus" then
|
||||
|
||||
@@ -52,7 +52,7 @@ pfUI:RegisterModule("combopoints", function ()
|
||||
-- combo
|
||||
if class == "DRUID" or class == "ROGUE" then
|
||||
local combo = CreateFrame("Frame")
|
||||
combo:RegisterEvent("UNIT_COMBO_POINTS")
|
||||
combo:RegisterUnitEvent("UNIT_COMBO_POINTS", "player")
|
||||
combo:RegisterEvent("PLAYER_COMBO_POINTS")
|
||||
combo:RegisterEvent("PLAYER_TARGET_CHANGED")
|
||||
combo:RegisterEvent("PLAYER_ENTERING_WORLD")
|
||||
|
||||
@@ -25,9 +25,9 @@ pfUI:RegisterModule("energytick", function()
|
||||
local energytick = CreateFrame("Frame", nil, pfUI.uf.player.power.bar)
|
||||
energytick:SetAllPoints(pfUI.uf.player.power.bar)
|
||||
energytick:RegisterEvent("PLAYER_ENTERING_WORLD")
|
||||
energytick:RegisterEvent("UNIT_DISPLAYPOWER")
|
||||
energytick:RegisterEvent("UNIT_ENERGY")
|
||||
energytick:RegisterEvent("UNIT_MANA")
|
||||
energytick:RegisterUnitEvent("UNIT_DISPLAYPOWER", "player")
|
||||
energytick:RegisterUnitEvent("UNIT_ENERGY", "player")
|
||||
energytick:RegisterUnitEvent("UNIT_MANA", "player")
|
||||
energytick:RegisterEvent("CHAT_MSG_SPELL_SELF_BUFF")
|
||||
energytick:RegisterEvent("CHAT_MSG_SPELL_PERIODIC_SELF_BUFFS")
|
||||
|
||||
|
||||
+1
-1
@@ -225,7 +225,7 @@ pfUI:RegisterModule("minimap", function ()
|
||||
pfUI.minimap.pvpicon = CreateFrame("Frame", nil, pfUI.minimap)
|
||||
pfUI.minimap.pvpicon:Hide()
|
||||
pfUI.minimap.pvpicon:RegisterEvent("UPDATE_FACTION")
|
||||
pfUI.minimap.pvpicon:RegisterEvent("UNIT_FACTION")
|
||||
pfUI.minimap.pvpicon:RegisterUnitEvent("UNIT_FACTION", "player")
|
||||
pfUI.minimap.pvpicon:SetFrameStrata("HIGH")
|
||||
pfUI.minimap.pvpicon:SetSize(16, 16)
|
||||
pfUI.minimap.pvpicon:SetAlpha(.5)
|
||||
|
||||
@@ -490,7 +490,7 @@ local nameplates = CreateFrame("Frame", "pfNameplates", UIParent)
|
||||
nameplates:RegisterEvent("PLAYER_ENTERING_WORLD")
|
||||
nameplates:RegisterEvent("PLAYER_TARGET_CHANGED")
|
||||
nameplates:RegisterEvent("PLAYER_LOGOUT")
|
||||
nameplates:RegisterEvent("UNIT_COMBO_POINTS")
|
||||
nameplates:RegisterUnitEvent("UNIT_COMBO_POINTS", "player")
|
||||
nameplates:RegisterEvent("PLAYER_COMBO_POINTS")
|
||||
nameplates:RegisterEvent("ZONE_CHANGED_NEW_AREA")
|
||||
nameplates:RegisterEvent("RAID_ROSTER_UPDATE")
|
||||
|
||||
+1
-1
@@ -486,7 +486,7 @@ pfUI:RegisterModule("panel", function()
|
||||
do -- Ammo
|
||||
local widget = CreateFrame("Frame", "pfPanelWidgetAmmo", UIParent)
|
||||
widget:RegisterEvent("PLAYER_ENTERING_WORLD")
|
||||
widget:RegisterEvent("UNIT_INVENTORY_CHANGED")
|
||||
widget:RegisterUnitEvent("UNIT_INVENTORY_CHANGED", "player")
|
||||
widget:RegisterEvent("BAG_UPDATE_DELAYED")
|
||||
widget.Tooltip = function()
|
||||
if GetInventoryItemQuality("player", 0) then
|
||||
|
||||
@@ -816,7 +816,7 @@ pfUI:RegisterModule("swingtimer", function ()
|
||||
events:RegisterEvent("PLAYER_REGEN_DISABLED")
|
||||
events:RegisterEvent("PLAYER_REGEN_ENABLED")
|
||||
events:RegisterEvent("ACTIONBAR_SLOT_CHANGED")
|
||||
events:RegisterEvent("UNIT_DIED")
|
||||
events:RegisterUnitEvent("UNIT_DIED", UnitGUID("player"))
|
||||
events:RegisterEvent("SPELL_QUEUE_EVENT")
|
||||
events:RegisterEvent("START_AUTOATTACK")
|
||||
events:RegisterEvent("STOP_AUTOATTACK")
|
||||
|
||||
+3
-3
@@ -363,9 +363,9 @@ end
|
||||
b:EnableMouse(true)
|
||||
|
||||
b:RegisterEvent("FACTION_STANDING_CHANGED")
|
||||
b:RegisterEvent("UNIT_PET")
|
||||
b:RegisterEvent("UNIT_LEVEL")
|
||||
b:RegisterEvent("UNIT_PET_EXPERIENCE")
|
||||
b:RegisterUnitEvent("UNIT_PET", "player")
|
||||
b:RegisterUnitEvent("UNIT_LEVEL", "player")
|
||||
b:RegisterUnitEvent("UNIT_PET_EXPERIENCE", "player", "pet")
|
||||
b:RegisterEvent("PLAYER_ENTERING_WORLD")
|
||||
b:RegisterEvent("UPDATE_EXHAUSTION")
|
||||
b:RegisterEvent("PLAYER_XP_UPDATE")
|
||||
|
||||
Reference in New Issue
Block a user