annotate WorldQuests.lua @ 73:25f7dbc20a72

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