local UIOfficialPrivilegeMain = UIViewClass() local UIOfficialPrivilegeCommon = "OfficialPrivilege/UIOfficialPrivilegeCommon" local Const_UI_OptType = { [MDL.OfficialPrivilege.OptType.Inquire] = Const_UI_Lua.UIEnum.UIOfficialPrivilegeInquire, [MDL.OfficialPrivilege.OptType.Silence] = Const_UI_Lua.UIEnum.UIOfficialPrivilegeSilence, [MDL.OfficialPrivilege.OptType.Punishment] = Const_UI_Lua.UIEnum.UIOfficialPrivilegePunishment, [MDL.OfficialPrivilege.OptType.Promote] = Const_UI_Lua.UIEnum.UIOfficialPrivilegePromote, } ----------- function UIOfficialPrivilegeMain:OnOpened(context) self.curTitleGradeID = 0 self:RegistSystemEvent(EventID.UI_RefreshOfficialPrivilegeInfo, self.RefreshRightsLoop) self:RegistSystemEvent(EventID.UI_RefreshOfficialPositionInfo, self.RefreshRightsLoop) self:RefreshRightsLoop() end function UIOfficialPrivilegeMain:OnCellInit(scrollRect, index, cellTable, data) UIUtils.SetLabelText(cellTable.txt_Title, Const_IDS[data.Name]) UIUtils.SetLabelText(cellTable.txt_Info, Const_IDS[data.Summary]) UIUtils.SetImageByAssetBundle(cellTable.img_WarHorse, data.Picture) local rightsInfoNum = MDL.OfficialPrivilege.GetPrivilegeInfoNum(data.RightsID) local leftNum = math.max(data.UseTimes - rightsInfoNum) cellTable.txt_Times.text = string.format("%s %s/%d",UIUtils.GetLocalizedTxt(Const_IDS.IDS_OfficialPrivilege_UseTimesDes), leftNum == 0 and UTL.Color.FormatRedColor(leftNum) or leftNum, data.UseTimes) -- 设置是否开启状态 local isArriveGrade = CTL.OfficialPosition.CheckIfUnlock(data.GradeID) local str = UIUtils.GetLocalizedTxt(Const_IDS[data.UnlockDes]) cellTable.txt_Limit.text = isArriveGrade and str or UTL.Color.FormatRedColor(str) UIUtils.SetActive(cellTable.group_UnGet, not isArriveGrade) -- 设置红点 if data.RightsID == MDL.OfficialPrivilege.OptType.Inquire then UIUtils.SetActive(cellTable.img_Redpoint, isArriveGrade and leftNum > 0) else UIUtils.SetActive(cellTable.img_Redpoint, false) end end function UIOfficialPrivilegeMain:OnCellClicked(scrollRect, index, cellTable, target, data) if self.curTitleGradeID ~= 0 and self.curTitleGradeID <= data.GradeID then if data.RightsID == MDL.OfficialPrivilege.OptType.Strengthen then UIManager.OpenView(Const_UI_Lua.UIEnum.UIOfficialPrivilegeStrengthen, data) else UIManager.OpenView(Const_UI_OptType[data.RightsID], data, UIOfficialPrivilegeCommon) end else CTL.Sound.PlayGameSound("UI_invalid") end end ----------- function UIOfficialPrivilegeMain:RefreshRightsLoop() self.curTitleGradeID = MDL.OfficialPosition.GetCurGradeID() local loopCount = self.loop_Privilege.Count if loopCount == 0 then for _, v in CTL.OfficialPrivilege.GetSortedRightsDataIterator() do self.loop_Privilege:AddData(v, 0) end else for i = 0, loopCount do self.loop_Privilege:UpdateIndex(i) end end end return UIOfficialPrivilegeMain