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 -- set up periodic updates
59 updaters[f] = function()
61 CTimerAfter(0.1, updaters[f]);
66 f:SetScript("OnShow", function()
71 f:SetScript("OnHide", function()
72 f:UnregisterAllEvents();
79 f:SetScript("OnEvent", event);
80 f:SetScript("OnEnter", showTooltip);
81 f:SetScript("OnLeave", hideTooltip);
83 f:RegisterForClicks("AnyDown");
84 for attr, val in pairs(attributes) do
85 f:SetAttribute(attr, val);
87 -- rest give target and menu
88 f:SetAttribute("*type1", "target");
89 f:SetAttribute("*type2", "togglemenu");
92 f.base = f:CreateTexture(nil, "BACKGROUND");
93 f.base:SetAllPoints();
94 f.base:SetColorTexture(1, 1, 1);
95 f.base:SetVertexColor(unpack(addon.Colors.Base));
96 f.background = f:CreateTexture(nil, "BACKGROUND", nil, 1);
97 f.background:SetPoint("TOPLEFT", f, "TOPLEFT", 1, -1);
98 f.background:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -1, 1);
99 f.background:SetColorTexture(0.7, 0.7, 0.7);
100 f.health = f:CreateTexture(nil, "BORDER");
101 f.health:SetPoint("TOPLEFT", f.background, "TOPLEFT");
102 f.health:SetPoint("BOTTOMLEFT", f.background, "BOTTOMLEFT");
103 f.health:SetTexture(barTexture);
104 f.health:SetVertexColor(0.3, 0.3, 0.3);
106 f.shield = f:CreateTexture(nil, "BORDER");
107 f.shield:SetPoint("TOPLEFT", f.health, "TOPRIGHT");
108 f.shield:SetPoint("BOTTOMLEFT", f.health, "BOTTOMRIGHT");
109 f.shield:SetTexture(barTexture);
110 f.shield:SetVertexColor(0, 0.7, 1);
112 f.shieldhl = f:CreateTexture(nil, "ARTWORK");
113 f.shieldhl:SetPoint("TOPLEFT", f, "TOPRIGHT", -2, 0);
114 f.shieldhl:SetPoint("BOTTOMRIGHT");
115 f.shieldhl:SetColorTexture(0.5, 0.8, 1);
117 f.healpred = f:CreateTexture(nil, "ARTWORK");
118 f.healpred:SetPoint("TOPLEFT", f.health, "TOPRIGHT");
119 f.healpred:SetPoint("BOTTOMLEFT", f.health, "BOTTOMRIGHT");
120 f.healpred:SetColorTexture(0.5, 0.6, 0.5);
122 f.healabsorb = f:CreateTexture(nil, "ARTWORK");
123 f.healabsorb:SetPoint("TOPRIGHT", f.health, "TOPRIGHT");
124 f.healabsorb:SetPoint("BOTTOMRIGHT", f.health, "BOTTOMRIGHT");
125 f.healabsorb:SetColorTexture(0.1, 0.1, 0.1);
127 f.overlay = f:CreateTexture(nil, "ARTWORK", nil, 1);
128 f.overlay:SetPoint("TOPLEFT", f.background, "TOPLEFT");
129 f.overlay:SetPoint("BOTTOMRIGHT", f.background, "BOTTOMRIGHT");
130 f.overlay:SetColorTexture(1, 1, 1);
132 f.role = f:CreateTexture(nil, "ARTWORK", nil, 2);
133 f.role:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -3, 3);
134 f.role:SetPoint("TOPLEFT", f, "BOTTOMRIGHT", -15, 15);
135 f.role:SetTexture("Interface\\LFGFRAME\\LFGROLE");
137 f.name = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
138 f.name:SetPoint("CENTER", f, "CENTER", 0, 11);
139 f.text = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
140 f.text:SetPoint("CENTER", f, "CENTER", 0, -1);
141 f.text:SetFont(STANDARD_TEXT_FONT, 13);
143 f.stack = f:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall");
144 f.stack:SetPoint("BOTTOMLEFT", f.background, "BOTTOMLEFT");
146 f.ready = f:CreateTexture(nil, "OVERLAY");
147 f.ready:SetPoint("TOPLEFT", f, "BOTTOMLEFT", 1, 15);
148 f.ready:SetPoint("BOTTOMRIGHT", f, "BOTTOMLEFT", 15, 1);
150 f.defensive = f:CreateTexture(nil, "OVERLAY");
151 f.defensive:SetPoint("TOPLEFT", f.background, "TOPLEFT", 1, -1);
152 f.defensive:SetWidth(6);
153 f.defensive:SetHeight(6);
154 f.defensive:SetColorTexture(1, 0.3, 0);
156 f.buffind1 = f:CreateTexture(nil, "OVERLAY");
157 f.buffind1:SetPoint("TOPRIGHT", f.background, "TOPRIGHT", -1, -1);
158 f.buffind1:SetWidth(6);
159 f.buffind1:SetHeight(6);
160 f.buffind1:SetColorTexture(0.8, 0.1, 0.1);
162 f.targeticon = f:CreateTexture(nil, "OVERLAY");
163 f.targeticon:SetPoint("CENTER", f, "TOP", 0, -1);
164 f.targeticon:SetWidth(12);
165 f.targeticon:SetHeight(12);
166 f.targeticon:SetTexture("Interface\\TARGETINGFRAME\\UI-RaidTargetingIcons");