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