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 RAID_CLASS_COLORS = RAID_CLASS_COLORS;
20 local READY_CHECK_READY_TEXTURE = READY_CHECK_READY_TEXTURE;
21 local READY_CHECK_NOT_READY_TEXTURE = READY_CHECK_NOT_READY_TEXTURE;
22 local READY_CHECK_WAITING_TEXTURE = READY_CHECK_WAITING_TEXTURE;
24 local checkIndicators = OmaRFIndicators.CheckIndicators;
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 powerColors = Settings.PowerColors;
32 local width = Settings.Width;
36 function M.RegisterEvents(frame)
37 frame:RegisterEvent("PLAYER_ENTERING_WORLD");
38 frame:RegisterEvent("PLAYER_ROLES_ASSIGNED");
39 frame:RegisterEvent("READY_CHECK");
40 frame:RegisterEvent("READY_CHECK_FINISHED");
41 frame:RegisterEvent("PARTY_MEMBER_ENABLE");
42 frame:RegisterEvent("PARTY_MEMBER_DISABLE");
43 frame:RegisterEvent("GROUP_ROSTER_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("UNIT_POWER");
52 frame:UnregisterEvent("UNIT_MAXPOWER");
53 frame:UnregisterEvent("UNIT_DISPLAYPOWER");
54 frame:UnregisterEvent("UNIT_POWER_BAR_SHOW");
55 frame:UnregisterEvent("UNIT_POWER_BAR_HIDE");
58 local function registerPower(frame)
59 frame.health:SetPoint("BOTTOMLEFT", frame.background, "BOTTOMLEFT", 0, 2);
60 frame.overlay:SetPoint("BOTTOMRIGHT", frame.background, "BOTTOMRIGHT", 0, 2);
62 frame:RegisterUnitEvent("UNIT_POWER", frame.unit);
63 frame:RegisterUnitEvent("UNIT_MAXPOWER", frame.unit);
64 frame:RegisterUnitEvent("UNIT_DISPLAYPOWER", frame.unit);
65 frame:RegisterUnitEvent("UNIT_POWER_BAR_SHOW", frame.unit);
66 frame:RegisterUnitEvent("UNIT_POWER_BAR_HIDE", frame.unit);
69 function M.RegisterUnitEvents(frame)
70 -- events are taken from FrameXML/CompactUnitFrame.lua
71 -- TODO raid marker support
72 local displayed = frame.unit ~= frame.displayed and frame.displayed or nil;
73 frame:RegisterUnitEvent("UNIT_HEALTH", frame.unit, displayed);
74 frame:RegisterUnitEvent("UNIT_HEALTH_FREQUENT", frame.unit, displayed);
75 frame:RegisterUnitEvent("UNIT_MAXHEALTH", frame.unit, displayed);
76 frame:RegisterUnitEvent("UNIT_NAME_UPDATE", frame.unit, displayed);
77 frame:RegisterUnitEvent("UNIT_AURA", frame.unit, displayed);
78 frame:RegisterUnitEvent("UNIT_HEAL_PREDICTION", frame.unit, displayed);
79 frame:RegisterUnitEvent("UNIT_ABSORB_AMOUNT_CHANGED", frame.unit, displayed);
80 frame:RegisterUnitEvent("UNIT_HEAL_ABSORB_AMOUNT_CHANGED", frame.unit, displayed);
81 frame:RegisterUnitEvent("UNIT_THREAT_SITUATION_UPDATE", frame.unit, displayed);
82 frame:RegisterUnitEvent("UNIT_CONNECTION", frame.unit, displayed);
83 frame:RegisterUnitEvent("INCOMING_RESURRECT_CHANGED", frame.unit, displayed);
84 frame:RegisterUnitEvent("PLAYER_FLAGS_CHANGED", frame.unit, displayed);
85 frame:RegisterUnitEvent("READY_CHECK_CONFIRM", frame.unit, displayed);
86 frame:RegisterUnitEvent("UNIT_ENTERED_VEHICLE", frame.unit, displayed);
87 frame:RegisterUnitEvent("UNIT_EXITED_VEHICLE", frame.unit, displayed);
88 frame:RegisterUnitEvent("UNIT_PET", frame.unit, displayed);
89 frame:RegisterUnitEvent("RAID_TARGET_UPDATE", frame.unit, displayed);
91 local registerUnitEvents = M.RegisterUnitEvents;
93 local function updateMaxHealth(frame, unit)
94 frame.health.max = UnitHealthMax(unit);
97 local function updateHealth(frame, unit)
98 local current, max = UnitHealth(unit), frame.health.max;
99 if current > max or max <= 0 then
100 -- somehow current health has gone over the maximum (missed maxhealth event possibly)
101 -- just put health bar full and update max health for next event
102 frame.health:SetWidth(width);
103 updateMaxHealth(frame, unit);
105 elseif UnitIsDeadOrGhost(unit) then
108 frame.health:SetWidth(current/max*width);
113 local function updateText(frame, unit)
114 local healthLost = frame.health.max - UnitHealth(unit);
115 if UnitIsDeadOrGhost(unit) then
116 frame.text:SetText("Dead");
118 elseif not UnitIsConnected(unit) then
119 frame.text:SetText("DC");
121 elseif UnitIsAFK(unit) then
122 frame.text:SetText("afk");
124 elseif UnitIsDND(unit) and healthLost == 0 then
125 frame.text:SetText("dnd");
127 elseif healthLost > 0 then
128 if healthLost > 1200000000 then -- 1.2B
129 frame.text:SetFormattedText("-%.1fB", healthLost / 1000000000);
130 elseif healthLost > 1200000 then -- 1.2M
131 frame.text:SetFormattedText("-%.1fM", healthLost / 1000000);
132 elseif healthLost > 1000 then -- 1K
133 frame.text:SetFormattedText("-%dK", healthLost / 1000);
135 frame.text:SetFormattedText("-%d", healthLost)
143 local function updateIncomingRes(frame, unit)
144 if UnitHasIncomingResurrection(unit) then frame.rez:Show();
145 else frame.rez:Hide(); end
148 local function updateMaxPower(frame, unit)
149 frame.mana.max = UnitPowerMax(unit);
152 local function updatePower(frame, unit)
153 local current, max = UnitPower(unit), frame.mana.max;
154 if current > max or max <= 0 then
155 frame.mana:SetWidth(width);
156 updateMaxPower(frame, unit);
158 frame.mana:SetWidth(current/max*width);
162 local function updatePowerColor(frame, unit)
163 frame.mana:SetVertexColor(unpack(powerColors[UnitPowerType(unit)]));
166 local function updateName(frame, unit)
167 local name = UnitName(unit);
168 if not name then return end
169 frame.name:SetText(ssub(name, 1, 6));
171 local _, class = UnitClass(unit);
172 local color = RAID_CLASS_COLORS[class];
173 if color then frame.name:SetVertexColor(color.r, color.g, color.b) end
176 local function updateHealPred(frame, unit)
177 local incoming = UnitGetIncomingHeals(unit) or 0;
179 -- always at least 1 pixel space for heal prediction
180 local space = width - frame.health:GetWidth() + 1;
181 incoming = (incoming / frame.health.max) * width;
182 frame.healpred:SetWidth(min(space, incoming));
183 frame.healpred:Show();
185 frame.healpred:Hide();
189 local function updateShield(frame, unit)
190 local shield = UnitGetTotalAbsorbs(unit) or 0;
192 local max = frame.health.max;
193 local space = width - frame.health:GetWidth();
194 shield = (shield / frame.health.max) * width;
195 if space < shield then
196 frame.shield:SetWidth(space);
197 frame.shieldhl:Show();
199 frame.shield:SetWidth(shield);
200 frame.shieldhl:Hide();
205 frame.shieldhl:Hide();
209 local function updateHealAbsorb(frame, unit)
210 local absorb = UnitGetTotalHealAbsorbs(unit) or 0;
212 local space = frame.health:GetWidth();
213 absorb = (absorb / frame.health.max) * width;
214 frame.healabsorb:SetWidth(min(space, absorb));
215 frame.healabsorb:Show();
217 frame.healabsorb:Hide();
221 local function updateAuras(frame, unit)
222 local alert = checkIndicators(frame, unit);
224 if frame.overlay.color ~= overlayColorAlert then
225 frame.overlay:SetVertexColor(unpack(overlayColorAlert));
226 frame.overlay.color = overlayColorAlert;
227 frame.overlay:Show();
229 elseif UnitDebuff(unit, 1, "RAID") ~= nil then
230 -- something dispellable
231 if frame.overlay.color ~= overlayColorDispel then
232 frame.overlay:SetVertexColor(unpack(overlayColorDispel));
233 frame.overlay.color = overlayColorDispel;
234 frame.overlay:Show();
236 -- don't overlay charmed when in vehicle
237 elseif UnitIsCharmed(unit) and unit == frame.unit then
238 if frame.overlay.color ~= overlayColorCharm then
239 frame.overlay:SetVertexColor(unpack(overlayColorCharm));
240 frame.overlay.color = overlayColorCharm;
241 frame.overlay:Show();
244 if frame.overlay.color ~= nil then
245 frame.overlay.color = nil;
246 frame.overlay:Hide();
251 local function updateAggro(frame, unit)
252 local status = UnitThreatSituation(unit);
253 if status and status > 0 then
254 frame.base:SetVertexColor(GetThreatStatusColor(status));
256 frame.base:SetVertexColor(unpack(baseColor));
260 local function updateVehicle(frame)
261 local shouldTargetVehicle = UnitHasVehicleUI(frame.unit) and
262 UnitTargetsVehicleInRaidUI(frame.unit) and UnitExists(frame.vehicle);
263 if shouldTargetVehicle then
264 if not frame.inVehicle then
265 frame.inVehicle = true;
266 frame.displayed = frame.vehicle;
267 registerUnitEvents(frame);
269 elseif frame.inVehicle then
270 frame.inVehicle = false;
271 frame.displayed = frame.unit;
272 registerUnitEvents(frame);
276 local function updateRole(frame, unit)
277 local role = UnitGroupRolesAssigned(unit);
278 if role == "HEALER" then
279 frame.role:SetTexCoord(0.75, 1, 0, 1);
281 if not frame.role.healer then
282 registerPower(frame);
283 frame.role.healer = true;
285 elseif role == "TANK" then
286 frame.role:SetTexCoord(0.5, 0.75, 0, 1);
288 if frame.role.healer then
289 unregisterPower(frame);
290 frame.role.healer = false;
294 if frame.role.healer then
295 unregisterPower(frame);
296 frame.role.healer = false;
301 local function updateReadyCheck(frame, unit)
302 local status = GetReadyCheckStatus(unit);
303 if status == "ready" then
304 frame.ready:SetTexture(READY_CHECK_READY_TEXTURE);
306 elseif status == "notready" then
307 frame.ready:SetTexture(READY_CHECK_NOT_READY_TEXTURE);
309 elseif status == "waiting" then
310 frame.ready:SetTexture(READY_CHECK_WAITING_TEXTURE);
317 local function updateRaidMarker(frame, unit)
318 --print(unit, "marker");
322 ["UNIT_HEALTH"] = function(frame)
323 updateHealth(frame, frame.displayed);
324 updateText(frame, frame.displayed);
325 updateShield(frame, frame.displayed);
326 updateHealAbsorb(frame, frame.displayed);
327 -- no heal prediction update, that doesn't overflow too much
328 -- raid marker update here, because marker is removed when unit dies
329 -- without a RAID_TARGET_UPDATE event
330 updateRaidMarker(frame, frame.unit);
332 ["UNIT_POWER"] = function(frame)
333 updatePower(frame, frame.displayed);
335 ["UNIT_AURA"] = function(frame)
336 updateAuras(frame, frame.displayed);
338 ["UNIT_HEAL_PREDICTION"] = function(frame)
339 updateHealPred(frame, frame.displayed);
341 ["UNIT_ABSORB_AMOUNT_CHANGED"] = function(frame)
342 updateShield(frame, frame.displayed);
344 ["UNIT_HEAL_ABSORB_AMOUNT_CHANGED"] = function(frame)
345 updateHealAbsorb(frame, frame.displayed);
347 ["UNIT_THREAT_SITUATION_UPDATE"] = function(frame)
348 updateAggro(frame, frame.displayed);
350 ["UNIT_MAXHEALTH"] = function(frame)
351 updateMaxHealth(frame, frame.displayed);
352 updateHealth(frame, frame.displayed);
353 updateText(frame, frame.displayed);
354 updateShield(frame, frame.displayed);
355 updateHealAbsorb(frame, frame.displayed);
357 ["UNIT_MAXPOWER"] = function(frame)
358 updateMaxPower(frame, frame.displayed);
359 updatePower(frame, frame.displayed);
361 ["UNIT_DISPLAYPOWER"] = function(frame)
362 updatePowerColor(frame, frame.displayed);
363 updateMaxPower(frame, frame.displayed);
364 updatePower(frame, frame.displayed);
366 ["UNIT_NAME_UPDATE"] = function(frame)
367 updateName(frame, frame.displayed);
369 ["UNIT_CONNECTION"] = function(frame)
370 updateText(frame, frame.displayed);
372 ["INCOMING_RESURRECT_CHANGED"] = function(frame)
373 updateIncomingRes(frame, frame.unit);
375 ["PARTY_MEMBER_ENABLE"] = function(frame)
376 -- new power info possibly (FrameXML/CompactUnitFrame.lua)
377 updateMaxPower(frame, frame.displayed);
378 updatePowerColor(frame, frame.displayed);
380 ["PLAYER_ROLES_ASSIGNED"] = function(frame)
381 updateRole(frame, frame.unit);
383 ["READY_CHECK"] = function(frame)
384 updateReadyCheck(frame, frame.unit);
386 ["RAID_TARGET_UPDATE"] = function(frame)
387 updateRaidMarker(frame, frame.unit);
389 ["UPDATE_ALL_BARS"] = function(frame)
390 updateRole(frame, frame.unit);
391 updateVehicle(frame);
392 updateMaxHealth(frame, frame.displayed);
393 updateMaxPower(frame, frame.displayed);
394 updateHealth(frame, frame.displayed);
395 updateText(frame, frame.displayed);
396 updatePower(frame, frame.displayed);
397 updateAuras(frame, frame.displayed);
398 updateShield(frame, frame.displayed);
399 updateHealPred(frame, frame.displayed);
400 updateHealAbsorb(frame, frame.displayed);
401 updatePowerColor(frame, frame.displayed);
402 updateAggro(frame, frame.displayed);
403 updateName(frame, frame.displayed);
404 updateIncomingRes(frame, frame.unit);
405 updateReadyCheck(frame, frame.unit);
406 updateRaidMarker(frame, frame.unit);
409 eventFuncs["UNIT_HEALTH_FREQUENT"] = eventFuncs["UNIT_HEALTH"];
410 eventFuncs["PARTY_MEMBER_DISABLE"] = eventFuncs["PARTY_MEMBER_ENABLE"];
411 eventFuncs["PLAYER_FLAGS_CHANGED"] = eventFuncs["UNIT_CONNECTION"];
412 eventFuncs["UNIT_POWER_BAR_SHOW"] = eventFuncs["UNIT_DISPLAYPOWER"];
413 eventFuncs["UNIT_POWER_BAR_HIDE"] = eventFuncs["UNIT_DISPLAYPOWER"];
414 eventFuncs["READY_CHECK_CONFIRM"] = eventFuncs["READY_CHECK"];
415 eventFuncs["READY_CHECK_FINISHED"] = eventFuncs["READY_CHECK"];
416 eventFuncs["UNIT_ENTERED_VEHICLE"] = eventFuncs["UPDATE_ALL_BARS"];
417 eventFuncs["UNIT_EXITED_VEHICLE"] = eventFuncs["UPDATE_ALL_BARS"];
418 eventFuncs["UNIT_PET"] = eventFuncs["UPDATE_ALL_BARS"];
419 eventFuncs["GROUP_ROSTER_UPDATE"] = eventFuncs["UPDATE_ALL_BARS"];
420 eventFuncs["PLAYER_ENTERING_WORLD"] = eventFuncs["UPDATE_ALL_BARS"];
421 eventFuncs["PLAYER_FOCUS_CHANGED"] = eventFuncs["UPDATE_ALL_BARS"];
423 function M.UnitEvent(self, event)
424 eventFuncs[event](self);