Mercurial > wow > worldplan
comparison WorldQuests.lua @ 67:96183f981acb
Update for Legion Patch 7.2
- Pins for quests detected from the flight map should properly update as needed.
- Fixed dropdown menu configurations not getting applied.
- Added a toggle button to the world map display that performs the same function as the 'Enable' option in the dropdown menu.
- Rewrote the majority of display update handlers for a significant performance improvements while interacting with the world map.
- AP token info should now reflect artifact knowledge changes.
author | Nenue |
---|---|
date | Sat, 01 Apr 2017 08:17:30 -0400 |
parents | e43e10c5576b |
children | 31de7e9e7849 |
comparison
equal
deleted
inserted
replaced
66:e43e10c5576b | 67:96183f981acb |
---|---|
16 local SpellCanTargetQuest = SpellCanTargetQuest | 16 local SpellCanTargetQuest = SpellCanTargetQuest |
17 local tonumber, abs = tonumber, math.abs | 17 local tonumber, abs = tonumber, math.abs |
18 local GetQuestLogRewardInfo = GetQuestLogRewardInfo | 18 local GetQuestLogRewardInfo = GetQuestLogRewardInfo |
19 local GetCurrentMapAreaID, GetMapInfo, GetMapNameByID = GetCurrentMapAreaID, GetMapInfo, GetMapNameByID | 19 local GetCurrentMapAreaID, GetMapInfo, GetMapNameByID = GetCurrentMapAreaID, GetMapInfo, GetMapNameByID |
20 | 20 |
21 | |
21 local print = DEVIAN_WORKSPACE and function(...) _G.print('WorldQuests', ...) end or function() end | 22 local print = DEVIAN_WORKSPACE and function(...) _G.print('WorldQuests', ...) end or function() end |
22 local rprint = DEVIAN_WORKSPACE and function(...) _G.print('WQRefresh', ...) end or function() end | 23 local rprint = DEVIAN_WORKSPACE and function(...) _G.print('WQRefresh', ...) end or function() end |
23 local qprint = DEVIAN_WORKSPACE and function(...) _G.print('POI', ...) end or function() end | 24 local qprint = DEVIAN_WORKSPACE and function(...) _G.print('POI', ...) end or function() end |
24 local wprint = DEVIAN_WORKSPACE and function(...) _G.print('WP', ...) end or function() end | 25 local wprint = DEVIAN_WORKSPACE and function(...) _G.print('WP', ...) end or function() end |
25 local mprint = DEVIAN_WORKSPACE and function(...) _G.print('Canvas', ...) end or function() end | 26 local mprint = DEVIAN_WORKSPACE and function(...) _G.print('Canvas', ...) end or function() end |
36 local REWARD_REAGENT = WORLD_QUEST_REWARD_TYPE_FLAG_MATERIALS | 37 local REWARD_REAGENT = WORLD_QUEST_REWARD_TYPE_FLAG_MATERIALS |
37 local SCALE_FACTORS = { | 38 local SCALE_FACTORS = { |
38 0.25, 0.7, 1 | 39 0.25, 0.7, 1 |
39 } | 40 } |
40 | 41 |
42 local ToggleButton = {} | |
41 local numShown = 0 | 43 local numShown = 0 |
42 local numLoaded = 0 | 44 local numLoaded = 0 |
43 local isDataLoaded | 45 local isDataLoaded |
44 local numPins = 0 | 46 local numPins = 0 |
45 local NumPinFrames = 1 | 47 local NumPinFrames = 1 |
54 end | 56 end |
55 end) | 57 end) |
56 end | 58 end |
57 | 59 |
58 function Module:OnUpdate(sinceLast) | 60 function Module:OnUpdate(sinceLast) |
59 if self.filtersDirty or self.isStale or self.isZoomDirty then | 61 |
62 if self.filtersDirty or self.isStale then | |
60 self:Refresh() | 63 self:Refresh() |
61 end | 64 end |
62 end | 65 if #db.UpdatedPins >= 1 then |
63 | 66 print('|cFF00FF88pending updates', #db.UpdatedPins) |
64 local InternalDoRefresh = function (self) | 67 self:UpdateQueuedPins() |
65 WorldPlanQuests:Refresh() | 68 end |
69 | |
70 end | |
71 | |
72 local currentScale = WorldMapDetailFrame:GetScale() | |
73 function Module:RefreshIfChanged() | |
74 local scaleCheck = WorldMapDetailFrame:GetScale() | |
75 if scaleCheck ~= currentScale then | |
76 print('|cFF00FF88scale changed from', currentScale, 'to', scaleCheck) | |
77 self:Refresh() | |
78 currentScale = scaleCheck | |
79 end | |
66 end | 80 end |
67 | 81 |
68 function Module:Setup() | 82 function Module:Setup() |
69 print('|cFFFF4400'..self:GetName()..':Setup()') | 83 print('|cFFFF4400'..self:GetName()..':Setup()') |
70 | 84 |
71 for mapID, mapName in pairs(WORLD_QUEST_MAPS) do | 85 for mapID, mapName in pairs(WORLD_QUEST_MAPS) do |
72 db.QuestsByZone[mapID] = {} | 86 db.QuestsByZone[mapID] = {} |
73 end | 87 end |
74 | 88 |
75 hooksecurefunc("ClickWorldMapActionButton", function () self:OnClickWorldMapActionButton() end) | 89 hooksecurefunc("ClickWorldMapActionButton", function () self:OnClickWorldMapActionButton() end) |
76 hooksecurefunc("WorldMapScrollFrame_ReanchorQuestPOIs", InternalDoRefresh) | 90 hooksecurefunc("WorldMapScrollFrame_ReanchorQuestPOIs", function() |
77 hooksecurefunc("WorldMap_UpdateQuestBonusObjectives", function () self:OnUpdateQuestBonusObjectives() end) | 91 print("WorldMapScrollFrame_ReanchorQuestPOIs") |
78 hooksecurefunc("WorldMapFrame_UpdateMap", InternalDoRefresh) | 92 self:RefreshIfChanged() |
79 WorldMapFrame.UIElementsFrame.BountyBoard:SetSelectedBountyChangedCallback(InternalDoRefresh); | 93 end) |
80 WorldMapFrame.UIElementsFrame.ActionButton:SetOnCastChangedCallback(InternalDoRefresh); | 94 hooksecurefunc("WorldMap_UpdateQuestBonusObjectives", function () |
95 self:OnUpdateQuestBonusObjectives() | |
96 end) | |
97 hooksecurefunc("WorldMapFrame_UpdateMap", function() | |
98 print("WorldMapFrame_UpdateMap") | |
99 self:RefreshIfChanged() | |
100 end) | |
101 WorldMapFrame.UIElementsFrame.BountyBoard:SetSelectedBountyChangedCallback(function() | |
102 self:OnSelectedBountyChanged() | |
103 end); | |
104 WorldMapFrame.UIElementsFrame.ActionButton:SetOnCastChangedCallback(function() | |
105 print("CastChangedCallback") | |
106 self:Refresh(true) | |
107 end); | |
81 | 108 |
82 self.Status = CreateFrame('Frame', nil, self) | 109 self.Status = CreateFrame('Frame', nil, self) |
83 self.Status:SetPoint('TOPLEFT', WorldMapPOIFrame, 'TOPLEFT', 0, 0) | 110 self.Status:SetPoint('TOPLEFT', WorldMapPOIFrame, 'TOPLEFT', 0, 0) |
84 self.Status:SetPoint('BOTTOMRIGHT', WorldMapPOIFrame, 'TOPRIGHT', 0, -4) | 111 self.Status:SetPoint('BOTTOMRIGHT', WorldMapPOIFrame, 'TOPRIGHT', 0, -4) |
85 self.Status.t = self.Status:CreateTexture(nil, 'OVERLAY') | 112 self.Status.t = self.Status:CreateTexture(nil, 'OVERLAY') |
101 status.t:SetWidth(translateTo) | 128 status.t:SetWidth(translateTo) |
102 end | 129 end |
103 | 130 |
104 | 131 |
105 end) | 132 end) |
133 | |
134 self:SetAllPoints(WorldMapPOIFrame) | |
135 for k,v in pairs( ToggleButton) do | |
136 self.Toggle:SetScript(k,v) | |
137 end | |
138 self:Show() | |
139 end | |
140 | |
141 local GetQuestBountyInfoForMapID, GetQuestLogTitle, GetQuestLogIndexByID, IsQuestFlaggedCompleted = GetQuestBountyInfoForMapID, GetQuestLogTitle, GetQuestLogIndexByID, IsQuestFlaggedCompleted | |
142 function Module:UpdateBountyInfo() | |
143 wipe(db.BountyInfo) | |
144 db.selectedBounty = nil | |
145 | |
146 local selectedBounty = WorldMapFrame.UIElementsFrame.BountyBoard:GetSelectedBountyIndex() | |
147 local bounties, numBounties = GetQuestBountyInfoForMapID(db.currentMapID) | |
148 | |
149 for index, data in ipairs(bounties) do | |
150 if data.factionID then | |
151 data.title = GetQuestLogTitle(GetQuestLogIndexByID(data.questID)) | |
152 data.complete = IsQuestFlaggedCompleted(data.questID) | |
153 db.BountyInfo[data.factionID] = data | |
154 if index == selectedBounty then | |
155 db.selectedBounty = data | |
156 end | |
157 end | |
158 end | |
159 | |
160 for questID, pin in pairs(db.QuestsByID) do | |
161 local doUpdate | |
162 if pin.factionID and db.BountyInfo[pin.factionID] then | |
163 if not pin.isCriteria then | |
164 pin.isCriteria = true | |
165 doUpdate = true | |
166 end | |
167 else | |
168 if pin.isCriteria then | |
169 doUpdate = true | |
170 pin.isCriteria = nil | |
171 end | |
172 end | |
173 if doUpdate then | |
174 if pin:IsVisible() then | |
175 pin:Refresh() | |
176 else | |
177 pin.isStale = true | |
178 end | |
179 end | |
180 end | |
181 db.BountyUpdate = nil | |
182 end | |
183 | |
184 function Module:OnSelectedBountyChanged() | |
185 self:UpdateBountyInfo() | |
106 end | 186 end |
107 | 187 |
108 function Module:OnConfigUpdate() | 188 function Module:OnConfigUpdate() |
189 print('|cFFFFFF00OnConfigUpdate()|r') | |
109 if db.Config.FadeWhileGrouped then | 190 if db.Config.FadeWhileGrouped then |
110 db.PinAlpha = 0.15 | 191 db.PinAlpha = 0.15 |
111 else | 192 else |
112 db.PinAlpha = 1 | 193 db.PinAlpha = 1 |
113 end | 194 end |
195 | |
196 if not db.Config.EnablePins then | |
197 for _, pin in pairs(db.QuestsByID) do | |
198 pin:SetShown(false) | |
199 end | |
200 end | |
201 | |
202 ToggleButton.OnShow(self.Toggle) | |
114 end | 203 end |
115 | 204 |
116 local InternalHideButton = function(button, index) | 205 local InternalHideButton = function(button, index) |
117 button:Hide() | 206 button:Hide() |
118 if button.questID and db.QuestsByID[button.questID] then | 207 if button.questID and db.QuestsByID[button.questID] then |
138 end | 227 end |
139 end | 228 end |
140 end | 229 end |
141 | 230 |
142 function Module:OnUpdateQuestBonusObjectives() | 231 function Module:OnUpdateQuestBonusObjectives() |
143 print('|cFFFF4400WorldMap_UpdateQuestBonusObjectives') | 232 rprint('|cFFFF4400WorldMap_UpdateQuestBonusObjectives') |
144 self:UpdateBlizzButtons() | 233 self:UpdateBlizzButtons() |
145 end | 234 end |
146 | 235 |
147 function Module:OnClickWorldMapActionButton() | 236 function Module:OnClickWorldMapActionButton() |
237 rprint('|cFFFF4400ClickWorldMapActionButton') | |
148 self:UpdateBlizzButtons() | 238 self:UpdateBlizzButtons() |
149 end | 239 end |
150 | 240 |
151 local defaults = {} | 241 local defaults = {} |
152 local REWARD_UNKNOWN = 768 | 242 local REWARD_UNKNOWN = 768 |
165 self:RegisterEvent('SUPER_TRACKED_QUEST_CHANGED') | 255 self:RegisterEvent('SUPER_TRACKED_QUEST_CHANGED') |
166 self:RegisterEvent('SKILL_LINES_CHANGED') | 256 self:RegisterEvent('SKILL_LINES_CHANGED') |
167 self:RegisterEvent('CURRENT_SPELL_CAST_CHANGED') | 257 self:RegisterEvent('CURRENT_SPELL_CAST_CHANGED') |
168 end | 258 end |
169 | 259 |
170 function Module:OnMapInfo(isBrokenIsle, isZoomedOut, mapAreaID) | 260 function Module:OnMapInfo(isBrokenIsle, isZoomedOut, mapAreaID, isNewMap, isMapOpen) |
171 print('|cFFFFFF00'..self:GetName()..':OnMapInfo()|r visible =', self:IsVisible()) | 261 |
172 if self.isZoomedOut ~= isZoomedOut then | 262 print('|cFFFFFF00'..self:GetName()..':OnMapInfo()|r, mapAreaID =', mapAreaID,'visible =', isMapOpen, 'changed =', isNewMap) |
173 self.sizesDirty = true | 263 |
174 end | 264 if db.BountyUpdate then |
175 | 265 self:UpdateBountyInfo() |
176 self.isZoomedOut = isZoomedOut | 266 end |
177 self.isWorldQuestMap = isBrokenIsle | 267 if isNewMap then |
178 self.currentMapID = mapAreaID | 268 print('|cFF00FF88refreshing for changed map') |
179 | 269 if isMapOpen then |
180 if self:IsVisible() then | 270 self:Refresh(true) |
181 self:Refresh(true) | 271 else |
182 else | 272 self.isStale = true |
183 self.isStale = true | 273 end |
184 end | 274 end |
275 | |
185 end | 276 end |
186 local superTrackedQuestID | 277 local superTrackedQuestID |
187 function Module:OnEvent (event, ...) | 278 function Module:OnEvent (event, ...) |
188 | 279 |
189 print('|cFFFFFF00'..self:GetName()..':OnEvent() '..event..'|r', GetTime(), ...) | 280 print('|cFFFFFF00'..self:GetName()..':OnEvent() '..event..'|r', GetTime(), ...) |
288 | 379 |
289 | 380 |
290 pin.isActive = TQ_IsActive(questID) | 381 pin.isActive = TQ_IsActive(questID) |
291 pin:CheckFilterRules() | 382 pin:CheckFilterRules() |
292 rprint(pin:GetID(), pin.filtered, pin.used) | 383 rprint(pin:GetID(), pin.filtered, pin.used) |
384 pin:SetShown(pin.used) | |
293 | 385 |
294 return pin | 386 return pin |
295 end | 387 end |
296 | 388 |
297 -- remove from index and add it to the recycling heap | 389 -- remove from index and add it to the recycling heap |
415 return REWARD_REAGENT, icon, quantity, name, itemID, quality | 507 return REWARD_REAGENT, icon, quantity, name, itemID, quality |
416 end | 508 end |
417 end | 509 end |
418 return 128, icon, quantity, name, itemID, quality | 510 return 128, icon, quantity, name, itemID, quality |
419 end | 511 end |
512 | |
513 -- pins are queued by their OnUpdate and are ostensibly already visible, we just need to fix the zoom and anchor | |
514 function Module:UpdateQueuedPins() | |
515 print('|cFF00FF88UpdateQueuedPins()') | |
516 local pin = tremove(db.UpdatedPins) | |
517 while pin do | |
518 pin:CheckFilterRules() | |
519 | |
520 local scaleFactor = SCALE_FACTORS[(pin.dataLoaded and not pin.filtered) and scaleConstant or 1] | |
521 print(pin.title, pin.dataLoaded and not pin.filtered, scaleFactor) | |
522 pin:SetAnchor(nil, pin.x, pin.y, self.hostWidth, self.hostHeight, scaleFactor) | |
523 pin = tremove(db.UpdatedPins) | |
524 end | |
525 end | |
526 | |
420 -- create of update quest pins for a map and its underlying zones | 527 -- create of update quest pins for a map and its underlying zones |
421 function Module:UpdateWorldQuests (mapID) | 528 function Module:UpdateWorldQuests (mapID) |
422 | 529 |
423 mapID = mapID or db.currentMapID | 530 mapID = mapID or db.currentMapID |
424 if not mapID then | 531 if not mapID then |
488 for id, pin in pairs(db.QuestsByID) do | 595 for id, pin in pairs(db.QuestsByID) do |
489 db:print(id, pin.worldQuestType, pin.rewardType, pin.title) | 596 db:print(id, pin.worldQuestType, pin.rewardType, pin.title) |
490 end | 597 end |
491 end | 598 end |
492 | 599 |
493 function Module:Refresh() | 600 local bountiesInitialized |
494 self.currentMapID = GetCurrentMapAreaID() | 601 function Module:Refresh(...) |
495 rprint('|cFF00FF88'..self:GetName()..':Refresh()|r') | 602 rprint('|cFF00FF88'..self:GetName()..':Refresh()|r', ...) |
496 print('|cFF00FF88'..self:GetName()..':Refresh()|r') | 603 print('|cFF00FF88'..self:GetName()..':Refresh()|r', ...) |
497 if not self:IsVisible() then | 604 if not self:IsVisible() then |
498 print(' not visible, flag for later') | 605 print(' not visible, flag for later') |
499 self.isStale = true | 606 self.isStale = true |
500 return self:MarkAllPins() | 607 return self:MarkAllPins() |
501 end | 608 end |
609 if not db.Config.EnablePins then | |
610 return | |
611 end | |
612 | |
613 | |
502 wprint(' |cFF00FF88'..self:GetName()..':Refresh()|r') | 614 wprint(' |cFF00FF88'..self:GetName()..':Refresh()|r') |
503 | 615 |
504 scaleConstant = db.isContinentMap and 2 or 3 | 616 scaleConstant = db.isContinentMap and 2 or 3 |
505 for index, pin in pairs(db.QuestsByID) do | 617 for index, pin in pairs(db.QuestsByID) do |
506 pin.used = nil | 618 pin.used = nil |
510 self:UpdateBlizzButtons() | 622 self:UpdateBlizzButtons() |
511 else | 623 else |
512 self:UpdateAnchors(nil) | 624 self:UpdateAnchors(nil) |
513 end | 625 end |
514 | 626 |
515 print('|cFFFFFF00'..self:GetName()..':Cleanup()|r') | |
516 rprint('|cFFFFFF00'..self:GetName()..':Cleanup()|r') | |
517 --local showQuestPOI = db.Config.EnablePins | 627 --local showQuestPOI = db.Config.EnablePins |
518 numShown = 0 | 628 numShown = 0 |
519 numLoaded = 0 | 629 numLoaded = 0 |
520 for questID, pin in pairs(db.QuestsByID) do | 630 for questID, pin in pairs(db.QuestsByID) do |
521 local oV = pin:IsShown() | 631 local oV = pin:IsShown() |
522 if pin.used then | 632 if pin.used then |
523 pin.throttle = 1 | 633 pin.throttle = 1 |
524 if oV == false then | 634 if oV == false then |
525 print('|cFF00FF00cleanup +|r', questID, pin.title) | 635 rprint('|cFF00FF00cleanup +|r', questID, pin.title) |
526 end | 636 end |
527 pin:SetShown(true) | 637 pin:SetShown(true) |
528 numShown = numShown + 1 | 638 numShown = numShown + 1 |
529 if pin.dataLoaded then | 639 if pin.dataLoaded then |
530 numLoaded = numLoaded + 1 | 640 numLoaded = numLoaded + 1 |
531 end | 641 end |
532 | 642 |
533 else | 643 else |
534 if oV == true then | 644 if oV == true then |
535 print('|cFFFF4400 -|r', questID, pin.title) | 645 rprint('|cFFFF4400 -|r', questID, pin.title) |
536 end | 646 end |
537 pin:HideFrames() | 647 pin:HideFrames() |
538 end | 648 end |
539 end | 649 end |
540 | 650 |
651 print(numShown, 'shown', numLoaded, 'loaded') | |
541 if numShown > numLoaded then | 652 if numShown > numLoaded then |
542 self.Status:Show() | 653 self.Status:Show() |
543 end | 654 end |
544 | 655 |
545 | 656 |
564 if not pin then | 675 if not pin then |
565 return | 676 return |
566 end | 677 end |
567 | 678 |
568 | 679 |
569 print('~ ', pin.mapID, pin.questID, pin.title) | 680 --print(' |- ', pin.questID, pin.title) |
570 rprint('|cFF00FF00update|r', pin.questID, pin.title) | 681 rprint('|cFF00FF00update|r', pin.questID, pin.title) |
571 | 682 |
572 if x and y then | 683 if x and y then |
573 local scaleFactor = SCALE_FACTORS[(pin.dataLoaded and not pin.filtered) and scaleConstant or 1] | 684 local scaleFactor = SCALE_FACTORS[(pin.dataLoaded and not pin.filtered) and scaleConstant or 1] |
574 pin:SetFrameLevel(PinBaseIndex+pin:GetID()) | 685 pin:SetFrameLevel(PinBaseIndex+pin:GetID()) |
601 wipe(self.UsedPositions) | 712 wipe(self.UsedPositions) |
602 print(' |cFF00FF00'..self:GetName()..':UpdateAnchors()') | 713 print(' |cFF00FF00'..self:GetName()..':UpdateAnchors()') |
603 self.hostWidth, self.hostHeight = WorldMapPOIFrame:GetSize() | 714 self.hostWidth, self.hostHeight = WorldMapPOIFrame:GetSize() |
604 self.nudgeThrescholdX = 16/self.hostWidth | 715 self.nudgeThrescholdX = 16/self.hostWidth |
605 self.nudgeThrescholdY = 16/self.hostHeight | 716 self.nudgeThrescholdY = 16/self.hostHeight |
606 local print = rprint | 717 |
607 print('|cFF00FF00'..self:GetName()..':UpdateAnchors()') | 718 rprint('|cFF00FF00'..self:GetName()..':UpdateAnchors()') |
608 local mapFileName, textureHeight, textureWidth, isMicroDungeon, microDungeonMapName = GetMapInfo() | 719 local mapFileName, textureHeight, textureWidth, isMicroDungeon, microDungeonMapName = GetMapInfo() |
609 if isMicroDungeon then | 720 if isMicroDungeon then |
610 return | 721 return |
611 end | 722 end |
612 -- starts as true | 723 -- starts as true |
613 isDataLoaded = true | 724 isDataLoaded = true |
614 | 725 |
615 numPins = 0 | 726 numPins = 0 |
616 local taskInfo = TQ_GetQuestsForPlayerByMapID(self.currentMapID) | 727 local taskInfo = TQ_GetQuestsForPlayerByMapID(db.currentMapID) |
617 if taskInfo then | 728 if taskInfo then |
618 self:UpdateMap(taskInfo, self.currentMapID) | 729 self:UpdateMap(taskInfo, db.currentMapID) |
619 end | 730 end |
620 local numZones = MC_GetNumZones(self.currentMapID) | 731 local numZones = MC_GetNumZones(db.currentMapID) |
621 if numZones then | 732 if numZones then |
622 for i = 1, numZones do | 733 for i = 1, numZones do |
623 local mapAreaID = MC_GetZoneInfo(self.currentMapID, i) | 734 local mapAreaID = MC_GetZoneInfo(db.currentMapID, i) |
624 local taskInfo = TQ_GetQuestsForPlayerByMapID(mapAreaID, self.currentMapID) | 735 local taskInfo = TQ_GetQuestsForPlayerByMapID(mapAreaID, db.currentMapID) |
625 if taskInfo then | 736 if taskInfo then |
626 self:UpdateMap(taskInfo, mapAreaID) | 737 self:UpdateMap(taskInfo, mapAreaID) |
627 end | 738 end |
628 end | 739 end |
629 end | 740 end |
630 end | 741 end |
631 | 742 |
743 function ToggleButton:OnShow() | |
744 self:SetChecked(db.Config.EnablePins and true or false) | |
745 end | |
746 function ToggleButton:OnClick() | |
747 print(self:GetChecked()) | |
748 db.Config.EnablePins = self:GetChecked() | |
749 _G.WorldPlan:OnConfigUpdate() | |
750 end |