477 lines
15 KiB
Lua
477 lines
15 KiB
Lua
|
|
local uiCtrl = require_ex('UI/Panels/Base/UICtrl')
|
|
local PANEL_ID = PanelId.SpaceshipControlCenter
|
|
local PHASE_ID = PhaseId.SpaceshipControlCenter
|
|
|
|
local HelpedStateByRoomType = {
|
|
[GEnums.SpaceshipRoomType.ControlCenter] = "MoodRecovery",
|
|
[GEnums.SpaceshipRoomType.ManufacturingStation] = "FastMade",
|
|
[GEnums.SpaceshipRoomType.GrowCabin] = "ExtraProducts",
|
|
[GEnums.SpaceshipRoomType.CommandCenter] = "FastAction",
|
|
[GEnums.SpaceshipRoomType.GuestRoom] = "ExtraRewards",
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SpaceshipControlCenterCtrl = HL.Class('SpaceshipControlCenterCtrl', uiCtrl.UICtrl)
|
|
|
|
|
|
SpaceshipControlCenterCtrl.m_roomCells = HL.Field(HL.Forward('UIListCache'))
|
|
|
|
|
|
SpaceshipControlCenterCtrl.m_roomIndexTab = HL.Field(HL.Table)
|
|
|
|
|
|
SpaceshipControlCenterCtrl.m_nowNaviRoomCell = HL.Field(HL.Table)
|
|
|
|
|
|
SpaceshipControlCenterCtrl.m_visitorHelpBindingId = HL.Field(HL.Number) << -1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SpaceshipControlCenterCtrl.s_messages = HL.StaticField(HL.Table) << {
|
|
[MessageConst.SPACESHIP_ON_SYNC_ROOM_STATION] = 'OnSyncRoomStation',
|
|
[MessageConst.SPACESHIP_ON_ROOM_LEVEL_UP] = '_RefreshRooms',
|
|
[MessageConst.ON_SPACESHIP_HELP_ROOM] = 'OnSSHelpRoom',
|
|
[MessageConst.ON_SPACESHIP_USE_HELP_CREDIT] = 'OnUseHelpCredit',
|
|
[MessageConst.ON_SPACESHIP_GROW_CABIN_HARVEST] = "OnSpaceshipGrowCabinHelped",
|
|
[MessageConst.ON_SPACESHIP_ASSIST_DATA_MODIFY] = "OnRefreshData",
|
|
}
|
|
|
|
|
|
SpaceshipControlCenterCtrl.OpenControlCenter = HL.StaticMethod() << function()
|
|
PhaseManager:OpenPhase(PhaseId.SpaceshipControlCenter)
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
SpaceshipControlCenterCtrl.OnCreate = HL.Override(HL.Any) << function(self, arg)
|
|
self.view.closeBtn.onClick:AddListener(function()
|
|
PhaseManager:PopPhase(PhaseId.SpaceshipControlCenter)
|
|
end)
|
|
self:BindInputPlayerAction("ss_open_control_center", function()
|
|
PhaseManager:PopPhase(PhaseId.SpaceshipControlCenter)
|
|
end)
|
|
|
|
self.view.reportBtn.onClick:AddListener(function()
|
|
PhaseManager:OpenPhase(PhaseId.SpaceshipDailyReport)
|
|
end)
|
|
if GameInstance.player.spaceship.isViewingFriend then
|
|
self.view.assistCtrlNode:SetState("Visitors")
|
|
self.view.moneyCell.view.gainNode.gameObject:SetActive(false)
|
|
self:_SetFriendState()
|
|
else
|
|
self.view.assistCtrlNode:SetState("Owner")
|
|
self:_SetSelfState()
|
|
end
|
|
self.m_roomCells = UIUtils.genCellCache(self.view.roomNode.roomCell)
|
|
self:_RefreshRooms()
|
|
self.view.redDotArrow:InitRedDot("SSControlCenterRoot", self.m_roomIndexTab)
|
|
self.view.controllerHintPlaceholder:InitControllerHintPlaceholder({self.view.inputGroup.groupId})
|
|
end
|
|
|
|
|
|
|
|
SpaceshipControlCenterCtrl.OnClose = HL.Override() << function(self)
|
|
|
|
end
|
|
|
|
|
|
|
|
SpaceshipControlCenterCtrl.OnShow = HL.Override() << function(self)
|
|
if not GameInstance.player.spaceship.isViewingFriend then
|
|
InputManagerInst.controllerNaviManager:SetTarget(self.view.control_center.ownerButton)
|
|
else
|
|
InputManagerInst.controllerNaviManager:SetTarget(self.view.control_center.visitorsNodeInputBindingGroupNaviDecorator)
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
SpaceshipControlCenterCtrl.OnRoomCellNaviTargetChange = HL.Method(HL.Opt(HL.Table, HL.Boolean))
|
|
<< function(self, cell, canHelp)
|
|
self.m_nowNaviRoomCell = cell
|
|
if self.m_visitorHelpBindingId ~= -1 then
|
|
InputManagerInst:ToggleBinding(self.m_visitorHelpBindingId, canHelp)
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
SpaceshipControlCenterCtrl._SetSelfState = HL.Method() << function(self)
|
|
if GameInstance.player.spaceship.isViewingFriend then
|
|
return
|
|
end
|
|
self.view.friendAssistNode:InitFriendAssistNode(Tables.spaceshipConst.controlCenterRoomId)
|
|
end
|
|
|
|
|
|
|
|
|
|
SpaceshipControlCenterCtrl._SetFriendState = HL.Method() << function(self)
|
|
if not GameInstance.player.spaceship.isViewingFriend then
|
|
return
|
|
end
|
|
local rewardItem = Tables.rewardTable[Tables.spaceshipConst.visitorHelpRewardId].itemBundles[CSIndex(1)]
|
|
local itemId = rewardItem.id
|
|
self.view.moneyCell:InitMoneyCell(itemId)
|
|
local friendInfo = GameInstance.player.spaceship:GetFriendRoleInfo()
|
|
if friendInfo then
|
|
self.view.playerNameNode:InitSocializeFriendName(friendInfo.roleId)
|
|
end
|
|
|
|
self.view.assistHintNode.swapMessNode.gameObject:SetActive(false)
|
|
self.view.assistHintNode.detailBtn.onClick:RemoveAllListeners()
|
|
self.view.assistHintNode.detailBtn.onClick:AddListener(function()
|
|
UIManager:Open(PanelId.InstructionBook, "control_center_help_rule")
|
|
end)
|
|
self:_SetTimeText()
|
|
self:_StartCoroutine(function()
|
|
while true do
|
|
coroutine.wait(UIConst.COMMON_UI_TIME_UPDATE_INTERVAL)
|
|
self:_SetTimeText()
|
|
end
|
|
end)
|
|
local isHelpDone = GameInstance.player.spaceship.helpOtherCount >= Tables.spaceshipConst.helpOthersCountLimit
|
|
self.view.assistHintNode.dayLimitNode:SetState(isHelpDone and "tomorrow" or "today")
|
|
self.view.assistHintNode.assistTimesTxt.text = string.format("%d/%d", GameInstance.player.spaceship.helpOtherRemainCount, Tables.spaceshipConst.helpOthersCountLimit)
|
|
self.m_visitorHelpBindingId = self:BindInputPlayerAction("ss_help_friend_room", function()
|
|
if self.m_nowNaviRoomCell then
|
|
AudioManager.PostEvent("Au_UI_Button_Produce")
|
|
self.m_nowNaviRoomCell.visitorsNode.helpBtn.onClick:Invoke()
|
|
end
|
|
end)
|
|
end
|
|
|
|
|
|
|
|
|
|
SpaceshipControlCenterCtrl.OnSSHelpRoom = HL.Method(HL.Opt(HL.Table)) << function(self, arg)
|
|
local roomId = arg and arg[1] or Tables.spaceshipConst.controlCenterRoomId
|
|
local success = arg and arg[2] or false
|
|
self:_RefreshGainNode(roomId, success)
|
|
self:_SetFriendState()
|
|
end
|
|
|
|
|
|
|
|
|
|
SpaceshipControlCenterCtrl.OnUseHelpCredit = HL.Method(HL.Opt(HL.Table)) << function(self, arg)
|
|
self:_SetSelfState()
|
|
end
|
|
|
|
|
|
|
|
SpaceshipControlCenterCtrl.OnRefreshData = HL.Method() << function(self)
|
|
self:_SetFriendState()
|
|
self:_RefreshRooms()
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
SpaceshipControlCenterCtrl._RefreshGainNode = HL.Method(HL.String, HL.Boolean) << function(self, roomId, success)
|
|
if success then
|
|
local gainNode = self.view.moneyCell.view.gainNode
|
|
gainNode.animationWrapper:ClearTween()
|
|
gainNode.gameObject:SetActive(true)
|
|
gainNode.animationWrapper:PlayWithTween("spaceshipcontrolcentergain_in", function()
|
|
gainNode.gameObject:SetActive(false)
|
|
end)
|
|
local rewardItem = Tables.rewardTable[Tables.spaceshipConst.visitorHelpRewardId].itemBundles[CSIndex(1)]
|
|
local itemCount = rewardItem.count
|
|
local itemId = rewardItem.id
|
|
gainNode.creditTxt.text = string.format("+%d", itemCount)
|
|
self.view.moneyCell:InitMoneyCell(itemId)
|
|
end
|
|
local rooms = GameInstance.player.spaceship:GetRoomsWithSort()
|
|
local itemIndex = 1
|
|
for i = CSIndex(1), CSIndex(rooms.Count) do
|
|
local info = rooms[i]
|
|
local roomId = rooms[i].id
|
|
if info.type == GEnums.SpaceshipRoomType.GuestRoom then
|
|
goto continue
|
|
end
|
|
if info.type ~= GEnums.SpaceshipRoomType.ControlCenter then
|
|
self:_RefreshRoomGainNode(self.m_roomCells:GetItem(itemIndex) , roomId, true)
|
|
itemIndex = itemIndex + 1
|
|
else
|
|
self:_RefreshRoomGainNode(self.view[roomId] , roomId, true)
|
|
end
|
|
::continue::
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SpaceshipControlCenterCtrl._RefreshRoomGainNode = HL.Method(HL.Table, HL.String, HL.Opt(HL.Boolean)) << function(self, cell, roomId, refreshNode)
|
|
cell.visitorsNode.gainNode.gameObject:SetActive(true)
|
|
local rewardItem = Tables.rewardTable[Tables.spaceshipConst.visitorHelpRewardId].itemBundles[CSIndex(1)]
|
|
local itemCount = rewardItem.count
|
|
cell.visitorsNode.creditTxt.text = string.format("+%d", itemCount)
|
|
if refreshNode then
|
|
self:_RefreshVisitorNode(cell, roomId)
|
|
end
|
|
end
|
|
|
|
|
|
|
|
SpaceshipControlCenterCtrl._SetTimeText = HL.Method() << function(self)
|
|
local targetTime = Utils.getNextCommonServerRefreshTime()
|
|
local curTime = DateTimeUtils.GetCurrentTimestampBySeconds()
|
|
local leftSec = targetTime - curTime
|
|
self.view.assistHintNode.refreshTimesTxt.text = UIUtils.getLeftTimeToSecond(leftSec)
|
|
end
|
|
|
|
|
|
|
|
SpaceshipControlCenterCtrl.OnSyncRoomStation = HL.Method() << function(self)
|
|
self:_RefreshRooms()
|
|
end
|
|
|
|
|
|
|
|
|
|
SpaceshipControlCenterCtrl._RefreshRooms = HL.Method(HL.Opt(HL.Any)) << function(self, _)
|
|
local roomCount = GameInstance.player.spaceship.rooms.Count - 1
|
|
local hasValue, _ = GameInstance.player.spaceship:TryGetRoom(Tables.spaceshipConst.guestRoomId)
|
|
if hasValue then
|
|
roomCount = roomCount - 1
|
|
end
|
|
self.m_roomCells:Refresh(roomCount)
|
|
local itemIndex = 1
|
|
self.m_roomIndexTab = {}
|
|
|
|
local rooms = GameInstance.player.spaceship:GetRoomsWithSort()
|
|
for i = CSIndex(1), CSIndex(rooms.Count) do
|
|
local info = rooms[i]
|
|
local roomId = rooms[i].id
|
|
if info.type == GEnums.SpaceshipRoomType.GuestRoom then
|
|
goto continue
|
|
end
|
|
if info.type ~= GEnums.SpaceshipRoomType.ControlCenter then
|
|
self:_UpdateRoomCell(self.m_roomCells:GetItem(itemIndex) , roomId)
|
|
self.m_roomIndexTab[roomId] = itemIndex
|
|
itemIndex = itemIndex + 1
|
|
else
|
|
self:_UpdateRoomCell(self.view[roomId] , roomId)
|
|
end
|
|
::continue::
|
|
end
|
|
local succ, roomInfo = GameInstance.player.spaceship:TryGetRoom(Tables.spaceshipConst.controlCenterRoomId)
|
|
self.view.roomEffectInfoNode:InitSSRoomEffectInfoNode({
|
|
attrsMap = roomInfo.attrsMap,
|
|
color = SpaceshipUtils.getRoomColor(roomInfo.id),
|
|
})
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SpaceshipControlCenterCtrl._UpdateRoomCell = HL.Method(HL.Table, HL.String) << function(self, cell, roomId)
|
|
local succ, roomInfo = GameInstance.player.spaceship:TryGetRoom(roomId)
|
|
if not succ then
|
|
return
|
|
end
|
|
local roomTypeData = Tables.spaceshipRoomTypeTable[roomInfo.type]
|
|
cell.ownerButton.enabled = true
|
|
cell.ownerButton.onClick:RemoveAllListeners()
|
|
cell.ownerButton.onClick:AddListener(function()
|
|
if roomInfo.type == GEnums.SpaceshipRoomType.ControlCenter then
|
|
PhaseManager:OpenPhase(PhaseId.SpaceshipStation, { roomId = roomId })
|
|
else
|
|
local phaseId = PhaseId[SpaceshipConst.ROOM_PHASE_ID_NAME_MAP_BY_TYPE[roomInfo.type]]
|
|
PhaseManager:OpenPhase(phaseId, { roomId = roomId, moveCam = false, })
|
|
end
|
|
end)
|
|
|
|
local node = cell.contentNode
|
|
node.icon:LoadSprite(UIConst.UI_SPRITE_SPACESHIP_ROOM, roomTypeData.icon)
|
|
node.iconColorBG.color = UIUtils.getColorByString(roomTypeData.color)
|
|
node.nameTxt.text = SpaceshipUtils.getFormatCabinSerialNum(roomId, roomInfo.serialNum)
|
|
node.lvDotNode:InitLvDotNode(roomInfo.lv, roomInfo.maxLv, node.iconColorBG.color)
|
|
self:_UpdateRoomCellStation(cell, roomInfo)
|
|
cell.simpleStateController:SetState("Normal")
|
|
cell.visitorsNode.helpBtn.onClick:RemoveAllListeners()
|
|
cell.visitorsNode.helpBtn.onClick:AddListener(function()
|
|
GameInstance.player.spaceship:SpaceshipHelpRoom(roomId)
|
|
end)
|
|
|
|
if GameInstance.player.spaceship.isViewingFriend then
|
|
cell.redDot.gameObject:SetActive(false)
|
|
else
|
|
if roomInfo.type == GEnums.SpaceshipRoomType.GrowCabin then
|
|
cell.redDot:InitRedDot("SSGrowCabin", roomId)
|
|
|
|
elseif roomInfo.type == GEnums.SpaceshipRoomType.ManufacturingStation then
|
|
cell.redDot:InitRedDot("SSManufacturingStation", roomId)
|
|
else
|
|
cell.redDot.gameObject:SetActive(false)
|
|
end
|
|
end
|
|
self:_RefreshVisitorNode(cell, roomId)
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
SpaceshipControlCenterCtrl._RefreshVisitorNode = HL.Method(HL.Table, HL.String) << function(self, cell, roomId)
|
|
if not GameInstance.player.spaceship.isViewingFriend then
|
|
return
|
|
end
|
|
local succ, roomInfo = GameInstance.player.spaceship:TryGetRoom(roomId)
|
|
if not succ then
|
|
return
|
|
end
|
|
|
|
local friendInfo = GameInstance.player.spaceship:GetFriendRoleInfo()
|
|
local isHelped = GameInstance.player.spaceship:CheckIsHelpOther(friendInfo.roleId, roomId)
|
|
local unableHelp = GameInstance.player.spaceship:CheckUnableHelpByRoomId(roomId)
|
|
if isHelped then
|
|
cell.visitorsNode.visitorsNode:SetState(HelpedStateByRoomType[roomInfo.type])
|
|
self:_RefreshRoomGainNode(cell, roomId)
|
|
elseif unableHelp then
|
|
cell.visitorsNode.visitorsNode:SetState("DisableAssist")
|
|
else
|
|
cell.visitorsNode.visitorsNode:SetState("AssistHelp")
|
|
end
|
|
local canHelp = not isHelped and not unableHelp
|
|
if self.m_visitorHelpBindingId ~= -1 then
|
|
InputManagerInst:ToggleBinding(self.m_visitorHelpBindingId, canHelp)
|
|
end
|
|
cell.visitorsNodeInputBindingGroupNaviDecorator.onIsNaviTargetChanged = function(isTarget)
|
|
if isTarget then
|
|
self:OnRoomCellNaviTargetChange(cell, canHelp)
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
SpaceshipControlCenterCtrl.OnSpaceshipGrowCabinHelped = HL.Method(HL.Any) << function(self, args)
|
|
if not GameInstance.player.spaceship.isViewingFriend then
|
|
return
|
|
end
|
|
local title = Language.LUA_SPACESHIP_ROOM_GROW_CABIN_HELP_OUTCOME_POPUP_TITLE
|
|
local items = unpack(args)
|
|
self:_ShowOutcomePopup(title, items)
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SpaceshipControlCenterCtrl._ShowOutcomePopup = HL.Method(HL.String, HL.Any) << function(self, title, csItems)
|
|
local itemMap = {}
|
|
for i = 0, csItems.Count - 1 do
|
|
local item = csItems[i]
|
|
|
|
if item.id == Tables.spaceshipConst.creditItemId then
|
|
goto continue
|
|
end
|
|
|
|
if itemMap[item.id or item.Id] then
|
|
local accCount = itemMap[item.id or item.Id]
|
|
itemMap[item.id or item.Id] = accCount + item.Count or 0 + item.count or 0
|
|
else
|
|
itemMap[item.id or item.Id] = item.Count or 0 + item.count or 0
|
|
end
|
|
::continue::
|
|
end
|
|
|
|
local items = {}
|
|
|
|
for id, count in pairs(itemMap) do
|
|
local needShowHelp = Tables.spaceshipGrowCabinOutCome2MaterialTable:ContainsKey(id)
|
|
table.insert(items, {
|
|
id = id,
|
|
count = count,
|
|
needShowHelp = needShowHelp,
|
|
})
|
|
end
|
|
if #items == 0 then
|
|
return
|
|
end
|
|
Notify(MessageConst.SHOW_SYSTEM_REWARDS, {
|
|
title = title,
|
|
items = items,
|
|
})
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SpaceshipControlCenterCtrl._UpdateRoomCellStation = HL.Method(HL.Table, CS.Beyond.Gameplay.SpaceshipSystem.Room) << function(self, cell, roomInfo)
|
|
local node = cell.contentNode
|
|
if not node.m_charCells then
|
|
node.m_charCells = UIUtils.genCellCache(node.charCell)
|
|
end
|
|
|
|
local maxCount = roomInfo.maxLvStationCount
|
|
local curMaxCount = roomInfo.maxStationCharNum
|
|
local curCount = roomInfo.stationedCharList.Count
|
|
node.m_charCells:Refresh(maxCount, function(charCell, index)
|
|
if index <= curCount then
|
|
charCell.view.simpleStateController:SetState("Normal")
|
|
charCell:InitSSCharHeadCell({
|
|
charId = roomInfo.stationedCharList[CSIndex(index)],
|
|
targetRoomId = roomInfo.id,
|
|
})
|
|
elseif index <= curMaxCount then
|
|
charCell.view.simpleStateController:SetState("Empty")
|
|
else
|
|
charCell.view.simpleStateController:SetState("Locked")
|
|
end
|
|
end)
|
|
|
|
node.countTxt.text = string.format("%d/%d", curCount, curMaxCount)
|
|
end
|
|
|
|
|
|
HL.Commit(SpaceshipControlCenterCtrl)
|