PGRData/Script/matrix/xui/xuiassign/XUiGridAssignFormationTeam.lua

142 lines
No EOL
4.5 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

local XUiGridAssignFormationTeam = XClass(nil, "XUiGridAssignFormationTeam")
local XUiGridAssignFormationMember = require("XUi/XUiAssign/XUiGridAssignFormationMember")
XUiGridAssignFormationTeam.BtnTabIndex = {
Blue = 2,
Red = 1, -- 注意队伍位置为1但显示位置在中间
Yellow = 3,
}
function XUiGridAssignFormationTeam:Ctor(rootUi, ui)
self.GameObject = ui.gameObject
self.Transform = ui.transform
self.RootUi = rootUi
XTool.InitUiObject(self)
self:InitComponent()
self:InitButtonGroup()
end
function XUiGridAssignFormationTeam:InitComponent()
self.MemberGridList = {}
self.GridTeamMember.gameObject:SetActiveEx(false)
end
function XUiGridAssignFormationTeam:GetMemberGrid(index)
local grid = self.MemberGridList[index]
if not grid then
local obj = CS.UnityEngine.Object.Instantiate(self.GridTeamMember)
obj.transform:SetParent(self.PanelRole, false)
grid = XUiGridAssignFormationMember.New(self, obj)
self.MemberGridList[index] = grid
end
return grid
end
function XUiGridAssignFormationTeam:ResetMemberGridList(len)
if #self.MemberGridList > len then
for _ = len + 1, #self.MemberGridList do
self.MemberGridList.GameObject:SetActiveEx(false)
end
end
end
function XUiGridAssignFormationTeam:InitButtonGroup()
self.TabGroup = {
self.BtnRed,
self.BtnBlue,
self.BtnYellow,
}
self.PanelTabFirst:Init(self.TabGroup, function(tabIndex) self:OnClickTabCallBack(tabIndex) end)
self.TabGroupCT = {
self.BtnCaptainRed,
self.BtnCaptainBlue,
self.BtnCaptainYellow,
}
self.PanelTabCaptain:Init(self.TabGroupCT, function(tabIndex) self:OnClickTabCallBackCT(tabIndex) end)
end
function XUiGridAssignFormationTeam:Refresh(groupId, teamOrder, teamInfoId)
local teamData = XDataCenter.FubenAssignManager.GetTeamDataById(teamInfoId)
local lastMemberNum = self.MemberNum
self.TeamOrder = teamOrder
self.TeamInfoId = teamInfoId
self.MemberNum = teamData:GetNeedCharacter()
self.TextTitle.text = CS.XTextManager.GetText("AssignTeamTitle", self.TeamOrder) -- 作战梯队1
self:ResetMemberGridList(self.MemberNum)
for i = 1, self.MemberNum do
local grid = self:GetMemberGrid(i)
grid.GameObject:SetActiveEx(true)
grid:Refresh(groupId, teamOrder, teamData, i)
end
local stageId = teamInfoId
local characterLimitType = XFubenConfigs.GetStageCharacterLimitType(teamInfoId)
if not XFubenConfigs.IsStageCharacterLimitConfigExist(characterLimitType) then
self.PanelRequireCharacter.gameObject:SetActiveEx(false)
else
local icon = XFubenConfigs.GetStageCharacterLimitImageTeamEdit(characterLimitType)
self.ImgRequireCharacter:SetSprite(icon)
local name = XFubenConfigs.GetStageCharacterLimitName(characterLimitType)
self.TxtRequireCharacter.text = name
self.PanelRequireCharacter.gameObject:SetActiveEx(true)
end
--队长/首发
for i = 1, #self.TabGroup do
self.TabGroup[i].gameObject:SetActiveEx(i <= self.MemberNum)
end
local firstFightPos = teamData:GetFirstFightIndex()
self.PanelTabFirst:SelectIndex(firstFightPos)
for i = 1, #self.TabGroupCT do
self.TabGroupCT[i].gameObject:SetActiveEx(i <= self.MemberNum)
end
local captainPos = teamData:GetLeaderIndex()
self.PanelTabCaptain:SelectIndex(captainPos)
end
function XUiGridAssignFormationTeam:RefreshMemberEffect(state)
for i = 1, self.MemberNum do
local grid = self:GetMemberGrid(i)
grid:RefreshEffect(state)
end
end
function XUiGridAssignFormationTeam:OnClickTabCallBack(index)
if self.SelectedIndex and self.SelectedIndex == index then
return
end
self.SelectedIndex = index
local teamData = XDataCenter.FubenAssignManager.GetTeamDataById(self.TeamInfoId)
teamData:SetFirstFightIndex(index)
for i = 1, self.MemberNum do
local grid = self:GetMemberGrid(i)
grid:RefreshLeaderIndex()
end
end
function XUiGridAssignFormationTeam:OnClickTabCallBackCT(index)
if self.SelectedIndexCT and self.SelectedIndexCT == index then
return
end
self.SelectedIndexCT = index
local teamData = XDataCenter.FubenAssignManager.GetTeamDataById(self.TeamInfoId)
teamData:SetLeaderIndex(index)
for i = 1, self.MemberNum do
local grid = self:GetMemberGrid(i)
grid:RefreshLeaderIndex()
end
end
return XUiGridAssignFormationTeam