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("GROUP_ROSTER_UPDATE");
42 if frame.unit == "focus" then frame:RegisterEvent("PLAYER_FOCUS_CHANGED") end
45 local function unregisterPower(frame)
46 frame.health:SetPoint("BOTTOMLEFT", frame.background, "BOTTOMLEFT");
47 frame.overlay:SetPoint("BOTTOMRIGHT", frame.background, "BOTTOMRIGHT");
49 frame:UnregisterEvent("PARTY_MEMBER_ENABLE");
50 frame:UnregisterEvent("PARTY_MEMBER_DISABLE");
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:RegisterEvent("PARTY_MEMBER_ENABLE");
63 frame:RegisterEvent("PARTY_MEMBER_DISABLE");
64 frame:RegisterUnitEvent("UNIT_POWER", frame.unit);
65 frame:RegisterUnitEvent("UNIT_MAXPOWER", frame.unit);
66 frame:RegisterUnitEvent("UNIT_DISPLAYPOWER", frame.unit);
67 frame:RegisterUnitEvent("UNIT_POWER_BAR_SHOW", frame.unit);
68 frame:RegisterUnitEvent("UNIT_POWER_BAR_HIDE", frame.unit);
71 function M.RegisterUnitEvents(frame)
72 -- events are taken from FrameXML/CompactUnitFrame.lua
73 -- TODO raid marker support
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("INCOMING_RESURRECT_CHANGED", frame.unit, displayed);
86 frame:RegisterUnitEvent("PLAYER_FLAGS_CHANGED", frame.unit, displayed);
87 frame:RegisterUnitEvent("READY_CHECK_CONFIRM", frame.unit, displayed);
88 frame:RegisterUnitEvent("UNIT_ENTERED_VEHICLE", frame.unit, displayed);
89 frame:RegisterUnitEvent("UNIT_EXITED_VEHICLE", frame.unit, displayed);
90 frame:RegisterUnitEvent("UNIT_PET", frame.unit, displayed);
91 frame:RegisterUnitEvent("RAID_TARGET_UPDATE", 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 if not frame.role.healer then
291 registerPower(frame);
292 frame.role.healer = true;
294 elseif role == "TANK" then
295 frame.role:SetTexCoord(0.5, 0.75, 0, 1);
297 if frame.role.healer then
298 unregisterPower(frame);
299 frame.role.healer = false;
303 if frame.role.healer then
304 unregisterPower(frame);
305 frame.role.healer = false;
310 local function updateReadyCheck(frame, unit)
311 local status = GetReadyCheckStatus(unit);
312 if status == "ready" then
313 frame.ready:SetTexture(READY_CHECK_READY_TEXTURE);
315 elseif status == "notready" then
316 frame.ready:SetTexture(READY_CHECK_NOT_READY_TEXTURE);
318 elseif status == "waiting" then
319 frame.ready:SetTexture(READY_CHECK_WAITING_TEXTURE);
326 local function updateRaidMarker(frame, unit)
327 --print(unit, "marker");
331 ["UNIT_HEALTH"] = function(frame)
332 updateHealth(frame, frame.displayed);
333 updateText(frame, frame.displayed);
334 updateShield(frame, frame.displayed);
335 updateHealAbsorb(frame, frame.displayed);
336 -- no heal prediction update, that doesn't overflow too much
337 -- raid marker update here, because marker is removed when unit dies
338 -- without a RAID_TARGET_UPDATE event
339 updateRaidMarker(frame, frame.unit);
341 ["UNIT_POWER"] = function(frame)
342 updatePower(frame, frame.displayed);
344 ["UNIT_AURA"] = function(frame)
345 updateAuras(frame, frame.displayed);
347 ["UNIT_HEAL_PREDICTION"] = function(frame)
348 updateHealPred(frame, frame.displayed);
350 ["UNIT_ABSORB_AMOUNT_CHANGED"] = function(frame)
351 updateShield(frame, frame.displayed);
353 ["UNIT_HEAL_ABSORB_AMOUNT_CHANGED"] = function(frame)
354 updateHealAbsorb(frame, frame.displayed);
356 ["UNIT_THREAT_SITUATION_UPDATE"] = function(frame)
357 updateAggro(frame, frame.displayed);
359 ["UNIT_MAXHEALTH"] = function(frame)
360 updateMaxHealth(frame, frame.displayed);
361 updateHealth(frame, frame.displayed);
362 updateText(frame, frame.displayed);
363 updateShield(frame, frame.displayed);
364 updateHealAbsorb(frame, frame.displayed);
366 ["UNIT_MAXPOWER"] = function(frame)
367 updateMaxPower(frame, frame.displayed);
368 updatePower(frame, frame.displayed);
370 ["UNIT_DISPLAYPOWER"] = function(frame)
371 updatePowerColor(frame, frame.displayed);
372 updateMaxPower(frame, frame.displayed);
373 updatePower(frame, frame.displayed);
375 ["UNIT_NAME_UPDATE"] = function(frame)
376 updateName(frame, frame.displayed);
378 ["UNIT_CONNECTION"] = function(frame)
379 updateText(frame, frame.displayed);
381 ["INCOMING_RESURRECT_CHANGED"] = function(frame)
382 updateIncomingRes(frame, frame.unit);
384 ["PARTY_MEMBER_ENABLE"] = function(frame)
385 -- new power info possibly (FrameXML/CompactUnitFrame.lua)
386 updateMaxPower(frame, frame.displayed);
387 updatePowerColor(frame, frame.displayed);
389 ["PLAYER_ROLES_ASSIGNED"] = function(frame)
390 updateRole(frame, frame.unit);
392 ["READY_CHECK"] = function(frame)
393 updateReadyCheck(frame, frame.unit);
395 ["RAID_TARGET_UPDATE"] = function(frame)
396 updateRaidMarker(frame, frame.unit);
398 ["UPDATE_ALL_BARS"] = function(frame)
399 updateRole(frame, frame.unit);
400 updateVehicle(frame);
401 updateMaxHealth(frame, frame.displayed);
402 updateHealth(frame, frame.displayed);
403 updateText(frame, frame.displayed);
404 if frame.role.healer then
405 updateMaxPower(frame, frame.displayed);
406 updatePower(frame, frame.displayed);
407 updatePowerColor(frame, frame.displayed);
409 updateAuras(frame, frame.displayed);
410 updateShield(frame, frame.displayed);
411 updateHealPred(frame, frame.displayed);
412 updateHealAbsorb(frame, frame.displayed);
413 updateAggro(frame, frame.displayed);
414 updateName(frame, frame.displayed);
415 updateIncomingRes(frame, frame.unit);
416 updateReadyCheck(frame, frame.unit);
417 updateRaidMarker(frame, frame.unit);
420 eventFuncs["UNIT_HEALTH_FREQUENT"] = eventFuncs["UNIT_HEALTH"];
421 eventFuncs["PARTY_MEMBER_DISABLE"] = eventFuncs["PARTY_MEMBER_ENABLE"];
422 eventFuncs["PLAYER_FLAGS_CHANGED"] = eventFuncs["UNIT_CONNECTION"];
423 eventFuncs["UNIT_POWER_BAR_SHOW"] = eventFuncs["UNIT_DISPLAYPOWER"];
424 eventFuncs["UNIT_POWER_BAR_HIDE"] = eventFuncs["UNIT_DISPLAYPOWER"];
425 eventFuncs["READY_CHECK_CONFIRM"] = eventFuncs["READY_CHECK"];
426 eventFuncs["READY_CHECK_FINISHED"] = eventFuncs["READY_CHECK"];
427 eventFuncs["UNIT_ENTERED_VEHICLE"] = eventFuncs["UPDATE_ALL_BARS"];
428 eventFuncs["UNIT_EXITED_VEHICLE"] = eventFuncs["UPDATE_ALL_BARS"];
429 eventFuncs["UNIT_PET"] = eventFuncs["UPDATE_ALL_BARS"];
430 eventFuncs["GROUP_ROSTER_UPDATE"] = eventFuncs["UPDATE_ALL_BARS"];
431 eventFuncs["PLAYER_ENTERING_WORLD"] = eventFuncs["UPDATE_ALL_BARS"];
432 eventFuncs["PLAYER_FOCUS_CHANGED"] = eventFuncs["UPDATE_ALL_BARS"];
434 function M.UnitEvent(self, event)
435 eventFuncs[event](self);