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