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");
83 local function updateMaxHealth(frame, unit)
84 frame.health.max = UnitHealthMax(unit);
87 local function updateHealth(frame, unit)
88 local current, max = UnitHealth(unit), frame.health.max;
89 if current > max or max <= 0 then
90 -- somehow current health has gone over the maximum (missed maxhealth event possibly)
91 -- just put health bar full and update max health for next event
92 frame.health:SetWidth(width);
93 updateMaxHealth(frame, unit);
95 elseif current <= 0 or UnitIsDeadOrGhost(unit) then
98 updateText(frame, unit); -- update death
100 frame.health:SetWidth(current/max*width);
104 if frame.dead and current > 0 then
106 updateText(frame, unit); -- update revive
110 -- TODO maybe add a prefix when in vehicle
111 local function updateName(frame, unit)
112 local name = UnitName(unit);
113 if not name then return end
114 frame.name:SetText(ssub(name, 1, 6));
116 local _, class = UnitClass(unit);
117 local color = RAID_CLASS_COLORS[class];
118 if color then frame.name:SetVertexColor(color.r, color.g, color.b) end
121 local function updateHealPred(frame, unit)
122 local incoming = UnitGetIncomingHeals(unit) or 0;
124 -- always at least 1 pixel space for heal prediction
125 local space = width - frame.health:GetWidth() + 1;
126 incoming = (incoming / frame.health.max) * width;
127 frame.healpred:SetWidth(min(space, incoming));
128 frame.healpred:Show();
130 frame.healpred:Hide();
134 local function updateShield(frame, unit)
135 local shield = UnitGetTotalAbsorbs(unit) or 0;
137 local space = width - frame.health:GetWidth();
138 shield = (shield / frame.health.max) * width;
141 frame.shieldhl:Show();
142 elseif space < shield then
143 frame.shield:SetWidth(space);
145 frame.shieldhl:Show();
147 frame.shield:SetWidth(shield);
149 frame.shieldhl:Hide();
153 frame.shieldhl:Hide();
157 local function updateHealAbsorb(frame, unit)
158 local absorb = UnitGetTotalHealAbsorbs(unit) or 0;
160 local space = frame.health:GetWidth();
161 absorb = (absorb / frame.health.max) * width;
162 frame.healabsorb:SetWidth(min(space, absorb));
163 frame.healabsorb:Show();
165 frame.healabsorb:Hide();
169 local function updateAuras(frame, unit)
170 local alert = checkIndicators(frame, unit);
172 if frame.overlay.color ~= overlayColorAlert then
173 frame.overlay:SetVertexColor(unpack(overlayColorAlert));
174 frame.overlay.color = overlayColorAlert;
175 frame.overlay:Show();
177 elseif UnitDebuff(unit, 1, "RAID") ~= nil then
178 -- something dispellable
179 if frame.overlay.color ~= overlayColorDispel then
180 frame.overlay:SetVertexColor(unpack(overlayColorDispel));
181 frame.overlay.color = overlayColorDispel;
182 frame.overlay:Show();
184 -- don't overlay charmed when in vehicle
185 elseif UnitIsCharmed(unit) and unit == frame.unit then
186 if frame.overlay.color ~= overlayColorCharm then
187 frame.overlay:SetVertexColor(unpack(overlayColorCharm));
188 frame.overlay.color = overlayColorCharm;
189 frame.overlay:Show();
192 if frame.overlay.color ~= nil then
193 frame.overlay.color = nil;
194 frame.overlay:Hide();
199 local function updateAggro(frame, unit)
200 local status = UnitThreatSituation(unit);
201 if status and status > 0 then
202 frame.base:SetVertexColor(GetThreatStatusColor(status));
204 frame.base:SetVertexColor(unpack(baseColor));
208 local function updateVehicle(frame)
209 local shouldTargetVehicle = UnitHasVehicleUI(frame.unit) and
210 UnitTargetsVehicleInRaidUI(frame.unit) and UnitExists(frame.vehicle);
211 if shouldTargetVehicle then
212 if not frame.inVehicle then
213 frame.inVehicle = true;
214 frame.displayed = frame.vehicle;
215 registerUnitEvents(frame);
217 elseif frame.inVehicle then
218 frame.inVehicle = false;
219 frame.displayed = frame.unit;
220 registerUnitEvents(frame);
224 local function updateRole(frame, unit)
225 local role = UnitGroupRolesAssigned(unit);
226 if role == "HEALER" then
227 frame.role:SetTexCoord(0.75, 1, 0, 1);
229 elseif role == "TANK" then
230 frame.role:SetTexCoord(0.5, 0.75, 0, 1);
237 local function updateReadyCheck(frame, unit)
238 local status = GetReadyCheckStatus(unit);
239 if status == "ready" then
240 frame.ready:SetTexture(READY_CHECK_READY_TEXTURE);
242 elseif status == "notready" then
243 frame.ready:SetTexture(READY_CHECK_NOT_READY_TEXTURE);
245 elseif status == "waiting" then
246 frame.ready:SetTexture(READY_CHECK_WAITING_TEXTURE);
253 local function updateRaidMarker(frame, unit)
254 local index = GetRaidTargetIndex(unit);
256 SetRaidTargetIconTexture(frame.targeticon, index);
257 frame.targeticon:Show();
259 frame.targeticon:Hide();
264 ["UNIT_HEALTH"] = function(frame)
265 updateHealth(frame, frame.displayed);
266 updateShield(frame, frame.displayed);
267 updateHealAbsorb(frame, frame.displayed);
268 -- no heal prediction update, that doesn't overflow too much
269 -- raid marker update here, if needed
270 -- because marker is removed when unit dies
271 -- without a RAID_TARGET_UPDATE event
272 --updateRaidMarker(frame, frame.unit);
274 ["UNIT_AURA"] = function(frame)
275 updateAuras(frame, frame.displayed);
277 ["UNIT_HEAL_PREDICTION"] = function(frame)
278 updateHealPred(frame, frame.displayed);
280 ["UNIT_ABSORB_AMOUNT_CHANGED"] = function(frame)
281 updateShield(frame, frame.displayed);
283 ["UNIT_HEAL_ABSORB_AMOUNT_CHANGED"] = function(frame)
284 updateHealAbsorb(frame, frame.displayed);
286 ["UNIT_THREAT_SITUATION_UPDATE"] = function(frame)
287 updateAggro(frame, frame.displayed);
289 ["UNIT_MAXHEALTH"] = function(frame)
290 updateMaxHealth(frame, frame.displayed);
291 updateHealth(frame, frame.displayed);
292 updateShield(frame, frame.displayed);
293 updateHealAbsorb(frame, frame.displayed);
295 ["UNIT_NAME_UPDATE"] = function(frame)
296 updateName(frame, frame.unit);
298 ["UNIT_CONNECTION"] = function(frame)
299 updateText(frame, frame.displayed);
301 ["PLAYER_ROLES_ASSIGNED"] = function(frame)
302 updateRole(frame, frame.unit);
304 ["READY_CHECK"] = function(frame)
305 updateReadyCheck(frame, frame.unit);
307 ["RAID_TARGET_UPDATE"] = function(frame)
308 updateRaidMarker(frame, frame.displayed);
310 ["UPDATE_ALL_BARS"] = function(frame)
311 updateRole(frame, frame.unit);
312 updateVehicle(frame);
313 updateMaxHealth(frame, frame.displayed);
314 updateHealth(frame, frame.displayed);
315 updateText(frame, frame.displayed);
316 updateAuras(frame, frame.displayed);
317 updateShield(frame, frame.displayed);
318 updateHealPred(frame, frame.displayed);
319 updateHealAbsorb(frame, frame.displayed);
320 updateAggro(frame, frame.displayed);
321 updateName(frame, frame.unit);
322 updateReadyCheck(frame, frame.unit);
323 updateRaidMarker(frame, frame.displayed);
326 eventFuncs["UNIT_HEALTH_FREQUENT"] = eventFuncs["UNIT_HEALTH"];
327 eventFuncs["PLAYER_FLAGS_CHANGED"] = eventFuncs["UNIT_CONNECTION"];
328 eventFuncs["READY_CHECK_CONFIRM"] = eventFuncs["READY_CHECK"];
329 eventFuncs["READY_CHECK_FINISHED"] = eventFuncs["READY_CHECK"];
330 eventFuncs["UNIT_ENTERED_VEHICLE"] = eventFuncs["UPDATE_ALL_BARS"];
331 eventFuncs["UNIT_EXITED_VEHICLE"] = eventFuncs["UPDATE_ALL_BARS"];
332 eventFuncs["UNIT_PET"] = eventFuncs["UPDATE_ALL_BARS"];
333 eventFuncs["GROUP_ROSTER_UPDATE"] = eventFuncs["UPDATE_ALL_BARS"];
334 eventFuncs["PLAYER_ENTERING_WORLD"] = eventFuncs["UPDATE_ALL_BARS"];
335 eventFuncs["PLAYER_FOCUS_CHANGED"] = eventFuncs["UPDATE_ALL_BARS"];
337 function M.UnitEvent(self, event)
338 eventFuncs[event](self);