Nenue@4: local wipe, tinsert, sort = table.wipe, tinsert, table.sort Nenue@2: local pairs, ipairs = pairs, ipairs Nenue@4: local floor, mod, time = floor, mod, time Nenue@2: local GetTime = GetTime Nenue@3: local GI_currentTime = time() Nenue@3: Nenue@4: local BOUND_FRAMES = {} Nenue@2: local blockTemplate = { Nenue@2: point = 'TOPLEFT', Nenue@2: relativePoint ='TOPLEFT', Nenue@2: } Nenue@2: Nenue@1: SLASH_CLASSPLAN1 = "/classplan" Nenue@1: SLASH_CLASSPLAN2 = "/cp" Nenue@1: SlashCmdList.CLASSPLAN = function(args) Nenue@3: ClassOrderPlan:Toggle() Nenue@3: end Nenue@3: Nenue@3: ClassOrderPlanCore = { Nenue@3: events = {}, Nenue@3: freeBlocks = {}, Nenue@3: blocks = {}, Nenue@3: sortedItems = {}, Nenue@3: timers = {}, Nenue@3: shipments = {}, Nenue@3: playerFirst = false, Nenue@3: prototypes = {} Nenue@3: } Nenue@3: ClassPlanBlockMixin = { Nenue@3: templateName = 'ClassPlanBlock', Nenue@4: events = {'GARRISON_MISSION_LIST_UPDATE', 'GARRISON_MISSION_STARTED', 'GARRISON_MISSION_FINISHED'},} Nenue@3: ClassPlanShipmentMixin = { Nenue@3: templateName = 'ClassPlanShipment', Nenue@3: parent = false, Nenue@3: point = 'TOPRIGHT', Nenue@3: relativePoint ='TOPRIGHT', Nenue@4: events = {'GARRISON_LANDINGPAGE_SHIPMENTS', 'GARRISON_TALENT_UPDATE', "GARRISON_TALENT_COMPLETE", "GARRISON_SHIPMENT_RECEIVED"}, Nenue@3: } Nenue@3: setmetatable(ClassPlanShipmentMixin, {__index = ClassPlanBlockMixin}) Nenue@3: local core, MissionsHandler, ShipmentsHandler = ClassOrderPlanCore, ClassPlanBlockMixin, ClassPlanShipmentMixin Nenue@3: local print = DEVIAN_WORKSPACE and function(...) print('ClassPlan', ...) end or nop Nenue@3: Nenue@4: local GetTimeLeftString = function(timeLeft) Nenue@4: local days = floor(timeLeft/(24*3600)) Nenue@4: local hours = floor(mod(timeLeft, (24*3600)) / 3600) Nenue@4: local minutes = floor(mod(timeLeft, 3600) / 60) Nenue@4: local seconds = mod(timeLeft, 60) Nenue@4: if days >= 1 then Nenue@4: return (days .. 'd' .. ' ') .. ((hours > 0) and (hours .. 'h ') or '') Nenue@4: else Nenue@4: return ((hours > 0) and (hours .. 'h ') or '') .. ((minutes > 0) and (minutes .. ' min') or '') Nenue@4: end Nenue@4: end Nenue@3: Nenue@3: MissionsHandler.GetPlayerData = function(self) Nenue@3: if not self.profile then Nenue@3: return Nenue@3: end Nenue@3: self.items = C_Garrison.GetLandingPageItems(LE_GARRISON_TYPE_7_0) Nenue@3: Nenue@4: wipe(self.profile.missions) Nenue@4: for index, data in ipairs(self.items) do Nenue@4: print(' ',data.name, '|cFF00FF00'.. data.timeLeft .. '|r', date("%A %I:%m %p", data.missionEndTime)) Nenue@4: tinsert(self.profile.missions, data) Nenue@3: end Nenue@4: print('items update pending') Nenue@4: self.isStale = true Nenue@3: Nenue@3: if self:IsVisible() then Nenue@3: self:Refresh() Nenue@1: end Nenue@1: end Nenue@1: Nenue@4: MissionsHandler.FreeBlock = function(self, block) Nenue@4: end Nenue@4: Nenue@3: MissionsHandler.SortHandler = function (a,b) Nenue@3: local result = false Nenue@4: --if not a or not b then Nenue@4: -- return true Nenue@4: --else Nenue@4: --if (a.isMine ~= b.isMine) then Nenue@4: -- result = a.isMine Nenue@4: --else Nenue@4: --if (not b.missionEndTime) or (not a.missionEndTime) then Nenue@4: -- print('missing article', b.missionEndTime, a.missionEndTime) Nenue@4: --end Nenue@4: return ( b.missionEndTime > a.missionEndTime) Nenue@4: --end Nenue@4: --end Nenue@1: end Nenue@1: Nenue@2: Nenue@3: ShipmentsHandler.OnGetItem = function(data) Nenue@3: if data.shipmentsTotal then Nenue@3: local timeLeft = data.creationTime + data.duration - GI_currentTime Nenue@3: if (timeLeft <= 0) and (data.shipmentsReady < data.shipmentsTotal) then Nenue@3: local numOrders = -1*floor(timeLeft/data.duration) Nenue@2: Nenue@3: data.originalCreationTime = data.creationTime Nenue@3: data.originalShipmentsReady = data.shipmentsReady Nenue@2: Nenue@3: data.creationTime = data.creationTime + numOrders*data.duration Nenue@3: data.shipmentsReady = data.shipmentsReady + numOrders Nenue@3: print(data.profileKey, 'shipment "'.. data.name..'" reconciling', numOrders, 'lapsed orders. -->', data.creationTime, data.shipmentsReady) Nenue@2: end Nenue@2: end Nenue@2: end Nenue@2: Nenue@3: ShipmentsHandler.SortHandler = function(a, b) Nenue@3: if b.isComplete ~= a.isComplete then Nenue@3: return a.isComplete and true or false Nenue@4: elseif a.shipmentsReady or b.shipmentsReady then Nenue@4: return (a.shipmentsReady or 0) > (b.shipmentsReady or 0) Nenue@4: else Nenue@4: return (a.creationTime) < (b.creationTime) Nenue@2: end Nenue@2: end Nenue@2: Nenue@4: local AddShipmentInfo = function(self, shipmentType, name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, itemName, itemIcon, itemQuality, itemID, followerID) Nenue@4: -- early login queries may return empty tables, causing the sorter to compare nil Nenue@4: if not creationTime then Nenue@4: return Nenue@4: end Nenue@4: print(shipmentType, name, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString) Nenue@4: tinsert(self.shipments, Nenue@4: { Nenue@4: shipmentType = shipmentType, Nenue@4: name = name, Nenue@4: icon = texture, Nenue@4: shipmentCapacity = shipmentCapacity, Nenue@4: shipmentsReady = shipmentsReady, Nenue@4: shipmentsTotal = shipmentsTotal, Nenue@4: creationTime = creationTime, Nenue@4: duration = duration, Nenue@4: timeleftString = timeleftString, Nenue@4: itemName = itemName, Nenue@4: itemIcon = itemIcon, Nenue@4: itemQuality = itemQuality, Nenue@4: itemID = itemID, Nenue@4: followerID = followerID, Nenue@4: }) Nenue@4: end Nenue@3: ShipmentsHandler.GetPlayerData = function (self) Nenue@2: if not self.profile then Nenue@2: return Nenue@2: end Nenue@2: wipe(self.shipments) Nenue@2: Nenue@2: Nenue@2: local garrisonType = LE_GARRISON_TYPE_7_0 Nenue@2: local buildings = C_Garrison.GetBuildings(garrisonType); Nenue@2: local shipmentIndex = 0 Nenue@3: --print('Buildings:') Nenue@2: for i = 1, #buildings do Nenue@2: local name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, itemName, itemIcon, itemQuality, itemID = C_Garrison.GetLandingPageShipmentInfo(buildingID); Nenue@4: AddShipmentInfo(self, 'Building', name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, itemName, itemIcon, itemQuality, itemID) Nenue@2: end Nenue@2: Nenue@3: --print('Follower:') Nenue@2: local followerShipments = C_Garrison.GetFollowerShipments(garrisonType); Nenue@2: for i = 1, #followerShipments do Nenue@2: local name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, _, _, _, _, followerID = C_Garrison.GetLandingPageShipmentInfoByContainerID(followerShipments[i]); Nenue@4: AddShipmentInfo(self, 'Follower', name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, nil, nil, nil, nil, followerID) Nenue@2: end Nenue@2: Nenue@3: --print('Loose:') Nenue@2: local looseShipments = C_Garrison.GetLooseShipments(garrisonType) Nenue@2: for i = 1, #looseShipments do Nenue@2: local name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString = C_Garrison.GetLandingPageShipmentInfoByContainerID(looseShipments[i]); Nenue@4: AddShipmentInfo(self, 'Follower', name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString) Nenue@2: end Nenue@2: Nenue@2: local talentTrees = C_Garrison.GetTalentTrees(garrisonType, select(3, UnitClass("player"))); Nenue@2: -- this is a talent that has completed, but has not been seen in the talent UI yet. Nenue@2: local completeTalentID = C_Garrison.GetCompleteTalent(garrisonType); Nenue@3: --print('Talents:') Nenue@2: if (talentTrees) then Nenue@2: for treeIndex, tree in ipairs(talentTrees) do Nenue@2: for talentIndex, talent in ipairs(tree) do Nenue@2: local showTalent = false; Nenue@4: if (talent.isBeingResearched) or (talent.id == completeTalentID) then Nenue@4: AddShipmentInfo(self, 'Talent', talent.name, talent.icon, 1, (talent.isBeingResearched and 0 or 1), 1, talent.researchStartTime, talent.researchDuration, talent.timeleftString) Nenue@2: end Nenue@1: end Nenue@1: end Nenue@2: end Nenue@1: Nenue@2: self.profile.shipments = self.profile.shipments or {} Nenue@2: if #self.shipments >= 1 then Nenue@2: wipe(self.profile.shipments) Nenue@3: for index, data in ipairs(self.shipments) do Nenue@4: Nenue@4: --DEFAULT_CHAT_FRAME:AddMessage(data.shipmentType ..' '.. tostring(data.name) ..' '.. tostring(data.creationTime) ..' '.. tostring(data.duration)) Nenue@3: tinsert(self.profile.shipments, data) Nenue@1: end Nenue@2: self.isStale = true Nenue@2: end Nenue@1: Nenue@2: if self:IsVisible() then Nenue@2: self:Refresh() Nenue@1: end Nenue@1: end Nenue@1: Nenue@3: function core:OnLoad () Nenue@3: self:RegisterUnitEvent('UNIT_PORTRAIT_UPDATE', 'player') Nenue@3: self:RegisterEvent('PLAYER_LOGIN') Nenue@3: self:RegisterEvent('PLAYER_ENTERING_WORLD') Nenue@3: self:RegisterEvent('ADDON_LOADED') Nenue@3: self:RegisterEvent('PLAYER_REGEN_ENABLED') Nenue@4: -- Blizzard_GarrisonUI already fires a shipment data request for GARRISON_SHIPMENT_RECEIVED; this is unlikely to Nenue@4: Nenue@3: Nenue@3: self:AddHandler('missions', MissionsHandler) Nenue@3: self:AddHandler('shipments', ShipmentsHandler) Nenue@4: Nenue@4: Nenue@4: self:Reanchor() Nenue@4: end Nenue@4: local parentFrames = {'VeneerWorldState', 'OrderHallCommandBar'} Nenue@4: function core:Reanchor() Nenue@4: Nenue@4: Nenue@4: self:ClearAllPoints() Nenue@4: Nenue@4: self.anchorParent = UIParent Nenue@4: for i, name in ipairs(parentFrames) do Nenue@4: local frame = _G[name] Nenue@4: if frame then Nenue@4: if not BOUND_FRAMES[frame] then Nenue@4: BOUND_FRAMES[frame] = {visible = frame:IsVisible()} Nenue@4: hooksecurefunc(frame, 'Show', function() Nenue@4: BOUND_FRAMES[frame].visible = true Nenue@4: print(frame:GetName(), 'Show', 'reanchor trigger') Nenue@4: self:Reanchor() Nenue@4: end) Nenue@4: hooksecurefunc(frame, 'Hide', function() Nenue@4: BOUND_FRAMES[frame].visible = false Nenue@4: print(frame:GetName(), 'Hide', 'reanchor trigger') Nenue@4: self:Reanchor() Nenue@4: end) Nenue@4: end Nenue@4: print('f:', frame:GetName(), frame:IsVisible()) Nenue@4: if BOUND_FRAMES[frame].visible then Nenue@4: self.anchorParent = frame Nenue@4: break Nenue@4: end Nenue@4: end Nenue@4: end Nenue@4: print('|cFFFF8800Using ' .. tostring(self.anchorParent:GetName()) .. ' as anchor point') Nenue@4: Nenue@4: if self:IsVisible() then Nenue@4: self:SetPoint('TOP', ClassPlanButton, 'BOTTOM', 0, 0) Nenue@4: ClassPlanButton.Background:Show() Nenue@4: ClassPlanButton:SetWidth(600) Nenue@4: else Nenue@4: ClassPlanButton.Background:Hide() Nenue@4: ClassPlanButton:SetWidth(200) Nenue@4: end Nenue@4: Nenue@4: ClassPlanButton:SetPoint('TOP', self.anchorParent, (self.anchorPoint == UIParent) and 'TOP' or 'BOTTOM', 0, 0) Nenue@4: Nenue@3: end Nenue@3: Nenue@3: function core:AddHandler(name, prototype) Nenue@3: self.prototypes[name] = setmetatable(prototype, { Nenue@3: __index = blockTemplate, Nenue@3: __tostring = function() return name end Nenue@3: }) Nenue@3: Nenue@3: for i, event in ipairs(prototype.events) do Nenue@3: if not self.events[event] then Nenue@3: self:RegisterEvent(event) Nenue@3: self.events[event] = {} Nenue@3: print('|cFF00FF00registering', event) Nenue@3: end Nenue@3: Nenue@3: prototype.numBlocks = 0 Nenue@3: if not self.events[event][name] then Nenue@3: print('adding', name, 'to', event) Nenue@3: self.events[event][name] = prototype.GetPlayerData Nenue@3: end Nenue@1: end Nenue@3: self.sortedItems[name] = {} Nenue@3: end Nenue@1: Nenue@4: function core:Setup() Nenue@4: if IsLoggedIn() then Nenue@4: WorldPlanData.OrderHall = WorldPlanData.OrderHall or {} Nenue@4: self.data = WorldPlanData.OrderHall Nenue@4: self.data.characters = self.data.characters or {} Nenue@4: Nenue@4: local name, realm = UnitName('player') Nenue@4: realm = realm or GetRealmName() Nenue@4: self.profileKey = name .. '-' .. realm Nenue@4: if not self.data.characters[self.profileKey] then Nenue@4: self.data.characters[self.profileKey] = {} Nenue@4: end Nenue@4: self.profile = self.data.characters[self.profileKey] Nenue@4: Nenue@4: self.profile.shipments = self.profile.shipments or {} Nenue@4: self.profile.missions = self.profile.missions or {} Nenue@4: self.profile.classColor = RAID_CLASS_COLORS[select(2, UnitClass('player'))] Nenue@4: Nenue@4: if self.data.IsShown then Nenue@4: self:Show() Nenue@4: end Nenue@4: self.initialized = true Nenue@4: end Nenue@4: end Nenue@4: Nenue@3: function core:OnEvent (event, ...) Nenue@3: print(event) Nenue@3: if event == 'UNIT_PORTRAIT_UPDATE' then Nenue@3: SetPortraitTexture(self.portrait, 'player') Nenue@3: elseif event == 'PLAYER_LOGIN' then Nenue@3: if not self.initialized then Nenue@4: self:Setup() Nenue@1: end Nenue@4: elseif self.initialized and self.events[event] then Nenue@4: local numCalls = 0 Nenue@3: for ptype, eventFunc in pairs(self.events[event]) do Nenue@4: numCalls = numCalls + 1 Nenue@4: print('|cFF88FF00' .. tostring(ptype) .. '|r:GetPlayerData() --', numCalls) Nenue@3: eventFunc(self, event) Nenue@3: end Nenue@2: end Nenue@2: end Nenue@2: Nenue@3: function core:UpdateNotifications() Nenue@3: end Nenue@3: Nenue@4: Nenue@4: local SetOwnerData = function(self, data) Nenue@4: local name, realm = string.match(data.profileKey, "(.+)%-(.+)") Nenue@4: local ownerText = '|c'.. data.classColor.colorStr .. name .. '|r' Nenue@4: if realm ~= GI_currentRealm then Nenue@4: ownerText = ownerText .. ' (' .. realm .. ')' Nenue@4: end Nenue@4: self.Owner:SetText(ownerText) Nenue@4: self.Background:SetColorTexture(data.classColor.r, data.classColor.g, data.classColor.b) Nenue@4: end Nenue@4: Nenue@3: function core:RefreshItems(configKey, prototype) Nenue@3: local sortedItems = self.sortedItems[configKey] Nenue@3: Nenue@3: self.blocks[configKey] = self.blocks[configKey] or {} Nenue@3: local blocks = self.blocks[configKey] Nenue@3: Nenue@3: local lastProfile Nenue@3: local numItems = #sortedItems Nenue@3: local totalHeight = 0 Nenue@3: for i, data in ipairs(sortedItems) do Nenue@3: local block = blocks[i] Nenue@3: Nenue@3: if not block then Nenue@3: block = CreateFrame('Button', nil, self, prototype.templateName) Nenue@3: block:SetID(i) Nenue@4: block.handler = prototype Nenue@3: prototype.numBlocks = prototype.numBlocks + 1 Nenue@3: Nenue@3: if prototype.lastBlock then Nenue@3: block:SetPoint('TOPLEFT', prototype.lastBlock, 'BOTTOMLEFT', 0, 0) Nenue@3: else Nenue@3: block:SetPoint(prototype.point, self[prototype.parent] or self, prototype.relativePoint, 0, 0) Nenue@3: end Nenue@3: prototype.lastBlock = block Nenue@3: blocks[i] = block Nenue@3: end Nenue@3: Nenue@3: totalHeight = totalHeight + block:GetHeight() Nenue@3: block.lastProfile = lastProfile Nenue@4: for k,v in pairs(data) do Nenue@4: if type(block[k]) ~= 'function' then Nenue@4: block[k] = v Nenue@4: end Nenue@4: end Nenue@3: block:Refresh(data) Nenue@4: SetOwnerData(block, data) Nenue@4: Nenue@3: block:Show() Nenue@3: lastProfile = data.profileKey Nenue@3: end Nenue@3: Nenue@3: for i = numItems + 1, prototype.numBlocks do Nenue@3: if blocks[i] then Nenue@3: blocks[i]:Hide() Nenue@3: end Nenue@3: end Nenue@3: Nenue@3: return totalHeight Nenue@3: end Nenue@3: local max = math.max Nenue@3: function core:Refresh() Nenue@3: if self.isStale then Nenue@3: self:SortItems() Nenue@3: end Nenue@3: self.isStale = nil Nenue@3: Nenue@3: self.currentHeight = 0 Nenue@3: for name, info in pairs(self.prototypes) do Nenue@3: local itemsHeight = self:RefreshItems(name, info) Nenue@3: self.currentHeight = max(itemsHeight, self.currentHeight) Nenue@3: end Nenue@3: Nenue@4: self:Reanchor() Nenue@3: self:SetHeight(self.currentHeight) Nenue@3: end Nenue@3: Nenue@3: function core:Toggle() Nenue@3: if self:IsVisible() then Nenue@3: self:Hide() Nenue@3: else Nenue@3: self:Show() Nenue@3: end Nenue@3: Nenue@3: if self.data then Nenue@3: self.data.IsShown = self:IsVisible() Nenue@3: end Nenue@3: end Nenue@3: Nenue@3: function core:OnUpdate() Nenue@3: if self.fadeTimer and self.fadeTimer < GetTime() then Nenue@3: self:Hide() Nenue@3: end Nenue@3: end Nenue@3: Nenue@3: function core:OnShow() Nenue@3: if self.isStale then Nenue@3: print('updating items on show') Nenue@3: self:Refresh() Nenue@3: end Nenue@4: -- grab this at least once Nenue@4: C_Garrison.RequestLandingPageShipmentInfo(); Nenue@4: ClassPlanButton.Background:Show() Nenue@4: ClassPlanButton.Grip:SetShown(true) Nenue@3: end Nenue@3: function core:OnHide() Nenue@4: ClassPlanButton.Background:Hide() Nenue@4: ClassPlanButton.Grip:SetShown(false) Nenue@3: end Nenue@3: Nenue@3: local GI_profileKey, GI_profile, GI_isMine Nenue@4: local defaultClassColor = {r = 0.7, g = 0.7, b =0.7, colorStr = "ffffffff"} Nenue@4: local DoItemList = function (source, dest, onGetItem) Nenue@3: if not source then Nenue@3: return Nenue@3: end Nenue@3: local numItems = 0 Nenue@3: for index, data in ipairs(source) do Nenue@4: data.classColor = GI_profile.classColor or defaultClassColor Nenue@3: data.profileKey = GI_profileKey Nenue@3: data.isMine = GI_isMine Nenue@3: if onGetItem then Nenue@3: onGetItem(data) Nenue@3: end Nenue@3: numItems = numItems + 1 Nenue@3: tinsert(dest, data) Nenue@3: end Nenue@3: return numItems Nenue@3: end Nenue@3: Nenue@3: function core:SortItems() Nenue@3: print('|cFF0088FFSortItems()|r') Nenue@3: GI_currentTime = time() Nenue@3: Nenue@3: for key, sortedItems in pairs(self.sortedItems) do Nenue@3: wipe(sortedItems) Nenue@3: local ptype = self.prototypes[key] Nenue@4: --print( 'object:', ptype) Nenue@3: for name, profile in pairs(self.data.characters) do Nenue@3: GI_profileKey = name Nenue@3: GI_profile = profile Nenue@3: GI_isMine = (profile == self.profile) Nenue@4: local results = DoItemList(profile[key], sortedItems, ptype.OnGetItem) Nenue@4: --print(' - ', name, results, 'items') Nenue@3: end Nenue@3: Nenue@3: if ptype.SortHandler then Nenue@4: sort(sortedItems, ptype.SortHandler) Nenue@3: end Nenue@3: end Nenue@3: end Nenue@3: Nenue@3: function MissionsHandler:OnComplete() Nenue@4: self.isComplete = true Nenue@2: self:Refresh() Nenue@2: end Nenue@2: Nenue@3: function MissionsHandler:OnUpdate() Nenue@4: if self.isComplete then Nenue@2: return Nenue@2: end Nenue@2: Nenue@1: if self.missionEndTime then Nenue@1: local timeLeft = self.missionEndTime - time() Nenue@1: if timeLeft < 0 then Nenue@2: self:OnComplete() Nenue@1: else Nenue@2: self.TimeLeft:SetText(GetTimeLeftString(timeLeft)) Nenue@2: Nenue@2: if timeLeft > 3600 then Nenue@2: self.TimeLeft:SetTextColor(1,1,1) Nenue@2: else Nenue@2: self.TimeLeft:SetTextColor(1,1,0) Nenue@2: end Nenue@2: Nenue@1: end Nenue@1: else Nenue@1: self.TimeLeft:SetText(self.missionEndTime) Nenue@1: end Nenue@2: end Nenue@2: Nenue@4: function MissionsHandler:Refresh() Nenue@2: Nenue@3: Nenue@2: local r,g,b = 1, 1, 1 Nenue@4: if self.isRare then Nenue@2: r,g,b = 0.1, 0.4, 1 Nenue@2: end Nenue@2: Nenue@2: Nenue@2: --self.missionData = data Nenue@4: self.Label:SetText(self.name) Nenue@2: self.Label:SetTextColor(r, g, b) Nenue@2: Nenue@4: if #self.rewards >= 1 then Nenue@4: self.Icon:SetTexture(self.rewards[1].icon or GetItemIcon(self.rewards[1].itemID)) Nenue@4: self.rewardInfo = self.rewards[1] Nenue@2: else Nenue@4: self.Icon:SetAtlas(self.typeAtlas, false) Nenue@2: end Nenue@2: if self.isComplete then Nenue@2: self.TimeLeft:SetText('Complete!') Nenue@2: end Nenue@4: Nenue@4: self.Background:SetAlpha(self.isComplete and 1 or 0.1) Nenue@2: end Nenue@2: Nenue@2: Nenue@3: function MissionsHandler:OnEnter() Nenue@2: if self.rewardInfo and self.rewardInfo.itemID then Nenue@2: GameTooltip:SetOwner(self, 'ANCHOR_LEFT') Nenue@2: GameTooltip:SetItemByID(self.rewardInfo.itemID) Nenue@2: GameTooltip:Show() Nenue@2: end Nenue@2: end Nenue@3: function MissionsHandler:OnLeave() Nenue@2: if GameTooltip:IsOwned(self) then Nenue@2: GameTooltip:Hide() Nenue@2: end Nenue@2: end Nenue@2: Nenue@2: Nenue@2: Nenue@4: function ShipmentsHandler:Refresh() Nenue@3: Nenue@3: --[[ Nenue@3: self.icon = data.icon Nenue@3: self.shipmentCapacity = data.shipmentCapacity Nenue@3: self.shipmentsReady = data.shipmentsReady Nenue@3: self.shipmentsTotal = data.shipmentsTotal Nenue@3: self.creationTime = data.creationTime Nenue@3: self.duration = data.duration Nenue@3: self.itemID = data.itemID Nenue@3: self.itemQuality = data.itemQuality Nenue@3: icon = texture, Nenue@3: shipmentCapacity = shipmentCapacity, Nenue@3: shipmentsReady = shipmentsReady, Nenue@3: shipmentsTotal = shipmentsTotal, Nenue@3: creationTime = creationTime, Nenue@3: duration = duration, Nenue@3: timeleftString = timeleftString, Nenue@3: itemName = itemName, Nenue@3: itemIcon = itemIcon, Nenue@3: itemQuality = itemQuality, Nenue@3: itemID = itemID Nenue@3: Nenue@3: --]] Nenue@3: Nenue@4: self.Icon:SetTexture(self.icon) Nenue@2: Nenue@4: self.Name:SetText(self.name) Nenue@4: self.Count:SetText(self.shipmentsReady) Nenue@4: self.Done:SetShown(self.shipmentsReady and (self.shipmentsReady >= 1)) Nenue@2: Nenue@3: Nenue@3: -- flag as complete Nenue@4: if ( self.shipmentsReady == self.shipmentsTotal ) and (not self.isBeingResearched) then Nenue@2: self.Swipe:SetCooldownUNIX(0, 0); Nenue@2: self.Done:Show(); Nenue@4: self.isComplete = true Nenue@2: else Nenue@4: self.Swipe:SetCooldownUNIX(self.creationTime or 0 , self.duration or 0); Nenue@2: end Nenue@2: Nenue@4: local hasPickups = (self.isComplete or (self.shipmentsTotal and (self.shipmentsReady > 0))) Nenue@4: self.Background:SetAlpha(hasPickups and 1 or 0.1) Nenue@4: end Nenue@4: local time = time Nenue@4: function ShipmentsHandler:OnUpdate() Nenue@2: Nenue@4: if (self.shipmentsReady and self.shipmentsTotal) and (self.shipmentsReady ~= self.shipmentsTotal) then Nenue@4: local timeLeft = self.creationTime + self.duration - time() Nenue@4: self.TimeLeft:SetText('Next: '.. GetTimeLeftString(timeLeft) .. ' |cFFFFFF00'..self.shipmentsTotal..' orders|r') Nenue@4: elseif self.isStale then Nenue@3: self.TimeLeft:SetText('|cFFFF0000Needs refresh|r') Nenue@4: elseif self.isBeingResearched then Nenue@4: self.TimeLeft:SetText(GetTimeLeftString(self.researchStartTime + self.researchDuration - time())) Nenue@2: else Nenue@2: self.TimeLeft:SetText('Complete!') Nenue@2: end Nenue@2: Nenue@2: end Nenue@2: Nenue@3: function ShipmentsHandler:OnEnter() Nenue@4: Nenue@4: if ( self.shipmentsReady and self.shipmentsTotal ) then Nenue@2: GameTooltip:SetOwner(self, 'ANCHOR_LEFT') Nenue@4: Nenue@4: GameTooltip:AddLine(self.Owner:GetText(), self.Owner:GetTextColor()) Nenue@4: GameTooltip:AddLine(self.shipmentType) Nenue@4: GameTooltip:AddLine(self.shipmentsReady .. ' of '.. self.shipmentsTotal) Nenue@2: GameTooltip:Show() Nenue@2: end Nenue@2: end Nenue@2: Nenue@3: function ShipmentsHandler:OnLeave() Nenue@2: if GameTooltip:IsOwned(self) then Nenue@2: GameTooltip:Hide() Nenue@2: end Nenue@2: end Nenue@2: Nenue@3: function ShipmentsHandler:OnClick(button) Nenue@3: if button == 'RightButton' then Nenue@4: self.handler:FreeBlock(self) Nenue@3: end Nenue@1: end