annotate ObjectiveTracker/QuestTracker.lua @ 24:66b927b46776

Refine the XML data logic, and sort out some EnableMouse inconsistencies.
author Nenue
date Mon, 11 Apr 2016 09:07:40 -0400
parents e837384ac363
children 4b3da1b221de
rev   line source
Nenue@23 1 local B = select(2,...).frame
Nenue@23 2 local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame')
Nenue@23 3 local _G, ipairs, max, min, unpack, floor, pairs, tostring, type, band = _G, ipairs, max, min, unpack, floor, pairs, tostring, type, bit.band
Nenue@23 4 local GetAutoQuestPopUp, GetQuestLogCompletionText = GetAutoQuestPopUp, GetQuestLogCompletionText
Nenue@23 5 local Default, Quest = T.DefaultHandler, T.Quest
Nenue@23 6 local format = format
Nenue@23 7 local print = B.print('Tracker')
Nenue@23 8 local lprint = B.print('Line')
Nenue@24 9 local iprint = B.print('Info')
Nenue@23 10
Nenue@23 11 local colors = T.colors
Nenue@24 12
Nenue@24 13 local tprint = B.print('Tracker')
Nenue@24 14 Quest.Update = function(self, reason, ...)
Nenue@24 15 local print = tprint
Nenue@24 16 print('QuestTracker:Update() received')
Nenue@24 17 T.UpdateActionButtons()
Nenue@24 18 Default.Update(self, reason, ...)
Nenue@24 19 end
Nenue@24 20
Nenue@23 21 Quest.UpdateObjectives = function(handler, block)
Nenue@23 22 local print = lprint
Nenue@23 23 print('|cFF00FFFFUpdateObjectives()')
Nenue@23 24 local info = block.info
Nenue@23 25
Nenue@23 26 local titlebg, textbg = colors.default.titlebg, colors.default.textbg
Nenue@23 27 print((info.isAccount and 'isAccount' or ''), (info.isFaction and 'isFaction' or ''), (info.isDaily and 'isDaily' or ''), (info.isWeekly and 'isWeekly' or ''), info.tagID, info.tagName)
Nenue@23 28
Nenue@23 29 if info.isAccount then
Nenue@23 30 if info.isFaction then
Nenue@23 31 print(' faction', info.tagID)
Nenue@23 32 titlebg, textbg = colors['faction_'..info.tagID].titlebg, colors.default.textbg
Nenue@23 33 else
Nenue@23 34 print(' account', info.isAccount, info.isFaction)
Nenue@23 35 titlebg, textbg = colors.account.titlebg, colors.account.textbg
Nenue@23 36 end
Nenue@23 37 elseif info.isDaily then
Nenue@23 38 print(' daily', info.frequency)
Nenue@23 39 titlebg, textbg = colors.daily.titlebg, colors.daily.textbg
Nenue@23 40 elseif info.isWeekly then
Nenue@23 41 print(' weekly', info.frequency)
Nenue@23 42 titlebg, textbg = colors.weekly.titlebg, colors.weekly.textbg
Nenue@23 43 end
Nenue@23 44
Nenue@23 45 block.titlebg:SetGradientAlpha(unpack(titlebg))
Nenue@23 46 block.statusbg:SetGradientAlpha(unpack(textbg))
Nenue@23 47
Nenue@23 48 local completionText
Nenue@23 49 if info.isAutoComplete then
Nenue@23 50 local questID, popupType = GetAutoQuestPopUp(info.questLogIndex)
Nenue@23 51 if popupType == 'COMPLETE' then
Nenue@23 52 print(' :: auto-complete quest :: set the message')
Nenue@24 53 info.completionText = T.strings.CLICK_TO_COMPLETE
Nenue@23 54 end
Nenue@23 55 end
Nenue@23 56 if info.isComplete then
Nenue@23 57 if not completionText or info.completionText then
Nenue@23 58 info.completionText = GetQuestLogCompletionText(info.questLogIndex)
Nenue@23 59 end
Nenue@23 60 print(' :: complete quest :: show instruction: "'.. tostring(info.completionText) .. '"')
Nenue@23 61 end
Nenue@23 62
Nenue@23 63 Default.UpdateObjectives(handler, block)
Nenue@23 64 end
Nenue@23 65
Nenue@23 66 Quest.UpdateLine = function(handler, block, line, data)
Nenue@23 67 local print = lprint
Nenue@23 68 local objectiveType = data.type
Nenue@23 69 local r, g, b, a = 0, 1, 1, 1
Nenue@23 70
Nenue@23 71 line.progress = 0
Nenue@23 72 if data.finished then
Nenue@23 73 line.progress = 2
Nenue@23 74 r, g, b, a = 0, 1, 0, 1
Nenue@23 75 elseif objectiveType == 'monster' then
Nenue@23 76 r, g, b, a = 1, .55, .2, 1
Nenue@23 77 elseif objectiveType == 'item' then
Nenue@23 78 r, g, b, a = .8, .8, .8, 1
Nenue@23 79 elseif objectiveType == 'object' then
Nenue@23 80 r, g, b, a = 1, 1, 1, 1
Nenue@23 81 elseif objectiveType == 'player' then
Nenue@23 82 r, g, b, a = 0, 0.8, 1, 1
Nenue@23 83 end
Nenue@23 84 print(format(' |cFF%02X%02X%02X%0.1f, %0.1f, %0.1f|r', (r * 255), g * 255, b * 255, r, g, b))
Nenue@23 85
Nenue@23 86 line.displayColor = {r, g, b, a}
Nenue@23 87 line.status:SetTextColor(r, g, b, a)
Nenue@23 88 line.displayText = data.text
Nenue@23 89
Nenue@23 90 return line
Nenue@23 91 end
Nenue@23 92
Nenue@23 93 -----------------------------
Nenue@23 94 --- QUEST
Nenue@23 95 Quest.POI = {}
Nenue@23 96 Quest.QuestBlock = {}
Nenue@23 97 Quest.LogBlock = {}
Nenue@23 98 Quest.LogInfo = {}
Nenue@23 99
Nenue@23 100 function Quest:GetNumWatched ()
Nenue@23 101 print(self.name, self)
Nenue@23 102 self.numAll = GetNumQuestLogEntries()
Nenue@23 103 self.numWatched = GetNumQuestWatches()
Nenue@23 104 return self.numWatched, self.numAll
Nenue@23 105 end
Nenue@23 106 Quest.GetInfo = function (self, watchIndex)
Nenue@24 107 local print = iprint
Nenue@23 108 print('|cFF00DDFFQuest|r.|cFF0088FFGetInfo(|r'.. tostring(watchIndex)..'|r)')
Nenue@24 109 local questID, title, questIndex, numObjectives, requiredMoney, _,
Nenue@24 110 _, isAutoComplete, failureTime, timeElapsed, questType, _, _, _, _ = GetQuestWatchInfo(watchIndex)
Nenue@23 111
Nenue@23 112 if not questIndex then
Nenue@23 113 return
Nenue@23 114 end
Nenue@23 115
Nenue@23 116 local _, level, suggestedGroup, isHeader, isCollapsed, isComplete, frequency, _, startEvent, displayQuestID, isOnMap, hasLocalPOI, isTask, isStory = GetQuestLogTitle(questIndex)
Nenue@23 117
Nenue@23 118
Nenue@23 119 if not questID then
Nenue@23 120 return
Nenue@23 121 end
Nenue@23 122 Quest.Info[questID] = Quest.Info[questID] or {}
Nenue@23 123
Nenue@23 124 local q = Quest.Info[questID]
Nenue@23 125 q.watchIndex = watchIndex
Nenue@23 126 q.type = 'Quest'
Nenue@23 127 q.questID = questID
Nenue@23 128 q.title = title
Nenue@23 129 q.level = level
Nenue@23 130 q.displayQuestID = displayQuestID
Nenue@23 131 q.suggestedGroup = suggestedGroup
Nenue@23 132 q.questLogIndex = questIndex
Nenue@23 133 q.numObjectives = numObjectives
Nenue@23 134 q.requiredMoney = requiredMoney
Nenue@23 135 q.isComplete = isComplete
Nenue@23 136 q.startEvent = startEvent
Nenue@23 137 q.isAutoComplete = isAutoComplete
Nenue@23 138 q.failureTime = failureTime
Nenue@23 139 q.timeElapsed = timeElapsed
Nenue@23 140 q.questType = questType
Nenue@23 141 q.isTask = isTask
Nenue@23 142 q.isStory = isStory
Nenue@23 143 q.isOnMap = isOnMap
Nenue@23 144 q.hasLocalPOI = hasLocalPOI
Nenue@23 145 q.frequency = frequency
Nenue@23 146 q.isComplete = isComplete
Nenue@23 147 q.isStory = isStory
Nenue@23 148 q.isTask = isTask
Nenue@23 149
Nenue@23 150 --- resolve icon type and template
Nenue@23 151 local questTagID, tagName = GetQuestTagInfo(questID)
Nenue@23 152 local tagID
Nenue@23 153
Nenue@23 154 local factionGroup = GetQuestFactionGroup(questID);
Nenue@23 155 if( questTagID and questTagID == QUEST_TAG_ACCOUNT ) then
Nenue@23 156 if( factionGroup ) then
Nenue@23 157 tagID = "ALLIANCE";
Nenue@23 158 if ( factionGroup == LE_QUEST_FACTION_HORDE ) then
Nenue@23 159 tagID = "HORDE";
Nenue@23 160 end
Nenue@23 161 q.isFaction = true
Nenue@23 162 else
Nenue@23 163 tagID = QUEST_TAG_ACCOUNT;
Nenue@23 164 q.isAccount = true
Nenue@23 165 end
Nenue@23 166 q.typeTag = QUEST_TAG_TCOORDS[tagID]
Nenue@23 167 elseif ( factionGroup) then
Nenue@23 168 tagID = "ALLIANCE";
Nenue@23 169 if ( factionGroup == LE_QUEST_FACTION_HORDE ) then
Nenue@23 170 tagID = "HORDE";
Nenue@23 171 end
Nenue@23 172 q.isFaction = true
Nenue@23 173 end
Nenue@23 174
Nenue@23 175 if( frequency == LE_QUEST_FREQUENCY_DAILY and (not isComplete or isComplete == 0) ) then
Nenue@23 176 tagID = "DAILY";
Nenue@23 177 q.frequencyTag = QUEST_TAG_TCOORDS["DAILY"]
Nenue@23 178 q.isDaily = true
Nenue@23 179 elseif( frequency == LE_QUEST_FREQUENCY_WEEKLY and (not isComplete or isComplete == 0) )then
Nenue@23 180 tagID = "WEEKLY";
Nenue@23 181 q.frequencyTag = QUEST_TAG_TCOORDS["WEEKLY"]
Nenue@23 182 q.isWeekly = true
Nenue@23 183 elseif( questTagID ) then
Nenue@23 184 tagID = questTagID;
Nenue@23 185 end
Nenue@23 186
Nenue@23 187 if ( isComplete and isComplete < 0 ) then
Nenue@23 188 q.completionTag = QUEST_TAG_TCOORDS["FAILED"]
Nenue@23 189 q.isFailed = true
Nenue@23 190 elseif isComplete then
Nenue@23 191 q.completionTag = QUEST_TAG_TCOORDS["COMPLETED"]
Nenue@23 192 end
Nenue@23 193
Nenue@23 194
Nenue@23 195 q.tagID = questTagID
Nenue@23 196 q.tagName = tagName
Nenue@23 197
Nenue@23 198
Nenue@23 199
Nenue@23 200 --q.isBreadCrumb = isBreadCrumb
Nenue@23 201 q.completionText= GetQuestLogCompletionText(questIndex)
Nenue@23 202 q.numObjectives = GetNumQuestLeaderBoards(questIndex)
Nenue@23 203 q.objectives = {}
Nenue@23 204 for i = 1, q.numObjectives do
Nenue@23 205 local text, type, finished = GetQuestLogLeaderBoard(i, questIndex)
Nenue@23 206 print(format(' #%d %s %s %s', i, tostring(type), tostring(text), tostring(finished)))
Nenue@23 207 q.objectives[i] = {
Nenue@23 208 index = i,
Nenue@23 209 type = type,
Nenue@23 210 text = text,
Nenue@23 211 finished = finished
Nenue@23 212 }
Nenue@23 213 if type == 'event' then
Nenue@23 214 elseif type == 'monster' then
Nenue@23 215 elseif type == 'object' then
Nenue@23 216 elseif type == 'reputation' then
Nenue@23 217 elseif type == 'item' then
Nenue@23 218 end
Nenue@23 219 end
Nenue@23 220
Nenue@23 221 if requiredMoney >= 1 then
Nenue@23 222 local money = GetMoney()
Nenue@23 223 local moneyText = money
Nenue@23 224 local requiredSilver, requiredCopper
Nenue@23 225 local requiredGold = (requiredMoney > 10000) and (floor(requiredMoney/10000)) or nil
Nenue@23 226 if mod(requiredMoney, 10000) ~= 0 then
Nenue@23 227 requiredSilver = (requiredMoney > 100) and (mod(requiredMoney, 10000) / 100) or nil
Nenue@23 228 if mod(requiredMoney, 100) ~= 0 then
Nenue@23 229 requiredCopper = mod(requiredMoney, 100)
Nenue@23 230 end
Nenue@23 231 end
Nenue@23 232
Nenue@23 233 -- round the money value down
Nenue@23 234 if requiredMoney > 9999 and not (requiredSilver or requiredCopper) then
Nenue@23 235 moneyText = floor(money/10000)
Nenue@23 236 elseif requiredMoney < 10000 and mod(requiredMoney,100) == 0 then
Nenue@23 237 moneyText = floor(money/100)
Nenue@23 238 end
Nenue@23 239
Nenue@23 240 local text = moneyText
Nenue@23 241 local index = #q.objectives + 1
Nenue@23 242 local finished = (GetMoney() >= requiredMoney)
Nenue@23 243
Nenue@23 244 if not finished then
Nenue@23 245 text = text .. ' / ' .. GetCoinTextureString(requiredMoney, 12)
Nenue@23 246 else
Nenue@23 247 text = '' .. GetCoinTextureString(requiredMoney, 12)
Nenue@23 248 end
Nenue@23 249 q.objectives[index] = {
Nenue@23 250 index = index,
Nenue@23 251 type = 'progressbar',
Nenue@23 252 quantity = money,
Nenue@23 253 requiredQuantity = requiredMoney,
Nenue@23 254 text = text,
Nenue@23 255 finished = finished
Nenue@23 256 }
Nenue@23 257 print(format(' #%d %s %s %s', index, 'money', text, tostring(finished)))
Nenue@23 258 end
Nenue@23 259
Nenue@23 260
Nenue@23 261 local link, icon, charges = GetQuestLogSpecialItemInfo(questIndex)
Nenue@23 262 local start, duration, enable = GetQuestLogSpecialItemCooldown(questIndex)
Nenue@23 263 if link or icon or charges then
Nenue@23 264 q.specialItem = {
Nenue@23 265 questID = questID,
Nenue@23 266 questIndex = questIndex,
Nenue@23 267 link = link,
Nenue@23 268 charges = charges,
Nenue@23 269 icon = icon,
Nenue@23 270 start = start,
Nenue@23 271 duration = duration,
Nenue@23 272 enable = enable,
Nenue@23 273 }
Nenue@23 274 end
Nenue@23 275
Nenue@23 276 if QuestHasPOIInfo(questID) then
Nenue@23 277 local distance, onContinent = GetDistanceSqToQuest(questIndex)
Nenue@23 278 if distance ~= nil and distance > 0 then
Nenue@23 279 self.POI[questIndex] = {
Nenue@23 280 questIndex = questIndex,
Nenue@23 281 questID = questID,
Nenue@23 282 distance = distance,
Nenue@23 283 onContinent = onContinent
Nenue@23 284 }
Nenue@23 285 end
Nenue@23 286 end
Nenue@23 287
Nenue@23 288
Nenue@23 289 q.selected = (questID == GetSuperTrackedQuestID()) -- call directly so artifact data doesn't become an issue
Nenue@23 290 self.WatchInfo[watchIndex] = q
Nenue@23 291 self.LogInfo[questIndex] = q
Nenue@23 292 print('- logIndex =', questIndex, 'title =', title)
Nenue@23 293 return q
Nenue@23 294 end
Nenue@23 295
Nenue@23 296 Quest.GetClosest = function()
Nenue@23 297 local minID, minTitle
Nenue@23 298 local minDist = math.huge
Nenue@23 299 local numQuests = GetNumQuestLogEntries()
Nenue@23 300 for questIndex = 1, numQuests do
Nenue@23 301 local distance, onContinent = GetDistanceSqToQuest(questIndex)
Nenue@23 302 local title, level, _, _, _, _, _, _, questID = GetQuestLogTitle(questIndex)
Nenue@23 303 if onContinent and distance < minDist then
Nenue@23 304 minDist = distance
Nenue@23 305 minTitle = title
Nenue@23 306 minID = questID
Nenue@23 307 end
Nenue@23 308 end
Nenue@23 309
Nenue@23 310 print('nearest quest is', minTitle, 'by', math.sqrt(minDist))
Nenue@23 311 return minID, minTitle, minDist
Nenue@23 312 end
Nenue@23 313
Nenue@23 314 Quest.OnTurnIn = function(self, questID, xp, money)
Nenue@23 315
Nenue@23 316 end