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.unit);
96 if checked and not inRange then
103 local function frameShow(frame)
104 -- events are taken from FrameXML/CompactUnitFrame.lua
105 -- TODO vehicle support, ready check support, raid marker support,
106 -- player flags support (/afk, /dnd)
107 -- TODO only update for vehicle events here
108 frame:RegisterEvent("PARTY_MEMBER_ENABLE");
109 frame:RegisterEvent("PARTY_MEMBER_DISABLE");
110 frame:RegisterUnitEvent("UNIT_HEALTH", frame.unit);
111 frame:RegisterUnitEvent("UNIT_HEALTH_FREQUENT", frame.unit);
112 frame:RegisterUnitEvent("UNIT_MAXHEALTH", frame.unit);
113 frame:RegisterUnitEvent("UNIT_POWER", frame.unit);
114 frame:RegisterUnitEvent("UNIT_MAXPOWER", frame.unit);
115 frame:RegisterUnitEvent("UNIT_DISPLAYPOWER", frame.unit);
116 frame:RegisterUnitEvent("UNIT_NAME_UPDATE", frame.unit);
117 frame:RegisterUnitEvent("UNIT_AURA", frame.unit);
118 frame:RegisterUnitEvent("UNIT_HEAL_PREDICTION", frame.unit);
119 frame:RegisterUnitEvent("UNIT_ABSORB_AMOUNT_CHANGED", frame.unit);
120 frame:RegisterUnitEvent("UNIT_HEAL_ABSORB_AMOUNT_CHANGED", frame.unit);
121 frame:RegisterUnitEvent("UNIT_THREAT_SITUATION_UPDATE", frame.unit);
122 frame:RegisterUnitEvent("UNIT_CONNECTION", frame.unit);
123 frame:RegisterUnitEvent("INCOMING_RESURRECT_CHANGED", frame.unit);
124 frame:SetScript("OnUpdate", unitUpdate);
125 unitEvent(frame, "UPDATE_ALL_BARS", frame.unit);
128 local function frameHide(frame)
129 frame:UnregisterAllEvents();
130 frame:SetScript("OnUpdate", nil);
133 local function setupFrame(frame, secure, unit)
135 secure:SetWidth(width+2);
136 frame:SetWidth(width+2);
137 frame.base = frame:CreateTexture(nil, "BACKGROUND");
138 frame.base:SetAllPoints();
139 frame.base:SetColorTexture(1, 1, 1);
140 frame.base:SetVertexColor(unpack(baseColor));
141 frame.background = frame:CreateTexture(nil, "BACKGROUND", nil, 1);
142 frame.background:SetPoint("TOPLEFT", frame, "TOPLEFT", 1, -1);
143 frame.background:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -1, 1);
144 frame.background:SetColorTexture(unpack(bgColor));
145 frame.health = frame:CreateTexture(nil, "BORDER");
146 frame.health:SetTexture("Interface\\RaidFrame\\Raid-Bar-Hp-Fill");
147 frame.health:SetPoint("TOPLEFT", frame.background, "TOPLEFT");
148 frame.health:SetPoint("BOTTOMLEFT", frame.background, "BOTTOMLEFT", 0, 2);
149 frame.health:SetVertexColor(unpack(healthColor));
150 frame.health:SetWidth(width);
151 frame.health.max = UnitHealthMax(unit);
152 frame.mana = frame:CreateTexture(nil, "BORDER");
153 frame.mana:SetPoint("TOPLEFT", frame.background, "BOTTOMLEFT", 0, 2);
154 frame.mana:SetPoint("BOTTOMLEFT", frame.background, "BOTTOMLEFT");
155 frame.mana:SetColorTexture(1, 1, 1);
156 frame.mana:SetWidth(width);
157 frame.mana.max = UnitPowerMax(unit);
158 frame.shield = frame:CreateTexture(nil, "BORDER");
159 frame.shield:SetPoint("TOPLEFT", frame.health, "TOPRIGHT");
160 frame.shield:SetPoint("BOTTOMLEFT", frame.health, "BOTTOMRIGHT");
161 frame.shield:SetColorTexture(unpack(shieldColor));
163 frame.shieldhl = frame:CreateTexture(nil, "ARTWORK");
164 frame.shieldhl:SetPoint("TOPLEFT", frame.background, "TOPRIGHT", -1, 0);
165 frame.shieldhl:SetPoint("BOTTOMRIGHT", frame.background, "BOTTOMRIGHT", 1, 0);
166 frame.shieldhl:SetColorTexture(unpack(shieldhlColor));
167 frame.shieldhl:Hide();
168 frame.healpred = frame:CreateTexture(nil, "ARTWORK");
169 frame.healpred:SetPoint("TOPLEFT", frame.health, "TOPRIGHT");
170 frame.healpred:SetPoint("BOTTOMLEFT", frame.health, "BOTTOMRIGHT");
171 frame.healpred:SetColorTexture(unpack(healpredColor));
172 frame.healpred:Hide();
173 frame.healabsorb = frame:CreateTexture(nil, "ARTWORK");
174 frame.healabsorb:SetPoint("TOPRIGHT", frame.health, "TOPRIGHT");
175 frame.healabsorb:SetPoint("BOTTOMRIGHT", frame.health, "BOTTOMRIGHT");
176 frame.healabsorb:SetColorTexture(unpack(healabsorbColor));
177 frame.healabsorb:Hide();
178 frame.overlay = frame:CreateTexture(nil, "ARTWORK", nil, 1);
179 frame.overlay:SetPoint("TOPLEFT", frame.background, "TOPLEFT");
180 frame.overlay:SetPoint("BOTTOMRIGHT", frame.background, "BOTTOMRIGHT", 0, 2);
181 frame.overlay:SetColorTexture(1, 1, 1);
182 frame.overlay:Hide();
183 frame.name = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
184 frame.name:SetPoint("CENTER", frame.background, "CENTER", 0, 11);
185 frame.text = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
186 frame.text:SetFont(STANDARD_TEXT_FONT, 13);
187 frame.text:SetPoint("CENTER", frame.background, "CENTER", 0, -1);
189 setupIndicators(frame);
190 frame:SetScript("OnShow", frameShow);
191 frame:SetScript("OnHide", frameHide);
193 secure:RegisterForClicks("AnyDown");
194 secure:SetAttribute("type1", "spell"); -- left click
195 secure:SetAttribute("type2", "spell"); -- right click
196 secure:SetAttribute("shift-type1", "spell"); -- shift left click
197 secure:SetAttribute("shift-type2", "spell"); -- shift right click
198 secure:SetAttribute("ctrl-type1", "spell"); -- ctrl left click
199 secure:SetAttribute("alt-type2", "spell"); -- alt right click
200 secure:SetAttribute("alt-shift-type1", "spell"); -- alt+shift left click
201 secure:SetAttribute("alt-shift-type2", "spell"); -- alt+shift right click
202 secure:SetAttribute("spell1", "Holy Light");
203 secure:SetAttribute("spell2", "Bestow Faith");
204 secure:SetAttribute("shift-spell1", "Flash of Light");
205 secure:SetAttribute("shift-spell2", "Light of the Martyr");
206 secure:SetAttribute("ctrl-spell1", "Cleanse");
207 secure:SetAttribute("alt-spell2", "Lay on Hands");
208 secure:SetAttribute("alt-shift-spell1", "Beacon of Light");
209 secure:SetAttribute("alt-shift-spell2", "Beacon of Faith");
210 -- rest give target and menu
211 secure:SetAttribute("*type1", "target");
212 secure:SetAttribute("*type2", "togglemenu");
215 -- TODO reorganizing needed for eventhandler stuff
216 function M.InitializeParty(parent, party, eventhandler)
217 unitEvent = eventhandler;
218 local secure = CreateFrame("Button", "OmaPartySecure0", parent, "SecureUnitButtonTemplate");
219 local frame = CreateFrame("Frame", "OmaParty0", parent);
220 local unit = "player";
221 secure:SetAttribute("unit", unit);
222 secure:SetPoint("TOPLEFT", parent, "TOPLEFT");
223 secure:SetHeight(height+2);
225 frame:SetAttribute("unit", unit);
226 frame:SetPoint("TOPLEFT", parent, "TOPLEFT");
227 frame:SetHeight(height+2);
228 frame:SetScript("OnEvent", eventhandler);
230 setupFrame(frame, secure, unit);
231 RegisterStateDriver(frame, "visibility", "[@player,group:raid] hide; show");
232 RegisterStateDriver(secure, "visibility", "[@player,group:raid] hide; show");
233 party[0] = {secure=secure, frame=frame};
235 local secure = CreateFrame("Button", "OmaPartySecure"..i, parent, "SecureUnitButtonTemplate");
236 local frame = CreateFrame("Frame", "OmaParty"..i, parent);
237 local unit = "party"..i;
238 secure:SetAttribute("unit", unit);
239 secure:SetPoint("TOPLEFT", party[i-1].secure, "TOPRIGHT");
240 secure:SetPoint("BOTTOMLEFT", party[i-1].secure, "BOTTOMRIGHT");
242 frame:SetAttribute("unit", unit);
243 frame:SetPoint("TOPLEFT", party[i-1].frame, "TOPRIGHT");
244 frame:SetPoint("BOTTOMLEFT", party[i-1].frame, "BOTTOMRIGHT");
245 frame:SetScript("OnEvent", unitEvent);
247 setupFrame(frame, secure, unit);
248 local visible = format("[@%s,exists,group:raid] hide; [@%s,exists] show; hide", unit, unit);
249 RegisterStateDriver(frame, "visibility", visible);
250 RegisterStateDriver(secure, "visibility", visible);
251 party[i] = {secure=secure, frame=frame};
255 function M.InitializeRaid(parent, raid, eventhandler)
256 local secure = CreateFrame("Button", "OmaRaidSecure1", parent, "SecureUnitButtonTemplate");
257 local frame = CreateFrame("Frame", "OmaRaid1", parent);
258 local unit = "raid1";
259 secure:SetAttribute("unit", unit);
260 secure:SetPoint("TOPLEFT", parent, "TOPLEFT");
261 secure:SetHeight(height+2);
263 frame:SetAttribute("unit", unit);
264 frame:SetPoint("TOPLEFT", parent, "TOPLEFT");
265 frame:SetHeight(height+2);
266 frame:SetScript("OnEvent", eventhandler);
268 setupFrame(frame, secure, unit);
269 RegisterUnitWatch(frame);
270 RegisterUnitWatch(secure);
271 raid[1] = {secure=secure, frame=frame};
274 local secure = CreateFrame("Button", "OmaRaidSecure"..i, parent, "SecureUnitButtonTemplate");
275 local frame = CreateFrame("Frame", "OmaRaid"..i, parent);
276 local unit = "raid"..i;
277 secure:SetAttribute("unit", unit);
278 secure:SetPoint("TOPLEFT", raid[i-5].secure, "BOTTOMLEFT");
279 secure:SetHeight(height+2);
281 frame:SetAttribute("unit", unit);
282 frame:SetPoint("TOPLEFT", raid[i-5].frame, "BOTTOMLEFT");
283 frame:SetHeight(height+2);
284 frame:SetScript("OnEvent", unitEvent);
286 setupFrame(frame, secure, unit);
287 RegisterUnitWatch(frame);
288 RegisterUnitWatch(secure);
289 raid[i] = {secure=secure, frame=frame};
294 local secure = CreateFrame("Button", "OmaRaidSecure"..i, parent, "SecureUnitButtonTemplate");
295 local frame = CreateFrame("Frame", "OmaRaid"..i, parent);
296 local unit = "raid"..i;
297 secure:SetAttribute("unit", unit);
298 secure:SetPoint("TOPLEFT", raid[i-1].secure, "TOPRIGHT");
299 secure:SetPoint("BOTTOMLEFT", raid[i-1].secure, "BOTTOMRIGHT");
301 frame:SetAttribute("unit", unit);
302 frame:SetPoint("TOPLEFT", raid[i-1].frame, "TOPRIGHT");
303 frame:SetPoint("BOTTOMLEFT", raid[i-1].frame, "BOTTOMRIGHT");
304 frame:SetScript("OnEvent", unitEvent);
306 setupFrame(frame, secure, unit);
307 RegisterUnitWatch(frame);
308 RegisterUnitWatch(secure);
309 raid[i] = {secure=secure, frame=frame};