4 local ssub = string.sub;
6 local UnitName, UnitClass, UnitExists = UnitName, UnitClass, UnitExists;
7 local UnitDebuff, UnitIsCharmed = UnitDebuff, UnitIsCharmed;
8 local UnitPower, UnitPowerMax, UnitPowerType = UnitPower, UnitPowerMax, UnitPowerType;
9 local UnitHealth, UnitHealthMax = UnitHealth, UnitHealthMax;
10 local UnitIsAFK, UnitIsDND = UnitIsAFK, UnitIsDND;
11 local UnitGetIncomingHeals, UnitGetTotalAbsorbs = UnitGetIncomingHeals, UnitGetTotalAbsorbs;
12 local UnitThreatSituation, GetThreatStatusColor = UnitThreatSituation, GetThreatStatusColor;
13 local UnitIsDeadOrGhost, UnitIsConnected = UnitIsDeadOrGhost, UnitIsConnected;
14 local UnitHasIncomingResurrection = UnitHasIncomingResurrection;
15 local UnitGetTotalHealAbsorbs = UnitGetTotalHealAbsorbs;
16 local UnitHasVehicleUI, UnitTargetsVehicleInRaidUI = UnitHasVehicleUI, UnitTargetsVehicleInRaidUI;
17 local GetReadyCheckTimeLeft, GetReadyCheckStatus = GetReadyCheckTimeLeft, GetReadyCheckStatus;
18 local UnitGroupRolesAssigned = UnitGroupRolesAssigned;
19 local GetRaidTargetIndex, SetRaidTargetIconTexture = GetRaidTargetIndex, SetRaidTargetIconTexture;
20 local RAID_CLASS_COLORS = RAID_CLASS_COLORS;
21 local READY_CHECK_READY_TEXTURE = READY_CHECK_READY_TEXTURE;
22 local READY_CHECK_NOT_READY_TEXTURE = READY_CHECK_NOT_READY_TEXTURE;
23 local READY_CHECK_WAITING_TEXTURE = READY_CHECK_WAITING_TEXTURE;
25 local checkIndicators = OmaRFIndicators.CheckIndicators;
27 local Settings = OmaRFSettings;
28 local baseColor = Settings.BaseColor;
29 local overlayColorDispel = Settings.OverlayColorDispel;
30 local overlayColorCharm = Settings.OverlayColorCharm;
31 local overlayColorAlert = Settings.OverlayColorAlert;
32 local powerColors = Settings.PowerColors;
33 local width = Settings.Width;
37 function M.RegisterEvents(frame)
38 frame:RegisterEvent("PLAYER_ENTERING_WORLD");
39 frame:RegisterEvent("PLAYER_ROLES_ASSIGNED");
40 frame:RegisterEvent("READY_CHECK");
41 frame:RegisterEvent("READY_CHECK_FINISHED");
42 frame:RegisterEvent("GROUP_ROSTER_UPDATE");
43 frame:RegisterEvent("RAID_TARGET_UPDATE");
44 if frame.unit == "focus" then frame:RegisterEvent("PLAYER_FOCUS_CHANGED") end
47 local function unregisterPower(frame)
48 frame.health:SetPoint("BOTTOMLEFT", frame.background, "BOTTOMLEFT");
49 frame.overlay:SetPoint("BOTTOMRIGHT", frame.background, "BOTTOMRIGHT");
51 frame:UnregisterEvent("PARTY_MEMBER_ENABLE");
52 frame:UnregisterEvent("PARTY_MEMBER_DISABLE");
53 frame:UnregisterEvent("UNIT_POWER");
54 frame:UnregisterEvent("UNIT_MAXPOWER");
55 frame:UnregisterEvent("UNIT_DISPLAYPOWER");
56 frame:UnregisterEvent("UNIT_POWER_BAR_SHOW");
57 frame:UnregisterEvent("UNIT_POWER_BAR_HIDE");
60 local function registerPower(frame)
61 frame.health:SetPoint("BOTTOMLEFT", frame.background, "BOTTOMLEFT", 0, 2);
62 frame.overlay:SetPoint("BOTTOMRIGHT", frame.background, "BOTTOMRIGHT", 0, 2);
64 frame:RegisterEvent("PARTY_MEMBER_ENABLE");
65 frame:RegisterEvent("PARTY_MEMBER_DISABLE");
66 frame:RegisterUnitEvent("UNIT_POWER", frame.unit);
67 frame:RegisterUnitEvent("UNIT_MAXPOWER", frame.unit);
68 frame:RegisterUnitEvent("UNIT_DISPLAYPOWER", frame.unit);
69 frame:RegisterUnitEvent("UNIT_POWER_BAR_SHOW", frame.unit);
70 frame:RegisterUnitEvent("UNIT_POWER_BAR_HIDE", frame.unit);
73 function M.RegisterUnitEvents(frame)
74 -- events are taken from FrameXML/CompactUnitFrame.lua
75 -- TODO raid marker support
76 local displayed = frame.unit ~= frame.displayed and frame.displayed or nil;
77 frame:RegisterUnitEvent("UNIT_HEALTH", frame.unit, displayed);
78 frame:RegisterUnitEvent("UNIT_HEALTH_FREQUENT", frame.unit, displayed);
79 frame:RegisterUnitEvent("UNIT_MAXHEALTH", frame.unit, displayed);
80 frame:RegisterUnitEvent("UNIT_NAME_UPDATE", frame.unit, displayed);
81 frame:RegisterUnitEvent("UNIT_AURA", frame.unit, displayed);
82 frame:RegisterUnitEvent("UNIT_HEAL_PREDICTION", frame.unit, displayed);
83 frame:RegisterUnitEvent("UNIT_ABSORB_AMOUNT_CHANGED", frame.unit, displayed);
84 frame:RegisterUnitEvent("UNIT_HEAL_ABSORB_AMOUNT_CHANGED", frame.unit, displayed);
85 frame:RegisterUnitEvent("UNIT_THREAT_SITUATION_UPDATE", frame.unit, displayed);
86 frame:RegisterUnitEvent("UNIT_CONNECTION", frame.unit, displayed);
87 frame:RegisterUnitEvent("INCOMING_RESURRECT_CHANGED", frame.unit, displayed);
88 frame:RegisterUnitEvent("PLAYER_FLAGS_CHANGED", frame.unit, displayed);
89 frame:RegisterUnitEvent("READY_CHECK_CONFIRM", frame.unit, displayed);
90 frame:RegisterUnitEvent("UNIT_ENTERED_VEHICLE", frame.unit, displayed);
91 frame:RegisterUnitEvent("UNIT_EXITED_VEHICLE", frame.unit, displayed);
92 frame:RegisterUnitEvent("UNIT_PET", frame.unit, displayed);
94 local registerUnitEvents = M.RegisterUnitEvents;
96 local function updateMaxHealth(frame, unit)
97 frame.health.max = UnitHealthMax(unit);
100 local function updateHealth(frame, unit)
101 local current, max = UnitHealth(unit), frame.health.max;
102 if current > max or max <= 0 then
103 -- somehow current health has gone over the maximum (missed maxhealth event possibly)
104 -- just put health bar full and update max health for next event
105 frame.health:SetWidth(width);
106 updateMaxHealth(frame, unit);
108 elseif current <= 0 or UnitIsDeadOrGhost(unit) then
111 frame.health:SetWidth(current/max*width);
116 local function updateText(frame, unit)
117 local healthLost = frame.health.max - UnitHealth(unit);
118 if UnitIsDeadOrGhost(unit) then
119 frame.text:SetText("Dead");
121 elseif not UnitIsConnected(unit) then
122 frame.text:SetText("DC");
124 elseif UnitIsAFK(unit) then
125 frame.text:SetText("afk");
127 elseif UnitIsDND(unit) and healthLost == 0 then
128 frame.text:SetText("dnd");
130 elseif healthLost > 0 then
131 if healthLost > 1200000000 then -- 1.2B
132 frame.text:SetFormattedText("-%.1fB", healthLost / 1000000000);
133 elseif healthLost > 1200000 then -- 1.2M
134 frame.text:SetFormattedText("-%.1fM", healthLost / 1000000);
135 elseif healthLost > 1000 then -- 1K
136 frame.text:SetFormattedText("-%dK", healthLost / 1000);
138 frame.text:SetFormattedText("-%d", healthLost)
146 local function updateIncomingRes(frame, unit)
147 if UnitHasIncomingResurrection(unit) then frame.rez:Show();
148 else frame.rez:Hide(); end
151 local function updateMaxPower(frame, unit)
152 frame.mana.max = UnitPowerMax(unit);
155 local function updatePower(frame, unit)
156 local current, max = UnitPower(unit), frame.mana.max;
159 elseif current > max or max <= 0 then
160 frame.mana:SetWidth(width);
161 updateMaxPower(frame, unit);
164 frame.mana:SetWidth(current/max*width);
169 local function updatePowerColor(frame, unit)
170 frame.mana:SetVertexColor(unpack(powerColors[UnitPowerType(unit)]));
173 local function updateName(frame, unit)
174 local name = UnitName(unit);
175 if not name then return end
176 frame.name:SetText(ssub(name, 1, 6));
178 local _, class = UnitClass(unit);
179 local color = RAID_CLASS_COLORS[class];
180 if color then frame.name:SetVertexColor(color.r, color.g, color.b) end
183 local function updateHealPred(frame, unit)
184 local incoming = UnitGetIncomingHeals(unit) or 0;
186 -- always at least 1 pixel space for heal prediction
187 local space = width - frame.health:GetWidth() + 1;
188 incoming = (incoming / frame.health.max) * width;
189 frame.healpred:SetWidth(min(space, incoming));
190 frame.healpred:Show();
192 frame.healpred:Hide();
196 local function updateShield(frame, unit)
197 local shield = UnitGetTotalAbsorbs(unit) or 0;
199 local space = width - frame.health:GetWidth();
200 shield = (shield / frame.health.max) * width;
203 frame.shieldhl:Show();
204 elseif space < shield then
205 frame.shield:SetWidth(space);
207 frame.shieldhl:Show();
209 frame.shield:SetWidth(shield);
211 frame.shieldhl:Hide();
215 frame.shieldhl:Hide();
219 local function updateHealAbsorb(frame, unit)
220 local absorb = UnitGetTotalHealAbsorbs(unit) or 0;
222 local space = frame.health:GetWidth();
223 absorb = (absorb / frame.health.max) * width;
224 frame.healabsorb:SetWidth(min(space, absorb));
225 frame.healabsorb:Show();
227 frame.healabsorb:Hide();
231 local function updateAuras(frame, unit)
232 local alert = checkIndicators(frame, unit);
234 if frame.overlay.color ~= overlayColorAlert then
235 frame.overlay:SetVertexColor(unpack(overlayColorAlert));
236 frame.overlay.color = overlayColorAlert;
237 frame.overlay:Show();
239 elseif UnitDebuff(unit, 1, "RAID") ~= nil then
240 -- something dispellable
241 if frame.overlay.color ~= overlayColorDispel then
242 frame.overlay:SetVertexColor(unpack(overlayColorDispel));
243 frame.overlay.color = overlayColorDispel;
244 frame.overlay:Show();
246 -- don't overlay charmed when in vehicle
247 elseif UnitIsCharmed(unit) and unit == frame.unit then
248 if frame.overlay.color ~= overlayColorCharm then
249 frame.overlay:SetVertexColor(unpack(overlayColorCharm));
250 frame.overlay.color = overlayColorCharm;
251 frame.overlay:Show();
254 if frame.overlay.color ~= nil then
255 frame.overlay.color = nil;
256 frame.overlay:Hide();
261 local function updateAggro(frame, unit)
262 local status = UnitThreatSituation(unit);
263 if status and status > 0 then
264 frame.base:SetVertexColor(GetThreatStatusColor(status));
266 frame.base:SetVertexColor(unpack(baseColor));
270 local function updateVehicle(frame)
271 local shouldTargetVehicle = UnitHasVehicleUI(frame.unit) and
272 UnitTargetsVehicleInRaidUI(frame.unit) and UnitExists(frame.vehicle);
273 if shouldTargetVehicle then
274 if not frame.inVehicle then
275 frame.inVehicle = true;
276 frame.displayed = frame.vehicle;
277 registerUnitEvents(frame);
279 elseif frame.inVehicle then
280 frame.inVehicle = false;
281 frame.displayed = frame.unit;
282 registerUnitEvents(frame);
286 local function updateRole(frame, unit)
287 local role = UnitGroupRolesAssigned(unit);
288 if role == "HEALER" then
289 frame.role:SetTexCoord(0.75, 1, 0, 1);
291 registerPower(frame);
292 frame.role.healer = true;
293 elseif role == "TANK" then
294 frame.role:SetTexCoord(0.5, 0.75, 0, 1);
296 if frame.role.healer then
297 frame.role.healer = false;
298 unregisterPower(frame);
302 if frame.role.healer then
303 frame.role.healer = false;
304 unregisterPower(frame);
309 local function updateReadyCheck(frame, unit)
310 local status = GetReadyCheckStatus(unit);
311 if status == "ready" then
312 frame.ready:SetTexture(READY_CHECK_READY_TEXTURE);
314 elseif status == "notready" then
315 frame.ready:SetTexture(READY_CHECK_NOT_READY_TEXTURE);
317 elseif status == "waiting" then
318 frame.ready:SetTexture(READY_CHECK_WAITING_TEXTURE);
325 local function updateRaidMarker(frame, unit)
326 local index = GetRaidTargetIndex(unit);
328 SetRaidTargetIconTexture(frame.targeticon, index);
329 frame.targeticon:Show();
331 frame.targeticon:Hide();
336 ["UNIT_HEALTH"] = function(frame)
337 updateHealth(frame, frame.displayed);
338 updateText(frame, frame.displayed);
339 updateShield(frame, frame.displayed);
340 updateHealAbsorb(frame, frame.displayed);
341 -- no heal prediction update, that doesn't overflow too much
342 -- raid marker update here, because marker is removed when unit dies
343 -- without a RAID_TARGET_UPDATE event
344 updateRaidMarker(frame, frame.unit);
346 ["UNIT_POWER"] = function(frame)
347 updatePower(frame, frame.displayed);
349 ["UNIT_AURA"] = function(frame)
350 updateAuras(frame, frame.displayed);
352 ["UNIT_HEAL_PREDICTION"] = function(frame)
353 updateHealPred(frame, frame.displayed);
355 ["UNIT_ABSORB_AMOUNT_CHANGED"] = function(frame)
356 updateShield(frame, frame.displayed);
358 ["UNIT_HEAL_ABSORB_AMOUNT_CHANGED"] = function(frame)
359 updateHealAbsorb(frame, frame.displayed);
361 ["UNIT_THREAT_SITUATION_UPDATE"] = function(frame)
362 updateAggro(frame, frame.displayed);
364 ["UNIT_MAXHEALTH"] = function(frame)
365 updateMaxHealth(frame, frame.displayed);
366 updateHealth(frame, frame.displayed);
367 updateText(frame, frame.displayed);
368 updateShield(frame, frame.displayed);
369 updateHealAbsorb(frame, frame.displayed);
371 ["UNIT_MAXPOWER"] = function(frame)
372 updateMaxPower(frame, frame.displayed);
373 updatePower(frame, frame.displayed);
375 ["UNIT_DISPLAYPOWER"] = function(frame)
376 updatePowerColor(frame, frame.displayed);
377 updateMaxPower(frame, frame.displayed);
378 updatePower(frame, frame.displayed);
380 ["UNIT_NAME_UPDATE"] = function(frame)
381 updateName(frame, frame.displayed);
383 ["UNIT_CONNECTION"] = function(frame)
384 updateText(frame, frame.displayed);
386 ["INCOMING_RESURRECT_CHANGED"] = function(frame)
387 updateIncomingRes(frame, frame.unit);
389 ["PARTY_MEMBER_ENABLE"] = function(frame)
390 -- new power info possibly (FrameXML/CompactUnitFrame.lua)
391 updateMaxPower(frame, frame.displayed);
392 updatePowerColor(frame, frame.displayed);
394 ["PLAYER_ROLES_ASSIGNED"] = function(frame)
395 updateRole(frame, frame.unit);
397 ["READY_CHECK"] = function(frame)
398 updateReadyCheck(frame, frame.unit);
400 ["RAID_TARGET_UPDATE"] = function(frame)
401 updateRaidMarker(frame, frame.displayed);
403 ["UPDATE_ALL_BARS"] = function(frame)
404 updateRole(frame, frame.unit);
405 updateVehicle(frame);
406 updateMaxHealth(frame, frame.displayed);
407 updateHealth(frame, frame.displayed);
408 updateText(frame, frame.displayed);
409 if frame.role.healer then
410 updateMaxPower(frame, frame.displayed);
411 updatePower(frame, frame.displayed);
412 updatePowerColor(frame, frame.displayed);
414 updateAuras(frame, frame.displayed);
415 updateShield(frame, frame.displayed);
416 updateHealPred(frame, frame.displayed);
417 updateHealAbsorb(frame, frame.displayed);
418 updateAggro(frame, frame.displayed);
419 updateName(frame, frame.displayed);
420 updateIncomingRes(frame, frame.unit);
421 updateReadyCheck(frame, frame.unit);
422 updateRaidMarker(frame, frame.displayed);
425 eventFuncs["UNIT_HEALTH_FREQUENT"] = eventFuncs["UNIT_HEALTH"];
426 eventFuncs["PARTY_MEMBER_DISABLE"] = eventFuncs["PARTY_MEMBER_ENABLE"];
427 eventFuncs["PLAYER_FLAGS_CHANGED"] = eventFuncs["UNIT_CONNECTION"];
428 eventFuncs["UNIT_POWER_BAR_SHOW"] = eventFuncs["UNIT_DISPLAYPOWER"];
429 eventFuncs["UNIT_POWER_BAR_HIDE"] = eventFuncs["UNIT_DISPLAYPOWER"];
430 eventFuncs["READY_CHECK_CONFIRM"] = eventFuncs["READY_CHECK"];
431 eventFuncs["READY_CHECK_FINISHED"] = eventFuncs["READY_CHECK"];
432 eventFuncs["UNIT_ENTERED_VEHICLE"] = eventFuncs["UPDATE_ALL_BARS"];
433 eventFuncs["UNIT_EXITED_VEHICLE"] = eventFuncs["UPDATE_ALL_BARS"];
434 eventFuncs["UNIT_PET"] = eventFuncs["UPDATE_ALL_BARS"];
435 eventFuncs["GROUP_ROSTER_UPDATE"] = eventFuncs["UPDATE_ALL_BARS"];
436 eventFuncs["PLAYER_ENTERING_WORLD"] = eventFuncs["UPDATE_ALL_BARS"];
437 eventFuncs["PLAYER_FOCUS_CHANGED"] = eventFuncs["UPDATE_ALL_BARS"];
439 function M.UnitEvent(self, event)
440 eventFuncs[event](self);