annotate ObjectiveTracker/DefaultTracker.lua @ 36:a487841050be

- attempts to solve the mystery of disappearing objectives
author Nenue
date Sun, 17 Apr 2016 13:00:31 -0400
parents ObjectiveTracker/Update.lua@69d03f8e293e
children e84d645c8ab8
rev   line source
Nenue@35 1 --- ${PACKAGE_NAME}
Nenue@35 2 -- @file-author@
Nenue@35 3 -- @project-revision@ @project-hash@
Nenue@35 4 -- @file-revision@ @file-hash@
Nenue@35 5 -- Created: 4/17/2016 7:33 AM
Nenue@35 6 local B = select(2,...).frame
Nenue@35 7 local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame')
Nenue@35 8 local _G, ipairs, max, min, unpack, floor, pairs, tostring, type, band = _G, ipairs, max, min, unpack, floor, pairs, tostring, type, bit.band
Nenue@35 9 local IsResting, UnitXP, UnitXPMax, GetXPExhaustion, tinsert, tremove = IsResting, UnitXP, UnitXPMax, GetXPExhaustion, table.insert, table.remove
Nenue@35 10 local UnitLevel, IsQuestWatched, UIParent = UnitLevel, IsQuestWatched, UIParent
Nenue@35 11 local GetAutoQuestPopUp, GetQuestLogCompletionText = GetAutoQuestPopUp, GetQuestLogCompletionText
Nenue@35 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@35 14 local InCombatLockdown, format, lshift, CreateFrame = InCombatLockdown, format, bit.lshift, CreateFrame
Nenue@35 15 local IsModifiedClick, ChatEdit_GetActiveWindow = IsModifiedClick, ChatEdit_GetActiveWindow
Nenue@35 16 local print = B.print('Tracker')
Nenue@35 17 local oprint = B.print('Objectives')
Nenue@35 18 local bprint = B.print('Block')
Nenue@35 19 local tprint = B.print('Tracker')
Nenue@35 20 local lprint = B.print('Line')
Nenue@35 21 local unitLevel = 1
Nenue@35 22 local OBJECTIVE_TRACKER_UPDATE_REASON = OBJECTIVE_TRACKER_UPDATE_REASON
Nenue@35 23 local debug = false
Nenue@35 24
Nenue@35 25 --- FRAMES
Nenue@35 26 local Wrapper = _G.VeneerObjectiveWrapper
Nenue@35 27 local Scroller = Wrapper.scrollArea
Nenue@35 28 local Scroll = _G.VeneerObjectiveScroll
Nenue@35 29 local orderedHandlers = T.orderedHandlers
Nenue@35 30 local orderedNames = T.orderedNames
Nenue@35 31
Nenue@35 32
Nenue@35 33 --- Placing the Update functions here since they shouldn't be messing with schema stuff
Nenue@35 34 local currentPosition, anchorFrame, anchorPoint
Nenue@35 35 --- Positioning and stuff
Nenue@35 36 local tick = 0
Nenue@35 37 local firstUpdate = true
Nenue@35 38 function T:Update (reason, ...)
Nenue@35 39 if not B.Conf.VeneerObjectiveWrapper.enabled then
Nenue@35 40 return
Nenue@35 41 end
Nenue@35 42
Nenue@35 43 tick = tick + 1
Nenue@35 44 if firstUpdate or not reason then
Nenue@35 45 reason = _G.OBJECTIVE_TRACKER_UPDATE_ALL
Nenue@35 46 end
Nenue@35 47
Nenue@35 48 local print = tprint
Nenue@35 49 local hasStuff = false
Nenue@35 50 local insertingStuff = false
Nenue@35 51
Nenue@35 52 print(format('|cFFBB0066Update:|r |cFFFF%04X%d|r ', tick, lshift(reason, 4)), reason, ...)
Nenue@35 53 currentPosition = 0
Nenue@35 54
Nenue@35 55 for id, handler in pairs(T.orderedHandlers) do
Nenue@35 56 local frame = handler.frame
Nenue@35 57
Nenue@35 58
Nenue@35 59 if band(reason, handler.updateReasonModule + handler.updateReasonEvents) > 0 then
Nenue@35 60 insertingStuff = handler:UpdateTracker(reason, ...)
Nenue@35 61 else
Nenue@35 62 print(' |cFFFF4400Update:|r skipping',handler.name)
Nenue@35 63 end
Nenue@35 64
Nenue@35 65 if handler.numWatched >= 1 then
Nenue@35 66 hasStuff = true
Nenue@35 67 currentPosition = currentPosition + 1
Nenue@35 68 Default.AddTracker(handler, frame, currentPosition)
Nenue@35 69
Nenue@35 70 else
Nenue@35 71 frame:ClearAllPoints()
Nenue@35 72 frame:SetPoint('BOTTOM', Scroll, 'BOTTOM', 0, 0)
Nenue@35 73 frame.destinationOffset = 0
Nenue@35 74 frame:Hide()
Nenue@35 75 frame.wasEmpty = true
Nenue@35 76 end
Nenue@35 77 end
Nenue@35 78
Nenue@35 79 -- do these whenever there is content or content is being added
Nenue@35 80 if hasStuff or insertingStuff then
Nenue@35 81 T:FinishWrapper()
Nenue@35 82 end
Nenue@35 83 Quest.GetClosest()
Nenue@35 84 --T.UpdateActionButtons(reason)
Nenue@35 85 if firstUpdate then
Nenue@35 86 firstUpdate = nil
Nenue@35 87 end
Nenue@35 88 end
Nenue@35 89
Nenue@35 90 Default.UpdateTracker = function (handler, reason, id, isNew)
Nenue@35 91 local print = tprint
Nenue@35 92 local tracker = handler.frame
Nenue@35 93 local blockIndex = 0
Nenue@35 94
Nenue@35 95 handler.updateReason = reason
Nenue@35 96 handler.numWatched = handler:GetNumWatched()
Nenue@35 97 if handler.numWatched >= 1 then
Nenue@35 98
Nenue@35 99 print(' |cFF00FF88GetNumWatched:|r',handler.name, handler.numWatched, 'of', handler.numAll)
Nenue@35 100 end
Nenue@35 101
Nenue@35 102 handler.numBlocks = 0
Nenue@35 103 handler.currentBlock = 0
Nenue@35 104 handler.currentAnchor = tracker.titlebg
Nenue@35 105 for blockIndex = 1, handler.numWatched do
Nenue@35 106 local currentBlock = handler:UpdateBlock(blockIndex, id, isNew)
Nenue@35 107 if currentBlock then
Nenue@35 108 handler:AddBlock(currentBlock)
Nenue@35 109 else
Nenue@35 110 print(' |cFFFF9900finished|r @', blockIndex)
Nenue@35 111 break -- done with quest stuff
Nenue@35 112 end
Nenue@35 113 end
Nenue@35 114
Nenue@35 115
Nenue@35 116 local numBlocks = handler.numBlocks
Nenue@35 117 local used = handler.usedBlocks
Nenue@35 118 local free = handler.freeBlocks
Nenue@35 119 print(format(' |cFFFF8800UpdateTracker|r(%s): |cFFFF8800%04X|r --- blocks |cFFFF8800%d|r, (used/free: |cFFFF8800%d|r/|cFFFF8800%d|r)', handler.name, band(reason, handler.updateReasonModule + handler.updateReasonEvents, reason), numBlocks, #used, #free))
Nenue@35 120 return tracker.numWatched, tracker.numAll
Nenue@35 121 end
Nenue@35 122
Nenue@35 123 Default.UpdateBlock = function (handler, blockIndex, id, added)
Nenue@35 124 local print = bprint
Nenue@35 125 if not blockIndex then
Nenue@35 126 return
Nenue@35 127 end
Nenue@35 128 local info = handler:GetInfo(blockIndex) -- should match up with whatever the internal watch list has
Nenue@35 129 if not info then
Nenue@35 130 return
Nenue@35 131 end
Nenue@35 132 print(' Updating |cFF00FF00'..handler.displayName..'|r|cFF00FFFF'..blockIndex..'|r|cFF0099FF', info.id ,'|r')
Nenue@35 133 local frame = handler.frame
Nenue@35 134 local block = handler:GetBlock(info.id)
Nenue@35 135
Nenue@35 136 if added then
Nenue@35 137 -- do something if the block is being assigned a new thing
Nenue@35 138 end
Nenue@35 139
Nenue@35 140 block.handler = handler
Nenue@35 141 block.info = info
Nenue@35 142
Nenue@35 143 info.blockIndex = blockIndex
Nenue@35 144 if info.questID then handler.QuestBlock[info.questID] = block end
Nenue@35 145 if info.logIndex then handler.LogBlock[info.logIndex] = block end
Nenue@35 146 if info.watchIndex then handler.WatchBlock[info.watchIndex] = block end
Nenue@35 147 handler.BlockInfo[blockIndex] = info
Nenue@35 148 local newSchema = handler:UpdateObjectives(block)
Nenue@35 149 if newSchema and newSchema ~= blockSchema then
Nenue@35 150 T.UpdateSchema('block', newSchema)
Nenue@35 151 end
Nenue@35 152
Nenue@35 153 block.title:SetText(info.title)
Nenue@35 154
Nenue@35 155 print(' |cFFFFFF00height|r:', block.height)
Nenue@35 156 print(' |cFF00FFFF)|r -> ', block, block:GetHeight())
Nenue@35 157
Nenue@35 158 block:Show()
Nenue@35 159
Nenue@35 160 if info.specialItem and not info.itemButton then
Nenue@35 161 print(' - |cFF00FFFFgenerating item button for info set')
Nenue@35 162 info.itemButton = T.SetItemButton(block, info)
Nenue@35 163 else
Nenue@35 164 --info.itemButton = nil
Nenue@35 165 end
Nenue@35 166
Nenue@35 167 local tagPoint, tagAnchor, tagRelative, x, y = 'TOPRIGHT', block, 'TOPRIGHT', -2, -2
Nenue@35 168
Nenue@35 169 local numCurrency = 0
Nenue@35 170 for i, rewardTile in ipairs(block.rewardTile) do
Nenue@35 171 if info.rewardInfo and info.rewardInfo[i] then
Nenue@35 172 local reward = info.rewardInfo[i]
Nenue@35 173 --rewardTile:SetPoint(tagPoint, tagAnchor, tagRelative, -2, -2)
Nenue@35 174 rewardTile:SetTexture(reward.texture)
Nenue@35 175 rewardTile:Show()
Nenue@35 176
Nenue@35 177 print('updating reward tile #'.. i, reward.type, reward.count, reward.text, reward.texture)
Nenue@35 178 if reward.count and reward.count > 1 then
Nenue@35 179 block.rewardLabel[i]:SetText(reward.count)
Nenue@35 180 block.rewardLabel[i]:Show()
Nenue@35 181 end
Nenue@35 182
Nenue@35 183 rewardTile:ClearAllPoints()
Nenue@35 184 rewardTile:SetPoint(tagPoint, tagAnchor, tagRelative, x, y)
Nenue@35 185 tagPoint, tagAnchor, tagRelative, x, y = 'TOPRIGHT', rewardTile, 'TOPLEFT', -2, 0
Nenue@35 186 else
Nenue@35 187 rewardTile:Hide()
Nenue@35 188 block.rewardLabel[i]:Hide()
Nenue@35 189 end
Nenue@35 190 end
Nenue@35 191
Nenue@35 192 if info.selected then
Nenue@35 193 block.SelectionOverlay:Show()
Nenue@35 194 else
Nenue@35 195 block.SelectionOverlay:Hide()
Nenue@35 196 end
Nenue@35 197
Nenue@35 198 if info.tagInfo then
Nenue@35 199 tagPoint, tagAnchor, tagRelative = handler:AddTag(block, 'frequencyTag', tagPoint, tagAnchor, tagRelative)
Nenue@35 200 tagPoint, tagAnchor, tagRelative = handler:AddTag(block, 'typeTag', tagPoint, tagAnchor, tagRelative)
Nenue@35 201 tagPoint, tagAnchor, tagRelative = handler:AddTag(block, 'completionTag', tagPoint, tagAnchor, tagRelative)
Nenue@35 202 end
Nenue@35 203
Nenue@35 204 if info.statusKey and (Devian and Devian.InWorkspace()) then
Nenue@35 205 block.debugText:SetText(info.statusKey)
Nenue@35 206 block.debugText:Show()
Nenue@35 207 end
Nenue@35 208 return block
Nenue@35 209 end
Nenue@35 210
Nenue@35 211 Default.UpdateObjectives = function(handler, block, block_schema)
Nenue@35 212 local print = lprint
Nenue@35 213 local info = block.info
Nenue@35 214 print(' |cFF00FF00default.objectives', block:GetName())
Nenue@35 215 -- reset the starting positions
Nenue@35 216 block.endPoint = block.titlebg
Nenue@35 217 block.attachmentHeight = 0
Nenue@35 218 block.currentLine = 0
Nenue@35 219
Nenue@35 220 local displayObjectiveHeader = false
Nenue@35 221
Nenue@35 222 block.attachmentHeight = 0
Nenue@35 223 local text, attachment, template
Nenue@35 224
Nenue@35 225
Nenue@35 226 if info.description and #info.description >= 1 then
Nenue@35 227 print(' |cFF00FFFF header line:|r', info.description)
Nenue@35 228 text = info.description
Nenue@35 229 handler:AddLine(block, text, nil)
Nenue@35 230 end
Nenue@35 231
Nenue@35 232 if (info.isComplete or info.numObjectives == 0) and info.completionText then
Nenue@35 233 print(' overriding line #1 for completion text:', info.completionText)
Nenue@35 234 text = info.completionText
Nenue@35 235 handler:AddLine(block, text, nil, 'completed')
Nenue@35 236 else
Nenue@35 237 if info.objectives then
Nenue@35 238 for i, data in ipairs(info.objectives) do
Nenue@35 239 local line = handler:GetLine(block)
Nenue@35 240 displayObjectiveHeader = true
Nenue@35 241 line.height = 0
Nenue@35 242 text, attachment, template = handler:UpdateLine(block, line, data)
Nenue@35 243 print(' |cFF88FF00#', i, data.type, text, attachment)
Nenue@35 244 handler:AddLine(block, text, attachment, template)
Nenue@35 245
Nenue@35 246 end
Nenue@35 247 end
Nenue@35 248 end
Nenue@35 249
Nenue@35 250 if block.currentLine < block.numLines then
Nenue@35 251 print(' - cull', block.currentLine, block.numLines)
Nenue@35 252 for i = block.currentLine + 1, block.numLines do
Nenue@35 253 print(' - hide |cFFFF0088'..i..'|r', block.lines[i])
Nenue@35 254 block.lines[i]:ClearAllPoints()
Nenue@35 255 block.lines[i]:Hide()
Nenue@35 256 end
Nenue@35 257 end
Nenue@35 258
Nenue@35 259 if block.currentLine > 0 then
Nenue@35 260 block.attachmentHeight = block.attachmentHeight
Nenue@35 261 print(' |cFF00FF00attachment:', block.attachmentHeight)
Nenue@35 262 end
Nenue@35 263 return block_schema
Nenue@35 264 end
Nenue@35 265
Nenue@35 266 Default.UpdateLine = function(handler, block, line, data)
Nenue@35 267 return data.text, line.widget, 'normal'
Nenue@35 268 end
Nenue@35 269
Nenue@35 270 Default.Select = function(handler, block)
Nenue@35 271 T:Update()
Nenue@35 272 end
Nenue@35 273 Default.Open = function(handler, block)
Nenue@35 274 T:Update(handler.watchReasonModule)
Nenue@35 275 end
Nenue@35 276 Default.Remove = function(handler, block)
Nenue@35 277 T:Update(handler.watchReasonModule)
Nenue@35 278 end
Nenue@35 279 Default.Report = function(handler, block)
Nenue@35 280 print('Stats:', handler.numWatched,'items tracked,', handler.numBlocks,'blocks assigned.')
Nenue@35 281 end
Nenue@35 282
Nenue@35 283 Default.OnMouseUp = function(self, button)
Nenue@35 284 print(self.handler.name, self.mainStyle, self.subStyle)
Nenue@35 285 if button == 'LeftButton' then
Nenue@35 286 if IsModifiedClick("CHATLINK") and ChatEdit_GetActiveWindow() then
Nenue@35 287 self.Link(self.handler, self)
Nenue@35 288 elseif IsModifiedClick("QUESTWATCHTOGGLE") then
Nenue@35 289 self.Remove(self.handler, self)
Nenue@35 290 else
Nenue@35 291 self.Select(self.handler, self)
Nenue@35 292 end
Nenue@35 293 elseif button == 'RightButton' then
Nenue@35 294 self.Open(self.handler, self)
Nenue@35 295 end
Nenue@35 296 self.initialButton = nil
Nenue@35 297 self.modChatLink = nil
Nenue@35 298 self.modQuestWatch = nil
Nenue@35 299 T:Update(self.handler.updateReasonModule)
Nenue@35 300 print('|cFFFF8800'..tostring(self:GetName())..':MouseUp()|r')
Nenue@35 301 end
Nenue@35 302 Default.OnMouseDown = function(self, button)
Nenue@35 303 print(self.info.title)
Nenue@35 304 end