local UIFairSoloTournamentBase = UIViewClass() local EventSystem = require('Event/EventSystem') -- 排序:id local function SortStage(MatchStage_1, MatchStage_2) return MatchStage_1.ID > MatchStage_2.ID end function UIFairSoloTournamentBase:OnOpened(context) UIManager.ActiveUIModle(false, "UIFairSoloTournamentBase") self:RegistSystemEvent(EventID.UI_CloseAndRecoverView, self.OnCloseAndRecoverView) UIUtils.SetLabelText(self.lab_Rule, Const_IDS.IDS_HeroMatch1v1_PromotionCondition) -- 晋级条件 self.txt_Chances.text = nil if MDL.FairSoloTournament.IsShowEntry() then --标题 UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS.IDS_FairTournament_Name) self:RegistSystemEvent(EventID.UI_FairSoloTournament_OnSeasonEnd, self.OnBackButtonPressed) -- 赛程结束关闭界面 self:RegistSystemEvent(EventID.UI_FairSoloTournament_RefreshModuleInfo, self.RefreshBase) -- 刷新界面信息 self:RegistSystemEvent(EventID.UI_FairSoloTournament_RefreshMyInfo, self.RefreshCurStageInfo) self:RegistSystemEvent(EventID.UI_FairSoloTournament_RefreshStageInfo, self.RefreshStageInfo) self:RegistSystemEvent(CTL.RedPoint.RedPointKey.FairSoloTournament_Task, self.RefreshBtnRed) -- stage选中的cell index self.selectIndex = 0 self.btn_Attend:SetGray(true) self:RefreshBtnRed() MDL.FairSoloTournament.FairTournamentOpenReq() MDL.FairSoloTournament.TryFairTournamentGetAllPlayerInfoReq(false) if MDL.FairSoloTournament.IsNo1GeneratedNextDay() then UIUtils.SetActive(self.btn_Watch, false) else UIUtils.SetActive(self.btn_Watch, true) end if context then self.selectStage = context.selectStage end else self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end end function UIFairSoloTournamentBase:RefreshBtnRed() self.btn_Watch:SetRedPoint(CTL.RedPoint.GetRedPointActive(CTL.RedPoint.RedPointKey.FairSoloTournament_Task)) end function UIFairSoloTournamentBase:UpdateAttendBtnStageRepeatFunc(deltaTime, timeSinceUpdate) self.btn_Attend:SetGray(false) end function UIFairSoloTournamentBase:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UIFairSoloTournamentBase:OnButtonClicked(comp) if comp == self.UITemplateTitlePanel.btn_close then self:CloseView(true) CTL.FairSoloTournament.SetLastGroupSelectIndex(nil) elseif comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() elseif comp == self.UITemplateTitlePanel.btn_Info then CTL.FairSoloTournament.OpenNote() elseif comp == self.btn_Shop then -- 奖励预览 UIManager.OpenView(Const_UI_Lua.UIEnum.UIFairSoloTournamentStore) elseif comp == self.btn_Reward then -- 奖励预览 UIManager.OpenView(Const_UI_Lua.UIEnum.UIFairSoloTournamentReward) elseif comp == self.btn_List then -- 参赛名单 UIManager.OpenView(Const_UI_Lua.UIEnum.UIFairSoloTournamentList) elseif comp == self.btn_Guess then -- 话题竞猜 UIManager.OpenView(Const_UI_Lua.UIEnum.UIFairSoloTournamentGuessing) elseif comp == self.btn_Go1V1 then -- 前往1v1 UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UISyncSoloMainPanel) elseif comp == self.btn_Watch then -- 活跃任务 CTL.FairSoloTournament.OpenTask() elseif comp == self.btn_Attend then -- 参加活动 CTL.FairSoloTournament.EnterLobby() elseif comp == self.btn_Course then UIManager.OpenView(Const_UI_Lua.UIEnum.UIFairSoloTournamentCourse) end end function UIFairSoloTournamentBase:OnCellInit(scrollRect, index, cellTable, data) if data.ID <= MDL.FairSoloTournament.ConfigStage.Group_2 then UIUtils.SetLabelText(cellTable.txt_Progress, Const_IDS.IDS_FairTournament_Race1) else UIUtils.SetLabel(cellTable.txt_Progress, string.FormatByIdsId(Const_IDS[data.InterfaceDes])) end if data.ID == self.selectStage then cellTable.state_TabBg:SetState(1) else if data.ID <= MDL.FairSoloTournament.ConfigStage.Group_2 then cellTable.state_TabBg:SetState(self.curStageID >= data.ID and 0 or 2) else if self.curStageID <= MDL.FairSoloTournament.ConfigStage.Group_2 then cellTable.state_TabBg:SetState(2) else cellTable.state_TabBg:SetState(data.ID >= self.curStageID and 0 or 2) end end end end function UIFairSoloTournamentBase:OnCellClicked(scrollRect, index, cellTable, target, data) if target == cellTable.btn_Select then if data.ID ~= self.selectStage then if data.ID <= MDL.FairSoloTournament.ConfigStage.Group_2 then if self.curStageID >= MDL.FairSoloTournament.ConfigStage.Group_2 then self.selectStage = data.ID self.selectIndex = index self:OpenSubView() end else if self.curStageID > MDL.FairSoloTournament.ConfigStage.Group_2 and data.ID >= self.curStageID then self.selectStage = data.ID self.selectIndex = index self:OpenSubView() end end end end end function UIFairSoloTournamentBase:RefreshBase() UIUtils.SetActive(self.btn_Ban, MDL.FairSoloTournament.CheckIfShowBanEntry()) local curStageID = MDL.FairSoloTournament.GetCurStageID() self.curStageID = curStageID if self.selectStage == nil then --防止切阶段跳转界面 self.selectStage = curStageID end self.winnerStageInfo = MDL.FairSoloTournament.GetStageInfo(self.selectStage) self.matchStageList = {} if self.winnerStageInfo then if self.selectStage >= MDL.FairSoloTournament.ConfigStage.Group_1 then for k, v in DataSheetManager.FairMatchStage:GetEnumerator() do if v.ID >= MDL.FairSoloTournament.ConfigStage.Finals_2T1 then table.insert(self.matchStageList, v) end end end if #self.matchStageList > 0 then table.sort(self.matchStageList, SortStage) if MDL.FairSoloTournament.GetStageInfo(MDL.FairSoloTournament.ConfigStage.Group_2) then table.insert(self.matchStageList, 1, DataSheetManager.FairMatchStage:GetDataByID(MDL.FairSoloTournament.ConfigStage.Group_2)) else table.insert(self.matchStageList, 1, DataSheetManager.FairMatchStage:GetDataByID(MDL.FairSoloTournament.ConfigStage.Group_1)) end table.insert(self.matchStageList, DataSheetManager.FairMatchStage:GetDataByID(MDL.FairSoloTournament.ConfigStage.Display)) end self:OpenSubView() end end function UIFairSoloTournamentBase:RefreshStageInfo() if self.isWaitingStageInfo then self.isWaitingStageInfo = false self:OpenSubView() end end function UIFairSoloTournamentBase:TryOpenSubView(viewName, context) if self.subView:IsViewOpened(viewName) then --子界面会监听变化,无需重开界面 return end self.subView:CloseAll() self.subView:OpenView(GetViewClass(viewName), context) local watchAcid = CTL.FairSoloTournament.GetWatchingBattleAcid() if watchAcid then EventSystem.Dispatch(EventID.UI_FairSoloTournament_JumpToPlayer, watchAcid) CTL.FairSoloTournament.ClearWatchingBattleParam() end end function UIFairSoloTournamentBase:OpenSubView() local stageInfo = MDL.FairSoloTournament.GetStageInfo(self.selectStage) if stageInfo == nil then self.isWaitingStageInfo = true MDL.FairSoloTournament.FairTournamentGetStageInfoReq(self.selectStage) return end UIUtils.SetActive(self.btn_Guess, true) UIUtils.SetActive(self.btn_Go1V1, false) UIUtils.SetActive(self.btn_Attend, true) UIUtils.SetActive(self.group_Progress, true) UIUtils.SetActive(self.img_BgBottom, false) UIUtils.SetActive(self.img_Bottom, true) self.curMatchTimeID = MDL.FairSoloTournament.GetCurMatchTimeID() self.winnerStageInfo = MDL.FairSoloTournament.GetStageInfo(self.selectStage) if MDL.FairSoloTournament.IsNo1Generated() then UIUtils.SetActive(self.group_Info, false) else UIUtils.SetActive(self.group_Info, true) end local MatchTime = DataSheetManager.FairMatchTime:GetDataByID(self.curMatchTimeID) self:StopRepeatFunc(self.UpdateAttendBtnStageRepeatFunc) if self.curMatchTimeID < MDL.FairSoloTournament.Enum_BigStage.FairDisplay then if self.winnerStageInfo.state == MDL.FairSoloTournament.Enum_State.Finish then self.btn_Attend:SetGray(true, false) else if UTL.Time.IsServerInOpeningTime(MatchTime.StartTime, MatchTime.EndTime) then self.btn_Attend:SetGray(false) else self.btn_Attend:SetGray(true, false) local offsetTime = UTL.Time.GetServerIntervalTimeByTimeId(MatchTime.StartTime) self:StartRepeatFunc(self.UpdateAttendBtnStageRepeatFunc, offsetTime > 0 and offsetTime or offsetTime + UTL.Time.TotalSecondsOneDay) end end else self.btn_Attend:SetGray(true, false) end UIUtils.SetActive(self.btn_Attend, not (BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.CrossFairSoloTournamentTown) or BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SingleFairSoloTournamentTown)) ) if self.selectStage <= MDL.FairSoloTournament.ConfigStage.Group_2 then -- 小组赛 UIUtils.SetActive(self.img_BgBottom, true) UIUtils.SetActive(self.group_Progress, false) self:TryOpenSubView(Const_UI_Lua.UIEnum.UIFairSoloTournamentStage1_GroupCompetition) else if self.selectStage == MDL.FairSoloTournament.ConfigStage.Display then -- 冠军展示期 UIUtils.SetActive(self.img_Bottom, false) UIUtils.SetActive(self.btn_Go1V1, true) UIUtils.SetActive(self.btn_Attend, false) UIUtils.SetActive(self.group_Info, false) self:TryOpenSubView(Const_UI_Lua.UIEnum.UIFairSoloTournamentStage6_Supremacy) elseif self.selectStage == MDL.FairSoloTournament.ConfigStage.Finals_2T1 then -- 冠军赛 UIUtils.SetActive(self.img_BgBottom, true) self:TryOpenSubView(Const_UI_Lua.UIEnum.UIFairSoloTournamentStage5) elseif self.selectStage == MDL.FairSoloTournament.ConfigStage.Finals_4T2 then -- 4进2 self:TryOpenSubView(Const_UI_Lua.UIEnum.UIFairSoloTournamentStage4) elseif self.selectStage == MDL.FairSoloTournament.ConfigStage.Finals_8T4 then -- 8进4 self:TryOpenSubView(Const_UI_Lua.UIEnum.UIFairSoloTournamentStage3) elseif self.selectStage >= MDL.FairSoloTournament.ConfigStage.Finals_16T8 then -- 16进8 以及大于16人的比赛都用同一个子界面 if self.selectStage ~= CTL.FairSoloTournament.GetCurStage2PanelStage() then self.subView:CloseAll() self:TryOpenSubView(Const_UI_Lua.UIEnum.UIFairSoloTournamentStage2, { stageID = self.selectStage }) end end end self.cdTimer:EndTimer() if self.selectStage == MDL.FairSoloTournament.ConfigStage.Display then UIUtils.SetActive(self.tips_Attend, false) else local stageInfo = MDL.FairSoloTournament.GetStageInfo(MDL.FairSoloTournament.GetCurStageID()) local isShowTipsAttend = (BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.CrossFairSoloTournamentTown) or BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SingleFairSoloTournamentTown))and stageInfo.state ~= MDL.FairSoloTournament.Enum_State.Finish UIUtils.SetActive(self.tips_Attend, isShowTipsAttend) if isShowTipsAttend then local startTimestamp = stageInfo.stateEndTime local leftTime = math.max(startTimestamp - UTL.Time.GetServerTimestamp(), 0) if stageInfo.state == MDL.FairSoloTournament.Enum_State.Roll or stageInfo.state == MDL.FairSoloTournament.Enum_State.BanPick or stageInfo.state == MDL.FairSoloTournament.Enum_State.Battle then --战斗时长 = 掷骰子 + bp + 战斗 local matchTimeCfg = DataSheetManager.FairMatchTime:GetDataByID(MDL.FairSoloTournament.GetCurMatchTimeID()) if stageInfo.state == MDL.FairSoloTournament.Enum_State.Roll then leftTime = leftTime + matchTimeCfg.BanHeroTime + matchTimeCfg.ChooseHeroTime + matchTimeCfg.ChangeHeroPlace + matchTimeCfg.WaitBattle + matchTimeCfg.BattleTime elseif stageInfo.state == MDL.FairSoloTournament.Enum_State.BanPick then leftTime = leftTime + matchTimeCfg.BattleTime end self.cdTimer:ResetAndBeginCustomTimer(false, leftTime, 0, string.FormatByIdsId(Const_IDS.IDS_HeroMatch1v1_SkipBattleTime).."\n{0}:{1}:{2}") else self.cdTimer:ResetAndBeginCustomTimer(false, leftTime, 0, string.FormatByIdsId(Const_IDS.IDS_HeroMatch1v1_MatchingTime).."\n{0}:{1}:{2}") end end end if #self.matchStageList > 0 then for k, v in ipairs(self.matchStageList) do if v.ID == self.selectStage then self.selectIndex = k - 1 break end end self.loop_Progress:ReloadAll(self.matchStageList) end if self.selectStage ~= MDL.FairSoloTournament.ConfigStage.Display then self:RefreshCurStageInfo() end end function UIFairSoloTournamentBase:RefreshCurStageInfo() self.myInfo = MDL.FairSoloTournament.GetMyInfo() if self.myInfo == nil then return end self.matchStageCfg = DataSheetManager.FairMatchStage:GetDataByID(self.curStageID) self.matchTimeCfg = DataSheetManager.FairMatchTime:GetDataByID(self.matchStageCfg.NowStage) self:SetTimer() --第一行:剩余场次/当前成绩 if self.curStageID > MDL.FairSoloTournament.ConfigStage.Group_2 then if MDL.FairSoloTournament.CheckIfInCompetition() then UIUtils.SetLabelText(self.lab_PersonalScore, Const_IDS.IDS_HeroMatch1v1_NowResult) -- 当前成绩 self.txt_PersonalScore.text = CTL.FairSoloTournament.GetMyRankDesc() else self.lab_PersonalScore.text = nil self.txt_PersonalScore.text = nil end else UIUtils.SetLabelText(self.lab_PersonalScore, Const_IDS.IDS_HeroMatch1v1_Condition) local left, max = MDL.FairSoloTournament.GetCurGroupTimes() self.txt_PersonalScore.text = left .. "/" .. max end --第二行:晋级条件 if self.curStageID <= MDL.FairSoloTournament.ConfigStage.Group_2 then -- 小组赛 local _, count = CTL.FairSoloTournament.GetGroupPlayerCount() self.txt_Rule.text = string.FormatByIdsId(Const_IDS.IDS_FairTournament_UpCondition, count) elseif self.curStageID >= MDL.FairSoloTournament.ConfigStage.Finals_2T1 then UIUtils.SetLabelText(self.txt_Rule, Const_IDS.IDS_FairTournament_UpCondition2) end --第三行:竞猜次数 local maxGuessTimes = MDL.FairSoloTournament.GetTodayGuessingMaxTimes() UIUtils.SetLabel(self.lab_Chances, string.FormatByIdsId(Const_IDS.IDS_HeroMatch1v1_LeftPickNum, maxGuessTimes - self.myInfo.battleBetNum, maxGuessTimes)) end function UIFairSoloTournamentBase:SetTimer() UIUtils.SetLabelText(self.lab_Time, Const_IDS.IDS_HeroMatch1v1_ActivityTime) if self.matchTimeCfg.StartTime > 0 then UIUtils.SetActive(self.group_Time, true) local starTime = UTL.Time.GetDiffLocalStrById(self.matchTimeCfg.StartTime) if self.curStageID >= MDL.FairSoloTournament.ConfigStage.Finals_2T1 and self.curStageID <= MDL.FairSoloTournament.ConfigStage.Finals_128T64 then local curStageInfo = MDL.FairSoloTournament.GetStageInfo(self.curStageID) local target = curStageInfo.stateEndTime - UTL.Time.GetDisplayDiffLocalTimeZone(); local startTimeSeconds = DataSheetManager.TimeRefresh:GetDataByID(self.matchTimeCfg.StartTime).HMS + UTL.Time.GetDisplayDiffLocalTimeZone() if startTimeSeconds < 0 then target = target - UTL.Time.TotalSecondsOneDay elseif startTimeSeconds - UTL.Time.TotalSecondsOneDay >= 0 then target = target + UTL.Time.TotalSecondsOneDay end local startDay = UTL.Time.OsDateOriginal("%d", target) local month = tonumber(UTL.Time.OsDateOriginal("%m", target)) UIUtils.SetLabel(self.txt_Time, string.FormatByIdsId(Const_IDS.IDS_FairTournament_PreOpenTime2, month, startDay, starTime)) else local moduleInfo = MDL.FairSoloTournament.GetModuleInfo() local dayNum = 0 for k, v in DataSheetManager.FairMatchTime:GetEnumerator() do dayNum = dayNum + v.Day if v.ID + 1 == self.curMatchTimeID then if self.curStageID == MDL.FairSoloTournament.ConfigStage.Group_2 then dayNum = dayNum + 1 end --因为只使用 target 计算天数,所以不要让 target 受 os.date 影响导致跨天,补时区偏移量。 local target = moduleInfo.startTm + dayNum * UTL.Time.TotalSecondsOneDay - UTL.Time.GetDisplayDiffLocalTimeZone(); --用后面的小时偏移量计算是否需要跨天 local startTimeSeconds = DataSheetManager.TimeRefresh:GetDataByID(self.matchTimeCfg.StartTime).HMS + UTL.Time.GetDisplayDiffLocalTimeZone() if startTimeSeconds < 0 then target = target - UTL.Time.TotalSecondsOneDay elseif startTimeSeconds - UTL.Time.TotalSecondsOneDay >= 0 then target = target + UTL.Time.TotalSecondsOneDay end local startDay = UTL.Time.OsDateOriginal("%d", target) local month = tonumber(UTL.Time.OsDateOriginal("%m", target)) UIUtils.SetLabel(self.txt_Time, string.FormatByIdsId(Const_IDS.IDS_FairTournament_PreOpenTime2, month, startDay, starTime)) break end end end else UIUtils.SetActive(self.group_Time, false) end --倒计时 local timeOffset = CTL.FairSoloTournament.GetGroupFinalDayStartTime() if self.curStageID <= MDL.FairSoloTournament.ConfigStage.Group_2 and timeOffset > 0 then self.txt_GuessTime:ResetAndBeginCustomTimer(false, timeOffset, 0, UIUtils.GetLocalizedTxt(Const_IDS.IDS_FairTournament_PickEndTime1), 1) else self.txt_GuessTime:EndTimer() end end function UIFairSoloTournamentBase:OnClosed() UIManager.ActiveUIModle(true, "UIFairSoloTournamentBase") end return UIFairSoloTournamentBase