Mercurial > wow > buffalo2
diff Modules/BuffFrame.lua @ 90:6e2cb847c3c6
Implement a mixin template for the basic visual config widgets.
author | Nenue |
---|---|
date | Mon, 24 Oct 2016 18:28:40 -0400 |
parents | 48182978d1c6 |
children | caded2668701 |
line wrap: on
line diff
--- a/Modules/BuffFrame.lua Fri Oct 21 18:03:35 2016 -0400 +++ b/Modules/BuffFrame.lua Mon Oct 24 18:28:40 2016 -0400 @@ -11,6 +11,7 @@ - BuffButtons can only be hidden/shown by blizzcode, so functions doing that have to be accounted for --]] + local BUFFS_PER_ROW = 12 local BUFF_BUTTON_SIZE = 48 local BUFF_BUTTON_SPACING_H = 5 @@ -40,10 +41,15 @@ VeneerBuffFrameMixin = { moduleName = 'Buff Frames', defaultCluster = 'TOPRIGHT', + anchorX = BUFF_FRAMES_X, + anchorY = BUFF_FRAMES_Y, + anchorPoint = 'TOPRIGHT', Buttons = {}, DetectedFrames = {}, AuraCache = {} } +VeneerBuffFrameButtonMixin = { +} local plugin = VeneerBuffFrameMixin local vn = Veneer @@ -116,7 +122,61 @@ CENTER = {0, 0}, } -function plugin:Acquire(target) +-- Associates skinning elements with said button +local surrogates = { + ['Show'] = false, + ['Hide'] = false, + ['SetText'] = false, + ['SetVertexColor'] = function(self, region, r, g, b, a) + if not self.progress then + return + end + + region:Hide() + tprint('|cFF0088FFborder:SetVertexColor|r', r,g,b,a) + self.progress.fg:SetColorTexture(r,g,b,a) + self.border:SetColorTexture(r,g,b,a) + self.border:Show() + end, +} +local DoRegionHooks = function (veneer, region) + + if region then + --print('hooking', region:GetName()) + region:ClearAllPoints() + for method, callback in pairs(surrogates) do + if type(region[method]) == 'function' then + + --print(method, type(callback)) + local func + if callback then + hooksecurefunc(region, method, function(self, ...) + --tprint('|cFF00FFFF'.. region:GetName().. ':', method) + region:ClearAllPoints() + callback(veneer, region, ...) + end) + else + hooksecurefunc(region, method, function(self,...) + tprint('|cFF0088FF'.. self:GetName().. ':', method) + self:ClearAllPoints() + veneer:Show() + veneer[method](veneer, ...) + + if self:GetName():match('Debuff.+Count') then + + print('|cFF00FFFF'.. self:GetName().. ':'.. method, '->', veneer:GetName()..':'..method..'(', ...,')') + print(veneer:IsVisible(),veneer:GetStringWidth(),veneer:GetText()) + print(veneer:GetTop(), veneer:GetLeft()) + print(veneer:GetPoint(1)) + end + + end) + end + end + end + end +end +function VeneerBuffFrameMixin:Acquire(target) local frame = self.Buttons[target] if not (self.Buttons[target]) then @@ -173,11 +233,11 @@ return frame end -function plugin:OnLoad() +function VeneerBuffFrameMixin:OnLoad() Veneer:AddHandler(self, self.defaultCluster) end -function plugin:Setup() +function VeneerBuffFrameMixin:Setup() hooksecurefunc("BuffFrame_Update", function(...) self:OnBuffFrameUpdate(...) end) @@ -190,68 +250,9 @@ _G['TempEnchant'..i..'Border']:SetVertexColor(0.5,0,1,1) end end --- Associates skinning elements with said button -local surrogates = { - ['Show'] = false, - ['Hide'] = false, - ['SetText'] = false, - ['SetVertexColor'] = function(self, region, r, g, b, a) - if not self.progress then - return - end - region:Hide() - tprint('|cFF0088FFborder:SetVertexColor|r', r,g,b,a) - self.progress.fg:SetColorTexture(r,g,b,a) - self.border:SetColorTexture(r,g,b,a) - self.border:Show() - end, -} -local DoRegionHooks = function (veneer, region) - if region then - --print('hooking', region:GetName()) - region:ClearAllPoints() - for method, callback in pairs(surrogates) do - if type(region[method]) == 'function' then - - --print(method, type(callback)) - local func - if callback then - func = function(self, ...) - --tprint('|cFF00FFFF'.. region:GetName().. ':', method) - region:ClearAllPoints() - callback(veneer, region, ...) - end - else - func = function(self,...) - tprint('|cFF0088FF'.. self:GetName().. ':', method) - self:ClearAllPoints() - veneer:Show() - veneer[method](veneer, ...) - - if self:GetName():match('Debuff.+Count') then - - print('|cFF00FFFF'.. self:GetName().. ':'.. method, '->', veneer:GetName()..':'..method..'(', ...,')') - print(veneer:IsVisible(),veneer:GetStringWidth(),veneer:GetText()) - print(veneer:GetTop(), veneer:GetLeft()) - print(veneer:GetPoint(1)) - end - - end - end - if func then - --print('hooking', region:GetName(), method) - hooksecurefunc(region, method, func) - - end - end - end - end -end - - -function plugin:SetupButton (name) +function VeneerBuffFrameMixin:SetupButton (name) local frame = _G[name ] if self.DetectedFrames[frame] then --print('|cFFFF4400Attempting to skin a frame that already went through.|r') @@ -320,7 +321,7 @@ --- Set widgets to reflect the passed parameters -function plugin:UpdateButton (frame, duration, expires) +function VeneerBuffFrameMixin:UpdateButton (frame, duration, expires) local veneer = self:Acquire(frame) -- is it a new button? if not self.DetectedFrames[frame] then @@ -374,9 +375,10 @@ veneer.cooldown:Hide() end - if count and count >= 1 then + if count and count > 1 then veneer.count:SetText(count) veneer.count:Show() + frame.count:ClearAllPoints() else veneer.count:Hide() end @@ -393,7 +395,7 @@ --- Provides the number of changed indices for use in deciding between partial and full veneer updates -function plugin:ButtonHasChanged (frame, ...) +function VeneerBuffFrameMixin:ButtonHasChanged (frame, ...) aurasCache[frame] = aurasCache[frame] or {} local hasChange = 0 local numVals = select('#',...) @@ -407,7 +409,7 @@ return hasChange end -function plugin:OnAuraButton_Update (name, index, filter) +function VeneerBuffFrameMixin:OnAuraButton_Update (name, index, filter) local bName = name..index local frame = _G[bName] if frame and frame:IsVisible() then @@ -423,7 +425,7 @@ end end -function plugin:OnUpdateAllBuffAnchors () +function VeneerBuffFrameMixin:OnUpdateAllBuffAnchors () local todo = {} if #pendingFrames >= 1 then @@ -446,6 +448,8 @@ local lastBuff, topBuff local numBuffs = 0 + local numColumns = 1 + local maxColumn = 1 for i = 1, BUFF_ACTUAL_DISPLAY do local buff = _G['BuffButton'..i] if buff then @@ -454,13 +458,19 @@ if mod(numBuffs,BUFFS_PER_ROW) == 1 then if numBuffs == 1 then buff:SetPoint('TOPRIGHT', UIParent, 'TOPRIGHT', BUFF_FRAMES_X, BUFF_FRAMES_Y) - plugin.currentTop = buff:GetTop() + plugin.currentTop = buff else buff:SetPoint('TOPRIGHT', topBuff, 'BOTTOMRIGHT', 0, -BUFF_BUTTON_SPACING_V) end + numColumns = 1 topBuff = buff else buff:SetPoint('TOPRIGHT', lastBuff, 'TOPLEFT', -BUFF_BUTTON_SPACING_H, 0) + numColumns = numColumns + 1 + end + if numColumns > maxColumn then + maxColumn = numColumns + plugin.currentLeft = buff end lastBuff = buff end @@ -489,11 +499,18 @@ end if lastBuff then - plugin.currentBottom = lastBuff:GetBottom() + plugin.currentBottom = lastBuff end + + self.Background:ClearAllPoints() + self.Background:SetPoint('TOPRIGHT', plugin.currentTop, 'TOPRIGHT', 4, 4) + self.Background:SetPoint('BOTTOM', plugin.currentBottom, 'BOTTOM', 0, -4) + self.Background:SetPoint('LEFT', plugin.currentLeft, 'LEFT', -4, 0) end - -function plugin:OnUpdateDuration (frame, timeLeft) +function VeneerBuffFrameMixin:UpdateConfigLayers (configMode) + self:SetShown(configMode) +end +function VeneerBuffFrameMixin:OnUpdateDuration (frame, timeLeft) local veneer = self:Acquire(frame) local hours = floor(timeLeft/3600) local minutes = floor(mod(timeLeft, 3600)/60) @@ -527,7 +544,7 @@ -- Obtains the first instance of Tenchant use -function plugin:OnTemporaryEnchantFrameUpdate (...) +function VeneerBuffFrameMixin:OnTemporaryEnchantFrameUpdate (...) local numVals = select('#', ...) local numItems = numVals / 4 if numItems >= 1 then @@ -558,9 +575,24 @@ end end -function plugin:OnBuffFrameUpdate () +function VeneerBuffFrameMixin:OnBuffFrameUpdate () end +function VeneerBuffFrameButtonMixin:OnLoad() + + self.duration = self.progress.duration + self.count = self.overlay.count + self.border = self.underlay.bg + + VeneerBuffFrame.ConfigLayers = VeneerBuffFrame.ConfigLayers or {} + self.configIndex = #VeneerBuffFrame.ConfigLayers + for i, region in ipairs(self.ConfigLayers) do + tinsert(VeneerBuffFrame.ConfigLayers, region) + end + + self.configIndexEnd = #VeneerBuffFrame.ConfigLayers +end + -- The TempEnchant frames are hardcoded in the base FrameXML, so get them now