Mercurial > wow > buffalo2
diff Modules/BuffFrame.lua @ 68:be5cea6e1e8f
- button size metrics
- anchor adjustment for temp enchant
- clean up call order
- use secure hooks to directly catch Show/Hide for individual buttons
author | Nenue |
---|---|
date | Sun, 21 Aug 2016 07:09:10 -0400 |
parents | f80ee484ac8a |
children | ebc18a7412a1 |
line wrap: on
line diff
--- a/Modules/BuffFrame.lua Fri Aug 19 11:49:51 2016 -0400 +++ b/Modules/BuffFrame.lua Sun Aug 21 07:09:10 2016 -0400 @@ -14,12 +14,22 @@ local BUFF_BUTTON_SIZE = 48 local BUFF_PROGRESS_SIZE = 4 local BUFF_PROGRESS_INSET = 1 -local BUFF_BUTTON_ZOOM = 0 +local BUFF_BUTTON_ZOOM = .15 +local BORDER_SIZE_L = 0 +local BORDER_SIZE_R = 0 +local BORDER_SIZE_U = 1 +local BORDER_SIZE_D = 7 local plugin = CreateFrame('Frame', 'VeneerBuffFrame', UIParent) local vn, print = LibStub("LibKraken").register(VeneerController, plugin) +local tprint = DEVIAN_WORKSPACE and function(...) _G.print('Timer', ...) end or function() end +local _G, UIParent = _G, UIParent +local tinsert, tremove, unpack, select, tconcat = table.insert, table.remove, unpack, select, table.concat +local floor, tonumber, format = math.floor, tonumber, string.format +local UnitAura, GetTime, CreateFrame = UnitAura, GetTime, CreateFrame +local hooksecurefunc = hooksecurefunc local buttons = {} local buffTypes = { @@ -52,6 +62,7 @@ local pendingFrames = {} local anchors = {} local expirationCache = {} +local visibility = {} local VeneerButton_OnHide = function(self) self:SetScript('OnDragStart', self.StartMoving) @@ -71,8 +82,8 @@ local GetVeneer = function(frame) local name = frame:GetName() - if not _G[name..'Veneer'] then - + if not (_G[name..'Veneer'] and _G[name..'Underlay']) then + print('|cFF88FF00Creating', name,'Veneer') local veneer = CreateFrame('Frame', name..'Veneer', UIParent) local id = frame:GetID() veneer:SetAllPoints(frame) @@ -96,6 +107,7 @@ veneer.progress:Hide() veneer.progress:SetPoint('BOTTOMLEFT', veneer, 'BOTTOMLEFT', 3, -6) veneer.progress:SetPoint('TOPRIGHT', veneer, 'BOTTOMRIGHT', -3, -1) + veneer.progress:SetHeight(BUFF_PROGRESS_SIZE + (BUFF_PROGRESS_INSET * 2)) veneer.progress.bg = veneer.progress:CreateTexture(nil, 'BACKGROUND') veneer.progress.bg:SetColorTexture(0,0,0,1) @@ -103,8 +115,8 @@ veneer.progress.fg = veneer.progress:CreateTexture(nil, 'ARTWORK') veneer.progress.fg:SetColorTexture(0,1,0,1) - veneer.progress.fg:SetPoint('BOTTOMLEFT', 1,1) - veneer.progress.fg:SetPoint('TOP', 0, -1) + veneer.progress.fg:SetPoint('BOTTOMLEFT', BUFF_PROGRESS_INSET,BUFF_PROGRESS_INSET) + veneer.progress.fg:SetPoint('TOP', 0, -BUFF_PROGRESS_INSET) veneer.progress.status = veneer.progress:CreateFontString() veneer.progress.status:SetFontObject(VeneerNumberFont) @@ -115,18 +127,120 @@ veneer.cooldown:SetAllPoints(frame) veneer.cooldown:SetReverse(true) + + + + local underlay = CreateFrame('Frame', name..'Underlay', UIParent) + underlay:Show() + underlay:SetFrameStrata('BACKGROUND') + local n = frame:GetNumPoints() + for i = 1, n do + underlay:SetPoint(frame:GetPoint(n)) + end + + + + + veneer.border = underlay:CreateTexture(name..'VeneerBorder', 'BACKGROUND') + 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:SetColorTexture(0,1,0,1) + veneer.border:Show() + end - return _G[name..'Veneer'] + return _G[name..'Veneer'], _G[name..'Underlay'] end + +-- Associates skinning elements with said button +local SkinFrame = function(name) + local frame = _G[name ] + if skinnedFrames[frame] then + print('|cFFFF4400Attempting to skin a frame that already went through.|r') + return + end + print('|cFFFFFF00Adopting', name) + + local icon = _G[name .. 'Icon'] + local border = _G[name .. 'Border'] + local count = _G[name .. 'Count'] + local duration = _G[name .. 'Duration'] + local slot = frame:GetID() or 0 + local veneer, underlay = GetVeneer(frame) + + skinnedFrames[frame] = frame + frame:SetSize(BUFF_BUTTON_SIZE,BUFF_BUTTON_SIZE) + + local offset = BUFF_BUTTON_ZOOM/2 + icon:SetTexCoord(offset, 1 - offset, offset, 1 - offset) + 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.border:SetColorTexture(r,g,b,a) + end) + + local color = DebuffTypeColor["none"] + if aurasCache[frame] and aurasCache[frame][5] then + color = DebuffTypeColor[aurasCache[frame][5]] + end + + veneer.border:SetColorTexture(color.r,color.g,color.b) + end + if duration then + duration:ClearAllPoints() + duration:SetPoint('TOP', frame, 'BOTTOM', 0, -8) + duration:SetFontObject(VeneerNumberFont) + duration:SetDrawLayer('OVERLAY') + + end + + + hooksecurefunc(frame, "Hide", function(self) + local isVisible = self:IsVisible() + if isVisible ~= visibility[self] then + visibility[self] = isVisible + end + veneer:Hide() + underlay:Hide() + end) + + hooksecurefunc(frame, 'Show', function(self) + veneer:Show() + veneer.border:Show() + underlay:Show() + local isVisible = self:IsVisible() + if isVisible ~= visibility[self] then + print('|cFFFFFF00SHOW|r', self:GetName()) + visibility[self] = isVisible + end + end) + + anchors[frame] = veneer +end + +local Aura_SetBorderColor = function(self, r,g,b,a) end +local Aura_OnShow = function(self) end +local Aura_OnHide = function(self) end + --- Set widgets to reflect the passed parameters local UpdateVeneer = function (frame, duration, expires) local veneer = GetVeneer(frame) + -- is it a new button? + if not skinnedFrames[frame] then + SkinFrame(frame:GetName()) + end + + if frame.filter == 'HARMFUL' then + + veneer.border:Show() + end + if expires and duration then - if duration ~= 0 then local startTime = (expires - duration) local endTime = expires or 0 @@ -143,7 +257,7 @@ local nw = (w - (w * progress)) if veneer.elapsed >= 0.25 then - print(t, startTime, floor(progress*100), w * progress, nw, w) + tprint(t, startTime, floor(progress*100), w * progress, nw, w) veneer.elapsed = 0.25 - veneer.elapsed end if (progress >= 1) or not frame:IsVisible() then @@ -173,46 +287,6 @@ end --- Associates skinning elements with said button -local SkinFrame = function(name) - local frame = _G[name ] - if skinnedFrames[frame] then - print('|cFFFF4400Attempting to skin a frame that already went through.|r') - return - end - - local icon = _G[name .. 'Icon'] - local border = _G[name .. 'Border'] - local duration = _G[name .. 'Duration'] - local slot = frame:GetID() or 0 - - tickCounter[frame] = (tickCounter[frame] or 0) + 1 - - - print(tickCounter[frame], frame:GetName(), '|cFFFFFF00'..slot..'|r') - skinnedFrames[frame] = frame - frame:SetSize(BUFF_BUTTON_SIZE,BUFF_BUTTON_SIZE) - - local offset = BUFF_BUTTON_ZOOM/2 - icon:SetTexCoord(offset, 1 - offset, offset, 1 - offset) - if border then - border:SetSize(50,50) - end - if duration then - duration:ClearAllPoints() - duration:SetPoint('TOP', frame, 'BOTTOM', 0, -8) - duration:SetFontObject(VeneerNumberFont) - duration:SetDrawLayer('OVERLAY') - - end - - GetVeneer(frame) - - anchors[frame] = veneer - print('Initializing', name) -end - - --- Provides the number of changed indices for use in deciding between partial and full veneer updates local CacheCheck = function(frame, ...) aurasCache[frame] = aurasCache[frame] or {} @@ -233,22 +307,25 @@ local frame = _G[bName] if frame and frame:IsVisible() then tickCounter[frame] = (tickCounter[frame] or 0) + 1 + + + local cacheDiff = CacheCheck(frame, UnitAura(frame.unit, frame:GetID(), frame.filter)) + -- if the name or expirationTime changed if (cacheDiff >= 1) then - print(frame:GetName(), 'diff:', cacheDiff) + print('|cFFFF4400', frame:GetName(), 'diff:', cacheDiff) if not skinnedFrames[frame] then tinsert(pendingFrames, frame) end expirationCache[name] = frame.expirationTime print(unpack(aurasCache[frame])) + + + UpdateVeneer(frame, aurasCache[frame][6], aurasCache[frame][7]) end - -- is it a new button? - if not skinnedFrames[frame] then - SkinFrame(bName) - end end end @@ -263,13 +340,13 @@ -- re-apply custom anchors end - print(table.concat(todo, ', ')) + print(tconcat(todo, ', ')) end --BuffButton1 --DebuffButton1 --todo: separate frame groups and iterate over them at appropriate times if BuffButton1 then - --TempEnchant1:SetPoint('TOPRIGHT', BuffButton1, 'TOPRIGHT', BuffButton1:GetWidth()+4, 0) + TempEnchant1:SetPoint('TOPRIGHT', BuffButton1, 'TOPRIGHT', BuffButton1:GetWidth()+4, 0) end end @@ -292,14 +369,6 @@ frame.duration:SetVertexColor(1,1,1) end -local visibility = {} -local TempEnchantButton_OnHide = function(self) - local isVisible = self:IsVisible() - if isVisible ~= visibility[self] then - print('|cFFFFFF00HIDE|r', self:GetName()) - visibility[self] = isVisible - end -end -- Obtains the first instance of Tenchant use @@ -350,8 +419,7 @@ for i = 1, 3 do SkinFrame('TempEnchant'..i) - hooksecurefunc(_G['TempEnchant'..i], "Hide", TempEnchantButton_OnHide) - + _G['TempEnchant'..i..'Border']:SetVertexColor(0.5,0,1,1) end