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 updateIndicatorAuras = OmaRFIndicators.UpdateAuras;
24 local updateMajorAuras = OmaRFIndicators.UpdateMajorAuras;
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 width = Settings.Width;
35 function M.RegisterEvents(frame)
36 frame:RegisterEvent("PLAYER_ENTERING_WORLD");
37 frame:RegisterEvent("PLAYER_ROLES_ASSIGNED");
38 frame:RegisterEvent("READY_CHECK");
39 frame:RegisterEvent("READY_CHECK_FINISHED");
40 frame:RegisterEvent("GROUP_ROSTER_UPDATE");
41 frame:RegisterEvent("RAID_TARGET_UPDATE");
42 if frame.unit == "focus" then frame:RegisterEvent("PLAYER_FOCUS_CHANGED") end
45 function M.RegisterUnitEvents(frame)
46 -- events are taken from FrameXML/CompactUnitFrame.lua
47 local displayed = frame.unit ~= frame.displayed and frame.displayed or nil;
48 frame:RegisterUnitEvent("UNIT_HEALTH", frame.unit, displayed);
49 frame:RegisterUnitEvent("UNIT_HEALTH_FREQUENT", frame.unit, displayed);
50 frame:RegisterUnitEvent("UNIT_MAXHEALTH", frame.unit, displayed);
51 frame:RegisterUnitEvent("UNIT_NAME_UPDATE", frame.unit, displayed);
52 frame:RegisterUnitEvent("UNIT_AURA", frame.unit, displayed);
53 frame:RegisterUnitEvent("UNIT_HEAL_PREDICTION", frame.unit, displayed);
54 frame:RegisterUnitEvent("UNIT_ABSORB_AMOUNT_CHANGED", frame.unit, displayed);
55 frame:RegisterUnitEvent("UNIT_HEAL_ABSORB_AMOUNT_CHANGED", frame.unit, displayed);
56 frame:RegisterUnitEvent("UNIT_THREAT_SITUATION_UPDATE", frame.unit, displayed);
57 frame:RegisterUnitEvent("UNIT_CONNECTION", frame.unit, displayed);
58 frame:RegisterUnitEvent("PLAYER_FLAGS_CHANGED", frame.unit, displayed);
59 frame:RegisterUnitEvent("READY_CHECK_CONFIRM", frame.unit, displayed);
60 frame:RegisterUnitEvent("UNIT_ENTERED_VEHICLE", frame.unit, displayed);
61 frame:RegisterUnitEvent("UNIT_EXITED_VEHICLE", frame.unit, displayed);
62 frame:RegisterUnitEvent("UNIT_PET", frame.unit, displayed);
64 local registerUnitEvents = M.RegisterUnitEvents;
66 local function updateText(frame, unit)
67 if UnitIsDeadOrGhost(unit) then
69 frame.text:SetText("Dead");
71 elseif not UnitIsConnected(unit) then
72 frame.text:SetText("DC");
74 elseif UnitIsAFK(unit) then
75 frame.text:SetText("afk");
77 elseif UnitIsDND(unit) then
78 frame.text:SetText("dnd");
84 M.UpdateText = updateText;
86 local function updateMaxHealth(frame, unit)
87 frame.health.max = UnitHealthMax(unit);
89 M.UpdateMaxHealth = updateMaxHealth;
91 local function updateHealth(frame, unit)
92 local current, max = UnitHealth(unit), frame.health.max;
93 if current > max or max <= 0 then
94 -- somehow current health has gone over the maximum (missed maxhealth event possibly)
95 -- just put health bar full and update max health for next event
96 frame.health:SetWidth(width);
97 frame.health.width = width;
98 updateMaxHealth(frame, unit);
100 elseif current <= 0 or UnitIsDeadOrGhost(unit) then
102 return updateText(frame, unit); -- update death
104 local w = current/max*width;
105 frame.health:SetWidth(w);
106 frame.health.width = w;
110 if frame.dead and current > 0 then
112 updateText(frame, unit); -- update revive
115 M.UpdateHealth = updateHealth;
117 local function updateName(frame, unit)
118 local name = UnitName(unit);
119 if not name then return end
120 name = ssub(name, 1, 6);
121 if frame.unit == unit then
122 frame.name:SetText(name);
124 frame.name:SetFormattedText("-%s", name);
127 local _, class = UnitClass(unit);
128 local color = RAID_CLASS_COLORS[class];
129 if color then frame.name:SetVertexColor(color.r, color.g, color.b) end
131 M.UpdateName = updateName;
133 local function updateHealPred(frame, unit)
134 local incoming = UnitGetIncomingHeals(unit) or 0;
136 incoming = (incoming / frame.health.max) * width;
137 -- always at least 1 pixel space for heal prediction
138 frame.healpred:SetWidth(min(width - frame.health.width + 1, incoming));
139 frame.healpred:Show();
141 frame.healpred:Hide();
144 M.UpdateHealPred = updateHealPred;
146 local function updateShield(frame, unit)
147 local shield = UnitGetTotalAbsorbs(unit) or 0;
149 local space = width - frame.health.width;
150 shield = (shield / frame.health.max) * width;
153 frame.shieldhl:Show();
154 elseif space < shield then
155 frame.shield:SetWidth(space);
157 frame.shieldhl:Show();
159 frame.shield:SetWidth(shield);
161 frame.shieldhl:Hide();
165 frame.shieldhl:Hide();
168 M.UpdateShield = updateShield;
170 local function updateHealAbsorb(frame, unit)
171 local absorb = UnitGetTotalHealAbsorbs(unit) or 0;
173 absorb = (absorb / frame.health.max) * width;
174 frame.healabsorb:SetWidth(min(frame.health.width, absorb));
175 frame.healabsorb:Show();
177 frame.healabsorb:Hide();
180 M.UpdateHealAbsorb = updateHealAbsorb;
182 local function updateAuras(frame, unit)
183 updateIndicatorAuras(frame, unit); -- this is throttled
184 if updateMajorAuras(frame, unit) then
185 if frame.overlay.color ~= overlayColorAlert then
186 frame.overlay:SetVertexColor(unpack(overlayColorAlert));
187 frame.overlay.color = overlayColorAlert;
188 frame.overlay:Show();
190 elseif UnitDebuff(unit, 1, "RAID") ~= nil then
191 -- something dispellable
192 if frame.overlay.color ~= overlayColorDispel then
193 frame.overlay:SetVertexColor(unpack(overlayColorDispel));
194 frame.overlay.color = overlayColorDispel;
195 frame.overlay:Show();
197 -- don't overlay charmed when in vehicle
198 elseif UnitIsCharmed(unit) and unit == frame.unit then
199 if frame.overlay.color ~= overlayColorCharm then
200 frame.overlay:SetVertexColor(unpack(overlayColorCharm));
201 frame.overlay.color = overlayColorCharm;
202 frame.overlay:Show();
205 if frame.overlay.color ~= nil then
206 frame.overlay.color = nil;
207 frame.overlay:Hide();
211 M.UpdateAuras = updateAuras;
213 local function updateAggro(frame, unit)
214 local status = UnitThreatSituation(unit);
215 if status and status > 0 then
216 frame.base:SetVertexColor(GetThreatStatusColor(status));
218 frame.base:SetVertexColor(unpack(baseColor));
221 M.UpdateAggro = updateAggro;
223 local function updateVehicle(frame)
224 local shouldTargetVehicle = UnitHasVehicleUI(frame.unit) and
225 UnitTargetsVehicleInRaidUI(frame.unit) and UnitExists(frame.vehicle);
226 if shouldTargetVehicle then
227 if not frame.inVehicle then
228 frame.inVehicle = true;
229 frame.displayed = frame.vehicle;
230 registerUnitEvents(frame);
232 elseif frame.inVehicle then
233 frame.inVehicle = false;
234 frame.displayed = frame.unit;
235 registerUnitEvents(frame);
238 M.UpdateVehicle = updateVehicle;
240 local function updateRole(frame, unit)
241 local role = UnitGroupRolesAssigned(unit);
242 if role == "HEALER" then
243 frame.role:SetTexCoord(0.75, 1, 0, 1);
245 elseif role == "TANK" then
246 frame.role:SetTexCoord(0.5, 0.75, 0, 1);
252 M.UpdateRole = updateRole;
254 local function updateReadyCheck(frame, unit)
255 local status = GetReadyCheckStatus(unit);
256 if status == "ready" then
257 frame.ready:SetTexture(READY_CHECK_READY_TEXTURE);
259 elseif status == "notready" then
260 frame.ready:SetTexture(READY_CHECK_NOT_READY_TEXTURE);
262 elseif status == "waiting" then
263 frame.ready:SetTexture(READY_CHECK_WAITING_TEXTURE);
269 M.UpdateReadyCheck = updateReadyCheck;
271 local function updateRaidMarker(frame, unit)
272 local index = GetRaidTargetIndex(unit);
274 SetRaidTargetIconTexture(frame.targeticon, index);
275 frame.targeticon:Show();
277 frame.targeticon:Hide();
280 M.UpdateRaidMarker = updateRaidMarker;
283 ["UNIT_HEALTH"] = function(frame)
284 updateHealth(frame, frame.displayed);
285 updateShield(frame, frame.displayed);
286 updateHealAbsorb(frame, frame.displayed);
287 -- no heal prediction update, that doesn't overflow too much
289 ["UNIT_AURA"] = function(frame)
290 updateAuras(frame, frame.displayed);
292 ["UNIT_HEAL_PREDICTION"] = function(frame)
293 updateHealPred(frame, frame.displayed);
295 ["UNIT_ABSORB_AMOUNT_CHANGED"] = function(frame)
296 updateShield(frame, frame.displayed);
298 ["UNIT_HEAL_ABSORB_AMOUNT_CHANGED"] = function(frame)
299 updateHealAbsorb(frame, frame.displayed);
301 ["UNIT_THREAT_SITUATION_UPDATE"] = function(frame)
302 updateAggro(frame, frame.displayed);
304 ["UNIT_MAXHEALTH"] = function(frame)
305 updateMaxHealth(frame, frame.displayed);
306 updateHealth(frame, frame.displayed);
307 updateShield(frame, frame.displayed);
308 updateHealAbsorb(frame, frame.displayed);
310 ["UNIT_NAME_UPDATE"] = function(frame)
311 updateName(frame, frame.unit);
313 ["UNIT_CONNECTION"] = function(frame)
314 updateText(frame, frame.displayed);
316 ["PLAYER_ROLES_ASSIGNED"] = function(frame)
317 updateRole(frame, frame.unit);
319 ["READY_CHECK"] = function(frame)
320 updateReadyCheck(frame, frame.unit);
322 ["RAID_TARGET_UPDATE"] = function(frame)
323 updateRaidMarker(frame, frame.displayed);
325 ["UPDATE_ALL_BARS"] = function(frame)
326 updateRole(frame, frame.unit);
327 updateVehicle(frame);
328 updateMaxHealth(frame, frame.displayed);
329 updateHealth(frame, frame.displayed);
330 updateText(frame, frame.displayed);
331 updateAuras(frame, frame.displayed);
332 updateShield(frame, frame.displayed);
333 updateHealPred(frame, frame.displayed);
334 updateHealAbsorb(frame, frame.displayed);
335 updateAggro(frame, frame.displayed);
336 updateName(frame, frame.unit);
337 updateReadyCheck(frame, frame.unit);
338 updateRaidMarker(frame, frame.displayed);
341 eventFuncs["UNIT_HEALTH_FREQUENT"] = eventFuncs["UNIT_HEALTH"];
342 eventFuncs["PLAYER_FLAGS_CHANGED"] = eventFuncs["UNIT_CONNECTION"];
343 eventFuncs["READY_CHECK_CONFIRM"] = eventFuncs["READY_CHECK"];
344 eventFuncs["READY_CHECK_FINISHED"] = eventFuncs["READY_CHECK"];
345 eventFuncs["UNIT_ENTERED_VEHICLE"] = eventFuncs["UPDATE_ALL_BARS"];
346 eventFuncs["UNIT_EXITED_VEHICLE"] = eventFuncs["UPDATE_ALL_BARS"];
347 eventFuncs["UNIT_PET"] = eventFuncs["UPDATE_ALL_BARS"];
348 eventFuncs["GROUP_ROSTER_UPDATE"] = eventFuncs["UPDATE_ALL_BARS"];
349 eventFuncs["PLAYER_ENTERING_WORLD"] = eventFuncs["UPDATE_ALL_BARS"];
350 eventFuncs["PLAYER_FOCUS_CHANGED"] = eventFuncs["UPDATE_ALL_BARS"];
352 function M.UnitEvent(self, event)
353 return eventFuncs[event](self);