annotate FlightMap.lua @ 38:a93cae445d3f v1.0-rc9

WorldPlan: - Quest pins are now placed on the flight map. Their visibility rules will mirror the filter options from the world map. - Filter controls polish: - First click negates other reward type filters. Subsequent clicks will then toggle individual reward types until the filters are reset via Right-click. - Adheres to the Blizzard CVars added in patch 7.1 - Numerous optimizations to how data and visual updates are handled; should see an even better load time, and snappier world map interaction. ClassPlan: - The 'Available Missions' list is now recorded. It can be reviewed by clicking on the mission list heading. - Information filtering by character and realm.
author Nenue
date Fri, 04 Nov 2016 02:53:57 -0400
parents 78cf1f19856a
children 589c444d4837
rev   line source
Nenue@36 1
Nenue@36 2 local print = DEVIAN_WORKSPACE and function(...) _G.print('Canvas', ...) end or function() end
Nenue@36 3 local wprint = DEVIAN_WORKSPACE and function(...) _G.print('WP', ...) end or function() end
Nenue@36 4 local wipe, pairs, ipairs = wipe, pairs, ipairs
Nenue@36 5 local HaveQuestData, QuestUtils_IsQuestWorldQuest, C_MapCanvas, C_TaskQuest = HaveQuestData, QuestUtils_IsQuestWorldQuest, C_MapCanvas, C_TaskQuest
Nenue@36 6
Nenue@36 7 WorldPlanFlightMapHandler = {
Nenue@36 8 TaskQueue = {}
Nenue@36 9 }
Nenue@36 10 WorldPlanDataProvider = {}
Nenue@36 11 WorldPlanDataPinMixin = {}
Nenue@36 12
Nenue@36 13 function WorldPlanFlightMapHandler:OnLoad()
Nenue@36 14 print('MapCanvas Module')
Nenue@36 15 self:RegisterEvent('ADDON_LOADED')
Nenue@36 16 end
Nenue@36 17 function WorldPlanFlightMapHandler:OnEvent(event, arg)
Nenue@36 18 if arg == "Blizzard_FlightMap" then
Nenue@36 19 print('sending data provider')
Nenue@36 20 local dataProvider = Mixin(MapCanvasDataProviderMixin, WorldPlanDataProvider)
Nenue@36 21 WorldPlanDataPinMixin = Mixin(MapCanvasPinMixin, WorldPlanDataPinMixin)
Nenue@36 22 WorldPlanDataPinMixin.OnNext = function(...) self:OnNext(...) end
Nenue@36 23 FlightMapFrame:AddDataProvider(dataProvider)
Nenue@36 24 end
Nenue@36 25 end
Nenue@36 26
Nenue@36 27 function WorldPlanFlightMapHandler:OnNext(func)
Nenue@36 28 tinsert(self.TaskQueue, func)
Nenue@36 29 end
Nenue@36 30
Nenue@36 31 function WorldPlanFlightMapHandler:OnUpdate()
Nenue@36 32 if #self.TaskQueue >= 1 then
Nenue@36 33 print('firing scheduled task ('.. tostring(#self.TaskQueue) ..' remaining)')
Nenue@36 34 local func = tremove(self.TaskQueue, 1)
Nenue@36 35 func()
Nenue@36 36 end
Nenue@36 37 end
Nenue@36 38
Nenue@36 39 function WorldPlanDataProvider:OnShow()
Nenue@36 40 assert(self.ticker == nil);
Nenue@36 41 self.ticker = C_Timer.NewTicker(10, function() self:RefreshAllData() end);
Nenue@36 42 end
Nenue@36 43 function WorldPlanDataProvider:OnHide()
Nenue@36 44 self.ticker:Cancel();
Nenue@36 45 self.ticker = nil;
Nenue@36 46 end
Nenue@36 47
Nenue@36 48 function WorldPlanDataProvider:OnAdded(mapCanvas)
Nenue@36 49 self.activePins = {};
Nenue@36 50 self.owningMap = mapCanvas
Nenue@37 51 self:RegisterEvent('QUEST_LOG_UPDATE')
Nenue@37 52
Nenue@38 53 -- get rid of blizzard's widgery-joob
Nenue@37 54 for frame in pairs(FlightMapFrame.dataProviders) do
Nenue@37 55 if frame.OnAdded == WorldQuestDataProviderMixin.OnAdded then
Nenue@37 56 FlightMapFrame:RemoveDataProvider(frame)
Nenue@37 57 break
Nenue@37 58 end
Nenue@37 59 end
Nenue@36 60 end
Nenue@36 61
Nenue@36 62
Nenue@36 63 function WorldPlanDataProvider:RefreshAllData()
Nenue@36 64 local print = print
Nenue@36 65 print('|cFFFF0088'..self.owningMap:GetName()..':RefreshAllData()|r')
Nenue@36 66
Nenue@36 67
Nenue@36 68 local pinsToRemove = {};
Nenue@36 69 for questId in pairs(self.activePins) do
Nenue@36 70 pinsToRemove[questId] = true;
Nenue@36 71 end
Nenue@36 72
Nenue@36 73
Nenue@36 74 local mapAreaID = self:GetMap():GetMapID();
Nenue@36 75 for zoneIndex = 1, C_MapCanvas.GetNumZones(mapAreaID) do
Nenue@36 76 local zoneMapID, zoneName, zoneDepth, left, right, top, bottom = C_MapCanvas.GetZoneInfo(mapAreaID, zoneIndex);
Nenue@36 77 print(zoneMapID, zoneName)
Nenue@36 78 if zoneDepth <= 1 then -- Exclude subzones
Nenue@36 79 local taskInfo = C_TaskQuest.GetQuestsForPlayerByMapID(zoneMapID, mapAreaID);
Nenue@36 80
Nenue@36 81 if taskInfo then
Nenue@36 82 for i, info in ipairs(taskInfo) do
Nenue@36 83 if HaveQuestData(info.questId) then
Nenue@36 84 if QuestUtils_IsQuestWorldQuest(info.questId) then
Nenue@36 85 local pin = WorldPlanQuests:AcquirePin(info.questId, zoneMapID)
Nenue@36 86 pin:RefreshData(info)
Nenue@36 87 pin:IsShowable()
Nenue@36 88 if pin.used then
Nenue@36 89 print(i, pin.x, pin.y, pin.used, pin.isNew, pin.isStale, pin:IsShown(), pin:GetAlpha())
Nenue@36 90 pinsToRemove[info.questId] = nil;
Nenue@36 91
Nenue@36 92 local frame = self.activePins[info.questId]
Nenue@36 93 if not frame then
Nenue@36 94 frame = self:GetMap():AcquirePin("WorldPlanFlightPin")
Nenue@36 95 frame:SetAlphaLimits(1, 0.7, 1)
Nenue@36 96 frame:SetScalingLimits(1, 3, 1.5);
Nenue@36 97 frame:SetFrameLevel(1000 + self:GetMap():GetNumActivePinsByTemplate("WorldPlanFlightPin"));
Nenue@36 98 frame:Show()
Nenue@36 99 self.activePins[info.questId] = frame
Nenue@36 100 end
Nenue@36 101 frame:SetPosition(info.x, info.y)
Nenue@36 102 frame.pin = pin
Nenue@36 103
Nenue@37 104 pin.owningFrame = self:GetMap()
Nenue@36 105 pin.isStale = true
Nenue@36 106 pin:SetParent(frame)
Nenue@36 107 pin:ClearAllPoints()
Nenue@36 108 pin:SetPoint('CENTER', frame, 'CENTER')
Nenue@36 109
Nenue@36 110 end
Nenue@36 111 pin:SetShown(pin.used)
Nenue@36 112 end
Nenue@36 113 end
Nenue@36 114 end
Nenue@36 115 end
Nenue@36 116 end
Nenue@36 117 end
Nenue@36 118
Nenue@36 119 for questId in pairs(pinsToRemove) do
Nenue@36 120 self:GetMap():RemovePin(self.activePins[questId]);
Nenue@36 121 self.activePins[questId] = nil;
Nenue@36 122 end
Nenue@36 123 --self:GetMap():RemoveAllPinsByTemplate("WorldQuestPinTemplate");
Nenue@37 124 for pin in self:GetMap():EnumeratePinsByTemplate("WorldQuestPinTemplate") do
Nenue@37 125 pin:Hide()
Nenue@37 126 end
Nenue@36 127
Nenue@36 128 end
Nenue@37 129 function WorldPlanDataProvider:OnEvent()
Nenue@37 130 for pin in self:GetMap():EnumeratePinsByTemplate("WorldQuestPinTemplate") do
Nenue@37 131 pin:Hide()
Nenue@37 132 end
Nenue@37 133 end
Nenue@36 134
Nenue@36 135 function WorldPlanDataPinMixin:OnShow()
Nenue@36 136 print('|cFFFFFF00'..tostring(self:GetName())..':OnShow()|r')
Nenue@36 137 end
Nenue@36 138
Nenue@36 139 function WorldPlanDataPinMixin:OnMouseEnter ()
Nenue@37 140
Nenue@36 141 end
Nenue@36 142
Nenue@36 143 function WorldPlanDataPinMixin:OnMouseLeave ()
Nenue@37 144
Nenue@36 145 end
Nenue@36 146
Nenue@36 147 function WorldPlanDataPinMixin:RemoveAllData()
Nenue@36 148 wipe(self.activePins);
Nenue@36 149 self:GetMap():RemoveAllPinsByTemplate("WorldPlanFlightPin");
Nenue@36 150 end