Mercurial > wow > buffalo2
comparison ObjectiveTracker/BonusObjectives.lua @ 33:64f2a9bbea79
- implementing structural revisions in bonus objectives
- prevent instances of nil arithmetic
- decide on where to keep style values
- start widgets with dummy values for operability
| author | Nenue |
|---|---|
| date | Fri, 15 Apr 2016 17:01:06 -0400 |
| parents | a3afe6c3771e |
| children | 9856ebc63fa4 |
comparison
equal
deleted
inserted
replaced
| 32:a3afe6c3771e | 33:64f2a9bbea79 |
|---|---|
| 6 local B = select(2,...).frame | 6 local B = select(2,...).frame |
| 7 local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame') | 7 local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame') |
| 8 local Default, Quest = T.DefaultHandler, T.Quest | 8 local Default, Quest = T.DefaultHandler, T.Quest |
| 9 local print = B.print('Tracker') | 9 local print = B.print('Tracker') |
| 10 local lprint = B.print('Line') | 10 local lprint = B.print('Line') |
| 11 local iprint = B.print('Info') | |
| 11 local Bonus = T.Bonus | 12 local Bonus = T.Bonus |
| 12 | 13 |
| 13 local UnitName, GetRealmName, GetQuestObjectiveInfo, GetTasksTable, GetTaskInfo = UnitName, GetRealmName, GetQuestObjectiveInfo, GetTasksTable, GetTaskInfo | 14 local UnitName, GetRealmName, GetQuestObjectiveInfo, GetTasksTable, GetTaskInfo = UnitName, GetRealmName, GetQuestObjectiveInfo, GetTasksTable, GetTaskInfo |
| 14 local GetMapNameByID, GetCurrentMapAreaID = GetMapNameByID, GetCurrentMapAreaID | 15 local GetMapNameByID, GetCurrentMapAreaID = GetMapNameByID, GetCurrentMapAreaID |
| 15 local tinsert, ipairs, pairs, tostring = tinsert, ipairs, pairs, tostring | 16 local tinsert, ipairs, pairs, tostring = tinsert, ipairs, pairs, tostring |
| 16 local GetNumQuestLogRewardCurrencies, GetQuestLogRewardCurrencyInfo = GetNumQuestLogRewardCurrencies, GetQuestLogRewardCurrencyInfo | |
| 17 local GetNumQuestLogRewards, GetQuestLogRewardInfo = GetNumQuestLogRewards, GetQuestLogRewardInfo | |
| 18 local GetQuestLogRewardMoney, GetMoneyString = GetQuestLogRewardMoney, GetMoneyString | |
| 19 local GetQuestProgressBarPercent, PERCENTAGE_STRING, GetTime = GetQuestProgressBarPercent, PERCENTAGE_STRING, GetTime | 17 local GetQuestProgressBarPercent, PERCENTAGE_STRING, GetTime = GetQuestProgressBarPercent, PERCENTAGE_STRING, GetTime |
| 20 | 18 local STICKY_TASKS = true |
| 21 | 19 |
| 22 --- Returns a tasks table modified to include recently completed objectives | 20 --- Returns a tasks table modified to include recently completed objectives |
| 23 local InternalGetTasksTable = function() | 21 local InternalGetTasksTable = function() |
| 24 local savedTasks = T.Conf.TasksLog | 22 local savedTasks = T.Conf.TasksLog |
| 25 local char = UnitName("player") | 23 local char = UnitName("player") |
| 86 Bonus.POI = {} | 84 Bonus.POI = {} |
| 87 Bonus.Scenario = {} | 85 Bonus.Scenario = {} |
| 88 Bonus.QuestBlock = {} | 86 Bonus.QuestBlock = {} |
| 89 Bonus.WatchInfo = {} | 87 Bonus.WatchInfo = {} |
| 90 function Bonus:GetNumWatched () | 88 function Bonus:GetNumWatched () |
| 89 local print = iprint | |
| 91 print(self.name, self) | 90 print(self.name, self) |
| 92 | 91 |
| 93 local tasks = InternalGetTasksTable() | 92 local tasks = InternalGetTasksTable() |
| 94 local numWatched = 0 | 93 local numWatched = 0 |
| 95 local numAll = 0 | 94 local numAll = 0 |
| 95 local existingTasks = {} | |
| 96 self.WatchInfo = {} | 96 self.WatchInfo = {} |
| 97 print('|cFFFFFF00Bonus.GetNumWatched()|r', #tasks) | 97 print('|cFFFFFF00Bonus.GetNumWatched()|r', #tasks) |
| 98 print(' TasksTable pull:') | 98 print(' TasksTable pull:') |
| 99 for i, questID in ipairs(tasks) do | 99 for i, questID in ipairs(tasks) do |
| 100 local isInArea, isOnMap, numObjectives = InternalGetTaskInfo(questID) | 100 local isInArea, isOnMap, numObjectives = InternalGetTaskInfo(questID) |
| 104 --local test = true | 104 --local test = true |
| 105 if test then | 105 if test then |
| 106 self.Info[questID] = self.Info[questID] or {} | 106 self.Info[questID] = self.Info[questID] or {} |
| 107 | 107 |
| 108 local t = self.Info[questID] | 108 local t = self.Info[questID] |
| 109 self.WatchInfo[i] = t | 109 if (isOnMap or isInArea) and existingTask then |
| 110 t.isInArea = isInArea | 110 t.areaID = GetCurrentMapAreaID() |
| 111 t.isOnMap = isOnMap | 111 local _ |
| 112 t.existingTask = existingTask | 112 t.mapName, _, _, t.isMicroDungeon, t.microDungeonMapName = GetMapInfo() |
| 113 t.questID = questID | 113 print('|cFF00FF00scooping map info (questID '..questID..'):|r', t.areaID, t.mapName) |
| 114 t.id = questID | 114 end |
| 115 | |
| 116 local taskTitle | |
| 115 t.objectives = {} | 117 t.objectives = {} |
| 116 t.taskIndex = i | |
| 117 | |
| 118 | |
| 119 T.SetRewards(t, questID) | |
| 120 | |
| 121 local taskTitle | |
| 122 local taskFinished = true; | 118 local taskFinished = true; |
| 123 for objectiveIndex = 1, numObjectives do | 119 for objectiveIndex = 1, numObjectives do |
| 124 local text, objectiveType, finished, displayAsObjective = InternalGetQuestObjectiveInfo(questID, objectiveIndex, false); | 120 local text, objectiveType, finished, displayAsObjective = InternalGetQuestObjectiveInfo(questID, objectiveIndex, false); |
| 125 displayObjectiveHeader = displayObjectiveHeader or displayAsObjective; | 121 displayObjectiveHeader = displayObjectiveHeader or displayAsObjective; |
| 126 if not taskTitle then | 122 if not taskTitle then |
| 141 o.finished = finished | 137 o.finished = finished |
| 142 o.displayAsObjective = displayAsObjective | 138 o.displayAsObjective = displayAsObjective |
| 143 print(' |cFF00FF88*', objectiveIndex, text) | 139 print(' |cFF00FF88*', objectiveIndex, text) |
| 144 end | 140 end |
| 145 | 141 |
| 142 T.SetRewards(t, questID) | |
| 143 | |
| 146 -- didn't get a name from progress bar? what about area name | 144 -- didn't get a name from progress bar? what about area name |
| 147 if not taskTitle then | 145 if not taskTitle then |
| 148 if isInArea then | 146 if isInArea then |
| 149 taskTitle = GetMapNameByID(GetCurrentMapAreaID()) | 147 taskTitle = GetMapNameByID(GetCurrentMapAreaID()) |
| 150 end | 148 end |
| 151 end | 149 end |
| 150 | |
| 151 t.isInArea = isInArea | |
| 152 t.isOnMap = isOnMap | |
| 153 t.existingTask = existingTask | |
| 154 t.questID = questID | |
| 155 t.id = questID | |
| 156 t.taskIndex = i | |
| 152 t.title = taskTitle | 157 t.title = taskTitle |
| 158 self.WatchInfo[i] = t | |
| 153 end | 159 end |
| 154 | 160 |
| 155 print (' |cFF00FF88#', i, 'questID', questID, 'inArea', isInArea, 'onMap', isOnMap, 'existing', (existingTask and 'Y' or 'N'), (test and '|cFF00FF00show|r' or '|cFFFF0088hide|r')) | 161 print (' |cFF00FF88#', i, 'questID', questID, 'inArea', isInArea, 'onMap', isOnMap, 'existing', (existingTask and 'Y' or 'N'), (test and '|cFF00FF00show|r' or '|cFFFF0088hide|r')) |
| 156 end | 162 end |
| 157 | 163 |
| 162 --return #tasks | 168 --return #tasks |
| 163 return #self.WatchInfo | 169 return #self.WatchInfo |
| 164 end | 170 end |
| 165 | 171 |
| 166 --- info cleanup done when turn-ins are detected | 172 --- info cleanup done when turn-ins are detected |
| 167 Bonus.OnTurnIn = function(self, questID, xp, money) | 173 Bonus.OnTurnIn = function(self, block, questID, xp, money) |
| 168 | 174 local info = self.Info[questID] |
| 169 if #self.info.rewardInfo >= 1 then | 175 if info.rewardInfo and #info.rewardInfo >= 1 then |
| 170 for i, reward in ipairs(self.info.rewardInfo) do | 176 for i, reward in ipairs(info.rewardInfo) do |
| 171 --[[ | 177 --[[ |
| 172 type = 'item', | 178 type = 'item', |
| 173 index = i , | 179 index = i , |
| 174 name = name, | 180 name = name, |
| 175 texture = texture, | 181 texture = texture, |
| 180 print(' reward ', i, ' ', reward.type, reward.name, reward.count) | 186 print(' reward ', i, ' ', reward.type, reward.name, reward.count) |
| 181 | 187 |
| 182 end | 188 end |
| 183 end | 189 end |
| 184 | 190 |
| 185 print('|cFFFF8800'..self.name..':OnTurnIn call', questID, xp, money) | 191 print('|cFFFF8800'..block.name..':OnTurnIn call', questID, xp, money) |
| 186 local savedTasks = B.Conf.TasksLog | 192 local savedTasks = B.Conf.TasksLog |
| 187 | 193 |
| 188 self.Info[questID].completedTime = GetTime() | 194 info.completedTime = GetTime() |
| 189 self.Info[questID].animate = true | 195 info.animate = true |
| 190 T.SetAnimate(self.watchReasonModule) | 196 T.SetAnimate(handler.watchReasonModule) |
| 191 savedTasks[questID] = self.Info[questID] | 197 savedTasks[questID] = info |
| 198 | |
| 199 print('adding', info.title, 'to cache') | |
| 192 end | 200 end |
| 193 | 201 |
| 194 Bonus.GetInfo = function(self, taskIndex) | 202 Bonus.GetInfo = function(self, taskIndex) |
| 195 print(self.name, self) | 203 print(self.name, self) |
| 196 return self.WatchInfo[taskIndex] | 204 return self.WatchInfo[taskIndex] |
| 201 --- Update hooks | 209 --- Update hooks |
| 202 Bonus.UpdateObjectives = function(handler, block) | 210 Bonus.UpdateObjectives = function(handler, block) |
| 203 Default.UpdateObjectives(handler, block) | 211 Default.UpdateObjectives(handler, block) |
| 204 end | 212 end |
| 205 | 213 |
| 206 Bonus.UpdateLine = function(handler, objectiveType, line, data) | 214 Bonus.UpdateLine = function(handler, block, line, data) |
| 207 local info = block.info | 215 local info = block.info |
| 208 local print = lprint | 216 local print = lprint |
| 209 local text, attachment = '', nil | 217 local text, attachment = '', nil |
| 210 line.displayColor = 'FFFFFF' | 218 line.displayColor = 'FFFFFF' |
| 211 print(' ', data.objectiveIndex,'|cFFFF0088-|r', data.objectiveType, data.text) | 219 print(' ', data.objectiveIndex,'|cFFFF0088-|r', data.objectiveType, data.text) |
| 212 if data.objectiveType == 'progressbar' then | 220 if data.objectiveType == 'progressbar' then |
| 213 print(' |cFFFF44DDpercent='..tostring(GetQuestProgressBarPercent(info.questID))) | 221 print(' |cFFFF44DDpercent='..tostring(GetQuestProgressBarPercent(info.questID))) |
| 214 data.value = GetQuestProgressBarPercent(info.questID) or 0 | 222 local percent = 100 |
| 215 data.maxValue = 100 | |
| 216 attachment = T.SetWidget(line, data, 'ProgressBar', info.questID..'-'..data.objectiveIndex) | 223 attachment = T.SetWidget(line, data, 'ProgressBar', info.questID..'-'..data.objectiveIndex) |
| 224 if not data.finished then | |
| 225 percent = GetQuestProgressBarPercent(info.questID) | |
| 226 end | |
| 227 attachment.value = percent | |
| 228 attachment.maxValue = 100 | |
| 217 attachment:SetPoint('TOP', line, 'TOP', 0, 0) | 229 attachment:SetPoint('TOP', line, 'TOP', 0, 0) |
| 218 attachment.status:SetFormattedText(PERCENTAGE_STRING, (data.value / data.maxValue)) | 230 attachment.status:SetFormattedText(PERCENTAGE_STRING, (percent / 100)) |
| 219 print(' |cFFFF0022** text:|r', data.text, '|cFFFF0022value:|r', data.value, '|cFFFF0022max:|r', data.maxValue) | 231 print(' |cFFFF0022** text:|r', data.text, '|cFFFF0022value:|r', data.value, '|cFFFF0022max:|r', data.maxValue) |
| 220 else | 232 else |
| 221 text = data.text | 233 text = data.text |
| 222 end | 234 end |
| 223 return text, attachment | 235 return text, attachment |
| 224 end | 236 end |
| 225 | 237 |
| 226 Bonus.Select = function(self) | 238 Bonus.Select = function(handler, block) |
| 227 Bonus:OnTurnIn(self.info.questID) | 239 print(handler, block) |
| 240 handler:OnTurnIn(block, block.info.questID) | |
| 228 end | 241 end |
| 229 Bonus.Remove = function(self) | 242 Bonus.Remove = function(self) |
| 230 | 243 |
| 231 end | 244 end |
