Nenue@40: local _, db = ... 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@40: function WorldPlanDataProvider:OnLoad() Nenue@40: Nenue@40: self:SetNudgeTargetFactor(0.015); Nenue@53: self:SetNudgeZoomedOutFactor(0.5); Nenue@53: self:SetNudgeZoomedInFactor(0.15); Nenue@40: end Nenue@40: 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@37: self:RegisterEvent('QUEST_LOG_UPDATE') Nenue@37: Nenue@38: -- get rid of blizzard's widgery-joob Nenue@37: for frame in pairs(FlightMapFrame.dataProviders) do Nenue@37: if frame.OnAdded == WorldQuestDataProviderMixin.OnAdded then Nenue@37: FlightMapFrame:RemoveDataProvider(frame) Nenue@37: break Nenue@37: end Nenue@37: end 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@40: print(unpack(db.Config.FlightMapAlphaLimits)) Nenue@40: local alpha1, alpha2, alpha3 = unpack(db.Config.FlightMapAlphaLimits) Nenue@40: local scale1, scale2, scale3 = unpack(db.Config.FlightMapScalingLimits) 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@49: local pin = WorldPlanQuests:AcquirePin(info, zoneMapID) Nenue@49: if pin then Nenue@49: Nenue@49: print(pin:GetID(), pin.used, pin.filtered) Nenue@49: Nenue@49: if pin.used then Nenue@49: pinsToRemove[info.questId] = nil; Nenue@49: Nenue@49: local frame = self.activePins[info.questId] Nenue@49: if not frame then Nenue@49: frame = self:GetMap():AcquirePin("WorldPlanFlightPin") Nenue@49: print(alpha1, alpha2, alpha3) Nenue@49: print(scale1, scale2, scale3) Nenue@49: frame:SetAlphaLimits(alpha1, alpha2, alpha3) Nenue@49: frame:SetScalingLimits(scale1, scale2, scale3); Nenue@49: frame:SetFrameLevel(1000 + self:GetMap():GetNumActivePinsByTemplate("WorldPlanFlightPin")); Nenue@49: frame:Show() Nenue@49: self.activePins[info.questId] = frame Nenue@49: end Nenue@49: frame:SetPosition(info.x, info.y) Nenue@49: frame.pin = pin Nenue@49: Nenue@52: -- sticking it onto the MapCanvas pin Nenue@56: pin.owningFrame = frame:GetMap() Nenue@49: pin.throttle = 1 Nenue@49: pin.isStale = true Nenue@53: pin:SetAnchor(frame) Nenue@52: --print(pin.Overlay:IsShown(), pin.Overlay:GetPoint(1)) Nenue@49: end Nenue@49: pin:SetShown(pin.used) Nenue@40: end Nenue@40: 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@37: for pin in self:GetMap():EnumeratePinsByTemplate("WorldQuestPinTemplate") do Nenue@37: pin:Hide() Nenue@37: end Nenue@36: Nenue@36: end Nenue@49: Nenue@49: Nenue@49: Nenue@37: function WorldPlanDataProvider:OnEvent() Nenue@37: end Nenue@36: Nenue@49: function WorldPlanDataPinMixin:OnLoad() Nenue@49: self.UpdateTooltip = self.OnMouseEnter; Nenue@49: Nenue@49: -- Flight points can nudge world quests. Nenue@49: self:SetNudgeTargetFactor(0.015); Nenue@49: self:SetNudgeZoomedOutFactor(1.0); Nenue@49: self:SetNudgeZoomedInFactor(0.25); Nenue@49: end Nenue@49: Nenue@36: function WorldPlanDataPinMixin:OnShow() Nenue@36: end Nenue@36: Nenue@36: function WorldPlanDataPinMixin:OnMouseEnter () Nenue@52: Nenue@52: WorldMap_HijackTooltip(self:GetMap()) Nenue@36: end Nenue@36: Nenue@36: function WorldPlanDataPinMixin:OnMouseLeave () Nenue@36: end Nenue@36: Nenue@36: function WorldPlanDataPinMixin:RemoveAllData() Nenue@36: wipe(self.activePins); Nenue@36: self:GetMap():RemoveAllPinsByTemplate("WorldPlanFlightPin"); Nenue@36: end