4 local ssub = string.sub;
6 local UnitName, UnitClass, UnitExists = UnitName, UnitClass, UnitExists;
7 local UnitDebuff, UnitIsCharmed = UnitDebuff, UnitIsCharmed;
8 local UnitHealth, UnitHealthMax = UnitHealth, UnitHealthMax;
9 local UnitIsAFK, UnitIsDND = UnitIsAFK, UnitIsDND;
10 local UnitGetIncomingHeals, UnitGetTotalAbsorbs = UnitGetIncomingHeals, UnitGetTotalAbsorbs;
11 local UnitThreatSituation, GetThreatStatusColor = UnitThreatSituation, GetThreatStatusColor;
12 local UnitIsDeadOrGhost, UnitIsConnected = UnitIsDeadOrGhost, UnitIsConnected;
13 local UnitGetTotalHealAbsorbs = UnitGetTotalHealAbsorbs;
14 local UnitHasVehicleUI, UnitTargetsVehicleInRaidUI = UnitHasVehicleUI, UnitTargetsVehicleInRaidUI;
15 local GetReadyCheckTimeLeft, GetReadyCheckStatus = GetReadyCheckTimeLeft, GetReadyCheckStatus;
16 local UnitGroupRolesAssigned = UnitGroupRolesAssigned;
17 local GetRaidTargetIndex, SetRaidTargetIconTexture = GetRaidTargetIndex, SetRaidTargetIconTexture;
18 local RAID_CLASS_COLORS = RAID_CLASS_COLORS;
19 local READY_CHECK_READY_TEXTURE = READY_CHECK_READY_TEXTURE;
20 local READY_CHECK_NOT_READY_TEXTURE = READY_CHECK_NOT_READY_TEXTURE;
21 local READY_CHECK_WAITING_TEXTURE = READY_CHECK_WAITING_TEXTURE;
23 local updateIndicatorAuras = OmaRFIndicators.UpdateAuras;
24 local updateMajorAuras = OmaRFIndicators.UpdateMajorAuras;
26 local Settings = OmaRFSettings;
27 local baseColor = Settings.BaseColor;
28 local overlayColorDispel = Settings.OverlayColorDispel;
29 local overlayColorCharm = Settings.OverlayColorCharm;
30 local overlayColorAlert = Settings.OverlayColorAlert;
31 local width = Settings.Width;
35 function M.RegisterEvents(frame)
36 frame:RegisterEvent("PLAYER_ENTERING_WORLD");
37 frame:RegisterEvent("PLAYER_ROLES_ASSIGNED");
38 frame:RegisterEvent("READY_CHECK");
39 frame:RegisterEvent("READY_CHECK_FINISHED");
40 frame:RegisterEvent("GROUP_ROSTER_UPDATE");
41 frame:RegisterEvent("RAID_TARGET_UPDATE");
42 if frame.unit == "focus" then frame:RegisterEvent("PLAYER_FOCUS_CHANGED") end
45 function M.RegisterUnitEvents(frame)
46 -- events are taken from FrameXML/CompactUnitFrame.lua
47 local displayed = frame.unit ~= frame.displayed and frame.displayed or nil;
48 frame:RegisterUnitEvent("UNIT_HEALTH", frame.unit, displayed);
49 frame:RegisterUnitEvent("UNIT_HEALTH_FREQUENT", frame.unit, displayed);
50 frame:RegisterUnitEvent("UNIT_MAXHEALTH", frame.unit, displayed);
51 frame:RegisterUnitEvent("UNIT_NAME_UPDATE", frame.unit, displayed);
52 frame:RegisterUnitEvent("UNIT_AURA", frame.unit, displayed);
53 frame:RegisterUnitEvent("UNIT_HEAL_PREDICTION", frame.unit, displayed);
54 frame:RegisterUnitEvent("UNIT_ABSORB_AMOUNT_CHANGED", frame.unit, displayed);
55 frame:RegisterUnitEvent("UNIT_HEAL_ABSORB_AMOUNT_CHANGED", frame.unit, displayed);
56 frame:RegisterUnitEvent("UNIT_THREAT_SITUATION_UPDATE", frame.unit, displayed);
57 frame:RegisterUnitEvent("UNIT_CONNECTION", frame.unit, displayed);
58 frame:RegisterUnitEvent("PLAYER_FLAGS_CHANGED", frame.unit, displayed);
59 frame:RegisterUnitEvent("READY_CHECK_CONFIRM", frame.unit, displayed);
60 frame:RegisterUnitEvent("UNIT_ENTERED_VEHICLE", frame.unit, displayed);
61 frame:RegisterUnitEvent("UNIT_EXITED_VEHICLE", frame.unit, displayed);
62 frame:RegisterUnitEvent("UNIT_PET", frame.unit, displayed);
64 local registerUnitEvents = M.RegisterUnitEvents;
66 local function updateText(frame, unit)
67 if UnitIsDeadOrGhost(unit) then
69 frame.text:SetText("Dead");
71 elseif not UnitIsConnected(unit) then
72 frame.text:SetText("DC");
74 elseif UnitIsAFK(unit) then
75 frame.text:SetText("afk");
77 elseif UnitIsDND(unit) then
78 frame.text:SetText("dnd");
84 M.UpdateText = updateText;
86 local function updateMaxHealth(frame, unit)
87 frame.health.max = UnitHealthMax(unit);
89 M.UpdateMaxHealth = updateMaxHealth;
91 local function updateHealth(frame, unit)
92 local current, max = UnitHealth(unit), frame.health.max;
93 if current > max or max <= 0 then
94 -- somehow current health has gone over the maximum (missed maxhealth event possibly)
95 -- just put health bar full and update max health for next event
96 frame.health:SetWidth(width);
97 frame.health.width = width;
98 updateMaxHealth(frame, unit);
100 elseif current <= 0 or UnitIsDeadOrGhost(unit) then
102 return updateText(frame, unit); -- update death
104 local w = current/max*width;
105 frame.health:SetWidth(w);
106 frame.health.width = w;
110 if frame.dead and current > 0 then
112 updateText(frame, unit); -- update revive
115 M.UpdateHealth = updateHealth;
117 local function updateName(frame, unit)
118 local name = UnitName(unit);
119 if not name then return end
120 name = ssub(name, 1, 6);
121 if frame.unit == unit then
122 frame.name:SetText(name);
124 frame.name:SetFormattedText("-%s", name);
127 local _, class = UnitClass(unit);
128 local color = RAID_CLASS_COLORS[class];
129 if color then frame.name:SetVertexColor(color.r, color.g, color.b) end
131 M.UpdateName = updateName;
133 local function updateHealPred(frame, unit)
134 local incoming = UnitGetIncomingHeals(unit) or 0;
136 incoming = (incoming / frame.health.max) * width;
137 -- always at least 1 pixel space for heal prediction
138 frame.healpred:SetWidth(min(width - frame.health.width + 1, incoming));
139 frame.healpred:Show();
141 frame.healpred:Hide();
144 M.UpdateHealPred = updateHealPred;
146 local function updateShield(frame, unit)
147 local shield = UnitGetTotalAbsorbs(unit) or 0;
149 local space = width - frame.health.width;
150 shield = (shield / frame.health.max) * width;
153 frame.shieldhl:Show();
154 elseif space < shield then
155 frame.shield:SetWidth(space);
157 frame.shieldhl:Show();
159 frame.shield:SetWidth(shield);
161 frame.shieldhl:Hide();
165 frame.shieldhl:Hide();
168 M.UpdateShield = updateShield;
170 local function updateHealAbsorb(frame, unit)
171 local absorb = UnitGetTotalHealAbsorbs(unit) or 0;
173 absorb = (absorb / frame.health.max) * width;
174 frame.healabsorb:SetWidth(min(frame.health.width, absorb));
175 frame.healabsorb:Show();
177 frame.healabsorb:Hide();
180 M.UpdateHealAbsorb = updateHealAbsorb;
182 local function updateAuras(frame, unit)
183 updateIndicatorAuras(frame, unit); -- this is throttled
184 local barColor = updateMajorAuras(frame, unit);
186 if barColor == true and frame.overlay.color ~= overlayColorAlert then
187 frame.overlay:SetVertexColor(unpack(overlayColorAlert));
188 frame.overlay.color = overlayColorAlert;
189 frame.overlay:Show();
190 elseif barColor ~= true and frame.overlay.color ~= barColor then
191 frame.overlay:SetVertexColor(unpack(barColor));
192 frame.overlay.color = barColor;
193 frame.overlay:Show();
195 elseif UnitDebuff(unit, 1, "RAID") ~= nil then
196 -- something dispellable
197 if frame.overlay.color ~= overlayColorDispel then
198 frame.overlay:SetVertexColor(unpack(overlayColorDispel));
199 frame.overlay.color = overlayColorDispel;
200 frame.overlay:Show();
202 -- don't overlay charmed when in vehicle
203 elseif UnitIsCharmed(unit) and unit == frame.unit then
204 if frame.overlay.color ~= overlayColorCharm then
205 frame.overlay:SetVertexColor(unpack(overlayColorCharm));
206 frame.overlay.color = overlayColorCharm;
207 frame.overlay:Show();
210 if frame.overlay.color ~= nil then
211 frame.overlay.color = nil;
212 frame.overlay:Hide();
216 M.UpdateAuras = updateAuras;
218 local function updateAggro(frame, unit)
219 local status = UnitThreatSituation(unit);
220 if status and status > 0 then
221 frame.base:SetVertexColor(GetThreatStatusColor(status));
223 frame.base:SetVertexColor(unpack(baseColor));
226 M.UpdateAggro = updateAggro;
228 local function updateVehicle(frame)
229 local shouldTargetVehicle = UnitHasVehicleUI(frame.unit) and
230 UnitTargetsVehicleInRaidUI(frame.unit) and UnitExists(frame.vehicle);
231 if shouldTargetVehicle then
232 if not frame.inVehicle then
233 frame.inVehicle = true;
234 frame.displayed = frame.vehicle;
235 registerUnitEvents(frame);
237 elseif frame.inVehicle then
238 frame.inVehicle = false;
239 frame.displayed = frame.unit;
240 registerUnitEvents(frame);
243 M.UpdateVehicle = updateVehicle;
245 local function updateRole(frame, unit)
246 local role = UnitGroupRolesAssigned(unit);
247 if role == "HEALER" then
248 frame.role:SetTexCoord(0.75, 1, 0, 1);
250 elseif role == "TANK" then
251 frame.role:SetTexCoord(0.5, 0.75, 0, 1);
257 M.UpdateRole = updateRole;
259 local function updateReadyCheck(frame, unit)
260 local status = GetReadyCheckStatus(unit);
261 if status == "ready" then
262 frame.ready:SetTexture(READY_CHECK_READY_TEXTURE);
264 elseif status == "notready" then
265 frame.ready:SetTexture(READY_CHECK_NOT_READY_TEXTURE);
267 elseif status == "waiting" then
268 frame.ready:SetTexture(READY_CHECK_WAITING_TEXTURE);
274 M.UpdateReadyCheck = updateReadyCheck;
276 local function updateRaidMarker(frame, unit)
277 local index = GetRaidTargetIndex(unit);
279 SetRaidTargetIconTexture(frame.targeticon, index);
280 frame.targeticon:Show();
282 frame.targeticon:Hide();
285 M.UpdateRaidMarker = updateRaidMarker;
288 ["UNIT_HEALTH"] = function(frame)
289 updateHealth(frame, frame.displayed);
290 updateShield(frame, frame.displayed);
291 updateHealAbsorb(frame, frame.displayed);
292 -- no heal prediction update, that doesn't overflow too much
294 ["UNIT_AURA"] = function(frame)
295 updateAuras(frame, frame.displayed);
297 ["UNIT_HEAL_PREDICTION"] = function(frame)
298 updateHealPred(frame, frame.displayed);
300 ["UNIT_ABSORB_AMOUNT_CHANGED"] = function(frame)
301 updateShield(frame, frame.displayed);
303 ["UNIT_HEAL_ABSORB_AMOUNT_CHANGED"] = function(frame)
304 updateHealAbsorb(frame, frame.displayed);
306 ["UNIT_THREAT_SITUATION_UPDATE"] = function(frame)
307 updateAggro(frame, frame.displayed);
309 ["UNIT_MAXHEALTH"] = function(frame)
310 updateMaxHealth(frame, frame.displayed);
311 updateHealth(frame, frame.displayed);
312 updateShield(frame, frame.displayed);
313 updateHealAbsorb(frame, frame.displayed);
315 ["UNIT_NAME_UPDATE"] = function(frame)
316 updateName(frame, frame.unit);
318 ["UNIT_CONNECTION"] = function(frame)
319 updateText(frame, frame.displayed);
321 ["PLAYER_ROLES_ASSIGNED"] = function(frame)
322 updateRole(frame, frame.unit);
324 ["READY_CHECK"] = function(frame)
325 updateReadyCheck(frame, frame.unit);
327 ["RAID_TARGET_UPDATE"] = function(frame)
328 updateRaidMarker(frame, frame.displayed);
330 ["UPDATE_ALL_BARS"] = function(frame)
331 updateRole(frame, frame.unit);
332 updateVehicle(frame);
333 updateMaxHealth(frame, frame.displayed);
334 updateHealth(frame, frame.displayed);
335 updateText(frame, frame.displayed);
336 updateAuras(frame, frame.displayed);
337 updateShield(frame, frame.displayed);
338 updateHealPred(frame, frame.displayed);
339 updateHealAbsorb(frame, frame.displayed);
340 updateAggro(frame, frame.displayed);
341 updateName(frame, frame.unit);
342 updateReadyCheck(frame, frame.unit);
343 updateRaidMarker(frame, frame.displayed);
346 eventFuncs["UNIT_HEALTH_FREQUENT"] = eventFuncs["UNIT_HEALTH"];
347 eventFuncs["PLAYER_FLAGS_CHANGED"] = eventFuncs["UNIT_CONNECTION"];
348 eventFuncs["READY_CHECK_CONFIRM"] = eventFuncs["READY_CHECK"];
349 eventFuncs["READY_CHECK_FINISHED"] = eventFuncs["READY_CHECK"];
350 eventFuncs["UNIT_ENTERED_VEHICLE"] = eventFuncs["UPDATE_ALL_BARS"];
351 eventFuncs["UNIT_EXITED_VEHICLE"] = eventFuncs["UPDATE_ALL_BARS"];
352 eventFuncs["UNIT_PET"] = eventFuncs["UPDATE_ALL_BARS"];
353 eventFuncs["GROUP_ROSTER_UPDATE"] = eventFuncs["UPDATE_ALL_BARS"];
354 eventFuncs["PLAYER_ENTERING_WORLD"] = eventFuncs["UPDATE_ALL_BARS"];
355 eventFuncs["PLAYER_FOCUS_CHANGED"] = eventFuncs["UPDATE_ALL_BARS"];
357 function M.UnitEvent(self, event)
358 return eventFuncs[event](self);