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:SetAttribute("unit", unit);
48 f.vehicle = unit == "player" and "vehicle" or format("%spet", unit);
49 f.prev = {} -- values stored from previous update
50 -- set up periodic updates
51 updaters[f] = function()
53 CTimerAfter(0.25, updaters[f]);
58 f:SetScript("OnShow", function()
63 f:SetScript("OnHide", function()
64 f:UnregisterAllEvents();
67 f:SetScript("OnEvent", event);
68 f:SetScript("OnEnter", showTooltip);
69 f:SetScript("OnLeave", hideTooltip);
71 f:RegisterForClicks("AnyDown");
72 for attr, val in pairs(attributes) do
73 f:SetAttribute(attr, val);
75 -- rest give target and menu
76 f:SetAttribute("*type1", "target");
77 f:SetAttribute("*type2", "togglemenu");
80 f.base = f:CreateTexture(nil, "BACKGROUND");
81 f.base:SetAllPoints();
82 f.base:SetColorTexture(1, 1, 1);
83 f.base:SetVertexColor(unpack(addon.Colors.Base));
84 f.background = f:CreateTexture(nil, "BACKGROUND", nil, 1);
85 f.background:SetPoint("TOPLEFT", f, "TOPLEFT", 1, -1);
86 f.background:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -1, 1);
87 f.background:SetColorTexture(0.7, 0.7, 0.7);
88 f.health = f:CreateTexture(nil, "BORDER");
89 f.health:SetPoint("TOPLEFT", f.background, "TOPLEFT");
90 f.health:SetPoint("BOTTOMLEFT", f.background, "BOTTOMLEFT");
91 f.health:SetTexture(barTexture);
92 f.health:SetVertexColor(0.3, 0.3, 0.3);
94 f.shield = f:CreateTexture(nil, "BORDER");
95 f.shield:SetPoint("TOPLEFT", f.health, "TOPRIGHT");
96 f.shield:SetPoint("BOTTOMLEFT", f.health, "BOTTOMRIGHT");
97 f.shield:SetTexture(barTexture);
98 f.shield:SetVertexColor(0, 0.7, 1);
100 f.shieldhl = f:CreateTexture(nil, "ARTWORK");
101 f.shieldhl:SetPoint("TOPLEFT", f, "TOPRIGHT", -2, 0);
102 f.shieldhl:SetPoint("BOTTOMRIGHT");
103 f.shieldhl:SetColorTexture(0.5, 0.8, 1);
105 f.healpred = f:CreateTexture(nil, "ARTWORK");
106 f.healpred:SetPoint("TOPLEFT", f.health, "TOPRIGHT");
107 f.healpred:SetPoint("BOTTOMLEFT", f.health, "BOTTOMRIGHT");
108 f.healpred:SetColorTexture(0.5, 0.6, 0.5);
110 f.healabsorb = f:CreateTexture(nil, "ARTWORK");
111 f.healabsorb:SetPoint("TOPRIGHT", f.health, "TOPRIGHT");
112 f.healabsorb:SetPoint("BOTTOMRIGHT", f.health, "BOTTOMRIGHT");
113 f.healabsorb:SetColorTexture(0.1, 0.1, 0.1);
115 f.overlay = f:CreateTexture(nil, "ARTWORK", nil, 1);
116 f.overlay:SetPoint("TOPLEFT", f.background, "TOPLEFT");
117 f.overlay:SetPoint("BOTTOMRIGHT", f.background, "BOTTOMRIGHT");
118 f.overlay:SetColorTexture(1, 1, 1);
120 f.role = f:CreateTexture(nil, "ARTWORK", nil, 2);
121 f.role:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -3, 3);
122 f.role:SetPoint("TOPLEFT", f, "BOTTOMRIGHT", -15, 15);
123 f.role:SetTexture("Interface\\LFGFRAME\\LFGROLE");
125 f.name = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
126 f.name:SetPoint("CENTER", f, "CENTER", 0, 11);
127 f.text = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
128 f.text:SetPoint("CENTER", f, "CENTER", 0, -1);
129 f.text:SetFont(STANDARD_TEXT_FONT, 13);
131 f.ready = f:CreateTexture(nil, "OVERLAY");
132 f.ready:SetPoint("TOPLEFT", f, "BOTTOMLEFT", 1, 15);
133 f.ready:SetPoint("BOTTOMRIGHT", f, "BOTTOMLEFT", 15, 1);
135 f.targeticon = f:CreateTexture(nil, "OVERLAY");
136 f.targeticon:SetPoint("CENTER", f, "TOP", 0, -1);
137 f.targeticon:SetWidth(12);
138 f.targeticon:SetHeight(12);
139 f.targeticon:SetTexture("Interface\\TARGETINGFRAME\\UI-RaidTargetingIcons");