annotate FlightMap.lua @ 36:21bcff08b0f4

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 01:40:39 -0400
parents
children 78cf1f19856a
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@36 51 end
Nenue@36 52
Nenue@36 53
Nenue@36 54 function WorldPlanDataProvider:RefreshAllData()
Nenue@36 55 local print = print
Nenue@36 56 print('|cFFFF0088'..self.owningMap:GetName()..':RefreshAllData()|r')
Nenue@36 57
Nenue@36 58
Nenue@36 59 local pinsToRemove = {};
Nenue@36 60 for questId in pairs(self.activePins) do
Nenue@36 61 pinsToRemove[questId] = true;
Nenue@36 62 end
Nenue@36 63
Nenue@36 64
Nenue@36 65 local mapAreaID = self:GetMap():GetMapID();
Nenue@36 66 for zoneIndex = 1, C_MapCanvas.GetNumZones(mapAreaID) do
Nenue@36 67 local zoneMapID, zoneName, zoneDepth, left, right, top, bottom = C_MapCanvas.GetZoneInfo(mapAreaID, zoneIndex);
Nenue@36 68 print(zoneMapID, zoneName)
Nenue@36 69 if zoneDepth <= 1 then -- Exclude subzones
Nenue@36 70 local taskInfo = C_TaskQuest.GetQuestsForPlayerByMapID(zoneMapID, mapAreaID);
Nenue@36 71
Nenue@36 72 if taskInfo then
Nenue@36 73 for i, info in ipairs(taskInfo) do
Nenue@36 74 if HaveQuestData(info.questId) then
Nenue@36 75 if QuestUtils_IsQuestWorldQuest(info.questId) then
Nenue@36 76 local pin = WorldPlanQuests:AcquirePin(info.questId, zoneMapID)
Nenue@36 77 pin:RefreshData(info)
Nenue@36 78 pin:IsShowable()
Nenue@36 79 if pin.used then
Nenue@36 80 print(i, pin.x, pin.y, pin.used, pin.isNew, pin.isStale, pin:IsShown(), pin:GetAlpha())
Nenue@36 81 pinsToRemove[info.questId] = nil;
Nenue@36 82
Nenue@36 83 local frame = self.activePins[info.questId]
Nenue@36 84 if not frame then
Nenue@36 85 frame = self:GetMap():AcquirePin("WorldPlanFlightPin")
Nenue@36 86 frame:SetAlphaLimits(1, 0.7, 1)
Nenue@36 87 frame:SetScalingLimits(1, 3, 1.5);
Nenue@36 88 frame:SetFrameLevel(1000 + self:GetMap():GetNumActivePinsByTemplate("WorldPlanFlightPin"));
Nenue@36 89 frame:Show()
Nenue@36 90 self.activePins[info.questId] = frame
Nenue@36 91 end
Nenue@36 92 frame:SetPosition(info.x, info.y)
Nenue@36 93 frame.pin = pin
Nenue@36 94
Nenue@36 95 pin.isStale = true
Nenue@36 96 pin:SetParent(frame)
Nenue@36 97 pin:ClearAllPoints()
Nenue@36 98 pin:SetPoint('CENTER', frame, 'CENTER')
Nenue@36 99
Nenue@36 100 end
Nenue@36 101 pin:SetShown(pin.used)
Nenue@36 102 end
Nenue@36 103 end
Nenue@36 104 end
Nenue@36 105 end
Nenue@36 106 end
Nenue@36 107 end
Nenue@36 108
Nenue@36 109 for questId in pairs(pinsToRemove) do
Nenue@36 110 self:GetMap():RemovePin(self.activePins[questId]);
Nenue@36 111 self.activePins[questId] = nil;
Nenue@36 112 end
Nenue@36 113 --self:GetMap():RemoveAllPinsByTemplate("WorldQuestPinTemplate");
Nenue@36 114
Nenue@36 115 end
Nenue@36 116
Nenue@36 117 function WorldPlanDataPinMixin:OnShow()
Nenue@36 118 print('|cFFFFFF00'..tostring(self:GetName())..':OnShow()|r')
Nenue@36 119 end
Nenue@36 120
Nenue@36 121 function WorldPlanDataPinMixin:OnMouseEnter ()
Nenue@36 122 self.pin:OnEnter()
Nenue@36 123 end
Nenue@36 124
Nenue@36 125 function WorldPlanDataPinMixin:OnMouseLeave ()
Nenue@36 126 self.pin:OnLeave()
Nenue@36 127 end
Nenue@36 128
Nenue@36 129 function WorldPlanDataPinMixin:RemoveAllData()
Nenue@36 130 wipe(self.activePins);
Nenue@36 131 self:GetMap():RemoveAllPinsByTemplate("WorldPlanFlightPin");
Nenue@36 132 end