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