local UIHeroMatch3v3Stage2 = UIViewClass() local TimerString = string.FormatByIdsId(Const_IDS.IDS_HeroMatch3v3_StartInMinutes, "{0}:{1}:{2}") function UIHeroMatch3v3Stage2:OnOpened(context) self.StageID = context.stageID self:RegistSystemEvent(EventID.UI_HeroMatch3v3_RefreshPlayerInfo, self.OnRefreshPlayerInfo) -- 刷新选手信息 self:RefreshStage2() end function UIHeroMatch3v3Stage2:OnRefreshPlayerInfo() if self.isWaitingPlayerData then self:LoadInfoOnGetPlayerData() self.isWaitingPlayerData = false else self:RefreshStage2() end end function UIHeroMatch3v3Stage2:RefreshPlayerInfo(stageId) self.StageID = stageId self:RefreshStage2() local groupIndex = self.lastGroupIndex or 0 self.loop_Match:ReloadAll(self.groupInfosDic[groupIndex + 1]) end --region ******************** Loop ************************* function UIHeroMatch3v3Stage2:OnCellInit(scrollRect, index, cellTable, data) local cell_Data = data.teamInfos UIUtils.SetLabel(cellTable.txt_Group, index + 1) local leftHavePlayerInfo, rightHavePlayerInfo = cell_Data[1].teamId ~= "", cell_Data[2].teamId ~= "" if leftHavePlayerInfo then cellTable.group_PlayerLeft.state_Info:SetState(0) self:SetTeamPlayerInfo(cellTable.group_PlayerLeft, cell_Data[1]) else cellTable.group_PlayerLeft.state_Info:SetState(1) end if rightHavePlayerInfo then cellTable.group_PlayerRight.state_Info:SetState(0) self:SetTeamPlayerInfo(cellTable.group_PlayerRight, cell_Data[2]) else cellTable.group_PlayerRight.state_Info:SetState(1) end local isLeftGuess = leftHavePlayerInfo and MDL.HeroMatch3v3.CheckIsGuessByGroupID_TeamID(data.groupId, cell_Data[1].teamId) UIUtils.SetActive(cellTable.group_PlayerLeft.img_Bet, isLeftGuess) local isRightGuess = rightHavePlayerInfo and MDL.HeroMatch3v3.CheckIsGuessByGroupID_TeamID(data.groupId, cell_Data[2].teamId) UIUtils.SetActive(cellTable.group_PlayerRight.img_Bet, isRightGuess) if leftHavePlayerInfo and rightHavePlayerInfo then if self.winnerInfo.state == MDL.HeroMatch3v3.Enum_State.Ready then -- 准备中 self:SetReadyState(cellTable, isLeftGuess, isRightGuess) elseif self.winnerInfo.state == MDL.HeroMatch3v3.Enum_State.Battle then -- 战斗中 if data.groupState == MDL.HeroMatch3v3.Enum_GroupState.Battle then cellTable.state_BtnLeft:SetState(0) cellTable.state_BtnRight:SetState(0) cellTable.state_Match:SetState(1) else self:SetWinState(cellTable, cell_Data) end elseif self.winnerInfo.state == MDL.HeroMatch3v3.Enum_State.Matching then -- 匹配中 self:SetReadyState(cellTable, isLeftGuess, isRightGuess) else self:SetWinState(cellTable, cell_Data) end else if leftHavePlayerInfo then cellTable.state_BtnLeft:SetState(2) cellTable.state_BtnRight:SetState(3) cellTable.state_Match:SetState(2) UIUtils.SetLabel(cellTable.txt_WinLeftNum, UTL.Color.FormatTextByColor(MDL.HeroMatch3v3.WinColor, cell_Data[1].winNum > 0 and cell_Data[1].winNum or 1)) UIUtils.SetLabel(cellTable.txt_WinRightNum, UTL.Color.FormatWhiteColor(0)) elseif rightHavePlayerInfo then cellTable.state_BtnLeft:SetState(3) cellTable.state_BtnRight:SetState(2) cellTable.state_Match:SetState(2) UIUtils.SetLabel(cellTable.txt_WinLeftNum, UTL.Color.FormatWhiteColor(0)) UIUtils.SetLabel(cellTable.txt_WinRightNum, UTL.Color.FormatTextByColor(MDL.HeroMatch3v3.WinColor, cell_Data[2].winNum > 0 and cell_Data[2].winNum or 1)) else self:SetNoPlayer(cellTable) end end end function UIHeroMatch3v3Stage2:SetTeamPlayerInfo(comp, info) comp.txt_TeamName.text = UTL.Color.FormatTextByColor("fff08b", info.teamName) if info.teamId == MDL.SpecialTeam.GetMyTeamId() then UIUtils.SetActive(comp.img_Self, true) else UIUtils.SetActive(comp.img_Self, false) end -- 设置服务器名 local headInfo_1 = MDL.HeroMatch3v3.GetPlayerInfoByACID(info.acids[1]) UIUtils.SetLabel(comp.txt_Server, CTL.CrossServer.GetFormatServerShow(headInfo_1.ShowServerId)) self:SetSinglePlayerInfo(headInfo_1, comp.UIHeroHead01, comp.txt_Name01, comp.group_Name01, comp) local headInfo_2 = MDL.HeroMatch3v3.GetPlayerInfoByACID(info.acids[2]) self:SetSinglePlayerInfo(headInfo_2, comp.UIHeroHead02, comp.txt_Name02, comp.group_Name02, comp) local headInfo_3 = MDL.HeroMatch3v3.GetPlayerInfoByACID(info.acids[3]) self:SetSinglePlayerInfo(headInfo_3, comp.UIHeroHead03, comp.txt_Name03, comp.group_Name03, comp) end function UIHeroMatch3v3Stage2:SetSinglePlayerInfo(showInfo, headComp, nameTxt, nameGroup, comp) if showInfo then UIUtils.SetActive(headComp.gameObject, true) UIUtils.SetActive(nameGroup, true) local name if showInfo.acid == BattleDataGetter.GetAcID() then name = UTL.Color.FormatTextByColor("fff08b", showInfo.name) else name = UTL.Color.FormatWhiteColor(showInfo.name) end UIUtils.SetLabel(nameTxt, name) CTL.Character.SetPortraitAndFrame(headComp, showInfo.PortraitId, showInfo.FrameId) UIUtils.SetCanvasSortingOrderByMainCanvas(headComp.effectUpCanvas, comp.group_Top, CTL.Character.UpOrder.Common) else UIUtils.SetActive(headComp.gameObject, false) nameTxt.text = nil UIUtils.SetActive(nameGroup, false) end end function UIHeroMatch3v3Stage2:OnCellClicked(scrollRect, index, cellTable, target, data) local cell_Data = data.teamInfos if target == cellTable.btn_LeftWatch then -- 左边观战 MDL.WatchBattle.WatchBattleRequest(cell_Data[1].groomId, MDL.WatchBattle.WatchBattleType.HeroMatch3v3, cell_Data[1].playerIds[1], MDL.HeroMatch3v3.GetCurStageID()) elseif target == cellTable.btn_LeftGuess then -- 左边竞猜 MDL.HeroMatch3v3.HeroMatchBattleBetRequest(self.winnerInfo.stageId, data.groupId, cell_Data[1].teamId) elseif target == cellTable.btn_RightWatch then -- 右边观战 MDL.WatchBattle.WatchBattleRequest(cell_Data[2].groomId, MDL.WatchBattle.WatchBattleType.HeroMatch3v3, cell_Data[2].playerIds[1], MDL.HeroMatch3v3.GetCurStageID()) elseif target == cellTable.btn_RightGuess then -- 右边竞猜 MDL.HeroMatch3v3.HeroMatchBattleBetRequest(self.winnerInfo.stageId, data.groupId, cell_Data[2].teamId) elseif target == cellTable.group_PlayerLeft.btn_TeamInfo then MDL.HeroMatch3v3.GetHeroMatchTeamSimpleInfoRequest(cell_Data[1].teamId) elseif target == cellTable.group_PlayerRight.btn_TeamInfo then MDL.HeroMatch3v3.GetHeroMatchTeamSimpleInfoRequest(cell_Data[2].teamId) elseif target == cellTable.group_PlayerLeft.UIHeroHead01.img_PlayerAvatarBg then -- 左边玩家1 CTL.PlayerInteract.OpenFriendInteractView(cell_Data[1].acids[1]) elseif target == cellTable.group_PlayerLeft.UIHeroHead02.img_PlayerAvatarBg then -- 左边玩家2 CTL.PlayerInteract.OpenFriendInteractView(cell_Data[1].acids[2]) elseif target == cellTable.group_PlayerLeft.UIHeroHead03.img_PlayerAvatarBg then -- 左边玩家3 CTL.PlayerInteract.OpenFriendInteractView(cell_Data[1].acids[3]) elseif target == cellTable.group_PlayerRight.UIHeroHead01.img_PlayerAvatarBg then -- 右边玩家1 CTL.PlayerInteract.OpenFriendInteractView(cell_Data[2].acids[1]) elseif target == cellTable.group_PlayerRight.UIHeroHead01.img_PlayerAvatarBg then -- 右边玩家2 CTL.PlayerInteract.OpenFriendInteractView(cell_Data[2].acids[2]) elseif target == cellTable.group_PlayerRight.UIHeroHead01.img_PlayerAvatarBg then -- 右边玩家3 CTL.PlayerInteract.OpenFriendInteractView(cell_Data[2].acids[3]) end end --endregion ******************** Loop ************************* function UIHeroMatch3v3Stage2:RefreshStage2() self.winnerInfo = MDL.HeroMatch3v3.GetMatchStageInfo(self.StageID) self.myGroupNum = MDL.HeroMatch3v3.GetMyGroupAndIndex(self.StageID) self.myIndex = 0 self.groupInfosDic = {} local groupCount = #self.winnerInfo.groupInfos / 4 for k,v in ipairs(self.winnerInfo.groupInfos) do local index = math.ceil(k / groupCount) if not self.groupInfosDic[index] then self.groupInfosDic[index] = {} end table.insert(self.groupInfosDic[index], v) end for k,v in ipairs(self.groupInfosDic[self.myGroupNum]) do for _, teamInfo in ipairs(v.teamInfos) do if teamInfo.teamId == MDL.SpecialTeam.GetMyTeamId() then self.myIndex = k - 1 break end end end end function UIHeroMatch3v3Stage2:SetPlayerGroupInfo(groupIndex) self.lastGroupIndex = groupIndex if MDL.HeroMatch3v3.TryGetAllPlayerInfo() == false then self.isWaitingPlayerData = false self:LoadInfoOnGetPlayerData() else self.isWaitingPlayerData = true end end function UIHeroMatch3v3Stage2:LoadInfoOnGetPlayerData() local groupIndex = self.lastGroupIndex or 0 self.loop_Match:ReloadAll(self.groupInfosDic[groupIndex + 1]) if self.myGroupNum == groupIndex + 1 then self.loop_Match:MoveIndex(self.myIndex) self.loop_Match:SelectIndex(self.myIndex) end end function UIHeroMatch3v3Stage2:SetNoPlayer(cellTable) cellTable.state_BtnLeft:SetState(3) cellTable.state_BtnRight:SetState(3) cellTable.state_Match:SetState(3) end function UIHeroMatch3v3Stage2:SetWinState(cellTable, cell_Data) cellTable.state_Match:SetState(2) local leftWin = cell_Data[1].winNum or 0 local rightWin = cell_Data[2].winNum if leftWin > rightWin then cellTable.state_BtnLeft:SetState(2) cellTable.state_BtnRight:SetState(3) UIUtils.SetLabel(cellTable.txt_WinLeftNum, UTL.Color.FormatTextByColor(MDL.HeroMatch3v3.WinColor, leftWin)) UIUtils.SetLabel(cellTable.txt_WinRightNum, UTL.Color.FormatWhiteColor(rightWin)) else cellTable.state_BtnLeft:SetState(3) cellTable.state_BtnRight:SetState(2) UIUtils.SetLabel(cellTable.txt_WinLeftNum, UTL.Color.FormatWhiteColor(leftWin)) UIUtils.SetLabel(cellTable.txt_WinRightNum, UTL.Color.FormatTextByColor(MDL.HeroMatch3v3.WinColor, rightWin)) end end function UIHeroMatch3v3Stage2:SetReadyState(cellTable, isLeftGuess, isRightGuess) cellTable.state_BtnLeft:SetState(isLeftGuess and 3 or 1) cellTable.state_BtnRight:SetState(isRightGuess and 3 or 1) cellTable.state_Match:SetState(0) cellTable.cdTimer:ResetAndBeginCustomTimer(false, self.winnerInfo.stateEndTime - UTL.Time.GetServerTimestamp(), 0, TimerString) end return UIHeroMatch3v3Stage2