local CsXTextManager = CS.XTextManager local Vector2 = CS.UnityEngine.Vector2 local XUiTheatreMassageGrid = require("XUi/XUiTheatre/RoleDetail/XUiTheatreMassageGrid") local XUiTheatreOwnedInfoPanel = require("XUi/XUiTheatre/RoleDetail/XUiTheatreOwnedInfoPanel") local XUiPanelRoleModel = require("XUi/XUiCharacter/XUiPanelRoleModel") --肉鸽成员列表界面 local XUiTheatreMainMassage = XLuaUiManager.Register(XLuaUi, "UiTheatreMainMassage") function XUiTheatreMainMassage:OnAwake() self.TheatreManager = XDataCenter.TheatreManager self.AdventureManager = self.TheatreManager.GetCurrentAdventureManager() self.RoleSelectStateDic = {} --招募角色当前显示的是试玩角色或自己的角色,false显示试玩角色,true显示对应自己的角色 self.CurrentEntityId = nil self.CurrentSelectTagGroup = { [XCharacterConfigs.CharacterType.Normal] = {}, [XCharacterConfigs.CharacterType.Isomer] = {} } self.CurrentCharacterType = self:GetDefaultCharacterType() -- 角色列表 self.DynamicTable = XDynamicTableNormal.New(self.SViewCharacterList) self.DynamicTable:SetProxy(XUiTheatreMassageGrid) self.DynamicTable:SetDelegate(self) self.GridCharacterNew.gameObject:SetActiveEx(false) self:RegisterUiEvents() -- 模型初始化 local panelRoleModel = self.UiModelGo.transform:FindTransform("PanelRoleModel") self.ImgEffectHuanren = self.UiModelGo.transform:FindTransform("ImgEffectHuanren") self.ImgEffectHuanren1 = self.UiModelGo.transform:FindTransform("ImgEffectHuanren1") self.ImgEffectHuanren1.gameObject:SetActiveEx(false) self.UiPanelRoleModel = XUiPanelRoleModel.New(panelRoleModel, self.Name, nil, true) XUiHelper.NewPanelActivityAsset(XDataCenter.TheatreManager.GetAdventureAssetItemIds(), self.PanelSpecialTool) self.OwnedInfoPanel = XUiTheatreOwnedInfoPanel.New(self.UiOwnedInfo, handler(self, self.SwitchRoleState), self) self.IsAscendOrder = false --初始降序 self:CheckBtnFilterActive() self:InitBtnTabShougezhe() end function XUiTheatreMainMassage:OnEnable() self.PanelCharacterTypeBtns:SelectIndex(self.CurrentCharacterType) end function XUiTheatreMainMassage:InitBtnTabShougezhe() local lockShougezhe = not XFunctionManager.JudgeOpen(XFunctionManager.FunctionName.Isomer) local roles = self.AdventureManager:GetCurrentRoles() local isHaveIsomer = false for _, role in ipairs(roles) do if role:GetCharacterViewModel():GetCharacterType() == XCharacterConfigs.CharacterType.Isomer then isHaveIsomer = true break end end self.BtnTabShougezhe:SetDisable(lockShougezhe and not isHaveIsomer) end function XUiTheatreMainMassage:GetDefaultCharacterType() local roles for characterType in ipairs(self.CurrentSelectTagGroup) do roles = self:GetAdventureRoles(characterType) if not XTool.IsTableEmpty(roles) then return characterType end end end function XUiTheatreMainMassage:Filter(selectTagGroupDic, sortTagId, isThereFilterDataCb) if self.TagCacheDic == nil then self.TagCacheDic = {} end XDataCenter.RoomCharFilterTipsManager.Filter( self.TagCacheDic, selectTagGroupDic, self:GetAdventureRoles(self.CurrentCharacterType), handler(self, self.GetFilterJudge), function(filteredData) self.CurrentSelectTagGroup[self.CurrentCharacterType].TagGroupDic = selectTagGroupDic self.CurrentSelectTagGroup[self.CurrentCharacterType].SortType = sortTagId self:FilterRefresh(filteredData, sortTagId) end, isThereFilterDataCb ) end function XUiTheatreMainMassage:GetFilterJudge(groupId, tagValue, entity) if not entity.GetCharacterViewModel then return false end local characterViewModel = entity:GetCharacterViewModel() -- 职业筛选 if groupId == XRoomCharFilterTipsConfigs.EnumFilterTagGroup.Career then if tagValue == characterViewModel:GetCareer() then return true end -- 能量元素筛选 elseif groupId == XRoomCharFilterTipsConfigs.EnumFilterTagGroup.Element then local obtainElementList = characterViewModel:GetObtainElements() for _, element in pairs(obtainElementList) do if element == tagValue then return true end end else XLog.Error(string.format("XUiTheatreMainMassage:GetFilterJudge函数错误,没有处理排序组:%s的逻辑", groupId)) return false end end function XUiTheatreMainMassage:FilterRefresh(filteredData, sortTagType) if self.IsAscendOrder then filteredData = XTool.ReverseList(filteredData) end self:RefreshRoleList(filteredData) end function XUiTheatreMainMassage:RegisterUiEvents() self:RegisterClickEvent(self.BtnBack, self.Close) self:RegisterClickEvent(self.BtnMainUi, function() XLuaUiManager.RunMain() end) self:RegisterClickEvent(self.BtnFilter, self.OnBtnFilterClicked) self:RegisterClickEvent(self.BtnFashion, self.OnBtnFashionClick) self:RegisterClickEvent(self.BtnOwnedDetail, self.OnBtnOwnedDetailClick) self:RegisterClickEvent(self.BtnTeaching, self.OnBtnTeachingClick) self:RegisterClickEvent(self.BtnShengxu, self.OnBtnOrderClick) self:RegisterClickEvent(self.BtnJiangxu, self.OnBtnOrderClick) self:BindHelpBtn(self.BtnHelp, "Theatre") -- 角色类型按钮组 self.PanelCharacterTypeBtns:Init( { [XCharacterConfigs.CharacterType.Normal] = self.BtnTabGouzaoti, [XCharacterConfigs.CharacterType.Isomer] = self.BtnTabShougezhe }, function(tabIndex) self:OnPanelCharacterTypeBtnsClicked(tabIndex) end ) end function XUiTheatreMainMassage:GetCurrentCharacterId() local entityId = self.CurrentEntityId local adventureRole = self.AdventureManager:GetRole(entityId) return adventureRole:GetCharacterId() end function XUiTheatreMainMassage:OnBtnOwnedDetailClick() XLuaUiManager.Open("UiCharacterDetail", self:GetCurrentCharacterId()) end function XUiTheatreMainMassage:OnBtnTeachingClick() XDataCenter.PracticeManager.OpenUiFubenPractice(self:GetCurrentCharacterId()) end function XUiTheatreMainMassage:OnBtnFashionClick() XLuaUiManager.Open("UiFashion", self:GetCurrentCharacterId()) end function XUiTheatreMainMassage:OnBtnFilterClicked() XLuaUiManager.Open( "UiRoomCharacterFilterTips", self, XRoomCharFilterTipsConfigs.EnumFilterType.Common, XRoomCharFilterTipsConfigs.EnumSortType.Common, self.CurrentCharacterType ) end function XUiTheatreMainMassage:OnBtnOrderClick() self.IsAscendOrder = not self.IsAscendOrder self:CheckBtnFilterActive() self:OnPanelCharacterTypeBtnsClicked(self.CurrentCharacterType) end function XUiTheatreMainMassage:CheckBtnFilterActive() self.BtnShengxu.gameObject:SetActiveEx(self.IsAscendOrder) self.BtnJiangxu.gameObject:SetActiveEx(not self.IsAscendOrder) end function XUiTheatreMainMassage:GetAdventureRoles(characterType) local roles = self.AdventureManager:GetCurrentRoles() local result = {} for _, role in ipairs(roles) do if role:GetCharacterViewModel():GetCharacterType() == characterType then local entityId = role:GetId() table.insert(result, role) if self.RoleSelectStateDic[entityId] == nil then self.RoleSelectStateDic[entityId] = false end end end return result end -- characterType : XCharacterConfigs.CharacterType function XUiTheatreMainMassage:OnPanelCharacterTypeBtnsClicked(characterType) self.CurrentCharacterType = characterType local selectTagGroupDic = self.CurrentSelectTagGroup[characterType].TagGroupDic or {} local sortTagId = self.CurrentSelectTagGroup[characterType].SortType or XRoomCharFilterTipsConfigs.EnumSortTag.Default local roles = self:GetAdventureRoles(self.CurrentCharacterType) if XTool.IsTableEmpty(roles) then XUiManager.TipError(XUiHelper.GetText("IsomerLimitTip")) local defaultType = self:GetDefaultCharacterType() roles = self:GetAdventureRoles(defaultType) if not XTool.IsTableEmpty(roles) then self.PanelCharacterTypeBtns:SelectIndex(defaultType) end return end self:Filter( selectTagGroupDic, sortTagId, function(roles) return true end ) end function XUiTheatreMainMassage:RefreshRoleList(roleEntities) local searchEntityId = self.CurrentEntityId local index = 1 if searchEntityId ~= nil or searchEntityId ~= 0 then for i, v in ipairs(roleEntities) do if v:GetId() == searchEntityId then index = i break end end end self.CurrentEntityId = roleEntities[index]:GetId() self.DynamicTable:SetDataSource(roleEntities) self.DynamicTable:ReloadDataSync(index) self:RefreshModel() self:RefreshDetailPanel() end function XUiTheatreMainMassage:OnDynamicTableEvent(event, index, grid) if index <= 0 or index > #self.DynamicTable.DataSource then return end local entity = self.DynamicTable.DataSource[index] if event == DYNAMIC_DELEGATE_EVENT.DYNAMIC_GRID_ATINDEX then grid:SetSelect(self.CurrentEntityId == entity:GetId()) if self.RoleSelectStateDic[entity:GetId()] then local characterId = entity:GetCharacterId() entity = self.AdventureManager:GetRole(characterId) end grid:UpdateGrid(entity) elseif event == DYNAMIC_DELEGATE_EVENT.DYNAMIC_GRID_TOUCHED then self.CurrentEntityId = entity:GetId() for _, tmpGrid in pairs(self.DynamicTable:GetGrids()) do tmpGrid:SetSelect(false) end grid:SetSelect(true) self:RefreshModel() self:RefreshDetailPanel() end end function XUiTheatreMainMassage:RefreshModel() local entityId = self.CurrentEntityId local adventureRole = self.AdventureManager:GetRole(entityId) local characterViewModel = self.RoleSelectStateDic[entityId] and self:GetCharacterViewModelByEntityId(adventureRole:GetCharacterId()) or self:GetCharacterViewModelByEntityId(entityId) if not characterViewModel then return end self.ImgEffectHuanren.gameObject:SetActiveEx(false) self.ImgEffectHuanren1.gameObject:SetActiveEx(false) local finishedCallback = function(model) self.PanelDrag.Target = model.transform self.ImgEffectHuanren.gameObject:SetActiveEx( self.CurrentCharacterType == XCharacterConfigs.CharacterType.Normal ) self.ImgEffectHuanren1.gameObject:SetActiveEx( self.CurrentCharacterType == XCharacterConfigs.CharacterType.Isomer ) end local sourceEntityId = characterViewModel:GetSourceEntityId() if XRobotManager.CheckIsRobotId(sourceEntityId) then local robot2CharId = XRobotManager.GetCharacterId(sourceEntityId) local isOwn = XDataCenter.CharacterManager.IsOwnCharacter(robot2CharId) if XRobotManager.CheckUseFashion(sourceEntityId) and isOwn then local character = XDataCenter.CharacterManager.GetCharacter(robot2CharId) local robot2CharViewModel = character:GetCharacterViewModel() self.UiPanelRoleModel:UpdateCharacterModel(robot2CharId, nil, nil, finishedCallback, nil, robot2CharViewModel:GetFashionId()) else local robotConfig = XRobotManager.GetRobotTemplate(sourceEntityId) self.UiPanelRoleModel:UpdateRobotModel(sourceEntityId, robotConfig.CharacterId, nil, robotConfig.FashionId, robotConfig.WeaponId, finishedCallback) end else self.UiPanelRoleModel:UpdateCharacterModel( sourceEntityId, nil, nil, finishedCallback, nil, characterViewModel:GetFashionId() ) end end function XUiTheatreMainMassage:GetCharacterViewModelByEntityId(entityId) local role = self.AdventureManager:GetRole(entityId) if role == nil then return nil end return role:GetCharacterViewModel() end function XUiTheatreMainMassage:RefreshDetailPanel() local entityId = self.CurrentEntityId local adventureRole = self.AdventureManager:GetRole(entityId) local isOwnRole = self.RoleSelectStateDic[entityId] if isOwnRole then local characterId = adventureRole:GetCharacterId() adventureRole = self.AdventureManager:GetRole(characterId) end self.OwnedInfoPanel:SetData(adventureRole, entityId) self.BtnFashion.gameObject:SetActiveEx(isOwnRole or false) end function XUiTheatreMainMassage:SwitchRoleState(entityId) self.OwnedInfoPanel:InitPanelActiveState() self:PlayAnimationWithMask("RoleQieHuan") local state = self.RoleSelectStateDic[entityId] self.RoleSelectStateDic[entityId] = not state for i, entity in ipairs(self.DynamicTable.DataSource) do if entityId == entity:GetId() then local grid = self.DynamicTable:GetGridByIndex(i) if grid then grid:PlaySwitchAnima() if self.RoleSelectStateDic[entity:GetId()] then local characterId = entity:GetCharacterId() entity = self.AdventureManager:GetRole(characterId) end grid:UpdateGrid(entity) end end end self:RefreshModel() self:RefreshDetailPanel() end function XUiTheatreMainMassage:PlayAnima(animaName, cb) self:PlayAnimationWithMask(animaName, function() if cb then cb() end end) end return XUiTheatreMainMassage