3 local unpack, pairs = unpack, pairs;
4 local format = string.format;
5 local UnitHealthMax, UnitPowerMax = UnitHealthMax, UnitPowerMax;
6 local CreateFrame, RegisterStateDriver, RegisterUnitWatch = CreateFrame, RegisterStateDriver, RegisterUnitWatch;
7 local STANDARD_TEXT_FONT = STANDARD_TEXT_FONT;
8 local GameTooltip = nil;
9 local GameTooltip_SetDefaultAnchor = nil;
11 local registerEvents = OmaUFEvents.RegisterEvents;
12 local unitEvent = OmaUFEvents.UnitEvent;
14 local Settings = OmaUFSettings;
15 local indSize = Settings.IndSize;
16 local baseColor = Settings.BaseColor;
17 local bgColor = Settings.BgColor;
18 local healthColor = Settings.HealthColor;
19 local shieldColor = Settings.ShieldColor;
20 local shieldhlColor = Settings.ShieldhlColor;
21 local healpredColor = Settings.HealpredColor;
22 local healabsorbColor = Settings.HealabsorbColor;
23 -- placeholders with visible values when error happens
24 local width, height = 10, 10;
25 local anchorX, anchorY = 10, 10;
26 local attributes = {};
28 local UnitFrames = CreateFrame("Frame", "OmaUnitFrames");
29 local inheritedFrames = "SecureUnitButtonTemplate,SecureHandlerStateTemplate";
33 "UNIT_ENTERED_VEHICLE",
34 "UNIT_EXITED_VEHICLE",
36 "PLAYER_ROLES_ASSIGNED",
37 "PLAYER_ENTERING_WORLD",
39 "PLAYER_REGEN_DISABLED",
40 "PLAYER_REGEN_ENABLED",
41 "PLAYER_UPDATE_RESTING",
44 "UNIT_ENTERED_VEHICLE",
45 "UNIT_EXITED_VEHICLE",
48 "GROUP_ROSTER_UPDATE",
49 "PLAYER_ROLES_ASSIGNED",
50 "PLAYER_ENTERING_WORLD",
51 "PLAYER_TARGET_CHANGED",
58 local function frameShow(frame)
59 for _, ev in pairs(events[frame.unit]) do
60 frame:RegisterEvent(ev);
62 registerEvents(frame);
63 unitEvent(frame, "UPDATE_ALL_BARS");
66 local function frameHide(frame)
67 frame:UnregisterAllEvents();
70 local function showTooltip(frame)
71 GameTooltip_SetDefaultAnchor(GameTooltip, PlayerFrame);
72 GameTooltip:SetUnit(frame:GetAttribute("unit"));
75 local function hideTooltip(frame)
76 GameTooltip:FadeOut();
79 local function setupFrame(frame, secure, unit)
80 secure:SetAttribute("unit", unit);
81 frame:SetAttribute("unit", unit);
83 frame.displayed = unit;
84 -- hide frame to get initial frameShow call
86 if unit == "player" then
87 frame.vehicle = "vehicle";
89 frame.vehicle = unit.."pet";
92 frame.base = frame:CreateTexture(nil, "BACKGROUND");
93 frame.base:SetAllPoints();
94 frame.base:SetColorTexture(1, 1, 1);
95 frame.base:SetVertexColor(unpack(baseColor));
96 frame.healthback = frame:CreateTexture(nil, "BACKGROUND", nil, 1);
97 frame.healthback:SetPoint("TOPLEFT", frame, "TOPLEFT", 1, -1);
98 frame.healthback:SetPoint("BOTTOMRIGHT", frame, "RIGHT", -1, -5);
99 frame.healthback:SetTexture("Interface\\RaidFrame\\Raid-Bar-Hp-Fill");
100 frame.healthback:SetVertexColor(unpack(bgColor));
101 frame.health = frame:CreateTexture(nil, "BORDER");
102 frame.health:SetTexture("Interface\\RaidFrame\\Raid-Bar-Hp-Fill");
103 frame.health:SetPoint("TOPLEFT", frame.healthback, "TOPLEFT");
104 frame.health:SetPoint("BOTTOMLEFT", frame.healthback, "BOTTOMLEFT");
105 frame.health:SetVertexColor(unpack(healthColor));
106 frame.health:SetWidth(width);
107 frame.health.max = UnitHealthMax(unit);
108 frame.healthText = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlightLarge");
109 frame.healthText:SetPoint("RIGHT", frame.healthback, "RIGHT", -2, 0);
110 frame.healthText:Hide();
111 frame.manaback = frame:CreateTexture(nil, "BACKGROUND", nil, 1);
112 frame.manaback:SetPoint("TOPLEFT", frame, "LEFT", 1, -5);
113 frame.manaback:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -1, 1);
114 frame.manaback:SetTexture("Interface\\RaidFrame\\Raid-Bar-Hp-Fill");
115 frame.manaback:SetVertexColor(unpack(bgColor));
116 frame.mana = frame:CreateTexture(nil, "BORDER");
117 frame.mana:SetPoint("TOPLEFT", frame.manaback, "TOPLEFT");
118 frame.mana:SetPoint("BOTTOMLEFT", frame.manaback, "BOTTOMLEFT");
119 frame.mana:SetTexture("Interface\\RaidFrame\\Raid-Bar-Hp-Fill");
120 frame.mana:SetWidth(width);
121 frame.mana.max = UnitPowerMax(unit);
122 frame.manaText = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlight");
123 frame.manaText:SetPoint("RIGHT", frame.manaback, "RIGHT", -2, 0);
124 frame.manaText:Hide();
125 frame.shield = frame:CreateTexture(nil, "BORDER");
126 frame.shield:SetPoint("TOPLEFT", frame.health, "TOPRIGHT");
127 frame.shield:SetPoint("BOTTOMLEFT", frame.health, "BOTTOMRIGHT");
128 frame.shield:SetTexture("Interface\\RaidFrame\\Shield-Fill");
129 frame.shield:SetVertexColor(unpack(shieldColor));
131 frame.shieldhl = frame:CreateTexture(nil, "ARTWORK");
132 frame.shieldhl:SetPoint("TOPLEFT", frame.healthback, "TOPRIGHT", -1, 0);
133 frame.shieldhl:SetPoint("BOTTOMRIGHT", frame.healthback, "BOTTOMRIGHT", 1, 0);
134 frame.shieldhl:SetColorTexture(unpack(shieldhlColor));
135 frame.shieldhl:Hide();
136 frame.healpred = frame:CreateTexture(nil, "ARTWORK");
137 frame.healpred:SetPoint("TOPLEFT", frame.health, "TOPRIGHT");
138 frame.healpred:SetPoint("BOTTOMLEFT", frame.health, "BOTTOMRIGHT");
139 frame.healpred:SetColorTexture(unpack(healpredColor));
140 frame.healpred:Hide();
141 frame.healabsorb = frame:CreateTexture(nil, "ARTWORK");
142 frame.healabsorb:SetPoint("TOPRIGHT", frame.health, "TOPRIGHT");
143 frame.healabsorb:SetPoint("BOTTOMRIGHT", frame.health, "BOTTOMRIGHT");
144 frame.healabsorb:SetColorTexture(unpack(healabsorbColor));
145 frame.healabsorb:Hide();
146 frame.overlay = frame:CreateTexture(nil, "ARTWORK", nil, 1);
147 frame.overlay:SetPoint("TOPLEFT", frame.healthback, "TOPLEFT");
148 frame.overlay:SetPoint("BOTTOMRIGHT", frame.healthback, "BOTTOMRIGHT");
149 frame.overlay:SetColorTexture(1, 1, 1);
150 frame.overlay:Hide();
151 frame.role = frame:CreateTexture(nil, "OVERLAY");
152 frame.role:SetPoint("TOPLEFT", frame.healthback, "TOPRIGHT", -8, 8);
153 frame.role:SetPoint("BOTTOMRIGHT", frame.healthback, "TOPRIGHT", 8, -8);
154 frame.role:SetTexture("Interface\\LFGFRAME\\UI-LFG-ICON-PORTRAITROLES");
156 frame.status = frame:CreateTexture(nil, "OVERLAY");
157 frame.status:SetPoint("TOPLEFT", frame.manaback, "BOTTOMLEFT", -8, 8);
158 frame.status:SetPoint("BOTTOMRIGHT", frame.manaback, "BOTTOMLEFT", 8, -8);
159 frame.status:SetTexture("Interface\\CHARACTERFRAME\\UI-StateIcon");
161 frame.pvp = frame:CreateTexture(nil, "OVERLAY");
162 frame.pvp:SetPoint("TOPLEFT", frame.manaback, "BOTTOMLEFT", 8, 6);
163 frame.pvp:SetPoint("BOTTOMRIGHT", frame.manaback, "BOTTOMLEFT", 32, -18);
164 frame.pvp:SetTexture("Interface\\TARGETINGFRAME\\UI-PVP-Horde");
166 frame.leader = frame:CreateTexture(nil, "OVERLAY");
167 frame.leader:SetPoint("TOPLEFT", frame.healthback, "TOPLEFT", -6, 6);
168 frame.leader:SetPoint("BOTTOMRIGHT", frame.healthback, "TOPLEFT", 6, -6);
170 frame.name = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlightLarge");
171 frame.name:SetPoint("LEFT", frame.healthback, "LEFT", 2, 1);
172 frame.level = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
173 frame.level:SetPoint("LEFT", frame.manaback, "LEFT", 2, 1);
175 frame:SetScript("OnShow", frameShow);
176 frame:SetScript("OnHide", frameHide);
177 frame:SetScript("OnEvent", unitEvent);
178 -- let other addons hook these to anchor tooltip elsewhere
179 GameTooltip = _G["GameTooltip"];
180 GameTooltip_SetDefaultAnchor = _G["GameTooltip_SetDefaultAnchor"];
181 secure:SetScript("OnEnter", showTooltip);
182 secure:SetScript("OnLeave", hideTooltip);
184 secure:RegisterForClicks("AnyDown");
185 for attr, val in pairs(attributes) do
186 secure:SetAttribute(attr, val);
188 -- rest give target and menu
189 secure:SetAttribute("*type1", "target");
190 secure:SetAttribute("*type2", "togglemenu");
193 -- vehicle toggle from Shadowed Unit Frames
194 local vehicletoggle = [=[
195 local unit = self:GetAttribute("unit");
196 if unit and newstate == "vehicle" and not UnitTargetsVehicleInRaidUI(unit) then
197 self:SetAttribute("toggleForVehicle", false);
199 self:SetAttribute("toggleForVehicle", true);
203 local function initializePlayer(parent)
204 local secure = CreateFrame("Button", "OmaPlayerSecure", parent, inheritedFrames);
205 local frame = CreateFrame("Frame", "OmaPlayer", parent);
206 local unit = "player";
207 secure:SetPoint("CENTER", parent, "CENTER", -320, -100);
208 secure:SetWidth(width+2);
209 secure:SetHeight(height+2);
210 frame:SetPoint("CENTER", parent, "CENTER", -320, -100);
211 frame:SetWidth(width+2);
212 frame:SetHeight(height+2);
213 setupFrame(frame, secure, unit);
214 RegisterUnitWatch(frame);
215 RegisterUnitWatch(secure);
216 RegisterStateDriver(secure, "vehicleui", "[vehicleui] vehicle; no");
217 secure:SetAttribute("_onstate-vehicleui", vehicletoggle);
220 local function initializeTarget(parent)
221 local secure = CreateFrame("Button", "OmaTargetSecure", parent, inheritedFrames);
222 local frame = CreateFrame("Frame", "OmaTarget", parent);
223 local unit = "target";
224 secure:SetPoint("CENTER", parent, "CENTER", 320, -100);
225 secure:SetWidth(width+2);
226 secure:SetHeight(height+2);
227 frame:SetPoint("CENTER", parent, "CENTER", 320, -100);
228 frame:SetWidth(width+2);
229 frame:SetHeight(height+2);
230 setupFrame(frame, secure, unit);
231 -- TODO target frame buffs/debuffs
232 RegisterUnitWatch(frame);
233 RegisterUnitWatch(secure);
234 RegisterStateDriver(secure, "vehicleui", "[vehicleui] vehicle; no");
235 secure:SetAttribute("_onstate-vehicleui", vehicletoggle);
238 local function initialize()
239 initializePlayer(UIParent);
240 initializeTarget(UIParent);
243 local function loadCharSettings()
244 width, height = Settings.Character.Width, Settings.Character.Height;
245 anchorX, anchorY = Settings.Character.AnchorX, Settings.Character.AnchorY;
246 attributes = Settings.Character.Clickheal;
249 UnitFrames:RegisterEvent("ADDON_LOADED");
250 UnitFrames:RegisterEvent("PLAYER_LOGIN");
251 UnitFrames:SetScript("OnEvent", function(self, event)
252 if event == "PLAYER_LOGIN" then
254 elseif event == "ADDON_LOADED" then
257 OmaUFEvents.LoadChar();