annotate WorldQuests.lua @ 52:6439015d74b1

- Set and use callbacks for the BountyBoard and ActionButton elements. - Check BountyBoard selections when updating pin visual - Check SpellCanTargetQuest() when determining pin visibility states
author Nenue
date Fri, 30 Dec 2016 18:31:32 -0500
parents dbd81d49af02
children b289eb3e6a32
rev   line source
Nenue@33 1 -- WorldPlan
Nenue@33 2 -- WorldQuests.lua
Nenue@33 3 -- Created: 11/2/2016 3:40 PM
Nenue@33 4 -- %file-revision%
Nenue@40 5 local _, db = ...
Nenue@45 6 local Module = WorldPlanQuestsMixin
Nenue@33 7
Nenue@33 8 local MC_GetNumZones, MC_GetZoneInfo = C_MapCanvas.GetNumZones, C_MapCanvas.GetZoneInfo
Nenue@33 9 local TQ_GetQuestsForPlayerByMapID = C_TaskQuest.GetQuestsForPlayerByMapID -- This function is not yet documented
Nenue@33 10 local TQ_GetQuestZoneID = C_TaskQuest.GetQuestZoneID
Nenue@33 11 local GetMapInfo = GetMapInfo
Nenue@40 12 local print = DEVIAN_WORKSPACE and function(...) _G.print('WorldQuests', ...) end or function() end
Nenue@40 13 local rprint = DEVIAN_WORKSPACE and function(...) _G.print('WQRefresh', ...) end or function() end
Nenue@33 14 local qprint = DEVIAN_WORKSPACE and function(...) _G.print('POI', ...) end or function() end
Nenue@33 15 local wprint = DEVIAN_WORKSPACE and function(...) _G.print('WP', ...) end or function() end
Nenue@35 16 local mprint = DEVIAN_WORKSPACE and function(...) _G.print('Canvas', ...) end or function() end
Nenue@45 17 local pairs = pairs
Nenue@33 18
Nenue@40 19 local PinBaseIndex = 1200
Nenue@33 20 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 21 local WORLD_QUEST_MAPS = { [DALARAN_ID] = 'Dalaran70', [AZSUNA_ID] = 'Azsuna', [VALSHARAH_ID] = "Val'sharah",
Nenue@33 22 [HIGHMOUNTAIN_ID] = 'Highmountain', [STORMHEIM_ID] = 'Stormheim', [SURAMAR_ID] = 'Suramar', [EOA_ID] = 'EyeOfAszhara', }
Nenue@33 23
Nenue@33 24 local REWARD_CASH = WORLD_QUEST_REWARD_TYPE_FLAG_GOLD
Nenue@33 25 local REWARD_ARTIFACT_POWER = WORLD_QUEST_REWARD_TYPE_FLAG_ARTIFACT_POWER
Nenue@33 26 local REWARD_GEAR = WORLD_QUEST_REWARD_TYPE_FLAG_EQUIPMENT
Nenue@33 27 local REWARD_CURRENCY = WORLD_QUEST_REWARD_TYPE_FLAG_ORDER_RESOURCES
Nenue@33 28 local REWARD_REAGENT = WORLD_QUEST_REWARD_TYPE_FLAG_MATERIALS
Nenue@33 29
Nenue@33 30
Nenue@33 31 local numPins = 0
Nenue@33 32 local NumPinFrames = 1
Nenue@45 33 Module.TasksByID = {}
Nenue@33 34
Nenue@33 35 --%debug%
Nenue@33 36 local SetTimedCallbackForAllPins = function(seconds, callback)
Nenue@33 37 C_Timer.After(seconds, function()
Nenue@33 38 for id, pin in pairs(WorldPlanQuests.QuestsByID) do
Nenue@33 39 callback(pin)
Nenue@33 40 end
Nenue@33 41 end)
Nenue@33 42 end
Nenue@33 43
Nenue@45 44 function Module:OnUpdate(sinceLast)
Nenue@40 45 if self.filtersDirty or self.isStale then
Nenue@40 46 self:Refresh()
Nenue@40 47 end
Nenue@40 48 end
Nenue@40 49
Nenue@52 50 local InternalDoRefresh = function (self)
Nenue@52 51 WorldPlanQuests:Refresh(true)
Nenue@52 52 end
Nenue@52 53
Nenue@45 54 function Module:Setup()
Nenue@40 55 print('|cFFFF4400'..self:GetName()..':Setup()')
Nenue@33 56
Nenue@33 57 for mapID, mapName in pairs(WORLD_QUEST_MAPS) do
Nenue@40 58 db.QuestsByZone[mapID] = {}
Nenue@33 59 end
Nenue@33 60
Nenue@45 61 hooksecurefunc("ClickWorldMapActionButton", function () self:OnClickWorldMapActionButton() end)
Nenue@45 62 hooksecurefunc("WorldMapScrollFrame_ReanchorQuestPOIs", function () self:Refresh() end)
Nenue@45 63 hooksecurefunc("WorldMap_UpdateQuestBonusObjectives", function () self:OnUpdateQuestBonusObjectives() end)
Nenue@52 64
Nenue@52 65
Nenue@52 66 WorldMapFrame.UIElementsFrame.BountyBoard:SetSelectedBountyChangedCallback(InternalDoRefresh);
Nenue@52 67 WorldMapFrame.UIElementsFrame.ActionButton:SetOnCastChangedCallback(InternalDoRefresh);
Nenue@45 68 end
Nenue@33 69
Nenue@49 70 function Module:OnConfigUpdate()
Nenue@49 71 if db.Config.FadeWhileGrouped then
Nenue@49 72 db.PinAlpha = 0.15
Nenue@49 73 else
Nenue@49 74 db.PinAlpha = 1
Nenue@49 75 end
Nenue@49 76 end
Nenue@49 77
Nenue@45 78 local InternalHideButton = function(button, index)
Nenue@45 79 button:Hide()
Nenue@45 80 if button.questID and db.QuestsByID[button.questID] then
Nenue@45 81 if db.QuestsByID[button.questID].used and not db.QuestsByID[button.questID].filtered then
Nenue@45 82 db.QuestsByID[button.questID]:SetShown(true)
Nenue@45 83 end
Nenue@45 84 end
Nenue@45 85 end
Nenue@45 86 local InternalShowButton = function(button, index)
Nenue@45 87 button:Show()
Nenue@45 88 if button.questID and db.QuestsByID[button.questID] then
Nenue@45 89 db.QuestsByID[button.questID]:SetShown(false)
Nenue@45 90 end
Nenue@45 91 end
Nenue@33 92
Nenue@45 93 function Module:OnUpdateQuestBonusObjectives()
Nenue@45 94 print('|cFFFF4400WorldMap_UpdateQuestBonusObjectives')
Nenue@45 95 local func = SpellCanTargetQuest() and InternalShowButton or InternalHideButton
Nenue@45 96 print(SpellCanTargetQuest())
Nenue@45 97 for i = 1, NUM_WORLDMAP_TASK_POIS do
Nenue@45 98 local button = _G['WorldMapFrameTaskPOI'..i]
Nenue@45 99 if button and button.worldQuest then
Nenue@45 100 func(button, i)
Nenue@45 101 end
Nenue@45 102 end
Nenue@45 103 end
Nenue@40 104
Nenue@45 105 function Module:OnClickWorldMapActionButton()
Nenue@45 106 self.IsTargeting = SpellCanTargetQuest()
Nenue@45 107 self:OnUpdateQuestBonusObjectives()
Nenue@45 108 end
Nenue@40 109
Nenue@33 110 local defaults = {}
Nenue@40 111 local REWARD_UNKNOWN = 768
Nenue@45 112 function Module:OnLoad()
Nenue@40 113 print('|cFFFF4400'..self:GetName()..':OnLoad()')
Nenue@33 114
Nenue@48 115 self:SetParent(WorldMapPOIFrame)
Nenue@33 116 WorldPlan:AddHandler(self, defaults)
Nenue@33 117
Nenue@40 118 local rgbWhite = {1, 1, 1 }
Nenue@47 119 WorldPlan:AddTypeInfo(self, REWARD_UNKNOWN, { r = 0, g = 0, b = 0})
Nenue@48 120 WorldPlan:AddTypeInfo(self, REWARD_REAGENT, { r = 0, g = 1, b = .5 })
Nenue@33 121 WorldPlan:AddTypeInfo(self, REWARD_ARTIFACT_POWER, { r = 1, g = .25, b = .5, hasNumeric = true, numberRGB = rgbWhite })
Nenue@48 122 WorldPlan:AddTypeInfo(self, REWARD_GEAR, { r = .3, g = .7, b = 1 })
Nenue@33 123 WorldPlan:AddTypeInfo(self, REWARD_CURRENCY, { r = 1, g = 1, b = 0, hasNumeric = true, numberRGB = {1,1,0}, })
Nenue@40 124 WorldPlan:AddTypeInfo(self, REWARD_CASH, { r = 1, g = 1, b = .32, pinMask = false, rewardMask = false })
Nenue@33 125
Nenue@33 126 for areaID, fileName in pairs(WORLD_QUEST_MAPS) do
Nenue@40 127 db.QuestsByZone[areaID] = {}
Nenue@33 128 end
Nenue@33 129
Nenue@41 130 -- WORLD_MAP_UPDATE and PLAYER_ENTERING_WORLD are passed down from a higher level
Nenue@33 131 self:RegisterEvent('WORLD_QUEST_COMPLETED_BY_SPELL')
Nenue@33 132 self:RegisterEvent('SKILL_LINES_CHANGED')
Nenue@33 133 end
Nenue@33 134
Nenue@45 135 function Module:OnMapInfo()
Nenue@49 136 print('|cFFFFFF00'..self:GetName()..':OnMapInfo()|r visible =', self:IsVisible())
Nenue@43 137 if self:IsVisible() then
Nenue@47 138 self:Refresh(true)
Nenue@43 139 else
Nenue@43 140 self.isStale = true
Nenue@43 141 end
Nenue@41 142 end
Nenue@41 143
Nenue@45 144 function Module:OnEvent (event, ...)
Nenue@40 145
Nenue@40 146 print('|cFFFFFF00'..self:GetName()..':OnEvent() '..event..'|r', GetTime(), ...)
Nenue@41 147 if event == 'QUEST_LOG_UPDATE' then
Nenue@33 148 local questID, added = ...
Nenue@33 149 if questID and added then
Nenue@33 150 local questPOI = self:AcquirePin(questID)
Nenue@40 151 questPOI:GetQuestInfo()
Nenue@40 152 questPOI.isStale = true
Nenue@40 153 self.isStale = true
Nenue@33 154 else
Nenue@40 155 self:Refresh(true)
Nenue@33 156 end
Nenue@33 157 print('WorldMapFrame', WorldMapFrame:IsVisible(), 'hasUpdates:', self.isStale)
Nenue@33 158 elseif event == 'WORLD_QUEST_COMPLETED_BY_SPELL' then
Nenue@33 159 local questID = ...
Nenue@40 160 if questID and db.QuestsByID[questID] then
Nenue@40 161 self:ReleasePin(db.QuestsByID[questID])
Nenue@40 162 rprint('|cFFFF4400release|r', questID)
Nenue@33 163 end
Nenue@33 164 elseif event == 'SKILL_LINES_CHANGED' then
Nenue@40 165 self:SetFilteredPins()
Nenue@33 166 end
Nenue@33 167 end
Nenue@33 168
Nenue@40 169 local totalPins = 0
Nenue@33 170 local TQ_GetQuestLocation = C_TaskQuest.GetQuestLocation
Nenue@45 171 function Module:AcquirePin (info)
Nenue@40 172 local questID = info.questId
Nenue@40 173 if not questID then
Nenue@40 174 return nil
Nenue@40 175 end
Nenue@40 176
Nenue@40 177 if not QuestUtils_IsQuestWorldQuest(questID) then
Nenue@40 178 return nil
Nenue@40 179 end
Nenue@40 180
Nenue@49 181 -- if we're grabbing a pin, the filters need to be checked
Nenue@40 182 local pin = db.QuestsByID[questID]
Nenue@33 183 if not pin then
Nenue@40 184 local numFree = #db.FreePins
Nenue@33 185 if numFree >= 1 then
Nenue@40 186 pin = tremove(db.FreePins, numFree)
Nenue@33 187 --print('|cFF00FF00Re-using', pin:GetName())
Nenue@33 188 else
Nenue@40 189 totalPins = totalPins + 1
Nenue@33 190 local name = 'WorldPlanQuestMarker' .. NumPinFrames
Nenue@33 191 --print('|cFF00FF00Creating', name)
Nenue@33 192 pin = CreateFrame('Frame', name, WorldMapPOIFrame, 'WorldPlanQuestPin')
Nenue@33 193
Nenue@33 194 pin:SetFrameStrata('HIGH')
Nenue@33 195 pin.GetTypeInfo = function(frame, typeID)
Nenue@33 196 return self:GetTypeInfo(typeID)
Nenue@33 197 end
Nenue@40 198 pin:SetID(totalPins)
Nenue@33 199 NumPinFrames = NumPinFrames + 1
Nenue@33 200 --pin.iconBorder:SetVertexColor(0,0,0,1)
Nenue@33 201 end
Nenue@40 202 pin.questID = questID
Nenue@40 203 pin.worldQuest = true
Nenue@40 204 pin.throttle = 1
Nenue@33 205 pin.isNew = true
Nenue@33 206 pin.currentWidth = nil
Nenue@40 207 db.QuestsByID[questID] = pin
Nenue@40 208 tinsert(db.UsedPins, pin)
Nenue@40 209 end
Nenue@33 210
Nenue@40 211 if pin and info then
Nenue@40 212 pin.inProgress = info.inProgress
Nenue@40 213 pin.floor = info.floor
Nenue@40 214 pin.numObjectives = info.numObjectives or 0
Nenue@40 215 if info.x and info.y then
Nenue@40 216 pin.x = info.x or pin.x
Nenue@40 217 pin.y = info.y or pin.y
Nenue@40 218 rprint('|cFFFF4400coords|r', info.x, info.y)
Nenue@40 219 end
Nenue@40 220 end
Nenue@33 221
Nenue@49 222 if not pin.dataLoaded then
Nenue@49 223 pin:GetData()
Nenue@49 224 C_TaskQuest.RequestPreloadRewardData(info.questId)
Nenue@49 225 end
Nenue@49 226
Nenue@49 227 pin:IsFiltered()
Nenue@49 228 pin:IsShowable()
Nenue@49 229 pin.isStale = true
Nenue@49 230 rprint(pin:GetID(), pin.filtered, pin.used)
Nenue@49 231
Nenue@40 232 return pin
Nenue@33 233 end
Nenue@33 234
Nenue@33 235 -- remove from index and add it to the recycling heap
Nenue@45 236 function Module:ReleasePin (pin)
Nenue@33 237
Nenue@40 238 local id = pin.questID
Nenue@33 239 if id then
Nenue@40 240 db.QuestsByID[id] = nil
Nenue@40 241
Nenue@40 242 for i, zone in pairs(db.QuestsByZone) do
Nenue@33 243 print('-', i, zone[i])
Nenue@33 244 zone[id] = nil
Nenue@33 245 end
Nenue@40 246 db.TasksByID[id] = nil
Nenue@33 247 end
Nenue@40 248 pin:SetShown(false)
Nenue@33 249 pin:ClearAllPoints()
Nenue@40 250 tinsert(db.FreePins, pin)
Nenue@40 251
Nenue@40 252 print('|cFF00FF00-'.. (pin.mapID and GetMapNameByID(pin.mapID) or '???') ..'|r', id, pin.title)
Nenue@33 253 end
Nenue@33 254
Nenue@45 255 function Module:GetBonusObjectives()
Nenue@40 256
Nenue@40 257
Nenue@40 258 local tasksTable = GetTasksTable()
Nenue@40 259 if tasksTable ~= nil then
Nenue@40 260 print('|cFF00FF88'..self:GetName()..':BonusObjectives()|r ')
Nenue@40 261 self.numTasks = #tasksTable
Nenue@40 262 for i, taskID in ipairs(tasksTable) do
Nenue@40 263 if not QuestUtils_IsQuestWorldQuest(taskID) then
Nenue@40 264 local info = db.TasksByID[taskID]
Nenue@40 265 if not info then
Nenue@40 266 local isInArea, isOnMap, numObjectives, taskName, displayAsObjective = GetTaskInfo(taskID)
Nenue@40 267 if isOnMap then
Nenue@40 268 print(' * '..i, taskID, GetTaskInfo(taskID))
Nenue@40 269 info = {
Nenue@40 270 questID = taskID,
Nenue@40 271 numObjectives = numObjectives,
Nenue@40 272 title = taskName,
Nenue@40 273 isInArea = isInArea,
Nenue@40 274 isOnMap = isOnMap,
Nenue@40 275 displayAsObjective = displayAsObjective,
Nenue@40 276 worldQuest = false,
Nenue@40 277 isPending = false,
Nenue@40 278 isNew = true,
Nenue@40 279 }
Nenue@40 280
Nenue@40 281
Nenue@40 282 db.TasksByID[taskID] = info
Nenue@40 283
Nenue@40 284 local pin = self:AcquirePin(taskID)
Nenue@40 285 for k,v in pairs(info) do
Nenue@40 286 pin[k] = v
Nenue@40 287 end
Nenue@40 288 pin:GetBonusObjectiveInfo(info)
Nenue@40 289 end
Nenue@40 290 end
Nenue@40 291 end
Nenue@40 292
Nenue@40 293
Nenue@40 294 end
Nenue@40 295 end
Nenue@40 296 end
Nenue@40 297
Nenue@40 298
Nenue@40 299
Nenue@40 300
Nenue@40 301 -- use tooltip object to extract item details
Nenue@45 302 function Module:GetRewardHeader(questID)
Nenue@40 303 local name, icon, quantity, quality, _, itemID = GetQuestLogRewardInfo(1, questID)
Nenue@40 304 local scanner = _G.WorldPlanTooltip
Nenue@40 305 local print = qprint
Nenue@40 306 if not itemID then
Nenue@40 307 return
Nenue@40 308 end
Nenue@49 309 qprint('GetRewardHeader', questID)
Nenue@40 310
Nenue@40 311 scanner:SetOwner(WorldPlan, "ANCHOR_NONE")
Nenue@40 312 scanner:SetItemByID(itemID)
Nenue@40 313 scanner:Show()
Nenue@40 314 local ttl1 = _G['WorldPlanTooltipTextLeft1']
Nenue@40 315 local ttl2 = _G['WorldPlanTooltipTextLeft2']
Nenue@40 316 local ttl3 = _G['WorldPlanTooltipTextLeft3']
Nenue@40 317 local ttl4 = _G['WorldPlanTooltipTextLeft4']
Nenue@40 318 --print(ttl2, ttl3, ttl4)
Nenue@40 319 if ttl2 then
Nenue@40 320 local text = ttl2:GetText()
Nenue@40 321 -- Artifact Power
Nenue@40 322 --print(text)
Nenue@40 323 if text then
Nenue@40 324 if text:match("|cFFE6CC80") then
Nenue@40 325 --print('AP token!', text)
Nenue@40 326 local power
Nenue@40 327 if ttl4 then
Nenue@40 328 local text = ttl4:GetText()
Nenue@40 329 --print('tip line 4', text)
Nenue@40 330 if text then
Nenue@40 331 power = text:gsub("%p", ""):match("%d+")
Nenue@40 332 power = tonumber(power)
Nenue@40 333 end
Nenue@40 334
Nenue@40 335 end
Nenue@40 336 return REWARD_ARTIFACT_POWER, "Interface\\ICONS\\inv_7xp_inscription_talenttome01", power, name, itemID, quality
Nenue@40 337 elseif text:match("Item Level") then
Nenue@40 338 --print('equipment!', text)
Nenue@40 339 quantity = text:match("Item Level ([%d\+]+)")
Nenue@40 340 return REWARD_GEAR, icon, quantity, name, itemID, quality
Nenue@40 341 elseif text:match("Crafting Reagent") then
Nenue@49 342 qprint('|cFFFF4400it is a reagent', text)
Nenue@40 343 return REWARD_REAGENT, icon, quantity, name, itemID, quality
Nenue@40 344 end
Nenue@40 345 end
Nenue@40 346 end
Nenue@40 347
Nenue@40 348 if ttl3 then
Nenue@40 349 local text = ttl3:GetText()
Nenue@40 350 if text and text:match("Crafting Reagent") then
Nenue@49 351 qprint('|cFFFF4400it is a reagent', text)
Nenue@40 352 return REWARD_REAGENT, icon, quantity, name, itemID, quality
Nenue@40 353 end
Nenue@40 354 end
Nenue@40 355 return 128, icon, quantity, name, itemID, quality
Nenue@40 356 end
Nenue@40 357
Nenue@40 358 local GetCurrentMapAreaID, GetMapNameByID= GetCurrentMapAreaID, GetMapNameByID
Nenue@40 359 local wipe, pairs = wipe, pairs
Nenue@33 360 -- create of update quest pins for a map and its underlying zones
Nenue@45 361 function Module:UpdateWorldQuests (mapID)
Nenue@40 362
Nenue@40 363 mapID = mapID or db.currentMapID
Nenue@33 364 if not mapID then
Nenue@33 365 -- info not available yet
Nenue@33 366 return
Nenue@33 367 end
Nenue@33 368
Nenue@34 369
Nenue@40 370 print('|cFF00FF88'..self:GetName()..':UpdateWorldQuests()|r', 'map:', mapID, 'realMap:', db.currentMapID)
Nenue@33 371
Nenue@40 372
Nenue@40 373 self.isStale = nil
Nenue@40 374 print('|cFF00FFFFContinent:|r', BROKEN_ISLES_ID, GetMapNameByID(BROKEN_ISLES_ID))
Nenue@40 375 self.isRecursed = true
Nenue@40 376 for i = 1, MC_GetNumZones(BROKEN_ISLES_ID) do
Nenue@40 377 local submapID, name, depth = MC_GetZoneInfo(BROKEN_ISLES_ID, i)
Nenue@40 378 local taskInfo = TQ_GetQuestsForPlayerByMapID(submapID, BROKEN_ISLES_ID)
Nenue@40 379 if taskInfo then
Nenue@40 380 local zoneName = GetMapNameByID(submapID)
Nenue@40 381 print('|cFF00FFFF Zone:|r', submapID, zoneName, #taskInfo)
Nenue@40 382 db.QuestsByZone[submapID] = db.QuestsByZone[submapID] or {}
Nenue@40 383 for i, info in ipairs(taskInfo) do
Nenue@40 384 if HaveQuestData(info.questId) then
Nenue@40 385 rprint('|cFF44FF44update|r', info.questId, zoneName)
Nenue@40 386 local questID = info.questId
Nenue@40 387 local pin = self:AcquirePin(questID)
Nenue@40 388 local pin = db.QuestsByID[questID]
Nenue@40 389 if pin then
Nenue@40 390 pin.isStale = true
Nenue@40 391 if pin.isPending then
Nenue@40 392 self.isPending = true
Nenue@40 393 end
Nenue@40 394 end
Nenue@40 395 else
Nenue@40 396 rprint('|cFFFF4400no data|r', info.questId, zoneName)
Nenue@40 397 end
Nenue@33 398 end
Nenue@33 399 end
Nenue@33 400 end
Nenue@33 401
Nenue@40 402 self:GetBonusObjectives()
Nenue@40 403
Nenue@40 404 print(' hasUpdate:', self.isStale, 'isPending:', self.isPending, 'timer:', (self.OnNext and 'waiting' or ''))
Nenue@40 405 --WorldPlan.isStale = (self.isStale or WorldPlan.isStale)
Nenue@40 406 if self.isStale and self:IsVisible() then
Nenue@40 407 self:Refresh()
Nenue@40 408 end
Nenue@40 409 end
Nenue@40 410
Nenue@45 411 function Module:Report()
Nenue@40 412 for i, pin in ipairs(db.UsedPins) do
Nenue@40 413 db:print(i, pin.questID, pin.title)
Nenue@33 414 end
Nenue@33 415
Nenue@40 416 for id, pin in pairs(db.QuestsByID) do
Nenue@40 417 db:print(id, pin.worldQuestType, pin.rewardType, pin.title)
Nenue@40 418 end
Nenue@33 419 end
Nenue@33 420
Nenue@45 421 function Module:Refresh(fromUser)
Nenue@49 422 self.isUserTriggered = fromUser
Nenue@40 423 self.currentMapID = GetCurrentMapAreaID()
Nenue@49 424 rprint('|cFF00FF88'..self:GetName()..':Refresh()|r', fromUser or '|cFFFFFF00internal')
Nenue@40 425 print('|cFF00FF88'..self:GetName()..':Refresh()|r', fromUser or '|cFFFFFF00internal')
Nenue@34 426 if not self:IsVisible() then
Nenue@40 427 print(' not visible, flag for later')
Nenue@34 428 self.isStale = true
Nenue@40 429 return
Nenue@40 430 end
Nenue@40 431 wprint(' |cFF00FF88'..self:GetName()..':Refresh()|r', fromUser or '|cFFFFFF00internal')
Nenue@40 432
Nenue@40 433 for index, pin in pairs(db.QuestsByID) do
Nenue@40 434 pin.used = nil
Nenue@40 435 end
Nenue@40 436
Nenue@40 437 self:UpdateAnchors(nil, fromUser)
Nenue@40 438 self:Cleanup (fromUser)
Nenue@40 439 self.isStale = nil
Nenue@49 440 self.isUserTriggered = nil
Nenue@40 441 end
Nenue@40 442
Nenue@40 443 -- update visibility states of all pins
Nenue@45 444 function Module:SetFilteredPins(pins)
Nenue@40 445 print(' |cFFFFFF00'..self:GetName()..':SetFilteredPins()|r', pins)
Nenue@40 446 pins = pins or db.QuestsByID
Nenue@40 447 for questID, pin in pairs(pins) do
Nenue@40 448 pin.isStale = true
Nenue@40 449 rprint('|cFF00FF00filter', pin.questID, pin.filtered, 'used:', pin.used)
Nenue@40 450 end
Nenue@40 451 end
Nenue@40 452
Nenue@40 453 local abs = math.abs
Nenue@45 454 function Module:UpdateQuestButton(info, mapID)
Nenue@40 455 local questID, x, y = info.questId, info.x, info.y
Nenue@40 456 local pin = self:AcquirePin(info)
Nenue@40 457 if not pin then
Nenue@34 458 return
Nenue@34 459 end
Nenue@34 460
Nenue@33 461
Nenue@49 462 --print('~ ', pin.mapID, pin.questID, pin.title)
Nenue@49 463 rprint('|cFF00FF00update|r', x, y, pin.mapID, pin.questID, pin.title)
Nenue@40 464
Nenue@40 465 if x and y then
Nenue@40 466 pin.x = x
Nenue@40 467 pin.y = y
Nenue@40 468 pin.throttle = 1
Nenue@49 469 pin:SetFrameLevel(PinBaseIndex+pin:GetID())
Nenue@52 470 pin:SetAnchor(self.hostFrame, pin.x, pin.y, self.hostWidth, self.hostHeight)
Nenue@40 471 tinsert(self.UsedPositions, pin)
Nenue@40 472 end
Nenue@40 473
Nenue@40 474 if mapID then
Nenue@40 475 if not db.QuestsByZone[mapID] then
Nenue@40 476 db.QuestsByZone[mapID] = {}
Nenue@40 477 end
Nenue@40 478 db.QuestsByZone[mapID][questID] = pin
Nenue@33 479 end
Nenue@33 480 end
Nenue@33 481
Nenue@45 482 function Module:UpdateMap(taskInfo, mapID)
Nenue@49 483 rprint('Map', GetMapNameByID(mapID), GetMapNameByID(db.currentMapID))
Nenue@40 484 for index, info in pairs(taskInfo) do
Nenue@40 485 self:UpdateQuestButton(info, mapID)
Nenue@40 486 end
Nenue@40 487 end
Nenue@33 488
Nenue@45 489 function Module:UpdateAnchors (fromUser)
Nenue@40 490 wipe(self.UsedPositions)
Nenue@40 491 print(' |cFF00FF00'..self:GetName()..':UpdateAnchors()', fromUser)
Nenue@40 492 self.hostFrame = WorldMapPOIFrame
Nenue@40 493 self.hostWidth, self.hostHeight = self.hostFrame:GetSize()
Nenue@40 494 self.nudgeThrescholdX = 16/self.hostWidth
Nenue@40 495 self.nudgeThrescholdY = 16/self.hostHeight
Nenue@40 496 local print = rprint
Nenue@40 497 print('|cFF00FF00'..self:GetName()..':UpdateAnchors()', fromUser)
Nenue@33 498 local mapFileName, textureHeight, textureWidth, isMicroDungeon, microDungeonMapName = GetMapInfo()
Nenue@33 499 if isMicroDungeon then
Nenue@33 500 return
Nenue@33 501 end
Nenue@33 502
Nenue@40 503 numPins = 0
Nenue@49 504 local taskInfo = TQ_GetQuestsForPlayerByMapID(db.currentMapID)
Nenue@40 505 if taskInfo then
Nenue@49 506 self:UpdateMap(taskInfo, db.currentMapID)
Nenue@33 507 end
Nenue@49 508 local numZones = MC_GetNumZones(db.currentMapID)
Nenue@33 509 if numZones then
Nenue@33 510 for i = 1, numZones do
Nenue@40 511 local mapAreaID = MC_GetZoneInfo(self.currentMapID, i)
Nenue@49 512 local taskInfo = TQ_GetQuestsForPlayerByMapID(mapAreaID, db.currentMapID)
Nenue@40 513 if taskInfo then
Nenue@40 514 self:UpdateMap(taskInfo, mapAreaID)
Nenue@40 515 end
Nenue@33 516 end
Nenue@33 517 end
Nenue@33 518 end
Nenue@33 519
Nenue@33 520 -- shows, animates, or hides pins based on their current visibility flags
Nenue@45 521 function Module:Cleanup (fromUser)
Nenue@40 522
Nenue@35 523 print('|cFFFFFF00'..self:GetName()..':Cleanup()|r')
Nenue@40 524 local print = rprint
Nenue@40 525 print('|cFFFFFF00'..self:GetName()..':Cleanup()|r')
Nenue@40 526 --local showQuestPOI = db.Config.EnablePins
Nenue@40 527 for questID, pin in pairs(db.QuestsByID) do
Nenue@40 528 local oV = pin:IsShown()
Nenue@40 529 if pin.used then
Nenue@40 530 pin.throttle = 1
Nenue@40 531 if oV == false then
Nenue@40 532 print('|cFF00FF00cleanup +|r', questID, pin.title)
Nenue@40 533 end
Nenue@40 534 else
Nenue@40 535 if oV == true then
Nenue@40 536 print('|cFFFF4400 -|r', questID, pin.title)
Nenue@40 537 end
Nenue@49 538 pin.isStale = true
Nenue@49 539 pin:SetShown(false)
Nenue@40 540 end
Nenue@33 541 end
Nenue@33 542 end
Nenue@33 543