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
61 -- set up periodic updates
62 updaters[f] = function()
64 CTimerAfter(0.1, updaters[f]);
69 f:SetScript("OnShow", function()
74 f:SetScript("OnHide", function()
75 f:UnregisterAllEvents();
82 f:SetScript("OnEvent", event);
83 f:SetScript("OnEnter", showTooltip);
84 f:SetScript("OnLeave", hideTooltip);
86 f:RegisterForClicks("AnyDown");
87 for attr, val in pairs(attributes) do
88 f:SetAttribute(attr, val);
90 -- rest give target and menu
91 f:SetAttribute("*type1", "target");
92 f:SetAttribute("*type2", "togglemenu");
95 f.base = f:CreateTexture(nil, "BACKGROUND");
96 f.base:SetAllPoints();
97 f.base:SetColorTexture(1, 1, 1);
98 f.base:SetVertexColor(unpack(addon.Colors.Base));
99 f.glow = f:CreateTexture(nil, "BACKGROUND", nil, 1);
100 f.glow:SetAllPoints();
101 f.glow:SetColorTexture(1, 1, 1);
102 f.glow:SetVertexColor(unpack(addon.Colors.Glow));
103 f.background = f:CreateTexture(nil, "BACKGROUND", nil, 2);
104 f.background:SetPoint("TOPLEFT", f, "TOPLEFT", 1, -1);
105 f.background:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -1, 1);
106 f.background:SetColorTexture(0.7, 0.7, 0.7);
107 f.health = f:CreateTexture(nil, "BORDER");
108 f.health:SetPoint("TOPLEFT", f.background, "TOPLEFT");
109 f.health:SetPoint("BOTTOMLEFT", f.background, "BOTTOMLEFT");
110 f.health:SetTexture(barTexture);
111 f.health:SetVertexColor(0.3, 0.3, 0.3);
113 f.shield = f:CreateTexture(nil, "BORDER");
114 f.shield:SetPoint("TOPLEFT", f.health, "TOPRIGHT");
115 f.shield:SetPoint("BOTTOMLEFT", f.health, "BOTTOMRIGHT");
116 f.shield:SetTexture(barTexture);
117 f.shield:SetVertexColor(0, 0.7, 1);
119 f.shieldhl = f:CreateTexture(nil, "ARTWORK");
120 f.shieldhl:SetPoint("TOPLEFT", f, "TOPRIGHT", -2, 0);
121 f.shieldhl:SetPoint("BOTTOMRIGHT");
122 f.shieldhl:SetColorTexture(0.5, 0.8, 1);
124 f.healpred = f:CreateTexture(nil, "ARTWORK");
125 f.healpred:SetPoint("TOPLEFT", f.health, "TOPRIGHT");
126 f.healpred:SetPoint("BOTTOMLEFT", f.health, "BOTTOMRIGHT");
127 f.healpred:SetColorTexture(0.5, 0.6, 0.5);
129 f.healabsorb = f:CreateTexture(nil, "ARTWORK");
130 f.healabsorb:SetPoint("TOPRIGHT", f.health, "TOPRIGHT");
131 f.healabsorb:SetPoint("BOTTOMRIGHT", f.health, "BOTTOMRIGHT");
132 f.healabsorb:SetColorTexture(0.1, 0.1, 0.1);
134 f.overlay = f:CreateTexture(nil, "ARTWORK", nil, 1);
135 f.overlay:SetPoint("TOPLEFT", f.background, "TOPLEFT");
136 f.overlay:SetPoint("BOTTOMRIGHT", f.background, "BOTTOMRIGHT");
137 f.overlay:SetColorTexture(1, 1, 1);
139 f.role = f:CreateTexture(nil, "ARTWORK", nil, 2);
140 f.role:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -3, 3);
141 f.role:SetPoint("TOPLEFT", f, "BOTTOMRIGHT", -15, 15);
142 f.role:SetTexture("Interface\\LFGFRAME\\LFGROLE");
144 f.name = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
145 f.name:SetPoint("CENTER", f, "CENTER", 0, 11);
146 f.text = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
147 f.text:SetPoint("CENTER", f, "CENTER", 0, -1);
148 f.text:SetFont(STANDARD_TEXT_FONT, 13);
150 f.stack = f:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall");
151 f.stack:SetPoint("BOTTOMLEFT", f.background, "BOTTOMLEFT");
153 f.ready = f:CreateTexture(nil, "OVERLAY");
154 f.ready:SetPoint("TOPLEFT", f, "BOTTOMLEFT", 1, 15);
155 f.ready:SetPoint("BOTTOMRIGHT", f, "BOTTOMLEFT", 15, 1);
157 f.buffind1 = f:CreateTexture(nil, "OVERLAY");
158 f.buffind1:SetPoint("TOPRIGHT", f.background, "TOPRIGHT", -1, -1);
159 f.buffind1:SetWidth(6);
160 f.buffind1:SetHeight(6);
161 f.buffind1:SetColorTexture(0.8, 0.1, 0.1);
163 f.buffind2 = f:CreateTexture(nil, "OVERLAY");
164 f.buffind2:SetPoint("TOPLEFT", f.background, "TOPLEFT", 1, -1);
165 f.buffind2:SetWidth(4);
166 f.buffind2:SetHeight(4);
167 f.buffind2:SetColorTexture(0.8, 0.7, 0.1);
169 f.defensive = f:CreateTexture(nil, "OVERLAY", nil, 1);
170 f.defensive:SetPoint("TOPLEFT", f.background, "TOPLEFT", 1, -1);
171 f.defensive:SetWidth(6);
172 f.defensive:SetHeight(6);
173 f.defensive:SetColorTexture(1, 0.3, 0);
175 f.targeticon = f:CreateTexture(nil, "OVERLAY");
176 f.targeticon:SetPoint("CENTER", f, "TOP", 0, -1);
177 f.targeticon:SetWidth(12);
178 f.targeticon:SetHeight(12);
179 f.targeticon:SetTexture("Interface\\TARGETINGFRAME\\UI-RaidTargetingIcons");