Nenue@40: --- ${PACKAGE_NAME} Nenue@40: -- @file-author@ Nenue@40: -- @project-revision@ @project-hash@ Nenue@40: -- @file-revision@ @file-hash@ Nenue@40: -- Created: 4/24/2016 11:30 AM Nenue@40: --- These functions deal with propagating and managing block/line templates Nenue@40: local B = select(2,...).frame Nenue@40: local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame') Nenue@40: local _G, ipairs, max, tostring = _G, ipairs, max, tostring Nenue@40: local tinsert, tremove, tContains = table.insert, table.remove, tContains Nenue@40: local Default = T.DefaultHandler Nenue@40: local CreateFrame = CreateFrame Nenue@40: local print = B.print('Layout') Nenue@40: local bprint = B.print('Block') Nenue@40: local lprint = B.print('Layout') Nenue@40: local fprint = B.print('Frame') Nenue@40: local used, free Nenue@40: Nenue@40: local blockFadeOut_OnPlay = function(self) Nenue@40: fprint(self:GetName(), '|cFF00FF00PLAY|r', debugstack(1,3,1)) Nenue@40: end Nenue@40: local blockFadeOut_OnFinished = function(self) Nenue@40: fprint(self:GetName(), '|cFF00FF00FINISHED|r', debugstack(1,3, 1)) Nenue@40: end Nenue@40: Nenue@40: local tMove = function(source, dest, frame) Nenue@40: -- if it's already in the stack, sanity check source stack Nenue@40: local removed Nenue@40: if tContains(dest, frame) then Nenue@40: for i, entry in ipairs(source) do Nenue@40: if entry == frame then Nenue@40: removed = i Nenue@40: tremove(source, i) Nenue@40: break Nenue@40: end Nenue@40: end Nenue@40: -- still need to resolve position Nenue@40: for i, entry in ipairs(dest) do Nenue@40: if entry == frame then Nenue@40: bprint('tMove result:', (removed and ('|cFFFF4400a|r['..removed .. '] is now ') or '') .. '|cFF00FF00b|r[' .. i..']') Nenue@40: return i Nenue@40: end Nenue@40: end Nenue@40: else Nenue@40: -- if it's not, then pull from source stack Nenue@40: for i, entry in ipairs(source) do Nenue@40: if entry == frame then Nenue@40: removed = i Nenue@40: tremove(source, i) Nenue@40: break Nenue@40: end Nenue@40: end Nenue@40: tinsert(dest, frame) Nenue@40: bprint('tMove result:', (removed and ('|cFFFF4400a|r['..removed .. '] is now ') or '') .. '|cFF00FF00b|r[' .. #dest..']') Nenue@40: return #dest Nenue@40: end Nenue@40: end Nenue@40: Nenue@40: Nenue@40: --- Creates or retrieves a complete line data object Nenue@43: function Default:GetLine (block, lineIndex) Nenue@40: local print = lprint Nenue@40: local blockIndex = block.index Nenue@40: local lines = block.lines Nenue@40: if not lineIndex then Nenue@40: lineIndex = block.currentLine + 1 Nenue@40: print(' |cFFFFFF00generating a frame') Nenue@40: end Nenue@40: Nenue@40: block.numLines = max(block.numLines, lineIndex) Nenue@40: Nenue@40: if not lines[lineIndex] then Nenue@43: print(' |cFF00FF88created line #'..lineIndex..' from for '..self.name..' block #'..blockIndex) Nenue@43: lines[lineIndex] = CreateFrame('Frame', 'Vn'..self.name .. blockIndex..'ObjectiveLine'..lineIndex, block, 'VeneerTrackerObjective') Nenue@40: local line = lines[lineIndex] Nenue@40: line.index = lineIndex Nenue@40: line.height = 0 Nenue@40: line.schema = '' Nenue@40: B.SetConfigLayers(line) Nenue@40: Nenue@40: if debug then Nenue@40: for _, region in ipairs(lines[lineIndex].debug) do Nenue@40: region:Show() Nenue@40: end Nenue@40: end Nenue@40: Nenue@40: end Nenue@40: return lines[lineIndex] Nenue@40: end Nenue@40: Nenue@40: Nenue@40: Nenue@40: --- Creates or retrieves a complete block frame object Nenue@40: --- todo: make it use data index to avoid re-coloring every block Nenue@43: function Default:GetBlock (index) Nenue@40: local print = bprint Nenue@43: print('|cFF0088FF'..self.name..':GetBlock', index) Nenue@43: local block = self.InfoBlock[index] Nenue@43: local used = self.usedBlocks Nenue@43: local free = self.freeBlocks Nenue@40: Nenue@44: if block and block.isAnimating then Nenue@44: return block Nenue@40: end Nenue@40: Nenue@40: -- if the frame entry is still good, sort heaps Nenue@40: if block and block.info.id == index then Nenue@40: block.posIndex = tMove(free, used, block) Nenue@43: print(' |cFFFFFF00using '..self.name..'|r.|cFF00FFBBusedBlocks['..tostring(block.posIndex)..'] ('.. block:GetName()..', "'..tostring(block.info.title)..'")') Nenue@40: else Nenue@40: local source = 'cache' Nenue@43: if #self.freeBlocks >= 1 then Nenue@43: block = tremove(self.freeBlocks) Nenue@40: print(' |cFF00FF00 assigning from free heap', block:GetName()) Nenue@40: else Nenue@40: Nenue@43: local blockIndex = (#self.usedBlocks + #self.freeBlocks) + 1 Nenue@43: block = CreateFrame('Frame', 'Veneer'..tostring(self)..'Block'..blockIndex, self.frame, 'VeneerTrackerBlock') Nenue@40: --block:SetParent() Nenue@40: block.schema = '' Nenue@40: block.lines = {} Nenue@40: block.numLines = 0 Nenue@40: block.currentLine = 0 Nenue@40: block.attachmentHeight = 0 Nenue@40: block.offset = 0 Nenue@40: B.SetConfigLayers(block) Nenue@40: --- methods for event handlers Nenue@43: block.Select = self.Select Nenue@43: block.Open = self.Open Nenue@43: block.Remove = self.Remove Nenue@43: block.Link = self.Link Nenue@43: block.clickZone:SetScript('OnMouseUp', function(frame, ...) self.OnMouseUp(block, ...) end) Nenue@43: block.clickZone:SetScript('OnMouseDown', function(frame, ...) self.OnMouseDown(block, ...) end) Nenue@40: block:ClearAllPoints() Nenue@40: block.index = blockIndex Nenue@40: block.blockFadeOut:SetScript('OnPlay', blockFadeOut_OnPlay) Nenue@40: source = 'new' Nenue@40: end Nenue@43: self.InfoBlock[index] = block Nenue@40: block.posIndex = tMove(free, used, block) Nenue@43: print(' |cFF00FF00('..source..')|r |cFF0088FF'..self.name..'|r.|cFF00FFBBusedBlocks['..block.posIndex..'] =|r', block:GetName()) Nenue@40: end Nenue@44: Nenue@44: block.blockFadeOut:SetScript('OnFinished', blockFadeOut_OnFinished) Nenue@44: block:SetScript('OnHide', function(self) Nenue@44: fprint(self:GetName(), '|cFF00FF00HIDE|r', debugstack(1,3,1)) Nenue@44: if(self.DebugTab:IsShown()) then Nenue@44: self.DebugTab:Hide() Nenue@44: end Nenue@44: self.blockFadeOut:SetScript('OnFinished', blockFadeOut_OnFinished) Nenue@44: self.isAnimating = nil Nenue@44: end) Nenue@43: print(' used/free: |cFFFFFF00' .. #self.usedBlocks .. '|r/|cFF00FFFF'..#self.freeBlocks ..'|r') Nenue@40: return block Nenue@40: end Nenue@40: Nenue@40: --- begins a blockFadeOut animation and fires FreeBlock when that's done Nenue@43: function Default:ClearBlock (block) Nenue@43: -- double ensure multiple finish scripts from firing Nenue@40: if block.isAnimating then Nenue@40: return Nenue@40: end Nenue@40: block.isAnimating = true Nenue@40: block.blockFadeOut:SetScript('OnFinished', nil) Nenue@43: block.blockFadeOut:SetScript('OnFinished', function(anim) Nenue@43: --@debug@ Nenue@43: fprint(anim:GetName(), '|cFFFFFF00FINISHED|r', debugstack())--@end-debug@ Nenue@43: anim:SetScript('OnFinished', blockFadeOut_OnFinished) Nenue@43: self:FreeBlock(block) Nenue@40: block.isAnimating = nil Nenue@40: end) Nenue@40: block.blockFadeOut:Play() Nenue@40: end Nenue@40: Nenue@43: --- fired by OnFinished scripts; does the actual table swapping Nenue@43: function Default:FreeBlock(block) Nenue@40: bprint('|cFFFF4400FreeBlock|r', block:GetName()) Nenue@43: local used = self.usedBlocks Nenue@43: local free = self.freeBlocks Nenue@40: tMove(used, free, block) Nenue@40: Nenue@40: bprint(' |cFFFF4444used/free:|r |cFFFFFF00' .. #used .. '|r/|cFF00FFFF'..#free ..'|r') Nenue@40: Nenue@40: block:Hide() Nenue@40: local animations = {block:GetAnimationGroups() } Nenue@40: for i, animGroup in ipairs(animations) do Nenue@40: bprint(' animGroup', i, animGroup:GetName()) Nenue@40: animGroup:Stop() Nenue@40: end Nenue@40: end