annotate FlightMap.lua @ 40:589c444d4837

WowAce/Curseforge migration push
author Nenue
date Sun, 25 Dec 2016 13:04:57 -0500
parents a93cae445d3f
children dbd81d49af02
rev   line source
Nenue@40 1 local _, db = ...
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@40 39 function WorldPlanDataProvider:OnLoad()
Nenue@40 40
Nenue@40 41 self:SetNudgeTargetFactor(0.015);
Nenue@40 42 self:SetNudgeZoomedOutFactor(1.0);
Nenue@40 43 self:SetNudgeZoomedInFactor(0.25);
Nenue@40 44 end
Nenue@40 45
Nenue@36 46 function WorldPlanDataProvider:OnShow()
Nenue@36 47 assert(self.ticker == nil);
Nenue@36 48 self.ticker = C_Timer.NewTicker(10, function() self:RefreshAllData() end);
Nenue@36 49 end
Nenue@36 50 function WorldPlanDataProvider:OnHide()
Nenue@36 51 self.ticker:Cancel();
Nenue@36 52 self.ticker = nil;
Nenue@36 53 end
Nenue@36 54
Nenue@36 55 function WorldPlanDataProvider:OnAdded(mapCanvas)
Nenue@36 56 self.activePins = {};
Nenue@36 57 self.owningMap = mapCanvas
Nenue@37 58 self:RegisterEvent('QUEST_LOG_UPDATE')
Nenue@37 59
Nenue@38 60 -- get rid of blizzard's widgery-joob
Nenue@37 61 for frame in pairs(FlightMapFrame.dataProviders) do
Nenue@37 62 if frame.OnAdded == WorldQuestDataProviderMixin.OnAdded then
Nenue@37 63 FlightMapFrame:RemoveDataProvider(frame)
Nenue@37 64 break
Nenue@37 65 end
Nenue@37 66 end
Nenue@36 67 end
Nenue@36 68
Nenue@36 69
Nenue@36 70 function WorldPlanDataProvider:RefreshAllData()
Nenue@36 71 local print = print
Nenue@36 72 print('|cFFFF0088'..self.owningMap:GetName()..':RefreshAllData()|r')
Nenue@36 73
Nenue@36 74
Nenue@36 75 local pinsToRemove = {};
Nenue@36 76 for questId in pairs(self.activePins) do
Nenue@36 77 pinsToRemove[questId] = true;
Nenue@36 78 end
Nenue@40 79 print(unpack(db.Config.FlightMapAlphaLimits))
Nenue@40 80 local alpha1, alpha2, alpha3 = unpack(db.Config.FlightMapAlphaLimits)
Nenue@40 81 local scale1, scale2, scale3 = unpack(db.Config.FlightMapScalingLimits)
Nenue@36 82
Nenue@36 83 local mapAreaID = self:GetMap():GetMapID();
Nenue@36 84 for zoneIndex = 1, C_MapCanvas.GetNumZones(mapAreaID) do
Nenue@36 85 local zoneMapID, zoneName, zoneDepth, left, right, top, bottom = C_MapCanvas.GetZoneInfo(mapAreaID, zoneIndex);
Nenue@36 86 print(zoneMapID, zoneName)
Nenue@36 87 if zoneDepth <= 1 then -- Exclude subzones
Nenue@36 88 local taskInfo = C_TaskQuest.GetQuestsForPlayerByMapID(zoneMapID, mapAreaID);
Nenue@36 89
Nenue@36 90 if taskInfo then
Nenue@36 91 for i, info in ipairs(taskInfo) do
Nenue@36 92 if HaveQuestData(info.questId) then
Nenue@36 93 if QuestUtils_IsQuestWorldQuest(info.questId) then
Nenue@40 94 local pin = db.QuestsByID[info.questId]
Nenue@40 95 if not db.QuestsByID[info.questId] then
Nenue@40 96 pin = WorldPlanQuests:AcquirePin(info, zoneMapID)
Nenue@40 97 end
Nenue@40 98
Nenue@36 99 pin:IsShowable()
Nenue@36 100 if pin.used then
Nenue@36 101 print(i, pin.x, pin.y, pin.used, pin.isNew, pin.isStale, pin:IsShown(), pin:GetAlpha())
Nenue@36 102 pinsToRemove[info.questId] = nil;
Nenue@36 103
Nenue@36 104 local frame = self.activePins[info.questId]
Nenue@36 105 if not frame then
Nenue@36 106 frame = self:GetMap():AcquirePin("WorldPlanFlightPin")
Nenue@40 107 print(alpha1, alpha2, alpha3)
Nenue@40 108 print(scale1, scale2, scale3)
Nenue@40 109 frame:SetAlphaLimits(alpha1, alpha2, alpha3)
Nenue@40 110 frame:SetScalingLimits(scale1, scale2, scale3);
Nenue@36 111 frame:SetFrameLevel(1000 + self:GetMap():GetNumActivePinsByTemplate("WorldPlanFlightPin"));
Nenue@36 112 frame:Show()
Nenue@36 113 self.activePins[info.questId] = frame
Nenue@36 114 end
Nenue@36 115 frame:SetPosition(info.x, info.y)
Nenue@36 116 frame.pin = pin
Nenue@36 117
Nenue@40 118 pin.owningFrame = frame:GetMap()
Nenue@36 119 pin.isStale = true
Nenue@36 120 pin:SetParent(frame)
Nenue@36 121 pin:ClearAllPoints()
Nenue@36 122 pin:SetPoint('CENTER', frame, 'CENTER')
Nenue@36 123
Nenue@36 124 end
Nenue@36 125 pin:SetShown(pin.used)
Nenue@36 126 end
Nenue@36 127 end
Nenue@36 128 end
Nenue@36 129 end
Nenue@36 130 end
Nenue@36 131 end
Nenue@36 132
Nenue@36 133 for questId in pairs(pinsToRemove) do
Nenue@36 134 self:GetMap():RemovePin(self.activePins[questId]);
Nenue@36 135 self.activePins[questId] = nil;
Nenue@36 136 end
Nenue@36 137 --self:GetMap():RemoveAllPinsByTemplate("WorldQuestPinTemplate");
Nenue@37 138 for pin in self:GetMap():EnumeratePinsByTemplate("WorldQuestPinTemplate") do
Nenue@37 139 pin:Hide()
Nenue@37 140 end
Nenue@36 141
Nenue@36 142 end
Nenue@37 143 function WorldPlanDataProvider:OnEvent()
Nenue@37 144 end
Nenue@36 145
Nenue@36 146 function WorldPlanDataPinMixin:OnShow()
Nenue@36 147 end
Nenue@36 148
Nenue@36 149 function WorldPlanDataPinMixin:OnMouseEnter ()
Nenue@36 150 end
Nenue@36 151
Nenue@36 152 function WorldPlanDataPinMixin:OnMouseLeave ()
Nenue@36 153 end
Nenue@36 154
Nenue@36 155 function WorldPlanDataPinMixin:RemoveAllData()
Nenue@36 156 wipe(self.activePins);
Nenue@36 157 self:GetMap():RemoveAllPinsByTemplate("WorldPlanFlightPin");
Nenue@36 158 end