Nenue@36: Nenue@36: local print = DEVIAN_WORKSPACE and function(...) _G.print('Canvas', ...) end or function() end Nenue@36: local wprint = DEVIAN_WORKSPACE and function(...) _G.print('WP', ...) end or function() end Nenue@36: local wipe, pairs, ipairs = wipe, pairs, ipairs Nenue@36: local HaveQuestData, QuestUtils_IsQuestWorldQuest, C_MapCanvas, C_TaskQuest = HaveQuestData, QuestUtils_IsQuestWorldQuest, C_MapCanvas, C_TaskQuest Nenue@36: Nenue@36: WorldPlanFlightMapHandler = { Nenue@36: TaskQueue = {} Nenue@36: } Nenue@36: WorldPlanDataProvider = {} Nenue@36: WorldPlanDataPinMixin = {} Nenue@36: Nenue@36: function WorldPlanFlightMapHandler:OnLoad() Nenue@36: print('MapCanvas Module') Nenue@36: self:RegisterEvent('ADDON_LOADED') Nenue@36: end Nenue@36: function WorldPlanFlightMapHandler:OnEvent(event, arg) Nenue@36: if arg == "Blizzard_FlightMap" then Nenue@36: print('sending data provider') Nenue@36: local dataProvider = Mixin(MapCanvasDataProviderMixin, WorldPlanDataProvider) Nenue@36: WorldPlanDataPinMixin = Mixin(MapCanvasPinMixin, WorldPlanDataPinMixin) Nenue@36: WorldPlanDataPinMixin.OnNext = function(...) self:OnNext(...) end Nenue@36: FlightMapFrame:AddDataProvider(dataProvider) Nenue@36: end Nenue@36: end Nenue@36: Nenue@36: function WorldPlanFlightMapHandler:OnNext(func) Nenue@36: tinsert(self.TaskQueue, func) Nenue@36: end Nenue@36: Nenue@36: function WorldPlanFlightMapHandler:OnUpdate() Nenue@36: if #self.TaskQueue >= 1 then Nenue@36: print('firing scheduled task ('.. tostring(#self.TaskQueue) ..' remaining)') Nenue@36: local func = tremove(self.TaskQueue, 1) Nenue@36: func() Nenue@36: end Nenue@36: end Nenue@36: Nenue@36: function WorldPlanDataProvider:OnShow() Nenue@36: assert(self.ticker == nil); Nenue@36: self.ticker = C_Timer.NewTicker(10, function() self:RefreshAllData() end); Nenue@36: end Nenue@36: function WorldPlanDataProvider:OnHide() Nenue@36: self.ticker:Cancel(); Nenue@36: self.ticker = nil; Nenue@36: end Nenue@36: Nenue@36: function WorldPlanDataProvider:OnAdded(mapCanvas) Nenue@36: self.activePins = {}; Nenue@36: self.owningMap = mapCanvas Nenue@36: end Nenue@36: Nenue@36: Nenue@36: function WorldPlanDataProvider:RefreshAllData() Nenue@36: local print = print Nenue@36: print('|cFFFF0088'..self.owningMap:GetName()..':RefreshAllData()|r') Nenue@36: Nenue@36: Nenue@36: local pinsToRemove = {}; Nenue@36: for questId in pairs(self.activePins) do Nenue@36: pinsToRemove[questId] = true; Nenue@36: end Nenue@36: Nenue@36: Nenue@36: local mapAreaID = self:GetMap():GetMapID(); Nenue@36: for zoneIndex = 1, C_MapCanvas.GetNumZones(mapAreaID) do Nenue@36: local zoneMapID, zoneName, zoneDepth, left, right, top, bottom = C_MapCanvas.GetZoneInfo(mapAreaID, zoneIndex); Nenue@36: print(zoneMapID, zoneName) Nenue@36: if zoneDepth <= 1 then -- Exclude subzones Nenue@36: local taskInfo = C_TaskQuest.GetQuestsForPlayerByMapID(zoneMapID, mapAreaID); Nenue@36: Nenue@36: if taskInfo then Nenue@36: for i, info in ipairs(taskInfo) do Nenue@36: if HaveQuestData(info.questId) then Nenue@36: if QuestUtils_IsQuestWorldQuest(info.questId) then Nenue@36: local pin = WorldPlanQuests:AcquirePin(info.questId, zoneMapID) Nenue@36: pin:RefreshData(info) Nenue@36: pin:IsShowable() Nenue@36: if pin.used then Nenue@36: print(i, pin.x, pin.y, pin.used, pin.isNew, pin.isStale, pin:IsShown(), pin:GetAlpha()) Nenue@36: pinsToRemove[info.questId] = nil; Nenue@36: Nenue@36: local frame = self.activePins[info.questId] Nenue@36: if not frame then Nenue@36: frame = self:GetMap():AcquirePin("WorldPlanFlightPin") Nenue@36: frame:SetAlphaLimits(1, 0.7, 1) Nenue@36: frame:SetScalingLimits(1, 3, 1.5); Nenue@36: frame:SetFrameLevel(1000 + self:GetMap():GetNumActivePinsByTemplate("WorldPlanFlightPin")); Nenue@36: frame:Show() Nenue@36: self.activePins[info.questId] = frame Nenue@36: end Nenue@36: frame:SetPosition(info.x, info.y) Nenue@36: frame.pin = pin Nenue@36: Nenue@36: pin.isStale = true Nenue@36: pin:SetParent(frame) Nenue@36: pin:ClearAllPoints() Nenue@36: pin:SetPoint('CENTER', frame, 'CENTER') Nenue@36: Nenue@36: end Nenue@36: pin:SetShown(pin.used) Nenue@36: end Nenue@36: end Nenue@36: end Nenue@36: end Nenue@36: end Nenue@36: end Nenue@36: Nenue@36: for questId in pairs(pinsToRemove) do Nenue@36: self:GetMap():RemovePin(self.activePins[questId]); Nenue@36: self.activePins[questId] = nil; Nenue@36: end Nenue@36: --self:GetMap():RemoveAllPinsByTemplate("WorldQuestPinTemplate"); Nenue@36: Nenue@36: end Nenue@36: Nenue@36: function WorldPlanDataPinMixin:OnShow() Nenue@36: print('|cFFFFFF00'..tostring(self:GetName())..':OnShow()|r') Nenue@36: end Nenue@36: Nenue@36: function WorldPlanDataPinMixin:OnMouseEnter () Nenue@36: self.pin:OnEnter() Nenue@36: end Nenue@36: Nenue@36: function WorldPlanDataPinMixin:OnMouseLeave () Nenue@36: self.pin:OnLeave() Nenue@36: end Nenue@36: Nenue@36: function WorldPlanDataPinMixin:RemoveAllData() Nenue@36: wipe(self.activePins); Nenue@36: self:GetMap():RemoveAllPinsByTemplate("WorldPlanFlightPin"); Nenue@36: end