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(attributes) == "table",
28 "Frame creation missing attributes table!");
29 assert(type(update) == "function",
30 "Frame creation missing update function!");
31 assert(type(event) == "function",
32 "Frame creation missing event function!");
33 assert(type(onshow) == "function",
34 "Frame creation missing onshow function!");
36 local f = CreateFrame(
38 format("kehys%i", frameid),
40 "SecureUnitButtonTemplate,SecureHandlerStateTemplate"
42 frameid = frameid + 1;
43 f:Hide(); -- hide frame to have an initial frame:OnShow call
46 f.barwidth = width - 2; -- 1px padding on both sides
47 f:SetAttribute("unit", unit);
50 f.vehicle = unit == "player" and "vehicle" or format("%spet", unit);
51 f.prev = {} -- values stored from previous update
52 f.alert = {}; -- alerting auras
53 -- set up periodic updates
54 updaters[f] = function()
56 CTimerAfter(0.1, updaters[f]);
61 f:SetScript("OnShow", function()
66 f:SetScript("OnHide", function()
67 f:UnregisterAllEvents();
74 f:SetScript("OnEvent", event);
75 f:SetScript("OnEnter", showTooltip);
76 f:SetScript("OnLeave", hideTooltip);
78 f:RegisterForClicks("AnyDown");
79 for attr, val in pairs(attributes) do
80 f:SetAttribute(attr, val);
82 -- rest give target and menu
83 f:SetAttribute("*type1", "target");
84 f:SetAttribute("*type2", "togglemenu");
87 f.base = f:CreateTexture(nil, "BACKGROUND");
88 f.base:SetAllPoints();
89 f.base:SetColorTexture(1, 1, 1);
90 f.base:SetVertexColor(unpack(addon.Colors.Base));
91 f.background = f:CreateTexture(nil, "BACKGROUND", nil, 1);
92 f.background:SetPoint("TOPLEFT", f, "TOPLEFT", 1, -1);
93 f.background:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -1, 1);
94 f.background:SetColorTexture(0.7, 0.7, 0.7);
95 f.health = f:CreateTexture(nil, "BORDER");
96 f.health:SetPoint("TOPLEFT", f.background, "TOPLEFT");
97 f.health:SetPoint("BOTTOMLEFT", f.background, "BOTTOMLEFT");
98 f.health:SetTexture(barTexture);
99 f.health:SetVertexColor(0.3, 0.3, 0.3);
101 f.shield = f:CreateTexture(nil, "BORDER");
102 f.shield:SetPoint("TOPLEFT", f.health, "TOPRIGHT");
103 f.shield:SetPoint("BOTTOMLEFT", f.health, "BOTTOMRIGHT");
104 f.shield:SetTexture(barTexture);
105 f.shield:SetVertexColor(0, 0.7, 1);
107 f.shieldhl = f:CreateTexture(nil, "ARTWORK");
108 f.shieldhl:SetPoint("TOPLEFT", f, "TOPRIGHT", -2, 0);
109 f.shieldhl:SetPoint("BOTTOMRIGHT");
110 f.shieldhl:SetColorTexture(0.5, 0.8, 1);
112 f.healpred = f:CreateTexture(nil, "ARTWORK");
113 f.healpred:SetPoint("TOPLEFT", f.health, "TOPRIGHT");
114 f.healpred:SetPoint("BOTTOMLEFT", f.health, "BOTTOMRIGHT");
115 f.healpred:SetColorTexture(0.5, 0.6, 0.5);
117 f.healabsorb = f:CreateTexture(nil, "ARTWORK");
118 f.healabsorb:SetPoint("TOPRIGHT", f.health, "TOPRIGHT");
119 f.healabsorb:SetPoint("BOTTOMRIGHT", f.health, "BOTTOMRIGHT");
120 f.healabsorb:SetColorTexture(0.1, 0.1, 0.1);
122 f.overlay = f:CreateTexture(nil, "ARTWORK", nil, 1);
123 f.overlay:SetPoint("TOPLEFT", f.background, "TOPLEFT");
124 f.overlay:SetPoint("BOTTOMRIGHT", f.background, "BOTTOMRIGHT");
125 f.overlay:SetColorTexture(1, 1, 1);
127 f.role = f:CreateTexture(nil, "ARTWORK", nil, 2);
128 f.role:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -3, 3);
129 f.role:SetPoint("TOPLEFT", f, "BOTTOMRIGHT", -15, 15);
130 f.role:SetTexture("Interface\\LFGFRAME\\LFGROLE");
132 f.name = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
133 f.name:SetPoint("CENTER", f, "CENTER", 0, 11);
134 f.text = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
135 f.text:SetPoint("CENTER", f, "CENTER", 0, -1);
136 f.text:SetFont(STANDARD_TEXT_FONT, 13);
138 f.ready = f:CreateTexture(nil, "OVERLAY");
139 f.ready:SetPoint("TOPLEFT", f, "BOTTOMLEFT", 1, 15);
140 f.ready:SetPoint("BOTTOMRIGHT", f, "BOTTOMLEFT", 15, 1);
142 f.targeticon = f:CreateTexture(nil, "OVERLAY");
143 f.targeticon:SetPoint("CENTER", f, "TOP", 0, -1);
144 f.targeticon:SetWidth(12);
145 f.targeticon:SetHeight(12);
146 f.targeticon:SetTexture("Interface\\TARGETINGFRAME\\UI-RaidTargetingIcons");