Mercurial > wow > buffalo2
comparison Modules/BuffFrame.lua @ 69:ebc18a7412a1
- use secure hook functions to manage duration and count text
author | Nenue |
---|---|
date | Sun, 21 Aug 2016 10:28:09 -0400 |
parents | be5cea6e1e8f |
children | 1b0d7bcd252e |
comparison
equal
deleted
inserted
replaced
68:be5cea6e1e8f | 69:ebc18a7412a1 |
---|---|
80 end | 80 end |
81 | 81 |
82 | 82 |
83 local GetVeneer = function(frame) | 83 local GetVeneer = function(frame) |
84 local name = frame:GetName() | 84 local name = frame:GetName() |
85 if not (_G[name..'Veneer'] and _G[name..'Underlay']) then | 85 if not (_G[name..'Veneer']) then |
86 print('|cFF88FF00Creating', name,'Veneer') | 86 print('|cFF88FF00Creating', name,'Veneer') |
87 local veneer = CreateFrame('Frame', name..'Veneer', UIParent) | 87 local veneer = CreateFrame('Frame', name..'Veneer', UIParent) |
88 local id = frame:GetID() | 88 local id = frame:GetID() |
89 veneer:SetAllPoints(frame) | 89 veneer:SetAllPoints(frame) |
90 veneer:SetParent(frame) | 90 veneer:SetParent(frame) |
125 | 125 |
126 veneer.cooldown = CreateFrame('Cooldown', name ..'VeneerCooldown', veneer, 'CooldownFrameTemplate') | 126 veneer.cooldown = CreateFrame('Cooldown', name ..'VeneerCooldown', veneer, 'CooldownFrameTemplate') |
127 veneer.cooldown:SetAllPoints(frame) | 127 veneer.cooldown:SetAllPoints(frame) |
128 veneer.cooldown:SetReverse(true) | 128 veneer.cooldown:SetReverse(true) |
129 | 129 |
130 | 130 local overlay = CreateFrame('Frame', name .. 'VeneerOverlay', UIParent) |
131 | 131 |
132 | 132 overlay:Show() |
133 local underlay = CreateFrame('Frame', name..'Underlay', UIParent) | 133 overlay:SetFrameStrata('MEDIUM') |
134 local n = frame:GetNumPoints() | |
135 for i = 1, n do | |
136 overlay:SetPoint(frame:GetPoint(n)) | |
137 end | |
138 | |
139 | |
140 local underlay = CreateFrame('Frame', name..'VeneerUnderlay', UIParent) | |
134 underlay:Show() | 141 underlay:Show() |
135 underlay:SetFrameStrata('BACKGROUND') | 142 underlay:SetFrameStrata('BACKGROUND') |
136 local n = frame:GetNumPoints() | 143 local n = frame:GetNumPoints() |
137 for i = 1, n do | 144 for i = 1, n do |
138 underlay:SetPoint(frame:GetPoint(n)) | 145 underlay:SetPoint(frame:GetPoint(n)) |
139 end | 146 end |
140 | 147 |
148 veneer.duration = overlay:CreateFontString(name..'VeneerDuration', 'OVERLAY') | |
149 veneer.duration:SetFontObject(VeneerNumberFont) | |
150 veneer.duration:SetPoint('TOP', frame, 'BOTTOM', 0, -8) | |
151 | |
152 veneer.count = overlay:CreateFontString(name..'VeneerCount', 'OVERLAY') | |
153 veneer.count:SetFontObject(VeneerNumberFont) | |
154 veneer.count:SetPoint('BOTTOMRIGHT', frame, 'BOTTOMRIGHT', -3, 3) | |
141 | 155 |
142 | 156 |
143 | 157 |
144 veneer.border = underlay:CreateTexture(name..'VeneerBorder', 'BACKGROUND') | 158 veneer.border = underlay:CreateTexture(name..'VeneerBorder', 'BACKGROUND') |
145 veneer.border:SetPoint('TOPLEFT', veneer, 'TOPLEFT', -BORDER_SIZE_L, BORDER_SIZE_U) | 159 veneer.border:SetPoint('TOPLEFT', veneer, 'TOPLEFT', -BORDER_SIZE_L, BORDER_SIZE_U) |
146 veneer.border:SetPoint('BOTTOMRIGHT', veneer, 'BOTTOMRIGHT', BORDER_SIZE_R, -BORDER_SIZE_D) | 160 veneer.border:SetPoint('BOTTOMRIGHT', veneer, 'BOTTOMRIGHT', BORDER_SIZE_R, -BORDER_SIZE_D) |
147 --veneer.border:SetColorTexture(0,1,0,1) | |
148 veneer.border:Show() | 161 veneer.border:Show() |
149 | 162 |
150 end | 163 |
151 | 164 veneer.overlay = overlay |
152 | 165 veneer.underlay = underlay |
153 return _G[name..'Veneer'], _G[name..'Underlay'] | 166 end |
167 | |
168 | |
169 return _G[name..'Veneer'] | |
154 end | 170 end |
155 | 171 |
156 | 172 |
157 -- Associates skinning elements with said button | 173 -- Associates skinning elements with said button |
158 local SkinFrame = function(name) | 174 local SkinFrame = function(name) |
166 local icon = _G[name .. 'Icon'] | 182 local icon = _G[name .. 'Icon'] |
167 local border = _G[name .. 'Border'] | 183 local border = _G[name .. 'Border'] |
168 local count = _G[name .. 'Count'] | 184 local count = _G[name .. 'Count'] |
169 local duration = _G[name .. 'Duration'] | 185 local duration = _G[name .. 'Duration'] |
170 local slot = frame:GetID() or 0 | 186 local slot = frame:GetID() or 0 |
171 local veneer, underlay = GetVeneer(frame) | 187 local veneer = GetVeneer(frame) |
188 local underlay = veneer.underlay | |
189 local overlay = veneer.overlay | |
172 | 190 |
173 skinnedFrames[frame] = frame | 191 skinnedFrames[frame] = frame |
174 frame:SetSize(BUFF_BUTTON_SIZE,BUFF_BUTTON_SIZE) | 192 frame:SetSize(BUFF_BUTTON_SIZE,BUFF_BUTTON_SIZE) |
175 | 193 |
176 local offset = BUFF_BUTTON_ZOOM/2 | 194 local offset = BUFF_BUTTON_ZOOM/2 |
190 | 208 |
191 veneer.border:SetColorTexture(color.r,color.g,color.b) | 209 veneer.border:SetColorTexture(color.r,color.g,color.b) |
192 end | 210 end |
193 if duration then | 211 if duration then |
194 duration:ClearAllPoints() | 212 duration:ClearAllPoints() |
195 duration:SetPoint('TOP', frame, 'BOTTOM', 0, -8) | 213 --duration:SetPoint('TOP', frame, 'BOTTOM', 0, -8) |
196 duration:SetFontObject(VeneerNumberFont) | 214 --duration:SetFontObject(VeneerNumberFont) |
197 duration:SetDrawLayer('OVERLAY') | 215 --duration:SetDrawLayer('OVERLAY') |
198 | 216 |
217 hooksecurefunc(duration, 'Hide', function(self, text) | |
218 veneer.duration:Hide() | |
219 end) | |
220 hooksecurefunc(duration, 'Show', function(self, text) | |
221 veneer.duration:Show() | |
222 end) | |
223 end | |
224 if count then | |
225 count:ClearAllPoints() | |
226 hooksecurefunc(count, 'SetText', function(self, text) | |
227 self:Hide() | |
228 veneer.count:SetText(text) | |
229 end) | |
230 hooksecurefunc(count, 'Hide', function(self, text) | |
231 veneer.count:Hide() | |
232 end) | |
233 hooksecurefunc(count, 'Show', function(self, text) | |
234 veneer.count:Show() | |
235 end) | |
199 end | 236 end |
200 | 237 |
201 | 238 |
202 hooksecurefunc(frame, "Hide", function(self) | 239 hooksecurefunc(frame, "Hide", function(self) |
203 local isVisible = self:IsVisible() | 240 local isVisible = self:IsVisible() |
350 end | 387 end |
351 | 388 |
352 end | 389 end |
353 | 390 |
354 local AuraButton_UpdateDuration = function(frame, timeLeft) | 391 local AuraButton_UpdateDuration = function(frame, timeLeft) |
392 local veneer = GetVeneer(frame) | |
355 local hours = floor(timeLeft/3600) | 393 local hours = floor(timeLeft/3600) |
356 local minutes = floor(mod(timeLeft, 3600)/60) | 394 local minutes = floor(mod(timeLeft, 3600)/60) |
357 local seconds = floor(mod(timeLeft, 60)) | 395 local seconds = floor(mod(timeLeft, 60)) |
358 local timeString = '%ds' | 396 local timeString = '%ds' |
359 if timeLeft > 3600 then | 397 if timeLeft > 3600 then |
363 else | 401 else |
364 timeString = format('%d', seconds) | 402 timeString = format('%d', seconds) |
365 end | 403 end |
366 | 404 |
367 | 405 |
368 frame.duration:SetText(timeString) | 406 veneer.duration:SetText(timeString) |
369 frame.duration:SetVertexColor(1,1,1) | 407 veneer.duration:SetVertexColor(1,1,1) |
370 end | 408 end |
371 | 409 |
372 | 410 |
373 -- Obtains the first instance of Tenchant use | 411 -- Obtains the first instance of Tenchant use |
374 | 412 |