# HG changeset patch # User Nenue # Date 1476810441 14400 # Node ID 16b300d967243b5d1e1d8289df64fc34494e8d6b # Parent 4ec4fd89fced50a95b02194d560e1113918d6e50 rewritten using mixin attributes diff -r 4ec4fd89fced -r 16b300d96724 Modules/BuffFrame.lua --- a/Modules/BuffFrame.lua Tue Oct 18 01:57:02 2016 -0400 +++ b/Modules/BuffFrame.lua Tue Oct 18 13:07:21 2016 -0400 @@ -25,9 +25,17 @@ local BUFF_FRAMES_X = -230 local BUFF_FRAMES_Y = -4 +VeneerBuffFrameMixin = { + moduleName = 'Buff Frames', + defaultCluster = 'TOPRIGHT', + Buttons = {}, + DetectedFrames = {}, + AuraCache = {} +} +local plugin = VeneerBuffFrameMixin -local plugin = CreateFrame('Frame', 'VeneerBuffFrame', UIParent) -local vn, print = LibStub("LibKraken").register(Veneer, plugin) +local vn = Veneer +local print = DEVIAN_WORKSPACE and function(...) _G.print('BuffFrame', ...) end or function() end local tprint = DEVIAN_WORKSPACE and function(...) _G.print('Timer', ...) end or function() end local _G, UIParent = _G, UIParent @@ -68,56 +76,96 @@ } -local GetVeneer = function(frame) +function plugin:Acquire(target) - if not (veneers[frame]) then - local name = frame:GetName() + local frame = self.Buttons[target] + if not (self.Buttons[target]) then + local name = target:GetName() + local id = target:GetID() print('|cFF88FF00Creating', name,'Veneer') - local veneer = vn.GetVeneer(frame, 'VeneerBuffTemplate') - local id = frame:GetID() + frame = vn:Acquire(target, 'VeneerBuffTemplate') - veneer.progress:SetPoint('BOTTOMLEFT', veneer, 'BOTTOMLEFT', -1, -7) - veneer.progress:SetPoint('TOPRIGHT', veneer, 'BOTTOMRIGHT', 1, -2) - veneer.progress:SetHeight(BUFF_PROGRESS_SIZE + (BUFF_PROGRESS_INSET * 2)) + frame.progress:SetHeight(BUFF_PROGRESS_SIZE + (BUFF_PROGRESS_INSET * 2)) - veneer.progress.bg:SetColorTexture(0,0,0,1) + frame.progress.fg:ClearAllPoints() + frame.progress.fg:SetPoint('BOTTOMLEFT', BUFF_PROGRESS_INSET,BUFF_PROGRESS_INSET) + frame.progress.fg:SetPoint('TOP', 0, -BUFF_PROGRESS_INSET) - veneer.progress.fg:SetColorTexture(1,1,1,1) - veneer.progress.fg:ClearAllPoints() - veneer.progress.fg:SetPoint('BOTTOMLEFT', BUFF_PROGRESS_INSET,BUFF_PROGRESS_INSET) - veneer.progress.fg:SetPoint('TOP', 0, -BUFF_PROGRESS_INSET) - veneer.duration:SetFontObject(VeneerNumberFont) - veneer.duration:ClearAllPoints() - veneer.duration:SetPoint('BOTTOM', veneer, 'BOTTOM', 0, 2) + frame.underlay:SetParent(UIParent) + frame.underlay:SetFrameStrata('BACKGROUND') + frame.border:SetColorTexture(0,0,0,1) + frame.border:SetPoint('TOPLEFT', frame, 'TOPLEFT', -BORDER_SIZE_L, BORDER_SIZE_U) + frame.border:SetPoint('BOTTOMRIGHT', frame, 'BOTTOMRIGHT', BORDER_SIZE_R, -BORDER_SIZE_D) + frame.border:Show() - veneer.count:SetFontObject(VeneerNumberFont) - veneer.count:ClearAllPoints() - veneer.count:SetPoint('TOPRIGHT', veneer, 'TOPRIGHT', -3, -3) - veneer.count:SetJustifyH('RIGHT') - veneer.count:SetSize(30,30) - - veneer.underlay:SetParent(UIParent) - veneer.underlay:SetFrameStrata('BACKGROUND') - veneer.border:SetColorTexture(0,0,0,1) - veneer.border:SetPoint('TOPLEFT', veneer, 'TOPLEFT', -BORDER_SIZE_L, BORDER_SIZE_U) - veneer.border:SetPoint('BOTTOMRIGHT', veneer, 'BOTTOMRIGHT', BORDER_SIZE_R, -BORDER_SIZE_D) - veneer.border:Show() - - - veneers[frame] = veneer + self.Buttons[target] = frame end - - - return veneers[frame] + return frame end +function plugin:OnLoad() + Veneer:AddHandler(self, self.defaultCluster) +end +function plugin:Setup() + + + hooksecurefunc("BuffFrame_Update", function(...) self:OnBuffFrameUpdate(...) end) + hooksecurefunc("AuraButton_UpdateDuration", function(...) self:OnUpdateDuration(...) end) + hooksecurefunc("AuraButton_Update", function(...) self:OnAuraButton_Update(...) end) + hooksecurefunc("BuffFrame_UpdateAllBuffAnchors", function(...) self:OnUpdateAllBuffAnchors(...) end) + hooksecurefunc("TemporaryEnchantFrame_Update", function(...) self:OnTemporaryEnchantFrameUpdate(...) end) + for i = 1, 3 do + self:SetupButton('TempEnchant'..i) + _G['TempEnchant'..i..'Border']:SetVertexColor(0.5,0,1,1) + end +end -- Associates skinning elements with said button -local SkinFrame = function(name) +local surrogates = { + Show = false, + Hide = false, + SetText = false, + SetVertexColor = function(surrogate, frame, r, g, b, a) + frame:Hide() + print('|cFF0088FFborder:SetVertexColor|r', r,g,b,a) + surrogate.progress.fg:SetColorTexture(r,g,b,a) + surrogate.border:Show() + end, +} +local DoRegionHooks = function (veneer, region) + + if region then + print('hooking', region:GetName()) + region:ClearAllPoints() + for method, callback in ipairs(surrogates) do + print(method, callback) + if region[method] then + local func + if callback then + print('hooking', region:GetName(), method) + func = function(self,...) + print(self:GetName(), ':', method) + self:ClearAllPoints() + veneer[method](...) + end + else + func = function(self, ...) + self:ClearAllPoints() + callback(veneer, region, ...) + end + end + hooksecurefunc(region, method, callback) + end + end + end +end + + +function plugin:SetupButton (name) local frame = _G[name ] - if skinnedFrames[frame] then + if self.DetectedFrames[frame] then print('|cFFFF4400Attempting to skin a frame that already went through.|r') return end @@ -127,30 +175,22 @@ local border = _G[name .. 'Border'] local count = _G[name .. 'Count'] local duration = _G[name .. 'Duration'] - local veneer = GetVeneer(frame) + local veneer = self:Acquire(frame) + local offset = BUFF_BUTTON_ZOOM/2 - skinnedFrames[frame] = frame + self.DetectedFrames[frame] = frame frame:SetSize(BUFF_BUTTON_SIZE,BUFF_BUTTON_SIZE) + icon:SetTexCoord(offset, 1 - offset, offset, 1 - offset) - local offset = BUFF_BUTTON_ZOOM/2 - icon:SetTexCoord(offset, 1 - offset, offset, 1 - offset) + DoRegionHooks(veneer, border) + DoRegionHooks(veneer.duration, duration) + DoRegionHooks(veneer.count, count) if border then - border:Hide() - hooksecurefunc(border, 'SetVertexColor', function(frame, r, g, b, a) - frame:Hide() - print('|cFF0088FFborder:SetVertexColor|r', r,g,b,a) - veneer.progress.fg:SetColorTexture(r,g,b,a) - veneer.border:Show() - end) - - - local color = DebuffTypeColor["none"] if aurasCache[frame] and aurasCache[frame][5] then color = DebuffTypeColor[aurasCache[frame][5]] end - veneer.progress.fg:SetColorTexture(color.r,color.g,color.b) veneer.border:SetColorTexture(0,0,0,1) veneer.border:Show() @@ -158,44 +198,6 @@ veneer.border:SetColorTexture(0,0,0,1) veneer.border:Show() end - if duration then - duration:ClearAllPoints() - --duration:SetPoint('TOP', frame, 'BOTTOM', 0, -8) - --duration:SetFontObject(VeneerNumberFont) - --duration:SetDrawLayer('OVERLAY') - - hooksecurefunc(duration, 'Hide', function(self, text) - veneer.duration:Hide() - end) - hooksecurefunc(duration, 'Show', function(self, text) - veneer.duration:Show() - end) - end - if count then - count:ClearAllPoints() - hooksecurefunc(count, 'SetText', function(self, text) - print(self:GetName(), 'SetText', text) - local n = veneer.count:GetNumPoints() - for i = 1, n do - print(i, veneer.count:GetPoint(n)) - end - veneer.count:Show() - veneer.count:SetText(text) - end) - hooksecurefunc(count, 'Hide', function(self) - if veneer.count.isUpdating then - print('|cFFFF4400blocked Hide hook|r') - return - end - - print(self:GetName(), 'Hide') - veneer.count:Hide() - end) - hooksecurefunc(count, 'Show', function(self) - print(self:GetName(), 'Show') - veneer.count:Show() - end) - end hooksecurefunc(frame, "Hide", function(self) @@ -221,11 +223,11 @@ --- Set widgets to reflect the passed parameters -local UpdateVeneer = function (frame, duration, expires) - local veneer = GetVeneer(frame) +function plugin:UpdateButton (frame, duration, expires) + local veneer = self:Acquire(frame) -- is it a new button? - if not skinnedFrames[frame] then - SkinFrame(frame:GetName()) + if not self.DetectedFrames[frame] then + self:SetupButton(frame:GetName()) end @@ -277,7 +279,7 @@ --- Provides the number of changed indices for use in deciding between partial and full veneer updates -local CacheCheck = function(frame, ...) +function plugin:ButtonHasChanged (frame, ...) aurasCache[frame] = aurasCache[frame] or {} local hasChange = 0 local numVals = select('#',...) @@ -291,11 +293,11 @@ return hasChange end -local AuraButton_Update = function(name, index, filter) +function plugin:OnAuraButton_Update (name, index, filter) local bName = name..index local frame = _G[bName] if frame and frame:IsVisible() then - local cacheDiff = CacheCheck(frame, UnitAura(frame.unit, frame:GetID(), frame.filter)) + local cacheDiff = self:ButtonHasChanged(frame, UnitAura(frame.unit, frame:GetID(), frame.filter)) -- if the name or expirationTime changed if (cacheDiff >= 1) then print('|cFFFF4400', frame:GetName(), 'diff:', cacheDiff) @@ -305,13 +307,13 @@ expirationCache[name] = frame.expirationTime print(unpack(aurasCache[frame])) - UpdateVeneer(frame, aurasCache[frame][6], aurasCache[frame][7]) + self:UpdateButton(frame, aurasCache[frame][6], aurasCache[frame][7]) end end end -local BuffFrame_UpdateAllBuffAnchors = function() +function plugin:OnUpdateAllBuffAnchors () local todo = {} if #pendingFrames >= 1 then @@ -381,8 +383,8 @@ end end -local AuraButton_UpdateDuration = function(frame, timeLeft) - local veneer = GetVeneer(frame) +function plugin:OnUpdateDuration (frame, timeLeft) + local veneer = self:Acquire(frame) local hours = floor(timeLeft/3600) local minutes = floor(mod(timeLeft, 3600)/60) local seconds = floor(mod(timeLeft, 60)) @@ -417,7 +419,7 @@ -- Obtains the first instance of Tenchant use -local TemporaryEnchantFrame_Update = function(...) +function plugin:OnTemporaryEnchantFrameUpdate (...) local numVals = select('#', ...) local numItems = numVals / 4 if numItems >= 1 then @@ -440,7 +442,7 @@ UpdateVeneer(frame, timeRemaining/1000, GetTime()+(timeRemaining/1000)) end else - GetVeneer(frame):Hide() + self:Acquire(frame):Hide() end end @@ -448,45 +450,9 @@ end end - -local BuffFrame_Update = function(...) - +function plugin:OnBuffFrameUpdate () end -hooksecurefunc("BuffFrame_Update", BuffFrame_Update) -hooksecurefunc("AuraButton_UpdateDuration", AuraButton_UpdateDuration) -hooksecurefunc("AuraButton_Update", AuraButton_Update) -hooksecurefunc("BuffFrame_UpdateAllBuffAnchors", BuffFrame_UpdateAllBuffAnchors) -hooksecurefunc("TemporaryEnchantFrame_Update", TemporaryEnchantFrame_Update) +-- The TempEnchant frames are hardcoded in the base FrameXML, so get them now --- The TempEnchant frames are hardcoded in the base FrameXML, so get them now -for i = 1, 3 do - - SkinFrame('TempEnchant'..i) - _G['TempEnchant'..i..'Border']:SetVertexColor(0.5,0,1,1) - -end - -local OrderHallCommandBarMod = CreateFrame('Frame') -function OrderHallCommandBarMod:Refresh() - OrderHallCommandBar.Background:SetAlpha(0.5) - OrderHallCommandBar:ClearAllPoints() - OrderHallCommandBar:SetPoint('TOP') - OrderHallCommandBar:SetWidth(580) -end -function OrderHallCommandBarMod:Setup() - if OrderHallCommandBar then - print('mapping orderhall bar') - hooksecurefunc(OrderHallCommandBar, 'Show', OrderHallCommandBarMod.Refresh) - self:Refresh() - self:UnregisterEvent('ADDON_LOADED') - else - self:RegisterEvent('ADDON_LOADED') - self:SetScript('OnEvent', OrderHallCommandBarMod.Setup) - end -end -plugin.init = function () - plugin.db = vn.db[PLUGIN_NAME] - OrderHallCommandBarMod:Setup() -end \ No newline at end of file diff -r 4ec4fd89fced -r 16b300d96724 Modules/BuffFrame.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Modules/BuffFrame.xml Tue Oct 18 13:07:21 2016 -0400 @@ -0,0 +1,72 @@ + +