local UIFairSoloTournamentStage2 = UIViewClass() local MAX_GROUP_NUM = 4 function UIFairSoloTournamentStage2:OnOpened(context) CTL.FairSoloTournament.SetCurStage2PanelStage(context.stageID) self:RegistSystemEvent(EventID.UI_FairSoloTournament_RefreshStageInfo, self.RefreshStageInfo) self:RegistSystemEvent(EventID.UI_FairSoloTournament_RefreshPlayerInfo, self.RefreshStageInfo) self:RegistSystemEvent(EventID.UI_FairSoloTournament_RefreshMyInfo, self.RefreshStageInfo) self:RegistSystemEvent(EventID.UI_FairSoloTournament_JumpToPlayer, self.OnJumpToPlayer) self.infoList = {} self.stageID = context.stageID UTL.Toggle.InitToggleGroupByIDS(self.group_TogglesStage2, "txt", { Const_IDS.IDS_HeroMatch1v1_Team1, Const_IDS.IDS_HeroMatch1v1_Team2, Const_IDS.IDS_HeroMatch1v1_Team3, Const_IDS.IDS_HeroMatch1v1_Team4 }) self.group_TogglesStage2:SetToggleCompActive(1, "img_Line", false) self:RefreshStageInfo() end function UIFairSoloTournamentStage2:OnJumpToPlayer(acid) local stageInfo = MDL.FairSoloTournament.GetStageInfo(self.stageID) if MDL.FairSoloTournament.TryGetAllPlayerInfo(self.stageID) == false then local selectIndex = -1 for i, groupInfo in ipairs(stageInfo.groupInfos) do if groupInfo.playerInfos[1].acid == acid or groupInfo.playerInfos[2].acid == acid then selectIndex = i % MAX_GROUP_NUM break end end if selectIndex == 0 then selectIndex = MAX_GROUP_NUM end self.group_TogglesStage2:SelectIndex(math.max(selectIndex - 1, 0)) for i, v in ipairs(self.infoList) do if v.playerInfos[1].acid == acid or v.playerInfos[2].acid == acid then self.loop_FairSoloTournamentStage2:SelectIndex(i - 1, false) break end end end end function UIFairSoloTournamentStage2:OnClosed() CTL.FairSoloTournament.SetCurStage2PanelStage(nil) end function UIFairSoloTournamentStage2:OnValueChanged(comp, index) if comp == self.group_TogglesStage2 then self.targetGroup = index + 1 self:OnSelectGroup() end end function UIFairSoloTournamentStage2:RefreshStageInfo() local stageInfo = MDL.FairSoloTournament.GetStageInfo(self.stageID) if stageInfo == nil then MDL.FairSoloTournament.FairTournamentGetStageInfoReq(self.stageID) else if MDL.FairSoloTournament.TryGetAllPlayerInfo(self.stageID) == false then local selectIndex = -1 if self.targetGroup == nil then local myAcid = BattleDataGetter.GetAcID() for i, groupInfo in ipairs(stageInfo.groupInfos) do if groupInfo.playerInfos[1].acid == myAcid or groupInfo.playerInfos[2].acid == myAcid then selectIndex = i % MAX_GROUP_NUM break end end else selectIndex = self.targetGroup end if selectIndex == 0 then selectIndex = MAX_GROUP_NUM end self.group_TogglesStage2:SelectIndex(math.max(selectIndex - 1, 0)) end end end function UIFairSoloTournamentStage2:OnSelectGroup() table.clearArray(self.infoList) local targetGroup = self.targetGroup if targetGroup == MAX_GROUP_NUM then targetGroup = 0 end local stageInfo = MDL.FairSoloTournament.GetStageInfo(self.stageID) for i, groupInfo in ipairs(stageInfo.groupInfos) do local value = i % MAX_GROUP_NUM if value == targetGroup then table.insert(self.infoList, groupInfo) end end self.loop_FairSoloTournamentStage2:ReloadAll(self.infoList) end function UIFairSoloTournamentStage2:OnCellInit(scrollRect, index, cellTable, data) cellTable.txt_Group.text = index + 1 local isBye = string.isNilOrEmpty(data.playerInfos[1].acid) or string.isNilOrEmpty(data.playerInfos[2].acid) if isBye then --轮空 UIUtils.SetActive(cellTable.group_PlayerLeft.btn_LeftWatch, false) UIUtils.SetActive(cellTable.group_PlayerRight.btn_RightWatch, false) UIUtils.SetActive(cellTable.group_PlayerLeft.state_BtnLeft, false) UIUtils.SetActive(cellTable.group_PlayerRight.state_BtnRight, false) CTL.FairSoloTournament.SetBattleCellInfo(cellTable.group_PlayerLeft, string.isNilOrEmpty(data.playerInfos[1].acid) and nil or MDL.FairSoloTournament.GetPlayerShowInfo(data.playerInfos[1].acid)) CTL.FairSoloTournament.SetBattleCellInfo(cellTable.group_PlayerRight, string.isNilOrEmpty(data.playerInfos[2].acid) and nil or MDL.FairSoloTournament.GetPlayerShowInfo(data.playerInfos[2].acid)) if string.isNilOrEmpty(data.playerInfos[1].acid) then UIUtils.SetActive(cellTable.group_PlayerLeft.state_BtnLeft, false) UIUtils.SetActive(cellTable.group_PlayerRight.state_BtnRight, true) cellTable.group_PlayerRight.state_BtnRight:SetState(2) else UIUtils.SetActive(cellTable.group_PlayerLeft.state_BtnLeft, true) UIUtils.SetActive(cellTable.group_PlayerRight.state_BtnRight, false) cellTable.group_PlayerLeft.state_BtnLeft:SetState(2) end else CTL.FairSoloTournament.SetBattleCellInfo(cellTable.group_PlayerLeft, MDL.FairSoloTournament.GetPlayerShowInfo(data.playerInfos[1].acid)) CTL.FairSoloTournament.SetBattleCellInfo(cellTable.group_PlayerRight, MDL.FairSoloTournament.GetPlayerShowInfo(data.playerInfos[2].acid)) --竞猜、观战相关 local isPassed = self.stageID < MDL.FairSoloTournament.GetCurStageID() or CTL.FairSoloTournament.CheckBattleGroupEnd(data) if isPassed then --已经结束,显示胜利方 UIUtils.SetActive(cellTable.group_PlayerLeft.btn_LeftWatch, false) UIUtils.SetActive(cellTable.group_PlayerRight.btn_RightWatch, false) local isLeftWin = true if string.isNilOrEmpty(data.playerInfos[2].acid) == false and data.playerInfos[2].winNum > data.playerInfos[1].winNum then isLeftWin = false end if isLeftWin then cellTable.txt_WinLeftNum.text = UTL.Color.FormatTextByColor(MDL.HeroMatch1v1.WinColor, data.playerInfos[1].winNum) cellTable.txt_WinRightNum.text = data.playerInfos[2].winNum UIUtils.SetActive(cellTable.group_PlayerLeft.state_BtnLeft, true) cellTable.group_PlayerLeft.state_BtnLeft:SetState(2) UIUtils.SetActive(cellTable.group_PlayerRight.state_BtnRight, false) else cellTable.txt_WinLeftNum.text = data.playerInfos[1].winNum cellTable.txt_WinRightNum.text = UTL.Color.FormatTextByColor(MDL.HeroMatch1v1.WinColor, data.playerInfos[2].winNum) UIUtils.SetActive(cellTable.group_PlayerRight.state_BtnRight, true) cellTable.group_PlayerRight.state_BtnRight:SetState(2) UIUtils.SetActive(cellTable.group_PlayerLeft.state_BtnLeft, false) end else UIUtils.SetActive(cellTable.group_PlayerLeft.btn_LeftWatch, true) UIUtils.SetActive(cellTable.group_PlayerRight.btn_RightWatch, true) UIUtils.SetActive(cellTable.group_PlayerLeft.state_BtnLeft, true) UIUtils.SetActive(cellTable.group_PlayerRight.state_BtnRight, true) --竞猜状态 local isLeftGuess = MDL.FairSoloTournament.CheckIsGuessByGroupID_ACID(data.groupId, data.playerInfos[1].acid, false) if isLeftGuess then cellTable.group_PlayerLeft.state_BtnLeft:SetState(1) cellTable.group_PlayerLeft.txt_MoreRate.text = string.FormatByIdsId(Const_IDS.IDS_FairTournament_PickRate, CTL.FairSoloTournament.ParseBetRate(data.playerInfos[1].multiplier)) else cellTable.group_PlayerLeft.state_BtnLeft:SetState(0) cellTable.group_PlayerLeft.txt_Rate.text = string.FormatByIdsId(Const_IDS.IDS_FairTournament_PickRate, CTL.FairSoloTournament.ParseBetRate(data.playerInfos[1].multiplier)) end local isRightGuess = MDL.FairSoloTournament.CheckIsGuessByGroupID_ACID(data.groupId, data.playerInfos[2].acid, false) if isRightGuess then cellTable.group_PlayerRight.state_BtnRight:SetState(1) cellTable.group_PlayerRight.txt_MoreRate.text = string.FormatByIdsId(Const_IDS.IDS_FairTournament_PickRate, CTL.FairSoloTournament.ParseBetRate(data.playerInfos[2].multiplier)) else cellTable.group_PlayerRight.state_BtnRight:SetState(0) cellTable.group_PlayerRight.txt_Rate.text = string.FormatByIdsId(Const_IDS.IDS_FairTournament_PickRate, CTL.FairSoloTournament.ParseBetRate(data.playerInfos[2].multiplier)) end end end local stageInfo = MDL.FairSoloTournament.GetStageInfo(self.stageID) if stageInfo.state == MDL.FairSoloTournament.Enum_State.Ready or stageInfo.state == MDL.FairSoloTournament.Enum_State.Matching then cellTable.state_Match:SetState(0) cellTable.txt_Score1.text = data.playerInfos[1].winNum .. " : " .. data.playerInfos[2].winNum cellTable.txt_NotStartedInfo.text = string.FormatByIdsId(Const_IDS.IDS_FairTournament_RoundStart, data.turn) cellTable.cdTimer:ResetAndBeginCustomTimer(false, stageInfo.stateEndTime - UTL.Time.GetServerTimestamp(), 0, "{0}:{1}:{2}") elseif stageInfo.state == MDL.FairSoloTournament.Enum_State.Battle then cellTable.txt_NotStartedInfo.text = nil cellTable.cdTimer:EndTimer() if data.isBattleEnd then cellTable.state_Match:SetState(3) local isLeftWin = data.playerInfos[1].winNum > data.playerInfos[2].winNum UIUtils.SetLabel(cellTable.txt_WinLeftNum, isLeftWin and UTL.Color.FormatTextByColor(MDL.HeroMatch1v1.WinColor, data.playerInfos[1].winNum) or UTL.Color.FormatWhiteColor(data.playerInfos[1].winNum)) UIUtils.SetLabel(cellTable.txt_WinRightNum, isLeftWin and UTL.Color.FormatWhiteColor(data.playerInfos[2].winNum) or UTL.Color.FormatTextByColor(MDL.HeroMatch1v1.WinColor, data.playerInfos[2].winNum)) else cellTable.state_Match:SetState(2) cellTable.txt_Score3.text = data.playerInfos[1].winNum .. " : " .. data.playerInfos[2].winNum end elseif stageInfo.state == MDL.FairSoloTournament.Enum_State.Roll then cellTable.state_Match:SetState(1) cellTable.txt_Score2.text = data.playerInfos[1].winNum .. " : " .. data.playerInfos[2].winNum cellTable.txt_NotStartedInfo.text = nil cellTable.cdTimer:EndTimer() elseif stageInfo.state == MDL.FairSoloTournament.Enum_State.BanPick then cellTable.state_Match:SetState(2) cellTable.txt_Score3.text = data.playerInfos[1].winNum .. " : " .. data.playerInfos[2].winNum cellTable.txt_NotStartedInfo.text = nil cellTable.cdTimer:EndTimer() elseif stageInfo.state == MDL.FairSoloTournament.Enum_State.Finish then cellTable.state_Match:SetState(3) cellTable.txt_NotStartedInfo.text = nil cellTable.cdTimer:EndTimer() local isLeftWin = data.playerInfos[1].winNum > data.playerInfos[2].winNum UIUtils.SetLabel(cellTable.txt_WinLeftNum, isLeftWin and UTL.Color.FormatTextByColor(MDL.HeroMatch1v1.WinColor, data.playerInfos[1].winNum) or UTL.Color.FormatWhiteColor(data.playerInfos[1].winNum)) UIUtils.SetLabel(cellTable.txt_WinRightNum, isLeftWin and UTL.Color.FormatWhiteColor(data.playerInfos[2].winNum) or UTL.Color.FormatTextByColor(MDL.HeroMatch1v1.WinColor, data.playerInfos[2].winNum)) end end function UIFairSoloTournamentStage2:OnCellClicked(scrollRect, index, cellTable, target, data) if target == cellTable.group_PlayerLeft.btn_LeftWatch then -- 左边观战 CTL.FairSoloTournament.WatchBattle(data, data.playerInfos[1].gRoomId, data.playerInfos[1].playerId, data.playerInfos[1].acid, self.stageID) elseif target == cellTable.group_PlayerLeft.btn_LeftGuess or target == cellTable.group_PlayerLeft.btn_LeftGuessMore then -- 左边竞猜 CTL.FairSoloTournament.OpenBetKeyBoard(data.groupId, data.playerInfos[1].acid, CTL.FairSoloTournament.ParseBetRate(data.playerInfos[1].multiplier), self.stageID, data.turn) elseif target == cellTable.group_PlayerRight.btn_RightWatch then -- 右边观战 CTL.FairSoloTournament.WatchBattle(data, data.playerInfos[2].gRoomId, data.playerInfos[2].playerId, data.playerInfos[2].acid, self.stageID) elseif target == cellTable.group_PlayerRight.btn_RightGuess or target == cellTable.group_PlayerRight.btn_RightGuessMore then -- 右边竞猜 CTL.FairSoloTournament.OpenBetKeyBoard(data.groupId, data.playerInfos[2].acid, CTL.FairSoloTournament.ParseBetRate(data.playerInfos[2].multiplier), self.stageID, data.turn) elseif target == cellTable.group_PlayerLeft.UIHeroHead.img_PlayerAvatarBg then -- 左边玩家 if data.playerInfos[1].acid ~= BattleDataGetter.GetAcID() then MDL.PlayerInteract.GetPlayerInteractiveInfoReq(data.playerInfos[1].acid) end elseif target == cellTable.group_PlayerRight.UIHeroHead.img_PlayerAvatarBg then -- 右边玩家 if data.playerInfos[2].acid ~= BattleDataGetter.GetAcID() then MDL.PlayerInteract.GetPlayerInteractiveInfoReq(data.playerInfos[2].acid) end end end return UIFairSoloTournamentStage2