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 -- set up periodic updates
58 updaters[f] = function()
60 CTimerAfter(0.1, updaters[f]);
65 f:SetScript("OnShow", function()
70 f:SetScript("OnHide", function()
71 f:UnregisterAllEvents();
78 f:SetScript("OnEvent", event);
79 f:SetScript("OnEnter", showTooltip);
80 f:SetScript("OnLeave", hideTooltip);
82 f:RegisterForClicks("AnyDown");
83 for attr, val in pairs(attributes) do
84 f:SetAttribute(attr, val);
86 -- rest give target and menu
87 f:SetAttribute("*type1", "target");
88 f:SetAttribute("*type2", "togglemenu");
91 f.base = f:CreateTexture(nil, "BACKGROUND");
92 f.base:SetAllPoints();
93 f.base:SetColorTexture(1, 1, 1);
94 f.base:SetVertexColor(unpack(addon.Colors.Base));
95 f.background = f:CreateTexture(nil, "BACKGROUND", nil, 1);
96 f.background:SetPoint("TOPLEFT", f, "TOPLEFT", 1, -1);
97 f.background:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -1, 1);
98 f.background:SetColorTexture(0.7, 0.7, 0.7);
99 f.health = f:CreateTexture(nil, "BORDER");
100 f.health:SetPoint("TOPLEFT", f.background, "TOPLEFT");
101 f.health:SetPoint("BOTTOMLEFT", f.background, "BOTTOMLEFT");
102 f.health:SetTexture(barTexture);
103 f.health:SetVertexColor(0.3, 0.3, 0.3);
105 f.shield = f:CreateTexture(nil, "BORDER");
106 f.shield:SetPoint("TOPLEFT", f.health, "TOPRIGHT");
107 f.shield:SetPoint("BOTTOMLEFT", f.health, "BOTTOMRIGHT");
108 f.shield:SetTexture(barTexture);
109 f.shield:SetVertexColor(0, 0.7, 1);
111 f.shieldhl = f:CreateTexture(nil, "ARTWORK");
112 f.shieldhl:SetPoint("TOPLEFT", f, "TOPRIGHT", -2, 0);
113 f.shieldhl:SetPoint("BOTTOMRIGHT");
114 f.shieldhl:SetColorTexture(0.5, 0.8, 1);
116 f.healpred = f:CreateTexture(nil, "ARTWORK");
117 f.healpred:SetPoint("TOPLEFT", f.health, "TOPRIGHT");
118 f.healpred:SetPoint("BOTTOMLEFT", f.health, "BOTTOMRIGHT");
119 f.healpred:SetColorTexture(0.5, 0.6, 0.5);
121 f.healabsorb = f:CreateTexture(nil, "ARTWORK");
122 f.healabsorb:SetPoint("TOPRIGHT", f.health, "TOPRIGHT");
123 f.healabsorb:SetPoint("BOTTOMRIGHT", f.health, "BOTTOMRIGHT");
124 f.healabsorb:SetColorTexture(0.1, 0.1, 0.1);
126 f.overlay = f:CreateTexture(nil, "ARTWORK", nil, 1);
127 f.overlay:SetPoint("TOPLEFT", f.background, "TOPLEFT");
128 f.overlay:SetPoint("BOTTOMRIGHT", f.background, "BOTTOMRIGHT");
129 f.overlay:SetColorTexture(1, 1, 1);
131 f.role = f:CreateTexture(nil, "ARTWORK", nil, 2);
132 f.role:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -3, 3);
133 f.role:SetPoint("TOPLEFT", f, "BOTTOMRIGHT", -15, 15);
134 f.role:SetTexture("Interface\\LFGFRAME\\LFGROLE");
136 f.name = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
137 f.name:SetPoint("CENTER", f, "CENTER", 0, 11);
138 f.text = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
139 f.text:SetPoint("CENTER", f, "CENTER", 0, -1);
140 f.text:SetFont(STANDARD_TEXT_FONT, 13);
142 f.stack = f:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall");
143 f.stack:SetPoint("BOTTOMLEFT", f.background, "BOTTOMLEFT");
145 f.ready = f:CreateTexture(nil, "OVERLAY");
146 f.ready:SetPoint("TOPLEFT", f, "BOTTOMLEFT", 1, 15);
147 f.ready:SetPoint("BOTTOMRIGHT", f, "BOTTOMLEFT", 15, 1);
149 f.defensive = f:CreateTexture(nil, "OVERLAY");
150 f.defensive:SetPoint("TOPLEFT", f.background, "TOPLEFT", 1, -1);
151 f.defensive:SetWidth(6);
152 f.defensive:SetHeight(6);
153 f.defensive:SetColorTexture(1, 0.3, 0);
155 f.targeticon = f:CreateTexture(nil, "OVERLAY");
156 f.targeticon:SetPoint("CENTER", f, "TOP", 0, -1);
157 f.targeticon:SetWidth(12);
158 f.targeticon:SetHeight(12);
159 f.targeticon:SetTexture("Interface\\TARGETINGFRAME\\UI-RaidTargetingIcons");