Mercurial > wow > buffalo2
comparison Modules/BuffFrame.lua @ 61:3f083d389c18
- don't send updates for BuffAnchors hook
author | Nenue |
---|---|
date | Mon, 15 Aug 2016 09:35:46 -0400 |
parents | 2a636b00c31e |
children | ef4116179e2f |
comparison
equal
deleted
inserted
replaced
60:2a636b00c31e | 61:3f083d389c18 |
---|---|
1 -- Veneer | 1 -- Veneer |
2 -- BuffFrame.lua | 2 -- BuffFrame.lua |
3 -- Created: 7/27/2016 8:08 PM | 3 -- Created: 7/27/2016 8:08 PM |
4 -- %file-revision% | 4 -- %file-revision% |
5 -- | 5 -- Adds progress bars and cooldown swirls to buffbutton frames |
6 | 6 |
7 local PLUGIN_NAME = 'BuffFrame' | 7 local PLUGIN_NAME = 'BuffFrame' |
8 local plugin = {} | 8 local plugin = {} |
9 local vn, print = LibStub("LibKraken").register(VeneerController, plugin) | 9 local vn, print = LibStub("LibKraken").register(VeneerController, plugin) |
10 | 10 |
64 local veneer = CreateFrame('Frame', name..'Veneer', UIParent) | 64 local veneer = CreateFrame('Frame', name..'Veneer', UIParent) |
65 local id = frame:GetID() | 65 local id = frame:GetID() |
66 veneer:SetAllPoints(frame) | 66 veneer:SetAllPoints(frame) |
67 veneer:SetParent(frame) | 67 veneer:SetParent(frame) |
68 veneer.bg = veneer:CreateTexture() | 68 veneer.bg = veneer:CreateTexture() |
69 veneer.bg:SetColorTexture((id / 16),0,1-(id/16),0.5) | 69 veneer.bg:SetColorTexture(1,1,1,0) |
70 print(id, id/16) | |
71 veneer.bg:SetAllPoints(veneer) | 70 veneer.bg:SetAllPoints(veneer) |
72 veneer.bg:Show() | 71 veneer.bg:Show() |
73 veneer:Hide() | 72 veneer:Hide() |
74 veneer:EnableMouse(false) | 73 veneer:EnableMouse(false) |
75 | 74 |
85 veneer.progress:Hide() | 84 veneer.progress:Hide() |
86 veneer.progress:SetPoint('BOTTOMLEFT', veneer, 'BOTTOMLEFT', 3, -6) | 85 veneer.progress:SetPoint('BOTTOMLEFT', veneer, 'BOTTOMLEFT', 3, -6) |
87 veneer.progress:SetPoint('TOPRIGHT', veneer, 'BOTTOMRIGHT', -3, -1) | 86 veneer.progress:SetPoint('TOPRIGHT', veneer, 'BOTTOMRIGHT', -3, -1) |
88 | 87 |
89 veneer.progress.bg = veneer.progress:CreateTexture(nil, 'BACKGROUND') | 88 veneer.progress.bg = veneer.progress:CreateTexture(nil, 'BACKGROUND') |
90 veneer.progress.bg:SetColorTexture(0,0,0,0.5) | 89 veneer.progress.bg:SetColorTexture(0,0,0,1) |
91 veneer.progress.bg:SetAllPoints(veneer.progress) | 90 veneer.progress.bg:SetAllPoints(veneer.progress) |
92 | 91 |
93 veneer.progress.fg = veneer.progress:CreateTexture(nil, 'ARTWORK') | 92 veneer.progress.fg = veneer.progress:CreateTexture(nil, 'ARTWORK') |
94 veneer.progress.fg:SetColorTexture(0,1,0,1) | 93 veneer.progress.fg:SetColorTexture(0,1,0,1) |
95 veneer.progress.fg:SetPoint('BOTTOMLEFT', 1,1) | 94 veneer.progress.fg:SetPoint('BOTTOMLEFT', 1,1) |
97 | 96 |
98 veneer.progress.status = veneer.progress:CreateFontString() | 97 veneer.progress.status = veneer.progress:CreateFontString() |
99 veneer.progress.status:SetFontObject(VeneerNumberFont) | 98 veneer.progress.status:SetFontObject(VeneerNumberFont) |
100 veneer.progress.status:SetPoint('TOP') | 99 veneer.progress.status:SetPoint('TOP') |
101 | 100 |
101 | |
102 veneer.cooldown = CreateFrame('Cooldown', name ..'VeneerCooldown', veneer, 'CooldownFrameTemplate') | |
103 veneer.cooldown:SetAllPoints(frame) | |
104 veneer.cooldown:SetReverse(true) | |
105 | |
102 end | 106 end |
103 | 107 |
104 | 108 |
105 return _G[name..'Veneer'] | 109 return _G[name..'Veneer'] |
106 end | 110 end |
107 | 111 |
112 --- Set widgets to reflect the passed parameters | |
108 local UpdateVeneer = function (frame, duration, expires) | 113 local UpdateVeneer = function (frame, duration, expires) |
109 local veneer = GetVeneer(frame) | 114 local veneer = GetVeneer(frame) |
110 | 115 |
111 if expires and (duration ~= 0) then | 116 if expires and duration then |
112 veneer.progress:Show() | 117 |
113 | 118 if duration ~= 0 then |
114 local startTime = (expires - duration) | 119 local startTime = (expires - duration) |
115 local endTime = expires or 0 | 120 local endTime = expires or 0 |
116 print('|cFF0088FF'..frame:GetName()..'|r', 'has expiration', startTime, 'to', endTime, 'over', duration, 'frame', veneer.progress:GetWidth()) | 121 print('|cFF0088FF'..frame:GetName()..'|r', duration, expires) |
117 veneer.progress:SetScript('OnUpdate', function(self) | 122 veneer.progress:Show() |
118 local w = floor(veneer.progress:GetWidth()+.5) | 123 veneer.elapsed = 0 |
119 local t = GetTime() | 124 veneer.progress:SetScript('OnUpdate', function(self, elapsed) |
120 local progress = (t - startTime) / duration | 125 veneer.elapsed = veneer.elapsed + elapsed |
121 | 126 |
122 local nw = w - ceil(w * progress) | 127 local w = floor(veneer.progress:GetWidth()+.5) |
123 print(progress, nw, w) | 128 local t = GetTime() |
124 if (progress >= 1) or not frame:IsVisible() then | 129 local progress = (t - startTime) / duration |
125 veneer.startTime = nil | 130 |
126 self:Hide() | 131 local nw = (w-2) - ceil(w * progress) |
127 self:SetScript('OnUpdate', nil) | 132 if veneer.elapsed >= 0.25 then |
128 else | 133 |
129 self.fg:SetWidth(nw) | 134 print(progress, nw, w) |
130 end | 135 veneer.elapsed = 0.25 - veneer.elapsed |
131 end) | 136 end |
132 end | 137 if (progress >= 1) or not frame:IsVisible() then |
133 | 138 veneer.startTime = nil |
134 | 139 self:Hide() |
135 | 140 self:SetScript('OnUpdate', nil) |
141 else | |
142 self.fg:SetWidth(nw) | |
143 end | |
144 end) | |
145 | |
146 veneer.cooldown:Show() | |
147 veneer.cooldown:SetCooldown(startTime, duration) | |
148 else | |
149 print('|cFF00FF88'..frame:GetName()..'|r', 'duration zero') | |
150 veneer.progress:SetScript('OnUpdate', nil) | |
151 veneer.progress:Hide() | |
152 veneer.cooldown:Hide() | |
153 end | |
154 else | |
155 veneer.progress:Hide() | |
156 veneer.cooldown:SetCooldown(0,0) | |
157 veneer.cooldown:Hide() | |
158 print('|cFF88FF00'..frame:GetName()..'|r', 'nil duration') | |
159 end | |
136 veneer:Show() | 160 veneer:Show() |
137 end | 161 end |
138 | 162 |
139 | 163 |
140 -- Associates skinning elements with said button | 164 -- Associates skinning elements with said button |
160 if border then | 184 if border then |
161 border:SetSize(50,50) | 185 border:SetSize(50,50) |
162 end | 186 end |
163 if duration then | 187 if duration then |
164 duration:ClearAllPoints() | 188 duration:ClearAllPoints() |
165 duration:SetPoint('BOTTOM') | 189 duration:SetPoint('TOP', frame, 'BOTTOM', 0, -8) |
166 duration:SetFontObject(VeneerNumberFont) | 190 duration:SetFontObject(VeneerNumberFont) |
167 duration:SetDrawLayer('OVERLAY') | 191 duration:SetDrawLayer('OVERLAY') |
168 | 192 |
169 end | 193 end |
170 | 194 |
194 local bName = name..index | 218 local bName = name..index |
195 local frame = _G[bName] | 219 local frame = _G[bName] |
196 if frame and frame:IsVisible() then | 220 if frame and frame:IsVisible() then |
197 tickCounter[frame] = (tickCounter[frame] or 0) + 1 | 221 tickCounter[frame] = (tickCounter[frame] or 0) + 1 |
198 local cacheDiff = CacheCheck(frame, UnitAura(frame.unit, frame:GetID(), frame.filter)) | 222 local cacheDiff = CacheCheck(frame, UnitAura(frame.unit, frame:GetID(), frame.filter)) |
199 -- did something change? | 223 -- if the name or expirationTime changed |
200 if (cacheDiff >= 1) or not skinnedFrames[frame] then | 224 if (cacheDiff >= 1) then |
201 print(frame:GetName(), 'diff:', cacheDiff) | 225 print(frame:GetName(), 'diff:', cacheDiff) |
202 tinsert(pendingFrames, frame) | 226 if not skinnedFrames[frame] then |
203 end | 227 tinsert(pendingFrames, frame) |
204 | 228 end |
205 | |
206 if frame.expirationTime ~= expirationCache[name] then | |
207 print('|cFFBBFF00expirationTime|r', name, frame.expirationTime) | |
208 expirationCache[name] = frame.expirationTime | 229 expirationCache[name] = frame.expirationTime |
209 print(unpack(aurasCache[frame])) | 230 print(unpack(aurasCache[frame])) |
210 UpdateVeneer(frame, aurasCache[frame][6], aurasCache[frame][7]) | 231 UpdateVeneer(frame, aurasCache[frame][6], aurasCache[frame][7]) |
211 end | 232 end |
212 | 233 |
224 print('|cFFBBFF00AllBuffAnchors|r', #pendingFrames) | 245 print('|cFFBBFF00AllBuffAnchors|r', #pendingFrames) |
225 while pendingFrames[1] do | 246 while pendingFrames[1] do |
226 local frame = tremove(pendingFrames) | 247 local frame = tremove(pendingFrames) |
227 tinsert(todo, frame:GetName()) | 248 tinsert(todo, frame:GetName()) |
228 | 249 |
229 UpdateVeneer(frame) | 250 -- re-apply custom anchors |
230 | |
231 | |
232 end | 251 end |
233 print(table.concat(todo, ', ')) | 252 print(table.concat(todo, ', ')) |
234 end | 253 end |
235 --BuffButton1 | 254 --BuffButton1 |
236 --DebuffButton1 | 255 --DebuffButton1 |
256 --todo: separate frame groups and iterate over them at appropriate times | |
237 if BuffButton1 then | 257 if BuffButton1 then |
238 TempEnchant1:SetPoint('TOPRIGHT', BuffButton1, 'TOPRIGHT', BuffButton1:GetWidth()+4, 0) | 258 --TempEnchant1:SetPoint('TOPRIGHT', BuffButton1, 'TOPRIGHT', BuffButton1:GetWidth()+4, 0) |
239 end | 259 end |
240 | 260 |
241 end | 261 end |
242 | 262 |
243 local AuraButton_UpdateDuration = function(frame, timeLeft) | 263 local AuraButton_UpdateDuration = function(frame, timeLeft) |
247 local timeString = '%ds' | 267 local timeString = '%ds' |
248 if timeLeft > 3600 then | 268 if timeLeft > 3600 then |
249 timeString = format('%d:%02d', hours, minutes) | 269 timeString = format('%d:%02d', hours, minutes) |
250 elseif timeLeft > 60 then | 270 elseif timeLeft > 60 then |
251 timeString = format('%d:%02d', minutes, seconds) | 271 timeString = format('%d:%02d', minutes, seconds) |
252 elseif timeLeft > 10 then | 272 else |
253 timeString = format('%d', seconds) | 273 timeString = format('%d', seconds) |
254 else | |
255 timeString = format('%0.1f', mod(timeLeft, 60)) | |
256 end | 274 end |
257 | 275 |
258 | 276 |
259 frame.duration:SetText(timeString) | 277 frame.duration:SetText(timeString) |
260 frame.duration:SetVertexColor(1,1,1) | 278 frame.duration:SetVertexColor(1,1,1) |
261 | |
262 end | 279 end |
263 | 280 |
264 local visibility = {} | 281 local visibility = {} |
265 local TempEnchantButton_OnHide = function(self) | 282 local TempEnchantButton_OnHide = function(self) |
266 local isVisible = self:IsVisible() | 283 local isVisible = self:IsVisible() |
303 end | 320 end |
304 | 321 |
305 end | 322 end |
306 | 323 |
307 local BuffFrame_Update = function(...) | 324 local BuffFrame_Update = function(...) |
308 --print('Time for udpate!', ...) | 325 |
309 end | 326 end |
310 | 327 |
311 | 328 |
312 hooksecurefunc("BuffFrame_Update", BuffFrame_Update) | 329 hooksecurefunc("BuffFrame_Update", BuffFrame_Update) |
313 hooksecurefunc("AuraButton_UpdateDuration", AuraButton_UpdateDuration) | 330 hooksecurefunc("AuraButton_UpdateDuration", AuraButton_UpdateDuration) |
323 | 340 |
324 | 341 |
325 end | 342 end |
326 | 343 |
327 plugin.init = function () | 344 plugin.init = function () |
345 | |
346 | |
347 | |
328 plugin.db = vn.db[PLUGIN_NAME] | 348 plugin.db = vn.db[PLUGIN_NAME] |
329 end | 349 end |