Mercurial > wow > buffalo2
comparison Modules/BuffFrame.lua @ 84:16b300d96724
rewritten using mixin attributes
| author | Nenue |
|---|---|
| date | Tue, 18 Oct 2016 13:07:21 -0400 |
| parents | bb6b532c5d2f |
| children | 48182978d1c6 |
comparison
equal
deleted
inserted
replaced
| 83:4ec4fd89fced | 84:16b300d96724 |
|---|---|
| 23 local BORDER_SIZE_U = 1 | 23 local BORDER_SIZE_U = 1 |
| 24 local BORDER_SIZE_D = 1 | 24 local BORDER_SIZE_D = 1 |
| 25 local BUFF_FRAMES_X = -230 | 25 local BUFF_FRAMES_X = -230 |
| 26 local BUFF_FRAMES_Y = -4 | 26 local BUFF_FRAMES_Y = -4 |
| 27 | 27 |
| 28 | 28 VeneerBuffFrameMixin = { |
| 29 local plugin = CreateFrame('Frame', 'VeneerBuffFrame', UIParent) | 29 moduleName = 'Buff Frames', |
| 30 local vn, print = LibStub("LibKraken").register(Veneer, plugin) | 30 defaultCluster = 'TOPRIGHT', |
| 31 Buttons = {}, | |
| 32 DetectedFrames = {}, | |
| 33 AuraCache = {} | |
| 34 } | |
| 35 local plugin = VeneerBuffFrameMixin | |
| 36 | |
| 37 local vn = Veneer | |
| 38 local print = DEVIAN_WORKSPACE and function(...) _G.print('BuffFrame', ...) end or function() end | |
| 31 local tprint = DEVIAN_WORKSPACE and function(...) _G.print('Timer', ...) end or function() end | 39 local tprint = DEVIAN_WORKSPACE and function(...) _G.print('Timer', ...) end or function() end |
| 32 | 40 |
| 33 local _G, UIParent = _G, UIParent | 41 local _G, UIParent = _G, UIParent |
| 34 local tinsert, tremove, unpack, select, tconcat = table.insert, table.remove, unpack, select, table.concat | 42 local tinsert, tremove, unpack, select, tconcat = table.insert, table.remove, unpack, select, table.concat |
| 35 local floor, tonumber, format = math.floor, tonumber, string.format | 43 local floor, tonumber, format = math.floor, tonumber, string.format |
| 66 max = 16, | 74 max = 16, |
| 67 } | 75 } |
| 68 } | 76 } |
| 69 | 77 |
| 70 | 78 |
| 71 local GetVeneer = function(frame) | 79 function plugin:Acquire(target) |
| 72 | 80 |
| 73 if not (veneers[frame]) then | 81 local frame = self.Buttons[target] |
| 74 local name = frame:GetName() | 82 if not (self.Buttons[target]) then |
| 83 local name = target:GetName() | |
| 84 local id = target:GetID() | |
| 75 print('|cFF88FF00Creating', name,'Veneer') | 85 print('|cFF88FF00Creating', name,'Veneer') |
| 76 local veneer = vn.GetVeneer(frame, 'VeneerBuffTemplate') | 86 |
| 77 local id = frame:GetID() | 87 frame = vn:Acquire(target, 'VeneerBuffTemplate') |
| 78 | 88 |
| 79 | 89 frame.progress:SetHeight(BUFF_PROGRESS_SIZE + (BUFF_PROGRESS_INSET * 2)) |
| 80 veneer.progress:SetPoint('BOTTOMLEFT', veneer, 'BOTTOMLEFT', -1, -7) | 90 |
| 81 veneer.progress:SetPoint('TOPRIGHT', veneer, 'BOTTOMRIGHT', 1, -2) | 91 frame.progress.fg:ClearAllPoints() |
| 82 veneer.progress:SetHeight(BUFF_PROGRESS_SIZE + (BUFF_PROGRESS_INSET * 2)) | 92 frame.progress.fg:SetPoint('BOTTOMLEFT', BUFF_PROGRESS_INSET,BUFF_PROGRESS_INSET) |
| 83 | 93 frame.progress.fg:SetPoint('TOP', 0, -BUFF_PROGRESS_INSET) |
| 84 veneer.progress.bg:SetColorTexture(0,0,0,1) | 94 |
| 85 | 95 |
| 86 veneer.progress.fg:SetColorTexture(1,1,1,1) | 96 frame.underlay:SetParent(UIParent) |
| 87 veneer.progress.fg:ClearAllPoints() | 97 frame.underlay:SetFrameStrata('BACKGROUND') |
| 88 veneer.progress.fg:SetPoint('BOTTOMLEFT', BUFF_PROGRESS_INSET,BUFF_PROGRESS_INSET) | 98 frame.border:SetColorTexture(0,0,0,1) |
| 89 veneer.progress.fg:SetPoint('TOP', 0, -BUFF_PROGRESS_INSET) | 99 frame.border:SetPoint('TOPLEFT', frame, 'TOPLEFT', -BORDER_SIZE_L, BORDER_SIZE_U) |
| 90 | 100 frame.border:SetPoint('BOTTOMRIGHT', frame, 'BOTTOMRIGHT', BORDER_SIZE_R, -BORDER_SIZE_D) |
| 91 veneer.duration:SetFontObject(VeneerNumberFont) | 101 frame.border:Show() |
| 92 veneer.duration:ClearAllPoints() | 102 |
| 93 veneer.duration:SetPoint('BOTTOM', veneer, 'BOTTOM', 0, 2) | 103 self.Buttons[target] = frame |
| 94 | 104 end |
| 95 veneer.count:SetFontObject(VeneerNumberFont) | 105 return frame |
| 96 veneer.count:ClearAllPoints() | 106 end |
| 97 veneer.count:SetPoint('TOPRIGHT', veneer, 'TOPRIGHT', -3, -3) | 107 |
| 98 veneer.count:SetJustifyH('RIGHT') | 108 function plugin:OnLoad() |
| 99 veneer.count:SetSize(30,30) | 109 Veneer:AddHandler(self, self.defaultCluster) |
| 100 | 110 end |
| 101 veneer.underlay:SetParent(UIParent) | 111 |
| 102 veneer.underlay:SetFrameStrata('BACKGROUND') | 112 function plugin:Setup() |
| 103 veneer.border:SetColorTexture(0,0,0,1) | 113 |
| 104 veneer.border:SetPoint('TOPLEFT', veneer, 'TOPLEFT', -BORDER_SIZE_L, BORDER_SIZE_U) | 114 |
| 105 veneer.border:SetPoint('BOTTOMRIGHT', veneer, 'BOTTOMRIGHT', BORDER_SIZE_R, -BORDER_SIZE_D) | 115 hooksecurefunc("BuffFrame_Update", function(...) self:OnBuffFrameUpdate(...) end) |
| 106 veneer.border:Show() | 116 hooksecurefunc("AuraButton_UpdateDuration", function(...) self:OnUpdateDuration(...) end) |
| 107 | 117 hooksecurefunc("AuraButton_Update", function(...) self:OnAuraButton_Update(...) end) |
| 108 | 118 hooksecurefunc("BuffFrame_UpdateAllBuffAnchors", function(...) self:OnUpdateAllBuffAnchors(...) end) |
| 109 veneers[frame] = veneer | 119 hooksecurefunc("TemporaryEnchantFrame_Update", function(...) self:OnTemporaryEnchantFrameUpdate(...) end) |
| 110 end | 120 for i = 1, 3 do |
| 111 | 121 self:SetupButton('TempEnchant'..i) |
| 112 | 122 _G['TempEnchant'..i..'Border']:SetVertexColor(0.5,0,1,1) |
| 113 return veneers[frame] | 123 end |
| 114 end | 124 end |
| 115 | |
| 116 | |
| 117 -- Associates skinning elements with said button | 125 -- Associates skinning elements with said button |
| 118 local SkinFrame = function(name) | 126 local surrogates = { |
| 127 Show = false, | |
| 128 Hide = false, | |
| 129 SetText = false, | |
| 130 SetVertexColor = function(surrogate, frame, r, g, b, a) | |
| 131 frame:Hide() | |
| 132 print('|cFF0088FFborder:SetVertexColor|r', r,g,b,a) | |
| 133 surrogate.progress.fg:SetColorTexture(r,g,b,a) | |
| 134 surrogate.border:Show() | |
| 135 end, | |
| 136 } | |
| 137 local DoRegionHooks = function (veneer, region) | |
| 138 | |
| 139 if region then | |
| 140 print('hooking', region:GetName()) | |
| 141 region:ClearAllPoints() | |
| 142 for method, callback in ipairs(surrogates) do | |
| 143 print(method, callback) | |
| 144 if region[method] then | |
| 145 local func | |
| 146 if callback then | |
| 147 print('hooking', region:GetName(), method) | |
| 148 func = function(self,...) | |
| 149 print(self:GetName(), ':', method) | |
| 150 self:ClearAllPoints() | |
| 151 veneer[method](...) | |
| 152 end | |
| 153 else | |
| 154 func = function(self, ...) | |
| 155 self:ClearAllPoints() | |
| 156 callback(veneer, region, ...) | |
| 157 end | |
| 158 end | |
| 159 hooksecurefunc(region, method, callback) | |
| 160 end | |
| 161 end | |
| 162 end | |
| 163 end | |
| 164 | |
| 165 | |
| 166 function plugin:SetupButton (name) | |
| 119 local frame = _G[name ] | 167 local frame = _G[name ] |
| 120 if skinnedFrames[frame] then | 168 if self.DetectedFrames[frame] then |
| 121 print('|cFFFF4400Attempting to skin a frame that already went through.|r') | 169 print('|cFFFF4400Attempting to skin a frame that already went through.|r') |
| 122 return | 170 return |
| 123 end | 171 end |
| 124 print('|cFFFFFF00Adopting', name) | 172 print('|cFFFFFF00Adopting', name) |
| 125 | 173 |
| 126 local icon = _G[name .. 'Icon'] | 174 local icon = _G[name .. 'Icon'] |
| 127 local border = _G[name .. 'Border'] | 175 local border = _G[name .. 'Border'] |
| 128 local count = _G[name .. 'Count'] | 176 local count = _G[name .. 'Count'] |
| 129 local duration = _G[name .. 'Duration'] | 177 local duration = _G[name .. 'Duration'] |
| 130 local veneer = GetVeneer(frame) | 178 local veneer = self:Acquire(frame) |
| 131 | 179 local offset = BUFF_BUTTON_ZOOM/2 |
| 132 skinnedFrames[frame] = frame | 180 |
| 181 self.DetectedFrames[frame] = frame | |
| 133 frame:SetSize(BUFF_BUTTON_SIZE,BUFF_BUTTON_SIZE) | 182 frame:SetSize(BUFF_BUTTON_SIZE,BUFF_BUTTON_SIZE) |
| 134 | |
| 135 | |
| 136 local offset = BUFF_BUTTON_ZOOM/2 | |
| 137 icon:SetTexCoord(offset, 1 - offset, offset, 1 - offset) | 183 icon:SetTexCoord(offset, 1 - offset, offset, 1 - offset) |
| 184 | |
| 185 | |
| 186 DoRegionHooks(veneer, border) | |
| 187 DoRegionHooks(veneer.duration, duration) | |
| 188 DoRegionHooks(veneer.count, count) | |
| 138 if border then | 189 if border then |
| 139 border:Hide() | |
| 140 hooksecurefunc(border, 'SetVertexColor', function(frame, r, g, b, a) | |
| 141 frame:Hide() | |
| 142 print('|cFF0088FFborder:SetVertexColor|r', r,g,b,a) | |
| 143 veneer.progress.fg:SetColorTexture(r,g,b,a) | |
| 144 veneer.border:Show() | |
| 145 end) | |
| 146 | |
| 147 | |
| 148 | |
| 149 local color = DebuffTypeColor["none"] | 190 local color = DebuffTypeColor["none"] |
| 150 if aurasCache[frame] and aurasCache[frame][5] then | 191 if aurasCache[frame] and aurasCache[frame][5] then |
| 151 color = DebuffTypeColor[aurasCache[frame][5]] | 192 color = DebuffTypeColor[aurasCache[frame][5]] |
| 152 end | 193 end |
| 153 | |
| 154 veneer.progress.fg:SetColorTexture(color.r,color.g,color.b) | 194 veneer.progress.fg:SetColorTexture(color.r,color.g,color.b) |
| 155 veneer.border:SetColorTexture(0,0,0,1) | 195 veneer.border:SetColorTexture(0,0,0,1) |
| 156 veneer.border:Show() | 196 veneer.border:Show() |
| 157 else | 197 else |
| 158 veneer.border:SetColorTexture(0,0,0,1) | 198 veneer.border:SetColorTexture(0,0,0,1) |
| 159 veneer.border:Show() | 199 veneer.border:Show() |
| 160 end | 200 end |
| 161 if duration then | |
| 162 duration:ClearAllPoints() | |
| 163 --duration:SetPoint('TOP', frame, 'BOTTOM', 0, -8) | |
| 164 --duration:SetFontObject(VeneerNumberFont) | |
| 165 --duration:SetDrawLayer('OVERLAY') | |
| 166 | |
| 167 hooksecurefunc(duration, 'Hide', function(self, text) | |
| 168 veneer.duration:Hide() | |
| 169 end) | |
| 170 hooksecurefunc(duration, 'Show', function(self, text) | |
| 171 veneer.duration:Show() | |
| 172 end) | |
| 173 end | |
| 174 if count then | |
| 175 count:ClearAllPoints() | |
| 176 hooksecurefunc(count, 'SetText', function(self, text) | |
| 177 print(self:GetName(), 'SetText', text) | |
| 178 local n = veneer.count:GetNumPoints() | |
| 179 for i = 1, n do | |
| 180 print(i, veneer.count:GetPoint(n)) | |
| 181 end | |
| 182 veneer.count:Show() | |
| 183 veneer.count:SetText(text) | |
| 184 end) | |
| 185 hooksecurefunc(count, 'Hide', function(self) | |
| 186 if veneer.count.isUpdating then | |
| 187 print('|cFFFF4400blocked Hide hook|r') | |
| 188 return | |
| 189 end | |
| 190 | |
| 191 print(self:GetName(), 'Hide') | |
| 192 veneer.count:Hide() | |
| 193 end) | |
| 194 hooksecurefunc(count, 'Show', function(self) | |
| 195 print(self:GetName(), 'Show') | |
| 196 veneer.count:Show() | |
| 197 end) | |
| 198 end | |
| 199 | 201 |
| 200 | 202 |
| 201 hooksecurefunc(frame, "Hide", function(self) | 203 hooksecurefunc(frame, "Hide", function(self) |
| 202 local isVisible = self:IsVisible() | 204 local isVisible = self:IsVisible() |
| 203 if isVisible ~= visibility[self] then | 205 if isVisible ~= visibility[self] then |
| 219 | 221 |
| 220 end | 222 end |
| 221 | 223 |
| 222 | 224 |
| 223 --- Set widgets to reflect the passed parameters | 225 --- Set widgets to reflect the passed parameters |
| 224 local UpdateVeneer = function (frame, duration, expires) | 226 function plugin:UpdateButton (frame, duration, expires) |
| 225 local veneer = GetVeneer(frame) | 227 local veneer = self:Acquire(frame) |
| 226 -- is it a new button? | 228 -- is it a new button? |
| 227 if not skinnedFrames[frame] then | 229 if not self.DetectedFrames[frame] then |
| 228 SkinFrame(frame:GetName()) | 230 self:SetupButton(frame:GetName()) |
| 229 end | 231 end |
| 230 | 232 |
| 231 | 233 |
| 232 if expires and duration then | 234 if expires and duration then |
| 233 if duration ~= 0 then | 235 if duration ~= 0 then |
| 275 veneer:Show() | 277 veneer:Show() |
| 276 end | 278 end |
| 277 | 279 |
| 278 | 280 |
| 279 --- Provides the number of changed indices for use in deciding between partial and full veneer updates | 281 --- Provides the number of changed indices for use in deciding between partial and full veneer updates |
| 280 local CacheCheck = function(frame, ...) | 282 function plugin:ButtonHasChanged (frame, ...) |
| 281 aurasCache[frame] = aurasCache[frame] or {} | 283 aurasCache[frame] = aurasCache[frame] or {} |
| 282 local hasChange = 0 | 284 local hasChange = 0 |
| 283 local numVals = select('#',...) | 285 local numVals = select('#',...) |
| 284 for i = 1, numVals do | 286 for i = 1, numVals do |
| 285 local arg = select(i, ...) | 287 local arg = select(i, ...) |
| 289 aurasCache[frame][i] = arg | 291 aurasCache[frame][i] = arg |
| 290 end | 292 end |
| 291 return hasChange | 293 return hasChange |
| 292 end | 294 end |
| 293 | 295 |
| 294 local AuraButton_Update = function(name, index, filter) | 296 function plugin:OnAuraButton_Update (name, index, filter) |
| 295 local bName = name..index | 297 local bName = name..index |
| 296 local frame = _G[bName] | 298 local frame = _G[bName] |
| 297 if frame and frame:IsVisible() then | 299 if frame and frame:IsVisible() then |
| 298 local cacheDiff = CacheCheck(frame, UnitAura(frame.unit, frame:GetID(), frame.filter)) | 300 local cacheDiff = self:ButtonHasChanged(frame, UnitAura(frame.unit, frame:GetID(), frame.filter)) |
| 299 -- if the name or expirationTime changed | 301 -- if the name or expirationTime changed |
| 300 if (cacheDiff >= 1) then | 302 if (cacheDiff >= 1) then |
| 301 print('|cFFFF4400', frame:GetName(), 'diff:', cacheDiff) | 303 print('|cFFFF4400', frame:GetName(), 'diff:', cacheDiff) |
| 302 if not skinnedFrames[frame] then | 304 if not skinnedFrames[frame] then |
| 303 tinsert(pendingFrames, frame) | 305 tinsert(pendingFrames, frame) |
| 304 end | 306 end |
| 305 expirationCache[name] = frame.expirationTime | 307 expirationCache[name] = frame.expirationTime |
| 306 print(unpack(aurasCache[frame])) | 308 print(unpack(aurasCache[frame])) |
| 307 | 309 |
| 308 UpdateVeneer(frame, aurasCache[frame][6], aurasCache[frame][7]) | 310 self:UpdateButton(frame, aurasCache[frame][6], aurasCache[frame][7]) |
| 309 end | 311 end |
| 310 | 312 |
| 311 end | 313 end |
| 312 end | 314 end |
| 313 | 315 |
| 314 local BuffFrame_UpdateAllBuffAnchors = function() | 316 function plugin:OnUpdateAllBuffAnchors () |
| 315 local todo = {} | 317 local todo = {} |
| 316 if #pendingFrames >= 1 then | 318 if #pendingFrames >= 1 then |
| 317 | 319 |
| 318 print('|cFFBBFF00AllBuffAnchors|r', #pendingFrames) | 320 print('|cFFBBFF00AllBuffAnchors|r', #pendingFrames) |
| 319 while pendingFrames[1] do | 321 while pendingFrames[1] do |
| 379 if lastBuff then | 381 if lastBuff then |
| 380 plugin.currentBottom = lastBuff:GetBottom() | 382 plugin.currentBottom = lastBuff:GetBottom() |
| 381 end | 383 end |
| 382 end | 384 end |
| 383 | 385 |
| 384 local AuraButton_UpdateDuration = function(frame, timeLeft) | 386 function plugin:OnUpdateDuration (frame, timeLeft) |
| 385 local veneer = GetVeneer(frame) | 387 local veneer = self:Acquire(frame) |
| 386 local hours = floor(timeLeft/3600) | 388 local hours = floor(timeLeft/3600) |
| 387 local minutes = floor(mod(timeLeft, 3600)/60) | 389 local minutes = floor(mod(timeLeft, 3600)/60) |
| 388 local seconds = floor(mod(timeLeft, 60)) | 390 local seconds = floor(mod(timeLeft, 60)) |
| 389 local timeString = '%ds' | 391 local timeString = '%ds' |
| 390 if timeLeft > 3600 then | 392 if timeLeft > 3600 then |
| 415 end | 417 end |
| 416 | 418 |
| 417 | 419 |
| 418 -- Obtains the first instance of Tenchant use | 420 -- Obtains the first instance of Tenchant use |
| 419 | 421 |
| 420 local TemporaryEnchantFrame_Update = function(...) | 422 function plugin:OnTemporaryEnchantFrameUpdate (...) |
| 421 local numVals = select('#', ...) | 423 local numVals = select('#', ...) |
| 422 local numItems = numVals / 4 | 424 local numItems = numVals / 4 |
| 423 if numItems >= 1 then | 425 if numItems >= 1 then |
| 424 for itemIndex = numItems, 1, -1 do | 426 for itemIndex = numItems, 1, -1 do |
| 425 local frame = _G['TempEnchant'..itemIndex] | 427 local frame = _G['TempEnchant'..itemIndex] |
| 438 expirationCache[frame] = endTime | 440 expirationCache[frame] = endTime |
| 439 print('push tempenchant timer update', timeRemaining / 1000, GetTime()+(timeRemaining/1000)) | 441 print('push tempenchant timer update', timeRemaining / 1000, GetTime()+(timeRemaining/1000)) |
| 440 UpdateVeneer(frame, timeRemaining/1000, GetTime()+(timeRemaining/1000)) | 442 UpdateVeneer(frame, timeRemaining/1000, GetTime()+(timeRemaining/1000)) |
| 441 end | 443 end |
| 442 else | 444 else |
| 443 GetVeneer(frame):Hide() | 445 self:Acquire(frame):Hide() |
| 444 end | 446 end |
| 445 | 447 |
| 446 end | 448 end |
| 447 | 449 |
| 448 end | 450 end |
| 449 | 451 |
| 450 end | 452 end |
| 451 | 453 function plugin:OnBuffFrameUpdate () |
| 452 local BuffFrame_Update = function(...) | 454 end |
| 453 | 455 |
| 454 end | |
| 455 | |
| 456 | |
| 457 hooksecurefunc("BuffFrame_Update", BuffFrame_Update) | |
| 458 hooksecurefunc("AuraButton_UpdateDuration", AuraButton_UpdateDuration) | |
| 459 hooksecurefunc("AuraButton_Update", AuraButton_Update) | |
| 460 hooksecurefunc("BuffFrame_UpdateAllBuffAnchors", BuffFrame_UpdateAllBuffAnchors) | |
| 461 hooksecurefunc("TemporaryEnchantFrame_Update", TemporaryEnchantFrame_Update) | |
| 462 | 456 |
| 463 -- The TempEnchant frames are hardcoded in the base FrameXML, so get them now | 457 -- The TempEnchant frames are hardcoded in the base FrameXML, so get them now |
| 464 for i = 1, 3 do | 458 |
| 465 | |
| 466 SkinFrame('TempEnchant'..i) | |
| 467 _G['TempEnchant'..i..'Border']:SetVertexColor(0.5,0,1,1) | |
| 468 | |
| 469 end | |
| 470 | |
| 471 local OrderHallCommandBarMod = CreateFrame('Frame') | |
| 472 function OrderHallCommandBarMod:Refresh() | |
| 473 OrderHallCommandBar.Background:SetAlpha(0.5) | |
| 474 OrderHallCommandBar:ClearAllPoints() | |
| 475 OrderHallCommandBar:SetPoint('TOP') | |
| 476 OrderHallCommandBar:SetWidth(580) | |
| 477 end | |
| 478 function OrderHallCommandBarMod:Setup() | |
| 479 if OrderHallCommandBar then | |
| 480 print('mapping orderhall bar') | |
| 481 hooksecurefunc(OrderHallCommandBar, 'Show', OrderHallCommandBarMod.Refresh) | |
| 482 self:Refresh() | |
| 483 self:UnregisterEvent('ADDON_LOADED') | |
| 484 else | |
| 485 self:RegisterEvent('ADDON_LOADED') | |
| 486 self:SetScript('OnEvent', OrderHallCommandBarMod.Setup) | |
| 487 end | |
| 488 end | |
| 489 plugin.init = function () | |
| 490 plugin.db = vn.db[PLUGIN_NAME] | |
| 491 OrderHallCommandBarMod:Setup() | |
| 492 end |
