2 -- 2019 Aleksi Blinnikka
5 local format = string.format;
6 local CreateFrame = CreateFrame;
7 local CTimerAfter = C_Timer.After;
10 local function showTooltip(frame)
11 GameTooltip_SetDefaultAnchor(GameTooltip, frame);
12 GameTooltip:SetUnit(frame:GetAttribute("unit"));
14 local function hideTooltip(frame)
15 if GameTooltip:IsOwned(frame) then GameTooltip:FadeOut() end
18 local barTexture = "Interface\\AddOns\\kehys\\images\\minimalist";
20 function addon.NewRaidFrame(parent, width, height, unit, attributes,
21 update, event, onshow)
22 assert(type(parent) == "table", "Frame creation missing parent!");
23 assert(type(width) == "number", "Frame creation missing width!");
24 assert(type(height) == "number", "Frame creation missing height!");
25 assert(type(unit) == "string", "Frame creation missing unit!");
26 assert(type(attributes) == "table",
27 "Frame creation missing attributes table!");
28 assert(type(update) == "function",
29 "Frame creation missing update function!");
30 assert(type(event) == "function",
31 "Frame creation missing event function!");
32 assert(type(onshow) == "function",
33 "Frame creation missing onshow function!");
35 local f = CreateFrame(
37 format("kehys%i", frameid),
39 "SecureUnitButtonTemplate,SecureHandlerStateTemplate"
41 frameid = frameid + 1;
42 f:Hide(); -- hide frame to have an initial frame:OnShow call
45 f.barwidth = width - 2; -- 1px padding on both sides
46 f:SetAttribute("unit", unit);
49 f.vehicle = unit == "player" and "vehicle" or format("%spet", unit);
50 f.prev = {} -- values stored from previous update
51 -- set up periodic updates
52 updaters[f] = function()
54 CTimerAfter(0.1, updaters[f]);
59 f:SetScript("OnShow", function()
64 f:SetScript("OnHide", function()
65 f:UnregisterAllEvents();
68 f:SetScript("OnEvent", event);
69 f:SetScript("OnEnter", showTooltip);
70 f:SetScript("OnLeave", hideTooltip);
72 f:RegisterForClicks("AnyDown");
73 for attr, val in pairs(attributes) do
74 f:SetAttribute(attr, val);
76 -- rest give target and menu
77 f:SetAttribute("*type1", "target");
78 f:SetAttribute("*type2", "togglemenu");
81 f.base = f:CreateTexture(nil, "BACKGROUND");
82 f.base:SetAllPoints();
83 f.base:SetColorTexture(1, 1, 1);
84 f.base:SetVertexColor(unpack(addon.Colors.Base));
85 f.background = f:CreateTexture(nil, "BACKGROUND", nil, 1);
86 f.background:SetPoint("TOPLEFT", f, "TOPLEFT", 1, -1);
87 f.background:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -1, 1);
88 f.background:SetColorTexture(0.7, 0.7, 0.7);
89 f.health = f:CreateTexture(nil, "BORDER");
90 f.health:SetPoint("TOPLEFT", f.background, "TOPLEFT");
91 f.health:SetPoint("BOTTOMLEFT", f.background, "BOTTOMLEFT");
92 f.health:SetTexture(barTexture);
93 f.health:SetVertexColor(0.3, 0.3, 0.3);
95 f.shield = f:CreateTexture(nil, "BORDER");
96 f.shield:SetPoint("TOPLEFT", f.health, "TOPRIGHT");
97 f.shield:SetPoint("BOTTOMLEFT", f.health, "BOTTOMRIGHT");
98 f.shield:SetTexture(barTexture);
99 f.shield:SetVertexColor(0, 0.7, 1);
101 f.shieldhl = f:CreateTexture(nil, "ARTWORK");
102 f.shieldhl:SetPoint("TOPLEFT", f, "TOPRIGHT", -2, 0);
103 f.shieldhl:SetPoint("BOTTOMRIGHT");
104 f.shieldhl:SetColorTexture(0.5, 0.8, 1);
106 f.healpred = f:CreateTexture(nil, "ARTWORK");
107 f.healpred:SetPoint("TOPLEFT", f.health, "TOPRIGHT");
108 f.healpred:SetPoint("BOTTOMLEFT", f.health, "BOTTOMRIGHT");
109 f.healpred:SetColorTexture(0.5, 0.6, 0.5);
111 f.healabsorb = f:CreateTexture(nil, "ARTWORK");
112 f.healabsorb:SetPoint("TOPRIGHT", f.health, "TOPRIGHT");
113 f.healabsorb:SetPoint("BOTTOMRIGHT", f.health, "BOTTOMRIGHT");
114 f.healabsorb:SetColorTexture(0.1, 0.1, 0.1);
116 f.overlay = f:CreateTexture(nil, "ARTWORK", nil, 1);
117 f.overlay:SetPoint("TOPLEFT", f.background, "TOPLEFT");
118 f.overlay:SetPoint("BOTTOMRIGHT", f.background, "BOTTOMRIGHT");
119 f.overlay:SetColorTexture(1, 1, 1);
121 f.role = f:CreateTexture(nil, "ARTWORK", nil, 2);
122 f.role:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -3, 3);
123 f.role:SetPoint("TOPLEFT", f, "BOTTOMRIGHT", -15, 15);
124 f.role:SetTexture("Interface\\LFGFRAME\\LFGROLE");
126 f.name = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
127 f.name:SetPoint("CENTER", f, "CENTER", 0, 11);
128 f.text = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
129 f.text:SetPoint("CENTER", f, "CENTER", 0, -1);
130 f.text:SetFont(STANDARD_TEXT_FONT, 13);
132 f.ready = f:CreateTexture(nil, "OVERLAY");
133 f.ready:SetPoint("TOPLEFT", f, "BOTTOMLEFT", 1, 15);
134 f.ready:SetPoint("BOTTOMRIGHT", f, "BOTTOMLEFT", 15, 1);
136 f.targeticon = f:CreateTexture(nil, "OVERLAY");
137 f.targeticon:SetPoint("CENTER", f, "TOP", 0, -1);
138 f.targeticon:SetWidth(12);
139 f.targeticon:SetHeight(12);
140 f.targeticon:SetTexture("Interface\\TARGETINGFRAME\\UI-RaidTargetingIcons");