annotate ObjectiveTracker/BonusObjectives.lua @ 32:a3afe6c3771e

- organize and display reward icons as a background hint - centralize reward data function
author Nenue
date Fri, 15 Apr 2016 07:01:40 -0400
parents 48b3e3959a0a
children 64f2a9bbea79
rev   line source
Nenue@27 1 --- ${PACKAGE_NAME}
Nenue@27 2 -- @file-author@
Nenue@27 3 -- @project-revision@ @project-hash@
Nenue@27 4 -- @file-revision@ @file-hash@
Nenue@27 5 -- Created: 4/13/2016 7:48 PM
Nenue@27 6 local B = select(2,...).frame
Nenue@27 7 local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame')
Nenue@27 8 local Default, Quest = T.DefaultHandler, T.Quest
Nenue@27 9 local print = B.print('Tracker')
Nenue@27 10 local lprint = B.print('Line')
Nenue@29 11 local Bonus = T.Bonus
Nenue@27 12
Nenue@29 13 local UnitName, GetRealmName, GetQuestObjectiveInfo, GetTasksTable, GetTaskInfo = UnitName, GetRealmName, GetQuestObjectiveInfo, GetTasksTable, GetTaskInfo
Nenue@29 14 local GetMapNameByID, GetCurrentMapAreaID = GetMapNameByID, GetCurrentMapAreaID
Nenue@29 15 local tinsert, ipairs, pairs, tostring = tinsert, ipairs, pairs, tostring
Nenue@29 16 local GetNumQuestLogRewardCurrencies, GetQuestLogRewardCurrencyInfo = GetNumQuestLogRewardCurrencies, GetQuestLogRewardCurrencyInfo
Nenue@29 17 local GetNumQuestLogRewards, GetQuestLogRewardInfo = GetNumQuestLogRewards, GetQuestLogRewardInfo
Nenue@29 18 local GetQuestLogRewardMoney, GetMoneyString = GetQuestLogRewardMoney, GetMoneyString
Nenue@29 19 local GetQuestProgressBarPercent, PERCENTAGE_STRING, GetTime = GetQuestProgressBarPercent, PERCENTAGE_STRING, GetTime
Nenue@27 20
Nenue@29 21
Nenue@29 22 --- Returns a tasks table modified to include recently completed objectives
Nenue@29 23 local InternalGetTasksTable = function()
Nenue@29 24 local savedTasks = T.Conf.TasksLog
Nenue@29 25 local char = UnitName("player")
Nenue@29 26 local realm = GetRealmName()
Nenue@29 27 local tasks = GetTasksTable()
Nenue@29 28
Nenue@29 29 for questID, data in pairs(Bonus.Info) do
Nenue@29 30
Nenue@29 31 print(' -- questID:', questID, #data.objectives)
Nenue@29 32 for i, o in ipairs(data.objectives) do
Nenue@29 33 print(' --', i, o.text)
Nenue@29 34 end
Nenue@29 35
Nenue@29 36 end
Nenue@29 37
Nenue@29 38
Nenue@29 39 for questID, data in pairs(savedTasks) do
Nenue@29 40 if questID > 0 then
Nenue@29 41 local found = false
Nenue@29 42 for i = 1, #tasks do
Nenue@29 43 if tasks[i] == questID then
Nenue@29 44 found = true
Nenue@29 45 break
Nenue@29 46 end
Nenue@29 47 end
Nenue@29 48 -- if it's not part of the current table, then try to insert it where it was last found
Nenue@29 49 if not found then
Nenue@29 50 if data.watchIndex < #tasks then
Nenue@29 51 tinsert(tasks, data.watchIndex, data)
Nenue@29 52 else
Nenue@29 53 tinsert(tasks, data)
Nenue@29 54 end
Nenue@29 55 end
Nenue@29 56 end
Nenue@29 57 end
Nenue@29 58 return tasks
Nenue@29 59 end
Nenue@29 60
Nenue@29 61 --- Returns an entry from the composed tasks table if possible, otherwise makes an API pull
Nenue@29 62 local InternalGetTaskInfo = function(questID)
Nenue@29 63 local completedTasks = T.Conf.TasksLog
Nenue@29 64 if completedTasks[questID] then
Nenue@29 65 return true, true, #completedTasks[questID].objectives
Nenue@29 66 else
Nenue@29 67 return GetTaskInfo(questID)
Nenue@29 68 end
Nenue@29 69 end
Nenue@29 70
Nenue@29 71 --- Same as above but for the objective entries
Nenue@29 72 local InternalGetQuestObjectiveInfo = function(questID, objectiveIndex)
Nenue@29 73 local completedTasks = T.Conf.TasksLog
Nenue@29 74 if ( completedTasks[questID] ) then
Nenue@29 75 print('using internal data')
Nenue@29 76 return completedTasks[questID].objectives[objectiveIndex], completedTasks[questID].objectiveType, true;
Nenue@29 77 else
Nenue@29 78 return GetQuestObjectiveInfo(questID, objectiveIndex, false);
Nenue@29 79 end
Nenue@29 80 end
Nenue@29 81
Nenue@29 82 --- end redundant copy of silliness
Nenue@29 83 ------------------------------------------------------------------------------------------
Nenue@29 84
Nenue@29 85 Bonus.Completed = {}
Nenue@29 86 Bonus.POI = {}
Nenue@29 87 Bonus.Scenario = {}
Nenue@29 88 Bonus.QuestBlock = {}
Nenue@29 89 Bonus.WatchInfo = {}
Nenue@29 90 function Bonus:GetNumWatched ()
Nenue@29 91 print(self.name, self)
Nenue@29 92
Nenue@29 93 local tasks = InternalGetTasksTable()
Nenue@29 94 local numWatched = 0
Nenue@29 95 local numAll = 0
Nenue@29 96 self.WatchInfo = {}
Nenue@29 97 print('|cFFFFFF00Bonus.GetNumWatched()|r', #tasks)
Nenue@29 98 print(' TasksTable pull:')
Nenue@29 99 for i, questID in ipairs(tasks) do
Nenue@29 100 local isInArea, isOnMap, numObjectives = InternalGetTaskInfo(questID)
Nenue@29 101 local existingTask = self.QuestBlock[questID]
Nenue@29 102 local displayObjectiveHeader = false;
Nenue@29 103 local test = (isInArea or (isOnMap and existingTask))
Nenue@29 104 --local test = true
Nenue@29 105 if test then
Nenue@29 106 self.Info[questID] = self.Info[questID] or {}
Nenue@29 107
Nenue@29 108 local t = self.Info[questID]
Nenue@29 109 self.WatchInfo[i] = t
Nenue@29 110 t.isInArea = isInArea
Nenue@29 111 t.isOnMap = isOnMap
Nenue@29 112 t.existingTask = existingTask
Nenue@29 113 t.questID = questID
Nenue@30 114 t.id = questID
Nenue@29 115 t.objectives = {}
Nenue@29 116 t.taskIndex = i
Nenue@29 117
Nenue@29 118
Nenue@32 119 T.SetRewards(t, questID)
Nenue@29 120
Nenue@29 121 local taskTitle
Nenue@29 122 local taskFinished = true;
Nenue@29 123 for objectiveIndex = 1, numObjectives do
Nenue@29 124 local text, objectiveType, finished, displayAsObjective = InternalGetQuestObjectiveInfo(questID, objectiveIndex, false);
Nenue@29 125 displayObjectiveHeader = displayObjectiveHeader or displayAsObjective;
Nenue@29 126 if not taskTitle then
Nenue@29 127 if objectiveType == 'progressbar' and not text:match('^%d%+\\%d+') then
Nenue@29 128 taskTitle = text
Nenue@29 129 text = ''
Nenue@29 130 end
Nenue@29 131 end
Nenue@29 132
Nenue@29 133
Nenue@29 134 print(' --', text, objectiveType, finished, displayAsObjective)
Nenue@29 135 t.objectives[objectiveIndex] = t.objectives[objectiveIndex] or {}
Nenue@29 136 local o = t.objectives[objectiveIndex]
Nenue@29 137
Nenue@29 138 o.objectiveIndex = objectiveIndex
Nenue@29 139 o.text = text
Nenue@29 140 o.objectiveType = objectiveType
Nenue@29 141 o.finished = finished
Nenue@29 142 o.displayAsObjective = displayAsObjective
Nenue@29 143 print(' |cFF00FF88*', objectiveIndex, text)
Nenue@29 144 end
Nenue@29 145
Nenue@29 146 -- didn't get a name from progress bar? what about area name
Nenue@29 147 if not taskTitle then
Nenue@29 148 if isInArea then
Nenue@29 149 taskTitle = GetMapNameByID(GetCurrentMapAreaID())
Nenue@29 150 end
Nenue@29 151 end
Nenue@29 152 t.title = taskTitle
Nenue@29 153 end
Nenue@29 154
Nenue@29 155 print (' |cFF00FF88#', i, 'questID', questID, 'inArea', isInArea, 'onMap', isOnMap, 'existing', (existingTask and 'Y' or 'N'), (test and '|cFF00FF00show|r' or '|cFFFF0088hide|r'))
Nenue@29 156 end
Nenue@29 157
Nenue@29 158
Nenue@29 159 self.numAll = #tasks
Nenue@29 160 self.numWatched = #self.WatchInfo
Nenue@29 161 print(' stats:', self.numAll, 'active tasks,', self.numWatched, 'nearby or animating')
Nenue@29 162 --return #tasks
Nenue@29 163 return #self.WatchInfo
Nenue@29 164 end
Nenue@29 165
Nenue@29 166 --- info cleanup done when turn-ins are detected
Nenue@29 167 Bonus.OnTurnIn = function(self, questID, xp, money)
Nenue@29 168
Nenue@29 169 if #self.info.rewardInfo >= 1 then
Nenue@29 170 for i, reward in ipairs(self.info.rewardInfo) do
Nenue@29 171 --[[
Nenue@29 172 type = 'item',
Nenue@29 173 index = i ,
Nenue@29 174 name = name,
Nenue@29 175 texture = texture,
Nenue@29 176 count = count,
Nenue@29 177 quality = quality,
Nenue@29 178 isUsable = isUsable
Nenue@29 179 ]]
Nenue@29 180 print(' reward ', i, ' ', reward.type, reward.name, reward.count)
Nenue@29 181
Nenue@29 182 end
Nenue@29 183 end
Nenue@29 184
Nenue@29 185 print('|cFFFF8800'..self.name..':OnTurnIn call', questID, xp, money)
Nenue@29 186 local savedTasks = B.Conf.TasksLog
Nenue@29 187
Nenue@29 188 self.Info[questID].completedTime = GetTime()
Nenue@29 189 self.Info[questID].animate = true
Nenue@29 190 T.SetAnimate(self.watchReasonModule)
Nenue@29 191 savedTasks[questID] = self.Info[questID]
Nenue@29 192 end
Nenue@29 193
Nenue@29 194 Bonus.GetInfo = function(self, taskIndex)
Nenue@29 195 print(self.name, self)
Nenue@29 196 return self.WatchInfo[taskIndex]
Nenue@29 197 end
Nenue@29 198
Nenue@29 199
Nenue@29 200
Nenue@29 201 --- Update hooks
Nenue@27 202 Bonus.UpdateObjectives = function(handler, block)
Nenue@27 203 Default.UpdateObjectives(handler, block)
Nenue@27 204 end
Nenue@27 205
Nenue@31 206 Bonus.UpdateLine = function(handler, objectiveType, line, data)
Nenue@27 207 local info = block.info
Nenue@27 208 local print = lprint
Nenue@31 209 local text, attachment = '', nil
Nenue@27 210 line.displayColor = 'FFFFFF'
Nenue@27 211 print(' ', data.objectiveIndex,'|cFFFF0088-|r', data.objectiveType, data.text)
Nenue@27 212 if data.objectiveType == 'progressbar' then
Nenue@27 213 print(' |cFFFF44DDpercent='..tostring(GetQuestProgressBarPercent(info.questID)))
Nenue@27 214 data.value = GetQuestProgressBarPercent(info.questID) or 0
Nenue@27 215 data.maxValue = 100
Nenue@31 216 attachment = T.SetWidget(line, data, 'ProgressBar', info.questID..'-'..data.objectiveIndex)
Nenue@31 217 attachment:SetPoint('TOP', line, 'TOP', 0, 0)
Nenue@31 218 attachment.status:SetFormattedText(PERCENTAGE_STRING, (data.value / data.maxValue))
Nenue@27 219 print(' |cFFFF0022** text:|r', data.text, '|cFFFF0022value:|r', data.value, '|cFFFF0022max:|r', data.maxValue)
Nenue@27 220 else
Nenue@31 221 text = data.text
Nenue@27 222 end
Nenue@31 223 return text, attachment
Nenue@27 224 end
Nenue@27 225
Nenue@27 226 Bonus.Select = function(self)
Nenue@27 227 Bonus:OnTurnIn(self.info.questID)
Nenue@27 228 end
Nenue@27 229 Bonus.Remove = function(self)
Nenue@27 230
Nenue@27 231 end