4 local ssub = string.sub;
6 local UnitName, UnitClass, UnitExists = UnitName, UnitClass, UnitExists;
7 local UnitDebuff, UnitIsCharmed = UnitDebuff, UnitIsCharmed;
8 local UnitHealth, UnitHealthMax = UnitHealth, UnitHealthMax;
9 local UnitIsAFK, UnitIsDND = UnitIsAFK, UnitIsDND;
10 local UnitGetIncomingHeals, UnitGetTotalAbsorbs = UnitGetIncomingHeals, UnitGetTotalAbsorbs;
11 local UnitThreatSituation, GetThreatStatusColor = UnitThreatSituation, GetThreatStatusColor;
12 local UnitIsDeadOrGhost, UnitIsConnected = UnitIsDeadOrGhost, UnitIsConnected;
13 local UnitGetTotalHealAbsorbs = UnitGetTotalHealAbsorbs;
14 local UnitHasVehicleUI, UnitTargetsVehicleInRaidUI = UnitHasVehicleUI, UnitTargetsVehicleInRaidUI;
15 local GetReadyCheckTimeLeft, GetReadyCheckStatus = GetReadyCheckTimeLeft, GetReadyCheckStatus;
16 local UnitGroupRolesAssigned = UnitGroupRolesAssigned;
17 local GetRaidTargetIndex, SetRaidTargetIconTexture = GetRaidTargetIndex, SetRaidTargetIconTexture;
18 local RAID_CLASS_COLORS = RAID_CLASS_COLORS;
19 local READY_CHECK_READY_TEXTURE = READY_CHECK_READY_TEXTURE;
20 local READY_CHECK_NOT_READY_TEXTURE = READY_CHECK_NOT_READY_TEXTURE;
21 local READY_CHECK_WAITING_TEXTURE = READY_CHECK_WAITING_TEXTURE;
23 local checkIndicators = OmaRFIndicators.CheckIndicators;
25 local Settings = OmaRFSettings;
26 local baseColor = Settings.BaseColor;
27 local overlayColorDispel = Settings.OverlayColorDispel;
28 local overlayColorCharm = Settings.OverlayColorCharm;
29 local overlayColorAlert = Settings.OverlayColorAlert;
30 local width = Settings.Width;
34 function M.RegisterEvents(frame)
35 frame:RegisterEvent("PLAYER_ENTERING_WORLD");
36 frame:RegisterEvent("PLAYER_ROLES_ASSIGNED");
37 frame:RegisterEvent("READY_CHECK");
38 frame:RegisterEvent("READY_CHECK_FINISHED");
39 frame:RegisterEvent("GROUP_ROSTER_UPDATE");
40 frame:RegisterEvent("RAID_TARGET_UPDATE");
41 if frame.unit == "focus" then frame:RegisterEvent("PLAYER_FOCUS_CHANGED") end
44 function M.RegisterUnitEvents(frame)
45 -- events are taken from FrameXML/CompactUnitFrame.lua
46 local displayed = frame.unit ~= frame.displayed and frame.displayed or nil;
47 frame:RegisterUnitEvent("UNIT_HEALTH", frame.unit, displayed);
48 frame:RegisterUnitEvent("UNIT_HEALTH_FREQUENT", frame.unit, displayed);
49 frame:RegisterUnitEvent("UNIT_MAXHEALTH", frame.unit, displayed);
50 frame:RegisterUnitEvent("UNIT_NAME_UPDATE", frame.unit, displayed);
51 frame:RegisterUnitEvent("UNIT_AURA", frame.unit, displayed);
52 frame:RegisterUnitEvent("UNIT_HEAL_PREDICTION", frame.unit, displayed);
53 frame:RegisterUnitEvent("UNIT_ABSORB_AMOUNT_CHANGED", frame.unit, displayed);
54 frame:RegisterUnitEvent("UNIT_HEAL_ABSORB_AMOUNT_CHANGED", frame.unit, displayed);
55 frame:RegisterUnitEvent("UNIT_THREAT_SITUATION_UPDATE", frame.unit, displayed);
56 frame:RegisterUnitEvent("UNIT_CONNECTION", frame.unit, displayed);
57 frame:RegisterUnitEvent("PLAYER_FLAGS_CHANGED", frame.unit, displayed);
58 frame:RegisterUnitEvent("READY_CHECK_CONFIRM", frame.unit, displayed);
59 frame:RegisterUnitEvent("UNIT_ENTERED_VEHICLE", frame.unit, displayed);
60 frame:RegisterUnitEvent("UNIT_EXITED_VEHICLE", frame.unit, displayed);
61 frame:RegisterUnitEvent("UNIT_PET", frame.unit, displayed);
63 local registerUnitEvents = M.RegisterUnitEvents;
65 local function updateText(frame, unit)
66 if UnitIsDeadOrGhost(unit) then
68 frame.text:SetText("Dead");
70 elseif not UnitIsConnected(unit) then
71 frame.text:SetText("DC");
73 elseif UnitIsAFK(unit) then
74 frame.text:SetText("afk");
76 elseif UnitIsDND(unit) then
77 frame.text:SetText("dnd");
83 M.UpdateText = updateText;
85 local function updateMaxHealth(frame, unit)
86 frame.health.max = UnitHealthMax(unit);
88 M.UpdateMaxHealth = updateMaxHealth;
90 local function updateHealth(frame, unit)
91 local current, max = UnitHealth(unit), frame.health.max;
92 if current > max or max <= 0 then
93 -- somehow current health has gone over the maximum (missed maxhealth event possibly)
94 -- just put health bar full and update max health for next event
95 frame.health:SetWidth(width);
96 frame.health.width = width;
97 updateMaxHealth(frame, unit);
99 elseif current <= 0 or UnitIsDeadOrGhost(unit) then
101 return updateText(frame, unit); -- update death
103 local w = current/max*width;
104 frame.health:SetWidth(w);
105 frame.health.width = w;
109 if frame.dead and current > 0 then
111 updateText(frame, unit); -- update revive
114 M.UpdateHealth = updateHealth;
116 local function updateName(frame, unit)
117 local name = UnitName(unit);
118 if not name then return end
119 name = ssub(name, 1, 6);
120 if frame.unit == unit then
121 frame.name:SetText(name);
123 frame.name:SetFormattedText("-%s", name);
126 local _, class = UnitClass(unit);
127 local color = RAID_CLASS_COLORS[class];
128 if color then frame.name:SetVertexColor(color.r, color.g, color.b) end
130 M.UpdateName = updateName;
132 local function updateHealPred(frame, unit)
133 local incoming = UnitGetIncomingHeals(unit) or 0;
135 incoming = (incoming / frame.health.max) * width;
136 -- always at least 1 pixel space for heal prediction
137 frame.healpred:SetWidth(min(width - frame.health.width + 1, incoming));
138 frame.healpred:Show();
140 frame.healpred:Hide();
143 M.UpdateHealPred = updateHealPred;
145 local function updateShield(frame, unit)
146 local shield = UnitGetTotalAbsorbs(unit) or 0;
148 local space = width - frame.health.width;
149 shield = (shield / frame.health.max) * width;
152 frame.shieldhl:Show();
153 elseif space < shield then
154 frame.shield:SetWidth(space);
156 frame.shieldhl:Show();
158 frame.shield:SetWidth(shield);
160 frame.shieldhl:Hide();
164 frame.shieldhl:Hide();
167 M.UpdateShield = updateShield;
169 local function updateHealAbsorb(frame, unit)
170 local absorb = UnitGetTotalHealAbsorbs(unit) or 0;
172 absorb = (absorb / frame.health.max) * width;
173 frame.healabsorb:SetWidth(min(frame.health.width, absorb));
174 frame.healabsorb:Show();
176 frame.healabsorb:Hide();
179 M.UpdateHealAbsorb = updateHealAbsorb;
181 local function updateAuras(frame, unit)
182 updateAuras(frame, unit); -- this is throttled
183 if updateMajorAuras(frame, unit) then
184 if frame.overlay.color ~= overlayColorAlert then
185 frame.overlay:SetVertexColor(unpack(overlayColorAlert));
186 frame.overlay.color = overlayColorAlert;
187 frame.overlay:Show();
189 elseif UnitDebuff(unit, 1, "RAID") ~= nil then
190 -- something dispellable
191 if frame.overlay.color ~= overlayColorDispel then
192 frame.overlay:SetVertexColor(unpack(overlayColorDispel));
193 frame.overlay.color = overlayColorDispel;
194 frame.overlay:Show();
196 -- don't overlay charmed when in vehicle
197 elseif UnitIsCharmed(unit) and unit == frame.unit then
198 if frame.overlay.color ~= overlayColorCharm then
199 frame.overlay:SetVertexColor(unpack(overlayColorCharm));
200 frame.overlay.color = overlayColorCharm;
201 frame.overlay:Show();
204 if frame.overlay.color ~= nil then
205 frame.overlay.color = nil;
206 frame.overlay:Hide();
210 M.UpdateAuras = updateAuras;
212 local function updateAggro(frame, unit)
213 local status = UnitThreatSituation(unit);
214 if status and status > 0 then
215 frame.base:SetVertexColor(GetThreatStatusColor(status));
217 frame.base:SetVertexColor(unpack(baseColor));
220 M.UpdateAggro = updateAggro;
222 local function updateVehicle(frame)
223 local shouldTargetVehicle = UnitHasVehicleUI(frame.unit) and
224 UnitTargetsVehicleInRaidUI(frame.unit) and UnitExists(frame.vehicle);
225 if shouldTargetVehicle then
226 if not frame.inVehicle then
227 frame.inVehicle = true;
228 frame.displayed = frame.vehicle;
229 registerUnitEvents(frame);
231 elseif frame.inVehicle then
232 frame.inVehicle = false;
233 frame.displayed = frame.unit;
234 registerUnitEvents(frame);
237 M.UpdateVehicle = updateVehicle;
239 local function updateRole(frame, unit)
240 local role = UnitGroupRolesAssigned(unit);
241 if role == "HEALER" then
242 frame.role:SetTexCoord(0.75, 1, 0, 1);
244 elseif role == "TANK" then
245 frame.role:SetTexCoord(0.5, 0.75, 0, 1);
251 M.UpdateRole = updateRole;
253 local function updateReadyCheck(frame, unit)
254 local status = GetReadyCheckStatus(unit);
255 if status == "ready" then
256 frame.ready:SetTexture(READY_CHECK_READY_TEXTURE);
258 elseif status == "notready" then
259 frame.ready:SetTexture(READY_CHECK_NOT_READY_TEXTURE);
261 elseif status == "waiting" then
262 frame.ready:SetTexture(READY_CHECK_WAITING_TEXTURE);
268 M.UpdateReadyCheck = updateReadyCheck;
270 local function updateRaidMarker(frame, unit)
271 local index = GetRaidTargetIndex(unit);
273 SetRaidTargetIconTexture(frame.targeticon, index);
274 frame.targeticon:Show();
276 frame.targeticon:Hide();
279 M.UpdateRaidMarker = updateRaidMarker;
282 ["UNIT_HEALTH"] = function(frame)
283 updateHealth(frame, frame.displayed);
284 updateShield(frame, frame.displayed);
285 updateHealAbsorb(frame, frame.displayed);
286 -- no heal prediction update, that doesn't overflow too much
288 ["UNIT_AURA"] = function(frame)
289 updateAuras(frame, frame.displayed);
291 ["UNIT_HEAL_PREDICTION"] = function(frame)
292 updateHealPred(frame, frame.displayed);
294 ["UNIT_ABSORB_AMOUNT_CHANGED"] = function(frame)
295 updateShield(frame, frame.displayed);
297 ["UNIT_HEAL_ABSORB_AMOUNT_CHANGED"] = function(frame)
298 updateHealAbsorb(frame, frame.displayed);
300 ["UNIT_THREAT_SITUATION_UPDATE"] = function(frame)
301 updateAggro(frame, frame.displayed);
303 ["UNIT_MAXHEALTH"] = function(frame)
304 updateMaxHealth(frame, frame.displayed);
305 updateHealth(frame, frame.displayed);
306 updateShield(frame, frame.displayed);
307 updateHealAbsorb(frame, frame.displayed);
309 ["UNIT_NAME_UPDATE"] = function(frame)
310 updateName(frame, frame.unit);
312 ["UNIT_CONNECTION"] = function(frame)
313 updateText(frame, frame.displayed);
315 ["PLAYER_ROLES_ASSIGNED"] = function(frame)
316 updateRole(frame, frame.unit);
318 ["READY_CHECK"] = function(frame)
319 updateReadyCheck(frame, frame.unit);
321 ["RAID_TARGET_UPDATE"] = function(frame)
322 updateRaidMarker(frame, frame.displayed);
324 ["UPDATE_ALL_BARS"] = function(frame)
325 updateRole(frame, frame.unit);
326 updateVehicle(frame);
327 updateMaxHealth(frame, frame.displayed);
328 updateHealth(frame, frame.displayed);
329 updateText(frame, frame.displayed);
330 updateAuras(frame, frame.displayed);
331 updateShield(frame, frame.displayed);
332 updateHealPred(frame, frame.displayed);
333 updateHealAbsorb(frame, frame.displayed);
334 updateAggro(frame, frame.displayed);
335 updateName(frame, frame.unit);
336 updateReadyCheck(frame, frame.unit);
337 updateRaidMarker(frame, frame.displayed);
340 eventFuncs["UNIT_HEALTH_FREQUENT"] = eventFuncs["UNIT_HEALTH"];
341 eventFuncs["PLAYER_FLAGS_CHANGED"] = eventFuncs["UNIT_CONNECTION"];
342 eventFuncs["READY_CHECK_CONFIRM"] = eventFuncs["READY_CHECK"];
343 eventFuncs["READY_CHECK_FINISHED"] = eventFuncs["READY_CHECK"];
344 eventFuncs["UNIT_ENTERED_VEHICLE"] = eventFuncs["UPDATE_ALL_BARS"];
345 eventFuncs["UNIT_EXITED_VEHICLE"] = eventFuncs["UPDATE_ALL_BARS"];
346 eventFuncs["UNIT_PET"] = eventFuncs["UPDATE_ALL_BARS"];
347 eventFuncs["GROUP_ROSTER_UPDATE"] = eventFuncs["UPDATE_ALL_BARS"];
348 eventFuncs["PLAYER_ENTERING_WORLD"] = eventFuncs["UPDATE_ALL_BARS"];
349 eventFuncs["PLAYER_FOCUS_CHANGED"] = eventFuncs["UPDATE_ALL_BARS"];
351 function M.UnitEvent(self, event)
352 return eventFuncs[event](self);