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 UnitGetTotalHealAbsorbs = UnitGetTotalHealAbsorbs;
15 local UnitHasVehicleUI, UnitTargetsVehicleInRaidUI = UnitHasVehicleUI, UnitTargetsVehicleInRaidUI;
16 local GetReadyCheckTimeLeft, GetReadyCheckStatus = GetReadyCheckTimeLeft, GetReadyCheckStatus;
17 local UnitGroupRolesAssigned = UnitGroupRolesAssigned;
18 local GetRaidTargetIndex, SetRaidTargetIconTexture = GetRaidTargetIndex, SetRaidTargetIconTexture;
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("GROUP_ROSTER_UPDATE");
42 frame:RegisterEvent("RAID_TARGET_UPDATE");
43 if frame.unit == "focus" then frame:RegisterEvent("PLAYER_FOCUS_CHANGED") end
46 local function unregisterPower(frame)
47 frame.health:SetPoint("BOTTOMLEFT", frame.background, "BOTTOMLEFT");
48 frame.overlay:SetPoint("BOTTOMRIGHT", frame.background, "BOTTOMRIGHT");
50 frame:UnregisterEvent("PARTY_MEMBER_ENABLE");
51 frame:UnregisterEvent("PARTY_MEMBER_DISABLE");
52 frame:UnregisterEvent("UNIT_POWER");
53 frame:UnregisterEvent("UNIT_MAXPOWER");
54 frame:UnregisterEvent("UNIT_DISPLAYPOWER");
55 frame:UnregisterEvent("UNIT_POWER_BAR_SHOW");
56 frame:UnregisterEvent("UNIT_POWER_BAR_HIDE");
59 local function registerPower(frame)
60 frame.health:SetPoint("BOTTOMLEFT", frame.background, "BOTTOMLEFT", 0, 2);
61 frame.overlay:SetPoint("BOTTOMRIGHT", frame.background, "BOTTOMRIGHT", 0, 2);
63 frame:RegisterEvent("PARTY_MEMBER_ENABLE");
64 frame:RegisterEvent("PARTY_MEMBER_DISABLE");
65 frame:RegisterUnitEvent("UNIT_POWER", frame.unit);
66 frame:RegisterUnitEvent("UNIT_MAXPOWER", frame.unit);
67 frame:RegisterUnitEvent("UNIT_DISPLAYPOWER", frame.unit);
68 frame:RegisterUnitEvent("UNIT_POWER_BAR_SHOW", frame.unit);
69 frame:RegisterUnitEvent("UNIT_POWER_BAR_HIDE", frame.unit);
72 function M.RegisterUnitEvents(frame)
73 -- events are taken from FrameXML/CompactUnitFrame.lua
74 local displayed = frame.unit ~= frame.displayed and frame.displayed or nil;
75 frame:RegisterUnitEvent("UNIT_HEALTH", frame.unit, displayed);
76 frame:RegisterUnitEvent("UNIT_HEALTH_FREQUENT", frame.unit, displayed);
77 frame:RegisterUnitEvent("UNIT_MAXHEALTH", frame.unit, displayed);
78 frame:RegisterUnitEvent("UNIT_NAME_UPDATE", frame.unit, displayed);
79 frame:RegisterUnitEvent("UNIT_AURA", frame.unit, displayed);
80 frame:RegisterUnitEvent("UNIT_HEAL_PREDICTION", frame.unit, displayed);
81 frame:RegisterUnitEvent("UNIT_ABSORB_AMOUNT_CHANGED", frame.unit, displayed);
82 frame:RegisterUnitEvent("UNIT_HEAL_ABSORB_AMOUNT_CHANGED", frame.unit, displayed);
83 frame:RegisterUnitEvent("UNIT_THREAT_SITUATION_UPDATE", frame.unit, displayed);
84 frame:RegisterUnitEvent("UNIT_CONNECTION", frame.unit, displayed);
85 frame:RegisterUnitEvent("PLAYER_FLAGS_CHANGED", frame.unit, displayed);
86 frame:RegisterUnitEvent("READY_CHECK_CONFIRM", frame.unit, displayed);
87 frame:RegisterUnitEvent("UNIT_ENTERED_VEHICLE", frame.unit, displayed);
88 frame:RegisterUnitEvent("UNIT_EXITED_VEHICLE", frame.unit, displayed);
89 frame:RegisterUnitEvent("UNIT_PET", 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 current <= 0 or 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 updateMaxPower(frame, unit)
144 frame.mana.max = UnitPowerMax(unit);
147 local function updatePower(frame, unit)
148 local current, max = UnitPower(unit), frame.mana.max;
151 elseif current > max or max <= 0 then
152 frame.mana:SetWidth(width);
153 updateMaxPower(frame, unit);
156 frame.mana:SetWidth(current/max*width);
161 local function updatePowerColor(frame, unit)
162 frame.mana:SetVertexColor(unpack(powerColors[UnitPowerType(unit)]));
165 local function updateName(frame, unit)
166 local name = UnitName(unit);
167 if not name then return end
168 frame.name:SetText(ssub(name, 1, 6));
170 local _, class = UnitClass(unit);
171 local color = RAID_CLASS_COLORS[class];
172 if color then frame.name:SetVertexColor(color.r, color.g, color.b) end
175 local function updateHealPred(frame, unit)
176 local incoming = UnitGetIncomingHeals(unit) or 0;
178 -- always at least 1 pixel space for heal prediction
179 local space = width - frame.health:GetWidth() + 1;
180 incoming = (incoming / frame.health.max) * width;
181 frame.healpred:SetWidth(min(space, incoming));
182 frame.healpred:Show();
184 frame.healpred:Hide();
188 local function updateShield(frame, unit)
189 local shield = UnitGetTotalAbsorbs(unit) or 0;
191 local space = width - frame.health:GetWidth();
192 shield = (shield / frame.health.max) * width;
195 frame.shieldhl:Show();
196 elseif space < shield then
197 frame.shield:SetWidth(space);
199 frame.shieldhl:Show();
201 frame.shield:SetWidth(shield);
203 frame.shieldhl:Hide();
207 frame.shieldhl:Hide();
211 local function updateHealAbsorb(frame, unit)
212 local absorb = UnitGetTotalHealAbsorbs(unit) or 0;
214 local space = frame.health:GetWidth();
215 absorb = (absorb / frame.health.max) * width;
216 frame.healabsorb:SetWidth(min(space, absorb));
217 frame.healabsorb:Show();
219 frame.healabsorb:Hide();
223 local function updateAuras(frame, unit)
224 local alert = checkIndicators(frame, unit);
226 if frame.overlay.color ~= overlayColorAlert then
227 frame.overlay:SetVertexColor(unpack(overlayColorAlert));
228 frame.overlay.color = overlayColorAlert;
229 frame.overlay:Show();
231 elseif UnitDebuff(unit, 1, "RAID") ~= nil then
232 -- something dispellable
233 if frame.overlay.color ~= overlayColorDispel then
234 frame.overlay:SetVertexColor(unpack(overlayColorDispel));
235 frame.overlay.color = overlayColorDispel;
236 frame.overlay:Show();
238 -- don't overlay charmed when in vehicle
239 elseif UnitIsCharmed(unit) and unit == frame.unit then
240 if frame.overlay.color ~= overlayColorCharm then
241 frame.overlay:SetVertexColor(unpack(overlayColorCharm));
242 frame.overlay.color = overlayColorCharm;
243 frame.overlay:Show();
246 if frame.overlay.color ~= nil then
247 frame.overlay.color = nil;
248 frame.overlay:Hide();
253 local function updateAggro(frame, unit)
254 local status = UnitThreatSituation(unit);
255 if status and status > 0 then
256 frame.base:SetVertexColor(GetThreatStatusColor(status));
258 frame.base:SetVertexColor(unpack(baseColor));
262 local function updateVehicle(frame)
263 local shouldTargetVehicle = UnitHasVehicleUI(frame.unit) and
264 UnitTargetsVehicleInRaidUI(frame.unit) and UnitExists(frame.vehicle);
265 if shouldTargetVehicle then
266 if not frame.inVehicle then
267 frame.inVehicle = true;
268 frame.displayed = frame.vehicle;
269 registerUnitEvents(frame);
271 elseif frame.inVehicle then
272 frame.inVehicle = false;
273 frame.displayed = frame.unit;
274 registerUnitEvents(frame);
278 local function updateRole(frame, unit)
279 local role = UnitGroupRolesAssigned(unit);
280 if role == "HEALER" then
281 frame.role:SetTexCoord(0.75, 1, 0, 1);
283 registerPower(frame);
284 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 frame.role.healer = false;
290 unregisterPower(frame);
294 if frame.role.healer then
295 frame.role.healer = false;
296 unregisterPower(frame);
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 local index = GetRaidTargetIndex(unit);
320 SetRaidTargetIconTexture(frame.targeticon, index);
321 frame.targeticon:Show();
323 frame.targeticon:Hide();
328 ["UNIT_HEALTH"] = function(frame)
329 updateHealth(frame, frame.displayed);
330 updateText(frame, frame.displayed);
331 updateShield(frame, frame.displayed);
332 updateHealAbsorb(frame, frame.displayed);
333 -- no heal prediction update, that doesn't overflow too much
334 -- raid marker update here, because marker is removed when unit dies
335 -- without a RAID_TARGET_UPDATE event
336 updateRaidMarker(frame, frame.unit);
338 ["UNIT_POWER"] = function(frame)
339 updatePower(frame, frame.displayed);
341 ["UNIT_AURA"] = function(frame)
342 updateAuras(frame, frame.displayed);
344 ["UNIT_HEAL_PREDICTION"] = function(frame)
345 updateHealPred(frame, frame.displayed);
347 ["UNIT_ABSORB_AMOUNT_CHANGED"] = function(frame)
348 updateShield(frame, frame.displayed);
350 ["UNIT_HEAL_ABSORB_AMOUNT_CHANGED"] = function(frame)
351 updateHealAbsorb(frame, frame.displayed);
353 ["UNIT_THREAT_SITUATION_UPDATE"] = function(frame)
354 updateAggro(frame, frame.displayed);
356 ["UNIT_MAXHEALTH"] = function(frame)
357 updateMaxHealth(frame, frame.displayed);
358 updateHealth(frame, frame.displayed);
359 updateText(frame, frame.displayed);
360 updateShield(frame, frame.displayed);
361 updateHealAbsorb(frame, frame.displayed);
363 ["UNIT_MAXPOWER"] = function(frame)
364 updateMaxPower(frame, frame.displayed);
365 updatePower(frame, frame.displayed);
367 ["UNIT_DISPLAYPOWER"] = function(frame)
368 updatePowerColor(frame, frame.displayed);
369 updateMaxPower(frame, frame.displayed);
370 updatePower(frame, frame.displayed);
372 ["UNIT_NAME_UPDATE"] = function(frame)
373 updateName(frame, frame.displayed);
375 ["UNIT_CONNECTION"] = function(frame)
376 updateText(frame, frame.displayed);
378 ["PARTY_MEMBER_ENABLE"] = function(frame)
379 -- new power info possibly (FrameXML/CompactUnitFrame.lua)
380 updateMaxPower(frame, frame.displayed);
381 updatePowerColor(frame, frame.displayed);
383 ["PLAYER_ROLES_ASSIGNED"] = function(frame)
384 updateRole(frame, frame.unit);
386 ["READY_CHECK"] = function(frame)
387 updateReadyCheck(frame, frame.unit);
389 ["RAID_TARGET_UPDATE"] = function(frame)
390 updateRaidMarker(frame, frame.displayed);
392 ["UPDATE_ALL_BARS"] = function(frame)
393 updateRole(frame, frame.unit);
394 updateVehicle(frame);
395 updateMaxHealth(frame, frame.displayed);
396 updateHealth(frame, frame.displayed);
397 updateText(frame, frame.displayed);
398 if frame.role.healer then
399 updateMaxPower(frame, frame.displayed);
400 updatePower(frame, frame.displayed);
401 updatePowerColor(frame, frame.displayed);
403 updateAuras(frame, frame.displayed);
404 updateShield(frame, frame.displayed);
405 updateHealPred(frame, frame.displayed);
406 updateHealAbsorb(frame, frame.displayed);
407 updateAggro(frame, frame.displayed);
408 updateName(frame, frame.displayed);
409 updateReadyCheck(frame, frame.unit);
410 updateRaidMarker(frame, frame.displayed);
413 eventFuncs["UNIT_HEALTH_FREQUENT"] = eventFuncs["UNIT_HEALTH"];
414 eventFuncs["PARTY_MEMBER_DISABLE"] = eventFuncs["PARTY_MEMBER_ENABLE"];
415 eventFuncs["PLAYER_FLAGS_CHANGED"] = eventFuncs["UNIT_CONNECTION"];
416 eventFuncs["UNIT_POWER_BAR_SHOW"] = eventFuncs["UNIT_DISPLAYPOWER"];
417 eventFuncs["UNIT_POWER_BAR_HIDE"] = eventFuncs["UNIT_DISPLAYPOWER"];
418 eventFuncs["READY_CHECK_CONFIRM"] = eventFuncs["READY_CHECK"];
419 eventFuncs["READY_CHECK_FINISHED"] = eventFuncs["READY_CHECK"];
420 eventFuncs["UNIT_ENTERED_VEHICLE"] = eventFuncs["UPDATE_ALL_BARS"];
421 eventFuncs["UNIT_EXITED_VEHICLE"] = eventFuncs["UPDATE_ALL_BARS"];
422 eventFuncs["UNIT_PET"] = eventFuncs["UPDATE_ALL_BARS"];
423 eventFuncs["GROUP_ROSTER_UPDATE"] = eventFuncs["UPDATE_ALL_BARS"];
424 eventFuncs["PLAYER_ENTERING_WORLD"] = eventFuncs["UPDATE_ALL_BARS"];
425 eventFuncs["PLAYER_FOCUS_CHANGED"] = eventFuncs["UPDATE_ALL_BARS"];
427 function M.UnitEvent(self, event)
428 eventFuncs[event](self);