190 lines
6.3 KiB
Lua
190 lines
6.3 KiB
Lua
local UIWidgetBase = require_ex('Common/Core/UIWidgetBase')
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
DomainDepotDeliveryCell = HL.Class('DomainDepotDeliveryCell', UIWidgetBase)
|
||
|
||
|
||
DomainDepotDeliveryCell.m_deliveryId = HL.Field(HL.String) << ""
|
||
|
||
|
||
DomainDepotDeliveryCell.m_roleId = HL.Field(HL.String) << ""
|
||
|
||
|
||
DomainDepotDeliveryCell.m_insId = HL.Field(HL.Number) << 0
|
||
|
||
|
||
DomainDepotDeliveryCell.m_canReceive = HL.Field(HL.Boolean) << false
|
||
|
||
|
||
DomainDepotDeliveryCell.m_deliveryOnClick = HL.Field(HL.Function)
|
||
|
||
|
||
DomainDepotDeliveryCell.m_domainDepotId = HL.Field(HL.String) << ""
|
||
|
||
|
||
|
||
|
||
|
||
DomainDepotDeliveryCell._OnFirstTimeInit = HL.Override() << function(self)
|
||
self.view.positionBtn.onClick:RemoveAllListeners()
|
||
self.view.positionBtn.onClick:AddListener(function()
|
||
DomainDepotUtils.ShowDepotTargetMapPreview(self.m_domainDepotId, self.m_deliveryId)
|
||
end)
|
||
|
||
self.view.taskNode.onClick:RemoveAllListeners()
|
||
self.view.taskNode.onClick:AddListener(function()
|
||
if 0 == GameInstance.player.domainDepotSystem.deliverInstId then
|
||
GameInstance.player.domainDepotSystem:SendDomainDepotDeliverAcceptMsg(self.m_insId)
|
||
elseif GameInstance.player.domainDepotSystem.deliverInstId == self.m_insId then
|
||
PhaseManager:OpenPhase(PhaseId.Mission, { autoSelect = Tables.domainDepotConst.depotDeliverMissionId })
|
||
else
|
||
Notify(MessageConst.SHOW_TOAST, Language.LUA_DOMAIN_DEPOT_DELIVERY_TASK_NOT_ACCEPTED)
|
||
end
|
||
end)
|
||
|
||
self.view.bgBtn.onClick:RemoveAllListeners()
|
||
self.view.bgBtn.onClick:AddListener(function()
|
||
if self.m_deliveryOnClick then
|
||
self.m_deliveryOnClick(self.m_insId)
|
||
end
|
||
GameInstance.player.domainDepotSystem:SendDomainDepotCollectDelegateRewardReq({ self.m_insId })
|
||
end)
|
||
|
||
end
|
||
|
||
|
||
|
||
|
||
DomainDepotDeliveryCell.InitDomainDepotDeliveryCell = HL.Method(HL.Userdata) << function(self, info)
|
||
self:_FirstTimeInit()
|
||
|
||
|
||
|
||
local timeStamp = info.delegateTimeStamp
|
||
local currentTime = DateTimeUtils.GetCurrentTimestampBySeconds()
|
||
local timeDiff = timeStamp - currentTime
|
||
|
||
self.m_insId = info.insId
|
||
self.m_domainDepotId = info.domainDepotId
|
||
if timeDiff <= 0 then
|
||
|
||
logger.error("InitRegionDeliveryCell: 送货已过期,deliveryId: " .. self.m_insId)
|
||
else
|
||
|
||
local daysLeft = math.ceil(timeDiff / (60 * 60 * 24))
|
||
self.view.timeTxt.text = string.format(Language.LUA_DOMAIN_DEPOT_DELIVERY_TIME_LEFT, daysLeft)
|
||
end
|
||
|
||
self.view.stateController:SetState(GameInstance.player.domainDepotSystem.deliverInstId == info.insId and "accepted" or "canAccept")
|
||
self.view.accessNode:SetState(GameInstance.player.domainDepotSystem.deliverInstId == info.insId and "recommend" or "Normal")
|
||
|
||
self:_UpdateInfo(info)
|
||
end
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
DomainDepotDeliveryCell.InitSelfDomainDepotDeliveryCell = HL.Method(HL.Userdata, HL.Function) << function(self, info, onClick)
|
||
self:_FirstTimeInit()
|
||
|
||
self.m_deliveryOnClick = onClick
|
||
self.m_canReceive = false
|
||
|
||
|
||
local timeStamp = info.delegateTimeStamp
|
||
local currentTime = DateTimeUtils.GetCurrentTimestampBySeconds()
|
||
local timeDiff = timeStamp - currentTime
|
||
|
||
self.m_insId = info.insId
|
||
self.m_domainDepotId = info.domainDepotId
|
||
|
||
local roleId = info.delegateRoleId
|
||
|
||
|
||
local daysLeft = UIUtils.getLeftTime(timeDiff)
|
||
self.view.expiredTxt.text = string.format(Language.LUA_DOMAIN_DEPOT_DELIVERY_NOT_COMPLETED_TIME_LEFT, daysLeft)
|
||
|
||
local showPlayerName = roleId ~= 0
|
||
|
||
if timeDiff <= 0 or info.packageProgress == GEnums.DomainDepotPackageProgress.SendPackageTimeout then
|
||
self.m_canReceive = true
|
||
self.view.stateController:SetState("expired")
|
||
elseif info.packageProgress == GEnums.DomainDepotPackageProgress.WaitingRecvFinalPayment then
|
||
self.m_canReceive = true
|
||
self.view.stateController:SetState("completed")
|
||
self.view.expiredTxt.text = string.format(Language.LUA_DOMAIN_DEPOT_DELIVERY_COMPLETED_TIME_LEFT, daysLeft)
|
||
elseif roleId == 0 then
|
||
self.view.stateController:SetState("waiting")
|
||
elseif info.packageProgress == GEnums.DomainDepotPackageProgress.WaitingSendPackage or info.packageProgress == GEnums.DomainDepotPackageProgress.WaitingRecvPackage then
|
||
self.view.stateController:SetState("delivering")
|
||
else
|
||
logger.error("InitRegionSelfDeliveryCell: 未知的包裹进度 " .. info.packageProgress:ToString())
|
||
end
|
||
self.view.redDot.gameObject:SetActive(self.m_canReceive)
|
||
self:_UpdateInfo(info)
|
||
self.view.commonPlayerHead.view.nameText.gameObject:SetActiveIfNecessary(showPlayerName)
|
||
self.view.blankText.gameObject:SetActiveIfNecessary(not showPlayerName and self.view.blankText.gameObject.activeSelf)
|
||
end
|
||
|
||
|
||
|
||
|
||
DomainDepotDeliveryCell._UpdateInfo = HL.Method(HL.Userdata) << function(self, info)
|
||
self.m_deliveryId = info.buyerInfo.targetId
|
||
local roleId = info.delegateRoleId
|
||
self.view.commonPlayerHead:UpdateHideSignature(true)
|
||
self.view.commonPlayerHead:InitCommonPlayerHeadByRoleId(roleId, true)
|
||
|
||
|
||
|
||
|
||
local packConfig = Tables.domainDepotDeliverPackTypeTable:GetValue(info.deliverPackType)
|
||
local itemConfig = Tables.domainDepotDeliverItemTypeTable:GetValue(info.itemType)
|
||
|
||
local str = I18nUtils.CombineStringWithLanguageSpilt(packConfig.deliveryDesc, itemConfig.deliveryDesc)
|
||
|
||
self.view.largeBagTxt.text = str
|
||
|
||
self.view.cargoType:SetState(info.itemType:ToString())
|
||
|
||
|
||
local deliverCfg = Tables.domainDepotDeliverTargetTable:GetValue(info.buyerInfo.targetId)
|
||
local levelDesc = Tables.levelDescTable:GetValue(deliverCfg.level)
|
||
local domainData = Tables.domainDataTable:GetValue(deliverCfg.domainId)
|
||
|
||
self.view.positionTxt.text = string.format(Language.LUA_DOMAIN_DEPOT_TARGET_SPACE, levelDesc.showName)
|
||
|
||
local timeStamp = info.delegateTimeStamp
|
||
local currentTime = DateTimeUtils.GetCurrentTimestampBySeconds()
|
||
local timeDiff = timeStamp - currentTime
|
||
|
||
local count = info.buyerInfo.rewardValue * (1 - Tables.domainDepotConst.depositRatio / 100) * (timeDiff < 0 and (Tables.domainDepotConst.expireFinalPaymentRatio / 100) or 1)
|
||
count = math.floor(count)
|
||
|
||
|
||
self.view.itemSmallBlack:InitItem({
|
||
id = domainData.domainGoldItemId,
|
||
count = count,
|
||
}, true)
|
||
|
||
self.view.bgBtn.interactable = self.m_canReceive
|
||
end
|
||
|
||
HL.Commit(DomainDepotDeliveryCell)
|
||
return DomainDepotDeliveryCell
|
||
|