annotate WorldQuests.lua @ 86:effb42f6fabd v1.4.6

- Fixed pins not returning to WorldMapFrame after the FlightMap is opened
author Nenue
date Mon, 10 Apr 2017 18:05:36 -0400
parents a12f782571c5
children 77013bd72adb
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@72 5
Nenue@75 6 local print = DEVIAN_WORKSPACE and function(...) _G.print('WorldQuests', ...) end or nop
Nenue@75 7 local rprint = DEVIAN_WORKSPACE and function(...) _G.print('WQRefresh', ...) end or nop
Nenue@75 8 local qprint = DEVIAN_WORKSPACE and function(...) _G.print('POI', ...) end or nop
Nenue@75 9 local wprint = DEVIAN_WORKSPACE and function(...) _G.print('WP', ...) end or nop
Nenue@75 10 local mprint = DEVIAN_WORKSPACE and function(...) _G.print('Canvas', ...) end or nop
Nenue@40 11 local _, db = ...
Nenue@45 12 local Module = WorldPlanQuestsMixin
Nenue@33 13
Nick@64 14 local _G = _G
Nenue@72 15 local type, tostring, tonumber, pairs, ipairs = type, tostring, tonumber, pairs, ipairs
Nenue@33 16 local MC_GetNumZones, MC_GetZoneInfo = C_MapCanvas.GetNumZones, C_MapCanvas.GetZoneInfo
Nenue@33 17 local TQ_GetQuestsForPlayerByMapID = C_TaskQuest.GetQuestsForPlayerByMapID -- This function is not yet documented
Nenue@33 18 local TQ_GetQuestZoneID = C_TaskQuest.GetQuestZoneID
Nick@64 19 local TQ_IsActive = C_TaskQuest.IsActive
Nenue@75 20 local TQ_RequestPreloadRewardData = C_TaskQuest.RequestPreloadRewardData
Nick@64 21 local pairs, ipairs, tinsert, tremove, wipe = pairs, ipairs, tinsert, tremove, table.wipe
Nick@64 22 local GetTaskInfo, GetTasksTable, HaveQuestData = GetTaskInfo, GetTasksTable, HaveQuestData
Nick@64 23 local GetTime = GetTime
Nenue@69 24 local SpellCanTargetQuest, IsQuestIDValidSpellTarget = SpellCanTargetQuest, IsQuestIDValidSpellTarget
Nick@64 25 local tonumber, abs = tonumber, math.abs
Nick@64 26 local GetQuestLogRewardInfo = GetQuestLogRewardInfo
Nick@64 27 local GetCurrentMapAreaID, GetMapInfo, GetMapNameByID = GetCurrentMapAreaID, GetMapInfo, GetMapNameByID
Nenue@72 28 local GetQuestBountyInfoForMapID, GetQuestLogTitle, GetQuestLogIndexByID, IsQuestComplete = GetQuestBountyInfoForMapID, GetQuestLogTitle, GetQuestLogIndexByID, IsQuestComplete
Nenue@72 29 local IsQuestCriteriaForBounty = IsQuestCriteriaForBounty
Nenue@33 30
Nenue@69 31 local ToggleButton = {}
Nenue@69 32 local callbacks = {}
Nenue@33 33 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 34 local WORLD_QUEST_MAPS = { [DALARAN_ID] = 'Dalaran70', [AZSUNA_ID] = 'Azsuna', [VALSHARAH_ID] = "Val'sharah",
Nenue@33 35 [HIGHMOUNTAIN_ID] = 'Highmountain', [STORMHEIM_ID] = 'Stormheim', [SURAMAR_ID] = 'Suramar', [EOA_ID] = 'EyeOfAszhara', }
Nenue@33 36
Nenue@33 37 local REWARD_CASH = WORLD_QUEST_REWARD_TYPE_FLAG_GOLD
Nenue@33 38 local REWARD_ARTIFACT_POWER = WORLD_QUEST_REWARD_TYPE_FLAG_ARTIFACT_POWER
Nenue@33 39 local REWARD_GEAR = WORLD_QUEST_REWARD_TYPE_FLAG_EQUIPMENT
Nenue@33 40 local REWARD_CURRENCY = WORLD_QUEST_REWARD_TYPE_FLAG_ORDER_RESOURCES
Nenue@33 41 local REWARD_REAGENT = WORLD_QUEST_REWARD_TYPE_FLAG_MATERIALS
Nenue@72 42 local SCALE_FACTORS = { 0.25, 0.7, 1 }
Nenue@33 43
Nenue@72 44 local BountyBoard = WorldMapFrame.UIElementsFrame.BountyBoard
Nenue@72 45 local ActionButton = WorldMapFrame.UIElementsFrame.ActionButton
Nenue@72 46
Nenue@75 47 local pinBaseIndex = 1500
Nenue@75 48 local overlayBaseIndex = 1580
Nenue@72 49 local layoutDirty = true
Nenue@72 50 local bountiesDirty = true
Nenue@69 51 local currentScale = WorldMapDetailFrame:GetScale()
Nenue@69 52 local canTargetQuests
Nenue@65 53 local numShown = 0
Nenue@65 54 local numLoaded = 0
Nenue@69 55 local isDataLoaded = true
Nenue@69 56 local numOverlays = 1
Nenue@66 57 local scaleConstant = 1
Nenue@45 58 Module.TasksByID = {}
Nenue@33 59
Nenue@33 60 --%debug%
Nenue@33 61 local SetTimedCallbackForAllPins = function(seconds, callback)
Nenue@33 62 C_Timer.After(seconds, function()
Nenue@33 63 for id, pin in pairs(WorldPlanQuests.QuestsByID) do
Nenue@33 64 callback(pin)
Nenue@33 65 end
Nenue@33 66 end)
Nenue@33 67 end
Nenue@33 68
Nenue@52 69
Nenue@45 70 function Module:Setup()
Nenue@75 71 --print('|cFFFF4400'..self:GetName()..':Setup()')
Nenue@33 72 for mapID, mapName in pairs(WORLD_QUEST_MAPS) do
Nenue@40 73 db.QuestsByZone[mapID] = {}
Nenue@33 74 end
Nenue@69 75 for target, arg in pairs(callbacks) do
Nenue@75 76 --print(type(target))
Nenue@69 77 if type(target) == 'table' then
Nenue@71 78 local callerName = target:GetName() or tostring(target)
Nenue@69 79 for name, method in pairs(arg) do
Nenue@75 80 --print(callerName, arg)
Nenue@69 81 hooksecurefunc(target, name, function(...)
Nenue@71 82 self:OnSecureHook(callerName .. '.' .. name, method, ...)
Nenue@69 83 end)
Nenue@69 84 end
Nenue@69 85 else
Nenue@69 86 hooksecurefunc(target, function(...)
Nenue@69 87 self:OnSecureHook(target, arg, ...)
Nenue@69 88 end)
Nenue@69 89 end
Nenue@69 90 end
Nenue@65 91
Nenue@65 92 self.Status = CreateFrame('Frame', nil, self)
Nenue@75 93 self.Status:SetPoint('TOPLEFT', WorldMapFrame.UIElementsFrame, 'TOPLEFT', 0, 0)
Nenue@75 94 self.Status:SetPoint('BOTTOMRIGHT', WorldMapFrame.UIElementsFrame, 'TOPRIGHT', 0, -4)
Nenue@65 95 self.Status.t = self.Status:CreateTexture(nil, 'OVERLAY')
Nenue@65 96 self.Status.b = self.Status:CreateTexture(nil, 'BACKGROUND')
Nenue@65 97 self.Status.b:SetColorTexture(0,0,0,.25)
Nenue@65 98 self.Status.b:SetAllPoints(self.Status)
Nenue@65 99 self.Status.t:SetColorTexture(1,1,1,.5)
Nenue@65 100 self.Status.t:SetPoint('TOP')
Nenue@65 101 self.Status.t:SetPoint('BOTTOM')
Nenue@65 102 self.Status.t:SetPoint('LEFT')
Nenue@65 103 local translationEnd, translationStart
Nenue@65 104 self.Status:SetScript('OnUpdate', function(status)
Nenue@65 105 local translateTo
Nenue@65 106 if numLoaded < numShown then
Nenue@75 107 translateTo = (numLoaded/numShown) * status:GetWidth()
Nenue@65 108 status.t:SetWidth(translateTo)
Nenue@65 109 else
Nenue@75 110 translateTo = status:GetWidth()
Nenue@65 111 status.t:SetWidth(translateTo)
Nenue@65 112 end
Nenue@65 113 end)
Nenue@67 114
Nenue@75 115 self:SetAllPoints(WorldMapFrame.UIElementsFrame)
Nenue@67 116 for k,v in pairs( ToggleButton) do
Nenue@67 117 self.Toggle:SetScript(k,v)
Nenue@67 118 end
Nenue@72 119
Nenue@72 120 self:UpdateBounties('SETUP')
Nenue@72 121
Nenue@67 122 self:Show()
Nenue@67 123 end
Nenue@69 124 callbacks.ClickWorldMapActionButton = function(WorldQuests)
Nenue@73 125 WorldQuests:Refresh('CLICK_MAP_ACTION_BUTTON')
Nenue@69 126 end
Nenue@69 127 callbacks.WorldMap_UpdateQuestBonusObjectives = function(WorldQuests)
Nenue@73 128 WorldQuests:UpdateTaskPOIs()
Nenue@69 129 end
Nenue@69 130 callbacks.WorldMapFrame_UpdateMap = function(WorldQuests)
Nenue@75 131 WorldQuests:RefreshIfChanged('WMF_UPDATE')
Nenue@69 132 end
Nenue@69 133 callbacks.WorldMapScrollFrame_ReanchorQuestPOIs = function (WorldQuests)
Nenue@75 134 WorldQuests:RefreshIfChanged('WMF_REANCHOR')
Nenue@69 135 end
Nenue@69 136
Nenue@72 137 callbacks[BountyBoard] = {}
Nenue@72 138 callbacks[BountyBoard].SetSelectedBountyIndex = function(WorldQuests)
Nenue@72 139 WorldQuests:UpdateBounties('BOUNTY_SELECTED')
Nenue@73 140 WorldQuests:Refresh('BOUNTY_SELECTED')
Nenue@72 141 end
Nenue@67 142
Nenue@72 143 callbacks[ActionButton] = {}
Nenue@72 144 callbacks[ActionButton].UpdateCastingState = function(WorldQuests)
Nenue@73 145 WorldQuests:Refresh('CASTING_STATE_CHANGED')
Nenue@67 146 end
Nenue@67 147
Nenue@49 148 function Module:OnConfigUpdate()
Nenue@75 149 --print('|cFFFFFF00OnConfigUpdate()|r')
Nenue@49 150 if db.Config.FadeWhileGrouped then
Nenue@49 151 db.PinAlpha = 0.15
Nenue@49 152 else
Nenue@49 153 db.PinAlpha = 1
Nenue@49 154 end
Nenue@67 155
Nenue@67 156 if not db.Config.EnablePins then
Nenue@67 157 for _, pin in pairs(db.QuestsByID) do
Nenue@67 158 pin:SetShown(false)
Nenue@67 159 end
Nenue@67 160 end
Nenue@67 161
Nenue@67 162 ToggleButton.OnShow(self.Toggle)
Nenue@49 163 end
Nenue@49 164
Nenue@45 165 local InternalHideButton = function(button, index)
Nenue@45 166 button:Hide()
Nenue@45 167 end
Nenue@45 168 local InternalShowButton = function(button, index)
Nenue@45 169 button:Show()
Nenue@45 170 end
Nenue@33 171
Nenue@69 172 function Module:OnSecureHook(callbackName, func, ...)
Nenue@75 173 --rprint('|cFFFF4400'..callbackName..'|r', ...)
Nenue@69 174 func(self, ...)
Nenue@45 175 end
Nenue@40 176
Nenue@33 177 local defaults = {}
Nenue@40 178 local REWARD_UNKNOWN = 768
Nenue@45 179 function Module:OnLoad()
Nenue@75 180 --print('|cFFFF4400'..self:GetName()..':OnLoad()')
Nenue@33 181
Nenue@75 182 self:SetParent(WorldMapFrame.UIElementsFrame)
Nenue@33 183 WorldPlan:AddHandler(self, defaults)
Nenue@33 184
Nenue@33 185 for areaID, fileName in pairs(WORLD_QUEST_MAPS) do
Nenue@40 186 db.QuestsByZone[areaID] = {}
Nenue@33 187 end
Nenue@33 188
Nenue@41 189 -- WORLD_MAP_UPDATE and PLAYER_ENTERING_WORLD are passed down from a higher level
Nenue@33 190 self:RegisterEvent('WORLD_QUEST_COMPLETED_BY_SPELL')
Nenue@55 191 self:RegisterEvent('SUPER_TRACKED_QUEST_CHANGED')
Nenue@33 192 self:RegisterEvent('SKILL_LINES_CHANGED')
Nenue@75 193 --self:RegisterEvent('CURRENT_SPELL_CAST_CHANGED')
Nenue@69 194 self:RegisterEvent('ARTIFACT_UPDATE')
Nenue@73 195 self:RegisterEvent('QUEST_LOG_UPDATE')
Nenue@33 196 end
Nenue@33 197
Nenue@72 198 local artifactKnowledgeMultiplier
Nenue@65 199 local superTrackedQuestID
Nenue@45 200 function Module:OnEvent (event, ...)
Nenue@40 201
Nenue@75 202 print('|cFFFFFF00OnEvent() '..event..'|r', GetTime(), ...)
Nenue@69 203 if (event == 'QUEST_LOG_UPDATE') then
Nenue@73 204 self:UpdateBounties(event)
Nenue@33 205 elseif event == 'WORLD_QUEST_COMPLETED_BY_SPELL' then
Nenue@33 206 local questID = ...
Nenue@40 207 if questID and db.QuestsByID[questID] then
Nenue@74 208 db.QuestsByID[questID].complete = true
Nenue@75 209 self:ReleasePin(db.QuestsByID[questID])
Nenue@33 210 end
Nenue@73 211 self:Refresh(event)
Nenue@65 212 elseif event == 'SKILL_LINES_CHANGED' or event == 'CURRENT_SPELL_CAST_CHANGED' then
Nenue@72 213 self:Refresh(event)
Nenue@59 214 elseif event == 'ARTIFACT_UPDATE' then
Nenue@72 215 local akCheck = C_ArtifactUI.GetArtifactKnowledgeMultiplier()
Nenue@72 216 if akCheck and (akCheck ~= artifactKnowledgeMultiplier) then
Nenue@72 217 if artifactKnowledgeMultiplier then
Nenue@75 218 --print('push artifact knowledge update', artifactKnowledgeMultiplier, 'to', akCheck)
Nenue@72 219 for index, pin in pairs( db.QuestsByID) do
Nenue@72 220 if pin.rewardType == REWARD_ARTIFACT_POWER then
Nenue@72 221 db.log(pin.questID .. ' ' .. tostring(pin.title) .. ' Flagged for artifact power.')
Nenue@72 222 pin.itemNumber = 0
Nenue@72 223 pin.dataLoaded = nil
Nenue@72 224 end
Nenue@69 225 end
Nenue@72 226 else
Nenue@72 227
Nenue@72 228 print('artifact knowledge multiplier is known', akCheck)
Nick@62 229 end
Nenue@72 230 artifactKnowledgeMultiplier = akCheck
Nenue@59 231 end
Nenue@65 232 elseif event == 'SUPER_TRACKED_QUEST_CHANGED' then
Nenue@65 233 if superTrackedQuestID and db.QuestsByID[superTrackedQuestID] then
Nenue@65 234 db.QuestsByID[superTrackedQuestID].isStale = true
Nenue@65 235 end
Nenue@65 236 local newID = GetSuperTrackedQuestID()
Nenue@65 237 if newID and db.QuestsByID[newID] then
Nenue@65 238 db.QuestsByID[newID].isStale = true
Nenue@65 239 end
Nenue@33 240 end
Nenue@33 241 end
Nenue@33 242
Nenue@72 243
Nenue@75 244 function Module:OnUpdate(sinceLast)
Nenue@75 245
Nenue@75 246 if self.refreshBenchMarkTicker then
Nenue@75 247 --print(self.refreshBenchMarkTicker)
Nenue@75 248 self.refreshBenchMarkTicker = self.refreshBenchMarkTicker - 1
Nenue@75 249
Nenue@75 250 if self.refreshBenchMarkTicker == 0 then
Nenue@75 251
Nenue@76 252 self.refreshTime = floor((GetTime() - self.refreshBenchMark) * 1000)
Nenue@75 253 self.debugMessage:SetText(self.refreshTime)
Nenue@75 254 self.refreshBenchMarkTicker = nil
Nenue@75 255 end
Nenue@75 256 else
Nenue@75 257 self.refreshBenchMark = GetTime()
Nenue@75 258 end
Nenue@75 259
Nenue@75 260 if self.filtersDirty or self.isStale then
Nenue@75 261 self:Refresh()
Nenue@75 262 end
Nenue@75 263 if #db.UpdatedPins >= 1 then
Nenue@75 264 --print('|cFF00FF88pending update', #db.UpdatedPins)
Nenue@75 265 self:UpdateNext()
Nenue@75 266 end
Nenue@75 267
Nenue@75 268 end
Nenue@75 269
Nenue@75 270 function Module:OnMapInfo(isBrokenIsle, isZoomedOut, mapAreaID, isNewMap, isMapOpen)
Nenue@86 271 if isNewMap or self.isStale then
Nenue@75 272 print('|cFF0088FFOnMapInfo()|r, mapAreaID =', mapAreaID,'visible =', isMapOpen, 'changed =', isNewMap)
Nenue@75 273 layoutDirty = true
Nenue@75 274 self:Refresh('WORLD_MAP_CHANGED')
Nenue@75 275 else
Nenue@75 276
Nenue@75 277 --print('|cFFFFFF00'..self:GetName()..':OnMapInfo()|r, mapAreaID =', mapAreaID,'visible =', isMapOpen, 'changed =', isNewMap)
Nenue@75 278 end
Nenue@75 279 end
Nenue@75 280
Nenue@75 281
Nenue@75 282 function Module:UpdateTaskPOIs()
Nenue@75 283 canTargetQuests = SpellCanTargetQuest()
Nenue@75 284 local func = canTargetQuests and 'Show' or 'Hide'
Nenue@75 285 for i = 1, NUM_WORLDMAP_TASK_POIS do
Nenue@75 286 local button = _G['WorldMapFrameTaskPOI'..i]
Nenue@75 287 if button and button.worldQuest then
Nenue@75 288 button[func](button)
Nenue@75 289 end
Nenue@75 290 end
Nenue@75 291 end
Nenue@72 292
Nenue@73 293 local bountyQuests = {}
Nenue@72 294 local bountyInfo = {}
Nenue@75 295
Nenue@72 296 local bountyDisplayLocation, bountyLockedQuestID, selectedBountyIndex, selectedBountyQuestID
Nenue@72 297 function Module:UpdateBounties(...)
Nenue@75 298 print('|cFF00FF88BountyInfo()|r', ...)
Nenue@72 299 wipe(db.BountiesByFactionID)
Nenue@75 300 wipe(db.BountiesByQuestID)
Nenue@72 301
Nenue@72 302 db.selectedBounty = nil
Nenue@72 303 selectedBountyIndex = BountyBoard:GetSelectedBountyIndex()
Nenue@75 304 db.Bounties, bountyDisplayLocation, bountyLockedQuestID = GetQuestBountyInfoForMapID(db.currentMapID, db.Bounties)
Nenue@72 305 local numBounties = 0
Nenue@75 306 for index, info in ipairs(db.Bounties) do
Nenue@72 307 numBounties = numBounties + 1
Nenue@73 308 info.index = index
Nenue@73 309 info.complete = IsQuestComplete(info.questID)
Nenue@73 310 if not info.complete then
Nenue@73 311 db.BountiesByFactionID[info.factionID] = info
Nenue@75 312 db.BountiesByQuestID[info.questID] = info
Nenue@72 313 if index == selectedBountyIndex then
Nenue@73 314 db.selectedBounty = info
Nenue@73 315 selectedBountyQuestID = info.questID
Nenue@72 316 end
Nenue@73 317 print(' ', index, info.factionID, GetQuestLogTitle(GetQuestLogIndexByID(info.questID)), info.complete, (index == selectedBountyIndex) and 'SELECTED' or '')
Nenue@72 318 end
Nenue@72 319 end
Nenue@73 320 bountiesDirty = nil
Nenue@72 321 end
Nenue@72 322
Nenue@72 323
Nenue@40 324 local totalPins = 0
Nenue@33 325 local TQ_GetQuestLocation = C_TaskQuest.GetQuestLocation
Nenue@45 326 function Module:AcquirePin (info)
Nenue@40 327 local questID = info.questId
Nenue@40 328 if not questID then
Nenue@40 329 return nil
Nenue@40 330 end
Nenue@40 331
Nenue@40 332 if not QuestUtils_IsQuestWorldQuest(questID) then
Nenue@40 333 return nil
Nenue@40 334 end
Nenue@40 335
Nenue@49 336 -- if we're grabbing a pin, the filters need to be checked
Nenue@40 337 local pin = db.QuestsByID[questID]
Nenue@33 338 if not pin then
Nenue@40 339 local numFree = #db.FreePins
Nenue@33 340 if numFree >= 1 then
Nenue@40 341 pin = tremove(db.FreePins, numFree)
Nenue@33 342 --print('|cFF00FF00Re-using', pin:GetName())
Nenue@33 343 else
Nenue@40 344 totalPins = totalPins + 1
Nenue@69 345 local name = 'WorldPlanQuestMarker' .. numOverlays
Nenue@33 346 --print('|cFF00FF00Creating', name)
Nenue@33 347 pin = CreateFrame('Frame', name, WorldMapPOIFrame, 'WorldPlanQuestPin')
Nenue@33 348
Nenue@75 349 pin:SetID(totalPins)
Nenue@69 350 numOverlays = numOverlays + 1
Nenue@33 351 --pin.iconBorder:SetVertexColor(0,0,0,1)
Nenue@33 352 end
Nenue@40 353 pin.questID = questID
Nenue@40 354 pin.worldQuest = true
Nenue@75 355 pin.throttle = pin.updateRate
Nenue@33 356 pin.isNew = true
Nenue@33 357 pin.currentWidth = nil
Nenue@40 358 db.QuestsByID[questID] = pin
Nenue@40 359 tinsert(db.UsedPins, pin)
Nenue@75 360
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@75 368 if (info.x ~= pin.x) or (info.y ~= pin.y) then
Nenue@75 369 pin.isStale = true
Nenue@75 370 --rprint('|cFFFF4400SetCoords|r', info.x, info.y)
Nenue@75 371 end
Nenue@75 372
Nenue@40 373 end
Nenue@40 374 end
Nenue@33 375
Nenue@75 376 pin.x = info.x or pin.x
Nenue@75 377 pin.y = info.y or pin.y
Nenue@75 378
Nenue@75 379 if not HaveQuestData(questID) then
Nenue@75 380 TQ_RequestPreloadRewardData(questID);
Nenue@75 381 end
Nenue@75 382
Nenue@75 383
Nick@62 384 if (not pin.dataLoaded) then
Nenue@65 385 local dataLoaded = pin:GetData()
Nenue@78 386 if dataLoaded then
Nenue@78 387 WorldPlan.dataFlush = true
Nenue@78 388 else
Nenue@78 389 isDataLoaded = false
Nenue@78 390 end
Nenue@49 391 end
Nenue@49 392
Nenue@66 393
Nick@64 394 pin.isActive = TQ_IsActive(questID)
Nenue@75 395 pin:GetCriteriaState()
Nenue@57 396 pin:CheckFilterRules()
Nenue@75 397 --rprint(pin:GetID(), pin.filtered, pin.used)
Nenue@49 398
Nenue@40 399 return pin
Nenue@33 400 end
Nenue@33 401
Nenue@33 402 -- remove from index and add it to the recycling heap
Nenue@45 403 function Module:ReleasePin (pin)
Nenue@33 404
Nenue@40 405 local id = pin.questID
Nenue@33 406 if id then
Nenue@40 407 db.QuestsByID[id] = nil
Nenue@40 408
Nenue@40 409 for i, zone in pairs(db.QuestsByZone) do
Nenue@75 410 --print('-', i, zone[i])
Nenue@33 411 zone[id] = nil
Nenue@33 412 end
Nenue@40 413 db.TasksByID[id] = nil
Nenue@33 414 end
Nick@64 415 pin.isActive = nil
Nenue@78 416 pin.used = nil
Nick@64 417 pin.dataLoaded = nil
Nenue@78 418 pin:SetShown(false)
Nenue@40 419 tinsert(db.FreePins, pin)
Nenue@40 420
Nick@63 421 WorldPlan.dataFlush = true
Nenue@75 422 --print('|cFF00FF00-'.. (pin.mapID and GetMapNameByID(pin.mapID) or '???') ..'|r', id, pin.title)
Nenue@33 423 end
Nenue@33 424
Nenue@72 425 -- re-anchors and scales pins that have had either of these changed due to data loading delays
Nenue@75 426 function Module:UpdateNext()
Nenue@75 427 --print('|cFF00FF88UpdateNext()')
Nenue@67 428 local pin = tremove(db.UpdatedPins)
Nenue@67 429 pin:CheckFilterRules()
Nenue@67 430
Nenue@75 431 local scaleFactor = SCALE_FACTORS[(pin.dataLoaded and not pin.filtered) and scaleConstant or 1]
Nenue@75 432 --print(pin.title, pin.dataLoaded and not pin.filtered, scaleFactor)
Nenue@75 433 if pin.used then
Nenue@75 434 pin:SetAnchor(nil, pin.x, pin.y, self.hostWidth, self.hostHeight, scaleFactor)
Nenue@75 435 pin:OnShow()
Nenue@75 436 end
Nenue@69 437
Nenue@69 438
Nenue@67 439 end
Nenue@67 440
Nenue@75 441 function Module:Debug(...)
Nenue@75 442 print(...)
Nenue@75 443 end
Nenue@40 444
Nenue@72 445 local msg = '|cFF00FF88WorldQuests:Refresh()|r|cFF00FFFF'
Nenue@75 446 local lastRefresh
Nenue@72 447 function Module:Refresh(...)
Nenue@75 448 --
Nenue@33 449
Nenue@34 450 if not self:IsVisible() then
Nenue@75 451 print('|cFFFF4400Refresh()|r', ...)
Nenue@75 452 --layoutDirty = true
Nenue@75 453 return
Nenue@73 454 else
Nenue@75 455 --
Nenue@75 456 if lastRefresh == GetTime() then
Nenue@75 457 print('|cFFFF4400multiple refreshes tried')
Nenue@75 458 end
Nenue@75 459 lastRefresh = GetTime()
Nenue@75 460 --rprint(msg, ...)
Nenue@75 461 print(msg, lastRefresh, ...)
Nenue@40 462 end
Nenue@73 463
Nenue@67 464 if not db.Config.EnablePins then
Nenue@69 465 numShown = 0
Nenue@76 466 self.refreshBenchMark = GetTime()
Nenue@76 467 self.refreshBenchMarkTicker = 2
Nenue@76 468 print('starting bench', self.refreshBenchMark)
Nenue@67 469 return
Nenue@67 470 end
Nenue@75 471 --wprint(' '..msg)
Nenue@67 472
Nenue@72 473 scaleConstant = db.isContinentMap and 2 or 3
Nenue@72 474 canTargetQuests = SpellCanTargetQuest()
Nenue@67 475
Nenue@40 476 for index, pin in pairs(db.QuestsByID) do
Nenue@40 477 pin.used = nil
Nenue@40 478 end
Nenue@40 479
Nenue@69 480 self:UpdateAnchors()
Nenue@75 481 --[[
Nenue@72 482 if bountiesDirty then
Nenue@75 483 --print(' bounties dirty, pushing that')
Nenue@72 484 self:UpdateBounties()
Nenue@72 485 end
Nenue@75 486 --]]
Nenue@72 487
Nick@60 488
Nenue@69 489 -- calculate quests shown
Nenue@65 490 numShown = 0
Nenue@65 491 numLoaded = 0
Nick@60 492 for questID, pin in pairs(db.QuestsByID) do
Nick@60 493 local oV = pin:IsShown()
Nick@60 494 if pin.used then
Nick@60 495 pin.throttle = 1
Nenue@75 496 --[[
Nick@60 497 if oV == false then
Nenue@75 498 --rprint('|cFF00FF00cleanup +|r', questID, pin.title)
Nick@60 499 end
Nenue@75 500 --]]
Nick@60 501 pin:SetShown(true)
Nenue@65 502 numShown = numShown + 1
Nenue@65 503 if pin.dataLoaded then
Nenue@65 504 numLoaded = numLoaded + 1
Nenue@65 505 end
Nenue@65 506
Nick@60 507 else
Nenue@75 508 --[[
Nick@60 509 if oV == true then
Nenue@67 510 rprint('|cFFFF4400 -|r', questID, pin.title)
Nick@60 511 end
Nenue@75 512 --]]
Nenue@69 513 pin.hideReason = "Not used in map area " .. (db.currentMapID)
Nenue@75 514 pin:SetShown(false)
Nick@60 515 end
Nick@60 516 end
Nick@60 517
Nenue@71 518
Nenue@75 519 --print('flags ', layoutDirty, self.isStale)
Nenue@75 520 --print(' ', numShown, 'shown,', numLoaded, 'with data')
Nenue@65 521 if numShown > numLoaded then
Nenue@65 522 self.Status:Show()
Nenue@65 523 end
Nenue@65 524
Nenue@75 525 --
Nenue@75 526 self.refreshBenchMark = GetTime()
Nenue@75 527 self.refreshBenchMarkTicker = 2
Nenue@75 528 print('starting bench', self.refreshBenchMark)
Nenue@76 529
Nenue@75 530 --
Nenue@65 531
Nenue@73 532 layoutDirty = nil
Nenue@40 533 self.isStale = nil
Nenue@54 534 self.sizesDirty = nil
Nenue@66 535 self.isZoomDirty = nil
Nenue@75 536
Nenue@40 537 end
Nenue@40 538
Nenue@73 539 local refreshReason
Nenue@75 540 function Module:RefreshIfChanged(event)
Nenue@69 541 local scaleCheck = WorldMapDetailFrame:GetScale()
Nenue@73 542 refreshReason = nil
Nenue@69 543 if scaleCheck ~= currentScale then
Nenue@73 544 refreshReason = 'map scale updated'
Nenue@69 545 currentScale = scaleCheck
Nenue@75 546 layoutDirty = true
Nenue@72 547 elseif self.isStale or layoutDirty then
Nenue@73 548 refreshReason = 'layout is marked dirty'
Nenue@73 549 end
Nenue@73 550 if not refreshReason then
Nenue@73 551 return
Nenue@73 552 end
Nenue@73 553
Nenue@73 554
Nenue@73 555 if self:IsVisible() then
Nenue@73 556 print('|cFF00FFFFRefreshIfChanged()|r', refreshReason)
Nenue@75 557 self:Refresh(event)
Nenue@73 558 else
Nenue@75 559 print('|cFF00FFFFRefreshIfChanged()|r', refreshReason)
Nenue@73 560 self.isStale = true
Nenue@69 561 end
Nenue@69 562 end
Nenue@69 563
Nenue@40 564 -- update visibility states of all pins
Nenue@57 565 function Module:MarkAllPins(pins)
Nenue@75 566 --print(' |cFFFFFF00'..self:GetName()..':MarkAllPins()|r', pins)
Nenue@40 567 pins = pins or db.QuestsByID
Nenue@40 568 for questID, pin in pairs(pins) do
Nenue@40 569 pin.isStale = true
Nenue@75 570 --rprint('|cFF00FF00filter', pin.questID, pin.filtered, 'used:', pin.used)
Nenue@33 571 end
Nenue@33 572 end
Nenue@33 573
Nenue@69 574 -- Updates quest markers in taskInfo while associating them with the given map
Nenue@69 575 function Module:UpdateQuestsForMap(taskInfo, mapID)
Nenue@84 576 print('|cFF00FF00UpdateQuestsForMap()|r', GetMapNameByID(mapID), GetMapNameByID(db.currentMapID), layoutDirty)
Nenue@82 577 if db.QuestsByZone[mapID] then
Nenue@75 578 wipe(db.QuestsByZone[mapID])
Nenue@75 579 end
Nenue@82 580
Nenue@82 581
Nenue@40 582 for index, info in pairs(taskInfo) do
Nenue@75 583
Nenue@75 584 local questID, x, y = info.questId, info.x, info.y
Nenue@75 585 local pin = self:AcquirePin(info)
Nenue@80 586
Nenue@75 587 if pin then
Nenue@84 588 pin.used = true
Nenue@82 589 print(pin.title, pin.isStale, layoutDirty, (pin.owningFrame ~= WorldMapFrame))
Nenue@80 590 if pin:IsShown() and (layoutDirty or pin.isStale or (pin.owningFrame ~= WorldMapFrame)) then
Nenue@75 591 local scaleFactor = SCALE_FACTORS[(pin.dataLoaded and not pin.filtered) and scaleConstant or 1]
Nenue@75 592 pin.owningFrame = WorldMapFrame
Nenue@75 593 pin:SetAnchor(WorldMapPOIFrame, x, y, self.hostWidth, self.hostHeight, scaleFactor)
Nenue@75 594 if pin.isStale then
Nenue@75 595 pin:Refresh('WORLDMAP_REFRESH ' .. GetTime())
Nenue@75 596 end
Nenue@75 597 else
Nenue@75 598 if layoutDirty then
Nenue@75 599 pin.isStale = true
Nenue@75 600 end
Nenue@75 601 end
Nenue@75 602
Nenue@82 603 if db.QuestsByZone[mapID] and pin.used then
Nenue@82 604 db.QuestsByZone[mapID][questID] = pin
Nenue@82 605 end
Nenue@75 606
Nenue@75 607 end
Nenue@40 608 end
Nenue@40 609 end
Nenue@33 610
Nenue@69 611 -- Used to refresh the visible quest markers
Nick@60 612 function Module:UpdateAnchors ()
Nenue@40 613 wipe(self.UsedPositions)
Nick@60 614 print(' |cFF00FF00'..self:GetName()..':UpdateAnchors()')
Nenue@74 615 local hostWidth, hostHeight = WorldMapPOIFrame:GetSize()
Nenue@74 616
Nenue@74 617 if (hostWidth ~= self.hostWidth) or (hostHeight ~= self.hostHeight) then
Nenue@74 618 self.hostWidth, self.hostHeight = hostWidth, hostHeight
Nenue@74 619 layoutDirty = true
Nenue@74 620 end
Nenue@74 621
Nenue@67 622
Nenue@75 623 --rprint('|cFF00FF00'..self:GetName()..':UpdateAnchors()')
Nenue@33 624 local mapFileName, textureHeight, textureWidth, isMicroDungeon, microDungeonMapName = GetMapInfo()
Nenue@33 625 if isMicroDungeon then
Nenue@33 626 return
Nenue@33 627 end
Nenue@69 628
Nenue@65 629 isDataLoaded = true
Nenue@67 630 local taskInfo = TQ_GetQuestsForPlayerByMapID(db.currentMapID)
Nenue@40 631 if taskInfo then
Nenue@69 632 self:UpdateQuestsForMap(taskInfo, db.currentMapID)
Nenue@33 633 end
Nenue@67 634 local numZones = MC_GetNumZones(db.currentMapID)
Nenue@33 635 if numZones then
Nenue@33 636 for i = 1, numZones do
Nenue@67 637 local mapAreaID = MC_GetZoneInfo(db.currentMapID, i)
Nenue@67 638 local taskInfo = TQ_GetQuestsForPlayerByMapID(mapAreaID, db.currentMapID)
Nenue@82 639
Nenue@82 640 db.QuestsByZone[mapAreaID] = db.QuestsByZone[mapAreaID] or {}
Nenue@82 641
Nenue@40 642 if taskInfo then
Nenue@69 643 self:UpdateQuestsForMap(taskInfo, mapAreaID)
Nenue@40 644 end
Nenue@33 645 end
Nenue@33 646 end
Nenue@33 647 end
Nenue@33 648
Nenue@67 649 function ToggleButton:OnShow()
Nenue@67 650 self:SetChecked(db.Config.EnablePins and true or false)
Nenue@67 651 end
Nenue@67 652 function ToggleButton:OnClick()
Nenue@75 653 --print(self:GetChecked())
Nenue@67 654 db.Config.EnablePins = self:GetChecked()
Nenue@67 655 _G.WorldPlan:OnConfigUpdate()
Nenue@67 656 end