--[[ 小组赛 ]] local PlayerHeadCell3V3Helper = require "Modules.TeamFairChampionship.PlayerHeadCell3V3Helper" local UITeamFairChampionshipBaseStage01 = UIViewClass() local TYPE_RANK = 1 function UITeamFairChampionshipBaseStage01:OnCreated() self.displayMatchStageId = -1 self.matchStageInfo = nil self.infoList = {} self.indexGroup = {} self.isForceSelectGroup = false local groupNum = MDL.TeamFairChampionship.GetMatchFilterGroupNum() for i = 1, groupNum do self.indexGroup[i] = i end self.myTeamRankData = nil end function UITeamFairChampionshipBaseStage01:OnOpened(context) self:RegistSystemEvent(EventID.UI_TeamFairChampionship_RefreshInfo, self.RefreshScrollList) self:RegistSystemEvent(EventID.UI_TeamFairChampionship_RefreshOneStage, self.RefreshStage) self:RegistSystemEvent(EventID.UI_TeamFairChampionship_BattleBet, self.RefreshScrollList) self:RegistSystemEvent(EventID.UI_TeamFairChampionship_AllPlayerInfo, self.RefreshScrollList) self:RegistSystemEvent(EventID.UI_TeamFairChampionship_MatchGroupTeamInfo,self.RefreshMatchGroupTeamInfo) self:RegistSystemEvent(EventID.UI_TeamFairChampionship_ChangeGroupSelect, self.OnChangeGroupSelect) if CTL.TeamFairChampionship.IsFilterMatchStage() then self.displayMatchStageId = MDL.TeamFairChampionship.GetCurStageID() else self.displayMatchStageId = MDL.TeamFairChampionship.Stage.Filtration_2 end self:InitFilterMatchToggle() self.matchStageInfo = MDL.TeamFairChampionship.GetMatchStageInfo(self.displayMatchStageId) if not self.matchStageInfo then MDL.TeamFairChampionship.TeamFairGetStageInfoReq(self.displayMatchStageId) else self:RefreshStage(self.displayMatchStageId, 0) end MDL.TeamFairChampionship.TeamFairGetClassTeamInfoReq() end function UITeamFairChampionshipBaseStage01:RefreshStage(stageId, myMatchGroupId) if stageId == self.displayMatchStageId then self.matchStageInfo = MDL.TeamFairChampionship.GetMatchStageInfo(self.displayMatchStageId) local index = CTL.TeamFairChampionship.GetLastGroupSelectIndex() local watchParam = MDL.TeamFairChampionship.GetWatchParam() if watchParam and watchParam.watchStageId == self.displayMatchStageId then self.selectGroup = watchParam.watchMatchGroupId self.isForceSelectGroup = true elseif myMatchGroupId and myMatchGroupId>0 then self.selectGroup = myMatchGroupId self.isForceSelectGroup = true else self.isForceSelectGroup = false end self.group_Toggles01:SelectIndex(index) end end function UITeamFairChampionshipBaseStage01:OnChangeGroupSelect(selectIndex) self.group_Toggles01:SelectIndex(selectIndex) end function UITeamFairChampionshipBaseStage01:InitFilterMatchToggle() UTL.Toggle.InitToggleGroupByIDS(self.group_Toggles01, "txt", {Const_IDS.IDS_FairTournament_RaceBattle, Const_IDS.IDS_FairTournament_BattleRank}) self.group_Toggles01:SetToggleCompActive(1, "img_Line", false) self.group_Toggles01:SetToggleCompActive(2, "img_Line", false) end function UITeamFairChampionshipBaseStage01:OnValueChanged(comp, index) if comp == self.group_Toggles01 then if self.selectGroupCell and self.selectToggleIndex ~= index then UIUtils.SetActive(self.selectGroupCell.img_UnSelected, true) UIUtils.SetActive(self.selectGroupCell.img_Selected, false) self.selectGroupCell = nil end self.selectToggleIndex = index CTL.TeamFairChampionship.SetLastGroupSelectIndex(self.selectToggleIndex) if index == TYPE_RANK then UIUtils.SetActive(self.group_Rank, true) UIUtils.SetActive(self.group_Competition, false) if self.indexGroup[1] == 0 then table.remove(self.indexGroup, 1) end else UIUtils.SetActive(self.group_Rank, false) UIUtils.SetActive(self.group_Competition, true) if self.indexGroup[1] == 1 then table.insert(self.indexGroup, 1, 0) end end self.loop_FTLeftTab:ReloadAll(self.indexGroup) self.targetSeletctIndex = self:GetSelectIndex() self.selectGroup = nil self.loop_FTLeftTab:SelectIndex(self.targetSeletctIndex, self.isForceSelectGroup) end end function UITeamFairChampionshipBaseStage01:OnChangeGroupTab(tabIndex) self.group_Toggles01:SelectIndex(tabIndex) end function UITeamFairChampionshipBaseStage01:GetSelectIndex() local targetIndex if self.selectGroup then --赛事页签多了个推荐,因此不用-1 if self.selectToggleIndex == TYPE_RANK then targetIndex = math.max(self.selectGroup - 1, 0) else targetIndex = math.max(self.selectGroup, 0) end else targetIndex = 0 end return targetIndex end function UITeamFairChampionshipBaseStage01:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_FTLeftTab then if data == 0 then UIUtils.SetLabelText(cellTable.txt_Name_Nomal, Const_IDS.IDS_FairTournament_Suggest) UIUtils.SetLabelText(cellTable.txt_Name_Selected, Const_IDS.IDS_FairTournament_Suggest) else local title = string.FormatByIdsId(Const_IDS.IDS_FairTournament_Group, data) cellTable.txt_Name_Nomal.text = title cellTable.txt_Name_Selected.text = title end if self.targetSeletctIndex == index then UIUtils.SetActive(cellTable.img_UnSelected, false) UIUtils.SetActive(cellTable.img_Selected, true) self.selectGroupCell = cellTable else UIUtils.SetActive(cellTable.img_UnSelected, true) UIUtils.SetActive(cellTable.img_Selected, false) end if MDL.TeamFairChampionship.GetGroupBetInfo(self.displayMatchStageId, data) then if not CTL.TeamFairChampionship.IsFilterMatchStage() and self.selectToggleIndex ~= TYPE_RANK then UIUtils.SetActive(cellTable.group_Tag, false) else UIUtils.SetActive(cellTable.group_Tag, true) UIUtils.SetLabelText(cellTable.txt_Tag, Const_IDS.IDS_FairTournament_Picked1) end else UIUtils.SetActive(cellTable.group_Tag, false) end elseif scrollRect == self.LoopScroll_TeamCompetition then PlayerHeadCell3V3Helper.Set3V3MatchPlayerNormalCellInit(string.FormatByIdsKey("IDS_FairTournament_Group", data.matchGroupId), cellTable, data, self.matchStageInfo, true) elseif scrollRect == self.LoopScroll_TeamInfo then self:SetRankCell(cellTable, data, index + 1) end end function UITeamFairChampionshipBaseStage01:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loop_FTLeftTab then if not self.selectGroup == nil or self.selectGroup ~= data then if self.selectGroupCell then UIUtils.SetActive(self.selectGroupCell.img_UnSelected, true) UIUtils.SetActive(self.selectGroupCell.img_Selected, false) end UIUtils.SetActive(cellTable.img_UnSelected, false) UIUtils.SetActive(cellTable.img_Selected, true) self.selectGroupCell = cellTable self.targetSeletctIndex = index self.selectGroup = data self:RefreshMatchGroupData() end elseif scrollRect == self.LoopScroll_TeamCompetition then PlayerHeadCell3V3Helper.On3V3MatchPlayerCellClick(cellTable, data, target, self.matchStageInfo) elseif scrollRect == self.LoopScroll_TeamInfo then if target == cellTable.btn_Guess or target == cellTable.btn_GuessMore then CTL.TeamFairChampionship.OpenBetKeyBoard(self.selectGroup, 0, data, self.displayMatchStageId, 1) elseif target == cellTable.btn_TeamInfo then CTL.TeamFairChampionship.OpenMatchTeamDetailPanel(data) end end end --选中页签(排行、赛制) function UITeamFairChampionshipBaseStage01:RefreshMatchGroupData() if self.selectToggleIndex == TYPE_RANK then self:ShowRankGroupData() else self:ShowTeamCompetitionGroupData() end end function UITeamFairChampionshipBaseStage01:RefreshMatchGroupTeamInfo() if self.selectToggleIndex == TYPE_RANK then self:ShowRankGroupData() end end local SortByWinNum = function(teamInfo1, teamInfo2) local teamGroupMatch1 = MDL.TeamFairChampionship.GetMatchGroupTeamInfoByTeamId(teamInfo1.teamId) local teamGroupMatch2 = MDL.TeamFairChampionship.GetMatchGroupTeamInfoByTeamId(teamInfo2.teamId) local winNum1 = teamGroupMatch1 and teamGroupMatch1.classWinNum or 0 local winNum2 = teamGroupMatch2 and teamGroupMatch2.classWinNum or 0 if winNum1 ~= winNum2 then return winNum1>winNum2 end local defeatNum1 = teamGroupMatch1 and teamGroupMatch1.defeatNum or 0 local defeatNum2 = teamGroupMatch1 and teamGroupMatch2.defeatNum or 0 if defeatNum1 ~= defeatNum2 then return defeatNum1>defeatNum2 end return teamInfo1.enterRank 0 then UIUtils.SetActive(self.group_RankEmpty, false) table.sort(self.infoList, SortByWinNum) for index, teamInfo in ipairs(self.infoList) do if teamInfo.teamId == MDL.TeamFairChampionship.GetMyTeamId() then myTeamRankIndex = index self.myTeamRankData = teamInfo break end end self.LoopScroll_TeamInfo:ReloadAll(self.infoList) else UIUtils.SetActive(self.group_RankEmpty, true) self.LoopScroll_TeamInfo:ClearCells() end if myTeamRankIndex then UIUtils.SetActive(self.my_Team3v3Rank.gameObject, true) self:SetRankCell(self.my_Team3v3Rank, self.myTeamRankData, myTeamRankIndex) self.my_Team3v3Rank.state_GuessBtn:SetState(2) else UIUtils.SetActive(self.my_Team3v3Rank.gameObject, false) end end local SortByGroup = function(groupInfo1, groupInfo2) if groupInfo1.matchGroupId ~= groupInfo2.matchGroupId then return groupInfo1.matchGroupId0 then table.sort(self.infoList, SortByGroup) end if #self.infoList > 0 then UIUtils.SetActive(self.group_CompetitionEmpty, false) self.LoopScroll_TeamCompetition:ReloadAll(self.infoList) else UIUtils.SetActive(self.group_CompetitionEmpty, true) self.LoopScroll_TeamCompetition:ClearCells() end end --设置排行信息 function UITeamFairChampionshipBaseStage01:SetRankCell(cellTable, data, rankIndex) --排名 if rankIndex <= 0 then UIUtils.SetLabelText(cellTable.group_Rank.txt_Rank, Const_IDS.IDS_Rank_Unranked) cellTable.group_Rank.state_Rank:SetState(3) else UIUtils.SetLabel(cellTable.group_Rank.txt_Rank, rankIndex) cellTable.group_Rank.state_Rank:SetState(rankIndex <= 3 and rankIndex - 1 or 3) end cellTable.state_Bg:SetState(rankIndex%2) cellTable.txt_TeamName.text = data.teamName --胜利场次 local teamGroupMatch = MDL.TeamFairChampionship.GetMatchGroupTeamInfoByTeamId(data.teamId) cellTable.txt_Win.text = teamGroupMatch and teamGroupMatch.classWinNum or 0 cellTable.txt_Beat.text = teamGroupMatch and teamGroupMatch.defeatNum or 0 local betRate = CTL.TeamFairChampionship.ParseBetRate(data.Multiplier) if MDL.TeamFairChampionship.GetMatchGroupTeamBetInfo(self.displayMatchStageId, self.selectGroup, data.teamId) then cellTable.state_GuessBtn:SetState(1) UIUtils.SetLabel(cellTable.txt_MoreRate, betRate) else cellTable.state_GuessBtn:SetState(0) UIUtils.SetLabel(cellTable.txt_Rate, betRate) end end function UITeamFairChampionshipBaseStage01:RefreshScrollList() if self.selectToggleIndex == TYPE_RANK then self.loop_FTLeftTab:UpdateIndex(self.selectGroup-1) self.LoopScroll_TeamInfo:RefreshCells() else self.LoopScroll_TeamCompetition:RefreshCells() end end function UITeamFairChampionshipBaseStage01:OnButtonClicked(comp) if comp == self.my_Team3v3Rank.btn_Guess or comp == self.my_Team3v3Rank.btn_GuessMore then CTL.TeamFairChampionship.OpenBetKeyBoard(self.selectGroup, self.myTeamRankData, self.displayMatchStageId, 1) elseif comp == self.my_Team3v3Rank.btn_TeamInfo then CTL.TeamFairChampionship.OpenMatchTeamDetailPanel(self.myTeamRankData) end end return UITeamFairChampionshipBaseStage01