Mercurial > wow > buffalo2
comparison ObjectiveTracker/BonusObjectiveData.lua @ 43:9480bd904f4c
- file name organizing
author | Nenue |
---|---|
date | Mon, 25 Apr 2016 13:51:58 -0400 |
parents | ObjectiveTracker/BonusObjectives.lua@03ed70f846de |
children |
comparison
equal
deleted
inserted
replaced
42:c73051785f19 | 43:9480bd904f4c |
---|---|
1 --- ${PACKAGE_NAME} | |
2 -- @file-author@ | |
3 -- @project-revision@ @project-hash@ | |
4 -- @file-revision@ @file-hash@ | |
5 -- Created: 4/13/2016 7:48 PM | |
6 local B = select(2,...).frame | |
7 local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame') | |
8 local Default, Quest = T.DefaultHandler, T.Quest | |
9 local print = B.print('Tracker') | |
10 local lprint = B.print('Line') | |
11 local iprint = B.print('Info') | |
12 local Bonus = T.Bonus | |
13 | |
14 local UnitName, GetRealmName, GetQuestObjectiveInfo, GetTasksTable, GetTaskInfo = UnitName, GetRealmName, GetQuestObjectiveInfo, GetTasksTable, GetTaskInfo | |
15 local GetMapNameByID, GetCurrentMapAreaID = GetMapNameByID, GetCurrentMapAreaID | |
16 local tinsert, ipairs, pairs, tostring, wipe = tinsert, ipairs, pairs, tostring, table.wipe | |
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 | |
19 | |
20 --- Holds data for recently completed tasks | |
21 local completedTasks = {} | |
22 | |
23 --- Returns a tasks table modified to include recently completed objectives | |
24 local InternalGetTasksTable = function() | |
25 local print = Bonus.print | |
26 local char = UnitName("player") | |
27 local realm = GetRealmName() | |
28 local tasks = GetTasksTable() | |
29 | |
30 for questID, data in pairs(Bonus.Info) do | |
31 print('GetTasksTable', questID, #data.objectives) | |
32 for i, o in ipairs(data.objectives) do | |
33 print('GetTasksTable', questID, i, o.text) | |
34 end | |
35 end | |
36 | |
37 for questID, data in pairs(completedTasks) do | |
38 if questID > 0 then | |
39 local found = false | |
40 for i = 1, #tasks do | |
41 if tasks[i] == questID then | |
42 found = true | |
43 break | |
44 end | |
45 end | |
46 -- if it's not part of the current table, then try to insert it where it was last found | |
47 if not found then | |
48 if data.watchIndex < #tasks then | |
49 tinsert(tasks, data.watchIndex, data) | |
50 else | |
51 tinsert(tasks, data) | |
52 end | |
53 end | |
54 end | |
55 end | |
56 return tasks | |
57 end | |
58 | |
59 --- Returns an entry from the composed tasks table if possible, otherwise makes an API pull | |
60 | |
61 local InternalGetTaskInfo = function(questID) | |
62 if completedTasks[questID] then | |
63 -- if it's a recently completed task, use the information stored for it | |
64 return true, true, #completedTasks[questID].objectives | |
65 else | |
66 return GetTaskInfo(questID) | |
67 end | |
68 end | |
69 | |
70 --- Same as above but for the objective entries | |
71 local InternalGetQuestObjectiveInfo = function(questID, objectiveIndex) | |
72 if ( completedTasks[questID] ) then | |
73 print('using internal data') | |
74 return completedTasks[questID].objectives[objectiveIndex], completedTasks[questID].objectiveType, true; | |
75 else | |
76 return GetQuestObjectiveInfo(questID, objectiveIndex, false); | |
77 end | |
78 end | |
79 | |
80 --- end redundant copy of silliness | |
81 ------------------------------------------------------------------------------------------ | |
82 | |
83 Bonus.Completed = {} | |
84 Bonus.POI = {} | |
85 Bonus.Scenario = {} | |
86 Bonus.QuestBlock = {} | |
87 Bonus.WatchInfo = {} | |
88 | |
89 local function CanShowTask(isInArea, isOnMap, existingTask, numObjectives) | |
90 if TASK_DISPLAY_TEST == 1 then | |
91 return (isInArea) | |
92 elseif TASK_DISPLAY_TEST == 2 then | |
93 return (isInArea and(isOnMap and existingTask)) | |
94 elseif TASK_DISPLAY_TEST == 3 then | |
95 return true | |
96 end | |
97 end | |
98 | |
99 function Bonus:GetNumWatched () | |
100 | |
101 local print = self.print | |
102 print(self.name, self) | |
103 | |
104 local tasks = InternalGetTasksTable() | |
105 local numWatched = 0 | |
106 local numAll = 0 | |
107 local existingTasks = {} | |
108 wipe(self.WatchList) | |
109 print('|cFF'..self.internalColor..'Bonus.GetNumWatched()|r', #tasks) | |
110 print('InternalGetTaskInfo') | |
111 | |
112 for i, questID in ipairs(tasks) do | |
113 local isInArea, isOnMap, numObjectives = InternalGetTaskInfo(questID) | |
114 local existingTask = self.InfoBlock[questID] | |
115 local displayObjectiveHeader = false; | |
116 local displayTask = CanShowTask(isInArea, isOnMap, existingTask) | |
117 if displayTask then | |
118 print('TaskInfo', '|cFF00FF00showable objective list', questID) | |
119 self.Info[questID] = self.Info[questID] or {} | |
120 | |
121 local t = self.Info[questID] | |
122 if (isOnMap or isInArea) and existingTask then | |
123 t.areaID = GetCurrentMapAreaID() | |
124 local _ | |
125 t.mapName, _, _, t.isMicroDungeon, t.microDungeonMapName = GetMapInfo() | |
126 print('InternalGetTaskInfo', 'map data', t.areaID, t.mapName) | |
127 end | |
128 | |
129 local taskTitle | |
130 t.id = questID | |
131 t.objectives = {} | |
132 local isComplete = true; | |
133 for objectiveIndex = 1, numObjectives do | |
134 local text, objectiveType, finished, displayAsObjective = InternalGetQuestObjectiveInfo(questID, objectiveIndex, false); | |
135 displayObjectiveHeader = displayObjectiveHeader or displayAsObjective; | |
136 if not taskTitle then | |
137 if objectiveType == 'progressbar' and not text:match('^%d%+\\%d+') then | |
138 taskTitle = text | |
139 text = '' | |
140 end | |
141 end | |
142 | |
143 | |
144 print('TaskObjective', text, objectiveType, finished, displayAsObjective) | |
145 t.objectives[objectiveIndex] = t.objectives[objectiveIndex] or {} | |
146 local o = t.objectives[objectiveIndex] | |
147 | |
148 o.index = objectiveIndex | |
149 o.text = text | |
150 o.type = objectiveType | |
151 o.finished = finished | |
152 o.displayAsObjective = displayAsObjective | |
153 isComplete = (isComplete and finished) | |
154 end | |
155 | |
156 T.SetRewards(t, questID) | |
157 | |
158 -- didn't get a name from progress bar? what about area name | |
159 if not taskTitle then | |
160 if isInArea then | |
161 taskTitle = GetMapNameByID(GetCurrentMapAreaID()) | |
162 end | |
163 end | |
164 t.numObjectives = numObjectives | |
165 t.isInArea = isInArea | |
166 t.isOnMap = isOnMap | |
167 t.existingTask = existingTask | |
168 t.questID = questID | |
169 t.id = questID | |
170 t.taskIndex = i | |
171 t.title = taskTitle | |
172 t.isComplete = isComplete | |
173 self.WatchList[i] = t | |
174 elseif existingTask then | |
175 print('TaskInfo', '|cFFFF4400hideable task', questID) | |
176 existingTask:Hide() | |
177 end | |
178 | |
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')) | |
181 end | |
182 | |
183 | |
184 self.numWatched = #self.WatchList | |
185 self.numAll = #existingTasks | |
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 | |
205 end | |
206 | |
207 --- info cleanup done when turn-ins are detected | |
208 Bonus.OnTurnIn = function(self, block, questID, xp, money) | |
209 --[=[ | |
210 local info = self.Info[questID] | |
211 if info.rewardInfo and #info.rewardInfo >= 1 then | |
212 for i, reward in ipairs(info.rewardInfo) do | |
213 --[[ | |
214 type = 'item', | |
215 index = i , | |
216 name = name, | |
217 texture = texture, | |
218 count = count, | |
219 quality = quality, | |
220 isUsable = isUsable | |
221 ]] | |
222 print(' reward ', i, ' ', reward.type, reward.name, reward.count) | |
223 | |
224 end | |
225 end | |
226 | |
227 print('|cFFFF8800'..block:GetName()..':OnTurnIn call', questID, xp, money) | |
228 local savedTasks = B.Conf.TasksLog or {} | |
229 | |
230 info.completedTime = GetTime() | |
231 info.animate = true | |
232 T.SetAnimate(self.updateReasonModule) | |
233 savedTasks[questID] = { | |
234 id = questID, | |
235 title = info.title, | |
236 finished = true, | |
237 numObjectives = info.numObjectives, | |
238 objectives = info.objectives, | |
239 rewardInfo = info.rewardInfo, | |
240 } | |
241 B.Conf.TasksLog = savedTasks | |
242 | |
243 print(' ## CONF TASKLOG ##') | |
244 for i, t in pairs(savedTasks[questID]) do | |
245 print(' |cFFFFFF00'.. tostring(i)..'|r', t) | |
246 | |
247 end | |
248 for o, j in ipairs(savedTasks[questID].objectives) do | |
249 print(' |cFF00FFFF#'.. o ..'|r', j.type, j.finished) | |
250 end | |
251 | |
252 print('adding', info.title, 'to cache') | |
253 --]=] | |
254 end | |
255 | |
256 Bonus.GetInfo = function(self, taskIndex) | |
257 print(self.name, self) | |
258 return self.WatchInfo[taskIndex] | |
259 end | |
260 | |
261 | |
262 | |
263 --- Update hooks | |
264 Bonus.UpdateObjectives = function(handler, block, blockSchema) | |
265 block.schema = blockSchema or 'default' | |
266 local info = block.info | |
267 block.title:SetText(info.title) | |
268 | |
269 | |
270 Default.UpdateObjectives(handler, block) | |
271 return blockSchema | |
272 end | |
273 | |
274 Bonus.UpdateLine = function(handler, block, data) | |
275 local info = block.info | |
276 local print = lprint | |
277 local text, attachment = '', nil | |
278 if data.type == 'progressbar' then | |
279 print(' |cFFFF44DDpercent='..tostring(GetQuestProgressBarPercent(info.questID))) | |
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 | |
287 attachment = T.GetWidget(data, 'StatusBar', info.questID..'-'..data.index) | |
288 attachment:SetParent(block) | |
289 print(attachment:GetNumPoints()) | |
290 for i = 1, attachment:GetNumPoints() do | |
291 print(' ',attachment:GetPoint(i)) | |
292 end | |
293 | |
294 attachment.value = percent | |
295 attachment.maxValue = 100 | |
296 attachment.status:SetFormattedText(PERCENTAGE_STRING, percent) | |
297 --attachment:SetParent(handler.frame) | |
298 --print(attachment.status:GetText()) | |
299 print(' |cFFFF0022** text:|r', data.text, '|cFFFF0022value:|r', data.value, '|cFFFF0022max:|r', data.maxValue) | |
300 end | |
301 text = data.text | |
302 return text, attachment, 'default' | |
303 end | |
304 | |
305 Bonus.Select = function(handler, block) | |
306 print(handler, block) | |
307 handler:OnTurnIn(block, block.info.questID) | |
308 end | |
309 Bonus.Remove = function(self) | |
310 | |
311 end |