annotate ObjectiveTracker/Frame.lua @ 35:69d03f8e293e

- separated layout and data logic between Frame.lua and Update.lua - solved disappearing tracker mystery
author Nenue
date Sun, 17 Apr 2016 11:07:48 -0400
parents 9856ebc63fa4
children a487841050be
rev   line source
Nenue@28 1 --- ${PACKAGE_NAME}
Nenue@28 2 -- @file-author@
Nenue@28 3 -- @project-revision@ @project-hash@
Nenue@28 4 -- @file-revision@ @file-hash@
Nenue@28 5 -- Created: 3/30/2016 12:49 AM
Nenue@28 6 local B = select(2,...).frame
Nenue@35 7 local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame')
Nenue@28 8 local _G, ipairs, max, min, unpack, floor, pairs, tostring, type, band = _G, ipairs, max, min, unpack, floor, pairs, tostring, type, bit.band
Nenue@34 9 local IsResting, UnitXP, UnitXPMax, GetXPExhaustion, tinsert, tremove = IsResting, UnitXP, UnitXPMax, GetXPExhaustion, table.insert, table.remove
Nenue@28 10 local UnitLevel, IsQuestWatched, UIParent = UnitLevel, IsQuestWatched, UIParent
Nenue@28 11 local GetAutoQuestPopUp, GetQuestLogCompletionText = GetAutoQuestPopUp, GetQuestLogCompletionText
Nenue@28 12 local PERCENTAGE_STRING, GetQuestProgressBarPercent = PERCENTAGE_STRING, GetQuestProgressBarPercent
Nenue@35 13 local Default, AutoQuest, Quest, Bonus, Cheevs = T.DefaultHandler, T.AutoQuest, T.Quest, T.Bonus, T.Cheevs
Nenue@28 14 local InCombatLockdown, format, lshift, CreateFrame = InCombatLockdown, format, bit.lshift, CreateFrame
Nenue@29 15 local IsModifiedClick, ChatEdit_GetActiveWindow = IsModifiedClick, ChatEdit_GetActiveWindow
Nenue@35 16 local print = B.print('Layout')
Nenue@34 17 local oprint = B.print('Objectives')
Nenue@34 18 local bprint = B.print('Block')
Nenue@34 19 local tprint = B.print('Tracker')
Nenue@35 20 local lprint = B.print('Layout')
Nenue@28 21 local unitLevel = 1
Nenue@28 22 local OBJECTIVE_TRACKER_UPDATE_REASON = OBJECTIVE_TRACKER_UPDATE_REASON
Nenue@28 23 local debug = false
Nenue@28 24
Nenue@34 25 --- FRAMES
Nenue@28 26 local Wrapper = _G.VeneerObjectiveWrapper
Nenue@28 27 local Scroller = Wrapper.scrollArea
Nenue@28 28 local Scroll = _G.VeneerObjectiveScroll
Nenue@35 29 local orderedHandlers = T.orderedHandlers
Nenue@35 30 local orderedNames = T.orderedNames
Nenue@28 31
Nenue@34 32 --- FRAME TEMP VARIABLES
Nenue@28 33 local wrapperWidth, wrapperHeight
Nenue@28 34 local scrollWidth, scrollHeight
Nenue@34 35
Nenue@34 36 --- SCHEMA VARIABLES
Nenue@34 37 local schemaName, lastSchema = {
Nenue@34 38 tracker = '',
Nenue@34 39 block = '',
Nenue@34 40 line = ''
Nenue@34 41 }, {}
Nenue@34 42 local trackerSchema, blockSchema, lineSchema
Nenue@34 43
Nenue@28 44 local itemButtonSize, itemButtonSpacing = 36, 1
Nenue@34 45 local wrapperMaxWidth, wrapperMaxHeight = 270, 490 -- these are the hard bounds, actual *Height variables are changed
Nenue@34 46 local wrapperHeadFont, wrapperHeadSize, wrapperHeadOutline = [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Bold.ttf]], 16, 'NONE'
Nenue@34 47 local wrapperPosition = {'RIGHT', UIParent, 'RIGHT', -84, 0 }
Nenue@34 48 local rewardSize = 24
Nenue@28 49
Nenue@30 50 local headerHeight, headerColor, headerSpacing = 16, {1,.75,0,1}, 2
Nenue@28 51 local headerbg = {'VERTICAL', 1, 1, 0.5, 0.5, 1, 1, 0.5, 0}
Nenue@28 52 local headerFont, headerSize, headerOutline = [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Bold.ttf]], 14, 'OUTLINE'
Nenue@28 53
Nenue@31 54 local titlebg = {'HORIZONTAL', 1, 0, .7, 0, 1, 0, .7, .2}
Nenue@28 55 local titleFont, titleSize, titleOutline = [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Bold.ttf]], 16, 'OUTLINE'
Nenue@34 56 local titleColor = {0,.7,1,1}
Nenue@28 57
Nenue@28 58 local textbg = {'HORIZONTAL', 0, 0, 0, 0.4, 0, 0, 0, 0 }
Nenue@28 59 local textFont, textSize, textOutline = [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Regular.ttf]], 16, 'OUTLINE'
Nenue@34 60 local textColor = {1,1,1,1}
Nenue@28 61
Nenue@28 62 local selectionbg = {'HORIZONTAL', 1, 1, 1, 0, 1, 1, 1, 0.225}
Nenue@28 63 local titleSpacing, textSpacing, blockSpacing = 3, 3, 1
Nenue@28 64 local titleIndent, textIndent,selectionIndent = 2, 5, 50
Nenue@34 65 --- END SCHEMA
Nenue@35 66 local blockPosition
Nenue@35 67
Nenue@34 68 --- schema swapper
Nenue@35 69 T.UpdateSchema = function(layer, newSchema)
Nenue@35 70 if not (T.Conf.Schema[layer] and T.Conf.Schema[layer][newSchema]) then
Nenue@34 71 return
Nenue@34 72 elseif schemaName[layer] == newSchema then
Nenue@34 73 return
Nenue@34 74 end
Nenue@34 75 lastSchema[layer] = schemaName[layer]
Nenue@34 76 schemaName[layer] = newSchema
Nenue@35 77 local c = T.Conf.Schema[layer][newSchema]
Nenue@28 78
Nenue@34 79 if layer == 'tracker' then
Nenue@34 80 headerHeight, headerSpacing = c.headerHeight, c.headerSpacing
Nenue@34 81 headerColor = c.headerColor
Nenue@34 82 headerbg = c.headerbg
Nenue@34 83 headerFont, headerSize, headerOutline = c.headerFont, c.headerSize, c.headerOutline
Nenue@34 84 trackerSchema = newSchema
Nenue@34 85 elseif layer == 'block' then
Nenue@34 86 titlebg = c.titlebg
Nenue@34 87 titleFont, titleSize, titleOutline = c.titleFont, c.titleSize, c.titleOutline
Nenue@34 88 selectionbg = c.selectionbg
Nenue@34 89 titleSpacing, textSpacing, blockSpacing = c.titleSpacing, c.textSpacing, c.blockSpacing
Nenue@34 90 titleIndent, textIndent,selectionIndent = 2, 5, 50
Nenue@34 91 titleColor = c.titleColor
Nenue@34 92 rewardSize = 24
Nenue@34 93 blockSchema = newSchema
Nenue@34 94 textFont, textSize, textOutline = c.textFont, c.textSize, c.textOutline
Nenue@34 95 textbg = c.textbg
Nenue@34 96 textIndent = c.textIndent
Nenue@34 97 rewardSize = c.rewardSize
Nenue@34 98 elseif layer == 'line' then
Nenue@34 99 textColor = c.textColor
Nenue@34 100 lineSchema = newSchema
Nenue@34 101 end
Nenue@34 102 print('|cFFFF0088UpdateSchema:|r', layer, lastSchema[layer], '->', newSchema)
Nenue@34 103 end
Nenue@35 104 -- todo: figure out why objectives go invisible
Nenue@35 105 local anchorPoint, anchorFrame
Nenue@35 106 local abs, GetTime = math.abs, GetTime
Nenue@35 107 Default.AddTracker = function(handler, frame, index)
Nenue@35 108 if index == 1 then
Nenue@35 109 print('|cFF00FF00### beginning wrapper layout -----------------')
Nenue@35 110 anchorPoint, anchorFrame = 'TOP', Scroll
Nenue@35 111 wrapperHeight = 0
Nenue@35 112 end
Nenue@35 113
Nenue@35 114 frame.destinationOffset = -wrapperHeight
Nenue@35 115 print(frame.destinationOffset, frame.previousOffset)
Nenue@35 116 if handler.initialized and (abs(frame.previousOffset - frame.destinationOffset) > 0.9) and frame:IsVisible() then
Nenue@35 117 if frame.wasEmpty then
Nenue@35 118 frame.previousOffset = -Wrapper:GetHeight()
Nenue@35 119 end
Nenue@35 120
Nenue@35 121 local postFrame, postPoint = anchorFrame, anchorPoint
Nenue@35 122 local delta = frame.destinationOffset - frame.previousOffset
Nenue@35 123 local _, _, _, _, offset = frame:GetPoint(1)
Nenue@35 124 print(' |cFF00FFBBpushing', frame:GetName(), delta, 'pixels, from', frame.previousOffset, '(', offset, ')')
Nenue@35 125 frame.SlideIn.translation:SetTarget(frame)
Nenue@35 126 frame.SlideIn.translation:SetOffset(0, delta)
Nenue@35 127 frame.SlideIn:Play()
Nenue@35 128 --for i, b in ipairs(handler.usedBlocks) do
Nenue@35 129 --b.SlideIn.translation:SetOffset(0, delta)
Nenue@35 130 -- b.SlideIn:Play()
Nenue@35 131 --end
Nenue@35 132 local start = GetTime()
Nenue@35 133 frame.SlideIn:SetScript('OnFinished', function()
Nenue@35 134 print(' |cFF00BBFF'..frame:GetName(), 'moved', delta, 'over duration of ', GetTime()-start)
Nenue@35 135 frame:SetParent(Scroll)
Nenue@35 136 frame:SetPoint('TOP', Scroll, 'TOP', 0, frame.destinationOffset)
Nenue@35 137 frame.previousOffset = frame.destinationOffset
Nenue@35 138 frame.SlideIn:SetScript('OnFinished', nil)
Nenue@35 139 if Wrapper.destinationHeight then
Nenue@35 140 Wrapper:SetHeight(Wrapper.destinationHeight)
Nenue@35 141 Scroller:SetHeight(Wrapper.destinationHeight)
Nenue@35 142 Scroll:SetHeight(Wrapper.destinationHeight)
Nenue@35 143 Wrapper.previousHeight = Wrapper.destinationHeight
Nenue@35 144 Wrapper.destinationHeight = nil
Nenue@35 145 end
Nenue@35 146
Nenue@35 147 end)
Nenue@35 148 else
Nenue@35 149 print(' |cFF00BBFFpinning to', anchorFrame:GetName(), anchorPoint, '|rcurrent frame height:', frame.height)
Nenue@35 150 print(' |cFFFF0088total height:', wrapperHeight)
Nenue@35 151 frame:ClearAllPoints()
Nenue@35 152 frame:SetParent(Scroll)
Nenue@35 153 frame:SetPoint('TOP', Scroll, 'TOP', 0, frame.destinationOffset)
Nenue@35 154 frame.previousOffset = frame.destinationOffset
Nenue@35 155 handler.initialized = true
Nenue@35 156 end
Nenue@35 157
Nenue@35 158 frame.title:SetFont(headerFont, headerSize, headerOutline)
Nenue@35 159 frame.titlebg:SetHeight(headerHeight)
Nenue@35 160 frame.title:SetTextColor(unpack(headerColor))
Nenue@35 161
Nenue@35 162 if frame.height ~= frame.previousHeight then
Nenue@35 163 frame:SetHeight(frame.height)
Nenue@35 164 end
Nenue@35 165
Nenue@35 166 frame:Show()
Nenue@35 167 if frame.wasEmpty then
Nenue@35 168 frame.headerFade:Play()
Nenue@35 169 frame.wasEmpty = nil
Nenue@35 170 end
Nenue@35 171
Nenue@35 172 wrapperHeight = wrapperHeight + frame.height
Nenue@35 173 anchorFrame = handler.frame
Nenue@35 174 anchorPoint = 'BOTTOM'
Nenue@35 175
Nenue@35 176 end
Nenue@28 177
Nenue@30 178 Default.AddBlock = function(self, block, blockIndex)
Nenue@30 179 local blockIndex = blockIndex or (self.currentBlock + 1)
Nenue@28 180 local print = bprint
Nenue@28 181 local tracker = self.frame
Nenue@28 182 local info = block.info
Nenue@30 183
Nenue@35 184 block.index = blockIndex
Nenue@35 185
Nenue@34 186 if blockSchema ~= block.schema then
Nenue@34 187 print('new schema detected, applicating...')
Nenue@34 188 block.schema = blockSchema
Nenue@35 189 block:SetWidth(T.Conf.Wrapper.Width)
Nenue@34 190 block.title:SetSpacing(titleSpacing)
Nenue@34 191 block.title:SetPoint('TOP', block, 'TOP', 0, -titleSpacing)
Nenue@34 192 block.title:SetPoint('LEFT', block, 'LEFT', titleIndent, 0)
Nenue@34 193 block.titlebg:SetTexture(1,1,1,1)
Nenue@34 194 block.titlebg:SetGradientAlpha(unpack(titlebg))
Nenue@34 195 block.titlebg:SetPoint('TOP', block, 'TOP', 0, 0)
Nenue@34 196 block.titlebg:SetPoint('BOTTOM', block.title, 'BOTTOM', 0, -titleSpacing)
Nenue@34 197 block.status:SetSpacing(textSpacing)
Nenue@34 198 block.status:SetPoint('TOP', block.titlebg, 'BOTTOM', 0, -textSpacing)
Nenue@34 199 block.status:SetPoint('LEFT', block.titlebg, 'LEFT', textIndent, 0)
Nenue@34 200 block.statusbg:SetPoint('TOP', block.titlebg, 'BOTTOM', 0, 0)
Nenue@34 201 block.statusbg:SetPoint('BOTTOM', block, 'BOTTOM', 0, 0)
Nenue@34 202 block.statusbg:SetTexture(1,1,1,1)
Nenue@34 203 block.statusbg:SetGradientAlpha(unpack(textbg))
Nenue@34 204 block.SelectionOverlay:SetGradientAlpha(unpack(selectionbg))
Nenue@34 205 block.SelectionOverlay:SetPoint('TOPLEFT', selectionIndent, 0)
Nenue@34 206 block.SelectionOverlay:SetPoint('BOTTOMRIGHT')
Nenue@34 207
Nenue@34 208 local anchor, target, point, x, y = 'TOPRIGHT', block, 'TOPRIGHT', -2, -2
Nenue@34 209 for i, tile in ipairs(block.rewardTile) do
Nenue@34 210 print(rewardSize)
Nenue@34 211 tile:SetSize(rewardSize, rewardSize)
Nenue@34 212 tile:ClearAllPoints()
Nenue@34 213 tile:SetPoint(anchor, target, point, x, y)
Nenue@34 214 block.rewardLabel[i]:SetPoint('TOP', tile, 'TOP', 0, 0)
Nenue@34 215 anchor, target, point, x, y = 'TOPRIGHT', tile, 'TOPLEFT', -2, 0
Nenue@34 216 end
Nenue@34 217 end
Nenue@34 218
Nenue@35 219
Nenue@35 220 local titleHeight = floor(block.title:GetHeight()+.5)
Nenue@35 221 local titlebgHeight = titleHeight + titleSpacing*2
Nenue@35 222 block.titlebg:SetHeight(titlebgHeight)
Nenue@35 223
Nenue@35 224 local statusHeight = floor(block.status:GetHeight()+.5)
Nenue@35 225 local statusbgHeight = statusHeight + textSpacing*2
Nenue@35 226 local attachmentHeight =floor(block.attachmentHeight + .5)
Nenue@35 227
Nenue@35 228 print(' |cFF0088FFanchor to', self.currentAnchor:GetName())
Nenue@35 229 print(' |cFF00FF00attachment:|r', attachmentHeight, '|cFF00FF00title:|r', titlebgHeight, '('.. titleHeight..')')
Nenue@35 230 if attachmentHeight > 0 then
Nenue@35 231 attachmentHeight = attachmentHeight + textSpacing
Nenue@35 232 end
Nenue@35 233
Nenue@35 234 block.height = titlebgHeight + attachmentHeight
Nenue@35 235 block:SetHeight(block.height)
Nenue@35 236
Nenue@34 237 if block.debug then
Nenue@34 238 local func = (B.Conf.GuidesMode == true) and 'Show' or 'Hide'
Nenue@34 239 for _, region in ipairs(block.debug) do
Nenue@34 240 region[func]()
Nenue@34 241 end
Nenue@34 242 end
Nenue@34 243
Nenue@35 244 --- Handler vars
Nenue@35 245 if blockIndex == 1 then
Nenue@35 246 tracker.previousHeight = tracker.height
Nenue@35 247 tracker.height = headerHeight
Nenue@35 248 blockPosition = -headerHeight
Nenue@35 249 tprint(' |cFF88FF00AddBlock:|r new layout: headerHeight =', headerHeight, 'previousHeight =', tracker.previousHeight)
Nenue@35 250 else
Nenue@35 251 blockPosition = blockPosition
Nenue@35 252 tprint(' |cFF8888FFAddBlock:|r advancing: height =', tracker.height)
Nenue@35 253 end
Nenue@30 254 self.currentBlock = blockIndex
Nenue@29 255 self.currentAnchor = block
Nenue@35 256
Nenue@35 257 block:SetPoint('TOPLEFT', self.frame, 'TOPLEFT', 0, blockPosition)
Nenue@35 258 block:SetPoint('RIGHT', tracker,'RIGHT', 0, 0)
Nenue@35 259 self.numBlocks = self.numBlocks + 1
Nenue@29 260 print(' |cFFFFFF00'..tracker.height..'|r', '|cFF00FF00'..block:GetName()..'|r', block.height, tracker.height)
Nenue@29 261 tracker.height = tracker.height + block.height
Nenue@35 262 blockPosition = blockPosition - block.height
Nenue@28 263 end
Nenue@28 264
Nenue@28 265 --- Used as an iterator of sorts for cascaded tag icon placements (the daily/faction/account icons)
Nenue@30 266 Default.AddTag = function (handler, block, tagInfo, tagPoint, tagAnchor, tagRelative)
Nenue@28 267 local print = bprint
Nenue@30 268
Nenue@30 269 for order, tagName in ipairs(block.info.tagInfo) do
Nenue@30 270 local tag = block[tagName]
Nenue@30 271 if block.tagCoords[tagName] and tag then
Nenue@30 272 tag:SetTexCoord(unpack(block.tagCoords[tagName]))
Nenue@30 273 tag:Show()
Nenue@30 274 tag:SetPoint(tagPoint, tagAnchor, tagRelative, 0, 0)
Nenue@30 275 tagPoint, tagAnchor, tagRelative = 'TOPRIGHT', tag, 'TOPLEFT'
Nenue@30 276 else
Nenue@30 277 block[tagName]:Hide()
Nenue@30 278 end
Nenue@28 279 end
Nenue@30 280
Nenue@28 281 return tagPoint, tagAnchor, tagRelative
Nenue@28 282 end
Nenue@28 283
Nenue@28 284 --- Adds the given line to the current content and advances the anchor pointer to that new line for the following call.
Nenue@30 285 Default.AddLine = function(handler, block, text, attachment, template)
Nenue@28 286 local print = lprint
Nenue@30 287 local lineIndex = block.currentLine + 1
Nenue@34 288 local line = handler:GetLine(block, lineIndex)
Nenue@31 289 line.index = lineIndex
Nenue@35 290 if template then
Nenue@35 291 if line.schema ~= template then
Nenue@35 292 print(' |cFF00FF00change schema', template)
Nenue@35 293 T.UpdateSchema('line', template)
Nenue@35 294 line.status:SetSpacing(textSpacing)
Nenue@35 295 line.status:SetPoint('LEFT', line, 'LEFT', textIndent, 0)
Nenue@35 296 line.status:SetPoint('RIGHT', line, 'RIGHT',0, 0)
Nenue@35 297 line.status:SetTextColor(unpack(textColor))
Nenue@35 298 line.schema = template
Nenue@35 299 else
Nenue@35 300 print(' |cFFFFFF00keep schema', line.schema)
Nenue@35 301 end
Nenue@34 302 end
Nenue@34 303 line:SetPoint('TOP', block.endPoint, 'BOTTOM', 0, -textSpacing)
Nenue@28 304 line:Show()
Nenue@28 305
Nenue@34 306
Nenue@35 307 tprint(' |cFF0088FFAddLine|r (|cFF00FFFF'..tostring(line.schema)..'|r):', line:GetName())
Nenue@34 308
Nenue@34 309
Nenue@34 310 -- fill in the text, then derive pixel-rounded height
Nenue@30 311 line.status:SetText(text)
Nenue@34 312 line.height = floor(line.status:GetStringHeight()+.5)
Nenue@30 313
Nenue@30 314 -- For progressbar and timer lines, status text may be used as the title heading
Nenue@30 315 if attachment then
Nenue@35 316 print(' |cFFFF0088doing things with a widget', attachment:GetSize())
Nenue@34 317 line.height = attachment:GetHeight()
Nenue@34 318 if text then
Nenue@34 319 line.height = max(line.height, line.status:GetStringHeight())
Nenue@31 320 end
Nenue@34 321 if attachment.status:GetText() then
Nenue@34 322 line.height = max(line.height, attachment.status:GetStringHeight())
Nenue@34 323 end
Nenue@30 324 attachment:Show()
Nenue@30 325 end
Nenue@30 326
Nenue@34 327 line:SetHeight(line.height)
Nenue@34 328 block.attachmentHeight = block.attachmentHeight + line.height + textSpacing
Nenue@35 329
Nenue@35 330 local debug_points = ''
Nenue@35 331 for i = 1, line:GetNumPoints() do
Nenue@35 332 local point, parent, anchor = line:GetPoint(i)
Nenue@35 333 debug_points = debug_points .. tostring(parent:GetName()) .. ', ' .. anchor .. ' '
Nenue@35 334 end
Nenue@35 335
Nenue@35 336 print(' |cFF0088FFsetting line #'..lineIndex..' for|r', block.info.title, "\n |cFF0088FFsize:|r", line.height,
Nenue@35 337 "|cFF0088FFpoint:|r", debug_points, "|cFF0088FFwidget:|r", (line.widget and 'Y' or 'N'))
Nenue@30 338 block.currentLine = lineIndex
Nenue@31 339 block.endPoint = line.statusbg -- edge used for the next block
Nenue@31 340
Nenue@31 341 return lineIndex
Nenue@28 342 end
Nenue@28 343
Nenue@28 344 --- Creates or retrieves a complete line data object
Nenue@30 345 Default.GetLine = function(handler, block, lineIndex)
Nenue@28 346 local print = lprint
Nenue@28 347 local blockIndex = block.index
Nenue@30 348 local lines = block.lines
Nenue@30 349 if not lineIndex then
Nenue@30 350 lineIndex = block.currentLine + 1
Nenue@34 351 print(' |cFFFFFF00generating a frame')
Nenue@28 352 end
Nenue@30 353
Nenue@30 354 block.numLines = max(block.numLines, lineIndex)
Nenue@30 355
Nenue@28 356 if not lines[lineIndex] then
Nenue@28 357 print(' |cFF00FF88created line #'..lineIndex..' from for '..handler.name..' block #'..blockIndex)
Nenue@28 358 lines[lineIndex] = CreateFrame('Frame', 'Vn'..handler.name .. blockIndex..'ObjectiveLine'..lineIndex, block, 'VeneerTrackerObjective')
Nenue@28 359 local line = lines[lineIndex]
Nenue@28 360 line.index = lineIndex
Nenue@28 361 line.height = 0
Nenue@35 362 line.schema = 'default'
Nenue@28 363 B.SetConfigLayers(line)
Nenue@28 364
Nenue@28 365 if debug then
Nenue@28 366 for _, region in ipairs(lines[lineIndex].debug) do
Nenue@28 367 region:Show()
Nenue@28 368 end
Nenue@28 369 end
Nenue@28 370
Nenue@28 371 end
Nenue@28 372 return lines[lineIndex]
Nenue@28 373 end
Nenue@28 374
Nenue@29 375
Nenue@29 376
Nenue@28 377 --- Creates or retrieves a complete block frame object
Nenue@34 378 --- todo: make it use data index to avoid re-coloring every block
Nenue@34 379 Default.GetBlock = function(handler, logIndex)
Nenue@28 380 local print = bprint
Nenue@35 381 print('|cFF0088FFgetting a block for logID', logIndex ..',', #handler.usedBlocks,'used', #handler.freeBlocks, 'free')
Nenue@34 382 local block = handler.LogBlock[logIndex]
Nenue@35 383 local used = handler.usedBlocks
Nenue@28 384
Nenue@34 385 if not block then
Nenue@28 386 if #handler.freeBlocks >= 1 then
Nenue@34 387 block = tremove(handler.freeBlocks)
Nenue@35 388 tinsert(handler.usedBlocks, block)
Nenue@35 389 block.posIndex = #handler.usedBlocks
Nenue@35 390 print(' |cFF00FF00 assigning from free heap', block:GetName())
Nenue@28 391 else
Nenue@34 392
Nenue@35 393 local blockIndex = (#handler.usedBlocks + #handler.freeBlocks) + 1
Nenue@30 394 block = CreateFrame('Frame', 'Veneer'..tostring(handler)..'Block'..blockIndex, handler.frame, 'VeneerTrackerBlock')
Nenue@35 395 --block:SetParent()
Nenue@30 396 block.lines = {}
Nenue@30 397 block.numLines = 0
Nenue@30 398 block.currentLine = 0
Nenue@34 399 block.attachmentHeight = 0
Nenue@35 400 block.offset = 0
Nenue@34 401 B.SetConfigLayers(block)
Nenue@28 402 --- methods for event handlers
Nenue@28 403
Nenue@28 404 block.Select = handler.Select
Nenue@28 405 block.Open = handler.Open
Nenue@28 406 block.Remove = handler.Remove
Nenue@28 407 block.Link = handler.Link
Nenue@28 408 block.clickZone:SetScript('OnMouseUp', function(self, ...) handler.OnMouseUp(block, ...) end)
Nenue@28 409 block.clickZone:SetScript('OnMouseDown', function(self, ...) handler.OnMouseDown(block, ...) end)
Nenue@28 410 block:ClearAllPoints()
Nenue@34 411 block.index = blockIndex
Nenue@35 412 print(' |cFF00FFBBcreating new|r', block:GetName())
Nenue@28 413 end
Nenue@34 414 handler.LogBlock[logIndex] = block
Nenue@34 415 tinsert(handler.usedBlocks, block)
Nenue@35 416 block.posIndex = #handler.usedBlocks
Nenue@34 417 else
Nenue@34 418 print(' |cFFFFFF00use existing block|r', block:GetName())
Nenue@35 419 local found = false
Nenue@35 420 for i, entry in ipairs(used) do
Nenue@35 421 if entry == block then
Nenue@35 422 found = true
Nenue@35 423 break
Nenue@35 424 end
Nenue@35 425 end
Nenue@35 426 if not found then
Nenue@35 427 tinsert(used, block)
Nenue@35 428 block.posIndex = #used
Nenue@35 429 end
Nenue@28 430 end
Nenue@34 431 return block
Nenue@28 432 end
Nenue@28 433
Nenue@34 434
Nenue@30 435
Nenue@30 436
Nenue@28 437 ----------
Nenue@28 438 --- Top level methods
Nenue@28 439
Nenue@28 440
Nenue@35 441 T.UpdateBlockAction = function (block, itemButton)
Nenue@35 442 local print = bprint
Nenue@28 443 print('**|cFF0088FF'..itemButton:GetName(), '|r:Update()')
Nenue@28 444 if itemButton.questID ~= block.info.questID then
Nenue@28 445 print('** |cFFFF0088mismatched block assignment', itemButton.questID,'<~>', block.info.questID)
Nenue@28 446 -- something happened between this and last frame, go back and set new probes
Nenue@35 447 return T.UpdateActionButtons()
Nenue@28 448 end
Nenue@28 449
Nenue@28 450 local previousItem = itemButton.previousItem
Nenue@28 451 local upper_bound = Scroller:GetTop() + Scroller.snap_upper
Nenue@28 452 local lower_bound = Scroller:GetBottom() + Scroller.snap_lower + itemButtonSize
Nenue@28 453 local point, anchor, relative
Nenue@28 454
Nenue@28 455 if block:GetBottom() < lower_bound then
Nenue@28 456 print('** ',block:GetName() ,'|cFFFFFF00bottom =', floor(block:GetBottom()+.5), 'threschold =', floor(lower_bound+.5))
Nenue@28 457 if previousItem then
Nenue@28 458 print('adjusting', previousItem:GetName())
Nenue@28 459 previousItem:ClearAllPoints()
Nenue@28 460 previousItem:SetPoint('BOTTOM', itemButton, 'TOP', 0, itemButtonSpacing)
Nenue@28 461 end
Nenue@28 462 itemButton:ClearAllPoints()
Nenue@28 463 itemButton.x = Wrapper:GetLeft() -4
Nenue@28 464 itemButton.y = Wrapper:GetBottom()
Nenue@28 465 point, anchor, relative = 'BOTTOMRIGHT', UIParent, 'BOTTOMLEFT'
Nenue@28 466 Scroller.snap_lower = Scroller.snap_lower + itemButtonSize + itemButtonSpacing
Nenue@28 467
Nenue@28 468 elseif block:GetTop() > upper_bound then
Nenue@28 469 print('** ',block:GetName() ,'|cFFFFFF00top =', floor(block:GetTop()+.5), 'threschold =', floor(upper_bound+.5))
Nenue@28 470 itemButton:ClearAllPoints()
Nenue@28 471 if previousItem then
Nenue@28 472 print('latch onto another piece')
Nenue@28 473 point, anchor, relative ='TOP', previousItem, 'BOTTOM'
Nenue@28 474 itemButton.x = 0
Nenue@28 475 itemButton.y = -itemButtonSpacing
Nenue@28 476 else
Nenue@28 477 print('latch at corner', Scroller:GetLeft() -itemButtonSpacing, Scroller:GetTop())
Nenue@28 478 point, anchor, relative = 'TOPRIGHT', UIParent, 'BOTTOMLEFT'
Nenue@28 479 itemButton.x = Scroller:GetLeft() -4
Nenue@28 480 itemButton.y = Scroller:GetTop()
Nenue@28 481 end
Nenue@28 482 itemButton:Show()
Nenue@28 483 Scroller.snap_upper = Scroller.snap_upper - (itemButtonSize + itemButtonSpacing)
Nenue@28 484 else
Nenue@28 485 print('** ',block:GetName() ,'|cFF00FF00span =', floor(block:GetBottom()+.5), floor(block:GetTop()+.5), 'threschold =', floor(lower_bound+.5))
Nenue@28 486 itemButton:ClearAllPoints()
Nenue@28 487 itemButton.x = block:GetLeft() - itemButtonSpacing
Nenue@28 488 itemButton.y = block:GetTop()
Nenue@28 489 point, anchor, relative = 'TOPRIGHT', UIParent, 'BOTTOMLEFT'
Nenue@28 490 end
Nenue@28 491
Nenue@28 492 itemButton:SetPoint(point, anchor, relative, itemButton.x, itemButton.y)
Nenue@28 493 itemButton:Show()
Nenue@28 494 end
Nenue@28 495
Nenue@35 496 T.UpdateItemButtonCooldown = function(button)
Nenue@28 497
Nenue@28 498 end
Nenue@28 499
Nenue@35 500 function T:FinishWrapper ()
Nenue@35 501 if wrapperHeight > Wrapper.previousHeight then
Nenue@35 502 Wrapper:SetHeight(wrapperHeight)
Nenue@35 503 Scroller:SetHeight(wrapperHeight*3)
Nenue@35 504 Scroll:SetHeight(wrapperHeight)
Nenue@35 505 Wrapper.previousHeight = wrapperHeight
Nenue@35 506 Wrapper.destinationHeight = wrapperHeight
Nenue@35 507 end
Nenue@35 508 Scroller:SetVerticalScroll(B.Conf.ObjectiveScroll or 0)
Nenue@35 509 print('|cFF00FF00### end of wrapper layout', Wrapper:GetSize())
Nenue@35 510 print(' |cFF00FF00Scroller:', Scroller:GetSize())
Nenue@35 511 print(' |cFF00FF00Scroll:', Scroll:GetSize())
Nenue@35 512 for i = 1, Wrapper:GetNumPoints() do
Nenue@35 513 print('|cFF00FF00 ', Wrapper:GetPoint(i))
Nenue@35 514 end
Nenue@35 515 for i = 1, Scroller:GetNumPoints() do
Nenue@35 516 print('|cFF00FF00 ', Scroller:GetPoint(i))
Nenue@35 517 end
Nenue@35 518 for i = 1, Scroll:GetNumPoints() do
Nenue@35 519 print('|cFF00FF00 ', Scroll:GetPoint(i))
Nenue@35 520 end
Nenue@34 521
Nenue@35 522 Wrapper:Show()
Nenue@35 523 Scroller:Show()
Nenue@35 524 Scroll:Show()
Nenue@28 525 end
Nenue@28 526