Mercurial > wow > buffalo2
comparison Modules/BuffFrame.lua @ 90:6e2cb847c3c6
Implement a mixin template for the basic visual config widgets.
author | Nenue |
---|---|
date | Mon, 24 Oct 2016 18:28:40 -0400 |
parents | 48182978d1c6 |
children | caded2668701 |
comparison
equal
deleted
inserted
replaced
89:74e714637d6a | 90:6e2cb847c3c6 |
---|---|
8 Known Limitations: | 8 Known Limitations: |
9 - Individual BuffButton frames are created upon use, making it difficult to do any sort of securestate priming | 9 - Individual BuffButton frames are created upon use, making it difficult to do any sort of securestate priming |
10 - TempEnchant info returns relative values only, and they don't synchronize with aura events | 10 - TempEnchant info returns relative values only, and they don't synchronize with aura events |
11 - BuffButtons can only be hidden/shown by blizzcode, so functions doing that have to be accounted for | 11 - BuffButtons can only be hidden/shown by blizzcode, so functions doing that have to be accounted for |
12 --]] | 12 --]] |
13 | |
13 | 14 |
14 local BUFFS_PER_ROW = 12 | 15 local BUFFS_PER_ROW = 12 |
15 local BUFF_BUTTON_SIZE = 48 | 16 local BUFF_BUTTON_SIZE = 48 |
16 local BUFF_BUTTON_SPACING_H = 5 | 17 local BUFF_BUTTON_SPACING_H = 5 |
17 local BUFF_BUTTON_SPACING_V = 14 | 18 local BUFF_BUTTON_SPACING_V = 14 |
38 local DURATION_PARENT | 39 local DURATION_PARENT |
39 | 40 |
40 VeneerBuffFrameMixin = { | 41 VeneerBuffFrameMixin = { |
41 moduleName = 'Buff Frames', | 42 moduleName = 'Buff Frames', |
42 defaultCluster = 'TOPRIGHT', | 43 defaultCluster = 'TOPRIGHT', |
44 anchorX = BUFF_FRAMES_X, | |
45 anchorY = BUFF_FRAMES_Y, | |
46 anchorPoint = 'TOPRIGHT', | |
43 Buttons = {}, | 47 Buttons = {}, |
44 DetectedFrames = {}, | 48 DetectedFrames = {}, |
45 AuraCache = {} | 49 AuraCache = {} |
50 } | |
51 VeneerBuffFrameButtonMixin = { | |
46 } | 52 } |
47 local plugin = VeneerBuffFrameMixin | 53 local plugin = VeneerBuffFrameMixin |
48 | 54 |
49 local vn = Veneer | 55 local vn = Veneer |
50 local print = DEVIAN_WORKSPACE and function(...) _G.print('BuffFrame', ...) end or function() end | 56 local print = DEVIAN_WORKSPACE and function(...) _G.print('BuffFrame', ...) end or function() end |
114 BOTTOMRIGHT = {-1, 1}, | 120 BOTTOMRIGHT = {-1, 1}, |
115 RIGHT = {-1, 0}, | 121 RIGHT = {-1, 0}, |
116 CENTER = {0, 0}, | 122 CENTER = {0, 0}, |
117 } | 123 } |
118 | 124 |
119 function plugin:Acquire(target) | 125 -- Associates skinning elements with said button |
126 local surrogates = { | |
127 ['Show'] = false, | |
128 ['Hide'] = false, | |
129 ['SetText'] = false, | |
130 ['SetVertexColor'] = function(self, region, r, g, b, a) | |
131 if not self.progress then | |
132 return | |
133 end | |
134 | |
135 region:Hide() | |
136 tprint('|cFF0088FFborder:SetVertexColor|r', r,g,b,a) | |
137 self.progress.fg:SetColorTexture(r,g,b,a) | |
138 self.border:SetColorTexture(r,g,b,a) | |
139 self.border:Show() | |
140 end, | |
141 } | |
142 local DoRegionHooks = function (veneer, region) | |
143 | |
144 if region then | |
145 --print('hooking', region:GetName()) | |
146 region:ClearAllPoints() | |
147 for method, callback in pairs(surrogates) do | |
148 if type(region[method]) == 'function' then | |
149 | |
150 --print(method, type(callback)) | |
151 local func | |
152 if callback then | |
153 hooksecurefunc(region, method, function(self, ...) | |
154 --tprint('|cFF00FFFF'.. region:GetName().. ':', method) | |
155 region:ClearAllPoints() | |
156 callback(veneer, region, ...) | |
157 end) | |
158 else | |
159 hooksecurefunc(region, method, function(self,...) | |
160 tprint('|cFF0088FF'.. self:GetName().. ':', method) | |
161 self:ClearAllPoints() | |
162 veneer:Show() | |
163 veneer[method](veneer, ...) | |
164 | |
165 if self:GetName():match('Debuff.+Count') then | |
166 | |
167 print('|cFF00FFFF'.. self:GetName().. ':'.. method, '->', veneer:GetName()..':'..method..'(', ...,')') | |
168 print(veneer:IsVisible(),veneer:GetStringWidth(),veneer:GetText()) | |
169 print(veneer:GetTop(), veneer:GetLeft()) | |
170 print(veneer:GetPoint(1)) | |
171 end | |
172 | |
173 end) | |
174 end | |
175 end | |
176 end | |
177 end | |
178 end | |
179 function VeneerBuffFrameMixin:Acquire(target) | |
120 | 180 |
121 local frame = self.Buttons[target] | 181 local frame = self.Buttons[target] |
122 if not (self.Buttons[target]) then | 182 if not (self.Buttons[target]) then |
123 local name = target:GetName() | 183 local name = target:GetName() |
124 local id = target:GetID() | 184 local id = target:GetID() |
171 self.Buttons[target] = frame | 231 self.Buttons[target] = frame |
172 end | 232 end |
173 return frame | 233 return frame |
174 end | 234 end |
175 | 235 |
176 function plugin:OnLoad() | 236 function VeneerBuffFrameMixin:OnLoad() |
177 Veneer:AddHandler(self, self.defaultCluster) | 237 Veneer:AddHandler(self, self.defaultCluster) |
178 end | 238 end |
179 | 239 |
180 function plugin:Setup() | 240 function VeneerBuffFrameMixin:Setup() |
181 | 241 |
182 | 242 |
183 hooksecurefunc("BuffFrame_Update", function(...) self:OnBuffFrameUpdate(...) end) | 243 hooksecurefunc("BuffFrame_Update", function(...) self:OnBuffFrameUpdate(...) end) |
184 hooksecurefunc("AuraButton_UpdateDuration", function(...) self:OnUpdateDuration(...) end) | 244 hooksecurefunc("AuraButton_UpdateDuration", function(...) self:OnUpdateDuration(...) end) |
185 hooksecurefunc("AuraButton_Update", function(...) self:OnAuraButton_Update(...) end) | 245 hooksecurefunc("AuraButton_Update", function(...) self:OnAuraButton_Update(...) end) |
188 for i = 1, 3 do | 248 for i = 1, 3 do |
189 self:SetupButton('TempEnchant'..i) | 249 self:SetupButton('TempEnchant'..i) |
190 _G['TempEnchant'..i..'Border']:SetVertexColor(0.5,0,1,1) | 250 _G['TempEnchant'..i..'Border']:SetVertexColor(0.5,0,1,1) |
191 end | 251 end |
192 end | 252 end |
193 -- Associates skinning elements with said button | 253 |
194 local surrogates = { | 254 |
195 ['Show'] = false, | 255 function VeneerBuffFrameMixin:SetupButton (name) |
196 ['Hide'] = false, | |
197 ['SetText'] = false, | |
198 ['SetVertexColor'] = function(self, region, r, g, b, a) | |
199 if not self.progress then | |
200 return | |
201 end | |
202 | |
203 region:Hide() | |
204 tprint('|cFF0088FFborder:SetVertexColor|r', r,g,b,a) | |
205 self.progress.fg:SetColorTexture(r,g,b,a) | |
206 self.border:SetColorTexture(r,g,b,a) | |
207 self.border:Show() | |
208 end, | |
209 } | |
210 local DoRegionHooks = function (veneer, region) | |
211 | |
212 if region then | |
213 --print('hooking', region:GetName()) | |
214 region:ClearAllPoints() | |
215 for method, callback in pairs(surrogates) do | |
216 if type(region[method]) == 'function' then | |
217 | |
218 --print(method, type(callback)) | |
219 local func | |
220 if callback then | |
221 func = function(self, ...) | |
222 --tprint('|cFF00FFFF'.. region:GetName().. ':', method) | |
223 region:ClearAllPoints() | |
224 callback(veneer, region, ...) | |
225 end | |
226 else | |
227 func = function(self,...) | |
228 tprint('|cFF0088FF'.. self:GetName().. ':', method) | |
229 self:ClearAllPoints() | |
230 veneer:Show() | |
231 veneer[method](veneer, ...) | |
232 | |
233 if self:GetName():match('Debuff.+Count') then | |
234 | |
235 print('|cFF00FFFF'.. self:GetName().. ':'.. method, '->', veneer:GetName()..':'..method..'(', ...,')') | |
236 print(veneer:IsVisible(),veneer:GetStringWidth(),veneer:GetText()) | |
237 print(veneer:GetTop(), veneer:GetLeft()) | |
238 print(veneer:GetPoint(1)) | |
239 end | |
240 | |
241 end | |
242 end | |
243 if func then | |
244 --print('hooking', region:GetName(), method) | |
245 hooksecurefunc(region, method, func) | |
246 | |
247 end | |
248 end | |
249 end | |
250 end | |
251 end | |
252 | |
253 | |
254 function plugin:SetupButton (name) | |
255 local frame = _G[name ] | 256 local frame = _G[name ] |
256 if self.DetectedFrames[frame] then | 257 if self.DetectedFrames[frame] then |
257 --print('|cFFFF4400Attempting to skin a frame that already went through.|r') | 258 --print('|cFFFF4400Attempting to skin a frame that already went through.|r') |
258 return | 259 return |
259 end | 260 end |
318 | 319 |
319 end | 320 end |
320 | 321 |
321 | 322 |
322 --- Set widgets to reflect the passed parameters | 323 --- Set widgets to reflect the passed parameters |
323 function plugin:UpdateButton (frame, duration, expires) | 324 function VeneerBuffFrameMixin:UpdateButton (frame, duration, expires) |
324 local veneer = self:Acquire(frame) | 325 local veneer = self:Acquire(frame) |
325 -- is it a new button? | 326 -- is it a new button? |
326 if not self.DetectedFrames[frame] then | 327 if not self.DetectedFrames[frame] then |
327 self:SetupButton(frame:GetName()) | 328 self:SetupButton(frame:GetName()) |
328 end | 329 end |
372 veneer.progress:SetScript('OnUpdate', nil) | 373 veneer.progress:SetScript('OnUpdate', nil) |
373 veneer.progress:Hide() | 374 veneer.progress:Hide() |
374 veneer.cooldown:Hide() | 375 veneer.cooldown:Hide() |
375 end | 376 end |
376 | 377 |
377 if count and count >= 1 then | 378 if count and count > 1 then |
378 veneer.count:SetText(count) | 379 veneer.count:SetText(count) |
379 veneer.count:Show() | 380 veneer.count:Show() |
381 frame.count:ClearAllPoints() | |
380 else | 382 else |
381 veneer.count:Hide() | 383 veneer.count:Hide() |
382 end | 384 end |
383 | 385 |
384 | 386 |
391 veneer:Show() | 393 veneer:Show() |
392 end | 394 end |
393 | 395 |
394 | 396 |
395 --- Provides the number of changed indices for use in deciding between partial and full veneer updates | 397 --- Provides the number of changed indices for use in deciding between partial and full veneer updates |
396 function plugin:ButtonHasChanged (frame, ...) | 398 function VeneerBuffFrameMixin:ButtonHasChanged (frame, ...) |
397 aurasCache[frame] = aurasCache[frame] or {} | 399 aurasCache[frame] = aurasCache[frame] or {} |
398 local hasChange = 0 | 400 local hasChange = 0 |
399 local numVals = select('#',...) | 401 local numVals = select('#',...) |
400 for i = 1, numVals do | 402 for i = 1, numVals do |
401 local arg = select(i, ...) | 403 local arg = select(i, ...) |
405 aurasCache[frame][i] = arg | 407 aurasCache[frame][i] = arg |
406 end | 408 end |
407 return hasChange | 409 return hasChange |
408 end | 410 end |
409 | 411 |
410 function plugin:OnAuraButton_Update (name, index, filter) | 412 function VeneerBuffFrameMixin:OnAuraButton_Update (name, index, filter) |
411 local bName = name..index | 413 local bName = name..index |
412 local frame = _G[bName] | 414 local frame = _G[bName] |
413 if frame and frame:IsVisible() then | 415 if frame and frame:IsVisible() then |
414 -- if the name or expirationTime changed | 416 -- if the name or expirationTime changed |
415 | 417 |
421 | 423 |
422 | 424 |
423 end | 425 end |
424 end | 426 end |
425 | 427 |
426 function plugin:OnUpdateAllBuffAnchors () | 428 function VeneerBuffFrameMixin:OnUpdateAllBuffAnchors () |
427 local todo = {} | 429 local todo = {} |
428 if #pendingFrames >= 1 then | 430 if #pendingFrames >= 1 then |
429 | 431 |
430 print('|cFFBBFF00AllBuffAnchors|r', #pendingFrames) | 432 print('|cFFBBFF00AllBuffAnchors|r', #pendingFrames) |
431 while pendingFrames[1] do | 433 while pendingFrames[1] do |
444 TempEnchant1:SetPoint('TOPRIGHT', BuffButton1, 'TOPRIGHT', BuffButton1:GetWidth()+4, 0) | 446 TempEnchant1:SetPoint('TOPRIGHT', BuffButton1, 'TOPRIGHT', BuffButton1:GetWidth()+4, 0) |
445 end | 447 end |
446 | 448 |
447 local lastBuff, topBuff | 449 local lastBuff, topBuff |
448 local numBuffs = 0 | 450 local numBuffs = 0 |
451 local numColumns = 1 | |
452 local maxColumn = 1 | |
449 for i = 1, BUFF_ACTUAL_DISPLAY do | 453 for i = 1, BUFF_ACTUAL_DISPLAY do |
450 local buff = _G['BuffButton'..i] | 454 local buff = _G['BuffButton'..i] |
451 if buff then | 455 if buff then |
452 numBuffs = numBuffs + 1 | 456 numBuffs = numBuffs + 1 |
453 buff:ClearAllPoints() | 457 buff:ClearAllPoints() |
454 if mod(numBuffs,BUFFS_PER_ROW) == 1 then | 458 if mod(numBuffs,BUFFS_PER_ROW) == 1 then |
455 if numBuffs == 1 then | 459 if numBuffs == 1 then |
456 buff:SetPoint('TOPRIGHT', UIParent, 'TOPRIGHT', BUFF_FRAMES_X, BUFF_FRAMES_Y) | 460 buff:SetPoint('TOPRIGHT', UIParent, 'TOPRIGHT', BUFF_FRAMES_X, BUFF_FRAMES_Y) |
457 plugin.currentTop = buff:GetTop() | 461 plugin.currentTop = buff |
458 else | 462 else |
459 buff:SetPoint('TOPRIGHT', topBuff, 'BOTTOMRIGHT', 0, -BUFF_BUTTON_SPACING_V) | 463 buff:SetPoint('TOPRIGHT', topBuff, 'BOTTOMRIGHT', 0, -BUFF_BUTTON_SPACING_V) |
460 end | 464 end |
465 numColumns = 1 | |
461 topBuff = buff | 466 topBuff = buff |
462 else | 467 else |
463 buff:SetPoint('TOPRIGHT', lastBuff, 'TOPLEFT', -BUFF_BUTTON_SPACING_H, 0) | 468 buff:SetPoint('TOPRIGHT', lastBuff, 'TOPLEFT', -BUFF_BUTTON_SPACING_H, 0) |
469 numColumns = numColumns + 1 | |
470 end | |
471 if numColumns > maxColumn then | |
472 maxColumn = numColumns | |
473 plugin.currentLeft = buff | |
464 end | 474 end |
465 lastBuff = buff | 475 lastBuff = buff |
466 end | 476 end |
467 end | 477 end |
468 | 478 |
487 lastBuff = debuff | 497 lastBuff = debuff |
488 end | 498 end |
489 end | 499 end |
490 | 500 |
491 if lastBuff then | 501 if lastBuff then |
492 plugin.currentBottom = lastBuff:GetBottom() | 502 plugin.currentBottom = lastBuff |
493 end | 503 end |
494 end | 504 |
495 | 505 self.Background:ClearAllPoints() |
496 function plugin:OnUpdateDuration (frame, timeLeft) | 506 self.Background:SetPoint('TOPRIGHT', plugin.currentTop, 'TOPRIGHT', 4, 4) |
507 self.Background:SetPoint('BOTTOM', plugin.currentBottom, 'BOTTOM', 0, -4) | |
508 self.Background:SetPoint('LEFT', plugin.currentLeft, 'LEFT', -4, 0) | |
509 end | |
510 function VeneerBuffFrameMixin:UpdateConfigLayers (configMode) | |
511 self:SetShown(configMode) | |
512 end | |
513 function VeneerBuffFrameMixin:OnUpdateDuration (frame, timeLeft) | |
497 local veneer = self:Acquire(frame) | 514 local veneer = self:Acquire(frame) |
498 local hours = floor(timeLeft/3600) | 515 local hours = floor(timeLeft/3600) |
499 local minutes = floor(mod(timeLeft, 3600)/60) | 516 local minutes = floor(mod(timeLeft, 3600)/60) |
500 local seconds = floor(mod(timeLeft, 60)) | 517 local seconds = floor(mod(timeLeft, 60)) |
501 local timeString = '%ds' | 518 local timeString = '%ds' |
525 end | 542 end |
526 | 543 |
527 | 544 |
528 -- Obtains the first instance of Tenchant use | 545 -- Obtains the first instance of Tenchant use |
529 | 546 |
530 function plugin:OnTemporaryEnchantFrameUpdate (...) | 547 function VeneerBuffFrameMixin:OnTemporaryEnchantFrameUpdate (...) |
531 local numVals = select('#', ...) | 548 local numVals = select('#', ...) |
532 local numItems = numVals / 4 | 549 local numItems = numVals / 4 |
533 if numItems >= 1 then | 550 if numItems >= 1 then |
534 for itemIndex = numItems, 1, -1 do | 551 for itemIndex = numItems, 1, -1 do |
535 local frame = _G['TempEnchant'..itemIndex] | 552 local frame = _G['TempEnchant'..itemIndex] |
556 end | 573 end |
557 | 574 |
558 end | 575 end |
559 | 576 |
560 end | 577 end |
561 function plugin:OnBuffFrameUpdate () | 578 function VeneerBuffFrameMixin:OnBuffFrameUpdate () |
562 end | 579 end |
563 | 580 |
581 | |
582 function VeneerBuffFrameButtonMixin:OnLoad() | |
583 | |
584 self.duration = self.progress.duration | |
585 self.count = self.overlay.count | |
586 self.border = self.underlay.bg | |
587 | |
588 VeneerBuffFrame.ConfigLayers = VeneerBuffFrame.ConfigLayers or {} | |
589 self.configIndex = #VeneerBuffFrame.ConfigLayers | |
590 for i, region in ipairs(self.ConfigLayers) do | |
591 tinsert(VeneerBuffFrame.ConfigLayers, region) | |
592 end | |
593 | |
594 self.configIndexEnd = #VeneerBuffFrame.ConfigLayers | |
595 end | |
564 | 596 |
565 -- The TempEnchant frames are hardcoded in the base FrameXML, so get them now | 597 -- The TempEnchant frames are hardcoded in the base FrameXML, so get them now |
566 | 598 |