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