--武将赛季信息界面 local UIReplayHistoryPopUp = UIViewClass() local IconPath = ConstAssetPathConfig.IconPath2 local EventSystem = require('Event/EventSystem') --不同职业图标 local selectProfessionIcon = { [1] = "zr_icon_po02.png", [2] = "zr_icon_tan02.png", [3] = "zr_icon_zhi02.png", [4] = "zr_icon_she02.png", [5] = "zr_icon_fu02.png", [6] = "zr_icon_meng02.png", } --不同职业图标 local unSelectProfessionIcon = { [1] = "zr_msz_ci.png", [2] = "zr_msz_tan.png", [3] = "zr_msz_fa.png", [4] = "zr_msz_she.png", [5] = "zr_msz_fu.png", [6] = "zr_msz_zhan.png", } local myRecordData = { } function UIReplayHistoryPopUp:OnOpened(context) UIUtils.SetLabelText(self.UICommonPopUpTab.txt_Title, Const_IDS["IDS_FairPlay_SeasonRecord_HeroInfo"]) --是否为当前赛季 UIUtils.SetLabel(self.txt_Season,string.FormatByIdsId(Const_IDS.IDS_FairPlay_SeasonRecord_SeasonNum,tostring(context.seasonId))) local isCurrentSeason = CTL.Replay.IsCurrentSeason(context.typ,context.seasonId) UIUtils.SetActive(self.group_Now,isCurrentSeason) if isCurrentSeason then UIUtils.SetLabelText(self.txt_Now,Const_IDS.IDS_FairPlay_SeasonRecord_ThisSeason) end --武将胜率列表 self.lists = context.lists self:InitHeroProfessionTab() end function UIReplayHistoryPopUp:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUpTab.btn_Close) end function UIReplayHistoryPopUp:OnButtonClicked(comp) if comp == self.UICommonPopUpTab.btn_Close then self:CloseView() end end function UIReplayHistoryPopUp:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.UICommonPopUpTab.loop_Tab then if data.isAll then UIUtils.SetActive(cellTable.img_Icon,false) UIUtils.SetActive(cellTable.img_Icon02,false) else UIUtils.SetActive(cellTable.img_Icon,true) UIUtils.SetActive(cellTable.img_Icon02,true) --没选中的图标 UIUtils.SetImageByAssetBundle(cellTable.img_Icon, string.format(IconPath, unSelectProfessionIcon[data.ID])) --选中的图标 UIUtils.SetImageByAssetBundle(cellTable.img_Icon02, string.format(IconPath, selectProfessionIcon[data.ID])) end UIUtils.SetLabelText(cellTable.txt_Name_Nomal,Const_IDS[data.Name]) UIUtils.SetLabelText(cellTable.txt_Name_Selected,Const_IDS[data.Name]) UIUtils.SetActive(cellTable.img_Arrow,false) UIUtils.SetActive(cellTable.img_ArrowS,false) elseif scrollRect == self.loop_Hero then --武将战绩 local recordData local gameCount = 0 local winCount = 0 --武将名字/头像 if type(data) == 'table' then recordData = myRecordData[data.ID] UTL.Item.SetHeroIconByHeroId(cellTable.img_HeroHead, data.ID) UIUtils.SetLabelText(cellTable.txt_Hero, Const_IDS[data.NameIDS]) gameCount = recordData.gameCount winCount = recordData.winCount else local id = CTL.HeroAwaken.DecodeHeroId(data) recordData = myRecordData[id] UTL.Item.SetHeroIconByHeroId(cellTable.img_HeroHead, id, true) local heroData = DataSheetManager.HeroNum:GetDataByID(id) UIUtils.SetLabelText(cellTable.txt_Hero, Const_IDS[heroData.NameIDS]) gameCount = recordData.awakenGameCount winCount = recordData.awakenWinCount end --总场次 UIUtils.SetLabel(cellTable.txt_Total, gameCount) --胜利场次 UIUtils.SetLabel(cellTable.txt_Win, winCount) --胜率 UIUtils.SetLabel(cellTable.txt_Rate, CTL.Replay.GetWinRateShow(winCount, gameCount)) UIUtils.SetActive(cellTable.img_BG02, index % 2 == 1) UIUtils.SetActive(cellTable.img_BG01, index % 2 == 0) end end function UIReplayHistoryPopUp:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.UICommonPopUpTab.loop_Tab then local heroDataArray = self:GetHeroNumDataByTypeId(data.ID) UIUtils.SetActive(self.group_Empty,#heroDataArray == 0) self.loop_Hero:ReloadAll(heroDataArray) end end local function SortHeroData(a,b) local recordDataA = myRecordData[a.ID] local recordDataB = myRecordData[b.ID] if recordDataA.gameCount == recordDataB.gameCount then if a.HeroQuality > b.HeroQuality then return true end if a.HeroQuality < b.HeroQuality then return false end return a.ID < b.ID end if recordDataA.gameCount > recordDataB.gameCount then return true end return false end function UIReplayHistoryPopUp:GetHeroNumDataByTypeId(typeId) local data = {} myRecordData = {} for _,v in DataSheetManager.HeroNum:GetEnumerator() do if v.TypeID == typeId or typeId == nil then for i,v2 in ipairs(self.lists) do if v2.heroId == v.ID then table.insert(data,v) myRecordData[v.ID] = v2 end end end end table.sort(data,SortHeroData) for id, record in pairs(myRecordData) do if record.awakenGameCount > 0 then for i, v in ipairs(data) do if v.ID == id then --如果武将有觉醒战绩,需要显示觉醒武将和相应战绩 table.insert(data, i, CTL.HeroAwaken.EncodeHeroId(v.ID)) break end end end end --剔除掉场次为0的武将 for i = #data, 1, -1 do if type(data[i]) == 'table' then if myRecordData[data[i].ID].gameCount <= 0 then table.remove(data, i) end end end return data end function UIReplayHistoryPopUp:InitHeroProfessionTab() local allData = {isAll = true,Name = "IDS_FairPlayReplay_All"} self.UICommonPopUpTab.loop_Tab:AddData(allData, 0); for k,v in DataSheetManager.HeroProfession:GetEnumerator() do self.UICommonPopUpTab.loop_Tab:AddData(v, 0); end self.UICommonPopUpTab.loop_Tab:SelectIndex(0) end return UIReplayHistoryPopUp