Nenue@1: SLASH_CLASSPLAN1 = "/classplan" Nenue@1: SLASH_CLASSPLAN2 = "/cp" Nenue@1: SlashCmdList.CLASSPLAN = function(args) Nenue@1: if ClassOrderPlan:IsVisible() then Nenue@1: ClassOrderPlan:Hide() Nenue@1: else Nenue@1: ClassOrderPlan:Show() Nenue@1: DEFAULT_CHAT_FRAME:AddMessage('|cFF88FF00WorldPlan|r: Order Hall Panel') Nenue@1: end Nenue@1: end Nenue@1: Nenue@1: ClassOrderPlanCore = { Nenue@1: blocks = {}, Nenue@1: playerFirst = true, Nenue@1: timers = {} Nenue@1: } Nenue@1: ClassPlanBlockMixin = { Nenue@1: followers = {}, Nenue@1: blocks = {}, Nenue@1: } Nenue@1: local core, block = ClassOrderPlanCore, ClassPlanBlockMixin Nenue@1: local print = DEVIAN_WORKSPACE and function(...) print('ClassPlan', ...) end or nop Nenue@1: Nenue@1: function core:OnLoad () Nenue@1: self:RegisterUnitEvent('UNIT_PORTRAIT_UPDATE', 'player') Nenue@1: self:RegisterEvent('GARRISON_MISSION_STARTED') Nenue@1: self:RegisterEvent('GARRISON_MISSION_FINISHED') Nenue@1: self:RegisterEvent('PLAYER_LOGIN') Nenue@1: self:RegisterEvent('PLAYER_ENTERING_WORLD') Nenue@1: end Nenue@1: Nenue@1: Nenue@1: function core:OnEvent (event, ...) Nenue@1: if event == 'UNIT_PORTRAIT_UPDATE' then Nenue@1: SetPortraitTexture(self.portrait, 'player') Nenue@1: elseif event == 'PLAYER_LOGIN' then Nenue@1: if not self.initialized then Nenue@1: if IsLoggedIn() then Nenue@1: WorldPlanData.OrderHall = WorldPlanData.OrderHall or {} Nenue@1: self.data = WorldPlanData.OrderHall Nenue@1: Nenue@1: Nenue@1: local name, realm = UnitName('player') Nenue@1: realm = realm or GetRealmName() Nenue@1: self.profileKey = name .. '-' .. realm Nenue@1: if not self.data[self.profileKey] then Nenue@1: self.data[self.profileKey] = {} Nenue@1: end Nenue@1: self.profile = self.data[self.profileKey] Nenue@1: Nenue@1: self.initialized = true Nenue@1: print('initialized') Nenue@1: end Nenue@1: end Nenue@1: else Nenue@1: self:Refresh () Nenue@1: end Nenue@1: end Nenue@1: Nenue@1: function core:UpdateList() Nenue@1: self.sortedMissions = self.sortedMissions or {} Nenue@1: table.wipe(self.sortedMissions) Nenue@1: Nenue@1: for name, profile in pairs(self.data) do Nenue@1: local isMine = (profile == self.profile) Nenue@1: for index, data in pairs(profile.missions) do Nenue@1: Nenue@1: data.classColor = profile.classColor or {r = 0.7, g = 0.7, b =0.7} Nenue@1: Nenue@1: data.profileKey = name Nenue@1: data.isMine = (profile == self.profile) Nenue@1: tinsert(self.sortedMissions, data) Nenue@1: end Nenue@1: end Nenue@1: Nenue@1: for i, v in ipairs(self.sortedMissions) do Nenue@1: print(i, v.missionEndTime, v.name) Nenue@1: end Nenue@1: Nenue@1: Nenue@1: table.sort(self.sortedMissions, function(a,b) Nenue@1: local result = false Nenue@1: if not a or not b then Nenue@1: result = true Nenue@1: else Nenue@1: Nenue@1: if (a.isMine ~= b.isMine) and self.playerFirst then Nenue@1: result = a.isMine Nenue@1: else Nenue@1: if (not b.missionEndTime) or (not a.missionEndTime) then Nenue@1: print('missing article', b.missionEndTime, a.missionEndTime) Nenue@1: end Nenue@1: Nenue@1: result = ( b.missionEndTime > a.missionEndTime) Nenue@1: end Nenue@1: end Nenue@1: Nenue@1: print('cmp', (b and (b.missionEndTime .. ' ' .. tostring(b.isMine)) or '-'), '>', (a and (a.missionEndTime .. ' ' .. tostring(a.isMine)) or '-'), result, n) Nenue@1: return result Nenue@1: end) Nenue@1: self.isStale = nil Nenue@1: Nenue@1: local lastProfile Nenue@1: local numItems = #self.sortedMissions Nenue@1: for i, data in ipairs(self.sortedMissions) do Nenue@1: local block = self.blocks[i] Nenue@1: if not block then Nenue@1: block = CreateFrame('Frame', nil, self, 'ClassPlanBlock') Nenue@1: block:SetID(i) Nenue@1: self.numBlocks = (self.numBlocks or 0) + 1 Nenue@1: Nenue@1: if self.lastBlock then Nenue@1: block:SetPoint('TOPLEFT', self.lastBlock, 'BOTTOMLEFT', 0, 0) Nenue@1: else Nenue@1: block:SetPoint('TOPLEFT', self.portrait, 'TOPRIGHT', 0, 0) Nenue@1: end Nenue@1: self.lastBlock = block Nenue@1: self.blocks[i] = block Nenue@1: end Nenue@1: Nenue@1: local r,g,b = 1, 1, 1 Nenue@1: if data.isRare then Nenue@1: r,g,b = 0.1, 0.4, 1 Nenue@1: end Nenue@1: if data.isMine then Nenue@1: block.Icon:SetVertexColor(0,1,0,1) Nenue@1: else Nenue@1: block.Icon:SetVertexColor(1,1,1) Nenue@1: end Nenue@1: Nenue@1: Nenue@1: --block.missionData = data Nenue@1: block.missionID = data.missionID Nenue@1: block.missionEndTime = data.missionEndTime Nenue@1: block.Icon:SetAtlas(data.typeAtlas, false) Nenue@1: block.Label:SetText(data.name) Nenue@1: block.Label:SetTextColor(r, g, b) Nenue@1: Nenue@1: if lastProfile ~= data.profileKey then Nenue@1: block.Owner:SetText(data.profileKey) Nenue@1: block.Owner:SetTextColor(data.classColor.r, data.classColor.g, data.classColor.b) Nenue@1: else Nenue@1: block.Owner:SetText(nil) Nenue@1: end Nenue@1: block.Background:SetColorTexture(data.classColor.r, data.classColor.g, data.classColor.b, 0.5) Nenue@1: Nenue@1: block:Show() Nenue@1: lastProfile = data.profileKey Nenue@1: end Nenue@1: for i = numItems + 1, self.numBlocks do Nenue@1: if self.blocks[i] then Nenue@1: self.blocks[i]:Hide() Nenue@1: end Nenue@1: end Nenue@1: end Nenue@1: Nenue@1: function core:OnShow() Nenue@1: if self.isStale then Nenue@1: print('updating items on show') Nenue@1: self:UpdateList() Nenue@1: end Nenue@1: end Nenue@1: Nenue@1: function core:Refresh () Nenue@1: if not self.profile then Nenue@1: return Nenue@1: end Nenue@1: Nenue@1: self.items = C_Garrison.GetLandingPageItems(LE_GARRISON_TYPE_7_0) Nenue@1: Nenue@1: self.profile.missions = self.profile.missions or {} Nenue@1: Nenue@1: self.profile.classColor = RAID_CLASS_COLORS[select(2, UnitClass('player'))] Nenue@1: Nenue@1: Nenue@1: print('|cFF0088FFLocal Scoop|r:', self.profileKey) Nenue@1: if #self.items >= 1 then Nenue@1: table.wipe(self.profile.missions) Nenue@1: for index, data in ipairs(self.items) do Nenue@1: print('', data.name) Nenue@1: print(' |cFF00FF00', data.timeLeft .. '|r', date("%A %I:%m %p", data.missionEndTime)) Nenue@1: tinsert(self.profile.missions, data) Nenue@1: end Nenue@1: end Nenue@1: Nenue@1: if self:IsVisible() then Nenue@1: self:UpdateList() Nenue@1: else Nenue@1: print('items update pending') Nenue@1: self.isStale = true Nenue@1: end Nenue@1: end Nenue@1: Nenue@1: function block:OnUpdate() Nenue@1: if self.missionEndTime then Nenue@1: local timeLeft = self.missionEndTime - time() Nenue@1: if timeLeft < 0 then Nenue@1: self.TimeLeft:SetText('Complete!') Nenue@1: else Nenue@1: local days = floor(timeLeft/(24*3600)) Nenue@1: local hours = floor(mod(timeLeft, (24*3600)) / 3600) Nenue@1: local minutes = floor(mod(timeLeft, 3600) / 60) Nenue@1: local seconds = mod(timeLeft, 60) Nenue@1: self.TimeLeft:SetText( Nenue@1: ((days > 0) and (days .. ' d') or '') .. Nenue@1: ((hours > 0) and (' '.. hours .. ' hr') or '').. Nenue@1: ((minutes > 0) and (' ' .. minutes .. ' min' or '')) Nenue@1: , 1,1,1) Nenue@1: end Nenue@1: else Nenue@1: self.TimeLeft:SetText(self.missionEndTime) Nenue@1: end Nenue@1: end