-local function unitEvent(self, event, ...)
- local arg1, arg2, arg3, arg4 = ...;
- eventFuncs[event](self, arg1);
-end
-
-local function unitUpdate(self, elapsed)
- -- there's no in/out of range event, have to check each frame
- -- from FrameXML/CompactUnitFrame.lua
- local inRange, checked = UnitInRange(self.unit);
- if checked and not inRange then
- self:SetAlpha(0.55);
- else
- self:SetAlpha(1);
- end
-end
-
-local function registerEvents(frame, unit)
- -- events are taken from FrameXML/CompactUnitFrame.lua
- -- TODO vehicle support, ready check support, raid marker support,
- -- player flags support (/afk, /dnd)
- -- TODO only update for vehicle events here
- frame:RegisterEvent("PARTY_MEMBER_ENABLE");
- frame:RegisterEvent("PARTY_MEMBER_DISABLE");
- frame:RegisterUnitEvent("UNIT_HEALTH", unit);
- frame:RegisterUnitEvent("UNIT_HEALTH_FREQUENT", unit);
- frame:RegisterUnitEvent("UNIT_MAXHEALTH", unit);
- frame:RegisterUnitEvent("UNIT_POWER", unit);
- frame:RegisterUnitEvent("UNIT_MAXPOWER", unit);
- frame:RegisterUnitEvent("UNIT_DISPLAYPOWER", unit);
- frame:RegisterUnitEvent("UNIT_NAME_UPDATE", unit);
- frame:RegisterUnitEvent("UNIT_AURA", unit);
- frame:RegisterUnitEvent("UNIT_HEAL_PREDICTION", unit);
- frame:RegisterUnitEvent("UNIT_ABSORB_AMOUNT_CHANGED", unit);
- frame:RegisterUnitEvent("UNIT_HEAL_ABSORB_AMOUNT_CHANGED", unit);
- frame:RegisterUnitEvent("UNIT_THREAT_SITUATION_UPDATE", unit);
- frame:RegisterUnitEvent("UNIT_CONNECTION", unit);
- frame:RegisterUnitEvent("INCOMING_RESURRECT_CHANGED", unit);
-end
-
-local function vis(frame, vis)
- if vis then
- frame:Show();
- frame:SetScript("OnUpdate", unitUpdate);
- --frame:UnregisterAllEvents();
- --registerEvents(frame, frame.unit);
- -- wait one frame to update data
- -- create function if needed to pass arguments to unitEvent
- local func = updaters[frame];
- if not func then
- func = function() unitEvent(frame, "UPDATE_ALL_BARS", frame.unit) end;
- updaters[frame] = func;
- end
- CTimerAfter(0.01, func);
- else
- frame:Hide();
- frame:SetScript("OnUpdate", nil);
- --frame:UnregisterAllEvents();
- end;
-end
-
-local function updateGroup()
- if IsInGroup() then
- if IsInRaid() then
- -- show raid
- for _, val in ipairs(raid) do
- if UnitInRaid(val.frame.unit) then
- vis(val.frame, true);
- elseif val.frame:IsShown() then
- vis(val.frame, false);
- end
- end
- -- hide player + party (use pairs, not ipairs)
- for _, val in pairs(party) do
- if val.frame:IsShown() then vis(val.frame, false) end
- end
- else
- -- show player + party
- for _, val in pairs(party) do
- if UnitInParty(val.frame.unit) then
- vis(val.frame, true);
- elseif val.frame:IsShown() then
- vis(val.frame, false);
- end
- end
- -- hide raid
- for _, val in ipairs(raid) do
- if val.frame:IsShown() then vis(val.frame, false) end
- end
- end
- else
- -- show player
- vis(party[0].frame, true);
- -- hide all other frames
- for _, val in ipairs(party) do
- if val.frame:IsShown() then vis(val.frame, false) end
- end
- for _, val in ipairs(raid) do
- if val.frame:IsShown() then vis(val.frame, false) end
- end
- end