annotate WorldQuests.lua @ 69:31de7e9e7849

stop hiding pins when the timeleft returns 0; use C_TQ.IsActive
author Nenue
date Wed, 05 Apr 2017 11:36:06 -0400
parents 96183f981acb
children d6c0bed32c51
rev   line source
Nenue@33 1 -- WorldPlan
Nenue@33 2 -- WorldQuests.lua
Nenue@33 3 -- Created: 11/2/2016 3:40 PM
Nenue@33 4 -- %file-revision%
Nenue@40 5 local _, db = ...
Nenue@45 6 local Module = WorldPlanQuestsMixin
Nenue@33 7
Nick@64 8 local _G = _G
Nenue@33 9 local MC_GetNumZones, MC_GetZoneInfo = C_MapCanvas.GetNumZones, C_MapCanvas.GetZoneInfo
Nenue@33 10 local TQ_GetQuestsForPlayerByMapID = C_TaskQuest.GetQuestsForPlayerByMapID -- This function is not yet documented
Nenue@33 11 local TQ_GetQuestZoneID = C_TaskQuest.GetQuestZoneID
Nick@64 12 local TQ_IsActive = C_TaskQuest.IsActive
Nick@64 13 local pairs, ipairs, tinsert, tremove, wipe = pairs, ipairs, tinsert, tremove, table.wipe
Nick@64 14 local GetTaskInfo, GetTasksTable, HaveQuestData = GetTaskInfo, GetTasksTable, HaveQuestData
Nick@64 15 local GetTime = GetTime
Nenue@69 16 local SpellCanTargetQuest, IsQuestIDValidSpellTarget = SpellCanTargetQuest, IsQuestIDValidSpellTarget
Nick@64 17 local tonumber, abs = tonumber, math.abs
Nick@64 18 local GetQuestLogRewardInfo = GetQuestLogRewardInfo
Nick@64 19 local GetCurrentMapAreaID, GetMapInfo, GetMapNameByID = GetCurrentMapAreaID, GetMapInfo, GetMapNameByID
Nick@64 20
Nenue@67 21
Nenue@40 22 local print = DEVIAN_WORKSPACE and function(...) _G.print('WorldQuests', ...) end or function() end
Nenue@40 23 local rprint = DEVIAN_WORKSPACE and function(...) _G.print('WQRefresh', ...) end or function() end
Nenue@33 24 local qprint = DEVIAN_WORKSPACE and function(...) _G.print('POI', ...) end or function() end
Nenue@33 25 local wprint = DEVIAN_WORKSPACE and function(...) _G.print('WP', ...) end or function() end
Nenue@35 26 local mprint = DEVIAN_WORKSPACE and function(...) _G.print('Canvas', ...) end or function() end
Nenue@33 27
Nenue@69 28 local ToggleButton = {}
Nenue@69 29 local callbacks = {}
Nenue@40 30 local PinBaseIndex = 1200
Nenue@33 31 local BROKEN_ISLES_ID, DALARAN_ID, AZSUNA_ID, VALSHARAH_ID, HIGHMOUNTAIN_ID, STORMHEIM_ID, SURAMAR_ID, EOA_ID = 1007, 1014, 1015,1018, 1024, 1017, 1033, 1096
Nenue@33 32 local WORLD_QUEST_MAPS = { [DALARAN_ID] = 'Dalaran70', [AZSUNA_ID] = 'Azsuna', [VALSHARAH_ID] = "Val'sharah",
Nenue@33 33 [HIGHMOUNTAIN_ID] = 'Highmountain', [STORMHEIM_ID] = 'Stormheim', [SURAMAR_ID] = 'Suramar', [EOA_ID] = 'EyeOfAszhara', }
Nenue@33 34
Nenue@33 35 local REWARD_CASH = WORLD_QUEST_REWARD_TYPE_FLAG_GOLD
Nenue@33 36 local REWARD_ARTIFACT_POWER = WORLD_QUEST_REWARD_TYPE_FLAG_ARTIFACT_POWER
Nenue@33 37 local REWARD_GEAR = WORLD_QUEST_REWARD_TYPE_FLAG_EQUIPMENT
Nenue@33 38 local REWARD_CURRENCY = WORLD_QUEST_REWARD_TYPE_FLAG_ORDER_RESOURCES
Nenue@33 39 local REWARD_REAGENT = WORLD_QUEST_REWARD_TYPE_FLAG_MATERIALS
Nenue@66 40 local SCALE_FACTORS = {
Nenue@66 41 0.25, 0.7, 1
Nenue@66 42 }
Nenue@33 43
Nenue@69 44 local currentScale = WorldMapDetailFrame:GetScale()
Nenue@69 45 local canTargetQuests
Nenue@65 46 local numShown = 0
Nenue@65 47 local numLoaded = 0
Nenue@69 48 local isDataLoaded = true
Nenue@69 49 local numOverlays = 1
Nenue@66 50 local scaleConstant = 1
Nenue@45 51 Module.TasksByID = {}
Nenue@33 52
Nenue@33 53 --%debug%
Nenue@33 54 local SetTimedCallbackForAllPins = function(seconds, callback)
Nenue@33 55 C_Timer.After(seconds, function()
Nenue@33 56 for id, pin in pairs(WorldPlanQuests.QuestsByID) do
Nenue@33 57 callback(pin)
Nenue@33 58 end
Nenue@33 59 end)
Nenue@33 60 end
Nenue@33 61
Nenue@45 62 function Module:OnUpdate(sinceLast)
Nenue@67 63
Nenue@67 64 if self.filtersDirty or self.isStale then
Nenue@40 65 self:Refresh()
Nenue@40 66 end
Nenue@67 67 if #db.UpdatedPins >= 1 then
Nenue@67 68 print('|cFF00FF88pending updates', #db.UpdatedPins)
Nenue@67 69 self:UpdateQueuedPins()
Nenue@67 70 end
Nenue@67 71
Nenue@40 72 end
Nenue@40 73
Nenue@52 74
Nenue@45 75 function Module:Setup()
Nenue@40 76 print('|cFFFF4400'..self:GetName()..':Setup()')
Nenue@33 77 for mapID, mapName in pairs(WORLD_QUEST_MAPS) do
Nenue@40 78 db.QuestsByZone[mapID] = {}
Nenue@33 79 end
Nenue@69 80 for target, arg in pairs(callbacks) do
Nenue@69 81 print(type(target))
Nenue@69 82 if type(target) == 'table' then
Nenue@69 83 local callerName = target:GetName()
Nenue@69 84 for name, method in pairs(arg) do
Nenue@69 85 print(callerName, arg)
Nenue@69 86 hooksecurefunc(target, name, function(...)
Nenue@69 87 self:OnSecureHook(callerName .. '.' .. arg, method, ...)
Nenue@69 88 end)
Nenue@69 89 end
Nenue@69 90 else
Nenue@69 91 hooksecurefunc(target, function(...)
Nenue@69 92 self:OnSecureHook(target, arg, ...)
Nenue@69 93 end)
Nenue@69 94 end
Nenue@69 95 end
Nenue@65 96
Nenue@65 97 self.Status = CreateFrame('Frame', nil, self)
Nenue@65 98 self.Status:SetPoint('TOPLEFT', WorldMapPOIFrame, 'TOPLEFT', 0, 0)
Nenue@65 99 self.Status:SetPoint('BOTTOMRIGHT', WorldMapPOIFrame, 'TOPRIGHT', 0, -4)
Nenue@65 100 self.Status.t = self.Status:CreateTexture(nil, 'OVERLAY')
Nenue@65 101 self.Status.b = self.Status:CreateTexture(nil, 'BACKGROUND')
Nenue@65 102 self.Status.b:SetColorTexture(0,0,0,.25)
Nenue@65 103 self.Status.b:SetAllPoints(self.Status)
Nenue@65 104 self.Status.t:SetColorTexture(1,1,1,.5)
Nenue@65 105 self.Status.t:SetPoint('TOP')
Nenue@65 106 self.Status.t:SetPoint('BOTTOM')
Nenue@65 107 self.Status.t:SetPoint('LEFT')
Nenue@65 108 local translationEnd, translationStart
Nenue@65 109 self.Status:SetScript('OnUpdate', function(status)
Nenue@65 110 local translateTo
Nenue@65 111 if numLoaded < numShown then
Nenue@65 112 translateTo = numLoaded/numShown * status:GetWidth()
Nenue@65 113 status.t:SetWidth(translateTo)
Nenue@65 114 else
Nenue@65 115 translateTo = numShown * status:GetWidth()
Nenue@65 116 status.t:SetWidth(translateTo)
Nenue@65 117 end
Nenue@65 118 end)
Nenue@67 119
Nenue@67 120 self:SetAllPoints(WorldMapPOIFrame)
Nenue@67 121 for k,v in pairs( ToggleButton) do
Nenue@67 122 self.Toggle:SetScript(k,v)
Nenue@67 123 end
Nenue@67 124 self:Show()
Nenue@67 125 end
Nenue@69 126 callbacks.ClickWorldMapActionButton = function(WorldQuests)
Nenue@69 127 WorldQuests:GetUsedPOIs()
Nenue@69 128 end
Nenue@69 129 callbacks.WorldMap_UpdateQuestBonusObjectives = function(WorldQuests)
Nenue@69 130 WorldQuests:GetUsedPOIs()
Nenue@69 131 end
Nenue@69 132 callbacks.WorldMapFrame_UpdateMap = function(WorldQuests)
Nenue@69 133 WorldQuests:RefreshIfChanged()
Nenue@69 134 end
Nenue@69 135 callbacks.WorldMapScrollFrame_ReanchorQuestPOIs = function (WorldQuests)
Nenue@69 136 WorldQuests:RefreshIfChanged()
Nenue@69 137 end
Nenue@69 138 callbacks[WorldMapFrame.UIElementsFrame.BountyBoard] = {
Nenue@69 139 SetSelectedBountyIndex = function(WorldQuests)
Nenue@69 140 WorldQuests:UpdateBountyInfo()
Nenue@69 141 end
Nenue@69 142 }
Nenue@69 143 callbacks[WorldMapFrame.UIElementsFrame.ActionButton] = {
Nenue@69 144 UpdateCastingState = function(WorldQuests)
Nenue@69 145 WorldQuests:Refresh(true)
Nenue@69 146 end
Nenue@69 147 }
Nenue@69 148
Nenue@67 149
Nenue@67 150 local GetQuestBountyInfoForMapID, GetQuestLogTitle, GetQuestLogIndexByID, IsQuestFlaggedCompleted = GetQuestBountyInfoForMapID, GetQuestLogTitle, GetQuestLogIndexByID, IsQuestFlaggedCompleted
Nenue@67 151 function Module:UpdateBountyInfo()
Nenue@67 152 wipe(db.BountyInfo)
Nenue@67 153 db.selectedBounty = nil
Nenue@67 154
Nenue@67 155 local selectedBounty = WorldMapFrame.UIElementsFrame.BountyBoard:GetSelectedBountyIndex()
Nenue@67 156 local bounties, numBounties = GetQuestBountyInfoForMapID(db.currentMapID)
Nenue@67 157
Nenue@67 158 for index, data in ipairs(bounties) do
Nenue@67 159 if data.factionID then
Nenue@67 160 data.title = GetQuestLogTitle(GetQuestLogIndexByID(data.questID))
Nenue@67 161 data.complete = IsQuestFlaggedCompleted(data.questID)
Nenue@67 162 db.BountyInfo[data.factionID] = data
Nenue@67 163 if index == selectedBounty then
Nenue@67 164 db.selectedBounty = data
Nenue@67 165 end
Nenue@67 166 end
Nenue@67 167 end
Nenue@67 168
Nenue@67 169 for questID, pin in pairs(db.QuestsByID) do
Nenue@67 170 local doUpdate
Nenue@67 171 if pin.factionID and db.BountyInfo[pin.factionID] then
Nenue@67 172 if not pin.isCriteria then
Nenue@67 173 pin.isCriteria = true
Nenue@67 174 doUpdate = true
Nenue@67 175 end
Nenue@67 176 else
Nenue@67 177 if pin.isCriteria then
Nenue@67 178 doUpdate = true
Nenue@67 179 pin.isCriteria = nil
Nenue@67 180 end
Nenue@67 181 end
Nenue@67 182 if doUpdate then
Nenue@67 183 if pin:IsVisible() then
Nenue@67 184 pin:Refresh()
Nenue@67 185 else
Nenue@67 186 pin.isStale = true
Nenue@67 187 end
Nenue@67 188 end
Nenue@67 189 end
Nenue@67 190 db.BountyUpdate = nil
Nenue@67 191 end
Nenue@67 192
Nenue@49 193 function Module:OnConfigUpdate()
Nenue@67 194 print('|cFFFFFF00OnConfigUpdate()|r')
Nenue@49 195 if db.Config.FadeWhileGrouped then
Nenue@49 196 db.PinAlpha = 0.15
Nenue@49 197 else
Nenue@49 198 db.PinAlpha = 1
Nenue@49 199 end
Nenue@67 200
Nenue@67 201 if not db.Config.EnablePins then
Nenue@67 202 for _, pin in pairs(db.QuestsByID) do
Nenue@67 203 pin:SetShown(false)
Nenue@67 204 end
Nenue@67 205 end
Nenue@67 206
Nenue@67 207 ToggleButton.OnShow(self.Toggle)
Nenue@49 208 end
Nenue@49 209
Nenue@45 210 local InternalHideButton = function(button, index)
Nenue@45 211 button:Hide()
Nenue@45 212 if button.questID and db.QuestsByID[button.questID] then
Nenue@45 213 if db.QuestsByID[button.questID].used and not db.QuestsByID[button.questID].filtered then
Nenue@45 214 db.QuestsByID[button.questID]:SetShown(true)
Nenue@45 215 end
Nenue@45 216 end
Nenue@45 217 end
Nenue@45 218 local InternalShowButton = function(button, index)
Nenue@45 219 button:Show()
Nenue@45 220 if button.questID and db.QuestsByID[button.questID] then
Nenue@45 221 db.QuestsByID[button.questID]:SetShown(false)
Nenue@45 222 end
Nenue@45 223 end
Nenue@33 224
Nenue@69 225 db.UsedPOIs = {}
Nenue@69 226 function Module:GetUsedPOIs()
Nenue@69 227 db.canTargetQuests = SpellCanTargetQuest()
Nenue@69 228 local func = db.canTargetQuests and InternalShowButton or InternalHideButton
Nenue@69 229 wipe(db.UsedPOIs)
Nenue@45 230 for i = 1, NUM_WORLDMAP_TASK_POIS do
Nenue@45 231 local button = _G['WorldMapFrameTaskPOI'..i]
Nenue@45 232 if button and button.worldQuest then
Nenue@45 233 func(button, i)
Nenue@69 234 db.UsedPOIs[button.questID] = button
Nenue@45 235 end
Nenue@45 236 end
Nenue@45 237 end
Nenue@40 238
Nenue@69 239 function Module:OnSecureHook(callbackName, func, ...)
Nenue@69 240 rprint('|cFFFF4400'..callbackName..'|r', ...)
Nenue@69 241 func(self, ...)
Nenue@45 242 end
Nenue@40 243
Nenue@33 244 local defaults = {}
Nenue@40 245 local REWARD_UNKNOWN = 768
Nenue@45 246 function Module:OnLoad()
Nenue@40 247 print('|cFFFF4400'..self:GetName()..':OnLoad()')
Nenue@33 248
Nenue@48 249 self:SetParent(WorldMapPOIFrame)
Nenue@33 250 WorldPlan:AddHandler(self, defaults)
Nenue@33 251
Nenue@33 252 for areaID, fileName in pairs(WORLD_QUEST_MAPS) do
Nenue@40 253 db.QuestsByZone[areaID] = {}
Nenue@33 254 end
Nenue@33 255
Nenue@41 256 -- WORLD_MAP_UPDATE and PLAYER_ENTERING_WORLD are passed down from a higher level
Nenue@33 257 self:RegisterEvent('WORLD_QUEST_COMPLETED_BY_SPELL')
Nenue@55 258 self:RegisterEvent('SUPER_TRACKED_QUEST_CHANGED')
Nenue@33 259 self:RegisterEvent('SKILL_LINES_CHANGED')
Nick@62 260 self:RegisterEvent('CURRENT_SPELL_CAST_CHANGED')
Nenue@69 261 self:RegisterEvent('ARTIFACT_UPDATE')
Nenue@33 262 end
Nenue@33 263
Nenue@67 264 function Module:OnMapInfo(isBrokenIsle, isZoomedOut, mapAreaID, isNewMap, isMapOpen)
Nenue@67 265
Nenue@67 266 print('|cFFFFFF00'..self:GetName()..':OnMapInfo()|r, mapAreaID =', mapAreaID,'visible =', isMapOpen, 'changed =', isNewMap)
Nenue@67 267
Nenue@67 268 if db.BountyUpdate then
Nenue@67 269 self:UpdateBountyInfo()
Nenue@67 270 end
Nenue@67 271 if isNewMap then
Nenue@67 272 print('|cFF00FF88refreshing for changed map')
Nenue@67 273 if isMapOpen then
Nenue@67 274 self:Refresh(true)
Nenue@67 275 else
Nenue@67 276 self.isStale = true
Nenue@67 277 end
Nenue@54 278 end
Nenue@56 279
Nenue@41 280 end
Nenue@65 281 local superTrackedQuestID
Nenue@45 282 function Module:OnEvent (event, ...)
Nenue@40 283
Nenue@40 284 print('|cFFFFFF00'..self:GetName()..':OnEvent() '..event..'|r', GetTime(), ...)
Nenue@69 285 if (event == 'QUEST_LOG_UPDATE') then
Nenue@69 286 if self:IsVisible() then
Nenue@69 287 self:Refresh()
Nenue@69 288 else
Nenue@40 289 self.isStale = true
Nenue@33 290 end
Nenue@33 291 print('WorldMapFrame', WorldMapFrame:IsVisible(), 'hasUpdates:', self.isStale)
Nenue@33 292 elseif event == 'WORLD_QUEST_COMPLETED_BY_SPELL' then
Nenue@33 293 local questID = ...
Nenue@40 294 if questID and db.QuestsByID[questID] then
Nenue@40 295 self:ReleasePin(db.QuestsByID[questID])
Nenue@40 296 rprint('|cFFFF4400release|r', questID)
Nenue@33 297 end
Nenue@65 298 elseif event == 'SKILL_LINES_CHANGED' or event == 'CURRENT_SPELL_CAST_CHANGED' then
Nick@62 299 self:Refresh()
Nenue@59 300 elseif event == 'ARTIFACT_UPDATE' then
Nenue@59 301 local ak = C_ArtifactUI.GetArtifactKnowledgeMultiplier()
Nenue@59 302 if ak and (ak ~= self.akLevel) then
Nick@62 303 print('push artifact knowledge update', self.akLevel, 'to', ak)
Nenue@59 304 self.akLevel = ak
Nick@62 305 for index, pin in pairs( db.QuestsByID) do
Nenue@69 306 if pin.rewardType == REWARD_ARTIFACT_POWER then
Nenue@69 307 pin.dataLoaded = nil
Nenue@69 308 end
Nick@62 309 end
Nenue@59 310 end
Nenue@65 311 elseif event == 'SUPER_TRACKED_QUEST_CHANGED' then
Nenue@65 312 if superTrackedQuestID and db.QuestsByID[superTrackedQuestID] then
Nenue@65 313 db.QuestsByID[superTrackedQuestID].isStale = true
Nenue@65 314 end
Nenue@65 315 local newID = GetSuperTrackedQuestID()
Nenue@65 316 if newID and db.QuestsByID[newID] then
Nenue@65 317 db.QuestsByID[newID].isStale = true
Nenue@65 318 end
Nenue@33 319 end
Nenue@33 320 end
Nenue@33 321
Nenue@40 322 local totalPins = 0
Nenue@33 323 local TQ_GetQuestLocation = C_TaskQuest.GetQuestLocation
Nenue@45 324 function Module:AcquirePin (info)
Nenue@40 325 local questID = info.questId
Nenue@40 326 if not questID then
Nenue@40 327 return nil
Nenue@40 328 end
Nenue@40 329
Nenue@40 330 if not QuestUtils_IsQuestWorldQuest(questID) then
Nenue@40 331 return nil
Nenue@40 332 end
Nenue@40 333
Nenue@49 334 -- if we're grabbing a pin, the filters need to be checked
Nenue@40 335 local pin = db.QuestsByID[questID]
Nenue@33 336 if not pin then
Nenue@40 337 local numFree = #db.FreePins
Nenue@33 338 if numFree >= 1 then
Nenue@40 339 pin = tremove(db.FreePins, numFree)
Nenue@33 340 --print('|cFF00FF00Re-using', pin:GetName())
Nenue@33 341 else
Nenue@40 342 totalPins = totalPins + 1
Nenue@69 343 local name = 'WorldPlanQuestMarker' .. numOverlays
Nenue@33 344 --print('|cFF00FF00Creating', name)
Nenue@33 345 pin = CreateFrame('Frame', name, WorldMapPOIFrame, 'WorldPlanQuestPin')
Nenue@33 346
Nenue@33 347 pin:SetFrameStrata('HIGH')
Nenue@33 348 pin.GetTypeInfo = function(frame, typeID)
Nenue@33 349 return self:GetTypeInfo(typeID)
Nenue@33 350 end
Nenue@40 351 pin:SetID(totalPins)
Nenue@69 352 numOverlays = numOverlays + 1
Nenue@33 353 --pin.iconBorder:SetVertexColor(0,0,0,1)
Nenue@33 354 end
Nenue@40 355 pin.questID = questID
Nenue@40 356 pin.worldQuest = true
Nenue@40 357 pin.throttle = 1
Nenue@33 358 pin.isNew = true
Nenue@33 359 pin.currentWidth = nil
Nenue@40 360 db.QuestsByID[questID] = pin
Nenue@40 361 tinsert(db.UsedPins, pin)
Nenue@40 362 end
Nenue@33 363
Nenue@40 364 if pin and info then
Nenue@40 365 pin.inProgress = info.inProgress
Nenue@40 366 pin.floor = info.floor
Nenue@40 367 pin.numObjectives = info.numObjectives or 0
Nenue@40 368 if info.x and info.y then
Nenue@40 369 pin.x = info.x or pin.x
Nenue@40 370 pin.y = info.y or pin.y
Nenue@40 371 rprint('|cFFFF4400coords|r', info.x, info.y)
Nenue@40 372 end
Nenue@40 373 end
Nenue@33 374
Nick@62 375 if (not pin.dataLoaded) then
Nenue@65 376 local dataLoaded = pin:GetData()
Nenue@65 377 isDataLoaded = (isDataLoaded and dataLoaded)
Nick@63 378 WorldPlan.dataFlush = true
Nenue@49 379 end
Nenue@49 380
Nenue@66 381
Nick@64 382 pin.isActive = TQ_IsActive(questID)
Nenue@57 383 pin:CheckFilterRules()
Nenue@49 384 rprint(pin:GetID(), pin.filtered, pin.used)
Nenue@49 385
Nenue@40 386 return pin
Nenue@33 387 end
Nenue@33 388
Nenue@33 389 -- remove from index and add it to the recycling heap
Nenue@45 390 function Module:ReleasePin (pin)
Nenue@33 391
Nenue@40 392 local id = pin.questID
Nenue@33 393 if id then
Nenue@40 394 db.QuestsByID[id] = nil
Nenue@40 395
Nenue@40 396 for i, zone in pairs(db.QuestsByZone) do
Nenue@33 397 print('-', i, zone[i])
Nenue@33 398 zone[id] = nil
Nenue@33 399 end
Nenue@40 400 db.TasksByID[id] = nil
Nenue@33 401 end
Nick@64 402 pin.isActive = nil
Nick@64 403 pin.dataLoaded = nil
Nick@62 404 pin:HideFrames()
Nenue@40 405 tinsert(db.FreePins, pin)
Nenue@40 406
Nick@63 407 WorldPlan.dataFlush = true
Nenue@40 408 print('|cFF00FF00-'.. (pin.mapID and GetMapNameByID(pin.mapID) or '???') ..'|r', id, pin.title)
Nenue@33 409 end
Nenue@33 410
Nick@64 411
Nenue@45 412 function Module:GetBonusObjectives()
Nenue@40 413
Nenue@40 414
Nenue@40 415 local tasksTable = GetTasksTable()
Nenue@40 416 if tasksTable ~= nil then
Nenue@40 417 print('|cFF00FF88'..self:GetName()..':BonusObjectives()|r ')
Nenue@40 418 self.numTasks = #tasksTable
Nenue@40 419 for i, taskID in ipairs(tasksTable) do
Nenue@40 420 if not QuestUtils_IsQuestWorldQuest(taskID) then
Nenue@40 421 local info = db.TasksByID[taskID]
Nenue@40 422 if not info then
Nenue@40 423 local isInArea, isOnMap, numObjectives, taskName, displayAsObjective = GetTaskInfo(taskID)
Nenue@40 424 if isOnMap then
Nenue@40 425 print(' * '..i, taskID, GetTaskInfo(taskID))
Nenue@40 426 info = {
Nenue@40 427 questID = taskID,
Nenue@40 428 numObjectives = numObjectives,
Nenue@40 429 title = taskName,
Nenue@40 430 isInArea = isInArea,
Nenue@40 431 isOnMap = isOnMap,
Nenue@40 432 displayAsObjective = displayAsObjective,
Nenue@40 433 worldQuest = false,
Nenue@40 434 isPending = false,
Nenue@40 435 isNew = true,
Nenue@40 436 }
Nenue@40 437
Nenue@40 438
Nenue@40 439 db.TasksByID[taskID] = info
Nenue@40 440
Nenue@40 441 local pin = self:AcquirePin(taskID)
Nenue@40 442 for k,v in pairs(info) do
Nenue@40 443 pin[k] = v
Nenue@40 444 end
Nenue@40 445 pin:GetBonusObjectiveInfo(info)
Nenue@40 446 end
Nenue@40 447 end
Nenue@40 448 end
Nenue@40 449
Nenue@40 450
Nenue@40 451 end
Nenue@40 452 end
Nenue@40 453 end
Nenue@40 454
Nenue@40 455
Nenue@40 456 -- use tooltip object to extract item details
Nenue@45 457 function Module:GetRewardHeader(questID)
Nenue@40 458 local name, icon, quantity, quality, _, itemID = GetQuestLogRewardInfo(1, questID)
Nenue@40 459 local scanner = _G.WorldPlanTooltip
Nenue@40 460 local print = qprint
Nenue@40 461 if not itemID then
Nenue@40 462 return
Nenue@40 463 end
Nenue@49 464 qprint('GetRewardHeader', questID)
Nenue@40 465
Nenue@40 466 scanner:SetOwner(WorldPlan, "ANCHOR_NONE")
Nenue@40 467 scanner:SetItemByID(itemID)
Nenue@40 468 scanner:Show()
Nenue@40 469 local ttl1 = _G['WorldPlanTooltipTextLeft1']
Nenue@40 470 local ttl2 = _G['WorldPlanTooltipTextLeft2']
Nenue@40 471 local ttl3 = _G['WorldPlanTooltipTextLeft3']
Nenue@40 472 local ttl4 = _G['WorldPlanTooltipTextLeft4']
Nenue@40 473 --print(ttl2, ttl3, ttl4)
Nenue@40 474 if ttl2 then
Nenue@40 475 local text = ttl2:GetText()
Nenue@40 476 -- Artifact Power
Nenue@40 477 --print(text)
Nenue@40 478 if text then
Nenue@40 479 if text:match("|cFFE6CC80") then
Nenue@40 480 --print('AP token!', text)
Nenue@40 481 local power
Nenue@40 482 if ttl4 then
Nenue@40 483 local text = ttl4:GetText()
Nenue@40 484 --print('tip line 4', text)
Nenue@40 485 if text then
Nenue@40 486 power = text:gsub("%p", ""):match("%d+")
Nenue@40 487 power = tonumber(power)
Nenue@40 488 end
Nenue@40 489
Nenue@40 490 end
Nenue@40 491 return REWARD_ARTIFACT_POWER, "Interface\\ICONS\\inv_7xp_inscription_talenttome01", power, name, itemID, quality
Nenue@40 492 elseif text:match("Item Level") then
Nenue@40 493 --print('equipment!', text)
Nenue@40 494 quantity = text:match("Item Level ([%d\+]+)")
Nenue@40 495 return REWARD_GEAR, icon, quantity, name, itemID, quality
Nenue@40 496 elseif text:match("Crafting Reagent") then
Nenue@49 497 qprint('|cFFFF4400it is a reagent', text)
Nenue@40 498 return REWARD_REAGENT, icon, quantity, name, itemID, quality
Nenue@40 499 end
Nenue@40 500 end
Nenue@40 501 end
Nenue@40 502
Nenue@40 503 if ttl3 then
Nenue@40 504 local text = ttl3:GetText()
Nenue@40 505 if text and text:match("Crafting Reagent") then
Nenue@49 506 qprint('|cFFFF4400it is a reagent', text)
Nenue@40 507 return REWARD_REAGENT, icon, quantity, name, itemID, quality
Nenue@40 508 end
Nenue@40 509 end
Nenue@40 510 return 128, icon, quantity, name, itemID, quality
Nenue@40 511 end
Nenue@67 512
Nenue@67 513 -- pins are queued by their OnUpdate and are ostensibly already visible, we just need to fix the zoom and anchor
Nenue@67 514 function Module:UpdateQueuedPins()
Nenue@67 515 print('|cFF00FF88UpdateQueuedPins()')
Nenue@67 516 local pin = tremove(db.UpdatedPins)
Nenue@67 517 while pin do
Nenue@67 518 pin:CheckFilterRules()
Nenue@67 519
Nenue@67 520 local scaleFactor = SCALE_FACTORS[(pin.dataLoaded and not pin.filtered) and scaleConstant or 1]
Nenue@67 521 print(pin.title, pin.dataLoaded and not pin.filtered, scaleFactor)
Nenue@67 522 pin:SetAnchor(nil, pin.x, pin.y, self.hostWidth, self.hostHeight, scaleFactor)
Nenue@69 523
Nenue@69 524 if pin.isNew then
Nenue@69 525 pin:OnShow()
Nenue@69 526 end
Nenue@69 527
Nenue@69 528
Nenue@67 529 pin = tremove(db.UpdatedPins)
Nenue@69 530
Nenue@67 531 end
Nenue@67 532 end
Nenue@67 533
Nenue@33 534 -- create of update quest pins for a map and its underlying zones
Nenue@45 535 function Module:UpdateWorldQuests (mapID)
Nenue@40 536
Nenue@40 537 mapID = mapID or db.currentMapID
Nenue@33 538 if not mapID then
Nenue@33 539 -- info not available yet
Nenue@33 540 return
Nenue@33 541 end
Nenue@33 542
Nenue@66 543 local scalingConstant = 1
Nenue@66 544 local style = DEFAULT_STYLE
Nenue@66 545 if self.dataLoaded then
Nenue@66 546 style = REWARD_TYPE_STYLES[self.rewardType]
Nenue@66 547 scalingConstant = db.isContinentMap and 2 or 3
Nenue@66 548 end
Nenue@66 549
Nenue@66 550 local pinScale = SCALE_FACTORS[scalingConstant]
Nenue@66 551 print(pinScale)
Nenue@66 552 self:SetScale(pinScale)
Nenue@66 553 self.Overlay:SetScale(pinScale)
Nenue@34 554
Nenue@40 555 print('|cFF00FF88'..self:GetName()..':UpdateWorldQuests()|r', 'map:', mapID, 'realMap:', db.currentMapID)
Nenue@33 556
Nenue@40 557
Nenue@40 558 self.isStale = nil
Nenue@40 559 print('|cFF00FFFFContinent:|r', BROKEN_ISLES_ID, GetMapNameByID(BROKEN_ISLES_ID))
Nenue@40 560 self.isRecursed = true
Nenue@40 561 for i = 1, MC_GetNumZones(BROKEN_ISLES_ID) do
Nenue@40 562 local submapID, name, depth = MC_GetZoneInfo(BROKEN_ISLES_ID, i)
Nenue@40 563 local taskInfo = TQ_GetQuestsForPlayerByMapID(submapID, BROKEN_ISLES_ID)
Nenue@40 564 if taskInfo then
Nenue@40 565 local zoneName = GetMapNameByID(submapID)
Nenue@40 566 print('|cFF00FFFF Zone:|r', submapID, zoneName, #taskInfo)
Nenue@40 567 db.QuestsByZone[submapID] = db.QuestsByZone[submapID] or {}
Nenue@40 568 for i, info in ipairs(taskInfo) do
Nenue@40 569 if HaveQuestData(info.questId) then
Nenue@40 570 rprint('|cFF44FF44update|r', info.questId, zoneName)
Nenue@40 571 local questID = info.questId
Nenue@40 572 local pin = self:AcquirePin(questID)
Nenue@40 573 local pin = db.QuestsByID[questID]
Nenue@40 574 if pin then
Nenue@40 575 pin.isStale = true
Nenue@40 576 if pin.isPending then
Nenue@40 577 self.isPending = true
Nenue@40 578 end
Nenue@40 579 end
Nenue@40 580 else
Nenue@40 581 rprint('|cFFFF4400no data|r', info.questId, zoneName)
Nenue@40 582 end
Nenue@33 583 end
Nenue@33 584 end
Nenue@33 585 end
Nenue@33 586
Nenue@40 587 self:GetBonusObjectives()
Nenue@40 588
Nenue@40 589 print(' hasUpdate:', self.isStale, 'isPending:', self.isPending, 'timer:', (self.OnNext and 'waiting' or ''))
Nenue@40 590 --WorldPlan.isStale = (self.isStale or WorldPlan.isStale)
Nenue@40 591 if self.isStale and self:IsVisible() then
Nenue@40 592 self:Refresh()
Nenue@40 593 end
Nick@63 594
Nenue@40 595 end
Nenue@40 596
Nenue@45 597 function Module:Report()
Nenue@40 598 for i, pin in ipairs(db.UsedPins) do
Nenue@40 599 db:print(i, pin.questID, pin.title)
Nenue@33 600 end
Nenue@33 601
Nenue@40 602 for id, pin in pairs(db.QuestsByID) do
Nenue@40 603 db:print(id, pin.worldQuestType, pin.rewardType, pin.title)
Nenue@40 604 end
Nenue@33 605 end
Nenue@33 606
Nenue@67 607 local bountiesInitialized
Nenue@67 608 function Module:Refresh(...)
Nenue@67 609 rprint('|cFF00FF88'..self:GetName()..':Refresh()|r', ...)
Nenue@67 610 print('|cFF00FF88'..self:GetName()..':Refresh()|r', ...)
Nenue@34 611 if not self:IsVisible() then
Nenue@40 612 print(' not visible, flag for later')
Nenue@34 613 self.isStale = true
Nenue@57 614 return self:MarkAllPins()
Nenue@40 615 end
Nenue@67 616 if not db.Config.EnablePins then
Nenue@69 617 numShown = 0
Nenue@67 618 return
Nenue@67 619 end
Nenue@67 620
Nenue@67 621
Nick@60 622 wprint(' |cFF00FF88'..self:GetName()..':Refresh()|r')
Nenue@40 623
Nenue@66 624 scaleConstant = db.isContinentMap and 2 or 3
Nenue@40 625 for index, pin in pairs(db.QuestsByID) do
Nenue@40 626 pin.used = nil
Nenue@40 627 end
Nenue@40 628
Nenue@69 629 canTargetQuests = SpellCanTargetQuest()
Nenue@69 630 self:UpdateAnchors()
Nick@60 631
Nenue@69 632 -- calculate quests shown
Nenue@65 633 numShown = 0
Nenue@65 634 numLoaded = 0
Nick@60 635 for questID, pin in pairs(db.QuestsByID) do
Nick@60 636 local oV = pin:IsShown()
Nick@60 637 if pin.used then
Nick@60 638 pin.throttle = 1
Nick@60 639 if oV == false then
Nenue@67 640 rprint('|cFF00FF00cleanup +|r', questID, pin.title)
Nick@60 641 end
Nick@60 642 pin:SetShown(true)
Nenue@65 643 numShown = numShown + 1
Nenue@65 644 if pin.dataLoaded then
Nenue@65 645 numLoaded = numLoaded + 1
Nenue@65 646 end
Nenue@65 647
Nick@60 648 else
Nick@60 649 if oV == true then
Nenue@67 650 rprint('|cFFFF4400 -|r', questID, pin.title)
Nick@60 651 end
Nenue@69 652 pin.hideReason = "Not used in map area " .. (db.currentMapID)
Nick@62 653 pin:HideFrames()
Nick@60 654 end
Nick@60 655 end
Nick@60 656
Nenue@67 657 print(numShown, 'shown', numLoaded, 'loaded')
Nenue@65 658 if numShown > numLoaded then
Nenue@65 659 self.Status:Show()
Nenue@65 660 end
Nenue@65 661
Nenue@65 662
Nenue@40 663 self.isStale = nil
Nenue@54 664 self.sizesDirty = nil
Nenue@66 665 self.isZoomDirty = nil
Nenue@40 666 end
Nenue@40 667
Nenue@69 668 function Module:RefreshIfChanged()
Nenue@69 669 local scaleCheck = WorldMapDetailFrame:GetScale()
Nenue@69 670 if scaleCheck ~= currentScale then
Nenue@69 671 print('|cFF00FF88scale changed from', currentScale, 'to', scaleCheck)
Nenue@69 672 self:Refresh()
Nenue@69 673 currentScale = scaleCheck
Nenue@69 674 elseif self.isStale then
Nenue@69 675 print('|cFF00FF88isStale flag was set')
Nenue@69 676 self:Refresh()
Nenue@69 677 end
Nenue@69 678 end
Nenue@69 679
Nenue@40 680 -- update visibility states of all pins
Nenue@57 681 function Module:MarkAllPins(pins)
Nenue@57 682 print(' |cFFFFFF00'..self:GetName()..':MarkAllPins()|r', pins)
Nenue@40 683 pins = pins or db.QuestsByID
Nenue@40 684 for questID, pin in pairs(pins) do
Nenue@40 685 pin.isStale = true
Nenue@40 686 rprint('|cFF00FF00filter', pin.questID, pin.filtered, 'used:', pin.used)
Nenue@40 687 end
Nenue@40 688 end
Nenue@40 689
Nenue@45 690 function Module:UpdateQuestButton(info, mapID)
Nenue@40 691 local questID, x, y = info.questId, info.x, info.y
Nenue@40 692 local pin = self:AcquirePin(info)
Nenue@40 693 if not pin then
Nenue@34 694 return
Nenue@34 695 end
Nenue@34 696
Nenue@67 697 --print(' |- ', pin.questID, pin.title)
Nenue@57 698 rprint('|cFF00FF00update|r', pin.questID, pin.title)
Nenue@40 699 if x and y then
Nenue@66 700 local scaleFactor = SCALE_FACTORS[(pin.dataLoaded and not pin.filtered) and scaleConstant or 1]
Nenue@49 701 pin:SetFrameLevel(PinBaseIndex+pin:GetID())
Nenue@57 702 pin.owningFrame = WorldMapFrame
Nenue@66 703 pin:SetAnchor(WorldMapPOIFrame, x, y, self.hostWidth, self.hostHeight, scaleFactor)
Nenue@54 704 --tinsert(self.UsedPositions, pin)
Nenue@40 705 end
Nenue@66 706
Nenue@66 707 if self:IsVisible() and (pin.isStale) then
Nenue@57 708 pin:Refresh()
Nenue@54 709 end
Nenue@69 710
Nenue@40 711 if mapID then
Nenue@40 712 if not db.QuestsByZone[mapID] then
Nenue@40 713 db.QuestsByZone[mapID] = {}
Nenue@40 714 end
Nenue@40 715 db.QuestsByZone[mapID][questID] = pin
Nenue@33 716 end
Nenue@33 717 end
Nenue@33 718
Nenue@69 719 -- Updates quest markers in taskInfo while associating them with the given map
Nenue@69 720 function Module:UpdateQuestsForMap(taskInfo, mapID)
Nenue@49 721 rprint('Map', GetMapNameByID(mapID), GetMapNameByID(db.currentMapID))
Nenue@40 722 for index, info in pairs(taskInfo) do
Nenue@40 723 self:UpdateQuestButton(info, mapID)
Nenue@40 724 end
Nenue@40 725 end
Nenue@33 726
Nenue@69 727 -- Used to refresh the visible quest markers
Nick@60 728 function Module:UpdateAnchors ()
Nenue@40 729 wipe(self.UsedPositions)
Nick@60 730 print(' |cFF00FF00'..self:GetName()..':UpdateAnchors()')
Nenue@57 731 self.hostWidth, self.hostHeight = WorldMapPOIFrame:GetSize()
Nenue@40 732 self.nudgeThrescholdX = 16/self.hostWidth
Nenue@40 733 self.nudgeThrescholdY = 16/self.hostHeight
Nenue@67 734
Nenue@67 735 rprint('|cFF00FF00'..self:GetName()..':UpdateAnchors()')
Nenue@33 736 local mapFileName, textureHeight, textureWidth, isMicroDungeon, microDungeonMapName = GetMapInfo()
Nenue@33 737 if isMicroDungeon then
Nenue@33 738 return
Nenue@33 739 end
Nenue@69 740
Nenue@65 741 isDataLoaded = true
Nenue@67 742 local taskInfo = TQ_GetQuestsForPlayerByMapID(db.currentMapID)
Nenue@40 743 if taskInfo then
Nenue@69 744 self:UpdateQuestsForMap(taskInfo, db.currentMapID)
Nenue@33 745 end
Nenue@67 746 local numZones = MC_GetNumZones(db.currentMapID)
Nenue@33 747 if numZones then
Nenue@33 748 for i = 1, numZones do
Nenue@67 749 local mapAreaID = MC_GetZoneInfo(db.currentMapID, i)
Nenue@67 750 local taskInfo = TQ_GetQuestsForPlayerByMapID(mapAreaID, db.currentMapID)
Nenue@40 751 if taskInfo then
Nenue@69 752 self:UpdateQuestsForMap(taskInfo, mapAreaID)
Nenue@40 753 end
Nenue@33 754 end
Nenue@33 755 end
Nenue@33 756 end
Nenue@33 757
Nenue@67 758 function ToggleButton:OnShow()
Nenue@67 759 self:SetChecked(db.Config.EnablePins and true or false)
Nenue@67 760 end
Nenue@67 761 function ToggleButton:OnClick()
Nenue@67 762 print(self:GetChecked())
Nenue@67 763 db.Config.EnablePins = self:GetChecked()
Nenue@67 764 _G.WorldPlan:OnConfigUpdate()
Nenue@67 765 end