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 -- set up periodic updates
56 updaters[f] = function()
58 CTimerAfter(0.1, updaters[f]);
63 f:SetScript("OnShow", function()
68 f:SetScript("OnHide", function()
69 f:UnregisterAllEvents();
76 f:SetScript("OnEvent", event);
77 f:SetScript("OnEnter", showTooltip);
78 f:SetScript("OnLeave", hideTooltip);
80 f:RegisterForClicks("AnyDown");
81 for attr, val in pairs(attributes) do
82 f:SetAttribute(attr, val);
84 -- rest give target and menu
85 f:SetAttribute("*type1", "target");
86 f:SetAttribute("*type2", "togglemenu");
89 f.base = f:CreateTexture(nil, "BACKGROUND");
90 f.base:SetAllPoints();
91 f.base:SetColorTexture(1, 1, 1);
92 f.base:SetVertexColor(unpack(addon.Colors.Base));
93 f.background = f:CreateTexture(nil, "BACKGROUND", nil, 1);
94 f.background:SetPoint("TOPLEFT", f, "TOPLEFT", 1, -1);
95 f.background:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -1, 1);
96 f.background:SetColorTexture(0.7, 0.7, 0.7);
97 f.health = f:CreateTexture(nil, "BORDER");
98 f.health:SetPoint("TOPLEFT", f.background, "TOPLEFT");
99 f.health:SetPoint("BOTTOMLEFT", f.background, "BOTTOMLEFT");
100 f.health:SetTexture(barTexture);
101 f.health:SetVertexColor(0.3, 0.3, 0.3);
103 f.shield = f:CreateTexture(nil, "BORDER");
104 f.shield:SetPoint("TOPLEFT", f.health, "TOPRIGHT");
105 f.shield:SetPoint("BOTTOMLEFT", f.health, "BOTTOMRIGHT");
106 f.shield:SetTexture(barTexture);
107 f.shield:SetVertexColor(0, 0.7, 1);
109 f.shieldhl = f:CreateTexture(nil, "ARTWORK");
110 f.shieldhl:SetPoint("TOPLEFT", f, "TOPRIGHT", -2, 0);
111 f.shieldhl:SetPoint("BOTTOMRIGHT");
112 f.shieldhl:SetColorTexture(0.5, 0.8, 1);
114 f.healpred = f:CreateTexture(nil, "ARTWORK");
115 f.healpred:SetPoint("TOPLEFT", f.health, "TOPRIGHT");
116 f.healpred:SetPoint("BOTTOMLEFT", f.health, "BOTTOMRIGHT");
117 f.healpred:SetColorTexture(0.5, 0.6, 0.5);
119 f.healabsorb = f:CreateTexture(nil, "ARTWORK");
120 f.healabsorb:SetPoint("TOPRIGHT", f.health, "TOPRIGHT");
121 f.healabsorb:SetPoint("BOTTOMRIGHT", f.health, "BOTTOMRIGHT");
122 f.healabsorb:SetColorTexture(0.1, 0.1, 0.1);
124 f.overlay = f:CreateTexture(nil, "ARTWORK", nil, 1);
125 f.overlay:SetPoint("TOPLEFT", f.background, "TOPLEFT");
126 f.overlay:SetPoint("BOTTOMRIGHT", f.background, "BOTTOMRIGHT");
127 f.overlay:SetColorTexture(1, 1, 1);
129 f.role = f:CreateTexture(nil, "ARTWORK", nil, 2);
130 f.role:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -3, 3);
131 f.role:SetPoint("TOPLEFT", f, "BOTTOMRIGHT", -15, 15);
132 f.role:SetTexture("Interface\\LFGFRAME\\LFGROLE");
134 f.name = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
135 f.name:SetPoint("CENTER", f, "CENTER", 0, 11);
136 f.text = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
137 f.text:SetPoint("CENTER", f, "CENTER", 0, -1);
138 f.text:SetFont(STANDARD_TEXT_FONT, 13);
140 f.ready = f:CreateTexture(nil, "OVERLAY");
141 f.ready:SetPoint("TOPLEFT", f, "BOTTOMLEFT", 1, 15);
142 f.ready:SetPoint("BOTTOMRIGHT", f, "BOTTOMLEFT", 15, 1);
144 f.targeticon = f:CreateTexture(nil, "OVERLAY");
145 f.targeticon:SetPoint("CENTER", f, "TOP", 0, -1);
146 f.targeticon:SetWidth(12);
147 f.targeticon:SetHeight(12);
148 f.targeticon:SetTexture("Interface\\TARGETINGFRAME\\UI-RaidTargetingIcons");