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;
10 local registerEvents = OmaRFEvents.RegisterEvents;
11 local unitEvent = OmaRFEvents.UnitEvent;
13 local Settings = OmaRFSettings;
14 local indSize = Settings.IndSize;
15 local baseColor = Settings.BaseColor;
16 local bgColor = Settings.BgColor;
17 local healthColor = Settings.HealthColor;
18 local shieldColor = Settings.ShieldColor;
19 local shieldhlColor = Settings.ShieldhlColor;
20 local healpredColor = Settings.HealpredColor;
21 local healabsorbColor = Settings.HealabsorbColor;
22 -- placeholders with visible values when error happens
24 local width, height = 10, 10;
25 local anchorX, anchorY = 10, 10;
26 local attributes = {};
28 local CFrame = CreateFrame("Frame", "OmaRFFrame", UIParent);
29 local inheritedFrames = "SecureUnitButtonTemplate,SecureHandlerStateTemplate";
36 local function setupIndicators(frame)
37 frame.inds = CreateFrame("Frame", nil, frame);
38 frame.inds:SetAllPoints();
40 for _, pos in pairs(positions) do
41 frame.inds[pos] = frame.inds:CreateTexture(nil, "OVERLAY");
42 frame.inds[pos]:SetPoint(pos, frame.inds, pos);
43 frame.inds[pos]:SetWidth(indSize);
44 frame.inds[pos]:SetHeight(indSize);
45 frame.inds[pos]:SetTexture("Interface\\AddOns\\OmaRF\\images\\rhomb");
46 frame.inds[pos]:SetVertexColor(1, 0, 0);
47 frame.inds[pos]:Hide();
48 frame.inds[pos].text = frame.inds:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
49 frame.inds[pos].text:SetPoint("BOTTOMRIGHT", frame.inds[pos], "BOTTOMRIGHT");
50 frame.inds[pos].text:Hide();
52 frame.major = CreateFrame("Frame", nil, frame);
53 frame.major:SetPoint("TOPLEFT", frame, "TOPLEFT", 4, -indSize + 4);
54 frame.major:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT");
56 frame.major[i] = frame.major:CreateTexture(nil, "OVERLAY");
58 frame.major[i]:SetPoint("TOPLEFT", frame.major, "TOPLEFT");
60 frame.major[i]:SetPoint("TOPLEFT", frame.major[i-1], "TOPRIGHT");
62 frame.major[i]:SetWidth(indSize*2);
63 frame.major[i]:SetHeight(indSize*2);
64 frame.major[i]:Hide();
65 frame.major[i].text = frame.major:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
66 frame.major[i].text:SetPoint("BOTTOMRIGHT", frame.major[i], "BOTTOMRIGHT");
67 frame.major[i].text:Hide();
68 frame.major[i].stack = frame.major:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
69 frame.major[i].stack:SetPoint("TOPLEFT", frame.major[i], "TOPLEFT");
70 frame.major[i].stack:Hide();
74 local function unitUpdate(self, elapsed)
75 -- there's no in/out of range event, have to check each frame
76 -- from FrameXML/CompactUnitFrame.lua
77 local inRange, checked = UnitInRange(self.displayed);
78 if checked and not inRange then
85 local function frameShow(frame)
86 frame:RegisterEvent("PARTY_MEMBER_ENABLE");
87 frame:RegisterEvent("PARTY_MEMBER_DISABLE");
88 frame:RegisterEvent("UNIT_ENTERED_VEHICLE");
89 frame:RegisterEvent("UNIT_EXITED_VEHICLE");
90 frame:RegisterEvent("UNIT_PET");
91 frame:RegisterEvent("PLAYER_ROLES_ASSIGNED");
92 frame:RegisterEvent("GROUP_ROSTER_UPDATE");
93 frame:RegisterEvent("PLAYER_ENTERING_WORLD");
94 registerEvents(frame);
95 frame:SetScript("OnUpdate", unitUpdate);
96 unitEvent(frame, "UPDATE_ALL_BARS", frame.displayed);
99 local function frameHide(frame)
100 frame:UnregisterAllEvents();
101 frame:SetScript("OnUpdate", nil);
104 local function setupFrame(frame, secure, unit)
105 secure:SetAttribute("unit", unit);
106 frame:SetAttribute("unit", unit);
108 frame.displayed = unit;
109 -- hide frame to get initial frameShow call
111 if unit == "player" then
112 frame.vehicle = "vehicle";
114 frame.vehicle = unit.."pet";
117 secure:SetWidth(width+2);
118 secure:SetHeight(height+2);
119 frame:SetWidth(width+2);
120 frame:SetHeight(height+2);
121 frame.base = frame:CreateTexture(nil, "BACKGROUND");
122 frame.base:SetAllPoints();
123 frame.base:SetColorTexture(1, 1, 1);
124 frame.base:SetVertexColor(unpack(baseColor));
125 frame.background = frame:CreateTexture(nil, "BACKGROUND", nil, 1);
126 frame.background:SetPoint("TOPLEFT", frame, "TOPLEFT", 1, -1);
127 frame.background:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -1, 1);
128 frame.background:SetColorTexture(unpack(bgColor));
129 frame.health = frame:CreateTexture(nil, "BORDER");
130 frame.health:SetTexture("Interface\\RaidFrame\\Raid-Bar-Hp-Fill");
131 frame.health:SetPoint("TOPLEFT", frame.background, "TOPLEFT");
132 frame.health:SetPoint("BOTTOMLEFT", frame.background, "BOTTOMLEFT", 0, 2);
133 frame.health:SetVertexColor(unpack(healthColor));
134 frame.health:SetWidth(width);
135 frame.health.max = UnitHealthMax(unit);
136 frame.mana = frame:CreateTexture(nil, "BORDER");
137 frame.mana:SetPoint("TOPLEFT", frame.background, "BOTTOMLEFT", 0, 2);
138 frame.mana:SetPoint("BOTTOMLEFT", frame.background, "BOTTOMLEFT");
139 frame.mana:SetColorTexture(1, 1, 1);
140 frame.mana:SetWidth(width);
141 frame.mana.max = UnitPowerMax(unit);
142 frame.shield = frame:CreateTexture(nil, "BORDER");
143 frame.shield:SetPoint("TOPLEFT", frame.health, "TOPRIGHT");
144 frame.shield:SetPoint("BOTTOMLEFT", frame.health, "BOTTOMRIGHT");
145 frame.shield:SetColorTexture(unpack(shieldColor));
147 frame.shieldhl = frame:CreateTexture(nil, "ARTWORK");
148 frame.shieldhl:SetPoint("TOPLEFT", frame.background, "TOPRIGHT", -1, 0);
149 frame.shieldhl:SetPoint("BOTTOMRIGHT", frame.background, "BOTTOMRIGHT", 1, 0);
150 frame.shieldhl:SetColorTexture(unpack(shieldhlColor));
151 frame.shieldhl:Hide();
152 frame.healpred = frame:CreateTexture(nil, "ARTWORK");
153 frame.healpred:SetPoint("TOPLEFT", frame.health, "TOPRIGHT");
154 frame.healpred:SetPoint("BOTTOMLEFT", frame.health, "BOTTOMRIGHT");
155 frame.healpred:SetColorTexture(unpack(healpredColor));
156 frame.healpred:Hide();
157 frame.healabsorb = frame:CreateTexture(nil, "ARTWORK");
158 frame.healabsorb:SetPoint("TOPRIGHT", frame.health, "TOPRIGHT");
159 frame.healabsorb:SetPoint("BOTTOMRIGHT", frame.health, "BOTTOMRIGHT");
160 frame.healabsorb:SetColorTexture(unpack(healabsorbColor));
161 frame.healabsorb:Hide();
162 frame.role = frame:CreateTexture(nil, "ARTWORK");
163 frame.role:SetPoint("BOTTOMRIGHT", frame.background, "BOTTOMRIGHT", -2, 2);
164 frame.role:SetPoint("TOPLEFT", frame.background, "BOTTOMRIGHT", -14, 14);
165 frame.role:SetTexCoord(0.75, 1, 0, 1);
166 frame.role:SetTexture("Interface\\LFGFRAME\\LFGROLE");
168 frame.overlay = frame:CreateTexture(nil, "ARTWORK", nil, 1);
169 frame.overlay:SetPoint("TOPLEFT", frame.background, "TOPLEFT");
170 frame.overlay:SetPoint("BOTTOMRIGHT", frame.background, "BOTTOMRIGHT", 0, 2);
171 frame.overlay:SetColorTexture(1, 1, 1);
172 frame.overlay:Hide();
173 frame.name = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
174 frame.name:SetPoint("CENTER", frame.background, "CENTER", 0, 11);
175 frame.text = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
176 frame.text:SetFont(STANDARD_TEXT_FONT, 13);
177 frame.text:SetPoint("CENTER", frame.background, "CENTER", 0, -1);
179 frame.rez = frame:CreateTexture(nil, "OVERLAY");
180 frame.rez:SetPoint("TOPLEFT", frame.background, "CENTER", -12, 12);
181 frame.rez:SetPoint("BOTTOMRIGHT", frame.background, "CENTER", 12, -12);
182 frame.rez:SetTexture("Interface\\RaidFrame\\Raid-Icon-Rez");
185 setupIndicators(frame);
187 frame:SetScript("OnShow", frameShow);
188 frame:SetScript("OnHide", frameHide);
189 frame:SetScript("OnEvent", unitEvent);
191 secure:RegisterForClicks("AnyDown");
192 for attr, val in pairs(attributes) do
193 secure:SetAttribute(attr, val);
195 -- rest give target and menu
196 secure:SetAttribute("*type1", "target");
197 secure:SetAttribute("*type2", "togglemenu");
200 -- vehicle toggle from Shadowed Unit Frames
201 local vehicletoggle = [=[
202 local unit = self:GetAttribute("unit");
203 if unit and newstate == "vehicle" and not UnitTargetsVehicleInRaidUI(unit) then
204 self:SetAttribute("toggleForVehicle", false);
206 self:SetAttribute("toggleForVehicle", true);
210 local function initializeParty(parent)
211 local secure = CreateFrame("Button", "OmaPartySecure0", parent, inheritedFrames);
212 local frame = CreateFrame("Frame", "OmaParty0", parent);
213 local unit = "player";
214 secure:SetPoint("TOPLEFT", parent, "TOPLEFT");
215 frame:SetPoint("TOPLEFT", parent, "TOPLEFT");
216 setupFrame(frame, secure, unit);
217 RegisterStateDriver(frame, "visibility", "[@player,group:raid] hide; show");
218 RegisterStateDriver(secure, "visibility", "[@player,group:raid] hide; show");
219 RegisterStateDriver(secure, "vehicleui", "[vehicleui] vehicle; no");
220 secure:SetAttribute("_onstate-vehicleui", vehicletoggle);
221 party[0] = {secure=secure, frame=frame};
223 local secure = CreateFrame("Button", "OmaPartySecure"..i, parent, inheritedFrames);
224 local frame = CreateFrame("Frame", "OmaParty"..i, parent);
225 local unit = "party"..i;
226 secure:SetPoint("TOPLEFT", party[i-1].secure, "TOPRIGHT");
227 frame:SetPoint("TOPLEFT", party[i-1].frame, "TOPRIGHT");
228 setupFrame(frame, secure, unit);
229 local visible = format("[@%s,exists,group:raid] hide; [@%s,exists] show; hide", unit, unit);
230 local vehicle = format("[@%s,unithasvehicleui] vehicle; no", unit);
231 RegisterStateDriver(frame, "visibility", visible);
232 RegisterStateDriver(secure, "visibility", visible);
233 RegisterStateDriver(secure, "vehicleui", vehicle);
234 secure:SetAttribute("_onstate-vehicleui", vehicletoggle);
235 party[i] = {secure=secure, frame=frame};
239 local function initializeRaid(parent)
240 local secure = CreateFrame("Button", "OmaRaidSecure1", parent, inheritedFrames);
241 local frame = CreateFrame("Frame", "OmaRaid1", parent);
242 local unit = "raid1";
243 secure:SetPoint("TOPLEFT", parent, "TOPLEFT");
244 frame:SetPoint("TOPLEFT", parent, "TOPLEFT");
245 setupFrame(frame, secure, unit);
246 RegisterUnitWatch(frame);
247 RegisterUnitWatch(secure);
248 local vehicle = format("[@%s,unithasvehicleui] vehicle; no", unit);
249 RegisterStateDriver(secure, "vehicleui", vehicle);
250 secure:SetAttribute("_onstate-vehicleui", vehicletoggle);
251 raid[1] = {secure=secure, frame=frame};
254 local secure = CreateFrame("Button", "OmaRaidSecure"..i, parent, inheritedFrames);
255 local frame = CreateFrame("Frame", "OmaRaid"..i, parent);
256 local unit = "raid"..i;
257 secure:SetPoint("TOPLEFT", raid[i-5].secure, "BOTTOMLEFT");
258 frame:SetPoint("TOPLEFT", raid[i-5].frame, "BOTTOMLEFT");
259 setupFrame(frame, secure, unit);
260 RegisterUnitWatch(frame);
261 RegisterUnitWatch(secure);
262 local vehicle = format("[@%s,unithasvehicleui] vehicle; no", unit);
263 RegisterStateDriver(secure, "vehicleui", vehicle);
264 secure:SetAttribute("_onstate-vehicleui", vehicletoggle);
265 raid[i] = {secure=secure, frame=frame};
270 local secure = CreateFrame("Button", "OmaRaidSecure"..i, parent, inheritedFrames);
271 local frame = CreateFrame("Frame", "OmaRaid"..i, parent);
272 local unit = "raid"..i;
273 secure:SetPoint("TOPLEFT", raid[i-1].secure, "TOPRIGHT");
274 frame:SetPoint("TOPLEFT", raid[i-1].frame, "TOPRIGHT");
275 setupFrame(frame, secure, unit);
276 RegisterUnitWatch(frame);
277 RegisterUnitWatch(secure);
278 local vehicle = format("[@%s,unithasvehicleui] vehicle; no", unit);
279 RegisterStateDriver(secure, "vehicleui", vehicle);
280 secure:SetAttribute("_onstate-vehicleui", vehicletoggle);
281 raid[i] = {secure=secure, frame=frame};
286 local function initialize()
287 CFrame:SetPoint("CENTER", nil, "CENTER", anchorX, anchorY);
288 CFrame:SetHeight((height+2)*8);
289 CFrame:SetWidth((width+2)*5+1);
290 initializeParty(CFrame);
291 initializeRaid(CFrame);
294 local function loadCharSettings()
295 width, height = Settings.Character.Width, Settings.Character.Height;
296 anchorX, anchorY = Settings.Character.AnchorX, Settings.Character.AnchorY;
297 attributes = Settings.Character.Clickheal;
298 positions = Settings.Character.Positions;
301 CFrame:RegisterEvent("ADDON_LOADED");
302 CFrame:RegisterEvent("PLAYER_LOGIN");
303 CFrame:SetScript("OnEvent", function(self, event)
304 if event == "PLAYER_LOGIN" then
306 elseif event == "ADDON_LOADED" then
309 OmaRFEvents.LoadChar();
310 OmaRFIndicators.LoadChar();