--我的战绩界面 local UIFairPlayHistoryMain = UIViewClass() local leftTabEnum = { Solo = 1,--1V1 Boss = 2,--boss挑战 TVT = 3,--3V3 } local rightTabEnum = { Battle = 1,--战斗记录 Season = 2,--赛季信息 } --region 生命周期方法 function UIFairPlayHistoryMain:OnOpened(context) UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS.IDS_FairPlay_History_Title) UTL.Toggle.InitToggleGroupByIDS(self.group_LeftBtn.toggles_Group, "txt",{Const_IDS.IDS_1v1Sync_Title, Const_IDS.IDS_ActivityName_BossChallenge,Const_IDS.IDS_ActivityName_3V3BattleGround}) --是否默认选中某个页签 if context and context.selectType then local tempSelect = self:GetLeftTabTypeByType(context.selectType) if tempSelect then self.group_LeftBtn.toggles_Group:SelectIndex(tempSelect - 1) else self.group_LeftBtn.toggles_Group:SelectIndex(leftTabEnum.Solo - 1) end else self.group_LeftBtn.toggles_Group:SelectIndex(leftTabEnum.Solo - 1) end self:RegistSystemEvent(EventID.UI_FairPlayHistory_ShowBattle,self.ShowBattleRecords) self:RegistSystemEvent(EventID.UI_FairPlayHistory_ShowSeason,self.ShowSeasonInfo) self:RegistSystemEvent(EventID.UI_FairPlayHistory_SetCurrentSeasonIndex,self.SetCurrentSeasonIndex) self:RegistSystemEvent(EventID.UI_FairPlayHistory_RefreshBattleInfo,self.RefreshBattleInfo) self.seasonIndex = 1 self.isOnlyShowLiked = false --是否只显示收藏战绩 self:RefreshLikedButton() self.isFromMainPanel = context and context.isFromMainPanel end function UIFairPlayHistoryMain:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UIFairPlayHistoryMain:OnClosed() --关闭界面时清空缓存数据 MDL.Replay.ClearCacheData() end function UIFairPlayHistoryMain:OnValueChanged(comp, index) if comp == self.group_LeftBtn.toggles_Group then self:SwitchLeftTab(index) elseif comp == self.toggle_TopGroup then self:SwitchRightTab(index) end end function UIFairPlayHistoryMain:OnButtonClicked(comp) if comp == self.UITemplateTitlePanel.btn_close then if self.isFromMainPanel then self:CloseView() else self:CloseView(true) end elseif comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() elseif comp == self.UITemplateTitlePanel.btn_Info then UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, {id = LuaConst.NoteID.FairPlayHistoryMain}) elseif comp == self.group_Competition.group_11and33.btn_Before then --1V1 or 3V3 切换赛季信息 local seasonInfo = MDL.Replay.GetSeasonInfoByType(self:GetType()) if self.seasonIndex == #seasonInfo then UIUtils.SetActive(self.group_Competition.group_11and33.btn_Next, true) end if self.seasonIndex > 1 then self.seasonIndex = self.seasonIndex - 1 else self.seasonIndex = 1 end if self.seasonIndex == 1 then UIUtils.SetActive(self.group_Competition.group_11and33.btn_Before, false) end self:ShowSeasonInfo(self:GetType()) elseif comp == self.group_Competition.group_11and33.btn_Next then --1V1 or 3V3 切换赛季信息 local seasonInfo = MDL.Replay.GetSeasonInfoByType(self:GetType()) if self.seasonIndex == 1 then UIUtils.SetActive(self.group_Competition.group_11and33.btn_Before, true) end if self.seasonIndex < #seasonInfo then self.seasonIndex = self.seasonIndex + 1 else self.seasonIndex = #seasonInfo end if self.seasonIndex == #seasonInfo then UIUtils.SetActive(self.group_Competition.group_11and33.btn_Next, false) end self:ShowSeasonInfo(self:GetType()) elseif comp == self.group_Competition.group_11and33.btn_Info then --1V1 or 3V3 查看所有武将赛季信息 local seasonInfo = MDL.Replay.GetSeasonInfoByType(self:GetType()) local info = seasonInfo[self.seasonIndex] CTL.Replay.OnMyHistoryPopUpPanel(info.seasonId,self:GetType(),info.lists) elseif comp == self.btn_Love then --是否打开筛选可收藏的战绩 self.isOnlyShowLiked = not self.isOnlyShowLiked self:RefreshLikedButton() --显示战绩 local type = self:GetType() self:ShowBattleRecords(type) end end function UIFairPlayHistoryMain:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_Score then --战绩信息 if self.currentLeftTabType == leftTabEnum.Solo then --1V1 self:Show1V1BattleInfo(cellTable,data, index) elseif self.currentLeftTabType == leftTabEnum.Boss then --无双挑战 self:ShowBossBattleInfo(cellTable,data, index) else --3V3 self:Show1V1BattleInfo(cellTable,data, index) --击败 UIUtils.SetLabel(cellTable.txt_Num01,tostring(data.killNum)) --被击败 UIUtils.SetLabel(cellTable.txt_Num02,tostring(data.beKillNum)) --mvp local isMvp, isWin = CTL.Replay.Is3V3battleMVP(data.gRoomId) UIUtils.SetActive(cellTable.img_mvp, isMvp) if isWin then UIUtils.SetLocalizationImage(cellTable.img_mvp, "UI_PVP/3v3_msz_wfzs.png") else UIUtils.SetLocalizationImage(cellTable.img_mvp, "UI_PVP/3v3_msz_dfzs.png") end end elseif scrollRect == self.group_Competition.group_11and33.loop_HeroData then --1V1 or 3v3 武将胜率信息 --武将头像\名字 local gameCount = data.gameCount local winCount = data.winCount local isAwaken = false if data.awakenGameCount > 0 then gameCount = data.awakenGameCount winCount = data.awakenWinCount isAwaken = true end UTL.Item.SetHeroIconByHeroId(cellTable.img_Hero, data.heroId, isAwaken) local heroNum = DataSheetManager.HeroNum:GetDataByID(data.heroId) if heroNum then UIUtils.SetLabelText(cellTable.txt_Name,Const_IDS[heroNum.NameIDS]) end --总场次 UIUtils.SetLabel(cellTable.txt_Total,tostring(gameCount)) --胜利场次 UIUtils.SetLabel(cellTable.txt_Win,tostring(winCount)) --胜率 UIUtils.SetLabel(cellTable.txt_Rate, CTL.Replay.GetWinRateShow(winCount, gameCount)) UIUtils.SetActive(cellTable.img_BG02,index % 2 == 1) elseif scrollRect == self.group_Competition.group_Boss.loop_Boss then --无双挑战 赛季信息 --赛季 UIUtils.SetLabel(cellTable.txt_Season,tostring(data.seasonId)) --首领 local bossLevelData = DataSheetManager.BossChallengeData:GetDataByID(data.bossId) if bossLevelData then UIUtils.SetLabel(cellTable.txt_Boss,UIUtils.GetLocalizedTxt(Const_IDS[bossLevelData.BossChallengeName])) else UIUtils.SetLabel(cellTable.txt_Boss,"") end --总分 UIUtils.SetLabel(cellTable.txt_Score,tostring(data.EloScore)) --排名 UIUtils.SetLabel(cellTable.txt_Rank,tostring(data.rank)) --挑战总次数 UIUtils.SetLabel(cellTable.txt_Total,tostring(data.gameCount)) UIUtils.SetActive(cellTable.img_BG02,index % 2 == 1) end end function UIFairPlayHistoryMain:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loop_Score then --战绩信息 if target == cellTable.event_History and (self.currentLeftTabType == leftTabEnum.Solo or self.currentLeftTabType == leftTabEnum.TVT) then --详情 (1V1 or 3v3 才有详情) local typ = self:GetType() MDL.Replay.ShowHistory(data.gRoomId,typ) elseif target == cellTable.event_Replay then --回放 UTL.MessageBox.ShowOKCancelBox(nil, Const_IDS.IDS_FairPlayReplay_ConfirmWatchTips, function() local typ = self:GetType() CTL.Replay.SetMyPlayerIDOfMyRecords(data.selfPlayerId) MDL.Replay.FairPlayMyRecordReplayReq(data.gRoomId, typ) end) elseif target == cellTable.event_Save then --收藏 --未收藏时,点击可收藏 local isSaved = not string.isNilOrEmpty(data.url) or MDL.Replay.IsLike(data.gRoomId) if not isSaved then local typ = self:GetType() MDL.Replay.FairPlayMyRecordLikeReq(data.gRoomId,typ) end end end end --endregion --1V1 or 3V3 or boss function UIFairPlayHistoryMain:SwitchLeftTab(index) self.currentLeftTabType = index + 1 self.currentRightTabType = rightTabEnum.Battle --检测是否有缓存数据,有的话,不再请求 local type = self:GetType() local recordsData = MDL.Replay.GetAllRecordsByType(type) if recordsData == nil then MDL.Replay.FairPlayMyRecordPanelReq(self:GetType()) else self:ShowBattleRecords(type) end self.toggle_TopGroup:SelectIndex(rightTabEnum.Battle - 1) end function UIFairPlayHistoryMain:GetLeftTabTypeByType(type) if type ~= nil then if type == MDL.Replay.FairPlayType.Solo then return leftTabEnum.Solo elseif type == MDL.Replay.FairPlayType.Boss then return leftTabEnum.Boss else return leftTabEnum.TVT end end return nil end --显示战斗记录 function UIFairPlayHistoryMain:ShowBattleRecords(type) self:ShowLikedUI(true) UIUtils.SetActive(self.group_Score,true) UIUtils.SetActive(self.group_Competition.gameObject,false) self.currentRightTabType = rightTabEnum.Battle local tempLeftTabType = self:GetLeftTabTypeByType(type) if tempLeftTabType then self.currentLeftTabType = tempLeftTabType end self.loop_Score:ClearCells() local isHasRecords = false if self.currentLeftTabType == leftTabEnum.Solo then --1V1 local records = MDL.Replay.GetAllRecordsByType(MDL.Replay.FairPlayType.Solo) if records and #records > 0 then local count = #records for i = count, 1, -1 do local v = records[i] local isSaved = not string.isNilOrEmpty(v.url) or MDL.Replay.IsLike(v.gRoomId) if self.isOnlyShowLiked then if isSaved then isHasRecords = true self.loop_Score:AddData(v,0) end else isHasRecords = true self.loop_Score:AddData(v,0) end end end UIUtils.SetActive(self.group_Title.group_1v1.gameObject,true) UIUtils.SetActive(self.group_Title.group_3v3.gameObject,false) UIUtils.SetActive(self.group_Title.group_Boss.gameObject,false) elseif self.currentLeftTabType == leftTabEnum.Boss then --无双挑战 local records = MDL.Replay.GetAllRecordsByType(MDL.Replay.FairPlayType.Boss) if records and #records > 0 then local count = #records for i = count, 1, -1 do local v = records[i] local isSaved = not string.isNilOrEmpty(v.url) or MDL.Replay.IsLike(v.gRoomId) if self.isOnlyShowLiked then if isSaved then isHasRecords = true self.loop_Score:AddData(v,2) end else isHasRecords = true self.loop_Score:AddData(v,2) end end end UIUtils.SetActive(self.group_Title.group_1v1.gameObject,false) UIUtils.SetActive(self.group_Title.group_3v3.gameObject,false) UIUtils.SetActive(self.group_Title.group_Boss.gameObject,true) else --3V3 local records = MDL.Replay.GetAllRecordsByType(MDL.Replay.FairPlayType.TVT) if records and #records > 0 then local count = #records for i = count, 1, -1 do local v = records[i] local isSaved = not string.isNilOrEmpty(v.url) or MDL.Replay.IsLike(v.gRoomId) if self.isOnlyShowLiked then if isSaved then isHasRecords = true self.loop_Score:AddData(v,1) end else isHasRecords = true self.loop_Score:AddData(v,1) end end end UIUtils.SetActive(self.group_Title.group_1v1.gameObject,false) UIUtils.SetActive(self.group_Title.group_3v3.gameObject,true) UIUtils.SetActive(self.group_Title.group_Boss.gameObject,false) end --无记录提示 if self.isOnlyShowLiked then UIUtils.SetActive(self.group_RecordsEmpty,not isHasRecords) if not isHasRecords then UIUtils.SetLabelText(self.lab_RecordsEmpty,Const_IDS.IDS_FairPlay_FightRecord_Nosave) end else if not isHasRecords then UIUtils.SetActive(self.group_RecordsEmpty,true) UIUtils.SetLabelText(self.lab_RecordsEmpty,Const_IDS.IDS_FairPlay_NoRecord_Season) else UIUtils.SetActive(self.group_RecordsEmpty,false) end end end --显示赛季信息 function UIFairPlayHistoryMain:ShowSeasonInfo(type) self:ShowLikedUI(false) UIUtils.SetActive(self.group_RecordsEmpty,false) UIUtils.SetActive(self.group_Score,false) UIUtils.SetActive(self.group_Competition.gameObject,true) self.currentRightTabType = rightTabEnum.Season if type ~= nil then if type == MDL.Replay.FairPlayType.Solo then self.currentLeftTabType = leftTabEnum.Solo elseif type == MDL.Replay.FairPlayType.Boss then self.currentLeftTabType = leftTabEnum.Boss else self.currentLeftTabType = leftTabEnum.TVT end end local seasonInfo = MDL.Replay.GetSeasonInfoByType(type) if self.currentLeftTabType == leftTabEnum.Solo or self.currentLeftTabType == leftTabEnum.TVT then --1V1 or 3V3 UIUtils.SetActive(self.group_Competition.group_11and33.gameObject,true) UIUtils.SetActive(self.group_Competition.group_Boss.gameObject,false) local group = self.group_Competition.group_11and33 if seasonInfo then local info = seasonInfo[self.seasonIndex] self:ShowSingleSeasonInfo(group,info) end UIUtils.SetActive(self.group_Competition.group_11and33.btn_Next, self.seasonIndex ~= #seasonInfo) UIUtils.SetActive(self.group_Competition.group_11and33.btn_Before, self.seasonIndex ~= 1) elseif self.currentLeftTabType == leftTabEnum.Boss then --boss UIUtils.SetActive(self.group_Competition.group_11and33.gameObject,false) UIUtils.SetActive(self.group_Competition.group_Boss.gameObject,true) local loop_Boss = self.group_Competition.group_Boss.loop_Boss if seasonInfo then loop_Boss:ReloadAll(seasonInfo) end end end function UIFairPlayHistoryMain:ShowSingleSeasonInfo(group,info) --是否为当前赛季 UIUtils.SetLabel(group.txt_Season,string.FormatByIdsId(Const_IDS.IDS_FairPlay_SeasonRecord_SeasonNum,tostring(info.seasonId))) local typ = self:GetType() local isCurrentSeason = CTL.Replay.IsCurrentSeason(typ,info.seasonId) UIUtils.SetActive(group.group_Now,isCurrentSeason) if isCurrentSeason then UIUtils.SetLabelText(group.txt_Now,Const_IDS.IDS_FairPlay_SeasonRecord_ThisSeason) end --总场次 UIUtils.SetLabel(group.txt_TotalNum,tostring(info.gameCount)) --胜利场次 UIUtils.SetLabel(group.txt_WinNum,tostring(info.winCount)) --胜率 UIUtils.SetLabel(group.txt_RateNum,CTL.Replay.GetWinRateShow(info.winCount,info.gameCount)) --最高连胜 UIUtils.SetLabel(group.txt_ComboNum,tostring(info.continuousWinTimes)) if self.currentLeftTabType == leftTabEnum.Solo then --1V1 --mvp场次 UIUtils.SetActive(group.lab_MVP,false) elseif self.currentLeftTabType == leftTabEnum.TVT then --3V3 --mvp场次 UIUtils.SetActive(group.lab_MVP,true) UIUtils.SetLabel(group.txt_MVPNum,tostring(info.mvpNum)) end --段位图 local rankData = DataSheetManager.SyncSoloData:GetDataByLevelID(info.dan) if rankData then group.effect_Rank:PlayUIEffect(rankData.LevelResidentEffect, 0) --段位 UIUtils.SetLabelText(group.txt_Level, Const_IDS[rankData.LevelName]) else group.effect_Rank:StopUIEffect() UIUtils.SetLabel(group.txt_Level, "") end --积分 if info.EloScore > 0 then UIUtils.SetLabel(group.txt_LevelScore,tostring(info.EloScore)) else UIUtils.SetLabel(group.txt_LevelScore,"") end --武将胜率信息 self:ShowHeroWinList(group,info.lists) end --武将胜率信息 function UIFairPlayHistoryMain:ShowHeroWinList(group,lists) local showHeroListCount = 5 group.loop_HeroData:ClearCells() for i,v in ipairs(lists) do if i <= showHeroListCount then group.loop_HeroData:AddData(v,0) end end UIUtils.SetActive(self.group_Competition.group_11and33.group_SeasonEmpty,#lists == 0) UIUtils.SetActive(self.group_Competition.group_11and33.group_HeroData,#lists > 0) end function UIFairPlayHistoryMain:ShowBattleOrSeason() if self.currentRightTabType == rightTabEnum.Battle then --战绩 self:ShowBattleRecords() else --赛季信息 --请求赛季信息 local typ = self:GetType() local seasonInfo = MDL.Replay.GetSeasonInfoByType(typ) if seasonInfo == nil then self.seasonIndex = 1 MDL.Replay.FairPlayMyRecordSeasonPanelReq(typ) else self:SetCurrentSeasonIndex(self:GetType()) self:ShowSeasonInfo(typ) end end end function UIFairPlayHistoryMain:SetCurrentSeasonIndex(type) self.seasonIndex = CTL.Replay.GetCurrentSeasonIndex(type) end function UIFairPlayHistoryMain:GetType() local typ if self.currentLeftTabType == leftTabEnum.Solo then typ = MDL.Replay.FairPlayType.Solo elseif self.currentLeftTabType == leftTabEnum.Boss then typ = MDL.Replay.FairPlayType.Boss else typ = MDL.Replay.FairPlayType.TVT end return typ end --战斗记录 或是赛季信息 function UIFairPlayHistoryMain:SwitchRightTab(index) self.currentRightTabType = index + 1 self:ShowBattleOrSeason() end function UIFairPlayHistoryMain:HandlePortrait(index, comp1, comp2, data) local heroId = data.heroId[2 * index - 1] local isHeroAwaken = data.heroAwakens[2 * index - 1] if isHeroAwaken then CTL.Character.SetPortraitAndFrame(comp1, CTL.HeroAwaken.GetAwakenPortraitId(heroId)) else local portraitData1 = MDL.Character.GetFullPortraitDataByHeroID(heroId) if portraitData1 then CTL.Character.SetPortraitAndFrame(comp1, portraitData1.ID) end end local heroId2 = data.heroId[2 * index] local isHeroAwaken2 = data.heroAwakens[2 * index] if isHeroAwaken2 then CTL.Character.SetPortraitAndFrame(comp2, CTL.HeroAwaken.GetAwakenPortraitId(heroId2)) else local portraitData2 = MDL.Character.GetFullPortraitDataByHeroID(heroId2) if portraitData2 then CTL.Character.SetPortraitAndFrame(comp2, portraitData2.ID) end end end --无双挑战 战绩信息 function UIFairPlayHistoryMain:ShowBossBattleInfo(cellTable,data, index) --时间 UIUtils.SetLabel(cellTable.lab_Time02, os.date(UTL.Time.FormatDateEnum.MDHM, data.time)) --首领 local bossLevelData = DataSheetManager.BossChallengeLevel:GetDataByID(data.bossId) UIUtils.SetLabel(cellTable.txt_Boss,UIUtils.GetLocalizedTxt(Const_IDS[bossLevelData.BossName])) --积分 UIUtils.SetLabel(cellTable.txt_Score,tostring(data.EloScore)) --阵容 for i = 1, #cellTable.group_Formation do self:HandlePortrait(i, cellTable.group_Formation[i].group_Member01, cellTable.group_Formation[i].group_Member001, data) UIUtils.SetActive(cellTable.group_Formation[i].effect_Seclected, false) end --是否收藏 local isSaved = not string.isNilOrEmpty(data.url) or MDL.Replay.IsLike(data.gRoomId) if isSaved then cellTable.state_Save:SetState(1) else cellTable.state_Save:SetState(0) end UIUtils.SetActive(cellTable.img_BG02,index % 2 == 1) end --1V1战绩信息 function UIFairPlayHistoryMain:Show1V1BattleInfo(cellTable,data, index) --结果 if data.isWin then --胜利 UIUtils.SetLabel(cellTable.lab_Result, UTL.Color.FormatTextByColor(UTL.Color.Green, UIUtils.GetLocalizedTxt(Const_IDS.IDS_FairPlay_FightRecord_Result_Win))) else --失败 UIUtils.SetLabel(cellTable.lab_Result, UTL.Color.FormatTextByColor(UTL.Color.Red, UIUtils.GetLocalizedTxt(Const_IDS.IDS_FairPlay_FightRecord_Result_Lose))) end if data.fightTyp == MDL.Replay.FairPlayFightType.fight then --切磋 UIUtils.SetLabelText(cellTable.lab_Time,Const_IDS.IDS_FairPlay_FightRecord_Type_RoomMatch) UIUtils.SetActive(cellTable.lab_Result02,false) else --排位赛 UIUtils.SetLabelText(cellTable.lab_Time,Const_IDS.IDS_FairPlay_FightRecord_Type_RankMatch) local content = "" if data.isWin then --胜利 UIUtils.SetLabel(cellTable.lab_Result, UTL.Color.FormatTextByColor(UTL.Color.Green, UIUtils.GetLocalizedTxt(Const_IDS.IDS_FairPlay_FightRecord_Result_Win))) content = string.format("%s(%s)",data.EloScore,UTL.Color.FormatTextByColor(UTL.Color.Green,"↑"..tostring(math.abs(data.diffValue)))) else --失败 UIUtils.SetLabel(cellTable.lab_Result, UTL.Color.FormatTextByColor(UTL.Color.Red, UIUtils.GetLocalizedTxt(Const_IDS.IDS_FairPlay_FightRecord_Result_Lose))) content = string.format("%s(%s)",data.EloScore,UTL.Color.FormatTextByColor(UTL.Color.Red,"↓"..tostring(math.abs(data.diffValue)))) end UIUtils.SetActive(cellTable.lab_Result02,true) UIUtils.SetLabel(cellTable.lab_Result02,content) end if data.isNegativeFight then UIUtils.SetLabel(cellTable.lab_Result, UTL.Color.FormatTextByColor(UTL.Color.Red, UIUtils.GetLocalizedTxt(Const_IDS.IDS_PunishForAFK_NoticeTips3))) end --时间 UIUtils.SetLabel(cellTable.lab_Time02, os.date(UTL.Time.FormatDateEnum.MDHM, data.time)) --阵容 for i = 1, #cellTable.group_Formation do self:HandlePortrait(i, cellTable.group_Formation[i].group_Member01, cellTable.group_Formation[i].group_Member001, data) UIUtils.SetActive(cellTable.group_Formation[i].effect_Seclected, false) end --是否收藏 local isSaved = not string.isNilOrEmpty(data.url) or MDL.Replay.IsLike(data.gRoomId) if isSaved then cellTable.state_Save:SetState(1) else cellTable.state_Save:SetState(0) end --显示背景条 UIUtils.SetActive(cellTable.img_BG02,index % 2 == 1) end --刷新战绩信息 function UIFairPlayHistoryMain:RefreshBattleInfo() self.loop_Score:RefreshCells(false) end --刷新显示收藏按钮 function UIFairPlayHistoryMain:RefreshLikedButton() UIUtils.SetActive(self.BGM_Open,self.isOnlyShowLiked) UIUtils.SetActive(self.BGM_Close,not self.isOnlyShowLiked) end --判断是否显示收藏UI function UIFairPlayHistoryMain:ShowLikedUI(isShow) UIUtils.SetActive(self.group_Love.gameObject,isShow) end return UIFairPlayHistoryMain