29d93c0 - change raid frame position as mage
[wowui.git] / kehys / frame.lua
1 -- frame.lua
2 -- 2019 Aleksi Blinnikka
3 local _, addon = ...;
4 local unpack = unpack;
5 local format = string.format;
6 local CreateFrame = CreateFrame;
7 local CTimerAfter = C_Timer.After;
8
9 local guids = addon.FrameGuids;
10 local updaters = {};
11 local function showTooltip(frame)
12     GameTooltip_SetDefaultAnchor(GameTooltip, frame);
13     GameTooltip:SetUnit(frame:GetAttribute("unit"));
14 end
15 local function hideTooltip(frame)
16     if GameTooltip:IsOwned(frame) then GameTooltip:FadeOut() end
17 end
18
19 local barTexture = "Interface\\AddOns\\kehys\\images\\minimalist";
20 local frameid = 1;
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
34         attributes = {};
35     end
36
37     local f = CreateFrame(
38         "Button",
39         format("kehys%i", frameid),
40         parent,
41         "SecureUnitButtonTemplate,SecureHandlerStateTemplate"
42     );
43     frameid = frameid + 1;
44     f:Hide(); -- hide frame to have an initial frame:OnShow call
45     f:SetWidth(width);
46     f:SetHeight(height);
47     f.barwidth = width - 2; -- 1px padding on both sides
48     f:SetAttribute("unit", unit);
49     f.unit = unit;
50     f.displayed = 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     f.hits = {}; -- hits aura tracking
58     f.stagger = {}; -- Monk Stagger tracking
59     f.buff1 = {}; -- custom buff indicator 1
60     f.buff2 = {}; -- custom buff indicator 2
61     f.incoming = {}; -- incoming ability indicator
62     f.rolename = nil; -- TANK, HEALER, DAMAGER, NONE
63     f.classname = nil; -- DK Death Strike and Monk Stagger tracker
64     f.raid = true;
65     f.rounds = 0;
66     -- set up periodic updates
67     updaters[f] = function()
68         if f.updating then
69             CTimerAfter(0.1, updaters[f]);
70             return update(f)
71         end
72     end
73     -- set scripts
74     f:SetScript("OnShow", function()
75         onshow(f);
76         f.updating = true;
77         updaters[f]();
78     end);
79     f:SetScript("OnHide", function()
80         f:UnregisterAllEvents();
81         f.updating = false;
82         if f.guid then
83             guids[f.guid] = nil;
84             f.guid = nil;
85         end
86     end);
87     f:SetScript("OnEvent", event);
88     f:SetScript("OnEnter", showTooltip);
89     f:SetScript("OnLeave", hideTooltip);
90     -- set attributes
91     f:RegisterForClicks("AnyDown");
92     for attr, val in pairs(attributes) do
93         f:SetAttribute(attr, val);
94     end
95     -- rest give target and menu
96     f:SetAttribute("*type1", "target");
97     f:SetAttribute("*type2", "togglemenu");
98
99     -- create visuals
100     f.base = f:CreateTexture(nil, "BACKGROUND");
101     f.base:SetAllPoints();
102     f.base:SetColorTexture(1, 1, 1);
103     f.base:SetVertexColor(unpack(addon.Colors.Base));
104     f.glow = f:CreateTexture(nil, "BACKGROUND", nil, 1);
105     f.glow:SetAllPoints();
106     f.glow:SetColorTexture(1, 1, 1);
107     f.glow:SetVertexColor(unpack(addon.Colors.Glow));
108     f.background = f:CreateTexture(nil, "BACKGROUND", nil, 2);
109     f.background:SetPoint("TOPLEFT", f, "TOPLEFT", 1, -1);
110     f.background:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -1, 1);
111     f.background:SetColorTexture(0.7, 0.7, 0.7);
112     f.health = f:CreateTexture(nil, "BORDER");
113     f.health:SetPoint("TOPLEFT", f.background, "TOPLEFT");
114     f.health:SetPoint("BOTTOMLEFT", f.background, "BOTTOMLEFT");
115     f.health:SetTexture(barTexture);
116     f.health:SetVertexColor(0.3, 0.3, 0.3);
117     f.health:Hide();
118     f.shield = f:CreateTexture(nil, "BORDER");
119     f.shield:SetPoint("TOPLEFT", f.health, "TOPRIGHT");
120     f.shield:SetPoint("BOTTOMLEFT", f.health, "BOTTOMRIGHT");
121     f.shield:SetTexture(barTexture);
122     f.shield:SetVertexColor(0, 0.7, 1);
123     f.shield:Hide();
124     f.shieldhl = f:CreateTexture(nil, "ARTWORK");
125     f.shieldhl:SetPoint("TOPLEFT", f, "TOPRIGHT", -2, 0);
126     f.shieldhl:SetPoint("BOTTOMRIGHT");
127     f.shieldhl:SetColorTexture(0.5, 0.8, 1);
128     f.shieldhl:Hide();
129     f.healpred = f:CreateTexture(nil, "ARTWORK");
130     f.healpred:SetPoint("TOPLEFT", f.health, "TOPRIGHT");
131     f.healpred:SetPoint("BOTTOMLEFT", f.health, "BOTTOMRIGHT");
132     f.healpred:SetColorTexture(0.5, 0.6, 0.5);
133     f.healpred:Hide();
134     f.healabsorb = f:CreateTexture(nil, "ARTWORK");
135     f.healabsorb:SetPoint("TOPRIGHT", f.health, "TOPRIGHT");
136     f.healabsorb:SetPoint("BOTTOMRIGHT", f.health, "BOTTOMRIGHT");
137     f.healabsorb:SetColorTexture(0.1, 0.1, 0.1);
138     f.healabsorb:Hide();
139     f.overlay = f:CreateTexture(nil, "ARTWORK", nil, 1);
140     f.overlay:SetPoint("TOPLEFT", f.background, "TOPLEFT");
141     f.overlay:SetPoint("BOTTOMRIGHT", f.background, "BOTTOMRIGHT");
142     f.overlay:SetColorTexture(1, 1, 1);
143     f.overlay:Hide();
144     f.bottomwarn = f:CreateTexture(nil, "ARTWORK", nil, 1);
145     f.bottomwarn:SetPoint("TOPLEFT", f.background, "BOTTOMLEFT", 16, 5);
146     f.bottomwarn:SetPoint("BOTTOMRIGHT", f.background, "BOTTOMRIGHT", -16, 1);
147     f.bottomwarn:SetColorTexture(1, 0.3, 0.1, 0.66);
148     f.bottomwarn:Hide();
149     f.role = f:CreateTexture(nil, "ARTWORK", nil, 2);
150     f.role:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -3, 3);
151     f.role:SetPoint("TOPLEFT", f, "BOTTOMRIGHT", -15, 15);
152     f.role:SetTexture("Interface\\LFGFRAME\\LFGROLE");
153     f.role:Hide();
154     f.name = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
155     f.name:SetPoint("CENTER", f, "CENTER", 0, 11);
156     f.text = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
157     f.text:SetPoint("CENTER", f, "CENTER", 0, -1);
158     f.text:SetFont(STANDARD_TEXT_FONT, 13);
159     f.text:Hide();
160     f.stack = f:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall");
161     f.stack:SetPoint("BOTTOMLEFT", f.background, "BOTTOMLEFT");
162     f.stack:Hide();
163     f.ready = f:CreateTexture(nil, "OVERLAY");
164     f.ready:SetPoint("TOPLEFT", f, "BOTTOMLEFT", 1, 15);
165     f.ready:SetPoint("BOTTOMRIGHT", f, "BOTTOMLEFT", 15, 1);
166     f.ready:Hide();
167     f.buffind1 = f:CreateTexture(nil, "OVERLAY");
168     f.buffind1:SetPoint("TOPRIGHT", f.background, "TOPRIGHT", -1, -1);
169     f.buffind1:SetWidth(6);
170     f.buffind1:SetHeight(6);
171     f.buffind1:SetColorTexture(0.8, 0.1, 0.1);
172     f.buffind1:Hide();
173     f.buffind2 = f:CreateTexture(nil, "OVERLAY");
174     f.buffind2:SetPoint("TOPLEFT", f.background, "TOPLEFT", 1, -1);
175     f.buffind2:SetWidth(4);
176     f.buffind2:SetHeight(4);
177     f.buffind2:SetColorTexture(0.8, 0.7, 0.1);
178     f.buffind2:Hide();
179     f.defensive = f:CreateTexture(nil, "OVERLAY", nil, 1);
180     f.defensive:SetPoint("TOPLEFT", f.background, "TOPLEFT", 1, -1);
181     f.defensive:SetWidth(6);
182     f.defensive:SetHeight(6);
183     f.defensive:SetColorTexture(1, 0.3, 0);
184     f.defensive:Hide();
185     f.targeticon = f:CreateTexture(nil, "OVERLAY");
186     f.targeticon:SetPoint("CENTER", f, "TOP", 0, -1);
187     f.targeticon:SetWidth(12);
188     f.targeticon:SetHeight(12);
189     f.targeticon:SetTexture("Interface\\TARGETINGFRAME\\UI-RaidTargetingIcons");
190     f.targeticon:Hide();
191
192     return f;
193 end