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 local displayed = frame.unit ~= frame.displayed and frame.displayed or nil;
76 frame:RegisterUnitEvent("UNIT_HEALTH", frame.unit, displayed);
77 frame:RegisterUnitEvent("UNIT_HEALTH_FREQUENT", frame.unit, displayed);
78 frame:RegisterUnitEvent("UNIT_MAXHEALTH", frame.unit, displayed);
79 frame:RegisterUnitEvent("UNIT_NAME_UPDATE", frame.unit, displayed);
80 frame:RegisterUnitEvent("UNIT_AURA", frame.unit, displayed);
81 frame:RegisterUnitEvent("UNIT_HEAL_PREDICTION", frame.unit, displayed);
82 frame:RegisterUnitEvent("UNIT_ABSORB_AMOUNT_CHANGED", frame.unit, displayed);
83 frame:RegisterUnitEvent("UNIT_HEAL_ABSORB_AMOUNT_CHANGED", frame.unit, displayed);
84 frame:RegisterUnitEvent("UNIT_THREAT_SITUATION_UPDATE", frame.unit, displayed);
85 frame:RegisterUnitEvent("UNIT_CONNECTION", frame.unit, displayed);
86 frame:RegisterUnitEvent("INCOMING_RESURRECT_CHANGED", frame.unit, displayed);
87 frame:RegisterUnitEvent("PLAYER_FLAGS_CHANGED", frame.unit, displayed);
88 frame:RegisterUnitEvent("READY_CHECK_CONFIRM", frame.unit, displayed);
89 frame:RegisterUnitEvent("UNIT_ENTERED_VEHICLE", frame.unit, displayed);
90 frame:RegisterUnitEvent("UNIT_EXITED_VEHICLE", frame.unit, displayed);
91 frame:RegisterUnitEvent("UNIT_PET", frame.unit, displayed);
93 local registerUnitEvents = M.RegisterUnitEvents;
95 local function updateMaxHealth(frame, unit)
96 frame.health.max = UnitHealthMax(unit);
99 local function updateHealth(frame, unit)
100 local current, max = UnitHealth(unit), frame.health.max;
101 if current > max or max <= 0 then
102 -- somehow current health has gone over the maximum (missed maxhealth event possibly)
103 -- just put health bar full and update max health for next event
104 frame.health:SetWidth(width);
105 updateMaxHealth(frame, unit);
107 elseif current <= 0 or UnitIsDeadOrGhost(unit) then
110 frame.health:SetWidth(current/max*width);
115 local function updateText(frame, unit)
116 local healthLost = frame.health.max - UnitHealth(unit);
117 if UnitIsDeadOrGhost(unit) then
118 frame.text:SetText("Dead");
120 elseif not UnitIsConnected(unit) then
121 frame.text:SetText("DC");
123 elseif UnitIsAFK(unit) then
124 frame.text:SetText("afk");
126 elseif UnitIsDND(unit) and healthLost == 0 then
127 frame.text:SetText("dnd");
129 elseif healthLost > 0 then
130 if healthLost > 1200000000 then -- 1.2B
131 frame.text:SetFormattedText("-%.1fB", healthLost / 1000000000);
132 elseif healthLost > 1200000 then -- 1.2M
133 frame.text:SetFormattedText("-%.1fM", healthLost / 1000000);
134 elseif healthLost > 1000 then -- 1K
135 frame.text:SetFormattedText("-%dK", healthLost / 1000);
137 frame.text:SetFormattedText("-%d", healthLost)
145 local function updateIncomingRes(frame, unit)
146 if UnitHasIncomingResurrection(unit) then frame.rez:Show();
147 else frame.rez:Hide(); end
150 local function updateMaxPower(frame, unit)
151 frame.mana.max = UnitPowerMax(unit);
154 local function updatePower(frame, unit)
155 local current, max = UnitPower(unit), frame.mana.max;
158 elseif current > max or max <= 0 then
159 frame.mana:SetWidth(width);
160 updateMaxPower(frame, unit);
163 frame.mana:SetWidth(current/max*width);
168 local function updatePowerColor(frame, unit)
169 frame.mana:SetVertexColor(unpack(powerColors[UnitPowerType(unit)]));
172 local function updateName(frame, unit)
173 local name = UnitName(unit);
174 if not name then return end
175 frame.name:SetText(ssub(name, 1, 6));
177 local _, class = UnitClass(unit);
178 local color = RAID_CLASS_COLORS[class];
179 if color then frame.name:SetVertexColor(color.r, color.g, color.b) end
182 local function updateHealPred(frame, unit)
183 local incoming = UnitGetIncomingHeals(unit) or 0;
185 -- always at least 1 pixel space for heal prediction
186 local space = width - frame.health:GetWidth() + 1;
187 incoming = (incoming / frame.health.max) * width;
188 frame.healpred:SetWidth(min(space, incoming));
189 frame.healpred:Show();
191 frame.healpred:Hide();
195 local function updateShield(frame, unit)
196 local shield = UnitGetTotalAbsorbs(unit) or 0;
198 local space = width - frame.health:GetWidth();
199 shield = (shield / frame.health.max) * width;
202 frame.shieldhl:Show();
203 elseif space < shield then
204 frame.shield:SetWidth(space);
206 frame.shieldhl:Show();
208 frame.shield:SetWidth(shield);
210 frame.shieldhl:Hide();
214 frame.shieldhl:Hide();
218 local function updateHealAbsorb(frame, unit)
219 local absorb = UnitGetTotalHealAbsorbs(unit) or 0;
221 local space = frame.health:GetWidth();
222 absorb = (absorb / frame.health.max) * width;
223 frame.healabsorb:SetWidth(min(space, absorb));
224 frame.healabsorb:Show();
226 frame.healabsorb:Hide();
230 local function updateAuras(frame, unit)
231 local alert = checkIndicators(frame, unit);
233 if frame.overlay.color ~= overlayColorAlert then
234 frame.overlay:SetVertexColor(unpack(overlayColorAlert));
235 frame.overlay.color = overlayColorAlert;
236 frame.overlay:Show();
238 elseif UnitDebuff(unit, 1, "RAID") ~= nil then
239 -- something dispellable
240 if frame.overlay.color ~= overlayColorDispel then
241 frame.overlay:SetVertexColor(unpack(overlayColorDispel));
242 frame.overlay.color = overlayColorDispel;
243 frame.overlay:Show();
245 -- don't overlay charmed when in vehicle
246 elseif UnitIsCharmed(unit) and unit == frame.unit then
247 if frame.overlay.color ~= overlayColorCharm then
248 frame.overlay:SetVertexColor(unpack(overlayColorCharm));
249 frame.overlay.color = overlayColorCharm;
250 frame.overlay:Show();
253 if frame.overlay.color ~= nil then
254 frame.overlay.color = nil;
255 frame.overlay:Hide();
260 local function updateAggro(frame, unit)
261 local status = UnitThreatSituation(unit);
262 if status and status > 0 then
263 frame.base:SetVertexColor(GetThreatStatusColor(status));
265 frame.base:SetVertexColor(unpack(baseColor));
269 local function updateVehicle(frame)
270 local shouldTargetVehicle = UnitHasVehicleUI(frame.unit) and
271 UnitTargetsVehicleInRaidUI(frame.unit) and UnitExists(frame.vehicle);
272 if shouldTargetVehicle then
273 if not frame.inVehicle then
274 frame.inVehicle = true;
275 frame.displayed = frame.vehicle;
276 registerUnitEvents(frame);
278 elseif frame.inVehicle then
279 frame.inVehicle = false;
280 frame.displayed = frame.unit;
281 registerUnitEvents(frame);
285 local function updateRole(frame, unit)
286 local role = UnitGroupRolesAssigned(unit);
287 if role == "HEALER" then
288 frame.role:SetTexCoord(0.75, 1, 0, 1);
290 registerPower(frame);
291 frame.role.healer = true;
292 elseif role == "TANK" then
293 frame.role:SetTexCoord(0.5, 0.75, 0, 1);
295 if frame.role.healer then
296 frame.role.healer = false;
297 unregisterPower(frame);
301 if frame.role.healer then
302 frame.role.healer = false;
303 unregisterPower(frame);
308 local function updateReadyCheck(frame, unit)
309 local status = GetReadyCheckStatus(unit);
310 if status == "ready" then
311 frame.ready:SetTexture(READY_CHECK_READY_TEXTURE);
313 elseif status == "notready" then
314 frame.ready:SetTexture(READY_CHECK_NOT_READY_TEXTURE);
316 elseif status == "waiting" then
317 frame.ready:SetTexture(READY_CHECK_WAITING_TEXTURE);
324 local function updateRaidMarker(frame, unit)
325 local index = GetRaidTargetIndex(unit);
327 SetRaidTargetIconTexture(frame.targeticon, index);
328 frame.targeticon:Show();
330 frame.targeticon:Hide();
335 ["UNIT_HEALTH"] = function(frame)
336 updateHealth(frame, frame.displayed);
337 updateText(frame, frame.displayed);
338 updateShield(frame, frame.displayed);
339 updateHealAbsorb(frame, frame.displayed);
340 -- no heal prediction update, that doesn't overflow too much
341 -- raid marker update here, because marker is removed when unit dies
342 -- without a RAID_TARGET_UPDATE event
343 updateRaidMarker(frame, frame.unit);
345 ["UNIT_POWER"] = function(frame)
346 updatePower(frame, frame.displayed);
348 ["UNIT_AURA"] = function(frame)
349 updateAuras(frame, frame.displayed);
351 ["UNIT_HEAL_PREDICTION"] = function(frame)
352 updateHealPred(frame, frame.displayed);
354 ["UNIT_ABSORB_AMOUNT_CHANGED"] = function(frame)
355 updateShield(frame, frame.displayed);
357 ["UNIT_HEAL_ABSORB_AMOUNT_CHANGED"] = function(frame)
358 updateHealAbsorb(frame, frame.displayed);
360 ["UNIT_THREAT_SITUATION_UPDATE"] = function(frame)
361 updateAggro(frame, frame.displayed);
363 ["UNIT_MAXHEALTH"] = function(frame)
364 updateMaxHealth(frame, frame.displayed);
365 updateHealth(frame, frame.displayed);
366 updateText(frame, frame.displayed);
367 updateShield(frame, frame.displayed);
368 updateHealAbsorb(frame, frame.displayed);
370 ["UNIT_MAXPOWER"] = function(frame)
371 updateMaxPower(frame, frame.displayed);
372 updatePower(frame, frame.displayed);
374 ["UNIT_DISPLAYPOWER"] = function(frame)
375 updatePowerColor(frame, frame.displayed);
376 updateMaxPower(frame, frame.displayed);
377 updatePower(frame, frame.displayed);
379 ["UNIT_NAME_UPDATE"] = function(frame)
380 updateName(frame, frame.displayed);
382 ["UNIT_CONNECTION"] = function(frame)
383 updateText(frame, frame.displayed);
385 ["INCOMING_RESURRECT_CHANGED"] = function(frame)
386 updateIncomingRes(frame, frame.unit);
388 ["PARTY_MEMBER_ENABLE"] = function(frame)
389 -- new power info possibly (FrameXML/CompactUnitFrame.lua)
390 updateMaxPower(frame, frame.displayed);
391 updatePowerColor(frame, frame.displayed);
393 ["PLAYER_ROLES_ASSIGNED"] = function(frame)
394 updateRole(frame, frame.unit);
396 ["READY_CHECK"] = function(frame)
397 updateReadyCheck(frame, frame.unit);
399 ["RAID_TARGET_UPDATE"] = function(frame)
400 updateRaidMarker(frame, frame.displayed);
402 ["UPDATE_ALL_BARS"] = function(frame)
403 updateRole(frame, frame.unit);
404 updateVehicle(frame);
405 updateMaxHealth(frame, frame.displayed);
406 updateHealth(frame, frame.displayed);
407 updateText(frame, frame.displayed);
408 if frame.role.healer then
409 updateMaxPower(frame, frame.displayed);
410 updatePower(frame, frame.displayed);
411 updatePowerColor(frame, frame.displayed);
413 updateAuras(frame, frame.displayed);
414 updateShield(frame, frame.displayed);
415 updateHealPred(frame, frame.displayed);
416 updateHealAbsorb(frame, frame.displayed);
417 updateAggro(frame, frame.displayed);
418 updateName(frame, frame.displayed);
419 updateIncomingRes(frame, frame.unit);
420 updateReadyCheck(frame, frame.unit);
421 updateRaidMarker(frame, frame.displayed);
424 eventFuncs["UNIT_HEALTH_FREQUENT"] = eventFuncs["UNIT_HEALTH"];
425 eventFuncs["PARTY_MEMBER_DISABLE"] = eventFuncs["PARTY_MEMBER_ENABLE"];
426 eventFuncs["PLAYER_FLAGS_CHANGED"] = eventFuncs["UNIT_CONNECTION"];
427 eventFuncs["UNIT_POWER_BAR_SHOW"] = eventFuncs["UNIT_DISPLAYPOWER"];
428 eventFuncs["UNIT_POWER_BAR_HIDE"] = eventFuncs["UNIT_DISPLAYPOWER"];
429 eventFuncs["READY_CHECK_CONFIRM"] = eventFuncs["READY_CHECK"];
430 eventFuncs["READY_CHECK_FINISHED"] = eventFuncs["READY_CHECK"];
431 eventFuncs["UNIT_ENTERED_VEHICLE"] = eventFuncs["UPDATE_ALL_BARS"];
432 eventFuncs["UNIT_EXITED_VEHICLE"] = eventFuncs["UPDATE_ALL_BARS"];
433 eventFuncs["UNIT_PET"] = eventFuncs["UPDATE_ALL_BARS"];
434 eventFuncs["GROUP_ROSTER_UPDATE"] = eventFuncs["UPDATE_ALL_BARS"];
435 eventFuncs["PLAYER_ENTERING_WORLD"] = eventFuncs["UPDATE_ALL_BARS"];
436 eventFuncs["PLAYER_FOCUS_CHANGED"] = eventFuncs["UPDATE_ALL_BARS"];
438 function M.UnitEvent(self, event)
439 eventFuncs[event](self);