local UIOfficialPositionRank = UIViewClass() local REVISEINDEX = 3 --将自己移动到中间 也就是把自己的位置-3移动到最顶 function UIOfficialPositionRank:OnOpened(context) UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS["IDS_OfflineSoloFight_ChallengeButton"]) self:RegistSystemEvent(EventID.UI_Solofight_RankInfo_Refresh, self.refreshRankInfo) self:RegistSystemEvent(EventID.UI_PurchaseNumsSuccess, self.RefreshEnterTimes) self.moveSelf = true self:RefreshEnterTimes() self:InitInfo() end function UIOfficialPositionRank:InitInfo() local officialPVPGradeID = DataSheetManager.ConstData:GetDataByID("OfficialPVPGradeID").IntValue for i, v in DataSheetManager.OfficialPosition:GetEnumerator() do if officialPVPGradeID == v.GradeID then self.specialTitleID = i break end end self.curTitle = MDL.OfficialPosition.GetCurTitle() local moveIndex = 1 local index = 0 for _, v in DataSheetManager.OfficialPosition:GetEnumerator() do if v.ID >= self.specialTitleID then index = index + 1 self.LoopScroll_LeftMenu_OfficialPositionRank:AddData(v, 0) end if v.ID == self.curTitle then moveIndex = index end end if moveIndex == 0 then self.LoopScroll_LeftMenu_OfficialPositionRank:SelectIndex(0, true) else self.LoopScroll_LeftMenu_OfficialPositionRank:SelectIndex(moveIndex - 1, true) end end function UIOfficialPositionRank:refreshRankInfo(msg) self.LoopScroll_Main_OfficialPositionRank:ClearCells() self.totalNum = math.ceil(msg.totalNum / 100) self.selfRankIdx = msg.selfRankIdx if #msg.rankInfos > 0 then self.group_Main:SetState(1) for i, v in ipairs(msg.rankInfos) do self.LoopScroll_Main_OfficialPositionRank:AddData(v, 0) end if self.moveSelf then if self.selfRankIdx - msg.rankInfos[1].rankIdx > REVISEINDEX then self.LoopScroll_Main_OfficialPositionRank:MoveIndex(self.selfRankIdx - msg.rankInfos[1].rankIdx - REVISEINDEX) end self.moveSelf = false end self.curPage = math.ceil(msg.rankInfos[1].rankIdx / 100) self.txt_Page.text = self.curPage .. "/" .. self.totalNum self.btn_PageLeft:SetGray(self.curPage == 1) self.btn_PageRight:SetGray(self.curPage == self.totalNum) else self.group_Main:SetState(0) end end function UIOfficialPositionRank:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.LoopScroll_LeftMenu_OfficialPositionRank then if self.curTitle <= self.specialTitleID then UIUtils.SetActive(cellTable.img_Check, data.ID == self.specialTitleID) UIUtils.SetActive(cellTable.img_UnCheck, data.ID == self.specialTitleID) else UIUtils.SetActive(cellTable.img_Check, self.curTitle == data.ID) UIUtils.SetActive(cellTable.img_UnCheck, self.curTitle == data.ID) end if data.ID == self.specialTitleID then local txt = UIUtils.GetLocalizedTxt(Const_IDS.IDS_OfficialPosition_PVPTab) cellTable.lab_LeftMenu_OfficialPositionRank.text = UTL.Color.FormatQualityText(txt, data.QualityColor) else local txt = CTL.OfficialPosition.GetTitleFullTxt(data) cellTable.lab_LeftMenu_OfficialPositionRank.text = UTL.Color.FormatQualityText(txt, data.QualityColor) end else if data.headInfo.acid == BattleDataGetter.GetAcID() then cellTable.txt_Name.text = UTL.Color.FormatGreenColor(data.headInfo.name) UIUtils.SetActive(cellTable.btn_Challenge, false) else cellTable.obj_challengeState:SetState(0) local isBattle = CTL.SoloFight.CanBattleByRankAndOffline(data.rankIdx, self.selfRankIdx) if self.selectTitle > self.specialTitleID then isBattle = isBattle and self.selectTitle == MDL.OfficialPosition.GetCurTitle() end UIUtils.SetActive(cellTable.btn_Challenge, isBattle) cellTable.txt_Name.text = data.headInfo.name end cellTable.txt_CE.text = data.headInfo.gsSum local sortIndex = data.rankIdx if sortIndex <= 3 then UIUtils.SetActive(cellTable.img_Rank, true) cellTable.section_Rank:SetState(sortIndex - 1) cellTable.txt_Rank.text = nil else UIUtils.SetActive(cellTable.img_Rank, false) cellTable.txt_Rank.text = sortIndex end if self.DegradationNum or self.DegradationNum == -1 then UIUtils.SetActive(cellTable.section_Jiang, false) else UIUtils.SetActive(cellTable.section_Jiang, sortIndex > self.DegradationNum) end CTL.Character.SetPortraitAndFrame(cellTable.UIHeroHead150, data.headInfo.PortraitId, data.headInfo.FrameId, data.headInfo.level) local guildName = data.headInfo.guildName if string.isNilOrEmpty(guildName) then UIUtils.SetActive(cellTable.section_Guild.gameObject, false) else UIUtils.SetActive(cellTable.section_Guild.gameObject, true) CTL.Guild.SetGuildEmblem(cellTable.section_Guild.img_Guild, cellTable.section_Guild.txt_Guild, data.headInfo.EmblemFrame, data.headInfo.EmblemContent) cellTable.section_Guild.txt_Name.text = CTL.Guild.GetColorGuildName(data.headInfo.guildId, guildName) end end end function UIOfficialPositionRank:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.LoopScroll_LeftMenu_OfficialPositionRank then self.selectTitle = data.ID local _, pvpData = DataSheetManager.OfficialPositionPromotion:TryGetDataByGradeID(data.GradeID) --降品人数 self.DegradationNum = pvpData and pvpData.DegradationNum or 0 MDL.SoloFight.RankInfoReq(data.ID) else if target == cellTable.UIHeroHead150.img_PlayerAvatarBg then CTL.PlayerInteract.OpenFriendInteractView(data.headInfo.acid) elseif target == cellTable.btn_Challenge then MDL.SoloFight.FightReq(data.headInfo.acid, data.rankIdx) end end end function UIOfficialPositionRank:RefreshEnterTimes() local totalTimes = DataSheetManager.ActivityData:GetDataByID(LuaConst.ActivityType.OffLineSoloFight).DailyRefreshTimes --只显示基础次数 local num = MDL.SoloFight.GetSoloFightLeftTimes() if num == 0 then self.txt_Times.text = UTL.Color.FormatRedColor(0) .. "/" .. totalTimes else self.txt_Times.text = num .. "/" .. totalTimes end end function UIOfficialPositionRank:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUp.btn_Close) end function UIOfficialPositionRank:OnButtonClicked(comp) if comp == self.UICommonPopUp.btn_Close then self:CloseView() elseif comp == self.btn_PageLeft then MDL.SoloFight.RankInfoReq(self.selectTitle, self.curPage - 1) elseif comp == self.btn_PageRight then MDL.SoloFight.RankInfoReq(self.selectTitle, self.curPage + 1) elseif comp == self.btn_Add then CTL.SoloFight.OpenTimeUpView() end end return UIOfficialPositionRank