annotate WorldQuests.lua @ 75:78d78dc77822

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