Mercurial > wow > buffalo2
comparison BuffFrame/BuffButton.lua @ 47:1a322b92dbfa
file cleanup
author | Nenue |
---|---|
date | Thu, 28 Apr 2016 05:54:21 -0400 |
parents | BuffButton.lua@5301c68f28d8 |
children | 9837069e366a |
comparison
equal
deleted
inserted
replaced
46:aa693607b813 | 47:1a322b92dbfa |
---|---|
1 --- Actual BlizzUI modifications are applied here | |
2 -- @file-author@ | |
3 -- @project-revision@ @project-hash@ | |
4 -- @file-revision@ @file-hash@ | |
5 -- Created: 3/12/2016 12:47 AM | |
6 local MODULE = 'BuffFrame' | |
7 local _, A = ... | |
8 local B, _G = A.frame, _G | |
9 local type, unpack, select, pairs, ipairs = _G.type, _G.unpack, _G.select, _G.pairs, _G.ipairs | |
10 local min, ceil, mod, tonumber, tostring = _G.min, _G.ceil, _G.mod, _G.tonumber, _G.tostring | |
11 local floor, wipe, max = _G.math.floor, _G.table.wipe, _G.math.max | |
12 local CreateFrame, IsInGroup, GetCVarBool = _G.CreateFrame, _G.IsInGroup, _G.GetCVarBool | |
13 local BuffFrame, ConsolidatedBuffs = _G.BuffFrame, _G.ConsolidatedBuffs | |
14 local print, gprint, aprint, fprint = B.print('Buff'), B.print('SetGuides'), B.print('SetAnchors'), B.fprint | |
15 local displays, anchors, guides, decors, positioned, drawn, zoom = B.displays, {}, {}, {}, {}, {}, {} | |
16 local UnitAura, UnitName, RegisterStateDriver = _G.UnitAura, _G.UnitName, _G.RegisterStateDriver | |
17 | |
18 local M = B:RegisterModule(MODULE) | |
19 | |
20 M.GetBuffZoom = function(buffName) | |
21 local zoom = tonumber(B.displays[buffName].conf['Zoom']) / 100 / 2 | |
22 local zoomL, zoomU, zoomR, zoomD = zoom, zoom, 1-zoom, 1-zoom | |
23 print(buffName, zoom) | |
24 return function(self, ...) | |
25 if select('#',...) == 4 then | |
26 zoomL, zoomR, zoomU, zoomD = ... | |
27 end | |
28 self:SetTexCoord(zoomL, zoomR, zoomU, zoomD) | |
29 return zoomL, zoomR, zoomU, zoomD | |
30 end | |
31 end | |
32 | |
33 | |
34 | |
35 M.UpdateButtonAlpha = function(self) | |
36 if not self.parent.timeLeft or not self:IsVisible() then | |
37 self:SetScript('OnUpdate', nil) | |
38 return | |
39 end | |
40 | |
41 if self.parent.timeLeft < _G.BUFF_WARNING_TIME then | |
42 self:SetAlpha(BuffFrame.BuffAlphaValue) | |
43 else | |
44 self:SetAlpha(1) | |
45 end | |
46 end | |
47 | |
48 --- Called infrequently to align stencil frames | |
49 local refreshCount = 0 | |
50 M.UpdateGuideFrames = function(buffName) | |
51 refreshCount = refreshCount + 1 | |
52 local print = fprint() | |
53 | |
54 | |
55 local anchor = anchors[buffName] | |
56 local c, g, d = displays[buffName].conf, guides[buffName], decors[buffName] | |
57 local perRow = c['PerRow'] | |
58 local buffSpacing, buffSize, buffBorder, buffDurationSize, buffCountSize, relativeX, relativeY = c['Spacing'], c['Size'], c['Border'], c['DurationSize'], c['CountSize'], c['RelativeX'], c['RelativeY'] | |
59 local consolidated = (anchors[buffName].contains and IsInGroup()) | |
60 local consolidatedPosition = (consolidated and anchors[buffName].containPosition or 0) | |
61 | |
62 | |
63 print('|cFF00FF00Setting Guides ('..refreshCount..'):|r', buffName, 'user max:',c['Max'], 'hard max:', displays[buffName].maxIcons) | |
64 | |
65 local buffMax = min(c['Max'], displays[buffName].maxIcons) | |
66 local anchorFrom, anchorTo = c.Point[1], c.Point[2] | |
67 anchor.Zoom = M.GetBuffZoom(buffName) | |
68 | |
69 | |
70 | |
71 if consolidated then | |
72 buffMax = buffMax + 1 | |
73 end | |
74 | |
75 local legend = {} | |
76 legend.r, legend.g, legend.b, legend.a = unpack(displays[buffName].legendColor) | |
77 local horizFrom = (relativeX < 0) and 'RIGHT' or 'LEFT' | |
78 local horizTo = (relativeX < 0) and 'LEFT' or 'RIGHT' | |
79 local vertFrom = (relativeY < 0) and 'TOP' or 'BOTTOM' | |
80 local vertTo = (relativeY < 0) and 'BOTTOM' or 'TOP' | |
81 local previous, up | |
82 local bottom_extent = 0 | |
83 for i = 1, buffMax do | |
84 print('update idx', i) | |
85 if not g[i] then | |
86 g[i] = CreateFrame('Frame', buffName..'Guide'..i, anchor, displays[buffName].template or 'VeneerGuideTemplate') | |
87 RegisterStateDriver(g[i], "visibility", "[petbattle] [vehicleui] hide; show") | |
88 end | |
89 | |
90 local guide = g[i] | |
91 | |
92 local row = ceil(i / perRow) | |
93 local col = mod(i, perRow) | |
94 if col == 0 then | |
95 col = perRow | |
96 end | |
97 | |
98 guide.previous = previous | |
99 guide.up = up | |
100 local x, y, parent = 0, 0, anchor | |
101 if i == 1 then | |
102 parent = anchor | |
103 up = guide | |
104 elseif col == 1 then | |
105 parent = g[i-perRow] | |
106 y = (buffSpacing + bottom_extent) * relativeY | |
107 up = guide | |
108 anchorFrom = vertFrom .. horizFrom | |
109 anchorTo = vertFrom .. horizFrom | |
110 bottom_extent = 0 | |
111 else | |
112 parent = g[i-1] | |
113 x = buffSpacing * relativeX | |
114 anchorFrom = vertFrom .. horizFrom | |
115 anchorTo = vertFrom .. horizTo | |
116 end | |
117 previous = guide | |
118 guide.parent = parent | |
119 | |
120 --------------------------------- | |
121 -- Positioning layer | |
122 if i ~= consolidatedPosition or not consolidated then | |
123 guide:SetSize(buffSize, buffSize + buffDurationSize) | |
124 -- RaidBuffTray will fix the sizing | |
125 end | |
126 bottom_extent = max(bottom_extent, guide:GetHeight()) | |
127 | |
128 guide.info = {} -- UnitAura cache | |
129 | |
130 if i == consolidatedPosition then | |
131 guide.legend:SetTexture(1,1,0,0.5) | |
132 else | |
133 guide.legend:SetTexture(legend.r, legend.g, legend.b, legend.a) | |
134 end | |
135 | |
136 guide.idText:SetText(i) -- needs to reflect the current position | |
137 | |
138 guide:ClearAllPoints() | |
139 guide:SetPoint(anchorFrom, parent, anchorTo, x, y) | |
140 print(anchorFrom, parent, anchorTo, x, y) | |
141 | |
142 guide.icon:SetSize(buffSize - buffBorder * 2, buffSize - buffBorder * 2) | |
143 guide.icon:ClearAllPoints() | |
144 guide.icon:SetPoint('TOPLEFT', guide, 'TOPLEFT', buffBorder, -buffBorder ) | |
145 | |
146 local anchorTo, anchorFrom, x, y = unpack(c.DurationPoint) | |
147 guide.duration:ClearAllPoints() | |
148 guide.duration:SetPoint(anchorTo, guide, anchorFrom, x, y) | |
149 --guide.duration:SetSize(buffSize, buffDurationSize) | |
150 print(' duration ->', anchorFrom, anchorTo, x, y) | |
151 | |
152 local anchorTo, anchorFrom, x, y = unpack(c.CountPoint) | |
153 guide.count:ClearAllPoints() | |
154 guide.count:SetPoint(anchorTo, guide.icon, anchorFrom, x, y) | |
155 --guide.count:SetSize(buffSize, c.CountSize) | |
156 print(' count ->', anchorFrom, anchorTo, x, y) | |
157 | |
158 ----------------------------------- | |
159 -- Background decorations layer | |
160 if not d[i] then | |
161 d[i] = CreateFrame('Frame', buffName..i..'Decor', _G.UIParent, 'VeneerDecorTemplate') | |
162 -- todo: sort out a way to fix this without creating taint issues | |
163 RegisterStateDriver(d[i], "visibility", "[petbattle] [vehicleui] hide") | |
164 end | |
165 | |
166 d[i]:SetPoint('BOTTOMLEFT', guide.icon, 'BOTTOMLEFT', -buffBorder, -buffBorder) | |
167 d[i]:SetPoint('TOPRIGHT', guide.icon, 'TOPRIGHT', buffBorder, buffBorder) | |
168 | |
169 | |
170 guide:Show() | |
171 B.SetConfigLayers(guide) | |
172 end | |
173 | |
174 | |
175 if #guides[buffName] > buffMax then | |
176 local lim = #guides[buffName] | |
177 for i = buffMax+1, lim do | |
178 | |
179 local g = guides[buffName][i] | |
180 if g:IsVisible() then | |
181 print('cleaning up #', i, buffName) | |
182 g:Hide() | |
183 B.RemoveConfigLayers(g) | |
184 end | |
185 | |
186 end | |
187 end | |
188 | |
189 anchor.last = previous | |
190 anchor.up = up | |
191 | |
192 print(anchor:GetName(), anchor:GetSize()) | |
193 end | |
194 | |
195 M.UpdateButtonPositions = function(buffName, auraType) | |
196 local print = fprint() | |
197 local c = auraType.conf | |
198 local numBuffs = 0 | |
199 local actualIcons = auraType.actualIcons() | |
200 local maxIcons = auraType.maxIcons | |
201 local anchor = anchors[buffName] | |
202 local buffMax = c['Max'] | |
203 local consolidated = (anchor.contains and IsInGroup()) | |
204 local consolidatedPosition = (consolidated and anchor.containPosition or 0) | |
205 | |
206 for k,v in pairs(decors[buffName]) do | |
207 print(v) | |
208 end | |
209 | |
210 if consolidated then | |
211 decors[buffName][1]:Hide() | |
212 numBuffs = numBuffs + 1 | |
213 buffMax = buffMax + 1 | |
214 end | |
215 | |
216 print(' ', 'frame count:', auraType.actualIcons(), 'hardmax:', maxIcons) | |
217 if auraType.actualIcons() > 0 then | |
218 for i = 1, actualIcons do | |
219 | |
220 | |
221 local buff = _G[buffName .. i] | |
222 local buffIcon = _G[buffName .. i .. 'Icon'] | |
223 local buffBorder = c['Border'] | |
224 local buffDuration = _G[buffName .. i .. 'Duration'] | |
225 local buffCount = _G[buffName .. i .. 'Count'] | |
226 local buffDurationSize = c['DurationSize'] | |
227 local debuffBorder = _G[buffName .. i .. 'Border'] | |
228 | |
229 | |
230 if buff and not buff.consolidated then | |
231 numBuffs = numBuffs + 1 | |
232 local guide = guides[buffName][numBuffs] | |
233 local deco = decors[buffName][numBuffs] | |
234 if numBuffs > buffMax then | |
235 -- if a limit is reached, start hiding | |
236 if guide then | |
237 guide.info = nil | |
238 end | |
239 if deco then | |
240 deco:Hide() | |
241 end | |
242 buff:Hide() | |
243 else | |
244 local buffData = guide.info | |
245 buffData.name, buffData.rank, buffData.icon, buffData.count, buffData.dispelType, buffData.duration, buffData.expires, buffData.caster, buffData.isStealable, buffData.shouldConsolidate, buffData.spellID, buffData.canApplyAura, buffData.isBossDebuff, buffData.value1, buffData.value2, buffData.value3 | |
246 = UnitAura(buff.unit, buff:GetID(), nil, buff.filters) | |
247 | |
248 if guide.caster and buffData.caster then | |
249 if (buffData.caster ~= 'player' or c.ShowSelfCast) then | |
250 guide.caster:SetText(UnitName(buffData.caster)) | |
251 else | |
252 guide.caster:SetText(nil) | |
253 end | |
254 end | |
255 | |
256 | |
257 print(numBuffs, i, buff:GetName(), buff:GetID(), decors[buffName][numBuffs]:GetName()) | |
258 | |
259 buff:SetAllPoints(guide) | |
260 buffIcon:ClearAllPoints() | |
261 buffIcon:SetPoint('TOPLEFT', guide.icon, 'TOPLEFT', 0, 0) | |
262 buffIcon:SetPoint('BOTTOMRIGHT', guide.icon, 'BOTTOMRIGHT', 0, 0) | |
263 | |
264 deco.parent = buff | |
265 -- make sure so they aren't re-shown in pet battle | |
266 if not C_PetBattles.IsInBattle() then | |
267 deco:Show() | |
268 deco:SetAlpha(1) | |
269 end | |
270 | |
271 if debuffBorder then | |
272 deco.background:SetTexture(debuffBorder:GetVertexColor()) | |
273 debuffBorder:Hide() | |
274 else | |
275 if guide.info.caster == 'player' then | |
276 print(guide.info.caster) | |
277 deco.background:SetTexture(unpack(c.PlayerColor)) | |
278 elseif buffData.isBossDebuff then | |
279 print(guide.info.isBossDebuff) | |
280 deco.background:SetTexture(unpack(c.BossColor)) | |
281 else | |
282 print(guide.info.caster) | |
283 deco.background:SetTexture(unpack(c.Color)) | |
284 end | |
285 end | |
286 | |
287 | |
288 buffDuration:ClearAllPoints() | |
289 local from, to = unpack(c.DurationPoint) | |
290 buffDuration:SetPoint(from, guide.duration, to) | |
291 buffDuration:SetText('WHAT') | |
292 | |
293 if buff.timeLeft and c.WarningFade then | |
294 deco:SetScript('OnUpdate', M.UpdateButtonAlpha) | |
295 else | |
296 deco:SetScript('OnUpdate', nil) | |
297 deco:SetAlpha(1.0) | |
298 end | |
299 | |
300 buffCount:ClearAllPoints() | |
301 local from, to = unpack(c.CountPoint) | |
302 buffCount:SetPoint(from, guide.count, to) | |
303 | |
304 if not drawn[buffName][numBuffs] then | |
305 anchors[buffName].Zoom(buffIcon) | |
306 | |
307 if buffDuration then | |
308 local font = buffDuration:GetFont() | |
309 buffDuration:SetFont(font, c.DurationSize, 'OUTLINE') | |
310 | |
311 end | |
312 | |
313 if buffCount then | |
314 local font = buffCount:GetFont() | |
315 buffCount:SetFont(font, c.CountSize, 'OUTLINE') | |
316 end | |
317 drawn[buffName][numBuffs] = true | |
318 end | |
319 end | |
320 end | |
321 | |
322 end | |
323 end | |
324 -- clear any outliers | |
325 for i = numBuffs+1, buffMax do | |
326 if guides[buffName][i].caster then | |
327 guides[buffName][i].caster:SetText(nil) | |
328 end | |
329 --if not decors[buffName][i].parent or | |
330 | |
331 decors[buffName][i].parent = nil | |
332 decors[buffName][i]:SetAlpha(1.0) | |
333 decors[buffName][i]:SetScript('OnUpdate', nil) | |
334 decors[buffName][i]:Hide() | |
335 end | |
336 | |
337 -- parametric occlusion data for compacted anchor points | |
338 if numBuffs == 0 then | |
339 anchor.cutout_X = 0 | |
340 anchor.cutout_Y = 0 | |
341 anchor.outer_X = 0 | |
342 anchor.outer_Y = 0 | |
343 elseif numBuffs <= buffMax then | |
344 local sX, sY = guides[buffName][numBuffs]:GetWidth(), guides[buffName][numBuffs]:GetHeight() | |
345 local p = c.PerRow | |
346 local lX = mod(numBuffs, p) | |
347 local lY = floor(numBuffs / p) | |
348 local oX = min(numBuffs, c.PerRow) | |
349 local oY = ceil(numBuffs / p) | |
350 anchor.cutout_X = lX * sX + lX * c.Spacing -- max clearance to fit alongside the row | |
351 anchor.cutout_Y = lY * sY + lY * c.Spacing | |
352 anchor.outer_Y = oY * sY + oY * c.Spacing -- distance of farthest row | |
353 anchor.outer_X = oX * sX + oX * c.Spacing | |
354 | |
355 | |
356 print('|cFF0088FF', 'inner corner', lX, lY, 'outer corners', oX, oY) | |
357 print('cutout delta =', anchor.cutout_X, anchor.cutout_Y, 'out of', floor(anchor:GetWidth()), floor(anchor:GetHeight())) | |
358 print('extent delta =', anchor.outer_X, anchor.outer_Y) | |
359 else | |
360 anchor.cutout_X = 0 | |
361 anchor.cutout_Y = 0 | |
362 anchor.outer_X = 0 | |
363 anchor.outer_Y = 0 | |
364 end | |
365 | |
366 if anchor.attached then | |
367 M.UpdateAnchorChild(anchor, anchor.attached, anchor.attachmentConf) | |
368 end | |
369 | |
370 end | |
371 | |
372 M.PostBuffAnchors = function() | |
373 local print = fprint() | |
374 if M.ShowConsolidatedBuffs then | |
375 M.UpdateRaidBuffs() | |
376 end | |
377 for buttonName, auraType in pairs(displays) do | |
378 print('sending', buttonName, auraType) | |
379 -- if waiting for anchors | |
380 if not anchors[buttonName] then | |
381 return | |
382 end | |
383 | |
384 --if positioned[buttonName] == 0 then | |
385 print('possibly reloaded UI, check positions') | |
386 M.UpdateGuideFrames(buttonName) | |
387 --end | |
388 | |
389 M.UpdateButtonPositions(buttonName, auraType) | |
390 end | |
391 end | |
392 | |
393 M.UpdateBuffs = function(buttonName, forced) | |
394 local print = B.fprint(buttonName) | |
395 local c = displays[buttonName].conf | |
396 if drawn[buttonName] then | |
397 wipe(drawn[buttonName]) | |
398 else | |
399 drawn[buttonName] = {} | |
400 end | |
401 | |
402 M.UpdateAnchorFrames(buttonName) | |
403 M.UpdateGuideFrames(buttonName) | |
404 M.UpdateButtonPositions(buttonName, displays[buttonName]) | |
405 end | |
406 | |
407 --- should only be called from user input | |
408 print('init def') | |
409 function M:OnInitialize () | |
410 drawn = B.Abstract(B.displays, 'drawn') | |
411 -- Lesser extent of guide frames that have been positioned | |
412 positioned = B.Abstract(B.displays, 'positioned', positioned) | |
413 -- Backdrop style frame | |
414 decors = B.Abstract(B.displays, 'decorator', decors) | |
415 -- Static positioning frames | |
416 guides = B.Abstract(B.displays, 'guides', guides) | |
417 -- Anchor points for guides | |
418 anchors = B.Abstract(B.displays, 'anchor') | |
419 -- Stored functions for doing icon texture adjustments | |
420 zoom = B.Abstract(B.displays, 'zoom', zoom) | |
421 | |
422 B:RegisterUnitEvent("UNIT_AURA", "player", "vehicle") | |
423 B:RegisterEvent("GROUP_ROSTER_UPDATE") | |
424 B:RegisterEvent("PLAYER_SPECIALIZATION_CHANGED") | |
425 hooksecurefunc("BuffFrame_UpdateAllBuffAnchors", M.PostBuffAnchors) | |
426 hooksecurefunc("RaidBuffTray_Update", M.UpdateRaidBuffs) | |
427 end | |
428 print('update def') | |
429 function M:OnUpdate () | |
430 M.ShowConsolidated = (IsInGroup() and GetCVarBool("consolidateBuffs")) | |
431 M.ShowMissingBuffs = (IsInGroup() and B.Conf.RaidShowMissing) | |
432 | |
433 for name, auraType in pairs(displays) do | |
434 print(name, auraType) | |
435 M.UpdateBuffs(auraType.buffName, true) | |
436 end | |
437 | |
438 M.UpdateAnchorAnchors() | |
439 M.UpdateRaidBuffs() | |
440 M.UpdateBuffsTodo() | |
441 end |