2 -- 2019 Aleksi Blinnikka
5 local format = string.format;
6 local CreateFrame = CreateFrame;
7 local CTimerAfter = C_Timer.After;
9 local guids = addon.FrameGuids;
11 local function showTooltip(frame)
12 GameTooltip_SetDefaultAnchor(GameTooltip, frame);
13 GameTooltip:SetUnit(frame:GetAttribute("unit"));
15 local function hideTooltip(frame)
16 if GameTooltip:IsOwned(frame) then GameTooltip:FadeOut() end
19 local barTexture = "Interface\\AddOns\\kehys\\images\\minimalist";
21 function addon.NewRaidFrame(parent, width, height, unit, attributes,
22 update, event, onshow)
23 assert(type(parent) == "table", "Frame creation missing parent!");
24 assert(type(width) == "number", "Frame creation missing width!");
25 assert(type(height) == "number", "Frame creation missing height!");
26 assert(type(unit) == "string", "Frame creation missing unit!");
27 assert(type(update) == "function",
28 "Frame creation missing update function!");
29 assert(type(event) == "function",
30 "Frame creation missing event function!");
31 assert(type(onshow) == "function",
32 "Frame creation missing onshow function!");
33 if type(attributes) ~= "table" then
37 local f = CreateFrame(
39 format("kehys%i", frameid),
41 "SecureUnitButtonTemplate,SecureHandlerStateTemplate"
43 frameid = frameid + 1;
44 f:Hide(); -- hide frame to have an initial frame:OnShow call
47 f.barwidth = width - 2; -- 1px padding on both sides
48 f:SetAttribute("unit", unit);
51 f.vehicle = unit == "player" and "vehicle" or format("%spet", unit);
52 f.prev = {} -- values stored from previous update
53 f.alert = {}; -- alerting auras
54 f.heal = {}; -- high healing auras
55 f.tankcd = {}; -- tank CD auras
56 f.stacks = {}; -- stacking aura tracking
57 f.buff1 = {}; -- custom buff indicator 1
58 f.buff2 = {}; -- custom buff indicator 2
59 f.incoming = {}; -- incoming ability indicator
60 f.rolename = nil; -- TANK, HEALER, DAMAGER, NONE
61 f.isdk = nil; -- DK death strike tracker for DK tanks
64 -- set up periodic updates
65 updaters[f] = function()
67 CTimerAfter(0.1, updaters[f]);
72 f:SetScript("OnShow", function()
77 f:SetScript("OnHide", function()
78 f:UnregisterAllEvents();
85 f:SetScript("OnEvent", event);
86 f:SetScript("OnEnter", showTooltip);
87 f:SetScript("OnLeave", hideTooltip);
89 f:RegisterForClicks("AnyDown");
90 for attr, val in pairs(attributes) do
91 f:SetAttribute(attr, val);
93 -- rest give target and menu
94 f:SetAttribute("*type1", "target");
95 f:SetAttribute("*type2", "togglemenu");
98 f.base = f:CreateTexture(nil, "BACKGROUND");
99 f.base:SetAllPoints();
100 f.base:SetColorTexture(1, 1, 1);
101 f.base:SetVertexColor(unpack(addon.Colors.Base));
102 f.glow = f:CreateTexture(nil, "BACKGROUND", nil, 1);
103 f.glow:SetAllPoints();
104 f.glow:SetColorTexture(1, 1, 1);
105 f.glow:SetVertexColor(unpack(addon.Colors.Glow));
106 f.background = f:CreateTexture(nil, "BACKGROUND", nil, 2);
107 f.background:SetPoint("TOPLEFT", f, "TOPLEFT", 1, -1);
108 f.background:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -1, 1);
109 f.background:SetColorTexture(0.7, 0.7, 0.7);
110 f.health = f:CreateTexture(nil, "BORDER");
111 f.health:SetPoint("TOPLEFT", f.background, "TOPLEFT");
112 f.health:SetPoint("BOTTOMLEFT", f.background, "BOTTOMLEFT");
113 f.health:SetTexture(barTexture);
114 f.health:SetVertexColor(0.3, 0.3, 0.3);
116 f.shield = f:CreateTexture(nil, "BORDER");
117 f.shield:SetPoint("TOPLEFT", f.health, "TOPRIGHT");
118 f.shield:SetPoint("BOTTOMLEFT", f.health, "BOTTOMRIGHT");
119 f.shield:SetTexture(barTexture);
120 f.shield:SetVertexColor(0, 0.7, 1);
122 f.shieldhl = f:CreateTexture(nil, "ARTWORK");
123 f.shieldhl:SetPoint("TOPLEFT", f, "TOPRIGHT", -2, 0);
124 f.shieldhl:SetPoint("BOTTOMRIGHT");
125 f.shieldhl:SetColorTexture(0.5, 0.8, 1);
127 f.healpred = f:CreateTexture(nil, "ARTWORK");
128 f.healpred:SetPoint("TOPLEFT", f.health, "TOPRIGHT");
129 f.healpred:SetPoint("BOTTOMLEFT", f.health, "BOTTOMRIGHT");
130 f.healpred:SetColorTexture(0.5, 0.6, 0.5);
132 f.healabsorb = f:CreateTexture(nil, "ARTWORK");
133 f.healabsorb:SetPoint("TOPRIGHT", f.health, "TOPRIGHT");
134 f.healabsorb:SetPoint("BOTTOMRIGHT", f.health, "BOTTOMRIGHT");
135 f.healabsorb:SetColorTexture(0.1, 0.1, 0.1);
137 f.overlay = f:CreateTexture(nil, "ARTWORK", nil, 1);
138 f.overlay:SetPoint("TOPLEFT", f.background, "TOPLEFT");
139 f.overlay:SetPoint("BOTTOMRIGHT", f.background, "BOTTOMRIGHT");
140 f.overlay:SetColorTexture(1, 1, 1);
142 f.bottomwarn = f:CreateTexture(nil, "ARTWORK", nil, 1);
143 f.bottomwarn:SetPoint("TOPLEFT", f.background, "BOTTOMLEFT", 16, 5);
144 f.bottomwarn:SetPoint("BOTTOMRIGHT", f.background, "BOTTOMRIGHT", -16, 1);
145 f.bottomwarn:SetColorTexture(1, 0.3, 0.1, 0.66);
147 f.role = f:CreateTexture(nil, "ARTWORK", nil, 2);
148 f.role:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -3, 3);
149 f.role:SetPoint("TOPLEFT", f, "BOTTOMRIGHT", -15, 15);
150 f.role:SetTexture("Interface\\LFGFRAME\\LFGROLE");
152 f.name = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
153 f.name:SetPoint("CENTER", f, "CENTER", 0, 11);
154 f.text = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
155 f.text:SetPoint("CENTER", f, "CENTER", 0, -1);
156 f.text:SetFont(STANDARD_TEXT_FONT, 13);
158 f.stack = f:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall");
159 f.stack:SetPoint("BOTTOMLEFT", f.background, "BOTTOMLEFT");
161 f.ready = f:CreateTexture(nil, "OVERLAY");
162 f.ready:SetPoint("TOPLEFT", f, "BOTTOMLEFT", 1, 15);
163 f.ready:SetPoint("BOTTOMRIGHT", f, "BOTTOMLEFT", 15, 1);
165 f.buffind1 = f:CreateTexture(nil, "OVERLAY");
166 f.buffind1:SetPoint("TOPRIGHT", f.background, "TOPRIGHT", -1, -1);
167 f.buffind1:SetWidth(6);
168 f.buffind1:SetHeight(6);
169 f.buffind1:SetColorTexture(0.8, 0.1, 0.1);
171 f.buffind2 = f:CreateTexture(nil, "OVERLAY");
172 f.buffind2:SetPoint("TOPLEFT", f.background, "TOPLEFT", 1, -1);
173 f.buffind2:SetWidth(4);
174 f.buffind2:SetHeight(4);
175 f.buffind2:SetColorTexture(0.8, 0.7, 0.1);
177 f.defensive = f:CreateTexture(nil, "OVERLAY", nil, 1);
178 f.defensive:SetPoint("TOPLEFT", f.background, "TOPLEFT", 1, -1);
179 f.defensive:SetWidth(6);
180 f.defensive:SetHeight(6);
181 f.defensive:SetColorTexture(1, 0.3, 0);
183 f.targeticon = f:CreateTexture(nil, "OVERLAY");
184 f.targeticon:SetPoint("CENTER", f, "TOP", 0, -1);
185 f.targeticon:SetWidth(12);
186 f.targeticon:SetHeight(12);
187 f.targeticon:SetTexture("Interface\\TARGETINGFRAME\\UI-RaidTargetingIcons");