Mercurial > wow > buffalo2
comparison Modules/BuffFrame.lua @ 86:48182978d1c6
- revert count info to non-hook method; something spam fires Hide making stacking debuffs unintelligible
- implement config variables for position and anchoring of buff sub-regions
author | Nenue |
---|---|
date | Tue, 18 Oct 2016 19:53:24 -0400 |
parents | 16b300d96724 |
children | 6e2cb847c3c6 |
comparison
equal
deleted
inserted
replaced
85:1196b8175674 | 86:48182978d1c6 |
---|---|
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 local BUFFS_PER_ROW = 12 | 14 local BUFFS_PER_ROW = 12 |
15 local BUFF_BUTTON_SIZE = 48 | 15 local BUFF_BUTTON_SIZE = 48 |
16 local BUFF_BUTTON_SPACING_H = 4 | 16 local BUFF_BUTTON_SPACING_H = 5 |
17 local BUFF_BUTTON_SPACING_V = 14 | 17 local BUFF_BUTTON_SPACING_V = 14 |
18 local BUFF_PROGRESS_SIZE = 4 | 18 local BUFF_PROGRESS_SIZE = 4 |
19 local BUFF_PROGRESS_INSET = 1 | 19 local BUFF_PROGRESS_INSET = 2 |
20 local PROGRESS_ANCHOR = 'BOTTOM' | |
21 local PROGRESS_PARENT | |
22 local PROGRESS_OFFSET = 1 | |
23 | |
20 local BUFF_BUTTON_ZOOM = .15 | 24 local BUFF_BUTTON_ZOOM = .15 |
21 local BORDER_SIZE_L = 1 | 25 local BORDER_SIZE_L = 2 |
22 local BORDER_SIZE_R = 1 | 26 local BORDER_SIZE_R = 2 |
23 local BORDER_SIZE_U = 1 | 27 local BORDER_SIZE_U = 2 |
24 local BORDER_SIZE_D = 1 | 28 local BORDER_SIZE_D = 2 |
25 local BUFF_FRAMES_X = -230 | 29 local BUFF_FRAMES_X = -230 |
26 local BUFF_FRAMES_Y = -4 | 30 local BUFF_FRAMES_Y = -4 |
31 | |
32 local COUNT_ANCHOR = 'TOPRIGHT' | |
33 local COUNT_INSET = 4 | |
34 local COUNT_PARENT | |
35 | |
36 local DURATION_ANCHOR = 'BOTTOMLEFT' | |
37 local DURATION_INSET = 4 | |
38 local DURATION_PARENT | |
27 | 39 |
28 VeneerBuffFrameMixin = { | 40 VeneerBuffFrameMixin = { |
29 moduleName = 'Buff Frames', | 41 moduleName = 'Buff Frames', |
30 defaultCluster = 'TOPRIGHT', | 42 defaultCluster = 'TOPRIGHT', |
31 Buttons = {}, | 43 Buttons = {}, |
73 min = 0, | 85 min = 0, |
74 max = 16, | 86 max = 16, |
75 } | 87 } |
76 } | 88 } |
77 | 89 |
90 local OFFSET_PARALLELS = { | |
91 TOP = {'LEFT', 'RIGHT', 'SetHeight'}, | |
92 BOTTOM = {'LEFT', 'RIGHT', 'SetHeight'}, | |
93 LEFT = {'TOP', 'BOTTOM', 'SetWidth'}, | |
94 RIGHT = {'TOP', 'BOTTOM', 'SetWidth'}, | |
95 } | |
96 local ANCHOR_OFFSET_POINT = { | |
97 TOP = 'BOTTOM', | |
98 TOPLEFT = 'BOTTOMRIGHT', | |
99 TOPRIGHT = 'BOTTOMLEFT', | |
100 LEFT = 'RIGHT', | |
101 RIGHT = 'LEFT', | |
102 CENTER = 'CENTER', | |
103 BOTTOM = 'TOP', | |
104 BOTTOMRIGHT = 'TOPLEFT', | |
105 BOTTOMLEFT = 'TOPRIGHT', | |
106 } | |
107 local ANCHOR_INSET_DELTA = { | |
108 TOP = {0, -1}, | |
109 TOPLEFT = {1, -1}, | |
110 TOPRIGHT = {-1,-1}, | |
111 LEFT = {1, 0}, | |
112 BOTTOMLEFT = {1, 1}, | |
113 BOTTOM = {0, 1}, | |
114 BOTTOMRIGHT = {-1, 1}, | |
115 RIGHT = {-1, 0}, | |
116 CENTER = {0, 0}, | |
117 } | |
78 | 118 |
79 function plugin:Acquire(target) | 119 function plugin:Acquire(target) |
80 | 120 |
81 local frame = self.Buttons[target] | 121 local frame = self.Buttons[target] |
82 if not (self.Buttons[target]) then | 122 if not (self.Buttons[target]) then |
84 local id = target:GetID() | 124 local id = target:GetID() |
85 print('|cFF88FF00Creating', name,'Veneer') | 125 print('|cFF88FF00Creating', name,'Veneer') |
86 | 126 |
87 frame = vn:Acquire(target, 'VeneerBuffTemplate') | 127 frame = vn:Acquire(target, 'VeneerBuffTemplate') |
88 | 128 |
89 frame.progress:SetHeight(BUFF_PROGRESS_SIZE + (BUFF_PROGRESS_INSET * 2)) | 129 frame.progress[OFFSET_PARALLELS[PROGRESS_ANCHOR][3]](frame.progress, BUFF_PROGRESS_SIZE + (BUFF_PROGRESS_INSET * 2)) |
130 print(BUFF_PROGRESS_SIZE + (BUFF_PROGRESS_INSET * 2)) | |
131 | |
132 frame.progress:ClearAllPoints() | |
133 frame.progress:SetPoint(ANCHOR_OFFSET_POINT[PROGRESS_ANCHOR], PROGRESS_PARENT or frame.border, PROGRESS_ANCHOR, | |
134 (ANCHOR_INSET_DELTA[PROGRESS_ANCHOR][1] * PROGRESS_OFFSET * -1), | |
135 (ANCHOR_INSET_DELTA[PROGRESS_ANCHOR][2] * PROGRESS_OFFSET * -1)) | |
136 frame.progress:SetPoint(OFFSET_PARALLELS[PROGRESS_ANCHOR][1], frame.border, OFFSET_PARALLELS[PROGRESS_ANCHOR][1], 0, 0) | |
137 frame.progress:SetPoint(OFFSET_PARALLELS[PROGRESS_ANCHOR][2], frame.border, OFFSET_PARALLELS[PROGRESS_ANCHOR][2], 0, 0) | |
138 | |
139 print(frame.progress:GetPoint(1)) | |
140 print(frame.progress:GetPoint(2)) | |
141 print(frame.progress:GetPoint(3)) | |
142 frame.progress:Show() | |
143 | |
144 frame.progress.bg:ClearAllPoints() | |
145 frame.progress.bg:SetAllPoints(frame.progress) | |
90 | 146 |
91 frame.progress.fg:ClearAllPoints() | 147 frame.progress.fg:ClearAllPoints() |
92 frame.progress.fg:SetPoint('BOTTOMLEFT', BUFF_PROGRESS_INSET,BUFF_PROGRESS_INSET) | 148 frame.progress.fg:SetPoint('BOTTOMLEFT', BUFF_PROGRESS_INSET,BUFF_PROGRESS_INSET) |
93 frame.progress.fg:SetPoint('TOP', 0, -BUFF_PROGRESS_INSET) | 149 frame.progress.fg:SetPoint('TOP', 0, -BUFF_PROGRESS_INSET) |
94 | 150 --frame.count:ClearAllPoints() |
151 --frame.count:SetPoint('TOPRIGHT', frame,'TOPRIGHT', -3, -3) | |
152 | |
153 | |
154 frame.duration:ClearAllPoints() | |
155 frame.duration:SetPoint(DURATION_ANCHOR, DURATION_PARENT or frame, DURATION_ANCHOR, | |
156 (ANCHOR_INSET_DELTA[DURATION_ANCHOR][1] * DURATION_INSET), | |
157 (ANCHOR_INSET_DELTA[DURATION_ANCHOR][2] * DURATION_INSET)) | |
158 | |
159 frame.count:ClearAllPoints() | |
160 frame.count:SetPoint(COUNT_ANCHOR, COUNT_PARENT or frame, COUNT_ANCHOR, | |
161 (ANCHOR_INSET_DELTA[COUNT_ANCHOR][1] * COUNT_INSET), | |
162 (ANCHOR_INSET_DELTA[COUNT_ANCHOR][2] * COUNT_INSET)) | |
95 | 163 |
96 frame.underlay:SetParent(UIParent) | 164 frame.underlay:SetParent(UIParent) |
97 frame.underlay:SetFrameStrata('BACKGROUND') | 165 frame.underlay:SetFrameStrata('BACKGROUND') |
98 frame.border:SetColorTexture(0,0,0,1) | 166 frame.border:SetColorTexture(0,0,0,1) |
99 frame.border:SetPoint('TOPLEFT', frame, 'TOPLEFT', -BORDER_SIZE_L, BORDER_SIZE_U) | 167 frame.border:SetPoint('TOPLEFT', frame, 'TOPLEFT', -BORDER_SIZE_L, BORDER_SIZE_U) |
122 _G['TempEnchant'..i..'Border']:SetVertexColor(0.5,0,1,1) | 190 _G['TempEnchant'..i..'Border']:SetVertexColor(0.5,0,1,1) |
123 end | 191 end |
124 end | 192 end |
125 -- Associates skinning elements with said button | 193 -- Associates skinning elements with said button |
126 local surrogates = { | 194 local surrogates = { |
127 Show = false, | 195 ['Show'] = false, |
128 Hide = false, | 196 ['Hide'] = false, |
129 SetText = false, | 197 ['SetText'] = false, |
130 SetVertexColor = function(surrogate, frame, r, g, b, a) | 198 ['SetVertexColor'] = function(self, region, r, g, b, a) |
131 frame:Hide() | 199 if not self.progress then |
132 print('|cFF0088FFborder:SetVertexColor|r', r,g,b,a) | 200 return |
133 surrogate.progress.fg:SetColorTexture(r,g,b,a) | 201 end |
134 surrogate.border:Show() | 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() | |
135 end, | 208 end, |
136 } | 209 } |
137 local DoRegionHooks = function (veneer, region) | 210 local DoRegionHooks = function (veneer, region) |
138 | 211 |
139 if region then | 212 if region then |
140 print('hooking', region:GetName()) | 213 --print('hooking', region:GetName()) |
141 region:ClearAllPoints() | 214 region:ClearAllPoints() |
142 for method, callback in ipairs(surrogates) do | 215 for method, callback in pairs(surrogates) do |
143 print(method, callback) | 216 if type(region[method]) == 'function' then |
144 if region[method] then | 217 |
218 --print(method, type(callback)) | |
145 local func | 219 local func |
146 if callback then | 220 if callback then |
147 print('hooking', region:GetName(), method) | 221 func = function(self, ...) |
148 func = function(self,...) | 222 --tprint('|cFF00FFFF'.. region:GetName().. ':', method) |
149 print(self:GetName(), ':', method) | 223 region:ClearAllPoints() |
150 self:ClearAllPoints() | 224 callback(veneer, region, ...) |
151 veneer[method](...) | |
152 end | 225 end |
153 else | 226 else |
154 func = function(self, ...) | 227 func = function(self,...) |
228 tprint('|cFF0088FF'.. self:GetName().. ':', method) | |
155 self:ClearAllPoints() | 229 self:ClearAllPoints() |
156 callback(veneer, region, ...) | 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 | |
157 end | 241 end |
158 end | 242 end |
159 hooksecurefunc(region, method, callback) | 243 if func then |
244 --print('hooking', region:GetName(), method) | |
245 hooksecurefunc(region, method, func) | |
246 | |
247 end | |
160 end | 248 end |
161 end | 249 end |
162 end | 250 end |
163 end | 251 end |
164 | 252 |
165 | 253 |
166 function plugin:SetupButton (name) | 254 function plugin:SetupButton (name) |
167 local frame = _G[name ] | 255 local frame = _G[name ] |
168 if self.DetectedFrames[frame] then | 256 if self.DetectedFrames[frame] then |
169 print('|cFFFF4400Attempting to skin a frame that already went through.|r') | 257 --print('|cFFFF4400Attempting to skin a frame that already went through.|r') |
170 return | 258 return |
171 end | 259 end |
172 print('|cFFFFFF00Adopting', name) | 260 --print('|cFFFFFF00Adopting', name) |
173 | 261 |
174 local icon = _G[name .. 'Icon'] | 262 local icon = _G[name .. 'Icon'] |
175 local border = _G[name .. 'Border'] | 263 local border = _G[name .. 'Border'] |
176 local count = _G[name .. 'Count'] | 264 local count = _G[name .. 'Count'] |
177 local duration = _G[name .. 'Duration'] | 265 local duration = _G[name .. 'Duration'] |
181 self.DetectedFrames[frame] = frame | 269 self.DetectedFrames[frame] = frame |
182 frame:SetSize(BUFF_BUTTON_SIZE,BUFF_BUTTON_SIZE) | 270 frame:SetSize(BUFF_BUTTON_SIZE,BUFF_BUTTON_SIZE) |
183 icon:SetTexCoord(offset, 1 - offset, offset, 1 - offset) | 271 icon:SetTexCoord(offset, 1 - offset, offset, 1 - offset) |
184 | 272 |
185 | 273 |
274 | |
186 DoRegionHooks(veneer, border) | 275 DoRegionHooks(veneer, border) |
187 DoRegionHooks(veneer.duration, duration) | |
188 DoRegionHooks(veneer.count, count) | |
189 if border then | 276 if border then |
190 local color = DebuffTypeColor["none"] | 277 local color = DebuffTypeColor["none"] |
191 if aurasCache[frame] and aurasCache[frame][5] then | 278 if aurasCache[frame] and aurasCache[frame][5] then |
192 color = DebuffTypeColor[aurasCache[frame][5]] | 279 color = DebuffTypeColor[aurasCache[frame][5]] |
193 end | 280 end |
197 else | 284 else |
198 veneer.border:SetColorTexture(0,0,0,1) | 285 veneer.border:SetColorTexture(0,0,0,1) |
199 veneer.border:Show() | 286 veneer.border:Show() |
200 end | 287 end |
201 | 288 |
289 if count and count:GetText() then | |
290 count:ClearAllPoints() | |
291 veneer.count:SetText(count:GetText()) | |
292 end | |
293 if duration then | |
294 duration:ClearAllPoints() | |
295 end | |
296 | |
297 | |
298 | |
202 | 299 |
203 hooksecurefunc(frame, "Hide", function(self) | 300 hooksecurefunc(frame, "Hide", function(self) |
204 local isVisible = self:IsVisible() | 301 local isVisible = self:IsVisible() |
205 if isVisible ~= visibility[self] then | 302 if isVisible ~= visibility[self] then |
206 visibility[self] = isVisible | 303 visibility[self] = isVisible |
227 local veneer = self:Acquire(frame) | 324 local veneer = self:Acquire(frame) |
228 -- is it a new button? | 325 -- is it a new button? |
229 if not self.DetectedFrames[frame] then | 326 if not self.DetectedFrames[frame] then |
230 self:SetupButton(frame:GetName()) | 327 self:SetupButton(frame:GetName()) |
231 end | 328 end |
329 | |
330 --[[ | |
331 if frame.count then | |
332 frame.count:SetText('test') | |
333 frame.count:Show() | |
334 end | |
335 --]] | |
336 local name, rank, icon, count, _, duration, expires = UnitAura(frame.unit, frame:GetID(), frame.filter) | |
232 | 337 |
233 | 338 |
234 if expires and duration then | 339 if expires and duration then |
235 if duration ~= 0 then | 340 if duration ~= 0 then |
236 local startTime = (expires - duration) | 341 local startTime = (expires - duration) |
266 print('|cFF00FF88'..frame:GetName()..'|r', 'duration zero') | 371 print('|cFF00FF88'..frame:GetName()..'|r', 'duration zero') |
267 veneer.progress:SetScript('OnUpdate', nil) | 372 veneer.progress:SetScript('OnUpdate', nil) |
268 veneer.progress:Hide() | 373 veneer.progress:Hide() |
269 veneer.cooldown:Hide() | 374 veneer.cooldown:Hide() |
270 end | 375 end |
376 | |
377 if count and count >= 1 then | |
378 veneer.count:SetText(count) | |
379 veneer.count:Show() | |
380 else | |
381 veneer.count:Hide() | |
382 end | |
383 | |
384 | |
271 else | 385 else |
272 veneer.progress:Hide() | 386 veneer.progress:Hide() |
273 veneer.cooldown:SetCooldown(0,0) | 387 veneer.cooldown:SetCooldown(0,0) |
274 veneer.cooldown:Hide() | 388 veneer.cooldown:Hide() |
275 print('|cFF88FF00'..frame:GetName()..'|r', 'nil duration') | 389 print('|cFF88FF00'..frame:GetName()..'|r', 'nil duration') |
295 | 409 |
296 function plugin:OnAuraButton_Update (name, index, filter) | 410 function plugin:OnAuraButton_Update (name, index, filter) |
297 local bName = name..index | 411 local bName = name..index |
298 local frame = _G[bName] | 412 local frame = _G[bName] |
299 if frame and frame:IsVisible() then | 413 if frame and frame:IsVisible() then |
300 local cacheDiff = self:ButtonHasChanged(frame, UnitAura(frame.unit, frame:GetID(), frame.filter)) | |
301 -- if the name or expirationTime changed | 414 -- if the name or expirationTime changed |
302 if (cacheDiff >= 1) then | 415 |
303 print('|cFFFF4400', frame:GetName(), 'diff:', cacheDiff) | |
304 if not skinnedFrames[frame] then | 416 if not skinnedFrames[frame] then |
305 tinsert(pendingFrames, frame) | 417 tinsert(pendingFrames, frame) |
306 end | 418 end |
307 expirationCache[name] = frame.expirationTime | 419 expirationCache[name] = frame.expirationTime |
308 print(unpack(aurasCache[frame])) | 420 self:UpdateButton(frame) |
309 | 421 |
310 self:UpdateButton(frame, aurasCache[frame][6], aurasCache[frame][7]) | |
311 end | |
312 | 422 |
313 end | 423 end |
314 end | 424 end |
315 | 425 |
316 function plugin:OnUpdateAllBuffAnchors () | 426 function plugin:OnUpdateAllBuffAnchors () |
407 if veneer.duration.getHuge then | 517 if veneer.duration.getHuge then |
408 veneer.duration.getHuge = nil | 518 veneer.duration.getHuge = nil |
409 veneer.duration:SetFontObject(VeneerNumberFont) | 519 veneer.duration:SetFontObject(VeneerNumberFont) |
410 veneer.duration:SetTextColor(1,1,1,1) | 520 veneer.duration:SetTextColor(1,1,1,1) |
411 end | 521 end |
412 | 522 end |
413 end | |
414 | |
415 | 523 |
416 veneer.duration:SetText(timeString) | 524 veneer.duration:SetText(timeString) |
417 end | 525 end |
418 | 526 |
419 | 527 |