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
67 frame.text:SetText("Dead");
69 elseif not UnitIsConnected(unit) then
70 frame.text:SetText("DC");
72 elseif UnitIsAFK(unit) then
73 frame.text:SetText("afk");
75 elseif UnitIsDND(unit) then
76 frame.text:SetText("dnd");
82 M.UpdateText = updateText;
84 local function updateMaxHealth(frame, unit)
85 frame.health.max = UnitHealthMax(unit);
87 M.UpdateMaxHealth = updateMaxHealth;
89 local function updateHealth(frame, unit)
90 local current, max = UnitHealth(unit), frame.health.max;
91 if current > max or max <= 0 then
92 -- somehow current health has gone over the maximum (missed maxhealth event possibly)
93 -- just put health bar full and update max health for next event
94 frame.health:SetWidth(width);
95 updateMaxHealth(frame, unit);
97 elseif current <= 0 or UnitIsDeadOrGhost(unit) then
100 updateText(frame, unit); -- update death
102 frame.health:SetWidth(current/max*width);
106 if frame.dead and current > 0 then
108 updateText(frame, unit); -- update revive
111 M.UpdateHealth = updateHealth;
113 local function updateName(frame, unit)
114 local name = UnitName(unit);
115 if not name then return end
116 name = ssub(name, 1, 6);
117 if frame.unit == unit then
118 frame.name:SetText(name);
120 frame.name:SetFormattedText("-%s", name);
123 local _, class = UnitClass(unit);
124 local color = RAID_CLASS_COLORS[class];
125 if color then frame.name:SetVertexColor(color.r, color.g, color.b) end
127 M.UpdateName = updateName;
129 local function updateHealPred(frame, unit)
130 local incoming = UnitGetIncomingHeals(unit) or 0;
132 -- always at least 1 pixel space for heal prediction
133 local space = width - frame.health:GetWidth() + 1;
134 incoming = (incoming / frame.health.max) * width;
135 frame.healpred:SetWidth(min(space, incoming));
136 frame.healpred:Show();
138 frame.healpred:Hide();
141 M.UpdateHealPred = updateHealPred;
143 local function updateShield(frame, unit)
144 local shield = UnitGetTotalAbsorbs(unit) or 0;
146 local space = width - frame.health:GetWidth();
147 shield = (shield / frame.health.max) * width;
150 frame.shieldhl:Show();
151 elseif space < shield then
152 frame.shield:SetWidth(space);
154 frame.shieldhl:Show();
156 frame.shield:SetWidth(shield);
158 frame.shieldhl:Hide();
162 frame.shieldhl:Hide();
165 M.UpdateShield = updateShield;
167 local function updateHealAbsorb(frame, unit)
168 local absorb = UnitGetTotalHealAbsorbs(unit) or 0;
170 local space = frame.health:GetWidth();
171 absorb = (absorb / frame.health.max) * width;
172 frame.healabsorb:SetWidth(min(space, absorb));
173 frame.healabsorb:Show();
175 frame.healabsorb:Hide();
178 M.UpdateHealAbsorb = updateHealAbsorb;
180 local function updateAuras(frame, unit)
181 local alert = checkIndicators(frame, unit);
183 if frame.overlay.color ~= overlayColorAlert then
184 frame.overlay:SetVertexColor(unpack(overlayColorAlert));
185 frame.overlay.color = overlayColorAlert;
186 frame.overlay:Show();
188 elseif UnitDebuff(unit, 1, "RAID") ~= nil then
189 -- something dispellable
190 if frame.overlay.color ~= overlayColorDispel then
191 frame.overlay:SetVertexColor(unpack(overlayColorDispel));
192 frame.overlay.color = overlayColorDispel;
193 frame.overlay:Show();
195 -- don't overlay charmed when in vehicle
196 elseif UnitIsCharmed(unit) and unit == frame.unit then
197 if frame.overlay.color ~= overlayColorCharm then
198 frame.overlay:SetVertexColor(unpack(overlayColorCharm));
199 frame.overlay.color = overlayColorCharm;
200 frame.overlay:Show();
203 if frame.overlay.color ~= nil then
204 frame.overlay.color = nil;
205 frame.overlay:Hide();
209 M.UpdateAuras = updateAuras;
211 local function updateAggro(frame, unit)
212 local status = UnitThreatSituation(unit);
213 if status and status > 0 then
214 frame.base:SetVertexColor(GetThreatStatusColor(status));
216 frame.base:SetVertexColor(unpack(baseColor));
219 M.UpdateAggro = updateAggro;
221 local function updateVehicle(frame)
222 local shouldTargetVehicle = UnitHasVehicleUI(frame.unit) and
223 UnitTargetsVehicleInRaidUI(frame.unit) and UnitExists(frame.vehicle);
224 if shouldTargetVehicle then
225 if not frame.inVehicle then
226 frame.inVehicle = true;
227 frame.displayed = frame.vehicle;
228 registerUnitEvents(frame);
230 elseif frame.inVehicle then
231 frame.inVehicle = false;
232 frame.displayed = frame.unit;
233 registerUnitEvents(frame);
236 M.UpdateVehicle = updateVehicle;
238 local function updateRole(frame, unit)
239 local role = UnitGroupRolesAssigned(unit);
240 if role == "HEALER" then
241 frame.role:SetTexCoord(0.75, 1, 0, 1);
243 elseif role == "TANK" then
244 frame.role:SetTexCoord(0.5, 0.75, 0, 1);
250 M.UpdateRole = updateRole;
252 local function updateReadyCheck(frame, unit)
253 local status = GetReadyCheckStatus(unit);
254 if status == "ready" then
255 frame.ready:SetTexture(READY_CHECK_READY_TEXTURE);
257 elseif status == "notready" then
258 frame.ready:SetTexture(READY_CHECK_NOT_READY_TEXTURE);
260 elseif status == "waiting" then
261 frame.ready:SetTexture(READY_CHECK_WAITING_TEXTURE);
267 M.UpdateReadyCheck = updateReadyCheck;
269 local function updateRaidMarker(frame, unit)
270 local index = GetRaidTargetIndex(unit);
272 SetRaidTargetIconTexture(frame.targeticon, index);
273 frame.targeticon:Show();
275 frame.targeticon:Hide();
278 M.UpdateRaidMarker = updateRaidMarker;
281 ["UNIT_HEALTH"] = function(frame)
282 updateHealth(frame, frame.displayed);
283 updateShield(frame, frame.displayed);
284 updateHealAbsorb(frame, frame.displayed);
285 -- no heal prediction update, that doesn't overflow too much
286 -- raid marker update here, if needed
287 -- because marker is removed when unit dies
288 -- without a RAID_TARGET_UPDATE event
289 --updateRaidMarker(frame, frame.unit);
291 ["UNIT_AURA"] = function(frame)
292 updateAuras(frame, frame.displayed);
294 ["UNIT_HEAL_PREDICTION"] = function(frame)
295 updateHealPred(frame, frame.displayed);
297 ["UNIT_ABSORB_AMOUNT_CHANGED"] = function(frame)
298 updateShield(frame, frame.displayed);
300 ["UNIT_HEAL_ABSORB_AMOUNT_CHANGED"] = function(frame)
301 updateHealAbsorb(frame, frame.displayed);
303 ["UNIT_THREAT_SITUATION_UPDATE"] = function(frame)
304 updateAggro(frame, frame.displayed);
306 ["UNIT_MAXHEALTH"] = function(frame)
307 updateMaxHealth(frame, frame.displayed);
308 updateHealth(frame, frame.displayed);
309 updateShield(frame, frame.displayed);
310 updateHealAbsorb(frame, frame.displayed);
312 ["UNIT_NAME_UPDATE"] = function(frame)
313 updateName(frame, frame.unit);
315 ["UNIT_CONNECTION"] = function(frame)
316 updateText(frame, frame.displayed);
318 ["PLAYER_ROLES_ASSIGNED"] = function(frame)
319 updateRole(frame, frame.unit);
321 ["READY_CHECK"] = function(frame)
322 updateReadyCheck(frame, frame.unit);
324 ["RAID_TARGET_UPDATE"] = function(frame)
325 updateRaidMarker(frame, frame.displayed);
327 ["UPDATE_ALL_BARS"] = function(frame)
328 updateRole(frame, frame.unit);
329 updateVehicle(frame);
330 updateMaxHealth(frame, frame.displayed);
331 updateHealth(frame, frame.displayed);
332 updateText(frame, frame.displayed);
333 updateAuras(frame, frame.displayed);
334 updateShield(frame, frame.displayed);
335 updateHealPred(frame, frame.displayed);
336 updateHealAbsorb(frame, frame.displayed);
337 updateAggro(frame, frame.displayed);
338 updateName(frame, frame.unit);
339 updateReadyCheck(frame, frame.unit);
340 updateRaidMarker(frame, frame.displayed);
343 eventFuncs["UNIT_HEALTH_FREQUENT"] = eventFuncs["UNIT_HEALTH"];
344 eventFuncs["PLAYER_FLAGS_CHANGED"] = eventFuncs["UNIT_CONNECTION"];
345 eventFuncs["READY_CHECK_CONFIRM"] = eventFuncs["READY_CHECK"];
346 eventFuncs["READY_CHECK_FINISHED"] = eventFuncs["READY_CHECK"];
347 eventFuncs["UNIT_ENTERED_VEHICLE"] = eventFuncs["UPDATE_ALL_BARS"];
348 eventFuncs["UNIT_EXITED_VEHICLE"] = eventFuncs["UPDATE_ALL_BARS"];
349 eventFuncs["UNIT_PET"] = eventFuncs["UPDATE_ALL_BARS"];
350 eventFuncs["GROUP_ROSTER_UPDATE"] = eventFuncs["UPDATE_ALL_BARS"];
351 eventFuncs["PLAYER_ENTERING_WORLD"] = eventFuncs["UPDATE_ALL_BARS"];
352 eventFuncs["PLAYER_FOCUS_CHANGED"] = eventFuncs["UPDATE_ALL_BARS"];
354 function M.UnitEvent(self, event)
355 eventFuncs[event](self);