annotate WorldQuests.lua @ 67:96183f981acb

Update for Legion Patch 7.2 - Pins for quests detected from the flight map should properly update as needed. - Fixed dropdown menu configurations not getting applied. - Added a toggle button to the world map display that performs the same function as the 'Enable' option in the dropdown menu. - Rewrote the majority of display update handlers for a significant performance improvements while interacting with the world map. - AP token info should now reflect artifact knowledge changes.
author Nenue
date Sat, 01 Apr 2017 08:17:30 -0400
parents e43e10c5576b
children 31de7e9e7849
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
Nick@64 16 local SpellCanTargetQuest = SpellCanTargetQuest
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@40 28 local PinBaseIndex = 1200
Nenue@33 29 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 30 local WORLD_QUEST_MAPS = { [DALARAN_ID] = 'Dalaran70', [AZSUNA_ID] = 'Azsuna', [VALSHARAH_ID] = "Val'sharah",
Nenue@33 31 [HIGHMOUNTAIN_ID] = 'Highmountain', [STORMHEIM_ID] = 'Stormheim', [SURAMAR_ID] = 'Suramar', [EOA_ID] = 'EyeOfAszhara', }
Nenue@33 32
Nenue@33 33 local REWARD_CASH = WORLD_QUEST_REWARD_TYPE_FLAG_GOLD
Nenue@33 34 local REWARD_ARTIFACT_POWER = WORLD_QUEST_REWARD_TYPE_FLAG_ARTIFACT_POWER
Nenue@33 35 local REWARD_GEAR = WORLD_QUEST_REWARD_TYPE_FLAG_EQUIPMENT
Nenue@33 36 local REWARD_CURRENCY = WORLD_QUEST_REWARD_TYPE_FLAG_ORDER_RESOURCES
Nenue@33 37 local REWARD_REAGENT = WORLD_QUEST_REWARD_TYPE_FLAG_MATERIALS
Nenue@66 38 local SCALE_FACTORS = {
Nenue@66 39 0.25, 0.7, 1
Nenue@66 40 }
Nenue@33 41
Nenue@67 42 local ToggleButton = {}
Nenue@65 43 local numShown = 0
Nenue@65 44 local numLoaded = 0
Nenue@65 45 local isDataLoaded
Nenue@33 46 local numPins = 0
Nenue@33 47 local NumPinFrames = 1
Nenue@66 48 local scaleConstant = 1
Nenue@45 49 Module.TasksByID = {}
Nenue@33 50
Nenue@33 51 --%debug%
Nenue@33 52 local SetTimedCallbackForAllPins = function(seconds, callback)
Nenue@33 53 C_Timer.After(seconds, function()
Nenue@33 54 for id, pin in pairs(WorldPlanQuests.QuestsByID) do
Nenue@33 55 callback(pin)
Nenue@33 56 end
Nenue@33 57 end)
Nenue@33 58 end
Nenue@33 59
Nenue@45 60 function Module:OnUpdate(sinceLast)
Nenue@67 61
Nenue@67 62 if self.filtersDirty or self.isStale then
Nenue@40 63 self:Refresh()
Nenue@40 64 end
Nenue@67 65 if #db.UpdatedPins >= 1 then
Nenue@67 66 print('|cFF00FF88pending updates', #db.UpdatedPins)
Nenue@67 67 self:UpdateQueuedPins()
Nenue@67 68 end
Nenue@67 69
Nenue@40 70 end
Nenue@40 71
Nenue@67 72 local currentScale = WorldMapDetailFrame:GetScale()
Nenue@67 73 function Module:RefreshIfChanged()
Nenue@67 74 local scaleCheck = WorldMapDetailFrame:GetScale()
Nenue@67 75 if scaleCheck ~= currentScale then
Nenue@67 76 print('|cFF00FF88scale changed from', currentScale, 'to', scaleCheck)
Nenue@67 77 self:Refresh()
Nenue@67 78 currentScale = scaleCheck
Nenue@67 79 end
Nenue@52 80 end
Nenue@52 81
Nenue@45 82 function Module:Setup()
Nenue@40 83 print('|cFFFF4400'..self:GetName()..':Setup()')
Nenue@33 84
Nenue@33 85 for mapID, mapName in pairs(WORLD_QUEST_MAPS) do
Nenue@40 86 db.QuestsByZone[mapID] = {}
Nenue@33 87 end
Nenue@33 88
Nenue@45 89 hooksecurefunc("ClickWorldMapActionButton", function () self:OnClickWorldMapActionButton() end)
Nenue@67 90 hooksecurefunc("WorldMapScrollFrame_ReanchorQuestPOIs", function()
Nenue@67 91 print("WorldMapScrollFrame_ReanchorQuestPOIs")
Nenue@67 92 self:RefreshIfChanged()
Nenue@67 93 end)
Nenue@67 94 hooksecurefunc("WorldMap_UpdateQuestBonusObjectives", function ()
Nenue@67 95 self:OnUpdateQuestBonusObjectives()
Nenue@67 96 end)
Nenue@67 97 hooksecurefunc("WorldMapFrame_UpdateMap", function()
Nenue@67 98 print("WorldMapFrame_UpdateMap")
Nenue@67 99 self:RefreshIfChanged()
Nenue@67 100 end)
Nenue@67 101 WorldMapFrame.UIElementsFrame.BountyBoard:SetSelectedBountyChangedCallback(function()
Nenue@67 102 self:OnSelectedBountyChanged()
Nenue@67 103 end);
Nenue@67 104 WorldMapFrame.UIElementsFrame.ActionButton:SetOnCastChangedCallback(function()
Nenue@67 105 print("CastChangedCallback")
Nenue@67 106 self:Refresh(true)
Nenue@67 107 end);
Nenue@65 108
Nenue@65 109 self.Status = CreateFrame('Frame', nil, self)
Nenue@65 110 self.Status:SetPoint('TOPLEFT', WorldMapPOIFrame, 'TOPLEFT', 0, 0)
Nenue@65 111 self.Status:SetPoint('BOTTOMRIGHT', WorldMapPOIFrame, 'TOPRIGHT', 0, -4)
Nenue@65 112 self.Status.t = self.Status:CreateTexture(nil, 'OVERLAY')
Nenue@65 113 self.Status.b = self.Status:CreateTexture(nil, 'BACKGROUND')
Nenue@65 114 self.Status.b:SetColorTexture(0,0,0,.25)
Nenue@65 115 self.Status.b:SetAllPoints(self.Status)
Nenue@65 116 self.Status.t:SetColorTexture(1,1,1,.5)
Nenue@65 117 self.Status.t:SetPoint('TOP')
Nenue@65 118 self.Status.t:SetPoint('BOTTOM')
Nenue@65 119 self.Status.t:SetPoint('LEFT')
Nenue@65 120 local translationEnd, translationStart
Nenue@65 121 self.Status:SetScript('OnUpdate', function(status)
Nenue@65 122 local translateTo
Nenue@65 123 if numLoaded < numShown then
Nenue@65 124 translateTo = numLoaded/numShown * status:GetWidth()
Nenue@65 125 status.t:SetWidth(translateTo)
Nenue@65 126 else
Nenue@65 127 translateTo = numShown * status:GetWidth()
Nenue@65 128 status.t:SetWidth(translateTo)
Nenue@65 129 end
Nenue@65 130
Nenue@65 131
Nenue@65 132 end)
Nenue@67 133
Nenue@67 134 self:SetAllPoints(WorldMapPOIFrame)
Nenue@67 135 for k,v in pairs( ToggleButton) do
Nenue@67 136 self.Toggle:SetScript(k,v)
Nenue@67 137 end
Nenue@67 138 self:Show()
Nenue@67 139 end
Nenue@67 140
Nenue@67 141 local GetQuestBountyInfoForMapID, GetQuestLogTitle, GetQuestLogIndexByID, IsQuestFlaggedCompleted = GetQuestBountyInfoForMapID, GetQuestLogTitle, GetQuestLogIndexByID, IsQuestFlaggedCompleted
Nenue@67 142 function Module:UpdateBountyInfo()
Nenue@67 143 wipe(db.BountyInfo)
Nenue@67 144 db.selectedBounty = nil
Nenue@67 145
Nenue@67 146 local selectedBounty = WorldMapFrame.UIElementsFrame.BountyBoard:GetSelectedBountyIndex()
Nenue@67 147 local bounties, numBounties = GetQuestBountyInfoForMapID(db.currentMapID)
Nenue@67 148
Nenue@67 149 for index, data in ipairs(bounties) do
Nenue@67 150 if data.factionID then
Nenue@67 151 data.title = GetQuestLogTitle(GetQuestLogIndexByID(data.questID))
Nenue@67 152 data.complete = IsQuestFlaggedCompleted(data.questID)
Nenue@67 153 db.BountyInfo[data.factionID] = data
Nenue@67 154 if index == selectedBounty then
Nenue@67 155 db.selectedBounty = data
Nenue@67 156 end
Nenue@67 157 end
Nenue@67 158 end
Nenue@67 159
Nenue@67 160 for questID, pin in pairs(db.QuestsByID) do
Nenue@67 161 local doUpdate
Nenue@67 162 if pin.factionID and db.BountyInfo[pin.factionID] then
Nenue@67 163 if not pin.isCriteria then
Nenue@67 164 pin.isCriteria = true
Nenue@67 165 doUpdate = true
Nenue@67 166 end
Nenue@67 167 else
Nenue@67 168 if pin.isCriteria then
Nenue@67 169 doUpdate = true
Nenue@67 170 pin.isCriteria = nil
Nenue@67 171 end
Nenue@67 172 end
Nenue@67 173 if doUpdate then
Nenue@67 174 if pin:IsVisible() then
Nenue@67 175 pin:Refresh()
Nenue@67 176 else
Nenue@67 177 pin.isStale = true
Nenue@67 178 end
Nenue@67 179 end
Nenue@67 180 end
Nenue@67 181 db.BountyUpdate = nil
Nenue@67 182 end
Nenue@67 183
Nenue@67 184 function Module:OnSelectedBountyChanged()
Nenue@67 185 self:UpdateBountyInfo()
Nenue@45 186 end
Nenue@33 187
Nenue@49 188 function Module:OnConfigUpdate()
Nenue@67 189 print('|cFFFFFF00OnConfigUpdate()|r')
Nenue@49 190 if db.Config.FadeWhileGrouped then
Nenue@49 191 db.PinAlpha = 0.15
Nenue@49 192 else
Nenue@49 193 db.PinAlpha = 1
Nenue@49 194 end
Nenue@67 195
Nenue@67 196 if not db.Config.EnablePins then
Nenue@67 197 for _, pin in pairs(db.QuestsByID) do
Nenue@67 198 pin:SetShown(false)
Nenue@67 199 end
Nenue@67 200 end
Nenue@67 201
Nenue@67 202 ToggleButton.OnShow(self.Toggle)
Nenue@49 203 end
Nenue@49 204
Nenue@45 205 local InternalHideButton = function(button, index)
Nenue@45 206 button:Hide()
Nenue@45 207 if button.questID and db.QuestsByID[button.questID] then
Nenue@45 208 if db.QuestsByID[button.questID].used and not db.QuestsByID[button.questID].filtered then
Nenue@45 209 db.QuestsByID[button.questID]:SetShown(true)
Nenue@45 210 end
Nenue@45 211 end
Nenue@45 212 end
Nenue@45 213 local InternalShowButton = function(button, index)
Nenue@45 214 button:Show()
Nenue@45 215 if button.questID and db.QuestsByID[button.questID] then
Nenue@45 216 db.QuestsByID[button.questID]:SetShown(false)
Nenue@45 217 end
Nenue@45 218 end
Nenue@33 219
Nick@62 220 function Module:UpdateBlizzButtons()
Nick@62 221
Nenue@45 222 local func = SpellCanTargetQuest() and InternalShowButton or InternalHideButton
Nenue@45 223 for i = 1, NUM_WORLDMAP_TASK_POIS do
Nenue@45 224 local button = _G['WorldMapFrameTaskPOI'..i]
Nenue@45 225 if button and button.worldQuest then
Nenue@45 226 func(button, i)
Nenue@45 227 end
Nenue@45 228 end
Nenue@45 229 end
Nenue@40 230
Nick@62 231 function Module:OnUpdateQuestBonusObjectives()
Nenue@67 232 rprint('|cFFFF4400WorldMap_UpdateQuestBonusObjectives')
Nick@62 233 self:UpdateBlizzButtons()
Nick@62 234 end
Nick@62 235
Nenue@45 236 function Module:OnClickWorldMapActionButton()
Nenue@67 237 rprint('|cFFFF4400ClickWorldMapActionButton')
Nick@62 238 self:UpdateBlizzButtons()
Nenue@45 239 end
Nenue@40 240
Nenue@33 241 local defaults = {}
Nenue@40 242 local REWARD_UNKNOWN = 768
Nenue@45 243 function Module:OnLoad()
Nenue@40 244 print('|cFFFF4400'..self:GetName()..':OnLoad()')
Nenue@33 245
Nenue@48 246 self:SetParent(WorldMapPOIFrame)
Nenue@33 247 WorldPlan:AddHandler(self, defaults)
Nenue@33 248
Nenue@33 249 for areaID, fileName in pairs(WORLD_QUEST_MAPS) do
Nenue@40 250 db.QuestsByZone[areaID] = {}
Nenue@33 251 end
Nenue@33 252
Nenue@41 253 -- WORLD_MAP_UPDATE and PLAYER_ENTERING_WORLD are passed down from a higher level
Nenue@33 254 self:RegisterEvent('WORLD_QUEST_COMPLETED_BY_SPELL')
Nenue@55 255 self:RegisterEvent('SUPER_TRACKED_QUEST_CHANGED')
Nenue@33 256 self:RegisterEvent('SKILL_LINES_CHANGED')
Nick@62 257 self:RegisterEvent('CURRENT_SPELL_CAST_CHANGED')
Nenue@33 258 end
Nenue@33 259
Nenue@67 260 function Module:OnMapInfo(isBrokenIsle, isZoomedOut, mapAreaID, isNewMap, isMapOpen)
Nenue@67 261
Nenue@67 262 print('|cFFFFFF00'..self:GetName()..':OnMapInfo()|r, mapAreaID =', mapAreaID,'visible =', isMapOpen, 'changed =', isNewMap)
Nenue@67 263
Nenue@67 264 if db.BountyUpdate then
Nenue@67 265 self:UpdateBountyInfo()
Nenue@67 266 end
Nenue@67 267 if isNewMap then
Nenue@67 268 print('|cFF00FF88refreshing for changed map')
Nenue@67 269 if isMapOpen then
Nenue@67 270 self:Refresh(true)
Nenue@67 271 else
Nenue@67 272 self.isStale = true
Nenue@67 273 end
Nenue@54 274 end
Nenue@56 275
Nenue@41 276 end
Nenue@65 277 local superTrackedQuestID
Nenue@45 278 function Module:OnEvent (event, ...)
Nenue@40 279
Nenue@40 280 print('|cFFFFFF00'..self:GetName()..':OnEvent() '..event..'|r', GetTime(), ...)
Nenue@55 281 if (event == 'QUEST_LOG_UPDATE') or (event == 'SUPER_TRACKED_QUEST_CHANGED') then
Nenue@33 282 local questID, added = ...
Nenue@33 283 if questID and added then
Nenue@33 284 local questPOI = self:AcquirePin(questID)
Nenue@40 285 questPOI:GetQuestInfo()
Nenue@40 286 questPOI.isStale = true
Nenue@40 287 self.isStale = true
Nenue@33 288 else
Nick@62 289 self:Refresh()
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
Nick@62 306 pin.dataLoaded = nil
Nick@62 307 end
Nick@62 308 self:Refresh()
Nenue@59 309 end
Nenue@65 310 elseif event == 'SUPER_TRACKED_QUEST_CHANGED' then
Nenue@65 311 if superTrackedQuestID and db.QuestsByID[superTrackedQuestID] then
Nenue@65 312 db.QuestsByID[superTrackedQuestID].isStale = true
Nenue@65 313 end
Nenue@65 314 local newID = GetSuperTrackedQuestID()
Nenue@65 315 if newID and db.QuestsByID[newID] then
Nenue@65 316 db.QuestsByID[newID].isStale = true
Nenue@65 317 end
Nenue@33 318 end
Nenue@33 319 end
Nenue@33 320
Nenue@40 321 local totalPins = 0
Nenue@33 322 local TQ_GetQuestLocation = C_TaskQuest.GetQuestLocation
Nenue@45 323 function Module:AcquirePin (info)
Nenue@40 324 local questID = info.questId
Nenue@40 325 if not questID then
Nenue@40 326 return nil
Nenue@40 327 end
Nenue@40 328
Nenue@40 329 if not QuestUtils_IsQuestWorldQuest(questID) then
Nenue@40 330 return nil
Nenue@40 331 end
Nenue@40 332
Nenue@49 333 -- if we're grabbing a pin, the filters need to be checked
Nenue@40 334 local pin = db.QuestsByID[questID]
Nenue@33 335 if not pin then
Nenue@40 336 local numFree = #db.FreePins
Nenue@33 337 if numFree >= 1 then
Nenue@40 338 pin = tremove(db.FreePins, numFree)
Nenue@33 339 --print('|cFF00FF00Re-using', pin:GetName())
Nenue@33 340 else
Nenue@40 341 totalPins = totalPins + 1
Nenue@33 342 local name = 'WorldPlanQuestMarker' .. NumPinFrames
Nenue@33 343 --print('|cFF00FF00Creating', name)
Nenue@33 344 pin = CreateFrame('Frame', name, WorldMapPOIFrame, 'WorldPlanQuestPin')
Nenue@33 345
Nenue@33 346 pin:SetFrameStrata('HIGH')
Nenue@33 347 pin.GetTypeInfo = function(frame, typeID)
Nenue@33 348 return self:GetTypeInfo(typeID)
Nenue@33 349 end
Nenue@40 350 pin:SetID(totalPins)
Nenue@33 351 NumPinFrames = NumPinFrames + 1
Nenue@33 352 --pin.iconBorder:SetVertexColor(0,0,0,1)
Nenue@33 353 end
Nenue@40 354 pin.questID = questID
Nenue@40 355 pin.worldQuest = true
Nenue@40 356 pin.throttle = 1
Nenue@33 357 pin.isNew = true
Nenue@33 358 pin.currentWidth = nil
Nenue@40 359 db.QuestsByID[questID] = pin
Nenue@40 360 tinsert(db.UsedPins, pin)
Nenue@40 361 end
Nenue@33 362
Nenue@40 363 if pin and info then
Nenue@40 364 pin.inProgress = info.inProgress
Nenue@40 365 pin.floor = info.floor
Nenue@40 366 pin.numObjectives = info.numObjectives or 0
Nenue@40 367 if info.x and info.y then
Nenue@40 368 pin.x = info.x or pin.x
Nenue@40 369 pin.y = info.y or pin.y
Nenue@40 370 rprint('|cFFFF4400coords|r', info.x, info.y)
Nenue@40 371 end
Nenue@40 372 end
Nenue@33 373
Nick@62 374 if (not pin.dataLoaded) then
Nenue@65 375 local dataLoaded = pin:GetData()
Nenue@65 376 isDataLoaded = (isDataLoaded and dataLoaded)
Nick@63 377 WorldPlan.dataFlush = true
Nenue@49 378 end
Nenue@49 379
Nenue@66 380
Nick@64 381 pin.isActive = TQ_IsActive(questID)
Nenue@57 382 pin:CheckFilterRules()
Nenue@49 383 rprint(pin:GetID(), pin.filtered, pin.used)
Nenue@67 384 pin:SetShown(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@67 523 pin = tremove(db.UpdatedPins)
Nenue@67 524 end
Nenue@67 525 end
Nenue@67 526
Nenue@33 527 -- create of update quest pins for a map and its underlying zones
Nenue@45 528 function Module:UpdateWorldQuests (mapID)
Nenue@40 529
Nenue@40 530 mapID = mapID or db.currentMapID
Nenue@33 531 if not mapID then
Nenue@33 532 -- info not available yet
Nenue@33 533 return
Nenue@33 534 end
Nenue@33 535
Nenue@66 536 local scalingConstant = 1
Nenue@66 537 local style = DEFAULT_STYLE
Nenue@66 538 if self.dataLoaded then
Nenue@66 539 style = REWARD_TYPE_STYLES[self.rewardType]
Nenue@66 540 scalingConstant = db.isContinentMap and 2 or 3
Nenue@66 541 end
Nenue@66 542
Nenue@66 543 local pinScale = SCALE_FACTORS[scalingConstant]
Nenue@66 544 print(pinScale)
Nenue@66 545 self:SetScale(pinScale)
Nenue@66 546 self.Overlay:SetScale(pinScale)
Nenue@34 547
Nenue@40 548 print('|cFF00FF88'..self:GetName()..':UpdateWorldQuests()|r', 'map:', mapID, 'realMap:', db.currentMapID)
Nenue@33 549
Nenue@40 550
Nenue@40 551 self.isStale = nil
Nenue@40 552 print('|cFF00FFFFContinent:|r', BROKEN_ISLES_ID, GetMapNameByID(BROKEN_ISLES_ID))
Nenue@40 553 self.isRecursed = true
Nenue@40 554 for i = 1, MC_GetNumZones(BROKEN_ISLES_ID) do
Nenue@40 555 local submapID, name, depth = MC_GetZoneInfo(BROKEN_ISLES_ID, i)
Nenue@40 556 local taskInfo = TQ_GetQuestsForPlayerByMapID(submapID, BROKEN_ISLES_ID)
Nenue@40 557 if taskInfo then
Nenue@40 558 local zoneName = GetMapNameByID(submapID)
Nenue@40 559 print('|cFF00FFFF Zone:|r', submapID, zoneName, #taskInfo)
Nenue@40 560 db.QuestsByZone[submapID] = db.QuestsByZone[submapID] or {}
Nenue@40 561 for i, info in ipairs(taskInfo) do
Nenue@40 562 if HaveQuestData(info.questId) then
Nenue@40 563 rprint('|cFF44FF44update|r', info.questId, zoneName)
Nenue@40 564 local questID = info.questId
Nenue@40 565 local pin = self:AcquirePin(questID)
Nenue@40 566 local pin = db.QuestsByID[questID]
Nenue@40 567 if pin then
Nenue@40 568 pin.isStale = true
Nenue@40 569 if pin.isPending then
Nenue@40 570 self.isPending = true
Nenue@40 571 end
Nenue@40 572 end
Nenue@40 573 else
Nenue@40 574 rprint('|cFFFF4400no data|r', info.questId, zoneName)
Nenue@40 575 end
Nenue@33 576 end
Nenue@33 577 end
Nenue@33 578 end
Nenue@33 579
Nenue@40 580 self:GetBonusObjectives()
Nenue@40 581
Nenue@40 582 print(' hasUpdate:', self.isStale, 'isPending:', self.isPending, 'timer:', (self.OnNext and 'waiting' or ''))
Nenue@40 583 --WorldPlan.isStale = (self.isStale or WorldPlan.isStale)
Nenue@40 584 if self.isStale and self:IsVisible() then
Nenue@40 585 self:Refresh()
Nenue@40 586 end
Nick@63 587
Nenue@40 588 end
Nenue@40 589
Nenue@45 590 function Module:Report()
Nenue@40 591 for i, pin in ipairs(db.UsedPins) do
Nenue@40 592 db:print(i, pin.questID, pin.title)
Nenue@33 593 end
Nenue@33 594
Nenue@40 595 for id, pin in pairs(db.QuestsByID) do
Nenue@40 596 db:print(id, pin.worldQuestType, pin.rewardType, pin.title)
Nenue@40 597 end
Nenue@33 598 end
Nenue@33 599
Nenue@67 600 local bountiesInitialized
Nenue@67 601 function Module:Refresh(...)
Nenue@67 602 rprint('|cFF00FF88'..self:GetName()..':Refresh()|r', ...)
Nenue@67 603 print('|cFF00FF88'..self:GetName()..':Refresh()|r', ...)
Nenue@34 604 if not self:IsVisible() then
Nenue@40 605 print(' not visible, flag for later')
Nenue@34 606 self.isStale = true
Nenue@57 607 return self:MarkAllPins()
Nenue@40 608 end
Nenue@67 609 if not db.Config.EnablePins then
Nenue@67 610 return
Nenue@67 611 end
Nenue@67 612
Nenue@67 613
Nick@60 614 wprint(' |cFF00FF88'..self:GetName()..':Refresh()|r')
Nenue@40 615
Nenue@66 616 scaleConstant = db.isContinentMap and 2 or 3
Nenue@40 617 for index, pin in pairs(db.QuestsByID) do
Nenue@40 618 pin.used = nil
Nenue@40 619 end
Nenue@40 620
Nick@62 621 if SpellCanTargetQuest() then
Nick@62 622 self:UpdateBlizzButtons()
Nick@62 623 else
Nick@62 624 self:UpdateAnchors(nil)
Nick@62 625 end
Nick@60 626
Nick@60 627 --local showQuestPOI = db.Config.EnablePins
Nenue@65 628 numShown = 0
Nenue@65 629 numLoaded = 0
Nick@60 630 for questID, pin in pairs(db.QuestsByID) do
Nick@60 631 local oV = pin:IsShown()
Nick@60 632 if pin.used then
Nick@60 633 pin.throttle = 1
Nick@60 634 if oV == false then
Nenue@67 635 rprint('|cFF00FF00cleanup +|r', questID, pin.title)
Nick@60 636 end
Nick@60 637 pin:SetShown(true)
Nenue@65 638 numShown = numShown + 1
Nenue@65 639 if pin.dataLoaded then
Nenue@65 640 numLoaded = numLoaded + 1
Nenue@65 641 end
Nenue@65 642
Nick@60 643 else
Nick@60 644 if oV == true then
Nenue@67 645 rprint('|cFFFF4400 -|r', questID, pin.title)
Nick@60 646 end
Nick@62 647 pin:HideFrames()
Nick@60 648 end
Nick@60 649 end
Nick@60 650
Nenue@67 651 print(numShown, 'shown', numLoaded, 'loaded')
Nenue@65 652 if numShown > numLoaded then
Nenue@65 653 self.Status:Show()
Nenue@65 654 end
Nenue@65 655
Nenue@65 656
Nenue@40 657 self.isStale = nil
Nenue@54 658 self.sizesDirty = nil
Nenue@66 659 self.isZoomDirty = nil
Nenue@40 660 end
Nenue@40 661
Nenue@40 662 -- update visibility states of all pins
Nenue@57 663 function Module:MarkAllPins(pins)
Nenue@57 664 print(' |cFFFFFF00'..self:GetName()..':MarkAllPins()|r', pins)
Nenue@40 665 pins = pins or db.QuestsByID
Nenue@40 666 for questID, pin in pairs(pins) do
Nenue@40 667 pin.isStale = true
Nenue@40 668 rprint('|cFF00FF00filter', pin.questID, pin.filtered, 'used:', pin.used)
Nenue@40 669 end
Nenue@40 670 end
Nenue@40 671
Nenue@45 672 function Module:UpdateQuestButton(info, mapID)
Nenue@40 673 local questID, x, y = info.questId, info.x, info.y
Nenue@40 674 local pin = self:AcquirePin(info)
Nenue@40 675 if not pin then
Nenue@34 676 return
Nenue@34 677 end
Nenue@34 678
Nenue@33 679
Nenue@67 680 --print(' |- ', pin.questID, pin.title)
Nenue@57 681 rprint('|cFF00FF00update|r', pin.questID, pin.title)
Nenue@40 682
Nenue@40 683 if x and y then
Nenue@66 684 local scaleFactor = SCALE_FACTORS[(pin.dataLoaded and not pin.filtered) and scaleConstant or 1]
Nenue@49 685 pin:SetFrameLevel(PinBaseIndex+pin:GetID())
Nenue@57 686 pin.owningFrame = WorldMapFrame
Nenue@66 687 pin:SetAnchor(WorldMapPOIFrame, x, y, self.hostWidth, self.hostHeight, scaleFactor)
Nenue@54 688 --tinsert(self.UsedPositions, pin)
Nenue@40 689 end
Nenue@66 690
Nenue@66 691
Nenue@66 692 if self:IsVisible() and (pin.isStale) then
Nenue@57 693 pin:Refresh()
Nenue@54 694 end
Nenue@40 695 if mapID then
Nenue@40 696 if not db.QuestsByZone[mapID] then
Nenue@40 697 db.QuestsByZone[mapID] = {}
Nenue@40 698 end
Nenue@40 699 db.QuestsByZone[mapID][questID] = pin
Nenue@33 700 end
Nenue@33 701 end
Nenue@33 702
Nenue@45 703 function Module:UpdateMap(taskInfo, mapID)
Nenue@49 704 rprint('Map', GetMapNameByID(mapID), GetMapNameByID(db.currentMapID))
Nenue@40 705 for index, info in pairs(taskInfo) do
Nenue@40 706 self:UpdateQuestButton(info, mapID)
Nenue@40 707 end
Nenue@40 708 end
Nenue@33 709
Nick@60 710 function Module:UpdateAnchors ()
Nenue@65 711
Nenue@40 712 wipe(self.UsedPositions)
Nick@60 713 print(' |cFF00FF00'..self:GetName()..':UpdateAnchors()')
Nenue@57 714 self.hostWidth, self.hostHeight = WorldMapPOIFrame:GetSize()
Nenue@40 715 self.nudgeThrescholdX = 16/self.hostWidth
Nenue@40 716 self.nudgeThrescholdY = 16/self.hostHeight
Nenue@67 717
Nenue@67 718 rprint('|cFF00FF00'..self:GetName()..':UpdateAnchors()')
Nenue@33 719 local mapFileName, textureHeight, textureWidth, isMicroDungeon, microDungeonMapName = GetMapInfo()
Nenue@33 720 if isMicroDungeon then
Nenue@33 721 return
Nenue@33 722 end
Nenue@65 723 -- starts as true
Nenue@65 724 isDataLoaded = true
Nick@62 725
Nenue@40 726 numPins = 0
Nenue@67 727 local taskInfo = TQ_GetQuestsForPlayerByMapID(db.currentMapID)
Nenue@40 728 if taskInfo then
Nenue@67 729 self:UpdateMap(taskInfo, db.currentMapID)
Nenue@33 730 end
Nenue@67 731 local numZones = MC_GetNumZones(db.currentMapID)
Nenue@33 732 if numZones then
Nenue@33 733 for i = 1, numZones do
Nenue@67 734 local mapAreaID = MC_GetZoneInfo(db.currentMapID, i)
Nenue@67 735 local taskInfo = TQ_GetQuestsForPlayerByMapID(mapAreaID, db.currentMapID)
Nenue@40 736 if taskInfo then
Nenue@40 737 self:UpdateMap(taskInfo, mapAreaID)
Nenue@40 738 end
Nenue@33 739 end
Nenue@33 740 end
Nenue@33 741 end
Nenue@33 742
Nenue@67 743 function ToggleButton:OnShow()
Nenue@67 744 self:SetChecked(db.Config.EnablePins and true or false)
Nenue@67 745 end
Nenue@67 746 function ToggleButton:OnClick()
Nenue@67 747 print(self:GetChecked())
Nenue@67 748 db.Config.EnablePins = self:GetChecked()
Nenue@67 749 _G.WorldPlan:OnConfigUpdate()
Nenue@67 750 end