3 local unpack, pairs, rawget = unpack, pairs, rawget;
4 local format = string.format;
5 local UnitHealthMax, UnitPowerMax = UnitHealthMax, UnitPowerMax;
6 local UnitInRange = UnitInRange;
7 local CreateFrame, RegisterStateDriver, RegisterUnitWatch = CreateFrame, RegisterStateDriver, RegisterUnitWatch;
8 local PowerTypeMana = Enum.PowerType.Mana;
9 local PowerTypeRage = Enum.PowerType.Rage;
10 local PowerTypeFocus = Enum.PowerType.Focus;
11 local PowerTypeEnergy = Enum.PowerType.Energy;
12 local PowerTypeRunic = Enum.PowerType.RunicPower;
14 local unitEvent = nil;
19 -- configurable settings
20 M.Positions = {"TOPRIGHT", "BOTTOMLEFT"};
21 M.Width, M.Height = 80, 40;
22 M.AnchorX, M.AnchorY = 0, -330;
23 M.IndSize = 14; M.BaseColor = {0, 0, 0};
24 M.BgColor = {0.7, 0.7, 0.7};
25 M.HealthColor = {0.3, 0.3, 0.3};
26 M.ShieldColor = {0, 0.7, 1};
27 M.ShieldhlColor = {0.5, 0.8, 1};
28 M.HealpredColor = {0.5, 0.6, 0.5};
29 M.HealabsorbColor = {0.1, 0.1, 0.1};
30 M.OverlayColorDispel = {1, 0.5, 0, 0.5};
31 M.OverlayColorCharm = {0.8, 0, 1, 0.5};
32 M.OverlayColorAlert = {1, 0, 0, 0.5};
34 [PowerTypeMana] = {0, 0.5, 1},
35 [PowerTypeRage] = {1, 0, 0},
36 [PowerTypeFocus] = {1, 0.5, 0},
37 [PowerTypeEnergy] = {1, 0.8, 0},
38 [PowerTypeRunic] = {0.9, 0, 0.1},
40 -- watch to not remove mana entry
41 setmetatable(M.PowerColors, {__index = function(t) return rawget(t, PowerTypeMana) end});
43 local positions = M.Positions;
44 local width, height = M.Width, M.Height;
45 local indSize = M.IndSize;
46 local baseColor = M.BaseColor;
47 local bgColor = M.BgColor;
48 local healthColor = M.HealthColor;
49 local shieldColor = M.ShieldColor;
50 local shieldhlColor = M.ShieldhlColor;
51 local healpredColor = M.HealpredColor;
52 local healabsorbColor = M.HealabsorbColor;
54 local function setupIndicators(frame)
55 frame.inds = CreateFrame("Frame", nil, frame);
56 frame.inds:SetAllPoints();
58 for _, pos in pairs(positions) do
59 frame.inds[pos] = frame.inds:CreateTexture(nil, "OVERLAY");
60 frame.inds[pos]:SetPoint(pos, frame.inds, pos);
61 frame.inds[pos]:SetWidth(indSize);
62 frame.inds[pos]:SetHeight(indSize);
63 frame.inds[pos]:SetTexture("Interface\\AddOns\\OmaRF\\images\\rhomb");
64 frame.inds[pos]:SetVertexColor(1, 0, 0);
65 frame.inds[pos]:Hide();
66 frame.inds[pos].text = frame.inds:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
67 frame.inds[pos].text:SetPoint("BOTTOMRIGHT", frame.inds[pos], "BOTTOMRIGHT");
68 frame.inds[pos].text:Hide();
70 frame.major = CreateFrame("Frame", nil, frame);
71 frame.major:SetPoint("TOPLEFT", frame, "TOPLEFT", 4, -indSize + 4);
72 frame.major:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT");
74 frame.major[i] = frame.major:CreateTexture(nil, "OVERLAY");
76 frame.major[i]:SetPoint("TOPLEFT", frame.major, "TOPLEFT");
78 frame.major[i]:SetPoint("TOPLEFT", frame.major[i-1], "TOPLEFT");
80 frame.major[i]:SetWidth(indSize*2);
81 frame.major[i]:SetHeight(indSize*2);
82 frame.major[i]:Hide();
83 frame.major[i].text = frame.major:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
84 frame.major[i].text:SetPoint("BOTTOMRIGHT", frame.major[i], "BOTTOMRIGHT");
85 frame.major[i].text:Hide();
86 frame.major[i].stack = frame.major:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
87 frame.major[i].stack:SetPoint("TOPLEFT", frame.major[i], "TOPLEFT");
88 frame.major[i].stack:Hide();
92 local function unitUpdate(self, elapsed)
93 -- there's no in/out of range event, have to check each frame
94 -- from FrameXML/CompactUnitFrame.lua
95 local inRange, checked = UnitInRange(self.displayed);
96 if checked and not inRange then
103 function M.RegisterEvents(frame)
104 -- events are taken from FrameXML/CompactUnitFrame.lua
105 -- TODO ready check support, raid marker support,
106 -- player flags support (/afk, /dnd)
107 local displayed = frame.unit ~= frame.displayed and frame.displayed or nil;
108 frame:RegisterUnitEvent("UNIT_HEALTH", frame.unit, displayed);
109 frame:RegisterUnitEvent("UNIT_HEALTH_FREQUENT", frame.unit, displayed);
110 frame:RegisterUnitEvent("UNIT_MAXHEALTH", frame.unit, displayed);
111 frame:RegisterUnitEvent("UNIT_POWER", frame.unit, displayed);
112 frame:RegisterUnitEvent("UNIT_MAXPOWER", frame.unit, displayed);
113 frame:RegisterUnitEvent("UNIT_DISPLAYPOWER", frame.unit, displayed);
114 frame:RegisterUnitEvent("UNIT_NAME_UPDATE", frame.unit, displayed);
115 frame:RegisterUnitEvent("UNIT_AURA", frame.unit, displayed);
116 frame:RegisterUnitEvent("UNIT_HEAL_PREDICTION", frame.unit, displayed);
117 frame:RegisterUnitEvent("UNIT_ABSORB_AMOUNT_CHANGED", frame.unit, displayed);
118 frame:RegisterUnitEvent("UNIT_HEAL_ABSORB_AMOUNT_CHANGED", frame.unit, displayed);
119 frame:RegisterUnitEvent("UNIT_THREAT_SITUATION_UPDATE", frame.unit, displayed);
120 frame:RegisterUnitEvent("UNIT_CONNECTION", frame.unit, displayed);
121 frame:RegisterUnitEvent("INCOMING_RESURRECT_CHANGED", frame.unit, displayed);
123 local registerEvents = M.RegisterEvents;
125 local function frameShow(frame)
126 frame:RegisterEvent("PARTY_MEMBER_ENABLE");
127 frame:RegisterEvent("PARTY_MEMBER_DISABLE");
128 frame:RegisterEvent("UNIT_ENTERED_VEHICLE");
129 frame:RegisterEvent("UNIT_EXITED_VEHICLE");
130 frame:RegisterEvent("UNIT_PET");
131 frame:RegisterEvent("PLAYER_ROLES_ASSIGNED");
132 frame:RegisterEvent("GROUP_ROSTER_UPDATE");
133 registerEvents(frame);
134 frame:SetScript("OnUpdate", unitUpdate);
135 unitEvent(frame, "UPDATE_ALL_BARS", frame.displayed);
138 local function frameHide(frame)
139 frame:UnregisterAllEvents();
140 frame:SetScript("OnUpdate", nil);
143 local function setupFrame(frame, secure, unit)
145 secure:SetWidth(width+2);
146 frame:SetWidth(width+2);
147 frame.base = frame:CreateTexture(nil, "BACKGROUND");
148 frame.base:SetAllPoints();
149 frame.base:SetColorTexture(1, 1, 1);
150 frame.base:SetVertexColor(unpack(baseColor));
151 frame.background = frame:CreateTexture(nil, "BACKGROUND", nil, 1);
152 frame.background:SetPoint("TOPLEFT", frame, "TOPLEFT", 1, -1);
153 frame.background:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -1, 1);
154 frame.background:SetColorTexture(unpack(bgColor));
155 frame.health = frame:CreateTexture(nil, "BORDER");
156 frame.health:SetTexture("Interface\\RaidFrame\\Raid-Bar-Hp-Fill");
157 frame.health:SetPoint("TOPLEFT", frame.background, "TOPLEFT");
158 frame.health:SetPoint("BOTTOMLEFT", frame.background, "BOTTOMLEFT", 0, 2);
159 frame.health:SetVertexColor(unpack(healthColor));
160 frame.health:SetWidth(width);
161 frame.health.max = UnitHealthMax(unit);
162 frame.mana = frame:CreateTexture(nil, "BORDER");
163 frame.mana:SetPoint("TOPLEFT", frame.background, "BOTTOMLEFT", 0, 2);
164 frame.mana:SetPoint("BOTTOMLEFT", frame.background, "BOTTOMLEFT");
165 frame.mana:SetColorTexture(1, 1, 1);
166 frame.mana:SetWidth(width);
167 frame.mana.max = UnitPowerMax(unit);
168 frame.shield = frame:CreateTexture(nil, "BORDER");
169 frame.shield:SetPoint("TOPLEFT", frame.health, "TOPRIGHT");
170 frame.shield:SetPoint("BOTTOMLEFT", frame.health, "BOTTOMRIGHT");
171 frame.shield:SetColorTexture(unpack(shieldColor));
173 frame.shieldhl = frame:CreateTexture(nil, "ARTWORK");
174 frame.shieldhl:SetPoint("TOPLEFT", frame.background, "TOPRIGHT", -1, 0);
175 frame.shieldhl:SetPoint("BOTTOMRIGHT", frame.background, "BOTTOMRIGHT", 1, 0);
176 frame.shieldhl:SetColorTexture(unpack(shieldhlColor));
177 frame.shieldhl:Hide();
178 frame.healpred = frame:CreateTexture(nil, "ARTWORK");
179 frame.healpred:SetPoint("TOPLEFT", frame.health, "TOPRIGHT");
180 frame.healpred:SetPoint("BOTTOMLEFT", frame.health, "BOTTOMRIGHT");
181 frame.healpred:SetColorTexture(unpack(healpredColor));
182 frame.healpred:Hide();
183 frame.healabsorb = frame:CreateTexture(nil, "ARTWORK");
184 frame.healabsorb:SetPoint("TOPRIGHT", frame.health, "TOPRIGHT");
185 frame.healabsorb:SetPoint("BOTTOMRIGHT", frame.health, "BOTTOMRIGHT");
186 frame.healabsorb:SetColorTexture(unpack(healabsorbColor));
187 frame.healabsorb:Hide();
188 frame.role = frame:CreateTexture(nil, "ARTWORK");
189 frame.role:SetPoint("BOTTOMRIGHT", frame.background, "BOTTOMRIGHT", -2, 2);
190 frame.role:SetPoint("TOPLEFT", frame.background, "BOTTOMRIGHT", -14, 14);
191 frame.role:SetTexCoord(0.75, 1, 0, 1);
192 frame.role:SetTexture("Interface\\LFGFRAME\\LFGROLE");
194 frame.overlay = frame:CreateTexture(nil, "ARTWORK", nil, 1);
195 frame.overlay:SetPoint("TOPLEFT", frame.background, "TOPLEFT");
196 frame.overlay:SetPoint("BOTTOMRIGHT", frame.background, "BOTTOMRIGHT", 0, 2);
197 frame.overlay:SetColorTexture(1, 1, 1);
198 frame.overlay:Hide();
199 frame.name = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
200 frame.name:SetPoint("CENTER", frame.background, "CENTER", 0, 11);
201 frame.text = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
202 frame.text:SetFont(STANDARD_TEXT_FONT, 13);
203 frame.text:SetPoint("CENTER", frame.background, "CENTER", 0, -1);
205 setupIndicators(frame);
206 frame:SetScript("OnShow", frameShow);
207 frame:SetScript("OnHide", frameHide);
209 secure:RegisterForClicks("AnyDown");
210 secure:SetAttribute("type1", "spell"); -- left click
211 secure:SetAttribute("type2", "spell"); -- right click
212 secure:SetAttribute("shift-type1", "spell"); -- shift left click
213 secure:SetAttribute("shift-type2", "spell"); -- shift right click
214 secure:SetAttribute("ctrl-type1", "spell"); -- ctrl left click
215 secure:SetAttribute("alt-type2", "spell"); -- alt right click
216 secure:SetAttribute("alt-shift-type1", "spell"); -- alt+shift left click
217 secure:SetAttribute("alt-shift-type2", "spell"); -- alt+shift right click
218 secure:SetAttribute("spell1", "Holy Light");
219 secure:SetAttribute("spell2", "Bestow Faith");
220 secure:SetAttribute("shift-spell1", "Flash of Light");
221 secure:SetAttribute("shift-spell2", "Light of the Martyr");
222 secure:SetAttribute("ctrl-spell1", "Cleanse");
223 secure:SetAttribute("alt-spell2", "Lay on Hands");
224 secure:SetAttribute("alt-shift-spell1", "Beacon of Light");
225 secure:SetAttribute("alt-shift-spell2", "Beacon of Faith");
226 -- rest give target and menu
227 secure:SetAttribute("*type1", "target");
228 secure:SetAttribute("*type2", "togglemenu");
231 -- vehicle toggle from Shadowed Unit Frames
232 local vehicletoggle = [=[
233 local unit = self:GetAttribute("unit");
234 if unit and newstate == "vehicle" and not UnitTargetsVehicleInRaidUI(unit) then
235 print(unit, "in vehicle, still target player");
236 self:SetAttribute("toggleForVehicle", false);
238 self:SetAttribute("toggleForVehicle", true);
242 -- TODO reorganizing needed for eventhandler stuff
243 function M.InitializeParty(parent, party, eventhandler)
244 unitEvent = eventhandler;
245 local secure = CreateFrame("Button", "OmaPartySecure0", parent, "SecureUnitButtonTemplate,SecureHandlerStateTemplate");
246 local frame = CreateFrame("Frame", "OmaParty0", parent);
247 local unit = "player";
248 secure:SetAttribute("unit", unit);
249 secure:SetPoint("TOPLEFT", parent, "TOPLEFT");
250 secure:SetHeight(height+2);
252 frame.vehicle = "vehicle";
253 frame.displayed = unit;
254 frame:SetAttribute("unit", unit);
255 frame:SetPoint("TOPLEFT", parent, "TOPLEFT");
256 frame:SetHeight(height+2);
257 frame:SetScript("OnEvent", eventhandler);
259 setupFrame(frame, secure, unit);
260 RegisterStateDriver(frame, "visibility", "[@player,group:raid] hide; show");
261 RegisterStateDriver(secure, "visibility", "[@player,group:raid] hide; show");
262 RegisterStateDriver(secure, "vehicleui", "[vehicleui] vehicle; no");
263 secure:SetAttribute("_onstate-vehicleui", vehicletoggle);
264 party[0] = {secure=secure, frame=frame};
266 local secure = CreateFrame("Button", "OmaPartySecure"..i, parent, "SecureUnitButtonTemplate,SecureHandlerStateTemplate");
267 local frame = CreateFrame("Frame", "OmaParty"..i, parent);
268 local unit = "party"..i;
269 secure:SetAttribute("unit", unit);
270 secure:SetPoint("TOPLEFT", party[i-1].secure, "TOPRIGHT");
271 secure:SetPoint("BOTTOMLEFT", party[i-1].secure, "BOTTOMRIGHT");
273 frame.vehicle = unit.."pet";
274 frame.displayed = unit;
275 frame:SetAttribute("unit", unit);
276 frame:SetPoint("TOPLEFT", party[i-1].frame, "TOPRIGHT");
277 frame:SetPoint("BOTTOMLEFT", party[i-1].frame, "BOTTOMRIGHT");
278 frame:SetScript("OnEvent", unitEvent);
280 setupFrame(frame, secure, unit);
281 local visible = format("[@%s,exists,group:raid] hide; [@%s,exists] show; hide", unit, unit);
282 local vehicle = format("[@%s,unithasvehicleui] vehicle; no", unit);
283 RegisterStateDriver(frame, "visibility", visible);
284 RegisterStateDriver(secure, "visibility", visible);
285 RegisterStateDriver(secure, "vehicleui", vehicle);
286 secure:SetAttribute("_onstate-vehicleui", vehicletoggle);
287 party[i] = {secure=secure, frame=frame};
291 function M.InitializeRaid(parent, raid, eventhandler)
292 local secure = CreateFrame("Button", "OmaRaidSecure1", parent, "SecureUnitButtonTemplate,SecureHandlerStateTemplate");
293 local frame = CreateFrame("Frame", "OmaRaid1", parent);
294 local unit = "raid1";
295 secure:SetAttribute("unit", unit);
296 secure:SetPoint("TOPLEFT", parent, "TOPLEFT");
297 secure:SetHeight(height+2);
299 frame.vehicle = unit.."pet";
300 frame.displayed = unit;
301 frame:SetAttribute("unit", unit);
302 frame:SetPoint("TOPLEFT", parent, "TOPLEFT");
303 frame:SetHeight(height+2);
304 frame:SetScript("OnEvent", eventhandler);
306 setupFrame(frame, secure, unit);
307 RegisterUnitWatch(frame);
308 RegisterUnitWatch(secure);
309 local vehicle = format("[@%s,unithasvehicleui] vehicle; no", unit);
310 RegisterStateDriver(secure, "vehicleui", vehicle);
311 secure:SetAttribute("_onstate-vehicleui", vehicletoggle);
312 raid[1] = {secure=secure, frame=frame};
315 local secure = CreateFrame("Button", "OmaRaidSecure"..i, parent, "SecureUnitButtonTemplate,SecureHandlerStateTemplate");
316 local frame = CreateFrame("Frame", "OmaRaid"..i, parent);
317 local unit = "raid"..i;
318 secure:SetAttribute("unit", unit);
319 secure:SetPoint("TOPLEFT", raid[i-5].secure, "BOTTOMLEFT");
320 secure:SetHeight(height+2);
322 frame.vehicle = unit.."pet";
323 frame.displayed = unit;
324 frame:SetAttribute("unit", unit);
325 frame:SetPoint("TOPLEFT", raid[i-5].frame, "BOTTOMLEFT");
326 frame:SetHeight(height+2);
327 frame:SetScript("OnEvent", unitEvent);
329 setupFrame(frame, secure, unit);
330 RegisterUnitWatch(frame);
331 RegisterUnitWatch(secure);
332 local vehicle = format("[@%s,unithasvehicleui] vehicle; no", unit);
333 RegisterStateDriver(secure, "vehicleui", vehicle);
334 secure:SetAttribute("_onstate-vehicleui", vehicletoggle);
335 raid[i] = {secure=secure, frame=frame};
340 local secure = CreateFrame("Button", "OmaRaidSecure"..i, parent, "SecureUnitButtonTemplate,SecureHandlerStateTemplate");
341 local frame = CreateFrame("Frame", "OmaRaid"..i, parent);
342 local unit = "raid"..i;
343 secure:SetAttribute("unit", unit);
344 secure:SetPoint("TOPLEFT", raid[i-1].secure, "TOPRIGHT");
345 secure:SetPoint("BOTTOMLEFT", raid[i-1].secure, "BOTTOMRIGHT");
347 frame.vehicle = unit.."pet";
348 frame.displayed = unit;
349 frame:SetAttribute("unit", unit);
350 frame:SetPoint("TOPLEFT", raid[i-1].frame, "TOPRIGHT");
351 frame:SetPoint("BOTTOMLEFT", raid[i-1].frame, "BOTTOMRIGHT");
352 frame:SetScript("OnEvent", unitEvent);
354 setupFrame(frame, secure, unit);
355 RegisterUnitWatch(frame);
356 RegisterUnitWatch(secure);
357 local vehicle = format("[@%s,unithasvehicleui] vehicle; no", unit);
358 RegisterStateDriver(secure, "vehicleui", vehicle);
359 secure:SetAttribute("_onstate-vehicleui", vehicletoggle);
360 raid[i] = {secure=secure, frame=frame};