Mercurial > wow > buffalo2
comparison ObjectiveTracker/Block.lua @ 43:9480bd904f4c
- file name organizing
author | Nenue |
---|---|
date | Mon, 25 Apr 2016 13:51:58 -0400 |
parents | ObjectiveTracker/TrackerBlock.lua@7a65ed86e4dd |
children | 756e8aeb040b |
comparison
equal
deleted
inserted
replaced
42:c73051785f19 | 43:9480bd904f4c |
---|---|
1 --- ${PACKAGE_NAME} | |
2 -- @file-author@ | |
3 -- @project-revision@ @project-hash@ | |
4 -- @file-revision@ @file-hash@ | |
5 -- Created: 4/24/2016 11:30 AM | |
6 --- These functions deal with propagating and managing block/line templates | |
7 local B = select(2,...).frame | |
8 local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame') | |
9 local _G, ipairs, max, tostring = _G, ipairs, max, tostring | |
10 local tinsert, tremove, tContains = table.insert, table.remove, tContains | |
11 local Default = T.DefaultHandler | |
12 local CreateFrame = CreateFrame | |
13 local print = B.print('Layout') | |
14 local bprint = B.print('Block') | |
15 local lprint = B.print('Layout') | |
16 local fprint = B.print('Frame') | |
17 local used, free | |
18 | |
19 local blockFadeOut_OnPlay = function(self) | |
20 fprint(self:GetName(), '|cFF00FF00PLAY|r', debugstack(1,3,1)) | |
21 end | |
22 local blockFadeOut_OnFinished = function(self) | |
23 fprint(self:GetName(), '|cFF00FF00FINISHED|r', debugstack(1,3, 1)) | |
24 end | |
25 | |
26 local tMove = function(source, dest, frame) | |
27 -- if it's already in the stack, sanity check source stack | |
28 local removed | |
29 if tContains(dest, frame) then | |
30 for i, entry in ipairs(source) do | |
31 if entry == frame then | |
32 removed = i | |
33 tremove(source, i) | |
34 break | |
35 end | |
36 end | |
37 -- still need to resolve position | |
38 for i, entry in ipairs(dest) do | |
39 if entry == frame then | |
40 bprint('tMove result:', (removed and ('|cFFFF4400a|r['..removed .. '] is now ') or '') .. '|cFF00FF00b|r[' .. i..']') | |
41 return i | |
42 end | |
43 end | |
44 else | |
45 -- if it's not, then pull from source stack | |
46 for i, entry in ipairs(source) do | |
47 if entry == frame then | |
48 removed = i | |
49 tremove(source, i) | |
50 break | |
51 end | |
52 end | |
53 tinsert(dest, frame) | |
54 bprint('tMove result:', (removed and ('|cFFFF4400a|r['..removed .. '] is now ') or '') .. '|cFF00FF00b|r[' .. #dest..']') | |
55 return #dest | |
56 end | |
57 end | |
58 | |
59 | |
60 --- Creates or retrieves a complete line data object | |
61 function Default:GetLine (block, lineIndex) | |
62 local print = lprint | |
63 local blockIndex = block.index | |
64 local lines = block.lines | |
65 if not lineIndex then | |
66 lineIndex = block.currentLine + 1 | |
67 print(' |cFFFFFF00generating a frame') | |
68 end | |
69 | |
70 block.numLines = max(block.numLines, lineIndex) | |
71 | |
72 if not lines[lineIndex] then | |
73 print(' |cFF00FF88created line #'..lineIndex..' from for '..self.name..' block #'..blockIndex) | |
74 lines[lineIndex] = CreateFrame('Frame', 'Vn'..self.name .. blockIndex..'ObjectiveLine'..lineIndex, block, 'VeneerTrackerObjective') | |
75 local line = lines[lineIndex] | |
76 line.index = lineIndex | |
77 line.height = 0 | |
78 line.schema = '' | |
79 B.SetConfigLayers(line) | |
80 | |
81 if debug then | |
82 for _, region in ipairs(lines[lineIndex].debug) do | |
83 region:Show() | |
84 end | |
85 end | |
86 | |
87 end | |
88 return lines[lineIndex] | |
89 end | |
90 | |
91 | |
92 | |
93 --- Creates or retrieves a complete block frame object | |
94 --- todo: make it use data index to avoid re-coloring every block | |
95 function Default:GetBlock (index) | |
96 local print = bprint | |
97 print('|cFF0088FF'..self.name..':GetBlock', index) | |
98 local block = self.InfoBlock[index] | |
99 local used = self.usedBlocks | |
100 local free = self.freeBlocks | |
101 | |
102 if block then | |
103 print(block.info.id, index) | |
104 end | |
105 | |
106 -- if the frame entry is still good, sort heaps | |
107 if block and block.info.id == index then | |
108 block.posIndex = tMove(free, used, block) | |
109 print(' |cFFFFFF00using '..self.name..'|r.|cFF00FFBBusedBlocks['..tostring(block.posIndex)..'] ('.. block:GetName()..', "'..tostring(block.info.title)..'")') | |
110 else | |
111 local source = 'cache' | |
112 if #self.freeBlocks >= 1 then | |
113 block = tremove(self.freeBlocks) | |
114 print(' |cFF00FF00 assigning from free heap', block:GetName()) | |
115 else | |
116 | |
117 local blockIndex = (#self.usedBlocks + #self.freeBlocks) + 1 | |
118 block = CreateFrame('Frame', 'Veneer'..tostring(self)..'Block'..blockIndex, self.frame, 'VeneerTrackerBlock') | |
119 --block:SetParent() | |
120 block.schema = '' | |
121 block.lines = {} | |
122 block.numLines = 0 | |
123 block.currentLine = 0 | |
124 block.attachmentHeight = 0 | |
125 block.offset = 0 | |
126 B.SetConfigLayers(block) | |
127 --- methods for event handlers | |
128 block.Select = self.Select | |
129 block.Open = self.Open | |
130 block.Remove = self.Remove | |
131 block.Link = self.Link | |
132 block.clickZone:SetScript('OnMouseUp', function(frame, ...) self.OnMouseUp(block, ...) end) | |
133 block.clickZone:SetScript('OnMouseDown', function(frame, ...) self.OnMouseDown(block, ...) end) | |
134 block:ClearAllPoints() | |
135 block.index = blockIndex | |
136 block.blockFadeOut:SetScript('OnPlay', blockFadeOut_OnPlay) | |
137 source = 'new' | |
138 end | |
139 self.InfoBlock[index] = block | |
140 block.posIndex = tMove(free, used, block) | |
141 print(' |cFF00FF00('..source..')|r |cFF0088FF'..self.name..'|r.|cFF00FFBBusedBlocks['..block.posIndex..'] =|r', block:GetName()) | |
142 end | |
143 block.blockFadeOut:SetScript('OnFinished', blockFadeOut_OnFinished) | |
144 block:SetScript('OnHide', function(self) | |
145 fprint(self:GetName(), '|cFF00FF00HIDE|r', debugstack(1,3,1)) | |
146 if(self.DebugTab:IsShown()) then | |
147 self.DebugTab:Hide() | |
148 end | |
149 self.blockFadeOut:SetScript('OnFinished', blockFadeOut_OnFinished) | |
150 self.isAnimating = nil | |
151 end) | |
152 print(' used/free: |cFFFFFF00' .. #self.usedBlocks .. '|r/|cFF00FFFF'..#self.freeBlocks ..'|r') | |
153 return block | |
154 end | |
155 | |
156 --- begins a blockFadeOut animation and fires FreeBlock when that's done | |
157 function Default:ClearBlock (block) | |
158 -- double ensure multiple finish scripts from firing | |
159 if block.isAnimating then | |
160 return | |
161 end | |
162 block.isAnimating = true | |
163 block.blockFadeOut:SetScript('OnFinished', nil) | |
164 block.blockFadeOut:SetScript('OnFinished', function(anim) | |
165 --@debug@ | |
166 fprint(anim:GetName(), '|cFFFFFF00FINISHED|r', debugstack())--@end-debug@ | |
167 anim:SetScript('OnFinished', blockFadeOut_OnFinished) | |
168 self:FreeBlock(block) | |
169 block.isAnimating = nil | |
170 end) | |
171 block.blockFadeOut:Play() | |
172 end | |
173 | |
174 --- fired by OnFinished scripts; does the actual table swapping | |
175 function Default:FreeBlock(block) | |
176 bprint('|cFFFF4400FreeBlock|r', block:GetName()) | |
177 local used = self.usedBlocks | |
178 local free = self.freeBlocks | |
179 tMove(used, free, block) | |
180 | |
181 bprint(' |cFFFF4444used/free:|r |cFFFFFF00' .. #used .. '|r/|cFF00FFFF'..#free ..'|r') | |
182 | |
183 block:Hide() | |
184 local animations = {block:GetAnimationGroups() } | |
185 for i, animGroup in ipairs(animations) do | |
186 bprint(' animGroup', i, animGroup:GetName()) | |
187 animGroup:Stop() | |
188 end | |
189 | |
190 T:Update(self.updateReasonsModule) | |
191 end |