Mercurial > wow > buffalo2
comparison ObjectiveTracker/BonusObjectives.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 | 1f8f9cc3d956 |
children |
comparison
equal
deleted
inserted
replaced
39:92534dc793f2 | 40:03ed70f846de |
---|---|
15 local GetMapNameByID, GetCurrentMapAreaID = GetMapNameByID, GetCurrentMapAreaID | 15 local GetMapNameByID, GetCurrentMapAreaID = GetMapNameByID, GetCurrentMapAreaID |
16 local tinsert, ipairs, pairs, tostring, wipe = tinsert, ipairs, pairs, tostring, table.wipe | 16 local tinsert, ipairs, pairs, tostring, wipe = tinsert, ipairs, pairs, tostring, table.wipe |
17 local GetQuestProgressBarPercent, PERCENTAGE_STRING, GetTime = GetQuestProgressBarPercent, PERCENTAGE_STRING, GetTime | 17 local GetQuestProgressBarPercent, PERCENTAGE_STRING, GetTime = GetQuestProgressBarPercent, PERCENTAGE_STRING, GetTime |
18 local TASK_DISPLAY_TEST = 1 -- 1: normal (is nearby or on the map) 2: strict (is nearby) 3: data exists | 18 local TASK_DISPLAY_TEST = 1 -- 1: normal (is nearby or on the map) 2: strict (is nearby) 3: data exists |
19 | 19 |
20 --- Holds data for recently completed tasks | |
21 local completedTasks = {} | |
22 | |
20 --- Returns a tasks table modified to include recently completed objectives | 23 --- Returns a tasks table modified to include recently completed objectives |
21 local InternalGetTasksTable = function() | 24 local InternalGetTasksTable = function() |
22 local print = Bonus.print | 25 local print = Bonus.print |
23 local savedTasks = T.Conf.TasksLog | |
24 local char = UnitName("player") | 26 local char = UnitName("player") |
25 local realm = GetRealmName() | 27 local realm = GetRealmName() |
26 local tasks = GetTasksTable() | 28 local tasks = GetTasksTable() |
27 | 29 |
28 for questID, data in pairs(Bonus.Info) do | 30 for questID, data in pairs(Bonus.Info) do |
30 for i, o in ipairs(data.objectives) do | 32 for i, o in ipairs(data.objectives) do |
31 print('GetTasksTable', questID, i, o.text) | 33 print('GetTasksTable', questID, i, o.text) |
32 end | 34 end |
33 end | 35 end |
34 | 36 |
35 for questID, data in pairs(savedTasks) do | 37 for questID, data in pairs(completedTasks) do |
36 if questID > 0 then | 38 if questID > 0 then |
37 local found = false | 39 local found = false |
38 for i = 1, #tasks do | 40 for i = 1, #tasks do |
39 if tasks[i] == questID then | 41 if tasks[i] == questID then |
40 found = true | 42 found = true |
53 end | 55 end |
54 return tasks | 56 return tasks |
55 end | 57 end |
56 | 58 |
57 --- Returns an entry from the composed tasks table if possible, otherwise makes an API pull | 59 --- Returns an entry from the composed tasks table if possible, otherwise makes an API pull |
60 | |
58 local InternalGetTaskInfo = function(questID) | 61 local InternalGetTaskInfo = function(questID) |
59 local completedTasks = T.Conf.TasksLog | |
60 if completedTasks[questID] then | 62 if completedTasks[questID] then |
63 -- if it's a recently completed task, use the information stored for it | |
61 return true, true, #completedTasks[questID].objectives | 64 return true, true, #completedTasks[questID].objectives |
62 else | 65 else |
63 return GetTaskInfo(questID) | 66 return GetTaskInfo(questID) |
64 end | 67 end |
65 end | 68 end |
66 | 69 |
67 --- Same as above but for the objective entries | 70 --- Same as above but for the objective entries |
68 local InternalGetQuestObjectiveInfo = function(questID, objectiveIndex) | 71 local InternalGetQuestObjectiveInfo = function(questID, objectiveIndex) |
69 local completedTasks = T.Conf.TasksLog | |
70 if ( completedTasks[questID] ) then | 72 if ( completedTasks[questID] ) then |
71 print('using internal data') | 73 print('using internal data') |
72 return completedTasks[questID].objectives[objectiveIndex], completedTasks[questID].objectiveType, true; | 74 return completedTasks[questID].objectives[objectiveIndex], completedTasks[questID].objectiveType, true; |
73 else | 75 else |
74 return GetQuestObjectiveInfo(questID, objectiveIndex, false); | 76 return GetQuestObjectiveInfo(questID, objectiveIndex, false); |
109 | 111 |
110 for i, questID in ipairs(tasks) do | 112 for i, questID in ipairs(tasks) do |
111 local isInArea, isOnMap, numObjectives = InternalGetTaskInfo(questID) | 113 local isInArea, isOnMap, numObjectives = InternalGetTaskInfo(questID) |
112 local existingTask = self.InfoBlock[questID] | 114 local existingTask = self.InfoBlock[questID] |
113 local displayObjectiveHeader = false; | 115 local displayObjectiveHeader = false; |
114 if CanShowTask(isInArea, isOnMap, existingTask) then | 116 local displayTask = CanShowTask(isInArea, isOnMap, existingTask) |
117 if displayTask then | |
115 print('TaskInfo', '|cFF00FF00showable objective list', questID) | 118 print('TaskInfo', '|cFF00FF00showable objective list', questID) |
116 self.Info[questID] = self.Info[questID] or {} | 119 self.Info[questID] = self.Info[questID] or {} |
117 | 120 |
118 local t = self.Info[questID] | 121 local t = self.Info[questID] |
119 if (isOnMap or isInArea) and existingTask then | 122 if (isOnMap or isInArea) and existingTask then |
124 end | 127 end |
125 | 128 |
126 local taskTitle | 129 local taskTitle |
127 t.id = questID | 130 t.id = questID |
128 t.objectives = {} | 131 t.objectives = {} |
129 local taskFinished = true; | 132 local isComplete = true; |
130 for objectiveIndex = 1, numObjectives do | 133 for objectiveIndex = 1, numObjectives do |
131 local text, objectiveType, finished, displayAsObjective = InternalGetQuestObjectiveInfo(questID, objectiveIndex, false); | 134 local text, objectiveType, finished, displayAsObjective = InternalGetQuestObjectiveInfo(questID, objectiveIndex, false); |
132 displayObjectiveHeader = displayObjectiveHeader or displayAsObjective; | 135 displayObjectiveHeader = displayObjectiveHeader or displayAsObjective; |
133 if not taskTitle then | 136 if not taskTitle then |
134 if objectiveType == 'progressbar' and not text:match('^%d%+\\%d+') then | 137 if objectiveType == 'progressbar' and not text:match('^%d%+\\%d+') then |
145 o.index = objectiveIndex | 148 o.index = objectiveIndex |
146 o.text = text | 149 o.text = text |
147 o.type = objectiveType | 150 o.type = objectiveType |
148 o.finished = finished | 151 o.finished = finished |
149 o.displayAsObjective = displayAsObjective | 152 o.displayAsObjective = displayAsObjective |
153 isComplete = (isComplete and finished) | |
150 end | 154 end |
151 | 155 |
152 T.SetRewards(t, questID) | 156 T.SetRewards(t, questID) |
153 | 157 |
154 -- didn't get a name from progress bar? what about area name | 158 -- didn't get a name from progress bar? what about area name |
163 t.existingTask = existingTask | 167 t.existingTask = existingTask |
164 t.questID = questID | 168 t.questID = questID |
165 t.id = questID | 169 t.id = questID |
166 t.taskIndex = i | 170 t.taskIndex = i |
167 t.title = taskTitle | 171 t.title = taskTitle |
172 t.isComplete = isComplete | |
168 self.WatchList[i] = t | 173 self.WatchList[i] = t |
169 elseif existingTask then | 174 elseif existingTask then |
170 print('TaskInfo', '|cFFFF4400hideable task', questID) | 175 print('TaskInfo', '|cFFFF4400hideable task', questID) |
171 existingTask:Hide() | 176 existingTask:Hide() |
172 end | 177 end |
173 | 178 |
174 print ('TaskInfo', i, 'questID', questID, 'inArea', isInArea, 'onMap', isOnMap, 'existing', (existingTask and 'Y' or 'N'), (test and '|cFF00FF00show|r' or '|cFFFF0088hide|r')) | 179 |
180 print ('TaskInfo', i, '|cFFFFFF00'.. questID..'|r', '('..(isInArea and '|cFF88FF88' or '|cFF666666') .. 'isInArea|r', 'AND', (isOnMap and '|cFF88FF88' or '|cFF666666') .. 'isOnMap|r)', 'OR', (existingTask and '|cFF88FF88' or '|cFF666666') .. 'existingTask|r', (displayTask and '|cFF00FF00show|r' or '|cFFFF4400hide|r')) | |
175 end | 181 end |
176 | 182 |
177 | 183 |
178 self.numWatched = #self.WatchList | 184 self.numWatched = #self.WatchList |
179 self.numAll = #existingTasks | 185 self.numAll = #existingTasks |
180 return self.numWatched, self.numWatched, self.WatchList | 186 return self.numWatched, self.numWatched, self.WatchList |
187 end | |
188 | |
189 Bonus.OnEvent = function(block, event, ...) | |
190 if event == 'QUEST_LOG_UPDATE' then | |
191 local info = block.info | |
192 | |
193 local isInArea, isOnMap, numObjectives = InternalGetTaskInfo(info.questID) | |
194 if not CanShowTask(isInArea, isOnMap, block, numObjectives) then | |
195 block:Hide() | |
196 end | |
197 end | |
198 end | |
199 | |
200 Bonus.GetBlock = function(self, index) | |
201 local block = Default.GetBlock(self, index) | |
202 block:SetScript('OnEvent', self.OnEvent) | |
203 block:RegisterEvent('QUEST_LOG_UPDATE') | |
204 return block | |
181 end | 205 end |
182 | 206 |
183 --- info cleanup done when turn-ins are detected | 207 --- info cleanup done when turn-ins are detected |
184 Bonus.OnTurnIn = function(self, block, questID, xp, money) | 208 Bonus.OnTurnIn = function(self, block, questID, xp, money) |
185 --[=[ | 209 --[=[ |
252 local print = lprint | 276 local print = lprint |
253 local text, attachment = '', nil | 277 local text, attachment = '', nil |
254 if data.type == 'progressbar' then | 278 if data.type == 'progressbar' then |
255 print(' |cFFFF44DDpercent='..tostring(GetQuestProgressBarPercent(info.questID))) | 279 print(' |cFFFF44DDpercent='..tostring(GetQuestProgressBarPercent(info.questID))) |
256 local percent = 100 | 280 local percent = 100 |
281 if not data.finished then | |
282 percent = GetQuestProgressBarPercent(info.questID) | |
283 end | |
284 data.value = percent | |
285 data.maxValue = 100 | |
286 | |
257 attachment = T.GetWidget(data, 'StatusBar', info.questID..'-'..data.index) | 287 attachment = T.GetWidget(data, 'StatusBar', info.questID..'-'..data.index) |
258 attachment:SetParent(block) | 288 attachment:SetParent(block) |
259 | |
260 if not data.finished then | |
261 percent = GetQuestProgressBarPercent(info.questID) | |
262 end | |
263 data.value = percent | |
264 data.maxValue = 100 | |
265 | |
266 print(attachment:GetNumPoints()) | 289 print(attachment:GetNumPoints()) |
267 for i = 1, attachment:GetNumPoints() do | 290 for i = 1, attachment:GetNumPoints() do |
268 print(' ',attachment:GetPoint(i)) | 291 print(' ',attachment:GetPoint(i)) |
269 end | 292 end |
270 | |
271 | 293 |
272 attachment.value = percent | 294 attachment.value = percent |
273 attachment.maxValue = 100 | 295 attachment.maxValue = 100 |
274 attachment.status:SetFormattedText(PERCENTAGE_STRING, percent) | 296 attachment.status:SetFormattedText(PERCENTAGE_STRING, percent) |
275 --attachment:SetParent(handler.frame) | 297 --attachment:SetParent(handler.frame) |