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 STANDARD_TEXT_FONT = STANDARD_TEXT_FONT;
9 local GameTooltip = nil;
10 local GameTooltip_SetDefaultAnchor = nil;
12 local registerEvents = OmaRFEvents.RegisterEvents;
13 local unitEvent = OmaRFEvents.UnitEvent;
15 local Settings = OmaRFSettings;
16 local indSize = Settings.IndSize;
17 local baseColor = Settings.BaseColor;
18 local bgColor = Settings.BgColor;
19 local healthColor = Settings.HealthColor;
20 local shieldColor = Settings.ShieldColor;
21 local shieldhlColor = Settings.ShieldhlColor;
22 local healpredColor = Settings.HealpredColor;
23 local healabsorbColor = Settings.HealabsorbColor;
24 -- placeholders with visible values when error happens
26 local width, height = 10, 10;
27 local anchorX, anchorY = 10, 10;
28 local attributes = {};
30 local CFrame = CreateFrame("Frame", "OmaRFFrame", UIParent);
31 local inheritedFrames = "SecureUnitButtonTemplate,SecureHandlerStateTemplate";
38 local function setupIndicators(frame)
39 frame.inds = CreateFrame("Frame", nil, frame);
40 frame.inds:SetAllPoints();
42 for _, pos in pairs(positions) do
43 frame.inds[pos] = frame.inds:CreateTexture(nil, "OVERLAY");
44 frame.inds[pos]:SetPoint(pos, frame.inds, pos);
45 frame.inds[pos]:SetWidth(indSize);
46 frame.inds[pos]:SetHeight(indSize);
47 frame.inds[pos]:SetTexture("Interface\\AddOns\\OmaRF\\images\\rhomb");
48 frame.inds[pos]:SetVertexColor(1, 0, 0);
49 frame.inds[pos]:Hide();
50 frame.inds[pos].text = frame.inds:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
51 frame.inds[pos].text:SetPoint("BOTTOMRIGHT", frame.inds[pos], "BOTTOMRIGHT");
52 frame.inds[pos].text:Hide();
54 frame.major = CreateFrame("Frame", nil, frame);
55 frame.major:SetPoint("TOPLEFT", frame, "TOPLEFT", 4, -indSize + 4);
56 frame.major:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT");
58 frame.major[i] = frame.major:CreateTexture(nil, "OVERLAY");
60 frame.major[i]:SetPoint("TOPLEFT", frame.major, "TOPLEFT");
62 frame.major[i]:SetPoint("TOPLEFT", frame.major[i-1], "TOPRIGHT");
64 frame.major[i]:SetWidth(indSize*2);
65 frame.major[i]:SetHeight(indSize*2);
66 frame.major[i]:Hide();
67 frame.major[i].text = frame.major:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
68 frame.major[i].text:SetPoint("BOTTOMRIGHT", frame.major[i], "BOTTOMRIGHT");
69 frame.major[i].text:Hide();
70 frame.major[i].stack = frame.major:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
71 frame.major[i].stack:SetPoint("TOPLEFT", frame.major[i], "TOPLEFT");
72 frame.major[i].stack:Hide();
76 local function unitUpdate(self, elapsed)
77 -- there's no in/out of range event, have to check each frame
78 -- from FrameXML/CompactUnitFrame.lua
79 local inRange, checked = UnitInRange(self.displayed);
80 if checked and not inRange then
87 local function frameShow(frame)
88 frame:RegisterEvent("PARTY_MEMBER_ENABLE");
89 frame:RegisterEvent("PARTY_MEMBER_DISABLE");
90 frame:RegisterEvent("UNIT_ENTERED_VEHICLE");
91 frame:RegisterEvent("UNIT_EXITED_VEHICLE");
92 frame:RegisterEvent("UNIT_PET");
93 frame:RegisterEvent("PLAYER_ROLES_ASSIGNED");
94 frame:RegisterEvent("GROUP_ROSTER_UPDATE");
95 frame:RegisterEvent("PLAYER_ENTERING_WORLD");
96 frame:RegisterEvent("READY_CHECK");
97 frame:RegisterEvent("READY_CHECK_CONFIRM");
98 frame:RegisterEvent("READY_CHECK_FINISHED");
99 if frame.unit == "focus" then frame:RegisterEvent("PLAYER_FOCUS_CHANGED") end
100 registerEvents(frame);
101 frame:SetScript("OnUpdate", unitUpdate);
102 unitEvent(frame, "UPDATE_ALL_BARS", frame.displayed);
105 local function frameHide(frame)
106 frame:UnregisterAllEvents();
107 frame:SetScript("OnUpdate", nil);
110 local function showTooltip(frame)
111 GameTooltip_SetDefaultAnchor(GameTooltip, PlayerFrame);
112 GameTooltip:SetUnit(frame:GetAttribute("unit"));
115 local function hideTooltip(frame)
116 GameTooltip:FadeOut();
119 local function setupFrame(frame, secure, unit)
120 secure:SetAttribute("unit", unit);
121 frame:SetAttribute("unit", unit);
123 frame.displayed = unit;
124 -- hide frame to get initial frameShow call
126 if unit == "player" then
127 frame.vehicle = "vehicle";
129 frame.vehicle = unit.."pet";
132 secure:SetWidth(width+2);
133 secure:SetHeight(height+2);
134 frame:SetWidth(width+2);
135 frame:SetHeight(height+2);
136 frame.base = frame:CreateTexture(nil, "BACKGROUND");
137 frame.base:SetAllPoints();
138 frame.base:SetColorTexture(1, 1, 1);
139 frame.base:SetVertexColor(unpack(baseColor));
140 frame.background = frame:CreateTexture(nil, "BACKGROUND", nil, 1);
141 frame.background:SetPoint("TOPLEFT", frame, "TOPLEFT", 1, -1);
142 frame.background:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -1, 1);
143 frame.background:SetColorTexture(unpack(bgColor));
144 frame.health = frame:CreateTexture(nil, "BORDER");
145 frame.health:SetTexture("Interface\\RaidFrame\\Raid-Bar-Hp-Fill");
146 frame.health:SetPoint("TOPLEFT", frame.background, "TOPLEFT");
147 frame.health:SetPoint("BOTTOMLEFT", frame.background, "BOTTOMLEFT", 0, 2);
148 frame.health:SetVertexColor(unpack(healthColor));
149 frame.health:SetWidth(width);
150 frame.health.max = UnitHealthMax(unit);
151 frame.mana = frame:CreateTexture(nil, "BORDER");
152 frame.mana:SetPoint("TOPLEFT", frame.background, "BOTTOMLEFT", 0, 2);
153 frame.mana:SetPoint("BOTTOMLEFT", frame.background, "BOTTOMLEFT");
154 frame.mana:SetColorTexture(1, 1, 1);
155 frame.mana:SetWidth(width);
156 frame.mana.max = UnitPowerMax(unit);
157 frame.shield = frame:CreateTexture(nil, "BORDER");
158 frame.shield:SetPoint("TOPLEFT", frame.health, "TOPRIGHT");
159 frame.shield:SetPoint("BOTTOMLEFT", frame.health, "BOTTOMRIGHT");
160 frame.shield:SetColorTexture(unpack(shieldColor));
162 frame.shieldhl = frame:CreateTexture(nil, "ARTWORK");
163 frame.shieldhl:SetPoint("TOPLEFT", frame.background, "TOPRIGHT", -1, 0);
164 frame.shieldhl:SetPoint("BOTTOMRIGHT", frame.background, "BOTTOMRIGHT", 1, 0);
165 frame.shieldhl:SetColorTexture(unpack(shieldhlColor));
166 frame.shieldhl:Hide();
167 frame.healpred = frame:CreateTexture(nil, "ARTWORK");
168 frame.healpred:SetPoint("TOPLEFT", frame.health, "TOPRIGHT");
169 frame.healpred:SetPoint("BOTTOMLEFT", frame.health, "BOTTOMRIGHT");
170 frame.healpred:SetColorTexture(unpack(healpredColor));
171 frame.healpred:Hide();
172 frame.healabsorb = frame:CreateTexture(nil, "ARTWORK");
173 frame.healabsorb:SetPoint("TOPRIGHT", frame.health, "TOPRIGHT");
174 frame.healabsorb:SetPoint("BOTTOMRIGHT", frame.health, "BOTTOMRIGHT");
175 frame.healabsorb:SetColorTexture(unpack(healabsorbColor));
176 frame.healabsorb:Hide();
177 frame.role = frame:CreateTexture(nil, "ARTWORK");
178 frame.role:SetPoint("BOTTOMRIGHT", frame.background, "BOTTOMRIGHT", -2, 2);
179 frame.role:SetPoint("TOPLEFT", frame.background, "BOTTOMRIGHT", -14, 14);
180 frame.role:SetTexCoord(0.75, 1, 0, 1);
181 frame.role:SetTexture("Interface\\LFGFRAME\\LFGROLE");
183 frame.overlay = frame:CreateTexture(nil, "ARTWORK", nil, 1);
184 frame.overlay:SetPoint("TOPLEFT", frame.background, "TOPLEFT");
185 frame.overlay:SetPoint("BOTTOMRIGHT", frame.background, "BOTTOMRIGHT", 0, 2);
186 frame.overlay:SetColorTexture(1, 1, 1);
187 frame.overlay:Hide();
188 frame.name = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
189 frame.name:SetPoint("CENTER", frame.background, "CENTER", 0, 11);
190 frame.text = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
191 frame.text:SetFont(STANDARD_TEXT_FONT, 13);
192 frame.text:SetPoint("CENTER", frame.background, "CENTER", 0, -1);
194 frame.rez = frame:CreateTexture(nil, "OVERLAY");
195 frame.rez:SetPoint("TOPLEFT", frame.background, "CENTER", -12, 12);
196 frame.rez:SetPoint("BOTTOMRIGHT", frame.background, "CENTER", 12, -12);
197 frame.rez:SetTexture("Interface\\RaidFrame\\Raid-Icon-Rez");
199 frame.ready = frame:CreateTexture(nil, "OVERLAY");
200 frame.ready:SetPoint("TOPLEFT", frame.background, "BOTTOMLEFT", 0, 12);
201 frame.ready:SetPoint("BOTTOMRIGHT", frame.background, "BOTTOMLEFT", 12, 0);
204 setupIndicators(frame);
206 frame:SetScript("OnShow", frameShow);
207 frame:SetScript("OnHide", frameHide);
208 frame:SetScript("OnEvent", unitEvent);
209 -- let other addons hook these to anchor tooltip elsewhere
210 GameTooltip = _G["GameTooltip"];
211 GameTooltip_SetDefaultAnchor = _G["GameTooltip_SetDefaultAnchor"];
212 secure:SetScript("OnEnter", showTooltip);
213 secure:SetScript("OnLeave", hideTooltip);
215 secure:RegisterForClicks("AnyDown");
216 for attr, val in pairs(attributes) do
217 secure:SetAttribute(attr, val);
219 -- rest give target and menu
220 secure:SetAttribute("*type1", "target");
221 secure:SetAttribute("*type2", "togglemenu");
224 -- vehicle toggle from Shadowed Unit Frames
225 local vehicletoggle = [=[
226 local unit = self:GetAttribute("unit");
227 if unit and newstate == "vehicle" and not UnitTargetsVehicleInRaidUI(unit) then
228 self:SetAttribute("toggleForVehicle", false);
230 self:SetAttribute("toggleForVehicle", true);
234 local function initializeParty(parent)
235 local secure = CreateFrame("Button", "OmaPartySecure0", parent, inheritedFrames);
236 local frame = CreateFrame("Frame", "OmaParty0", parent);
237 local unit = "player";
238 secure:SetPoint("TOPLEFT", parent, "TOPLEFT");
239 frame:SetPoint("TOPLEFT", parent, "TOPLEFT");
240 setupFrame(frame, secure, unit);
241 RegisterStateDriver(frame, "visibility", "[@player,group:raid] hide; show");
242 RegisterStateDriver(secure, "visibility", "[@player,group:raid] hide; show");
243 RegisterStateDriver(secure, "vehicleui", "[vehicleui] vehicle; no");
244 secure:SetAttribute("_onstate-vehicleui", vehicletoggle);
245 party[0] = {secure=secure, frame=frame};
247 local secure = CreateFrame("Button", "OmaPartySecure"..i, parent, inheritedFrames);
248 local frame = CreateFrame("Frame", "OmaParty"..i, parent);
249 local unit = "party"..i;
250 secure:SetPoint("TOPLEFT", party[i-1].secure, "TOPRIGHT");
251 frame:SetPoint("TOPLEFT", party[i-1].frame, "TOPRIGHT");
252 setupFrame(frame, secure, unit);
253 local visible = format("[@%s,exists,group:raid] hide; [@%s,exists] show; hide", unit, unit);
254 local vehicle = format("[@%s,unithasvehicleui] vehicle; no", unit);
255 RegisterStateDriver(frame, "visibility", visible);
256 RegisterStateDriver(secure, "visibility", visible);
257 RegisterStateDriver(secure, "vehicleui", vehicle);
258 secure:SetAttribute("_onstate-vehicleui", vehicletoggle);
259 party[i] = {secure=secure, frame=frame};
263 local function initializeRaid(parent)
264 local secure = CreateFrame("Button", "OmaRaidSecure1", parent, inheritedFrames);
265 local frame = CreateFrame("Frame", "OmaRaid1", parent);
266 local unit = "raid1";
267 secure:SetPoint("TOPLEFT", parent, "TOPLEFT");
268 frame:SetPoint("TOPLEFT", parent, "TOPLEFT");
269 setupFrame(frame, secure, unit);
270 RegisterUnitWatch(frame);
271 RegisterUnitWatch(secure);
272 local vehicle = format("[@%s,unithasvehicleui] vehicle; no", unit);
273 RegisterStateDriver(secure, "vehicleui", vehicle);
274 secure:SetAttribute("_onstate-vehicleui", vehicletoggle);
275 raid[1] = {secure=secure, frame=frame};
278 local secure = CreateFrame("Button", "OmaRaidSecure"..i, parent, inheritedFrames);
279 local frame = CreateFrame("Frame", "OmaRaid"..i, parent);
280 local unit = "raid"..i;
281 secure:SetPoint("TOPLEFT", raid[i-5].secure, "BOTTOMLEFT");
282 frame:SetPoint("TOPLEFT", raid[i-5].frame, "BOTTOMLEFT");
283 setupFrame(frame, secure, unit);
284 RegisterUnitWatch(frame);
285 RegisterUnitWatch(secure);
286 local vehicle = format("[@%s,unithasvehicleui] vehicle; no", unit);
287 RegisterStateDriver(secure, "vehicleui", vehicle);
288 secure:SetAttribute("_onstate-vehicleui", vehicletoggle);
289 raid[i] = {secure=secure, frame=frame};
294 local secure = CreateFrame("Button", "OmaRaidSecure"..i, parent, inheritedFrames);
295 local frame = CreateFrame("Frame", "OmaRaid"..i, parent);
296 local unit = "raid"..i;
297 secure:SetPoint("TOPLEFT", raid[i-1].secure, "TOPRIGHT");
298 frame:SetPoint("TOPLEFT", raid[i-1].frame, "TOPRIGHT");
299 setupFrame(frame, secure, unit);
300 RegisterUnitWatch(frame);
301 RegisterUnitWatch(secure);
302 local vehicle = format("[@%s,unithasvehicleui] vehicle; no", unit);
303 RegisterStateDriver(secure, "vehicleui", vehicle);
304 secure:SetAttribute("_onstate-vehicleui", vehicletoggle);
305 raid[i] = {secure=secure, frame=frame};
310 local function initializeFocus(parent)
311 local secure = CreateFrame("Button", "OmaFocusSecure", parent, inheritedFrames);
312 local frame = CreateFrame("Frame", "OmaFocus", parent);
313 local unit = "focus";
314 secure:SetPoint("BOTTOMLEFT", parent, "TOPLEFT");
315 frame:SetPoint("BOTTOMLEFT", parent, "TOPLEFT");
316 setupFrame(frame, secure, unit);
317 RegisterUnitWatch(frame);
318 RegisterUnitWatch(secure);
319 local vehicle = format("[@%s,unithasvehicleui] vehicle; no", unit);
320 RegisterStateDriver(secure, "vehicleui", vehicle);
321 secure:SetAttribute("_onstate-vehicleui", vehicletoggle);
324 local function initialize()
325 CFrame:SetPoint("CENTER", nil, "CENTER", anchorX, anchorY);
326 CFrame:SetHeight((height+2)*8);
327 CFrame:SetWidth((width+2)*5+1);
328 initializeParty(CFrame);
329 initializeRaid(CFrame);
330 initializeFocus(CFrame);
333 local function loadCharSettings()
334 width, height = Settings.Character.Width, Settings.Character.Height;
335 anchorX, anchorY = Settings.Character.AnchorX, Settings.Character.AnchorY;
336 attributes = Settings.Character.Clickheal;
337 positions = Settings.Character.Positions;
340 CFrame:RegisterEvent("ADDON_LOADED");
341 CFrame:RegisterEvent("PLAYER_LOGIN");
342 CFrame:SetScript("OnEvent", function(self, event)
343 if event == "PLAYER_LOGIN" then
345 elseif event == "ADDON_LOADED" then
348 OmaRFEvents.LoadChar();
349 OmaRFIndicators.LoadChar();