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 -- events are taken from FrameXML/CompactUnitFrame.lua
38 -- TODO raid marker support
39 local displayed = frame.unit ~= frame.displayed and frame.displayed or nil;
40 frame:RegisterUnitEvent("UNIT_HEALTH", frame.unit, displayed);
41 frame:RegisterUnitEvent("UNIT_HEALTH_FREQUENT", frame.unit, displayed);
42 frame:RegisterUnitEvent("UNIT_MAXHEALTH", frame.unit, displayed);
43 frame:RegisterUnitEvent("UNIT_POWER", frame.unit, displayed);
44 frame:RegisterUnitEvent("UNIT_MAXPOWER", frame.unit, displayed);
45 frame:RegisterUnitEvent("UNIT_DISPLAYPOWER", frame.unit, displayed);
46 frame:RegisterUnitEvent("UNIT_POWER_BAR_SHOW", frame.unit, displayed);
47 frame:RegisterUnitEvent("UNIT_POWER_BAR_HIDE", frame.unit, displayed);
48 frame:RegisterUnitEvent("UNIT_NAME_UPDATE", frame.unit, displayed);
49 frame:RegisterUnitEvent("UNIT_AURA", frame.unit, displayed);
50 frame:RegisterUnitEvent("UNIT_HEAL_PREDICTION", frame.unit, displayed);
51 frame:RegisterUnitEvent("UNIT_ABSORB_AMOUNT_CHANGED", frame.unit, displayed);
52 frame:RegisterUnitEvent("UNIT_HEAL_ABSORB_AMOUNT_CHANGED", frame.unit, displayed);
53 frame:RegisterUnitEvent("UNIT_THREAT_SITUATION_UPDATE", frame.unit, displayed);
54 frame:RegisterUnitEvent("UNIT_CONNECTION", frame.unit, displayed);
55 frame:RegisterUnitEvent("INCOMING_RESURRECT_CHANGED", frame.unit, displayed);
56 frame:RegisterUnitEvent("PLAYER_FLAGS_CHANGED", frame.unit, displayed);
58 local registerEvents = M.RegisterEvents;
60 local function updateHealth(frame, unit)
61 local current, max = UnitHealth(unit), frame.health.max;
63 -- sanity check, occasionally UnitHealthMax gives zero
65 -- somehow current health has gone over the maximum (missed maxhealth event)
66 frame.health.max = UnitHealthMax(unit);
67 max = frame.health.max;
69 -- error state, still over maximum
70 frame.health:SetWidth(width);
74 frame.health:SetWidth(current/frame.health.max*width);
76 frame.health:SetWidth(width);
80 if UnitIsDeadOrGhost(unit) then
85 local function updateText(frame, unit)
86 local current, max = UnitHealth(unit), frame.health.max;
87 local healthLost = max - current;
88 if UnitIsDeadOrGhost(unit) then
89 frame.text:SetText("Dead");
91 elseif not UnitIsConnected(unit) then
92 frame.text:SetText("DC");
94 elseif UnitIsAFK(unit) then
95 frame.text:SetText("afk");
97 elseif UnitIsDND(unit) and healthLost == 0 then
98 frame.text:SetText("dnd");
100 elseif healthLost > 0 then
101 if healthLost > 1200000000 then -- 1.2B
102 frame.text:SetFormattedText("-%.1fB", healthLost / 1000000000);
103 elseif healthLost > 1200000 then -- 1.2M
104 frame.text:SetFormattedText("-%.1fM", healthLost / 1000000);
105 elseif healthLost > 1000 then -- 1K
106 frame.text:SetFormattedText("-%dK", healthLost / 1000);
108 frame.text:SetFormattedText("-%d", healthLost)
116 local function updateIncomingRes(frame, unit)
117 if UnitHasIncomingResurrection(unit) then
124 local function updateMaxHealth(frame, unit)
125 frame.health.max = UnitHealthMax(unit);
128 local function updatePower(frame, unit)
129 local current, max = UnitPower(unit), frame.mana.max;
130 -- sanity check, occasionally UnitPowerMax gives zero
131 if current > max then
132 frame.mana.max = UnitPowerMax(unit);
133 max = frame.mana.max;
134 if current > max then
136 frame.mana:SetWidth(width);
140 frame.mana:SetWidth(UnitPower(unit)/max*width);
142 frame.mana:SetWidth(width);
146 local function updateMaxPower(frame, unit)
147 frame.mana.max = UnitPowerMax(unit);
150 local function updatePowerColor(frame, unit)
151 frame.mana:SetVertexColor(unpack(powerColors[UnitPowerType(unit)]));
154 local function updateName(frame, unit)
155 local name = UnitName(unit);
156 if not name then return end
157 frame.name:SetText(ssub(name, 1, 6));
159 local _, class = UnitClass(unit);
160 local color = RAID_CLASS_COLORS[class];
161 if color then frame.name:SetVertexColor(color.r, color.g, color.b) end
164 local function updateHealPred(frame, unit)
165 local incoming = UnitGetIncomingHeals(unit) or 0;
167 local max = frame.health.max;
168 local space = width - frame.health:GetWidth() + 1;
169 local pred = (incoming / max) * width;
170 frame.healpred:SetWidth(min(space, pred));
171 frame.healpred:Show();
173 frame.healpred:Hide();
177 local function updateShield(frame, unit)
178 local shield = UnitGetTotalAbsorbs(unit) or 0;
180 local max = frame.health.max;
181 local space = width - frame.health:GetWidth();
182 shield = (shield / max) * width;
183 if space < shield then
184 frame.shield:SetWidth(space);
185 frame.shieldhl:Show();
187 frame.shield:SetWidth(shield);
188 frame.shieldhl:Hide();
193 frame.shieldhl:Hide();
197 local function updateHealAbsorb(frame, unit)
198 local absorb = UnitGetTotalHealAbsorbs(unit) or 0;
200 local max = frame.health.max;
201 local space = frame.health:GetWidth();
202 absorb = (absorb / max) * width;
203 frame.healabsorb:SetWidth(min(space, absorb));
204 frame.healabsorb:Show();
206 frame.healabsorb:Hide();
210 local function updateAuras(frame, unit)
211 checkIndicators(frame, unit);
212 if UnitDebuff(unit, 1, "RAID") ~= nil then
213 -- something dispellable
214 if frame.overlay.color ~= overlayColorDispel then
215 frame.overlay:SetVertexColor(unpack(overlayColorDispel));
216 frame.overlay:Show();
217 frame.overlay.color = overlayColorDispel;
219 -- don't overlay charmed when in vehicle
220 elseif UnitIsCharmed(unit) and unit == frame.unit then
221 if frame.overlay.color ~= overlayColorCharm then
222 frame.overlay:SetVertexColor(unpack(overlayColorCharm));
223 frame.overlay:Show();
224 frame.overlay.color = overlayColorCharm;
227 if frame.overlay.color ~= nil then
228 frame.overlay:Hide();
229 frame.overlay.color = nil;
234 local function updateAggro(frame, unit)
235 local status = UnitThreatSituation(unit);
236 if status and status > 0 then
237 frame.base:SetVertexColor(GetThreatStatusColor(status));
239 frame.base:SetVertexColor(unpack(baseColor));
243 local function updateVehicle(frame)
244 local shouldTargetVehicle = UnitHasVehicleUI(frame.unit) and UnitTargetsVehicleInRaidUI(frame.unit) and UnitExists(frame.vehicle);
245 if shouldTargetVehicle then
246 if not frame.inVehicle then
247 frame.inVehicle = true;
248 frame.displayed = frame.vehicle;
249 registerEvents(frame);
251 elseif frame.inVehicle then
252 frame.inVehicle = false;
253 frame.displayed = frame.unit;
254 registerEvents(frame);
258 local function updateRole(frame, unit)
259 local role = UnitGroupRolesAssigned(unit);
260 if role == "HEALER" then
261 frame.role:SetTexCoord(0.75, 1, 0, 1);
263 elseif role == "TANK" then
264 frame.role:SetTexCoord(0.5, 0.75, 0, 1);
271 local function updateReadyCheck(frame, unit)
272 local status = GetReadyCheckStatus(unit);
273 if status == "ready" then
274 frame.ready:SetTexture(READY_CHECK_READY_TEXTURE);
276 elseif status == "notready" then
277 frame.ready:SetTexture(READY_CHECK_NOT_READY_TEXTURE);
279 elseif status == "waiting" then
280 frame.ready:SetTexture(READY_CHECK_WAITING_TEXTURE);
288 ["UNIT_HEALTH"] = function(frame)
289 updateHealth(frame, frame.displayed);
290 updateText(frame, frame.displayed);
291 updateShield(frame, frame.displayed);
292 updateHealAbsorb(frame, frame.displayed);
293 -- no heal prediction update, that doesn't overflow too much
295 ["UNIT_POWER"] = function(frame)
296 updatePower(frame, frame.displayed);
298 ["UNIT_AURA"] = function(frame)
299 updateAuras(frame, frame.displayed);
301 ["UNIT_HEAL_PREDICTION"] = function(frame)
302 updateHealPred(frame, frame.displayed);
304 ["UNIT_ABSORB_AMOUNT_CHANGED"] = function(frame)
305 updateShield(frame, frame.displayed);
307 ["UNIT_HEAL_ABSORB_AMOUNT_CHANGED"] = function(frame)
308 updateHealAbsorb(frame, frame.displayed);
310 ["UNIT_THREAT_SITUATION_UPDATE"] = function(frame)
311 updateAggro(frame, frame.displayed);
313 ["UNIT_MAXHEALTH"] = function(frame)
314 updateMaxHealth(frame, frame.displayed);
315 updateHealth(frame, frame.displayed);
316 updateText(frame, frame.displayed);
317 updateShield(frame, frame.displayed);
318 updateHealAbsorb(frame, frame.displayed);
320 ["UNIT_MAXPOWER"] = function(frame)
321 updateMaxPower(frame, frame.displayed);
322 updatePower(frame, frame.displayed);
324 ["UNIT_DISPLAYPOWER"] = function(frame)
325 updatePowerColor(frame, frame.displayed);
326 updateMaxPower(frame, frame.displayed);
327 updatePower(frame, frame.displayed);
329 ["UNIT_NAME_UPDATE"] = function(frame)
330 updateName(frame, frame.displayed);
332 ["UNIT_CONNECTION"] = function(frame)
333 updateText(frame, frame.displayed);
335 ["INCOMING_RESURRECT_CHANGED"] = function(frame)
336 updateIncomingRes(frame, frame.unit);
338 ["PARTY_MEMBER_ENABLE"] = function(frame)
339 -- new power info possibly (FrameXML/CompactUnitFrame.lua)
340 updateMaxPower(frame, frame.displayed);
341 updatePowerColor(frame, frame.displayed);
343 ["PLAYER_ROLES_ASSIGNED"] = function(frame)
344 updateRole(frame, frame.unit);
346 ["READY_CHECK"] = function(frame)
347 updateReadyCheck(frame, frame.unit);
349 ["UPDATE_ALL_BARS"] = function(frame)
350 updateVehicle(frame);
351 updateMaxHealth(frame, frame.displayed);
352 updateMaxPower(frame, frame.displayed);
353 updateHealth(frame, frame.displayed);
354 updateText(frame, frame.displayed);
355 updatePower(frame, frame.displayed);
356 updateAuras(frame, frame.displayed);
357 updateShield(frame, frame.displayed);
358 updateHealPred(frame, frame.displayed);
359 updateHealAbsorb(frame, frame.displayed);
360 updatePowerColor(frame, frame.displayed);
361 updateIncomingRes(frame, frame.unit);
362 updateReadyCheck(frame, frame.unit);
363 updateAggro(frame, frame.displayed);
364 updateName(frame, frame.displayed);
365 updateRole(frame, frame.unit);
368 eventFuncs["UNIT_HEALTH_FREQUENT"] = eventFuncs["UNIT_HEALTH"];
369 eventFuncs["PARTY_MEMBER_DISABLE"] = eventFuncs["PARTY_MEMBER_ENABLE"];
370 eventFuncs["PLAYER_FLAGS_CHANGED"] = eventFuncs["UNIT_CONNECTION"];
371 eventFuncs["UNIT_POWER_BAR_SHOW"] = eventFuncs["UNIT_DISPLAYPOWER"];
372 eventFuncs["UNIT_POWER_BAR_HIDE"] = eventFuncs["UNIT_DISPLAYPOWER"];
373 eventFuncs["READY_CHECK_CONFIRM"] = eventFuncs["READY_CHECK"];
374 eventFuncs["READY_CHECK_FINISHED"] = eventFuncs["READY_CHECK"];
375 eventFuncs["UNIT_ENTERED_VEHICLE"] = eventFuncs["UPDATE_ALL_BARS"];
376 eventFuncs["UNIT_EXITED_VEHICLE"] = eventFuncs["UPDATE_ALL_BARS"];
377 eventFuncs["UNIT_PET"] = eventFuncs["UPDATE_ALL_BARS"];
378 eventFuncs["GROUP_ROSTER_UPDATE"] = eventFuncs["UPDATE_ALL_BARS"];
379 eventFuncs["PLAYER_ENTERING_WORLD"] = eventFuncs["UPDATE_ALL_BARS"];
380 eventFuncs["PLAYER_FOCUS_CHANGED"] = eventFuncs["UPDATE_ALL_BARS"];
382 function M.UnitEvent(self, event)
383 eventFuncs[event](self);