annotate WorldQuests.lua @ 72:6db0b9696936

do bounty criteria checking in the QuestButtonUpdate segment
author Nenue
date Fri, 07 Apr 2017 01:07:48 -0400
parents d6c0bed32c51
children 25f7dbc20a72
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@69 135 WorldQuests:GetUsedPOIs()
Nenue@69 136 end
Nenue@69 137 callbacks.WorldMap_UpdateQuestBonusObjectives = function(WorldQuests)
Nenue@69 138 WorldQuests:GetUsedPOIs()
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@72 150 WorldQuests:RefreshIfChanged()
Nenue@72 151 end
Nenue@67 152
Nenue@72 153 callbacks[ActionButton] = {}
Nenue@72 154 callbacks[ActionButton].UpdateCastingState = function(WorldQuests)
Nenue@72 155 WorldQuests:Refresh(true)
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 if button.questID and db.QuestsByID[button.questID] then
Nenue@45 178 if db.QuestsByID[button.questID].used and not db.QuestsByID[button.questID].filtered then
Nenue@45 179 db.QuestsByID[button.questID]:SetShown(true)
Nenue@45 180 end
Nenue@45 181 end
Nenue@45 182 end
Nenue@45 183 local InternalShowButton = function(button, index)
Nenue@45 184 button:Show()
Nenue@45 185 if button.questID and db.QuestsByID[button.questID] then
Nenue@45 186 db.QuestsByID[button.questID]:SetShown(false)
Nenue@45 187 end
Nenue@45 188 end
Nenue@33 189
Nenue@69 190 db.UsedPOIs = {}
Nenue@69 191 function Module:GetUsedPOIs()
Nenue@69 192 db.canTargetQuests = SpellCanTargetQuest()
Nenue@69 193 local func = db.canTargetQuests and InternalShowButton or InternalHideButton
Nenue@69 194 wipe(db.UsedPOIs)
Nenue@45 195 for i = 1, NUM_WORLDMAP_TASK_POIS do
Nenue@45 196 local button = _G['WorldMapFrameTaskPOI'..i]
Nenue@45 197 if button and button.worldQuest then
Nenue@45 198 func(button, i)
Nenue@69 199 db.UsedPOIs[button.questID] = button
Nenue@45 200 end
Nenue@45 201 end
Nenue@45 202 end
Nenue@40 203
Nenue@69 204 function Module:OnSecureHook(callbackName, func, ...)
Nenue@69 205 rprint('|cFFFF4400'..callbackName..'|r', ...)
Nenue@69 206 func(self, ...)
Nenue@45 207 end
Nenue@40 208
Nenue@33 209 local defaults = {}
Nenue@40 210 local REWARD_UNKNOWN = 768
Nenue@45 211 function Module:OnLoad()
Nenue@40 212 print('|cFFFF4400'..self:GetName()..':OnLoad()')
Nenue@33 213
Nenue@48 214 self:SetParent(WorldMapPOIFrame)
Nenue@33 215 WorldPlan:AddHandler(self, defaults)
Nenue@33 216
Nenue@33 217 for areaID, fileName in pairs(WORLD_QUEST_MAPS) do
Nenue@40 218 db.QuestsByZone[areaID] = {}
Nenue@33 219 end
Nenue@33 220
Nenue@41 221 -- WORLD_MAP_UPDATE and PLAYER_ENTERING_WORLD are passed down from a higher level
Nenue@33 222 self:RegisterEvent('WORLD_QUEST_COMPLETED_BY_SPELL')
Nenue@55 223 self:RegisterEvent('SUPER_TRACKED_QUEST_CHANGED')
Nenue@33 224 self:RegisterEvent('SKILL_LINES_CHANGED')
Nick@62 225 self:RegisterEvent('CURRENT_SPELL_CAST_CHANGED')
Nenue@69 226 self:RegisterEvent('ARTIFACT_UPDATE')
Nenue@33 227 end
Nenue@33 228
Nenue@72 229 local artifactKnowledgeMultiplier
Nenue@65 230 local superTrackedQuestID
Nenue@45 231 function Module:OnEvent (event, ...)
Nenue@40 232
Nenue@40 233 print('|cFFFFFF00'..self:GetName()..':OnEvent() '..event..'|r', GetTime(), ...)
Nenue@69 234 if (event == 'QUEST_LOG_UPDATE') then
Nenue@69 235 if self:IsVisible() then
Nenue@69 236 self:Refresh()
Nenue@69 237 else
Nenue@40 238 self.isStale = true
Nenue@33 239 end
Nenue@72 240
Nenue@33 241 print('WorldMapFrame', WorldMapFrame:IsVisible(), 'hasUpdates:', self.isStale)
Nenue@33 242 elseif event == 'WORLD_QUEST_COMPLETED_BY_SPELL' then
Nenue@33 243 local questID = ...
Nenue@40 244 if questID and db.QuestsByID[questID] then
Nenue@40 245 self:ReleasePin(db.QuestsByID[questID])
Nenue@40 246 rprint('|cFFFF4400release|r', questID)
Nenue@33 247 end
Nenue@65 248 elseif event == 'SKILL_LINES_CHANGED' or event == 'CURRENT_SPELL_CAST_CHANGED' then
Nenue@72 249 self:Refresh(event)
Nenue@59 250 elseif event == 'ARTIFACT_UPDATE' then
Nenue@72 251 local akCheck = C_ArtifactUI.GetArtifactKnowledgeMultiplier()
Nenue@72 252 if akCheck and (akCheck ~= artifactKnowledgeMultiplier) then
Nenue@72 253 if artifactKnowledgeMultiplier then
Nenue@72 254 print('push artifact knowledge update', artifactKnowledgeMultiplier, 'to', akCheck)
Nenue@72 255 for index, pin in pairs( db.QuestsByID) do
Nenue@72 256 if pin.rewardType == REWARD_ARTIFACT_POWER then
Nenue@72 257 db.log(pin.questID .. ' ' .. tostring(pin.title) .. ' Flagged for artifact power.')
Nenue@72 258 pin.itemNumber = 0
Nenue@72 259 pin.dataLoaded = nil
Nenue@72 260 end
Nenue@69 261 end
Nenue@72 262 else
Nenue@72 263
Nenue@72 264 print('artifact knowledge multiplier is known', akCheck)
Nick@62 265 end
Nenue@72 266 artifactKnowledgeMultiplier = akCheck
Nenue@59 267 end
Nenue@65 268 elseif event == 'SUPER_TRACKED_QUEST_CHANGED' then
Nenue@65 269 if superTrackedQuestID and db.QuestsByID[superTrackedQuestID] then
Nenue@65 270 db.QuestsByID[superTrackedQuestID].isStale = true
Nenue@65 271 end
Nenue@65 272 local newID = GetSuperTrackedQuestID()
Nenue@65 273 if newID and db.QuestsByID[newID] then
Nenue@65 274 db.QuestsByID[newID].isStale = true
Nenue@65 275 end
Nenue@33 276 end
Nenue@33 277 end
Nenue@33 278
Nenue@72 279
Nenue@72 280
Nenue@72 281
Nenue@72 282 local bountyInfo = {}
Nenue@72 283 local bountyDisplayLocation, bountyLockedQuestID, selectedBountyIndex, selectedBountyQuestID
Nenue@72 284 function Module:UpdateBounties(...)
Nenue@72 285 print('|cFF00FF88BountyInfo()|r', ...)
Nenue@72 286 wipe(db.BountiesByFactionID)
Nenue@72 287
Nenue@72 288 bountiesDirty = nil
Nenue@72 289 db.selectedBounty = nil
Nenue@72 290 selectedBountyIndex = BountyBoard:GetSelectedBountyIndex()
Nenue@72 291 bountyInfo, bountyDisplayLocation, bountyLockedQuestID = GetQuestBountyInfoForMapID(db.currentMapID, bountyInfo)
Nenue@72 292 local numBounties = 0
Nenue@72 293 for index, data in ipairs(bountyInfo) do
Nenue@72 294 if data.factionID then
Nenue@72 295 numBounties = numBounties + 1
Nenue@72 296 data.index = index
Nenue@72 297 data.complete = IsQuestComplete(data.questID)
Nenue@72 298 if not data.complete then
Nenue@72 299 db.BountiesByFactionID[data.factionID] = data
Nenue@72 300 if index == selectedBountyIndex then
Nenue@72 301 db.selectedBounty = data
Nenue@72 302 selectedBountyQuestID = data.questID
Nenue@72 303 end
Nenue@72 304 print(' ', index, data.factionID, GetQuestLogTitle(GetQuestLogIndexByID(data.questID)), data.complete, (index == selectedBountyIndex) and 'SELECTED' or '')
Nenue@72 305 end
Nenue@72 306 end
Nenue@72 307 end
Nenue@72 308
Nenue@72 309 local numUpdated = 0
Nenue@72 310 local numHidden = 0
Nenue@72 311 for questID, pin in pairs(db.QuestsByID) do
Nenue@72 312 end
Nenue@72 313 --print(numUpdated, 'changes from Bounty Board ('..tostring(numHidden)..' hidden)')
Nenue@72 314 end
Nenue@72 315
Nenue@72 316 function Module:OnMapInfo(isBrokenIsle, isZoomedOut, mapAreaID, isNewMap, isMapOpen)
Nenue@72 317 if isNewMap then
Nenue@72 318 print('|cFF00FF88'..self:GetName()..':OnMapInfo()|r, mapAreaID =', mapAreaID,'visible =', isMapOpen, 'changed =', isNewMap)
Nenue@72 319 if isMapOpen then
Nenue@72 320 self:Refresh(true)
Nenue@72 321 else
Nenue@72 322 self.isStale = true
Nenue@72 323 end
Nenue@72 324 else
Nenue@72 325
Nenue@72 326 rprint('|cFFFFFF00'..self:GetName()..':OnMapInfo()|r, mapAreaID =', mapAreaID,'visible =', isMapOpen, 'changed =', isNewMap)
Nenue@72 327 end
Nenue@72 328 end
Nenue@72 329
Nenue@72 330
Nenue@40 331 local totalPins = 0
Nenue@33 332 local TQ_GetQuestLocation = C_TaskQuest.GetQuestLocation
Nenue@45 333 function Module:AcquirePin (info)
Nenue@40 334 local questID = info.questId
Nenue@40 335 if not questID then
Nenue@40 336 return nil
Nenue@40 337 end
Nenue@40 338
Nenue@40 339 if not QuestUtils_IsQuestWorldQuest(questID) then
Nenue@40 340 return nil
Nenue@40 341 end
Nenue@40 342
Nenue@49 343 -- if we're grabbing a pin, the filters need to be checked
Nenue@40 344 local pin = db.QuestsByID[questID]
Nenue@33 345 if not pin then
Nenue@40 346 local numFree = #db.FreePins
Nenue@33 347 if numFree >= 1 then
Nenue@40 348 pin = tremove(db.FreePins, numFree)
Nenue@33 349 --print('|cFF00FF00Re-using', pin:GetName())
Nenue@33 350 else
Nenue@40 351 totalPins = totalPins + 1
Nenue@69 352 local name = 'WorldPlanQuestMarker' .. numOverlays
Nenue@33 353 --print('|cFF00FF00Creating', name)
Nenue@33 354 pin = CreateFrame('Frame', name, WorldMapPOIFrame, 'WorldPlanQuestPin')
Nenue@33 355
Nenue@33 356 pin:SetFrameStrata('HIGH')
Nenue@33 357 pin.GetTypeInfo = function(frame, typeID)
Nenue@33 358 return self:GetTypeInfo(typeID)
Nenue@33 359 end
Nenue@40 360 pin:SetID(totalPins)
Nenue@69 361 numOverlays = numOverlays + 1
Nenue@33 362 --pin.iconBorder:SetVertexColor(0,0,0,1)
Nenue@33 363 end
Nenue@40 364 pin.questID = questID
Nenue@40 365 pin.worldQuest = true
Nenue@40 366 pin.throttle = 1
Nenue@33 367 pin.isNew = true
Nenue@33 368 pin.currentWidth = nil
Nenue@40 369 db.QuestsByID[questID] = pin
Nenue@40 370 tinsert(db.UsedPins, pin)
Nenue@40 371 end
Nenue@33 372
Nenue@40 373 if pin and info then
Nenue@40 374 pin.inProgress = info.inProgress
Nenue@40 375 pin.floor = info.floor
Nenue@40 376 pin.numObjectives = info.numObjectives or 0
Nenue@40 377 if info.x and info.y then
Nenue@40 378 pin.x = info.x or pin.x
Nenue@40 379 pin.y = info.y or pin.y
Nenue@40 380 rprint('|cFFFF4400coords|r', info.x, info.y)
Nenue@40 381 end
Nenue@40 382 end
Nenue@33 383
Nick@62 384 if (not pin.dataLoaded) then
Nenue@65 385 local dataLoaded = pin:GetData()
Nenue@65 386 isDataLoaded = (isDataLoaded and dataLoaded)
Nick@63 387 WorldPlan.dataFlush = true
Nenue@49 388 end
Nenue@49 389
Nenue@66 390
Nick@64 391 pin.isActive = TQ_IsActive(questID)
Nenue@57 392 pin:CheckFilterRules()
Nenue@49 393 rprint(pin:GetID(), pin.filtered, pin.used)
Nenue@49 394
Nenue@40 395 return pin
Nenue@33 396 end
Nenue@33 397
Nenue@33 398 -- remove from index and add it to the recycling heap
Nenue@45 399 function Module:ReleasePin (pin)
Nenue@33 400
Nenue@40 401 local id = pin.questID
Nenue@33 402 if id then
Nenue@40 403 db.QuestsByID[id] = nil
Nenue@40 404
Nenue@40 405 for i, zone in pairs(db.QuestsByZone) do
Nenue@33 406 print('-', i, zone[i])
Nenue@33 407 zone[id] = nil
Nenue@33 408 end
Nenue@40 409 db.TasksByID[id] = nil
Nenue@33 410 end
Nick@64 411 pin.isActive = nil
Nick@64 412 pin.dataLoaded = nil
Nick@62 413 pin:HideFrames()
Nenue@40 414 tinsert(db.FreePins, pin)
Nenue@40 415
Nick@63 416 WorldPlan.dataFlush = true
Nenue@40 417 print('|cFF00FF00-'.. (pin.mapID and GetMapNameByID(pin.mapID) or '???') ..'|r', id, pin.title)
Nenue@33 418 end
Nenue@33 419
Nenue@72 420 -- re-anchors and scales pins that have had either of these changed due to data loading delays
Nenue@72 421 function Module:RefreshIfQueued()
Nenue@72 422 print('|cFF00FF88RefreshIfQueued()')
Nenue@67 423 local pin = tremove(db.UpdatedPins)
Nenue@67 424 while pin do
Nenue@67 425 pin:CheckFilterRules()
Nenue@67 426
Nenue@67 427 local scaleFactor = SCALE_FACTORS[(pin.dataLoaded and not pin.filtered) and scaleConstant or 1]
Nenue@67 428 print(pin.title, pin.dataLoaded and not pin.filtered, scaleFactor)
Nenue@71 429 if pin.used then
Nenue@71 430 pin:SetAnchor(nil, pin.x, pin.y, self.hostWidth, self.hostHeight, scaleFactor)
Nenue@71 431 if pin.isNew then
Nenue@71 432 pin:OnShow()
Nenue@71 433 end
Nenue@69 434 end
Nenue@69 435
Nenue@67 436 pin = tremove(db.UpdatedPins)
Nenue@69 437
Nenue@67 438 end
Nenue@67 439 end
Nenue@67 440
Nenue@40 441
Nenue@72 442 local msg = '|cFF00FF88WorldQuests:Refresh()|r|cFF00FFFF'
Nenue@72 443 function Module:Refresh(...)
Nenue@33 444
Nenue@72 445 rprint(msg, ...)
Nenue@72 446 print('|cFF00FF88WorldQuests:Refresh()|r', ...)
Nenue@34 447 if not self:IsVisible() then
Nenue@40 448 print(' not visible, flag for later')
Nenue@34 449 self.isStale = true
Nenue@57 450 return self:MarkAllPins()
Nenue@40 451 end
Nenue@67 452 if not db.Config.EnablePins then
Nenue@69 453 numShown = 0
Nenue@67 454 return
Nenue@67 455 end
Nenue@72 456 wprint(' '..msg)
Nenue@67 457
Nenue@72 458 layoutDirty = nil
Nenue@72 459 scaleConstant = db.isContinentMap and 2 or 3
Nenue@72 460 canTargetQuests = SpellCanTargetQuest()
Nenue@67 461
Nenue@40 462 for index, pin in pairs(db.QuestsByID) do
Nenue@40 463 pin.used = nil
Nenue@40 464 end
Nenue@40 465
Nenue@69 466 self:UpdateAnchors()
Nenue@72 467 if bountiesDirty then
Nenue@72 468 print(' bounties dirty, pushing that')
Nenue@72 469 self:UpdateBounties()
Nenue@72 470 bountiesDirty = nil
Nenue@72 471 end
Nenue@72 472
Nick@60 473
Nenue@69 474 -- calculate quests shown
Nenue@65 475 numShown = 0
Nenue@65 476 numLoaded = 0
Nick@60 477 for questID, pin in pairs(db.QuestsByID) do
Nick@60 478 local oV = pin:IsShown()
Nick@60 479 if pin.used then
Nick@60 480 pin.throttle = 1
Nick@60 481 if oV == false then
Nenue@67 482 rprint('|cFF00FF00cleanup +|r', questID, pin.title)
Nick@60 483 end
Nick@60 484 pin:SetShown(true)
Nenue@65 485 numShown = numShown + 1
Nenue@65 486 if pin.dataLoaded then
Nenue@65 487 numLoaded = numLoaded + 1
Nenue@65 488 end
Nenue@65 489
Nick@60 490 else
Nick@60 491 if oV == true then
Nenue@67 492 rprint('|cFFFF4400 -|r', questID, pin.title)
Nick@60 493 end
Nenue@69 494 pin.hideReason = "Not used in map area " .. (db.currentMapID)
Nick@62 495 pin:HideFrames()
Nick@60 496 end
Nick@60 497 end
Nick@60 498
Nenue@71 499
Nenue@71 500
Nenue@72 501 print(numShown, 'shown,', numLoaded, 'with data')
Nenue@65 502 if numShown > numLoaded then
Nenue@65 503 self.Status:Show()
Nenue@65 504 end
Nenue@65 505
Nenue@65 506
Nenue@40 507 self.isStale = nil
Nenue@54 508 self.sizesDirty = nil
Nenue@66 509 self.isZoomDirty = nil
Nenue@40 510 end
Nenue@40 511
Nenue@69 512 function Module:RefreshIfChanged()
Nenue@69 513 local scaleCheck = WorldMapDetailFrame:GetScale()
Nenue@69 514 if scaleCheck ~= currentScale then
Nenue@72 515 print('|cFF00FF88RefreshIfChanged()|r map scale updated')
Nenue@72 516 self:Refresh('WORLD_MAP_SCALE_CHANGED')
Nenue@69 517 currentScale = scaleCheck
Nenue@72 518 elseif self.isStale or layoutDirty then
Nenue@72 519 print('|cFF00FF88RefreshIfChanged()|r layout is dirty')
Nenue@69 520 self:Refresh()
Nenue@69 521 end
Nenue@69 522 end
Nenue@69 523
Nenue@40 524 -- update visibility states of all pins
Nenue@57 525 function Module:MarkAllPins(pins)
Nenue@57 526 print(' |cFFFFFF00'..self:GetName()..':MarkAllPins()|r', pins)
Nenue@40 527 pins = pins or db.QuestsByID
Nenue@40 528 for questID, pin in pairs(pins) do
Nenue@40 529 pin.isStale = true
Nenue@40 530 rprint('|cFF00FF00filter', pin.questID, pin.filtered, 'used:', pin.used)
Nenue@40 531 end
Nenue@40 532 end
Nenue@40 533
Nenue@45 534 function Module:UpdateQuestButton(info, mapID)
Nenue@40 535 local questID, x, y = info.questId, info.x, info.y
Nenue@40 536 local pin = self:AcquirePin(info)
Nenue@40 537 if not pin then
Nenue@34 538 return
Nenue@34 539 end
Nenue@34 540
Nenue@67 541 --print(' |- ', pin.questID, pin.title)
Nenue@57 542 rprint('|cFF00FF00update|r', pin.questID, pin.title)
Nenue@40 543 if x and y then
Nenue@66 544 local scaleFactor = SCALE_FACTORS[(pin.dataLoaded and not pin.filtered) and scaleConstant or 1]
Nenue@49 545 pin:SetFrameLevel(PinBaseIndex+pin:GetID())
Nenue@57 546 pin.owningFrame = WorldMapFrame
Nenue@66 547 pin:SetAnchor(WorldMapPOIFrame, x, y, self.hostWidth, self.hostHeight, scaleFactor)
Nenue@54 548 --tinsert(self.UsedPositions, pin)
Nenue@40 549 end
Nenue@66 550
Nenue@72 551
Nenue@72 552 local isCriteria, isBounty
Nenue@72 553 if pin.factionID then
Nenue@72 554 if db.BountiesByFactionID[pin.factionID] then
Nenue@72 555 isCriteria = true
Nenue@72 556 end
Nenue@72 557 if selectedBountyQuestID then
Nenue@72 558 isBounty = IsQuestCriteriaForBounty(pin.questID, selectedBountyQuestID) and true or nil
Nenue@72 559 end
Nenue@72 560 end
Nenue@72 561
Nenue@72 562 if (pin.isBounty ~= isBounty) or (pin.isCriteria ~= isCriteria) then
Nenue@72 563 print(pin.isBounty, '~=', isBounty)
Nenue@72 564 print(pin.isCriteria, '~=', isCriteria)
Nenue@72 565 pin.isBounty = isBounty
Nenue@72 566 pin.isCriteria = isCriteria
Nenue@72 567 if pin:IsVisible() then
Nenue@72 568 --print(' changed', pin.title)
Nenue@72 569 --numUpdated = numUpdated + 1
Nenue@72 570 pin:Refresh('BOUNTY_UPDATE')
Nenue@72 571 else
Nenue@72 572 --numHidden = numHidden + 1
Nenue@72 573 pin.isStale = true
Nenue@72 574 end
Nenue@72 575 layoutDirty = true
Nenue@72 576 end
Nenue@72 577
Nenue@66 578 if self:IsVisible() and (pin.isStale) then
Nenue@57 579 pin:Refresh()
Nenue@54 580 end
Nenue@69 581
Nenue@40 582 if mapID then
Nenue@40 583 if not db.QuestsByZone[mapID] then
Nenue@40 584 db.QuestsByZone[mapID] = {}
Nenue@40 585 end
Nenue@40 586 db.QuestsByZone[mapID][questID] = pin
Nenue@33 587 end
Nenue@33 588 end
Nenue@33 589
Nenue@69 590 -- Updates quest markers in taskInfo while associating them with the given map
Nenue@69 591 function Module:UpdateQuestsForMap(taskInfo, mapID)
Nenue@49 592 rprint('Map', GetMapNameByID(mapID), GetMapNameByID(db.currentMapID))
Nenue@40 593 for index, info in pairs(taskInfo) do
Nenue@40 594 self:UpdateQuestButton(info, mapID)
Nenue@40 595 end
Nenue@40 596 end
Nenue@33 597
Nenue@69 598 -- Used to refresh the visible quest markers
Nick@60 599 function Module:UpdateAnchors ()
Nenue@40 600 wipe(self.UsedPositions)
Nick@60 601 print(' |cFF00FF00'..self:GetName()..':UpdateAnchors()')
Nenue@57 602 self.hostWidth, self.hostHeight = WorldMapPOIFrame:GetSize()
Nenue@40 603 self.nudgeThrescholdX = 16/self.hostWidth
Nenue@40 604 self.nudgeThrescholdY = 16/self.hostHeight
Nenue@67 605
Nenue@67 606 rprint('|cFF00FF00'..self:GetName()..':UpdateAnchors()')
Nenue@33 607 local mapFileName, textureHeight, textureWidth, isMicroDungeon, microDungeonMapName = GetMapInfo()
Nenue@33 608 if isMicroDungeon then
Nenue@33 609 return
Nenue@33 610 end
Nenue@69 611
Nenue@65 612 isDataLoaded = true
Nenue@67 613 local taskInfo = TQ_GetQuestsForPlayerByMapID(db.currentMapID)
Nenue@40 614 if taskInfo then
Nenue@69 615 self:UpdateQuestsForMap(taskInfo, db.currentMapID)
Nenue@33 616 end
Nenue@67 617 local numZones = MC_GetNumZones(db.currentMapID)
Nenue@33 618 if numZones then
Nenue@33 619 for i = 1, numZones do
Nenue@67 620 local mapAreaID = MC_GetZoneInfo(db.currentMapID, i)
Nenue@67 621 local taskInfo = TQ_GetQuestsForPlayerByMapID(mapAreaID, db.currentMapID)
Nenue@40 622 if taskInfo then
Nenue@69 623 self:UpdateQuestsForMap(taskInfo, mapAreaID)
Nenue@40 624 end
Nenue@33 625 end
Nenue@33 626 end
Nenue@33 627 end
Nenue@33 628
Nenue@67 629 function ToggleButton:OnShow()
Nenue@67 630 self:SetChecked(db.Config.EnablePins and true or false)
Nenue@67 631 end
Nenue@67 632 function ToggleButton:OnClick()
Nenue@67 633 print(self:GetChecked())
Nenue@67 634 db.Config.EnablePins = self:GetChecked()
Nenue@67 635 _G.WorldPlan:OnConfigUpdate()
Nenue@67 636 end