Nenue@40: local _, db= ... Nenue@35: local ORDERHALL_TYPE = LE_GARRISON_TYPE_7_0 Nenue@40: local UnitClass = UnitClass Nenue@40: local time, max, min = time, max, min Nenue@40: local print = DEVIAN_WORKSPACE and function(...) print('ClassPlan', ...) end or nop Nenue@35: local GetPrimaryGarrisonFollowerType = GetPrimaryGarrisonFollowerType Nenue@35: local C_Garrison = C_Garrison Nenue@35: Nenue@35: local wipe, tinsert, date, ipairs = table.wipe, table.insert, date, ipairs Nenue@35: local GetItemIcon = GetItemIcon Nenue@35: Nenue@40: Nenue@40: local MissionList = { Nenue@40: templateName = 'ClassPlanMissionEntry', Nenue@40: listKey = {'missions', 'available'}, Nenue@40: listTitle = {'In Progress', 'Available'}, Nenue@40: Nenue@40: point = 'TOPLEFT', Nenue@40: relativePoint ='TOPLEFT', Nenue@40: events = { Nenue@40: 'GARRISON_MISSION_LIST_UPDATE'}, Nenue@40: } Nenue@40: local ListEntry = {} Nenue@40: Nenue@40: function MissionList:Reanchor() Nenue@40: self:SetPoint('TOPRIGHT', ClassOrderPlan.BackgroundInset, 'TOPRIGHT', 0, 0) Nenue@40: self:SetPoint('BOTTOMLEFT', ClassOrderPlan:GetWidth()/2, 0) Nenue@40: end Nenue@40: Nenue@40: Nenue@40: Nenue@40: Nenue@40: function MissionList:GetPlayerData () Nenue@40: local profile = self:GetParent().profile Nenue@35: local items = C_Garrison.GetAvailableMissions(GetPrimaryGarrisonFollowerType(ORDERHALL_TYPE)); Nenue@35: if not items then Nenue@35: return Nenue@35: end Nenue@35: wipe(profile.missions) Nenue@35: wipe(profile.available) Nenue@35: Nenue@35: Nenue@95: for _, data in ipairs(items) do Nenue@35: Nenue@95: --print(' -',data.name, '|cFF00FF00'.. data.offerEndTime .. '|r', date("%A %I:%m %p", data.offerEndTime)) Nenue@95: if data.offerEndTime then Nenue@95: data.offerEndTime = time() + (data.offerEndTime - GetTime()) Nenue@35: end Nenue@95: tinsert(profile.available, data) Nenue@95: Nenue@35: end Nenue@35: Nenue@35: local items = C_Garrison.GetLandingPageItems(ORDERHALL_TYPE) Nenue@35: for index, data in ipairs(items) do Nenue@35: print(' -',data.name, '|cFF00FF00'.. data.timeLeft .. '|r', date("%A %I:%m %p", data.missionEndTime)) Nenue@35: tinsert(profile.missions, data) Nenue@35: end Nenue@35: return true Nenue@35: end Nenue@35: Nenue@40: function MissionList:OnGetItem (data) Nenue@40: if data.missionEndTime then Nenue@40: if (data.missionEndTime < self.currentTime) then Nenue@40: data.isComplete = true Nenue@40: else Nenue@40: self:ScheduleUpdate(data.missionEndTime) Nenue@40: end Nenue@35: end Nenue@40: Nenue@40: if data.offerEndTime then Nenue@40: if (data.offerEndTime < self.currentTime) then Nenue@40: data.isExpired = true Nenue@40: data.timeToKeep = self.currentTime + 300 Nenue@40: else Nenue@40: self:ScheduleUpdate(data.offerEndTime) Nenue@40: end Nenue@35: end Nenue@40: Nenue@35: end Nenue@35: Nenue@35: MissionList.SortHandler = function (a,b) Nenue@35: local result = false Nenue@35: if b.isComplete ~= a.isComplete then Nenue@35: return a.isComplete Nenue@35: else Nenue@40: if b.isMine ~= a.isMine then Nenue@40: return a.isMine Nenue@40: else Nenue@40: if a.isComplete then Nenue@40: if a.profileKey ~= b.profileKey then Nenue@40: return (a.profileKey < b.profileKey) Nenue@40: else Nenue@40: return (a.name < b.name) Nenue@40: end Nenue@40: else Nenue@40: if b.missionEndTime then Nenue@40: return ( b.missionEndTime > a.missionEndTime) Nenue@40: else Nenue@40: return ((b.offerEndTime or 0) > (a.offerEndTime or 0)) Nenue@40: end Nenue@40: end Nenue@40: end Nenue@40: end Nenue@40: end Nenue@40: Nenue@40: function MissionList:OnEvent(event, ...) Nenue@40: self:RefreshData() Nenue@40: if event == 'GARRISON_MISSION_FINISHED' then Nenue@40: local followerTypeID, missionID = ...; Nenue@40: elseif event == 'GARRISON_TALENT_COMPLETE' then Nenue@40: local garrisonType = ...; Nenue@40: elseif event == '' then Nenue@35: end Nenue@35: Nenue@35: end Nenue@35: Nenue@35: function MissionList:OnShow() Nenue@35: print('|cFF00FF88'..self:GetName()..':OnShow()|r') Nenue@35: end Nenue@35: Nenue@40: function ListEntry:OnComplete() Nenue@35: print('flagging complete', self.name) Nenue@35: self:Update() Nenue@35: end Nenue@35: Nenue@40: function ListEntry:OnUpdate(sinceLast) Nenue@40: if self.doAnimation then Nenue@40: self.doAnimation = nil Nenue@40: self.NewBlockFade:Play() Nenue@40: end Nenue@35: self.throttle = (self.throttle or .5) + sinceLast Nenue@35: if self.throttle < .5 then Nenue@35: return Nenue@35: else Nenue@35: self.throttle = self.throttle - .5 Nenue@35: end Nenue@40: Nenue@35: if self.offerEndTime then Nenue@35: self:SetTimeLeft(self.offerEndTime) Nenue@35: elseif self.missionEndTime then Nenue@35: self:SetTimeLeft(self.missionEndTime, self.durationSeconds) Nenue@35: end Nenue@35: end Nenue@35: Nenue@40: function ListEntry:OnHide(...) Nenue@40: print(self:GetName().. ':Hide()', ...) Nenue@40: end Nenue@40: Nenue@40: function ListEntry:OnLoad() Nenue@40: print('|cFFFF4400'..self:GetName()..':OnLoad()') Nenue@35: self.Count = self.Overlay.Count Nenue@35: self.Name = self.Overlay.Name Nenue@35: self.TimeLeft = self.Overlay.TimeLeft Nenue@35: self.Owner = self.Overlay.Owner Nenue@35: self.maxDisplayed = 10 Nenue@35: Nenue@35: self.Icon:SetDesaturated(false) Nenue@35: self.Done:Hide() Nenue@40: --[[ Nenue@40: hooksecurefunc(self.Background, 'SetColorTexture', function(self, ...) Nenue@40: print(self:GetName(), ...) Nenue@40: end) Nenue@40: hooksecurefunc(self.Background, 'SetTexture', function(self, ...) Nenue@40: --print(self:GetName(), ...) Nenue@40: end) Nenue@40: --]] Nenue@35: end Nenue@35: Nenue@40: function ListEntry:Update() Nenue@35: local r,g,b = 1, 1, 1 Nenue@35: if self.isRare then Nenue@35: r,g,b = 0.1, 0.4, 1 Nenue@35: self.IconBorder:SetVertexColor(r, g, b, 1) Nenue@35: end Nenue@35: Nenue@35: --self.missionData = data Nenue@35: self.Name:SetText(self.name) Nenue@35: if #self.rewards >= 1 then Nenue@35: self.Icon:SetTexture(self.rewards[1].icon or GetItemIcon(self.rewards[1].itemID)) Nenue@35: self.rewardInfo = self.rewards[1] Nenue@35: else Nenue@35: self.Icon:SetAtlas(self.typeAtlas, false) Nenue@35: end Nenue@35: Nenue@40: local itemType = db.ClassPlanTypes.inProgress Nenue@40: if self.isComplete then Nenue@40: itemType = db.ClassPlanTypes.complete Nenue@40: end Nenue@35: Nenue@40: self.Background:SetColorTexture(unpack(itemType.backgroundColor)) Nenue@35: end Nenue@35: Nenue@35: function ListEntry:OnEnter() Nenue@40: WorldMap_HijackTooltip(self) Nenue@35: if self.rewardInfo and self.rewardInfo.itemID then Nenue@40: WorldMapTooltip:SetOwner(self, 'ANCHOR_LEFT') Nenue@40: WorldMapTooltip:AddLine(self.name) Nenue@40: EmbeddedItemTooltip_SetItemByID(WorldMapTooltip.ItemTooltip, self.rewardInfo.itemID) Nenue@40: WorldMapTooltip:Show() Nenue@35: end Nenue@35: end Nenue@35: Nenue@35: function ListEntry:OnLeave() Nenue@40: WorldMap_RestoreTooltip() Nenue@40: if WorldMapTooltip:IsOwned(self) then Nenue@40: WorldMapTooltip:Hide() Nenue@35: end Nenue@40: end Nenue@40: Nenue@40: Nenue@40: ClassPlanMissionHandler = CreateFromMixins(ClassPlanHandlerBase, MissionList) Nenue@40: ClassPlanMissionEntryMixin = CreateFromMixins(ClassPlanEntryBase, ListEntry)