comparison ObjectiveTracker/Frame.lua @ 37:e84d645c8ab8

- revised the tracker update function to build its complete data list up front and use the values as points of comparison for determining possible out of place blocks, which will be iterated over afterward to remove what wasn't re-used - also entailed revising the exact role of global event handlers and function hooks, limiting their directions of communication so one doesn't end up calling the other multiple or inifinity times - schema handling polish
author Nenue
date Mon, 18 Apr 2016 07:56:23 -0400
parents a487841050be
children 1f8f9cc3d956
comparison
equal deleted inserted replaced
36:a487841050be 37:e84d645c8ab8
28 local Scroll = _G.VeneerObjectiveScroll 28 local Scroll = _G.VeneerObjectiveScroll
29 local orderedHandlers = T.orderedHandlers 29 local orderedHandlers = T.orderedHandlers
30 local orderedNames = T.orderedNames 30 local orderedNames = T.orderedNames
31 31
32 --- FRAME TEMP VARIABLES 32 --- FRAME TEMP VARIABLES
33 local wrapperWidth, wrapperHeight 33 local wrapperWidth, wrapperHeight = 0, 0
34 local scrollWidth, scrollHeight 34 local scrollWidth, scrollHeight
35 35
36 --- SCHEMA VARIABLES 36 --- SCHEMA VARIABLES
37 local schemaName, lastSchema = { 37 local schemaName, lastSchema = {
38 tracker = '', 38 tracker = '',
78 78
79 if layer == 'tracker' then 79 if layer == 'tracker' then
80 headerHeight, headerSpacing = c.headerHeight, c.headerSpacing 80 headerHeight, headerSpacing = c.headerHeight, c.headerSpacing
81 headerColor = c.headerColor 81 headerColor = c.headerColor
82 headerbg = c.headerbg 82 headerbg = c.headerbg
83 headerFont, headerSize, headerOutline = c.headerFont, c.headerSize, c.headerOutline 83 headerFont, headerSize, headerOutline = unpack(c.headerFont)
84 trackerSchema = newSchema 84 trackerSchema = newSchema
85 elseif layer == 'block' then 85 elseif layer == 'block' then
86 titlebg = c.titlebg 86 titlebg = c.titlebg
87 titleFont, titleSize, titleOutline = c.titleFont, c.titleSize, c.titleOutline 87 titleFont, titleSize, titleOutline = unpack(c.titleFont)
88 selectionbg = c.selectionbg 88 selectionbg = c.selectionbg
89 titleSpacing, textSpacing, blockSpacing = c.titleSpacing, c.textSpacing, c.blockSpacing 89 titleSpacing, textSpacing, blockSpacing = c.titleSpacing, c.textSpacing, c.blockSpacing
90 titleIndent, textIndent,selectionIndent = 2, 5, 50 90 titleIndent, textIndent,selectionIndent = c.titleIndex, c.textIndex, c.selectionIndent
91 titleColor = c.titleColor 91 titleColor = c.titleColor
92 print(unpack(c.titleColor))
92 rewardSize = 24 93 rewardSize = 24
93 blockSchema = newSchema 94 textFont, textSize, textOutline = unpack(c.textFont)
94 textFont, textSize, textOutline = c.textFont, c.textSize, c.textOutline
95 textbg = c.textbg 95 textbg = c.textbg
96 textIndent = c.textIndent 96 textIndent = c.textIndent
97 rewardSize = c.rewardSize 97 rewardSize = c.rewardSize
98 blockSchema = newSchema
98 elseif layer == 'line' then 99 elseif layer == 'line' then
99 textColor = c.textColor 100 textColor = c.textColor
100 lineSchema = newSchema 101 lineSchema = newSchema
101 end 102 end
102 print('|cFFFF0088UpdateSchema:|r', layer, lastSchema[layer], '->', newSchema) 103 tprint('|cFFFF0088UpdateSchema:|r', layer, lastSchema[layer], '->', newSchema)
103 end 104 end
104 -- todo: figure out why objectives go invisible 105 -- todo: figure out why objectives go invisible
105 local anchorPoint, anchorFrame 106 local anchorPoint, anchorFrame
106 local abs, GetTime = math.abs, GetTime 107 local abs, GetTime = math.abs, GetTime
107 Default.AddTracker = function(handler, frame, index) 108 Default.AddTracker = function(handler, frame, index)
144 Wrapper.destinationHeight = nil 145 Wrapper.destinationHeight = nil
145 end 146 end
146 147
147 end) 148 end)
148 else 149 else
149 print(' |cFF00BBFFpinning to', anchorFrame:GetName(), anchorPoint, '|rcurrent frame height:', frame.height) 150 print(' |cFF00BBFFpinning '..handler.name..' to', anchorFrame:GetName(), anchorPoint, '|rcurrent frame height:', frame.height)
150 print(' |cFFFF0088total height:', wrapperHeight) 151 print(' |cFFFF0088total height:', wrapperHeight)
151 frame:ClearAllPoints() 152 frame:ClearAllPoints()
152 frame:SetParent(Scroll) 153 frame:SetParent(Scroll)
153 frame:SetPoint('TOP', Scroll, 'TOP', 0, frame.destinationOffset) 154 frame:SetPoint('TOP', Scroll, 'TOP', 0, frame.destinationOffset)
154 frame.previousOffset = frame.destinationOffset 155 frame.previousOffset = frame.destinationOffset
181 local tracker = self.frame 182 local tracker = self.frame
182 local info = block.info 183 local info = block.info
183 184
184 block.index = blockIndex 185 block.index = blockIndex
185 186
187 print('blockschema', blockSchema, block.schema)
186 if blockSchema ~= block.schema then 188 if blockSchema ~= block.schema then
189 T.UpdateSchema('block', block.schema)
187 print('new schema detected, applicating...') 190 print('new schema detected, applicating...')
188 block.schema = blockSchema 191 end
189 block:SetWidth(T.Conf.Wrapper.Width) 192
190 block.title:SetSpacing(titleSpacing) 193 block:SetWidth(T.Conf.Wrapper.Width)
191 block.title:SetPoint('TOP', block, 'TOP', 0, -titleSpacing) 194 block.title:SetSpacing(titleSpacing)
192 block.title:SetPoint('LEFT', block, 'LEFT', titleIndent, 0) 195 block.title:SetPoint('TOP', block, 'TOP', 0, -titleSpacing)
193 block.titlebg:SetTexture(1,1,1,1) 196 block.title:SetPoint('LEFT', block, 'LEFT', titleIndent, 0)
194 block.titlebg:SetGradientAlpha(unpack(titlebg)) 197 block.title:SetTextColor(unpack(titleColor))
195 block.titlebg:SetPoint('TOP', block, 'TOP', 0, 0) 198 block.titlebg:SetTexture(1,1,1,1)
196 block.titlebg:SetPoint('BOTTOM', block.title, 'BOTTOM', 0, -titleSpacing) 199 block.titlebg:SetGradientAlpha(unpack(titlebg))
197 block.status:SetSpacing(textSpacing) 200 block.titlebg:SetPoint('TOP', block, 'TOP', 0, 0)
198 block.status:SetPoint('TOP', block.titlebg, 'BOTTOM', 0, -textSpacing) 201 block.titlebg:SetPoint('BOTTOM', block.title, 'BOTTOM', 0, -titleSpacing)
199 block.status:SetPoint('LEFT', block.titlebg, 'LEFT', textIndent, 0) 202 block.status:SetSpacing(textSpacing)
200 block.statusbg:SetPoint('TOP', block.titlebg, 'BOTTOM', 0, 0) 203 block.status:SetPoint('TOP', block.titlebg, 'BOTTOM', 0, -textSpacing)
201 block.statusbg:SetPoint('BOTTOM', block, 'BOTTOM', 0, 0) 204 block.status:SetPoint('LEFT', block.titlebg, 'LEFT', textIndent, 0)
202 block.statusbg:SetTexture(1,1,1,1) 205 block.statusbg:SetPoint('TOP', block.titlebg, 'BOTTOM', 0, 0)
203 block.statusbg:SetGradientAlpha(unpack(textbg)) 206 block.statusbg:SetPoint('BOTTOM', block, 'BOTTOM', 0, 0)
204 block.SelectionOverlay:SetGradientAlpha(unpack(selectionbg)) 207 block.statusbg:SetTexture(1,1,1,1)
205 block.SelectionOverlay:SetPoint('TOPLEFT', selectionIndent, 0) 208 block.statusbg:SetGradientAlpha(unpack(textbg))
206 block.SelectionOverlay:SetPoint('BOTTOMRIGHT') 209 block.SelectionOverlay:SetGradientAlpha(unpack(selectionbg))
207 210 block.SelectionOverlay:SetPoint('TOPLEFT', selectionIndent, 0)
208 local anchor, target, point, x, y = 'TOPRIGHT', block, 'TOPRIGHT', -2, -2 211 block.SelectionOverlay:SetPoint('BOTTOMRIGHT')
209 for i, tile in ipairs(block.rewardTile) do 212
210 print(rewardSize) 213 local anchor, target, point, x, y = 'TOPRIGHT', block, 'TOPRIGHT', -2, -2
211 tile:SetSize(rewardSize, rewardSize) 214 for i, tile in ipairs(block.rewardTile) do
212 tile:ClearAllPoints() 215 --print(rewardSize)
213 tile:SetPoint(anchor, target, point, x, y) 216 tile:SetSize(rewardSize, rewardSize)
214 block.rewardLabel[i]:SetPoint('TOP', tile, 'TOP', 0, 0) 217 tile:ClearAllPoints()
215 anchor, target, point, x, y = 'TOPRIGHT', tile, 'TOPLEFT', -2, 0 218 tile:SetPoint(anchor, target, point, x, y)
216 end 219 block.rewardLabel[i]:SetPoint('TOP', tile, 'TOP', 0, 0)
220 anchor, target, point, x, y = 'TOPRIGHT', tile, 'TOPLEFT', -2, 0
217 end 221 end
218 222
219 223
220 local titleHeight = floor(block.title:GetHeight()+.5) 224 local titleHeight = floor(block.title:GetHeight()+.5)
221 local titlebgHeight = titleHeight + titleSpacing*2 225 local titlebgHeight = titleHeight + titleSpacing*2
300 else 304 else
301 print(' |cFFFFFF00keep schema', line.schema) 305 print(' |cFFFFFF00keep schema', line.schema)
302 end 306 end
303 end 307 end
304 line:SetPoint('TOP', block.endPoint, 'BOTTOM', 0, -textSpacing) 308 line:SetPoint('TOP', block.endPoint, 'BOTTOM', 0, -textSpacing)
309 line.status:SetPoint('LEFT', line, 'LEFT', textIndent, 0)
310 line:SetPoint('LEFT', block, 'LEFT')
311 line:SetPoint('RIGHT', block, 'RIGHT')
305 line:Show() 312 line:Show()
306 313
307 314
308 tprint(' |cFF0088FFAddLine|r (|cFF00FFFF'..tostring(line.schema)..'|r):', line:GetName()) 315 tprint(' |cFF0088FFAddLine|r (|cFF00FFFF'..tostring(line.schema)..'|r):', line:GetName())
309 316
358 print(' |cFF00FF88created line #'..lineIndex..' from for '..handler.name..' block #'..blockIndex) 365 print(' |cFF00FF88created line #'..lineIndex..' from for '..handler.name..' block #'..blockIndex)
359 lines[lineIndex] = CreateFrame('Frame', 'Vn'..handler.name .. blockIndex..'ObjectiveLine'..lineIndex, block, 'VeneerTrackerObjective') 366 lines[lineIndex] = CreateFrame('Frame', 'Vn'..handler.name .. blockIndex..'ObjectiveLine'..lineIndex, block, 'VeneerTrackerObjective')
360 local line = lines[lineIndex] 367 local line = lines[lineIndex]
361 line.index = lineIndex 368 line.index = lineIndex
362 line.height = 0 369 line.height = 0
363 line.schema = 'default' 370 line.schema = ''
364 B.SetConfigLayers(line) 371 B.SetConfigLayers(line)
365 372
366 if debug then 373 if debug then
367 for _, region in ipairs(lines[lineIndex].debug) do 374 for _, region in ipairs(lines[lineIndex].debug) do
368 region:Show() 375 region:Show()
375 382
376 383
377 384
378 --- Creates or retrieves a complete block frame object 385 --- Creates or retrieves a complete block frame object
379 --- todo: make it use data index to avoid re-coloring every block 386 --- todo: make it use data index to avoid re-coloring every block
380 Default.GetBlock = function(handler, logIndex) 387 Default.GetBlock = function(handler, index)
381 local print = bprint 388 local print = bprint
382 print('|cFF0088FFgetting a block for logID', logIndex ..',', #handler.usedBlocks,'used', #handler.freeBlocks, 'free') 389 print('|cFF0088FFgetting a block for index', index ..',', #handler.usedBlocks,'used', #handler.freeBlocks, 'free')
383 local block = handler.LogBlock[logIndex] 390 local block = handler.InfoBlock[index]
384 local used = handler.usedBlocks 391 local used = handler.usedBlocks
385 392
386 if not block then 393 if not block then
387 if #handler.freeBlocks >= 1 then 394 if #handler.freeBlocks >= 1 then
388 block = tremove(handler.freeBlocks) 395 block = tremove(handler.freeBlocks)
392 else 399 else
393 400
394 local blockIndex = (#handler.usedBlocks + #handler.freeBlocks) + 1 401 local blockIndex = (#handler.usedBlocks + #handler.freeBlocks) + 1
395 block = CreateFrame('Frame', 'Veneer'..tostring(handler)..'Block'..blockIndex, handler.frame, 'VeneerTrackerBlock') 402 block = CreateFrame('Frame', 'Veneer'..tostring(handler)..'Block'..blockIndex, handler.frame, 'VeneerTrackerBlock')
396 --block:SetParent() 403 --block:SetParent()
404 block.schema = ''
397 block.lines = {} 405 block.lines = {}
398 block.numLines = 0 406 block.numLines = 0
399 block.currentLine = 0 407 block.currentLine = 0
400 block.attachmentHeight = 0 408 block.attachmentHeight = 0
401 block.offset = 0 409 block.offset = 0
410 block.clickZone:SetScript('OnMouseDown', function(self, ...) handler.OnMouseDown(block, ...) end) 418 block.clickZone:SetScript('OnMouseDown', function(self, ...) handler.OnMouseDown(block, ...) end)
411 block:ClearAllPoints() 419 block:ClearAllPoints()
412 block.index = blockIndex 420 block.index = blockIndex
413 print(' |cFF00FFBBcreating new|r', block:GetName()) 421 print(' |cFF00FFBBcreating new|r', block:GetName())
414 end 422 end
415 handler.LogBlock[logIndex] = block 423 handler.InfoBlock[index] = block
416 tinsert(handler.usedBlocks, block) 424 tinsert(handler.usedBlocks, block)
417 block.posIndex = #handler.usedBlocks 425 block.posIndex = #handler.usedBlocks
418 else 426 else
419 print(' |cFFFFFF00use existing block|r', block:GetName()) 427 print(' |cFFFFFF00use existing block|r', block:GetName())
420 local found = false 428 local found = false