annotate ObjectiveTracker/Frame.lua @ 30:7583684becf4

- implement procedural block contents generation - redo anchor calculations to allow for transitional animation - attempt to sort out event handling quirks related to autopopup quest completion and turn-in - revise the data structures created by the different GetInfo's - start on trimming out redundant variables
author Nenue
date Thu, 14 Apr 2016 17:11:13 -0400
parents adcd7c328d07
children 48b3e3959a0a
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@30 7 local Module = 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@28 9 local IsResting, UnitXP, UnitXPMax, GetXPExhaustion = IsResting, UnitXP, UnitXPMax, GetXPExhaustion
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@30 13 local Default, AutoQuest, Quest, Bonus, Cheevs = Module.DefaultHandler, Module.AutoQuest, Module.Quest, Module.Bonus, Module.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@28 16 local print = B.print('Tracker')
Nenue@28 17 local unitLevel = 1
Nenue@28 18 local OBJECTIVE_TRACKER_UPDATE_REASON = OBJECTIVE_TRACKER_UPDATE_REASON
Nenue@28 19 local debug = false
Nenue@28 20
Nenue@28 21 --- Upvalues
Nenue@28 22 local Wrapper = _G.VeneerObjectiveWrapper
Nenue@28 23 local Scroller = Wrapper.scrollArea
Nenue@28 24 local Scroll = _G.VeneerObjectiveScroll
Nenue@30 25 local orderedHandlers = Module.orderedHandlers
Nenue@30 26 local orderedNames = Module.orderedNames
Nenue@28 27
Nenue@28 28 --- Temp values set during updates
Nenue@28 29 local wrapperWidth, wrapperHeight
Nenue@28 30 local scrollWidth, scrollHeight
Nenue@28 31 local previousBlock
Nenue@28 32 local currentBlock
Nenue@28 33 --- todo: source these from config
Nenue@28 34 local itemButtonSize, itemButtonSpacing = 36, 1
Nenue@28 35
Nenue@30 36 local headerHeight, headerColor, headerSpacing = 16, {1,.75,0,1}, 2
Nenue@28 37 local headerbg = {'VERTICAL', 1, 1, 0.5, 0.5, 1, 1, 0.5, 0}
Nenue@28 38 local headerFont, headerSize, headerOutline = [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Bold.ttf]], 14, 'OUTLINE'
Nenue@28 39
Nenue@28 40 local titlebg = {'HORIZONTAL', 1, 0, .7, .25, 1, 0, .7, .125}
Nenue@28 41 local titlebg_daily = {'HORIZONTAL', 0, .7, 1, .25, 0, 1, .7, .125 }
Nenue@28 42 local titlebg_account = {'HORIZONTAL', 0, .45, 1, .25, 0, .45, 1, .125}
Nenue@28 43 local titleFont, titleSize, titleOutline = [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Bold.ttf]], 16, 'OUTLINE'
Nenue@28 44
Nenue@28 45 local textbg = {'HORIZONTAL', 0, 0, 0, 0.4, 0, 0, 0, 0 }
Nenue@28 46 local textbg_daily = {'HORIZONTAL', 0, .7, 1, .1, 0, 1, .7, .075 }
Nenue@28 47 local textbg_account = {'HORIZONTAL', 0, .45, 1, 0.4, 0, .41, 1, .085 }
Nenue@28 48 local textFont, textSize, textOutline = [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Regular.ttf]], 16, 'OUTLINE'
Nenue@28 49
Nenue@28 50
Nenue@28 51 local selectionbg = {'HORIZONTAL', 1, 1, 1, 0, 1, 1, 1, 0.225}
Nenue@28 52 local titleSpacing, textSpacing, blockSpacing = 3, 3, 1
Nenue@28 53 local titleIndent, textIndent,selectionIndent = 2, 5, 50
Nenue@28 54
Nenue@30 55 local lineColors = {
Nenue@30 56 text = {.5,.75,1},
Nenue@30 57 }
Nenue@30 58
Nenue@28 59 local wrapperMaxWidth, wrapperMaxHeight = 270, 490 -- these are the hard bounds, actual *Height variables are changed
Nenue@28 60 local wrapperHeadFont, wrapperHeadSize, wrapperHeadOutline = [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Bold.ttf]], 16, 'NONE'
Nenue@28 61 local wrapperPosition = {'RIGHT', UIParent, 'RIGHT', -84, 0 }
Nenue@28 62 local rewardSize = 32
Nenue@28 63 local oprint = B.print('Objectives')
Nenue@28 64 local bprint = B.print('Block')
Nenue@28 65 local tprint = B.print('Tracker')
Nenue@28 66 local lprint = B.print('Line')
Nenue@28 67
Nenue@30 68 Default.AddBlock = function(self, block, blockIndex)
Nenue@30 69 local blockIndex = blockIndex or (self.currentBlock + 1)
Nenue@28 70 local print = bprint
Nenue@28 71 local tracker = self.frame
Nenue@28 72 local info = block.info
Nenue@30 73
Nenue@30 74 block.index = blockIndex
Nenue@30 75 block:SetPoint('TOPLEFT', self.frame, 'TOPLEFT', 0, block.offset)
Nenue@29 76 block:SetPoint('RIGHT', tracker,'RIGHT', 0, 0)
Nenue@30 77 self.currentBlock = blockIndex
Nenue@29 78 self.currentAnchor = block
Nenue@29 79 print(' |cFFFFFF00'..tracker.height..'|r', '|cFF00FF00'..block:GetName()..'|r', block.height, tracker.height)
Nenue@29 80 tracker.height = tracker.height + block.height
Nenue@30 81 self.numBlocks = max(self.numBlocks, blockIndex)
Nenue@29 82 self.actualBlocks = self.actualBlocks + 1
Nenue@28 83 end
Nenue@28 84
Nenue@28 85 --- Used as an iterator of sorts for cascaded tag icon placements (the daily/faction/account icons)
Nenue@30 86 Default.AddTag = function (handler, block, tagInfo, tagPoint, tagAnchor, tagRelative)
Nenue@28 87 local print = bprint
Nenue@30 88
Nenue@30 89 for order, tagName in ipairs(block.info.tagInfo) do
Nenue@30 90 local tag = block[tagName]
Nenue@30 91 if block.tagCoords[tagName] and tag then
Nenue@30 92 tag:SetTexCoord(unpack(block.tagCoords[tagName]))
Nenue@30 93 tag:Show()
Nenue@30 94 tag:SetPoint(tagPoint, tagAnchor, tagRelative, 0, 0)
Nenue@30 95 tagPoint, tagAnchor, tagRelative = 'TOPRIGHT', tag, 'TOPLEFT'
Nenue@30 96 else
Nenue@30 97 block[tagName]:Hide()
Nenue@30 98 end
Nenue@28 99 end
Nenue@30 100
Nenue@28 101 return tagPoint, tagAnchor, tagRelative
Nenue@28 102 end
Nenue@28 103
Nenue@28 104 --- Adds the given line to the current content and advances the anchor pointer to that new line for the following call.
Nenue@30 105 Default.AddLine = function(handler, block, text, attachment, template)
Nenue@28 106 local print = lprint
Nenue@30 107 local lineIndex = block.currentLine + 1
Nenue@30 108 local line = handler:GetLine(block)
Nenue@28 109 line:ClearAllPoints()
Nenue@28 110 line:SetPoint('LEFT', block, 'LEFT', 0, 0)
Nenue@28 111 line:SetPoint('TOP', block.endPoint, 'BOTTOM', 0, -textSpacing)
Nenue@28 112 line:SetPoint('RIGHT', block, 'RIGHT', 0, 0)
Nenue@28 113 line:Show()
Nenue@28 114
Nenue@30 115 local r, g, b, a = 1, 1, 1, 1
Nenue@30 116 if lineColors[template] then
Nenue@30 117 r, g, b = unpack(lineColors[template])
Nenue@30 118 end
Nenue@30 119
Nenue@30 120 line.status:SetText(text)
Nenue@30 121 line.height = floor(line.status:GetStringHeight()+.5) + textSpacing
Nenue@30 122 line:SetHeight(line.height)
Nenue@30 123 line.status:SetTextColor(r, g, b, a)
Nenue@30 124
Nenue@30 125 -- For progressbar and timer lines, status text may be used as the title heading
Nenue@30 126 if attachment then
Nenue@30 127 local widgetPosition = 0
Nenue@30 128 attachment:SetPoint('TOP', line, 'TOP', 0, -block.attachmentHeight)
Nenue@30 129 attachment:Show()
Nenue@30 130 if text and #text >= 1 then
Nenue@30 131 widgetPosition = line.status:GetHeight() + textSpacing
Nenue@30 132 line.status:SetText(text)
Nenue@30 133 line.height = floor(line.status:GetStringHeight()+.5) + textSpacing + attachment.height
Nenue@30 134 print(' - progressbar has text, adjust')
Nenue@30 135 end
Nenue@30 136 else
Nenue@30 137 print(' |cFFFF0088no attachments')
Nenue@30 138 end
Nenue@30 139
Nenue@28 140 block.endIndex = line.index
Nenue@28 141 block.attachmentHeight = block.attachmentHeight + (line.height + textSpacing)
Nenue@30 142 print(' |cFF0088FFsetting line #'..lineIndex..' for|r', block.info.title, "\n |cFF0088FFsize:|r", line.height,
Nenue@28 143 "|cFF0088FFpoint:|r", line:GetPoint(1), "|cFF0088FFwidget:|r", (line.widget and 'Y' or 'N'))
Nenue@30 144 block.currentLine = lineIndex
Nenue@28 145 block.endPoint = line
Nenue@28 146 end
Nenue@28 147
Nenue@28 148 --- Creates or retrieves a complete line data object
Nenue@30 149 Default.GetLine = function(handler, block, lineIndex)
Nenue@28 150 local print = lprint
Nenue@28 151 local blockIndex = block.index
Nenue@30 152 local lines = block.lines
Nenue@30 153 if not lineIndex then
Nenue@30 154 lineIndex = block.currentLine + 1
Nenue@30 155 print('fetching the "next" line:', lineIndex)
Nenue@30 156 else
Nenue@30 157 print('fetching explicit offset:', lineIndex)
Nenue@28 158 end
Nenue@30 159
Nenue@30 160 block.numLines = max(block.numLines, lineIndex)
Nenue@30 161 print('|cFF00FFFFnumLines:|r', block.numLines, '|cFF00FFFFcurrentLine:|r', block.currentLine)
Nenue@30 162
Nenue@28 163 if not lines[lineIndex] then
Nenue@28 164 print(' |cFF00FF88created line #'..lineIndex..' from for '..handler.name..' block #'..blockIndex)
Nenue@28 165 lines[lineIndex] = CreateFrame('Frame', 'Vn'..handler.name .. blockIndex..'ObjectiveLine'..lineIndex, block, 'VeneerTrackerObjective')
Nenue@28 166 local line = lines[lineIndex]
Nenue@28 167 line.index = lineIndex
Nenue@28 168 line.height = 0
Nenue@28 169 line.status:SetSpacing(textSpacing)
Nenue@28 170 line.status:SetPoint('LEFT', line, 'LEFT', textIndent, 0)
Nenue@28 171 B.SetConfigLayers(line)
Nenue@28 172
Nenue@28 173 if lines[lineIndex+1] then
Nenue@28 174 lines[lineIndex+1]:ClearAllPoints()
Nenue@28 175 end
Nenue@28 176
Nenue@28 177 if debug then
Nenue@28 178 for _, region in ipairs(lines[lineIndex].debug) do
Nenue@28 179 region:Show()
Nenue@28 180 end
Nenue@28 181 end
Nenue@28 182
Nenue@28 183 end
Nenue@28 184 return lines[lineIndex]
Nenue@28 185 end
Nenue@28 186
Nenue@29 187
Nenue@29 188
Nenue@28 189 --- Creates or retrieves a complete block frame object
Nenue@30 190 Default.GetBlock = function(handler, blockIndex)
Nenue@28 191 local print = bprint
Nenue@28 192 local block = handler.usedBlocks[blockIndex]
Nenue@28 193
Nenue@28 194 if not handler.usedBlocks[blockIndex] then
Nenue@28 195 if #handler.freeBlocks >= 1 then
Nenue@28 196 block = handler.freeBlocks[#handler.freeBlocks]
Nenue@28 197 handler.freeBlocks[#handler.freeBlocks] = nil
Nenue@28 198 else
Nenue@30 199 block = CreateFrame('Frame', 'Veneer'..tostring(handler)..'Block'..blockIndex, handler.frame, 'VeneerTrackerBlock')
Nenue@28 200
Nenue@30 201 local c = Module.Conf.Wrapper
Nenue@28 202 block.index = blockIndex
Nenue@30 203 block.lines = {}
Nenue@30 204 block.numLines = 0
Nenue@30 205 block.currentLine = 0
Nenue@28 206 block:SetWidth(c.Width)
Nenue@28 207
Nenue@28 208 block.title:SetSpacing(c.TitleSpacing)
Nenue@28 209 block.title:SetPoint('TOP', block, 'TOP', 0, -titleSpacing)
Nenue@28 210
Nenue@28 211 block.titlebg:SetTexture(1,1,1,1)
Nenue@30 212 block.titlebg:SetGradientAlpha(unpack(Module.colors.default.titlebg))
Nenue@28 213 block.titlebg:SetPoint('TOP', block, 'TOP', 0, 0)
Nenue@28 214 block.titlebg:SetPoint('BOTTOM', block.title, 'BOTTOM', 0, -titleSpacing)
Nenue@28 215
Nenue@28 216 block.status:SetSpacing(c.TextSpacing)
Nenue@28 217 block.status:SetPoint('TOP', block.titlebg, 'BOTTOM', 0, -textSpacing)
Nenue@28 218 block.status:SetPoint('LEFT', block.titlebg, 'LEFT', textIndent, 0)
Nenue@28 219
Nenue@28 220 block.statusbg:SetPoint('TOP', block.titlebg, 'BOTTOM', 0, 0)
Nenue@28 221 block.statusbg:SetPoint('BOTTOM', block, 'BOTTOM', 0, 0)
Nenue@28 222 block.statusbg:SetTexture(1,1,1,1)
Nenue@30 223 block.statusbg:SetGradientAlpha(unpack(Module.colors.default.textbg))
Nenue@28 224
Nenue@30 225 block.SelectionOverlay:SetGradientAlpha(unpack(Module.colors.default.selectionbg))
Nenue@28 226 block.SelectionOverlay:SetPoint('TOPLEFT', selectionIndent, 0)
Nenue@28 227 block.SelectionOverlay:SetPoint('BOTTOMRIGHT')
Nenue@28 228
Nenue@28 229 block.icon:SetSize(rewardSize, rewardSize)
Nenue@28 230 block.icon:SetPoint('TOPRIGHT', block, 'TOPRIGHT', -2, -2)
Nenue@28 231
Nenue@28 232
Nenue@28 233 --- methods for event handlers
Nenue@28 234
Nenue@28 235 block.Select = handler.Select
Nenue@28 236 block.Open = handler.Open
Nenue@28 237 block.Remove = handler.Remove
Nenue@28 238 block.Link = handler.Link
Nenue@28 239 block.clickZone:SetScript('OnMouseUp', function(self, ...) handler.OnMouseUp(block, ...) end)
Nenue@28 240 block.clickZone:SetScript('OnMouseDown', function(self, ...) handler.OnMouseDown(block, ...) end)
Nenue@28 241 block.attachmentHeight = 0
Nenue@28 242 block:ClearAllPoints()
Nenue@28 243
Nenue@28 244 B.SetConfigLayers(block)
Nenue@28 245
Nenue@28 246 if debug then
Nenue@28 247 for _, region in ipairs(block.debug) do
Nenue@28 248 region:Show()
Nenue@28 249 end
Nenue@28 250 end
Nenue@28 251 end
Nenue@28 252 handler.usedBlocks[blockIndex] = block
Nenue@28 253 end
Nenue@28 254 return handler.usedBlocks[blockIndex]
Nenue@28 255 end
Nenue@28 256
Nenue@30 257 local currentPosition, anchorFrame, anchorPoint
Nenue@30 258 --- Positioning and stuff
Nenue@30 259 local tick = 0
Nenue@30 260 local maxReason = 0
Nenue@30 261 function Module:Update (reason, ...)
Nenue@30 262 tick = tick + 1
Nenue@30 263 -- is this the first time updating?
Nenue@30 264 if maxReason == 0 then
Nenue@30 265 reason = OBJECTIVE_TRACKER_UPDATE_ALL
Nenue@30 266 elseif not reason then
Nenue@30 267 reason = OBJECTIVE_TRACKER_UPDATE_REASON
Nenue@30 268 end
Nenue@30 269
Nenue@30 270 local print = tprint
Nenue@30 271 local updateWrapper = 0
Nenue@30 272 local hasStuff
Nenue@30 273 local insertingStuff
Nenue@30 274
Nenue@30 275 print(format('%d |cFFFF%04X Update()', tick, lshift(reason, 4)), reason, ...)
Nenue@30 276 currentPosition = 0
Nenue@30 277 anchorPoint = 'TOP'
Nenue@30 278 anchorFrame = Scroll
Nenue@30 279
Nenue@30 280 local wrapperHeight = 0
Nenue@30 281 for id, handler in pairs(Module.orderedHandlers) do
Nenue@30 282 local frame = handler.frame
Nenue@30 283
Nenue@30 284 print(format('|cFF00FFFF%s and(%04X vs %04x+%04x) = %04X|r', handler.name, reason, handler.updateReasonModule, handler.updateReasonEvents, band(reason, handler.updateReasonModule + handler.updateReasonEvents)))
Nenue@30 285 if band(reason, handler.updateReasonModule + handler.updateReasonEvents) > 0 then
Nenue@30 286 handler:UpdateTracker(reason, ...)
Nenue@30 287 print(' |cFF00FF00'..id..'|r', handler.displayName, 'count:', handler.numWatched)
Nenue@30 288 insertingStuff = true
Nenue@30 289 else
Nenue@30 290 print(' |cFFFF0088'..id..'|r', 'no reason to update')
Nenue@30 291 end
Nenue@30 292
Nenue@30 293 if handler.numWatched >= 1 then
Nenue@30 294 hasStuff = true
Nenue@30 295 currentPosition = currentPosition + 1
Nenue@30 296 frame.destinationOffset = -wrapperHeight
Nenue@30 297 if frame.previousOffset ~= wrapperHeight and frame:IsVisible() then
Nenue@30 298 print(frame.SlideIn.translation)
Nenue@30 299 local postFrame, postPoint = anchorFrame, anchorPoint
Nenue@30 300 local delta = frame.destinationOffset - frame.previousOffset
Nenue@30 301 local _, _, _, _, offset = frame:GetPoint(1)
Nenue@30 302 print(' |cFF00BBFFstart slide for', delta, 'pixels, from', frame.previousOffset, '(', offset, ')')
Nenue@30 303 frame.SlideIn.translation:SetTarget(frame)
Nenue@30 304 frame.SlideIn.translation:SetOffset(0, delta)
Nenue@30 305 frame.SlideIn:Play()
Nenue@30 306 for i, b in ipairs(handler.usedBlocks) do
Nenue@30 307 b.SlideIn.translation:SetOffset(0, delta)
Nenue@30 308 b.SlideIn:Play()
Nenue@30 309 end
Nenue@30 310 frame.SlideIn:SetScript('OnFinished', function()
Nenue@30 311 print(' |cFF00BBFFsliding finished:', delta, 'pixels covered')
Nenue@30 312 frame:SetParent(Scroll)
Nenue@30 313 frame:SetPoint('TOP', Scroll, 'TOP', 0, frame.destinationOffset)
Nenue@30 314 frame.previousOffset = frame.destinationOffset
Nenue@30 315 frame.SlideIn:SetScript('OnFinished', nil)
Nenue@30 316 if Wrapper.destinationHeight then
Nenue@30 317 Wrapper:SetHeight(Wrapper.destinationHeight)
Nenue@30 318 Scroller:SetHeight(Wrapper.destinationHeight)
Nenue@30 319 Scroll:SetHeight(Wrapper.destinationHeight)
Nenue@30 320 Wrapper.previousHeight = Wrapper.destinationHeight
Nenue@30 321 Wrapper.destinationHeight = nil
Nenue@30 322 end
Nenue@30 323
Nenue@30 324 end)
Nenue@30 325 else
Nenue@30 326 print(' |cFF00BBFFpinning to', anchorFrame:GetName(), anchorPoint)
Nenue@30 327 frame:SetParent(Scroll)
Nenue@30 328 frame:SetPoint('TOP', Scroll, 'TOP', 0, frame.destinationOffset)
Nenue@30 329 end
Nenue@30 330
Nenue@30 331 frame:Show()
Nenue@30 332 anchorFrame = handler.frame
Nenue@30 333 anchorPoint = 'BOTTOM'
Nenue@30 334
Nenue@30 335 print('current frame height:', frame.height)
Nenue@30 336 wrapperHeight = wrapperHeight + frame.height
Nenue@30 337 print('|cFFFF0088total height:', wrapperHeight)
Nenue@30 338 else
Nenue@30 339 frame:SetPoint('TOP', Scroll, 'TOP', 0, 0)
Nenue@30 340 frame.destinationOffset = 0
Nenue@30 341 frame.previousOffset = 0
Nenue@30 342 handler.frame:Hide()
Nenue@30 343 end
Nenue@30 344 end
Nenue@30 345
Nenue@30 346
Nenue@30 347 if hasStuff or insertingStuff then
Nenue@30 348 print('updating height to', wrapperHeight)
Nenue@30 349 if wrapperHeight > Wrapper.previousHeight then
Nenue@30 350 Wrapper:SetHeight(wrapperHeight)
Nenue@30 351 Scroller:SetHeight(wrapperHeight)
Nenue@30 352 Scroll:SetHeight(wrapperHeight)
Nenue@30 353 Wrapper.previousHeight = wrapperHeight
Nenue@30 354 Wrapper.destinationHeight = wrapperHeight
Nenue@30 355 end
Nenue@30 356 Scroller:SetVerticalScroll(B.Conf.ObjectiveScroll or 0)
Nenue@30 357 print('|cFFFF8800Wrapper:', Wrapper:GetSize())
Nenue@30 358 for i = 1, Wrapper:GetNumPoints() do
Nenue@30 359 print(' ', Wrapper:GetPoint(i))
Nenue@30 360 end
Nenue@30 361 print(' |cFF00FFFFScroller:', Scroller:GetSize())
Nenue@30 362 for i = 1, Scroller:GetNumPoints() do
Nenue@30 363 print(' ', Scroller:GetPoint(i))
Nenue@30 364 end
Nenue@30 365 print(' |cFF00FFFFScroll:', Scroll:GetSize())
Nenue@30 366 for i = 1, Scroll:GetNumPoints() do
Nenue@30 367 print(' ', Scroll:GetPoint(i))
Nenue@30 368 end
Nenue@30 369
Nenue@30 370 Wrapper:Show()
Nenue@30 371 Scroller:Show()
Nenue@30 372 Scroll:Show()
Nenue@30 373 end
Nenue@30 374 Quest.GetClosest()
Nenue@30 375 --Module.UpdateActionButtons(reason)
Nenue@30 376 end
Nenue@30 377
Nenue@28 378 --- Content generator base
Nenue@30 379 Default.UpdateTracker = function (handler, reason, id, isNew)
Nenue@28 380 local print = tprint
Nenue@30 381 local tracker = handler.frame
Nenue@28 382 local blockIndex = 0
Nenue@28 383 tracker.previousHeight = tracker.height
Nenue@28 384 tracker.height = 0
Nenue@28 385
Nenue@28 386 tracker.title:SetFont(headerFont, headerSize, headerOutline)
Nenue@28 387 tracker.titlebg:SetHeight(headerHeight)
Nenue@28 388 tracker.title:SetTextColor(unpack(headerColor))
Nenue@28 389
Nenue@30 390 handler.updateReason = reason
Nenue@30 391 handler.numWatched = handler:GetNumWatched()
Nenue@30 392 handler.currentBlock = 0
Nenue@30 393 handler.currentAnchor = tracker.titlebg
Nenue@30 394 local blockPosition = -headerHeight
Nenue@30 395 for blockIndex = 1, handler.numWatched do
Nenue@30 396 local currentBlock = handler:UpdateBlock(blockIndex, id, isNew)
Nenue@30 397 if currentBlock then
Nenue@30 398 currentBlock.offset = blockPosition
Nenue@30 399 handler:AddBlock(currentBlock)
Nenue@30 400 blockPosition = blockPosition - currentBlock.height
Nenue@28 401 else
Nenue@28 402 print(' |cFFFF9900END|r @', blockIndex)
Nenue@28 403 break -- done with quest stuff
Nenue@28 404 end
Nenue@28 405 end
Nenue@28 406
Nenue@30 407 for i = handler.currentBlock+1, handler.numBlocks do
Nenue@30 408 local used = handler.usedBlocks
Nenue@30 409 local free = handler.freeBlocks
Nenue@30 410 print('clean up dead quest block')
Nenue@30 411 if used[i] then
Nenue@30 412 used[i]:Hide()
Nenue@30 413 used[i]:ClearAllPoints()
Nenue@30 414 free[#free+1]= used[blockIndex]
Nenue@30 415 used[i] = nil
Nenue@30 416 end
Nenue@30 417 end
Nenue@28 418
Nenue@30 419
Nenue@30 420 if handler.currentBlock >= 1 then
Nenue@28 421 tracker.height = tracker.height + headerHeight
Nenue@28 422 tracker:Show()
Nenue@28 423
Nenue@28 424 if tracker.wasEmpty then
Nenue@28 425 tracker.headerFade:Play()
Nenue@28 426 tracker.wasEmpty = nil
Nenue@28 427 end
Nenue@28 428 if tracker.height ~= tracker.previousHeight then
Nenue@28 429 tracker:SetHeight(tracker.height)
Nenue@28 430 end
Nenue@29 431 print(' |cFFFFFF00', tracker.height, tracker:GetWidth())
Nenue@28 432 else
Nenue@28 433 tracker:Hide()
Nenue@28 434 tracker.wasEmpty = true
Nenue@28 435 end
Nenue@28 436
Nenue@28 437 return tracker.numWatched, tracker.numAll
Nenue@28 438 end
Nenue@28 439
Nenue@28 440 --- Updates the selected block frame to display the given info batch
Nenue@28 441 -- If `previousBlock` is set, it will attempt to anchor to that
Nenue@28 442 -- @param blockNum the ordered block to be updated, not a watchIndex value
Nenue@28 443 -- @param info the reference returned by the GetXInfo functions
Nenue@28 444 -- REMEMBER: t.info and questData[questID] are the same table
Nenue@30 445 Default.UpdateBlock = function (handler, blockIndex, id, added)
Nenue@28 446 local print = bprint
Nenue@30 447 print(' Updating |cFF00FF00'..handler.displayName..'|r|cFF00FFFF'..blockIndex..'|r')
Nenue@30 448 if not blockIndex then
Nenue@30 449 return
Nenue@30 450 end
Nenue@30 451 local info = handler:GetInfo(blockIndex) -- should match up with whatever the internal watch list has
Nenue@30 452 if not info then
Nenue@28 453 return
Nenue@28 454 end
Nenue@28 455 local frame = handler.frame
Nenue@30 456 local block = handler:GetBlock(blockIndex)
Nenue@30 457
Nenue@30 458 block.questID = info.questID
Nenue@30 459 if id == info.questID then
Nenue@30 460 --block.questFadeIn:Play()
Nenue@30 461 end
Nenue@30 462
Nenue@28 463 block.handler = handler
Nenue@28 464 block.info = info
Nenue@28 465 block.mainStyle = info.mainStyle or 'Normal'
Nenue@28 466 block.subStyle = info.subStyle
Nenue@28 467
Nenue@28 468 info.blockIndex = blockIndex
Nenue@28 469 if info.questID then handler.QuestBlock[info.questID] = block end
Nenue@28 470 if info.questLogIndex then handler.LogBlock[info.questLogIndex] = block end
Nenue@28 471 if info.watchIndex then handler.WatchBlock[info.watchIndex] = block end
Nenue@28 472 handler.BlockInfo[blockIndex] = info
Nenue@28 473 handler:UpdateObjectives(block)
Nenue@28 474
Nenue@28 475 block.title:SetText(info.title)
Nenue@28 476 local titleHeight = floor(block.title:GetHeight()+.5)
Nenue@28 477 local titlebgHeight = titleHeight + titleSpacing*2
Nenue@28 478 block.titlebg:SetHeight(titlebgHeight)
Nenue@28 479
Nenue@30 480 local statusHeight = floor(block.status:GetHeight()+.5)
Nenue@30 481 local statusbgHeight = statusHeight + textSpacing*2
Nenue@30 482 local attachmentHeight =floor(block.attachmentHeight + .5)
Nenue@28 483
Nenue@28 484 print(' |cFF0088FFanchor to', handler.currentAnchor:GetName())
Nenue@30 485 print(' |cFF00FF00attachment:|r', attachmentHeight, '|cFF00FF00title:|r', titlebgHeight, '('.. titleHeight..')')
Nenue@30 486 --block.titlebg:SetHeight(block.title:GetHeight() + Module.Conf.Wrapper.TitleSpacing)
Nenue@30 487 block.height = titlebgHeight + attachmentHeight
Nenue@28 488
Nenue@28 489 if statusHeight > 1 then
Nenue@28 490 block.height = block.height + statusbgHeight
Nenue@28 491 print(' status:', statusbgHeight, '('.. statusHeight..')')
Nenue@28 492 else
Nenue@28 493 print(' |cFFFF0088 skipped')
Nenue@28 494 end
Nenue@28 495 block:SetHeight(block.height)
Nenue@28 496
Nenue@28 497 print(' |cFFFFFF00height|r:', block.height)
Nenue@28 498 print(' |cFF00FFFF)|r -> ', block, block:GetHeight())
Nenue@28 499
Nenue@28 500 block:Show()
Nenue@28 501
Nenue@28 502 if info.specialItem and not info.itemButton then
Nenue@28 503 print(' - |cFF00FFFFgenerating item button for info set')
Nenue@30 504 info.itemButton = Module.SetItemButton(block, info)
Nenue@28 505 else
Nenue@28 506 --info.itemButton = nil
Nenue@28 507 end
Nenue@28 508
Nenue@28 509 local tagPoint, tagAnchor, tagRelative = 'TOPRIGHT', block, 'TOPRIGHT'
Nenue@28 510
Nenue@28 511 if info.rewardInfo then
Nenue@28 512 print('has immediate reward')
Nenue@28 513 if info.rewardInfo[1].type == 'currency' or info.rewardInfo[1].type == 'item' then
Nenue@28 514 block.icon:Show()
Nenue@28 515 block.iconLabel:SetText(info.rewardInfo[1].count)
Nenue@28 516 block.icon:SetPoint(tagPoint, tagAnchor, tagRelative, -2, -2)
Nenue@28 517 tagPoint, tagAnchor, tagRelative = 'TOPRIGHT', block.icon, 'TOPLEFT'
Nenue@28 518 block.icon:SetTexture(info.rewardInfo[1].texture)
Nenue@28 519 end
Nenue@28 520 else
Nenue@28 521 block.icon:Hide()
Nenue@28 522 end
Nenue@28 523
Nenue@28 524 if info.selected then
Nenue@28 525 block.SelectionOverlay:Show()
Nenue@28 526 else
Nenue@28 527 block.SelectionOverlay:Hide()
Nenue@28 528 end
Nenue@28 529 -- workaround for scrollchild issue where layers fall out of sync: in this case, it's by 1 vertical pixel
Nenue@28 530 --block.highlight:SetPoint('TOPLEFT', block, 'TOPLEFT', 0, 1)
Nenue@28 531 --block.lowlight:SetPoint('BOTTOMLEFT', block, 'BOTTOMLEFT', 0, 1)
Nenue@28 532
Nenue@30 533 tagPoint, tagAnchor, tagRelative = handler:AddTag(block, 'frequencyTag', tagPoint, tagAnchor, tagRelative)
Nenue@30 534 tagPoint, tagAnchor, tagRelative = handler:AddTag(block, 'typeTag', tagPoint, tagAnchor, tagRelative)
Nenue@30 535 tagPoint, tagAnchor, tagRelative = handler:AddTag(block, 'completionTag', tagPoint, tagAnchor, tagRelative)
Nenue@28 536
Nenue@28 537 return block
Nenue@28 538 end
Nenue@28 539
Nenue@28 540
Nenue@28 541
Nenue@28 542
Nenue@28 543 --- Does the main iterations for populating block content.
Nenue@28 544 -- Hooked by corresponding handler functions where additional details need to be sorted.
Nenue@28 545 Default.UpdateObjectives = function(handler, block)
Nenue@28 546 local print = lprint
Nenue@28 547 local info = block.info
Nenue@28 548 print(' |cFF00FF00default objectives routine', block:GetName())
Nenue@30 549 block.endPoint = block.titlebg
Nenue@30 550 block.attachmentHeight = 0
Nenue@30 551 block.currentLine = 0
Nenue@28 552
Nenue@28 553 -- reset the starting positions
Nenue@28 554 block.attachmentHeight = 0
Nenue@28 555 block.endPoint = block.titlebg
Nenue@28 556 local completionScore, completionMax = 0, 0
Nenue@28 557 local displayObjectiveHeader = false
Nenue@28 558
Nenue@28 559
Nenue@28 560 --- The first line is going to be used no matter what, so it is hard-pulled.
Nenue@28 561 -- It also ensures that we're in the right position for cleaning up the leftover lines.
Nenue@28 562
Nenue@28 563 block.attachmentHeight = 0
Nenue@28 564
Nenue@30 565 local text, attachment
Nenue@28 566 if info.description and #info.description >= 1 then
Nenue@28 567 print(' |cFF00FFFF header line:|r', info.description)
Nenue@30 568 text = info.description
Nenue@30 569 handler:AddLine(block, text, nil)
Nenue@28 570 end
Nenue@28 571
Nenue@28 572 if (info.isComplete or info.numObjectives == 0) and info.completionText then
Nenue@28 573 print(' overriding line #1 for completion text:', info.completionText)
Nenue@30 574 text = info.completionText
Nenue@30 575 Module.AddLine(block, text, nil)
Nenue@28 576 else
Nenue@28 577 if info.objectives then
Nenue@28 578 for i, data in ipairs(info.objectives) do
Nenue@30 579 local line = handler:GetLine(block)
Nenue@28 580 displayObjectiveHeader = true
Nenue@28 581 line.height = 0
Nenue@30 582 text, attachment = handler:UpdateLine(block, line, data)
Nenue@30 583 print(' |cFF88FF00#', i, data.type, text)
Nenue@30 584 handler:AddLine(block, text, attachment)
Nenue@28 585
Nenue@28 586 end
Nenue@28 587 end
Nenue@28 588 end
Nenue@28 589
Nenue@30 590 for i = block.currentLine + 1, block.numLines do
Nenue@30 591 print(i, block.numLines)
Nenue@30 592 print(' - hide |cFFFF0088'..i..'|r', block.lines[i])
Nenue@30 593 block.lines[i]:ClearAllPoints()
Nenue@30 594 block.lines[i]:Hide()
Nenue@28 595 end
Nenue@28 596
Nenue@30 597 if block.currentLine > 0 then
Nenue@28 598 block.attachmentHeight = block.attachmentHeight + textSpacing * 2
Nenue@28 599 print(' |cFF00FF00attachment:', block.attachmentHeight)
Nenue@28 600 end
Nenue@28 601
Nenue@28 602
Nenue@28 603 if debug then
Nenue@28 604 for i, region in ipairs(block.debug) do
Nenue@28 605 for j = 1, region:GetNumPoints() do
Nenue@28 606 local _, target = region:GetPoint(j)
Nenue@28 607 if target:IsVisible() then
Nenue@28 608 region:Hide()
Nenue@28 609 else
Nenue@28 610 region:Show()
Nenue@28 611 end
Nenue@28 612 end
Nenue@28 613 end
Nenue@28 614 end
Nenue@28 615
Nenue@28 616 block.completionScore = completionScore / completionMax
Nenue@28 617 end
Nenue@28 618
Nenue@28 619
Nenue@28 620 --- Module-specific display variables
Nenue@28 621 -- * height - height of whatever display widget is involved in conveying the task
Nenue@28 622 -- * money - boolean that determines listening for money events or not
Nenue@28 623 -- * progress - number ranging 0 to 2 indicating none/partial/full completion respectively
Nenue@28 624
Nenue@28 625
Nenue@28 626 Default.UpdateLine = function(block, line)
Nenue@28 627 if line.finished then
Nenue@28 628 line.progress = 2
Nenue@28 629 elseif line.quantity > 0 then
Nenue@28 630 line.progress = 1
Nenue@28 631 else
Nenue@28 632 line.progress = 0
Nenue@28 633 end
Nenue@30 634 return line.displayText, line.widget
Nenue@28 635 end
Nenue@28 636 ----------
Nenue@28 637 --- Top level methods
Nenue@28 638
Nenue@28 639 --- Queue any active item buttons for update for that frame
Nenue@28 640 local iprint = B.print('ItemButton')
Nenue@30 641 Module.UpdateActionButtons = function(updateReason)
Nenue@28 642 local print = iprint
Nenue@28 643 Scroller.snap_upper = 0
Nenue@28 644 Scroller.snap_lower = 0
Nenue@28 645 local print = B.print('ItemButton')
Nenue@28 646 if updateReason then
Nenue@28 647 print = B.print('IB_'..updateReason)
Nenue@28 648 end
Nenue@28 649
Nenue@28 650 local previousItem
Nenue@28 651 for questID, itemButton in pairs(Quest.itemButtons) do
Nenue@30 652 local info= Module.Quest.Info[questID]
Nenue@28 653
Nenue@28 654 print('|cFF00FFFF'.. questID .. '|r', itemButton:GetName())
Nenue@30 655 local block = Module.Quest.QuestBlock[questID]
Nenue@28 656 if block then
Nenue@28 657 -- Dispatch the probe
Nenue@28 658 if IsQuestWatched(info.questLogIndex) then
Nenue@28 659 itemButton.previousItem = previousItem
Nenue@28 660 print(' |cFFFFFF00probing', block:GetName())
Nenue@28 661 block:SetScript('OnUpdate', function()
Nenue@28 662 if block:GetBottom() and not InCombatLockdown() then
Nenue@28 663 print(' '..block:GetName()..' |cFF00FF00probe hit!')
Nenue@30 664 Module.UpdateBlockAction(block, itemButton, itemButton.previousItem) -- needs to be previousItem from this scope
Nenue@28 665 block:SetScript('OnUpdate', nil)
Nenue@28 666
Nenue@28 667 end
Nenue@28 668 end)
Nenue@28 669 previousItem = itemButton
Nenue@28 670 else
Nenue@28 671 print('hidden block or unwatched quest')
Nenue@28 672 itemButton.previousItem = nil
Nenue@28 673 itemButton:Hide()
Nenue@28 674 end
Nenue@28 675 elseif itemButton:IsVisible() then
Nenue@28 676 print(' |cFFFF0088hiding unwatched quest button', itemButton:GetName())
Nenue@28 677 itemButton.previousItem = nil
Nenue@28 678 itemButton:Hide()
Nenue@28 679 else
Nenue@28 680 print(' |cFFBBBBBBignoring hidden log quest button', itemButton:GetName())
Nenue@28 681 end
Nenue@28 682 end
Nenue@28 683 end
Nenue@28 684
Nenue@30 685 Module.UpdateBlockAction = function (block, itemButton)
Nenue@28 686 local print = iprint
Nenue@28 687 print('**|cFF0088FF'..itemButton:GetName(), '|r:Update()')
Nenue@28 688 if itemButton.questID ~= block.info.questID then
Nenue@28 689 print('** |cFFFF0088mismatched block assignment', itemButton.questID,'<~>', block.info.questID)
Nenue@28 690 -- something happened between this and last frame, go back and set new probes
Nenue@30 691 return Module.UpdateActionButtons()
Nenue@28 692 end
Nenue@28 693
Nenue@28 694 local previousItem = itemButton.previousItem
Nenue@28 695 local upper_bound = Scroller:GetTop() + Scroller.snap_upper
Nenue@28 696 local lower_bound = Scroller:GetBottom() + Scroller.snap_lower + itemButtonSize
Nenue@28 697 local point, anchor, relative
Nenue@28 698
Nenue@28 699 if block:GetBottom() < lower_bound then
Nenue@28 700 print('** ',block:GetName() ,'|cFFFFFF00bottom =', floor(block:GetBottom()+.5), 'threschold =', floor(lower_bound+.5))
Nenue@28 701 if previousItem then
Nenue@28 702 print('adjusting', previousItem:GetName())
Nenue@28 703 previousItem:ClearAllPoints()
Nenue@28 704 previousItem:SetPoint('BOTTOM', itemButton, 'TOP', 0, itemButtonSpacing)
Nenue@28 705 end
Nenue@28 706 itemButton:ClearAllPoints()
Nenue@28 707 itemButton.x = Wrapper:GetLeft() -4
Nenue@28 708 itemButton.y = Wrapper:GetBottom()
Nenue@28 709 point, anchor, relative = 'BOTTOMRIGHT', UIParent, 'BOTTOMLEFT'
Nenue@28 710 Scroller.snap_lower = Scroller.snap_lower + itemButtonSize + itemButtonSpacing
Nenue@28 711
Nenue@28 712 elseif block:GetTop() > upper_bound then
Nenue@28 713 print('** ',block:GetName() ,'|cFFFFFF00top =', floor(block:GetTop()+.5), 'threschold =', floor(upper_bound+.5))
Nenue@28 714 itemButton:ClearAllPoints()
Nenue@28 715 if previousItem then
Nenue@28 716 print('latch onto another piece')
Nenue@28 717 point, anchor, relative ='TOP', previousItem, 'BOTTOM'
Nenue@28 718 itemButton.x = 0
Nenue@28 719 itemButton.y = -itemButtonSpacing
Nenue@28 720 else
Nenue@28 721 print('latch at corner', Scroller:GetLeft() -itemButtonSpacing, Scroller:GetTop())
Nenue@28 722 point, anchor, relative = 'TOPRIGHT', UIParent, 'BOTTOMLEFT'
Nenue@28 723 itemButton.x = Scroller:GetLeft() -4
Nenue@28 724 itemButton.y = Scroller:GetTop()
Nenue@28 725 end
Nenue@28 726 itemButton:Show()
Nenue@28 727 Scroller.snap_upper = Scroller.snap_upper - (itemButtonSize + itemButtonSpacing)
Nenue@28 728 else
Nenue@28 729 print('** ',block:GetName() ,'|cFF00FF00span =', floor(block:GetBottom()+.5), floor(block:GetTop()+.5), 'threschold =', floor(lower_bound+.5))
Nenue@28 730 itemButton:ClearAllPoints()
Nenue@28 731 itemButton.x = block:GetLeft() - itemButtonSpacing
Nenue@28 732 itemButton.y = block:GetTop()
Nenue@28 733 point, anchor, relative = 'TOPRIGHT', UIParent, 'BOTTOMLEFT'
Nenue@28 734 end
Nenue@28 735
Nenue@28 736 itemButton:SetPoint(point, anchor, relative, itemButton.x, itemButton.y)
Nenue@28 737 itemButton:Show()
Nenue@28 738 end
Nenue@28 739
Nenue@30 740 Module.UpdateItemButtonCooldown = function(button)
Nenue@28 741
Nenue@28 742 end
Nenue@28 743
Nenue@29 744 Default.Select = function(handler, block)
Nenue@30 745 Module:Update(handler.watchReasonModule)
Nenue@28 746 end
Nenue@29 747 Default.Open = function(handler, block)
Nenue@30 748 Module:Update(handler.watchReasonModule)
Nenue@28 749 end
Nenue@29 750 Default.Remove = function(handler, block)
Nenue@30 751 Module:Update(handler.watchReasonModule)
Nenue@28 752 end
Nenue@29 753 Default.Report = function(handler, block)
Nenue@29 754 print('Stats:', handler.numWatched,'items tracked,', handler.numBlocks,'blocks assigned.')
Nenue@28 755 end
Nenue@28 756
Nenue@28 757 Default.OnMouseUp = function(self, button)
Nenue@28 758 print(self.handler.name, self.mainStyle, self.subStyle)
Nenue@28 759 if button == 'LeftButton' then
Nenue@28 760 if IsModifiedClick("CHATLINK") and ChatEdit_GetActiveWindow() then
Nenue@29 761 self.Link(self.handler, self)
Nenue@28 762 elseif IsModifiedClick("QUESTWATCHTOGGLE") then
Nenue@29 763 self.Remove(self.handler, self)
Nenue@28 764 else
Nenue@29 765 self.Select(self.handler, self)
Nenue@28 766 end
Nenue@28 767 elseif button == 'RightButton' then
Nenue@29 768 self.Open(self.handler, self)
Nenue@28 769 end
Nenue@28 770 self.initialButton = nil
Nenue@28 771 self.modChatLink = nil
Nenue@28 772 self.modQuestWatch = nil
Nenue@30 773 Module:Update(self.handler.updateReasonModule)
Nenue@28 774 print('|cFFFF8800'..tostring(self:GetName())..':MouseUp()|r')
Nenue@28 775 end
Nenue@28 776 Default.OnMouseDown = function(self, button)
Nenue@28 777 print(self.info.title)
Nenue@28 778 end