local UIHeroMatch1v1Stage2 = UIViewClass() local TimerString = string.FormatByIdsId(Const_IDS.IDS_HeroMatch1v1_StartInMinutes, "{0}:{1}:{2}") function UIHeroMatch1v1Stage2:OnOpened(context) self.StageID = context.stageID self:RegistSystemEvent(EventID.UI_HeroMatch1v1_RefreshPlayerInfo, self.RefreshStage2) -- 刷新选手信息 self:RefreshStage2() end --region ******************** Loop ************************* function UIHeroMatch1v1Stage2:OnCellInit(scrollRect, index, cellTable, data) local cell_Data = data.playerInfos UIUtils.SetLabel(cellTable.txt_Group, index + 1) local leftHavePlayerInfo, rightHavePlayerInfo = cell_Data[1].acid ~= "", cell_Data[2].acid ~= "" CTL.HeroMatch1v1.SetHeroMatch1v1PlayerInfo(cellTable.group_PlayerLeft, leftHavePlayerInfo and MDL.HeroMatch1v1.GetPlayerInfoByACID(cell_Data[1].acid) or nil) -- 左边玩家 CTL.HeroMatch1v1.SetHeroMatch1v1PlayerInfo(cellTable.group_PlayerRight, rightHavePlayerInfo and MDL.HeroMatch1v1.GetPlayerInfoByACID(cell_Data[2].acid) or nil) -- 右边玩家 UIUtils.SetCanvasSortingOrderByMainCanvas(cellTable.group_PlayerLeft.UIHeroHead.effectUpCanvas, cellTable.group_PlayerLeft.canvas_Bet, CTL.Character.UpOrder.Common) UIUtils.SetCanvasSortingOrderByMainCanvas(cellTable.group_PlayerRight.UIHeroHead.effectUpCanvas, cellTable.group_PlayerRight.canvas_Bet, CTL.Character.UpOrder.Common) local isLeftGuess = leftHavePlayerInfo and MDL.HeroMatch1v1.CheckIsGuessByGroupID_ACID(data.groupId, cell_Data[1].acid) UIUtils.SetActive(cellTable.group_PlayerLeft.img_Bet, isLeftGuess) local isRightGuess = rightHavePlayerInfo and MDL.HeroMatch1v1.CheckIsGuessByGroupID_ACID(data.groupId, cell_Data[2].acid) UIUtils.SetActive(cellTable.group_PlayerRight.img_Bet, isRightGuess) if leftHavePlayerInfo and rightHavePlayerInfo then if self.winnerInfo.state == MDL.HeroMatch1v1.Enum_State.Ready then -- 准备中 self:SetReadyState(cellTable, isLeftGuess, isRightGuess) elseif self.winnerInfo.state == MDL.HeroMatch1v1.Enum_State.Battle then -- 战斗中 if data.groupState == MDL.HeroMatch1v1.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.HeroMatch1v1.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.HeroMatch1v1.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.HeroMatch1v1.WinColor, cell_Data[2].winNum > 0 and cell_Data[2].winNum or 1)) else self:SetNoPlayer(cellTable) end end end function UIHeroMatch1v1Stage2:OnCellClicked(scrollRect, index, cellTable, target, data) local cell_Data = data.playerInfos local myMatchInfo = MDL.HeroMatch1v1.GetMyMatchInfo() if target == cellTable.btn_LeftWatch then -- 左边观战 MDL.WatchBattle.WatchBattleRequest(cell_Data[1].groomId, MDL.WatchBattle.WatchBattleType.HeroMatch1v1, cell_Data[1].playerId, MDL.HeroMatch1v1.GetCurStageID()) elseif target == cellTable.btn_LeftGuess then -- 左边竞猜 MDL.HeroMatch1v1.HeroMatchBattleBetRequest(self.winnerInfo.stageId, data.groupId, cell_Data[1].acid) elseif target == cellTable.btn_RightWatch then -- 右边观战 MDL.WatchBattle.WatchBattleRequest(cell_Data[2].groomId, MDL.WatchBattle.WatchBattleType.HeroMatch1v1, cell_Data[2].playerId, MDL.HeroMatch1v1.GetCurStageID()) elseif target == cellTable.btn_RightGuess then -- 右边竞猜 MDL.HeroMatch1v1.HeroMatchBattleBetRequest(self.winnerInfo.stageId, data.groupId, cell_Data[2].acid) elseif target == cellTable.group_PlayerLeft.UIHeroHead.img_PlayerAvatarBg then -- 左边玩家 if cell_Data[1].acid ~= BattleDataGetter.GetAcID() then MDL.PlayerInteract.GetPlayerInteractiveInfoReq(cell_Data[1].acid) end elseif target == cellTable.group_PlayerRight.UIHeroHead.img_PlayerAvatarBg then -- 右边玩家 if cell_Data[2].acid ~= BattleDataGetter.GetAcID() then MDL.PlayerInteract.GetPlayerInteractiveInfoReq(cell_Data[2].acid) end end end --endregion ******************** Loop ************************* function UIHeroMatch1v1Stage2:RefreshStage2() self.winnerInfo = MDL.HeroMatch1v1.GetMatchStageInfo(self.StageID) self.myGroupNum = MDL.HeroMatch1v1.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 _, playerInfo in ipairs(v.playerInfos) do if playerInfo.acid == BattleDataGetter.GetAcID() then self.myIndex = k - 1 end end end end function UIHeroMatch1v1Stage2:SetPlayerGroupInfo(groupIndex) 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 UIHeroMatch1v1Stage2:SetNoPlayer(cellTable) cellTable.state_BtnLeft:SetState(3) cellTable.state_BtnRight:SetState(3) cellTable.state_Match:SetState(3) end function UIHeroMatch1v1Stage2:SetWinState(cellTable, cell_Data) cellTable.state_Match:SetState(2) local leftWin = cell_Data[1].winNum or 0 local rightWin = cell_Data[2].winNum or 0 if leftWin > rightWin then cellTable.state_BtnLeft:SetState(2) cellTable.state_BtnRight:SetState(3) UIUtils.SetLabel(cellTable.txt_WinLeftNum, UTL.Color.FormatTextByColor(MDL.HeroMatch1v1.WinColor, leftWin)) UIUtils.SetLabel(cellTable.txt_WinRightNum, UTL.Color.FormatWhiteColor(rightWin)) elseif leftWin < rightWin then 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.HeroMatch1v1.WinColor, rightWin)) else cellTable.state_BtnLeft:SetState(3) cellTable.state_BtnRight:SetState(3) UIUtils.SetLabel(cellTable.txt_WinLeftNum, UTL.Color.FormatWhiteColor(leftWin)) UIUtils.SetLabel(cellTable.txt_WinRightNum, UTL.Color.FormatWhiteColor(rightWin)) end end function UIHeroMatch1v1Stage2: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 UIHeroMatch1v1Stage2