Commit e47ba016 authored by Merathilis's avatar Merathilis

[WIP] needs testing:

Update the event system

The main purpose of this PR was to address an issue where oUF wasn't updating pet frame's unit while switching between `pet`, `player`, and `vehicle` units while having a real pet summoned. In this sense it addresses the same issue as #481 does, but in a different way.

It also addresses few other issues related to headers, e.g., unintentional registration of unit events as unitless, excessive `UpdateAllElements` calls on GRU, etc.
parent feb306e8
......@@ -13,30 +13,58 @@ local registerUnitEvent = frame_metatable.__index.RegisterUnitEvent
local unregisterEvent = frame_metatable.__index.UnregisterEvent
local isEventRegistered = frame_metatable.__index.IsEventRegistered
-- to update unit frames correctly, some events need to be registered for
-- a specific combination of primary and secondary units
local secondaryUnits = {
UNIT_ENTERED_VEHICLE = {
pet = 'player',
},
UNIT_EXITED_VEHICLE = {
pet = 'player',
},
UNIT_PET = {
pet = 'player',
},
}
function Private.UpdateUnits(frame, unit, realUnit)
if(unit == realUnit) then
realUnit = nil
end
if(frame.unit ~= unit or frame.realUnit ~= realUnit) then
if(frame.unitEvents) then
-- don't let invalid units in, otherwise unit events will end up being
-- registered as unitless
if(frame.unitEvents and validateUnit(unit)) then
local resetRealUnit = false
for event in next, frame.unitEvents do
local registered, unit1 = isEventRegistered(frame, event)
-- unit event registration for header units is postponed until
-- the frame units are known
if(not realUnit and secondaryUnits[event]) then
realUnit = secondaryUnits[event][unit]
resetRealUnit = true
end
local registered, unit1, unit2 = isEventRegistered(frame, event)
-- we don't want to re-register unitless/shared events in case
-- someone added them by hand to the unitEvents table
if(registered and unit1 and unit1 ~= unit or not registered) then
if(not registered or unit1 and (unit1 ~= unit or unit2 ~= realUnit)) then
-- BUG: passing explicit nil units to RegisterUnitEvent
-- makes it silently fall back to RegisterEvent
-- makes it silently fall back to RegisterEvent, using ''
-- instead of explicit nils doesn't cause this behaviour
registerUnitEvent(frame, event, unit, realUnit or '')
end
if(resetRealUnit) then
realUnit = nil
resetRealUnit = false
end
end
end
frame.unit = unit
frame.realUnit = realUnit
frame.id = unit:match('^.-(%d+)')
return true
end
end
......@@ -109,9 +137,13 @@ function frame_metatable.__index:RegisterEvent(event, func, unitless)
self.unitEvents[event] = true
-- UpdateUnits will take care of unit event registration for header
-- units in case we don't have a valid unit yet
local unit = self.unit
if(unit and validateUnit(unit)) then
registerUnitEvent(self, event, unit)
local unit1, unit2 = self.unit
if(unit1 and validateUnit(unit1)) then
if(secondaryUnits[event]) then
unit2 = secondaryUnits[event][unit1]
end
registerUnitEvent(self, event, unit1, unit2 or '')
end
end
end
......@@ -134,6 +166,7 @@ function frame_metatable.__index:UnregisterEvent(event, func)
for k, infunc in next, curev do
if(infunc == func) then
curev[k] = nil
break
end
end
......@@ -148,6 +181,7 @@ function frame_metatable.__index:UnregisterEvent(event, func)
if(self.unitEvents) then
self.unitEvents[event] = nil
end
unregisterEvent(self, event)
end
end
......@@ -61,7 +61,7 @@ local function updateActiveUnit(self, event, unit)
if(not UnitExists(modUnit)) then return end
-- Change the active unit and run a full update.
if Private.UpdateUnits(self, modUnit, realUnit) then
if(Private.UpdateUnits(self, modUnit, realUnit)) then
self:UpdateAllElements('RefreshUnit')
return true
......@@ -248,6 +248,15 @@ local function updatePet(self, event, unit)
end
end
local function updateRaid(self, event)
local unitGUID = UnitGUID(self.unit)
if unitGUID and unitGUID ~= self.unitGUID then
self.unitGUID = unitGUID
self:UpdateAllElements(event)
end
end
local function initObject(unit, style, styleFunc, header, ...)
local num = select('#', ...)
for i = 1, num do
......@@ -274,7 +283,6 @@ local function initObject(unit, style, styleFunc, header, ...)
if(not (suffix == 'target' or objectUnit and objectUnit:match('target'))) then
object:RegisterEvent('UNIT_ENTERED_VEHICLE', updateActiveUnit)
object:RegisterEvent('UNIT_EXITED_VEHICLE', updateActiveUnit)
object:RegisterEvent('UNIT_EXITING_VEHICLE', updateActiveUnit)
-- We don't need to register UNIT_PET for the player unit. We register it
-- mainly because UNIT_EXITED_VEHICLE and UNIT_ENTERED_VEHICLE doesn't always
......@@ -301,8 +309,9 @@ local function initObject(unit, style, styleFunc, header, ...)
oUF:HandleUnit(object)
end
else
-- Used to update frames when they change position in a group.
object:RegisterEvent('GROUP_ROSTER_UPDATE', object.UpdateAllElements, true)
-- update the frame when its prev unit is replaced with a new one
-- updateRaid relies on UnitGUID to detect the unit change
object:RegisterEvent('GROUP_ROSTER_UPDATE', updateRaid, true)
if(num > 1) then
if(object:GetParent() == header) then
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment