Mercurial > wow > buffalo2
comparison ObjectiveTracker/BonusObjectives.lua @ 38:1f8f9cc3d956
- module integration brought up to speed with current frame management structure
author | Nenue |
---|---|
date | Thu, 21 Apr 2016 11:36:41 -0400 |
parents | e84d645c8ab8 |
children | 03ed70f846de |
comparison
equal
deleted
inserted
replaced
37:e84d645c8ab8 | 38:1f8f9cc3d956 |
---|---|
11 local iprint = B.print('Info') | 11 local iprint = B.print('Info') |
12 local Bonus = T.Bonus | 12 local Bonus = T.Bonus |
13 | 13 |
14 local UnitName, GetRealmName, GetQuestObjectiveInfo, GetTasksTable, GetTaskInfo = UnitName, GetRealmName, GetQuestObjectiveInfo, GetTasksTable, GetTaskInfo | 14 local UnitName, GetRealmName, GetQuestObjectiveInfo, GetTasksTable, GetTaskInfo = UnitName, GetRealmName, GetQuestObjectiveInfo, GetTasksTable, GetTaskInfo |
15 local GetMapNameByID, GetCurrentMapAreaID = GetMapNameByID, GetCurrentMapAreaID | 15 local GetMapNameByID, GetCurrentMapAreaID = GetMapNameByID, GetCurrentMapAreaID |
16 local tinsert, ipairs, pairs, tostring = tinsert, ipairs, pairs, tostring | 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 STICKY_TASKS = true | 18 local TASK_DISPLAY_TEST = 1 -- 1: normal (is nearby or on the map) 2: strict (is nearby) 3: data exists |
19 | 19 |
20 --- Returns a tasks table modified to include recently completed objectives | 20 --- Returns a tasks table modified to include recently completed objectives |
21 local InternalGetTasksTable = function() | 21 local InternalGetTasksTable = function() |
22 local print = Bonus.print | |
22 local savedTasks = T.Conf.TasksLog | 23 local savedTasks = T.Conf.TasksLog |
23 local char = UnitName("player") | 24 local char = UnitName("player") |
24 local realm = GetRealmName() | 25 local realm = GetRealmName() |
25 local tasks = GetTasksTable() | 26 local tasks = GetTasksTable() |
26 | 27 |
27 for questID, data in pairs(Bonus.Info) do | 28 for questID, data in pairs(Bonus.Info) do |
28 | 29 print('GetTasksTable', questID, #data.objectives) |
29 print(' -- questID:', questID, #data.objectives) | |
30 for i, o in ipairs(data.objectives) do | 30 for i, o in ipairs(data.objectives) do |
31 print(' --', i, o.text) | 31 print('GetTasksTable', questID, i, o.text) |
32 end | 32 end |
33 | 33 end |
34 end | |
35 | |
36 | 34 |
37 for questID, data in pairs(savedTasks) do | 35 for questID, data in pairs(savedTasks) do |
38 if questID > 0 then | 36 if questID > 0 then |
39 local found = false | 37 local found = false |
40 for i = 1, #tasks do | 38 for i = 1, #tasks do |
83 Bonus.Completed = {} | 81 Bonus.Completed = {} |
84 Bonus.POI = {} | 82 Bonus.POI = {} |
85 Bonus.Scenario = {} | 83 Bonus.Scenario = {} |
86 Bonus.QuestBlock = {} | 84 Bonus.QuestBlock = {} |
87 Bonus.WatchInfo = {} | 85 Bonus.WatchInfo = {} |
86 | |
87 local function CanShowTask(isInArea, isOnMap, existingTask, numObjectives) | |
88 if TASK_DISPLAY_TEST == 1 then | |
89 return (isInArea) | |
90 elseif TASK_DISPLAY_TEST == 2 then | |
91 return (isInArea and(isOnMap and existingTask)) | |
92 elseif TASK_DISPLAY_TEST == 3 then | |
93 return true | |
94 end | |
95 end | |
96 | |
88 function Bonus:GetNumWatched () | 97 function Bonus:GetNumWatched () |
89 if true then return 0, 0, nil end | 98 |
90 local print = iprint | 99 local print = self.print |
91 print(self.name, self) | 100 print(self.name, self) |
92 | 101 |
93 local tasks = InternalGetTasksTable() | 102 local tasks = InternalGetTasksTable() |
94 local numWatched = 0 | 103 local numWatched = 0 |
95 local numAll = 0 | 104 local numAll = 0 |
96 local existingTasks = {} | 105 local existingTasks = {} |
97 self.WatchInfo = {} | 106 wipe(self.WatchList) |
98 print('|cFFFFFF00Bonus.GetNumWatched()|r', #tasks) | 107 print('|cFF'..self.internalColor..'Bonus.GetNumWatched()|r', #tasks) |
99 print(' |cFF00FFFFInternalGetTaskInfo|r:') | 108 print('InternalGetTaskInfo') |
109 | |
100 for i, questID in ipairs(tasks) do | 110 for i, questID in ipairs(tasks) do |
101 local isInArea, isOnMap, numObjectives = InternalGetTaskInfo(questID) | 111 local isInArea, isOnMap, numObjectives = InternalGetTaskInfo(questID) |
102 local existingTask = self.QuestBlock[questID] | 112 local existingTask = self.InfoBlock[questID] |
103 local displayObjectiveHeader = false; | 113 local displayObjectiveHeader = false; |
104 local test = (isInArea or (isOnMap and existingTask)) | 114 if CanShowTask(isInArea, isOnMap, existingTask) then |
105 --local test = true | 115 print('TaskInfo', '|cFF00FF00showable objective list', questID) |
106 if test then | |
107 self.Info[questID] = self.Info[questID] or {} | 116 self.Info[questID] = self.Info[questID] or {} |
108 | 117 |
109 local t = self.Info[questID] | 118 local t = self.Info[questID] |
110 if (isOnMap or isInArea) and existingTask then | 119 if (isOnMap or isInArea) and existingTask then |
111 t.areaID = GetCurrentMapAreaID() | 120 t.areaID = GetCurrentMapAreaID() |
112 local _ | 121 local _ |
113 t.mapName, _, _, t.isMicroDungeon, t.microDungeonMapName = GetMapInfo() | 122 t.mapName, _, _, t.isMicroDungeon, t.microDungeonMapName = GetMapInfo() |
114 print('|cFF00FF00scooping map info (questID '..questID..'):|r', t.areaID, t.mapName) | 123 print('InternalGetTaskInfo', 'map data', t.areaID, t.mapName) |
115 end | 124 end |
116 | 125 |
117 local taskTitle | 126 local taskTitle |
127 t.id = questID | |
118 t.objectives = {} | 128 t.objectives = {} |
119 local taskFinished = true; | 129 local taskFinished = true; |
120 for objectiveIndex = 1, numObjectives do | 130 for objectiveIndex = 1, numObjectives do |
121 local text, objectiveType, finished, displayAsObjective = InternalGetQuestObjectiveInfo(questID, objectiveIndex, false); | 131 local text, objectiveType, finished, displayAsObjective = InternalGetQuestObjectiveInfo(questID, objectiveIndex, false); |
122 displayObjectiveHeader = displayObjectiveHeader or displayAsObjective; | 132 displayObjectiveHeader = displayObjectiveHeader or displayAsObjective; |
126 text = '' | 136 text = '' |
127 end | 137 end |
128 end | 138 end |
129 | 139 |
130 | 140 |
131 print(' --', text, objectiveType, finished, displayAsObjective) | 141 print('TaskObjective', text, objectiveType, finished, displayAsObjective) |
132 t.objectives[objectiveIndex] = t.objectives[objectiveIndex] or {} | 142 t.objectives[objectiveIndex] = t.objectives[objectiveIndex] or {} |
133 local o = t.objectives[objectiveIndex] | 143 local o = t.objectives[objectiveIndex] |
134 | 144 |
135 o.index = objectiveIndex | 145 o.index = objectiveIndex |
136 o.text = text | 146 o.text = text |
153 t.existingTask = existingTask | 163 t.existingTask = existingTask |
154 t.questID = questID | 164 t.questID = questID |
155 t.id = questID | 165 t.id = questID |
156 t.taskIndex = i | 166 t.taskIndex = i |
157 t.title = taskTitle | 167 t.title = taskTitle |
158 self.WatchInfo[i] = t | 168 self.WatchList[i] = t |
159 end | 169 elseif existingTask then |
160 | 170 print('TaskInfo', '|cFFFF4400hideable task', questID) |
161 print (' |cFF00FF88#', i, 'questID', questID, 'inArea', isInArea, 'onMap', isOnMap, 'existing', (existingTask and 'Y' or 'N'), (test and '|cFF00FF00show|r' or '|cFFFF0088hide|r')) | 171 existingTask:Hide() |
162 end | 172 end |
163 | 173 |
164 for i = 1, #self.usedBlocks do | 174 print ('TaskInfo', i, 'questID', questID, 'inArea', isInArea, 'onMap', isOnMap, 'existing', (existingTask and 'Y' or 'N'), (test and '|cFF00FF00show|r' or '|cFFFF0088hide|r')) |
165 self.usedBlocks[i]:Hide() | 175 end |
166 end | 176 |
167 | 177 |
168 | 178 self.numWatched = #self.WatchList |
169 self.numAll = #tasks | 179 self.numAll = #existingTasks |
170 self.numWatched = #self.WatchInfo | 180 return self.numWatched, self.numWatched, self.WatchList |
171 print(' stats:', self.numAll, 'active tasks,', self.numWatched, 'nearby or animating') | |
172 --return #tasks | |
173 return #self.WatchInfo | |
174 end | 181 end |
175 | 182 |
176 --- info cleanup done when turn-ins are detected | 183 --- info cleanup done when turn-ins are detected |
177 Bonus.OnTurnIn = function(self, block, questID, xp, money) | 184 Bonus.OnTurnIn = function(self, block, questID, xp, money) |
185 --[=[ | |
178 local info = self.Info[questID] | 186 local info = self.Info[questID] |
179 if info.rewardInfo and #info.rewardInfo >= 1 then | 187 if info.rewardInfo and #info.rewardInfo >= 1 then |
180 for i, reward in ipairs(info.rewardInfo) do | 188 for i, reward in ipairs(info.rewardInfo) do |
181 --[[ | 189 --[[ |
182 type = 'item', | 190 type = 'item', |
216 for o, j in ipairs(savedTasks[questID].objectives) do | 224 for o, j in ipairs(savedTasks[questID].objectives) do |
217 print(' |cFF00FFFF#'.. o ..'|r', j.type, j.finished) | 225 print(' |cFF00FFFF#'.. o ..'|r', j.type, j.finished) |
218 end | 226 end |
219 | 227 |
220 print('adding', info.title, 'to cache') | 228 print('adding', info.title, 'to cache') |
229 --]=] | |
221 end | 230 end |
222 | 231 |
223 Bonus.GetInfo = function(self, taskIndex) | 232 Bonus.GetInfo = function(self, taskIndex) |
224 print(self.name, self) | 233 print(self.name, self) |
225 return self.WatchInfo[taskIndex] | 234 return self.WatchInfo[taskIndex] |
226 end | 235 end |
227 | 236 |
228 | 237 |
229 | 238 |
230 --- Update hooks | 239 --- Update hooks |
231 Bonus.UpdateObjectives = function(handler, block) | 240 Bonus.UpdateObjectives = function(handler, block, blockSchema) |
241 block.schema = blockSchema or 'default' | |
242 local info = block.info | |
243 block.title:SetText(info.title) | |
244 | |
245 | |
232 Default.UpdateObjectives(handler, block) | 246 Default.UpdateObjectives(handler, block) |
233 return 'default' | 247 return blockSchema |
234 end | 248 end |
235 | 249 |
236 Bonus.UpdateLine = function(handler, block, line, data) | 250 Bonus.UpdateLine = function(handler, block, data) |
237 local info = block.info | 251 local info = block.info |
238 local print = lprint | 252 local print = lprint |
239 local text, attachment = '', nil | 253 local text, attachment = '', nil |
240 line.displayColor = 'FFFFFF' | |
241 if data.type == 'progressbar' then | 254 if data.type == 'progressbar' then |
242 print(' |cFFFF44DDpercent='..tostring(GetQuestProgressBarPercent(info.questID))) | 255 print(' |cFFFF44DDpercent='..tostring(GetQuestProgressBarPercent(info.questID))) |
243 local percent = 100 | 256 local percent = 100 |
244 attachment = T.SetWidget(line, data, 'ProgressBar', info.questID..'-'..data.index) | 257 attachment = T.GetWidget(data, 'StatusBar', info.questID..'-'..data.index) |
258 attachment:SetParent(block) | |
259 | |
245 if not data.finished then | 260 if not data.finished then |
246 percent = GetQuestProgressBarPercent(info.questID) | 261 percent = GetQuestProgressBarPercent(info.questID) |
247 end | 262 end |
248 data.value = percent | 263 data.value = percent |
249 data.maxValue = 100 | 264 data.maxValue = 100 |
254 end | 269 end |
255 | 270 |
256 | 271 |
257 attachment.value = percent | 272 attachment.value = percent |
258 attachment.maxValue = 100 | 273 attachment.maxValue = 100 |
259 attachment:SetPoint('TOP', line, 'TOP', 0, 0) | |
260 attachment.status:SetFormattedText(PERCENTAGE_STRING, percent) | 274 attachment.status:SetFormattedText(PERCENTAGE_STRING, percent) |
261 attachment:SetParent(handler.frame) | 275 --attachment:SetParent(handler.frame) |
262 print(attachment.status:GetText()) | 276 --print(attachment.status:GetText()) |
263 print(' |cFFFF0022** text:|r', data.text, '|cFFFF0022value:|r', data.value, '|cFFFF0022max:|r', data.maxValue) | 277 print(' |cFFFF0022** text:|r', data.text, '|cFFFF0022value:|r', data.value, '|cFFFF0022max:|r', data.maxValue) |
264 end | 278 end |
265 text = data.text | 279 text = data.text |
266 return text, attachment | 280 return text, attachment, 'default' |
267 end | 281 end |
268 | 282 |
269 Bonus.Select = function(handler, block) | 283 Bonus.Select = function(handler, block) |
270 print(handler, block) | 284 print(handler, block) |
271 handler:OnTurnIn(block, block.info.questID) | 285 handler:OnTurnIn(block, block.info.questID) |