3 local unpack, pairs = unpack, pairs;
4 local format = string.format;
5 local UnitExists, ShowBossFrameWhenUninteractable = UnitExists, ShowBossFrameWhenUninteractable;
6 local GameTooltip = GameTooltip;
7 local GameTooltip_SetDefaultAnchor = GameTooltip_SetDefaultAnchor;
9 local registerUnitEvents = OmaUFEvents.RegisterUnitEvents;
10 local registerCastEvents = OmaUFCastBar.RegisterCastEvents;
11 local unregisterCastEvents = OmaUFCastBar.UnregisterCastEvents;
12 local unitEvent = OmaUFEvents.UnitEvent;
14 local Settings = OmaUFSettings;
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 local width, height = Settings.Boss.Width, Settings.Boss.Height;
23 local anchorX, anchorY = Settings.Boss.AnchorX, Settings.Boss.AnchorY;
24 -- placeholders with visible values when error happens
25 local attributes = {};
27 local inheritedFrames = "SecureUnitButtonTemplate,SecureHandlerStateTemplate";
28 local barTexture = "Interface\\AddOns\\OmaRF\\images\\minimalist";
30 local function frameShow(frame)
31 frame:RegisterEvent("PLAYER_ENTERING_WORLD");
32 frame:RegisterEvent("INSTANCE_ENCOUNTER_ENGAGE_UNIT");
33 frame:RegisterEvent("UNIT_TARGETABLE_CHANGED");
34 frame:RegisterUnitEvent("UNIT_LEVEL", frame.unit);
35 registerUnitEvents(frame);
36 registerCastEvents(frame.castbar);
37 unitEvent(frame, "UPDATE_ALL_BARS");
40 local function frameHide(frame)
41 frame:UnregisterAllEvents();
42 unregisterCastEvents(frame.castbar);
45 local function showTooltip(secure)
46 GameTooltip_SetDefaultAnchor(GameTooltip, secure);
47 GameTooltip:SetUnit(secure:GetAttribute("unit"));
50 local function hideTooltip(secure)
51 GameTooltip:FadeOut();
54 function OmaUnitFrames.UpdateBossTooltips()
55 GameTooltip = _G["GameTooltip"];
56 GameTooltip_SetDefaultAnchor = _G["GameTooltip_SetDefaultAnchor"];
59 local function bossEvent(self)
60 -- INSTANCE_ENCOUNTER_ENGAGE_UNIT only
61 for unit, frame in pairs(self.frames) do
62 if UnitExists(unit) or ShowBossFrameWhenUninteractable(unit) then
70 local function createFrame(framename, securename, parent, unit, anchorX, anchorY)
71 local secure = CreateFrame("Button", securename, parent, inheritedFrames);
72 local frame = CreateFrame("Frame", framename, parent);
73 secure:SetPoint("CENTER", parent, "CENTER", anchorX, anchorY);
74 secure:SetAttribute("unit", unit);
75 frame:SetPoint("CENTER", parent, "CENTER", anchorX, anchorY);
76 frame:SetAttribute("unit", unit);
78 frame.displayed = unit;
79 -- hide frame to get initial frameShow call
82 secure:SetWidth(width+2);
83 secure:SetHeight(height+2);
84 frame:SetWidth(width+2);
85 frame:SetHeight(height+2);
87 frame.base = frame:CreateTexture(nil, "BACKGROUND");
88 frame.base:SetAllPoints();
89 frame.base:SetColorTexture(1, 1, 1);
90 frame.base:SetVertexColor(unpack(baseColor));
91 frame.healthback = frame:CreateTexture(nil, "BACKGROUND", nil, 1);
92 frame.healthback:SetPoint("TOPLEFT", frame, "TOPLEFT", 1, -1);
93 frame.healthback:SetPoint("BOTTOMRIGHT", frame, "RIGHT", -1, -5);
94 frame.healthback:SetTexture(barTexture);
95 frame.healthback:SetVertexColor(unpack(bgColor));
96 frame.health = frame:CreateTexture(nil, "BORDER");
97 frame.health:SetPoint("TOPLEFT", frame.healthback, "TOPLEFT");
98 frame.health:SetPoint("BOTTOMLEFT", frame.healthback, "BOTTOMLEFT");
99 frame.health:SetTexture(barTexture);
100 frame.health:SetVertexColor(unpack(healthColor));
101 frame.healthText = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlight");
102 frame.healthText:SetPoint("RIGHT", frame.healthback, "RIGHT", -2, 1);
103 frame.healthText.percent = true;
104 frame.manaback = frame:CreateTexture(nil, "BACKGROUND", nil, 1);
105 frame.manaback:SetPoint("TOPLEFT", frame, "LEFT", 1, -5);
106 frame.manaback:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -1, 1);
107 frame.manaback:SetTexture(barTexture);
108 frame.manaback:SetVertexColor(unpack(bgColor));
109 frame.mana = frame:CreateTexture(nil, "BORDER");
110 frame.mana:SetPoint("TOPLEFT", frame.manaback, "TOPLEFT");
111 frame.mana:SetPoint("BOTTOMLEFT", frame.manaback, "BOTTOMLEFT");
112 frame.mana:SetTexture(barTexture);
113 frame.manaText = frame:CreateFontString(nil, "ARTWORK", "GameFontWhiteTiny");
114 frame.manaText:SetPoint("RIGHT", frame.manaback, "RIGHT", -2, 0);
115 frame.manaText:Hide();
116 frame.shield = frame:CreateTexture(nil, "BORDER");
117 frame.shield:SetPoint("TOPLEFT", frame.health, "TOPRIGHT");
118 frame.shield:SetPoint("BOTTOMLEFT", frame.health, "BOTTOMRIGHT");
119 frame.shield:SetTexture(barTexture);
120 frame.shield:SetVertexColor(unpack(shieldColor));
122 frame.shieldhl = frame:CreateTexture(nil, "ARTWORK");
123 frame.shieldhl:SetPoint("TOPLEFT", frame.healthback, "TOPRIGHT", -1, 0);
124 frame.shieldhl:SetPoint("BOTTOMRIGHT", frame.healthback, "BOTTOMRIGHT", 1, 0);
125 frame.shieldhl:SetColorTexture(unpack(shieldhlColor));
126 frame.shieldhl:Hide();
127 frame.healabsorb = frame:CreateTexture(nil, "ARTWORK");
128 frame.healabsorb:SetPoint("TOPRIGHT", frame.health, "TOPRIGHT");
129 frame.healabsorb:SetPoint("BOTTOMRIGHT", frame.health, "BOTTOMRIGHT");
130 frame.healabsorb:SetColorTexture(unpack(healabsorbColor));
131 frame.healabsorb:Hide();
132 frame.name = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
133 frame.name:SetPoint("LEFT", frame.healthback, "LEFT", 2, 1);
134 frame.name.count = 10;
135 frame.level = frame:CreateFontString(nil, "OVERLAY", "GameFontWhiteTiny");
136 frame.level:SetPoint("LEFT", frame.manaback, "LEFT", 2, 0);
137 frame.targeticon = frame:CreateTexture(nil, "OVERLAY");
138 frame.targeticon:SetPoint("CENTER", frame.healthback, "TOP");
139 frame.targeticon:SetWidth(16);
140 frame.targeticon:SetHeight(16);
141 frame.targeticon:SetTexture("Interface\\TARGETINGFRAME\\UI-RaidTargetingIcons");
142 frame.targeticon:Hide();
143 frame.castbar = OmaUFCastBar.CreateCastBar(frame, unit, -height-24);
145 frame:SetScript("OnShow", frameShow);
146 frame:SetScript("OnHide", frameHide);
147 frame:SetScript("OnEvent", unitEvent);
148 secure:SetScript("OnEnter", showTooltip);
149 secure:SetScript("OnLeave", hideTooltip);
151 -- TODO other set of click cast on boss frames possibly
152 --secure:RegisterForClicks("AnyDown");
153 --for attr, val in pairs(attributes) do
154 -- secure:SetAttribute(attr, val);
156 -- rest give target and menu
157 secure:SetAttribute("*type1", "target");
158 secure:SetAttribute("*type2", "togglemenu");
159 -- TODO dunno how to update frame securely without hiding frame too often
160 -- ShowBossFrameWhenUninteractable not in restricted environment
161 -- this way all frames are clickable, but there's some invisible clickframes
162 RegisterStateDriver(secure, "visibility", "[@boss1,exists][@boss2,exists][@boss3,exists][@boss4,exists][@boss5,exists] show; hide");
166 function OmaUnitFrames.InitializeBoss(parent)
167 attributes = Settings.Character.Clickheal;
169 -- hidden frame to handle hiding insecure boss frames
170 local bossHeader = CreateFrame("Frame");
171 bossHeader.frames = {};
172 bossHeader:SetScript("OnEvent", bossEvent);
173 bossHeader:RegisterEvent("INSTANCE_ENCOUNTER_ENGAGE_UNIT");
174 bossHeader.frames["boss1"] = createFrame("OmaBoss1", "OmaBossSecure1", parent, "boss1", anchorX, anchorY);
175 for i = 2,MAX_BOSS_FRAMES do
176 bossHeader.frames["boss"..i] = createFrame("OmaBoss"..i, "OmaBossSecure"..i, _G["OmaBossSecure"..(i-1)], "boss"..i, 0, -height-26);
178 bossEvent(bossHeader);
180 -- Arena frames are in the same spot
181 --[[createFrame("OmaArena1", "OmaArenaSecure1", parent, "arena1", anchorX, anchorY);
182 -- MAX_ARENA_ENEMIES from AddOns/Blizzard_ArenaUI/Blizzard_ArenaUI.lua not available
183 -- as the addon is not loaded yet, update manually if it changes
185 createFrame("OmaArena"..i, "OmaArenaSecure"..i, _G["OmaArena"..(i-1)], "arena"..i, 0, -height-26);