Mercurial > wow > buffalo2
comparison ObjectiveTracker/Quests.lua @ 40:03ed70f846de
- move block accessors into a new file
- define a tMove function for reconciling the free/used tables as needed
- when retrieving an old block frame, confirm ID still matches; resolves multiple watch items on one block
- stop any animations when a block is freed; resolves stuck flare graphics
author | Nenue |
---|---|
date | Sun, 24 Apr 2016 14:15:25 -0400 |
parents | 92534dc793f2 |
children |
comparison
equal
deleted
inserted
replaced
39:92534dc793f2 | 40:03ed70f846de |
---|---|
11 local Default, Quest = T.DefaultHandler, T.Quest | 11 local Default, Quest = T.DefaultHandler, T.Quest |
12 local format, wipe, select = format, table.wipe, select | 12 local format, wipe, select = format, table.wipe, select |
13 local wipeall = B.wipeall | 13 local wipeall = B.wipeall |
14 local lprint, iprint, tprint = B.print('Line'), B.print('Info'), B.print('Tracker') | 14 local lprint, iprint, tprint = B.print('Line'), B.print('Info'), B.print('Tracker') |
15 local print = tprint | 15 local print = tprint |
16 | 16 local fprint = B.print('Frame') |
17 | 17 |
18 | 18 |
19 local superTrackQuestID, playerMoney, inScenario, showPOIs | 19 local superTrackQuestID, playerMoney, inScenario, showPOIs |
20 Quest.Update = function(self, reason, ...) | 20 Quest.Update = function(self, reason, ...) |
21 local print = self.print | 21 local print = self.print |
69 displayObjectives = false | 69 displayObjectives = false |
70 print('|cFF'..self.internalColor..' :: complete quest :: show instruction: "'.. tostring(info.completionText) .. '"') | 70 print('|cFF'..self.internalColor..' :: complete quest :: show instruction: "'.. tostring(info.completionText) .. '"') |
71 end | 71 end |
72 | 72 |
73 Default.UpdateObjectives(self, block, block_schema, displayObjectives) | 73 Default.UpdateObjectives(self, block, block_schema, displayObjectives) |
74 return block_schema | 74 return 0, block_schema |
75 end | 75 end |
76 | 76 |
77 Quest.UpdateLine = function(handler, block, data) | 77 Quest.UpdateLine = function(handler, block, data) |
78 local objectiveType = data.type | 78 local objectiveType = data.type |
79 return data.text, nil, objectiveType | 79 return data.text, nil, objectiveType |
84 local tremove, tinsert = tremove, tinsert | 84 local tremove, tinsert = tremove, tinsert |
85 local GetQuestLogIndexByID, IsQuestWatched = GetQuestLogIndexByID, IsQuestWatched | 85 local GetQuestLogIndexByID, IsQuestWatched = GetQuestLogIndexByID, IsQuestWatched |
86 Quest.QuestBlock = {} | 86 Quest.QuestBlock = {} |
87 Quest.LogBlock = {} | 87 Quest.LogBlock = {} |
88 Quest.LogInfo = {} | 88 Quest.LogInfo = {} |
89 function Quest:FreeBlock (block) | |
90 local used = Quest.usedBlocks | |
91 local free = Quest.freeBlocks | |
92 local reason = '' | |
93 local doRelease = false | |
94 local info = block.info | |
95 local questID = info.questID | |
96 local logIndex = info.logIndex | |
97 | |
98 if info.posIndex then | |
99 if used[info.posIndex] == block then | |
100 doRelease = true | |
101 reason = 'posIndex mismatch' | |
102 end | |
103 elseif logIndex then | |
104 if not IsQuestWatched(logIndex) then | |
105 reason = 'not being watched' | |
106 elseif not self.LogBlock[logIndex] then | |
107 doRelease = true | |
108 reason = 'missing logBlock entry' | |
109 elseif (self.LogBlock[logIndex] ~= block) then | |
110 doRelease = true | |
111 reason = 'different block using index' | |
112 end | |
113 elseif info.questID then | |
114 if not GetQuestLogIndexByID(info.questID) then | |
115 doRelease = true | |
116 reason = 'no identifiable quest log entry' | |
117 end | |
118 end | |
119 | |
120 | |
121 if doRelease then | |
122 print(' |cFF00FF00FreeBlock (' .. block:GetName() .. '):', reason) | |
123 block:Hide() | |
124 tremove(used, info.posIndex) | |
125 tinsert(free, block) | |
126 end | |
127 end | |
128 | 89 |
129 Quest.OnRemoved = function(block) | 90 Quest.OnRemoved = function(block) |
130 | 91 |
131 end | 92 end |
132 | 93 |
137 return block | 98 return block |
138 end | 99 end |
139 | 100 |
140 local watchesChecked = {} | 101 local watchesChecked = {} |
141 local infosChecked = {} | 102 local infosChecked = {} |
142 local blocksChecked = {} | |
143 local GetQuestWatchIndex = GetQuestWatchIndex | 103 local GetQuestWatchIndex = GetQuestWatchIndex |
144 --- Get a total of things to show, and straighten out the index while we're at it | 104 --- Get a total of things to show, and straighten out the index while we're at it |
145 --- Return the number shown, total in log, and the info table to parse | 105 --- Return the number shown, total in log, and the info table to parse |
106 local blocksChecked = {} | |
146 Quest.GetNumWatched = function (self, id, added) | 107 Quest.GetNumWatched = function (self, id, added) |
147 local print = self.print | 108 local print = self.print |
109 B.print('Block')('########') | |
110 B.print('Block')('########') | |
148 superTrackQuestID = GetSuperTrackedQuestID() | 111 superTrackQuestID = GetSuperTrackedQuestID() |
149 playerMoney = GetMoney(); | 112 playerMoney = GetMoney(); |
150 inScenario = C_Scenario.IsInScenario(); | 113 inScenario = C_Scenario.IsInScenario(); |
151 showPOIs = GetCVarBool("questPOI"); | 114 showPOIs = GetCVarBool("questPOI"); |
152 local numAll = GetNumQuestLogEntries() | 115 local numAll = GetNumQuestLogEntries() |
153 local numWatched = GetNumQuestWatches() | 116 local numWatched = GetNumQuestWatches() |
154 local bottomIndex = 1 | 117 local bottomIndex = 1 |
155 print('GetNumWatched', self.name, numWatched, 'of', numAll) | 118 print('GetNumWatched', self.name, numWatched, 'of', numAll) |
156 local start, limit = 1, numAll | 119 local start, limit = 1, numAll |
157 | 120 |
158 --- start a list of blocks affected by this function | |
159 wipe(blocksChecked) | |
160 if id and not added then | 121 if id and not added then |
122 -- if a particular id is supplied, add to checklist | |
161 if self.InfoBlock[id] then | 123 if self.InfoBlock[id] then |
162 tinsert(blocksChecked, self.InfoBlock[id]) | 124 blocksChecked[self.InfoBlock[id]] = self.InfoBlock[id] |
163 end | 125 end |
164 end | 126 end |
165 | 127 |
128 --- Start complicated frame-recycling bullshit | |
166 for logIndex = start, limit do | 129 for logIndex = start, limit do |
167 local reason1, reason2 = '', '' | 130 local reason1, reason2 = '', '' |
168 local title, level, suggestedGroup, isHeader, isCollapsed, isComplete, frequency, questID, startEvent, displayQuestID, isOnMap, hasLocalPOI, isTask, isStory = GetQuestLogTitle(logIndex) | 131 local title, level, suggestedGroup, isHeader, isCollapsed, isComplete, frequency, questID, startEvent, displayQuestID, isOnMap, hasLocalPOI, isTask, isStory = GetQuestLogTitle(logIndex) |
169 local watchIndex = GetQuestWatchIndex(logIndex) | 132 local watchIndex = GetQuestWatchIndex(logIndex) |
170 | 133 |
134 -- check if: the watch data pointers don't match | |
171 if watchIndex and watchIndex >= bottomIndex then | 135 if watchIndex and watchIndex >= bottomIndex then |
172 local watchInfo = self.WatchInfo[watchIndex] | 136 local watchInfo = self.WatchInfo[watchIndex] |
173 local watchBlock = self.WatchBlock[watchIndex] | 137 local watchBlock = self.WatchBlock[watchIndex] |
174 if watchInfo and watchInfo.questID ~= questID then | 138 if watchInfo and watchInfo.questID ~= questID then |
175 print('GetNumWatched', 'trimming WatchInfo ['..watchIndex..'] =/=', questID) | 139 print('GetNumWatched', 'trimming WatchInfo ['..watchIndex..'] =/=', questID) |
176 self.WatchInfo[watchIndex] = nil | 140 self.WatchInfo[watchIndex] = nil |
177 end | 141 end |
178 if watchBlock and watchBlock.info.questID ~= questID then | 142 if watchBlock and watchBlock.info.questID ~= questID then |
179 print('GetNumWatched', 'trimming WatchBlock ['..watchIndex..'] =/=', watchBlock:GetName()) | 143 print('GetNumWatched', 'trimming WatchBlock ['..watchIndex..'] =/=', watchBlock:GetName()) |
180 self.WatchBlock[watchIndex] = nil | 144 self.WatchBlock[watchIndex] = nil |
181 tinsert(blocksChecked, watchBlock) | 145 blocksChecked[watchBlock] = watchBlock |
182 end | 146 end |
183 end | 147 end |
184 | 148 |
149 -- check if: the logIndex pointer doesn't match | |
185 local logBlock = self.LogBlock[logIndex] | 150 local logBlock = self.LogBlock[logIndex] |
186 if logBlock and logBlock.info.questID ~= questID then | 151 if logBlock and logBlock.info.questID ~= questID then |
187 --print(' |cFFBBFF00GetNumWatched: trimming LogBlock ['..logIndex..'] =/=', logBlock:GetName()) | 152 print('GetQuests', 'replace info', logBlock.info.questID, '->', questID) |
188 self.LogBlock[logIndex] = nil | 153 self.LogBlock[logIndex] = nil |
189 tinsert(blocksChecked, logBlock) | 154 blocksChecked[logBlock] = logBlock |
190 end | 155 end |
191 | 156 |
157 -- add to watch index if: the questID is non-zero | |
192 if questID ~= 0 then | 158 if questID ~= 0 then |
193 self.Info[questID] = self:GetInfo(logIndex, watchIndex) | 159 self.Info[questID] = self:GetInfo(logIndex, watchIndex) |
194 --print(' |cFF44BBFFGetNumWatched:|r map', questID, 'to', logIndex, (watchIndex and ('('..watchIndex..')') or '')) | 160 print('GetQuests', format('request info |cFF00FF00%2d|r |cFFFFFF00%6d|r |cFFFF4400%3s|r', logIndex, questID, tostring(watchIndex or ''))) |
195 end | 161 end |
196 end | 162 end |
197 | 163 |
198 --- remove any orphaned blocks from view and, if possible, free it for re-use | 164 --- After GetInfo pass, look for any non-conformant blocks and deal with them |
199 for i, block in ipairs(blocksChecked) do | 165 for _, block in pairs(blocksChecked) do |
200 if not GetQuestLogIndexByID(block.info.questID, 'player') then | 166 local logIndex = GetQuestLogIndexByID(block.info.questID, 'player') |
201 print('GetNumWatched', 'iterating a block without an index |cFFBBFF00'.. block:GetName()..'|r') | 167 -- free if: logIndex doesn't resolve |
202 block:Hide() | 168 if not logIndex then |
203 self:FreeBlock(block) | 169 B.print('Block')('GetNumWatched', '|cFFBBFF00block has no index '.. block:GetName()..'|r') |
204 end | 170 self:ClearBlock(block) |
205 if not IsQuestWatched(block.info.logIndex) then | 171 -- hide if: logIndex isn't being watched |
206 print('GetNumWatched', 'hiding untracked quest |cFFBBFF00'.. block:GetName()..'|r') | 172 elseif not IsQuestWatched(block.info.logIndex) then |
207 block:Hide() | 173 B.print('Block')('GetNumWatched', '|cFFBBFF00fade from list '.. block:GetName()..'|r') |
208 end | 174 -- todo: figure out why animation gets clobbered |
175 self:ClearBlock(block) | |
176 end | |
177 blocksChecked[block] = nil | |
209 end | 178 end |
210 | 179 |
211 self.numWatched = numWatched | 180 self.numWatched = numWatched |
212 self.numAll = numAll | 181 self.numAll = numAll |
213 | 182 |