local UIOfficialPrivilegeCommon = UIViewClass() UIOfficialPrivilegeCommon.tab_Type = { Guild = 1, Friend = 2, Stranger = 3, Blacklist = 4, } local usedTimesMax = 10 local ids_TabType = { [UIOfficialPrivilegeCommon.tab_Type.Guild] = Const_IDS.IDS_FunctionName_Guild, [UIOfficialPrivilegeCommon.tab_Type.Friend] = Const_IDS.IDS_FunctionName_Friend, [UIOfficialPrivilegeCommon.tab_Type.Stranger] = Const_IDS.IDS_TeamUI_ActiveInvitation_Stranger, [UIOfficialPrivilegeCommon.tab_Type.Blacklist] = Const_IDS.IDS_Friend_Blacklist, } local ids_OptBtn = { [MDL.OfficialPrivilege.OptType.Inquire] = Const_IDS.IDS_OfficialPrivilege_Button1, [MDL.OfficialPrivilege.OptType.Silence] = Const_IDS.IDS_OfficialPrivilege_Button3, [MDL.OfficialPrivilege.OptType.Punishment] = Const_IDS.IDS_OfficialPrivilege_Button4, [MDL.OfficialPrivilege.OptType.Promote] = Const_IDS.IDS_OfficialPrivilege_Button5, } local ids_SearchInit = { [MDL.OfficialPrivilege.OptType.Inquire] = Const_IDS.IDS_OfficialPrivilege_EnterName, [MDL.OfficialPrivilege.OptType.Silence] = Const_IDS.IDS_OfficialPrivilege_EnterName1, [MDL.OfficialPrivilege.OptType.Punishment] = Const_IDS.IDS_OfficialPrivilege_EnterName2, } ----------- local function SortRuleFriends(a, b) return MDL.OfficialPrivilege.beInquiredNumsFriendList[a.acid] < MDL.OfficialPrivilege.beInquiredNumsFriendList[b.acid] end local function SortRuleGuildMembers(a, b) return MDL.OfficialPrivilege.beInquiredNumsGuildList[a.roleInfo.acid] < MDL.OfficialPrivilege.beInquiredNumsGuildList[b.roleInfo.acid] end local function SortRuleStrangers(a, b) return MDL.OfficialPrivilege.beInquiredNumsStrangerList[a.PlayerInfo.PlayerShowInfo.acid] < MDL.OfficialPrivilege.beInquiredNumsStrangerList[b.PlayerInfo.PlayerShowInfo.acid] end function UIOfficialPrivilegeCommon:OnCreated() self.toggleList = {} self.curToggleTab = 0 self.useRecommendList = false self.guildMembers = {} self.limitIndexList = {} end function UIOfficialPrivilegeCommon:OnOpened(context) self.isDefault = true self.costItemNum = self.context.Parm[1] self:RegistSystemEvent(EventID.UI_RefreshOfficialPrivilegeInfo, self.RefreshOptTimes) self:RegistSystemEvent(EventID.UI_Guild_GuildInfoRefresh, self.RefreshGuildMembers) self:RegistSystemEvent(EventID.UI_Guild_BeInquiredRefresh, self.RefreshDefault) self:RegistSystemEvent(EventID.UI_UpdateFriendInfo, self.RefreshFriendList) self:RegistSystemEvent(EventID.UI_UpdateFriendSearch, self.OnSearchFinish) self:RegistSystemEvent(EventID.UI_UpdateFriendRecommend, self.OnSearchFinish) self:RegistSystemEvent(EventID.UI_RefreshOfficialPrivilegeGetOptRecord, self.OnShowLog) self:RegistSystemEvent(EventID.UI_RefreshOfficialPrivilegeCurTab, self.RefreshCurTab) self:RegistSystemEvent(EventID.UI_OfficialPrivilege_StangerRefresh, self.RefreshStranger) if self.context.RightsID ~= MDL.OfficialPrivilege.OptType.Inquire then self:RegistSystemEvent(EventID.BagItem_Update, self.RefreshConsumeOrOwn) self:RefreshConsumeOrOwn() end self:RefreshOptTimes() UIUtils.SetLabelText(self.UIOfficialPrivilegePopUpLeft.UICommonPopUp.txt_Title, Const_IDS[context.Name]) --默认隐藏日志相关 UIUtils.SetActive(self.group_LogTips.gameObject, false) self:RefreshCurTab() end function UIOfficialPrivilegeCommon:OnBackButtonPressed() if self.group_LogTips.gameObject.activeSelf then self:OnButtonClicked(self.event_Click) else self:OnButtonClicked(self.UIOfficialPrivilegePopUpLeft.UICommonPopUp.btn_Close) end end function UIOfficialPrivilegeCommon:OnButtonClicked(comp) if comp == self.UIOfficialPrivilegePopUpLeft.UICommonPopUp.btn_Close then self:CloseView() elseif comp == self.btn_Search then local msg = self.obj_InputField.text if string.isNilOrEmpty(msg) then if self.useRecommendList then if MDL.Friend.CacheRecommendPlayerInfos then self:OnSearchFinish(MDL.Friend.CacheRecommendPlayerInfos) end else self:OnSearchFinish(nil) end elseif msg == BattleDataGetter.GetAcID() or msg == BattleDataGetter.GetPlayerName() then self:OnSearchFinish(nil) else MDL.Friend.PrecisePlayerSearchReq(msg) end elseif comp == self.btn_Log then MDL.OfficialPrivilege.OfficialPrivilegeGetOptRecordRequest() elseif comp == self.event_Click then UIUtils.SetActive(self.group_LogTips.gameObject, false) end end function UIOfficialPrivilegeCommon:OnValueChanged(comp, index) self:ClickTab(comp, index, false) end function UIOfficialPrivilegeCommon:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.UIOfficialPrivilegePopUpLeft.loop_Limit then if data == CTL.OfficialPrivilege.LimitType.ConsumeOrOwn then UIUtils.SetLabelText(cellTable.txt_LimitTitle, Const_IDS.IDS_OfficialPrivilege_Consume) local count = MDL.Bag.GetItemCount(self.context.ItemID) cellTable.txt_Num.text = string.format("%s/%s", count >= self.costItemNum and count or UTL.Color.FormatRedColor(count), self.costItemNum) UTL.Item.MoneyIcon(cellTable.img_Icon, self.context.ItemID) --这里不需要显示按钮 UIUtils.SetActive(cellTable.btn_Add, false) elseif data == CTL.OfficialPrivilege.LimitType.UseNum then local infoNum, _ = MDL.OfficialPrivilege.GetPrivilegeInfoNum(self.context.RightsID) UIUtils.SetLabelText(cellTable.txt_LimitTitle, Const_IDS[self.context.UseTimesDes]) local leftNum = math.max(self.context.UseTimes - infoNum, 0) cellTable.txt_Num.text = string.format("%s/%s", leftNum == 0 and UTL.Color.FormatRedColor(leftNum) or leftNum, self.context.UseTimes) elseif data == CTL.OfficialPrivilege.LimitType.BeUseNum then local _, beInfoNum = MDL.OfficialPrivilege.GetPrivilegeInfoNum(self.context.RightsID) UIUtils.SetLabelText(cellTable.txt_LimitTitle, Const_IDS[self.context.UsedTimesDes]) local leftbeNum = math.max(self.context.UsedTimes - beInfoNum, 0) cellTable.txt_Num.text = string.format("%s/%s", leftbeNum == 0 and UTL.Color.FormatRedColor(leftbeNum) or leftbeNum, self.context.UsedTimes) end elseif scrollRect == self.loop_Player then if self.curToggleTab == UIOfficialPrivilegeCommon.tab_Type.Guild then local roleInfo = data.roleInfo local beInquiredNumsLeft = 10 - MDL.OfficialPrivilege.beInquiredNumsGuildList[roleInfo.acid] self:SetPlayerCell(cellTable, roleInfo.name, roleInfo.level, roleInfo.OfficialId, roleInfo.SoloFightRank, roleInfo.guildName, roleInfo.isOnline, roleInfo.PortraitId, roleInfo.FrameId, beInquiredNumsLeft) elseif self.curToggleTab == UIOfficialPrivilegeCommon.tab_Type.Friend or self.curToggleTab == UIOfficialPrivilegeCommon.tab_Type.Blacklist then local beInquiredNumsLeft = 0 if self.context.RightsID == MDL.OfficialPrivilege.OptType.Inquire then beInquiredNumsLeft = 10 - data.beInquiredNums end self:SetPlayerCell(cellTable, data.name, data.level, data.officialId, data.soloFightRank, data.guildName, data.isOnline, data.portraitId, data.frameId, beInquiredNumsLeft) end elseif scrollRect == self.loop_Search then local playerInfo = data.PlayerInfo.PlayerShowInfo local beInquiredNumsLeft = 10 - MDL.OfficialPrivilege.beInquiredNumsStrangerList[playerInfo.acid] self:SetPlayerCell(cellTable, playerInfo.name, playerInfo.level, playerInfo.OfficialId, playerInfo.SoloFightRank, playerInfo.guildName, playerInfo.isOnline, playerInfo.PortraitId, playerInfo.FrameId, beInquiredNumsLeft) elseif scrollRect == self.loop_Logs then cellTable.txt_Time.text = UTL.Time.FormatTimeCompletely(data.optTime) cellTable.txt_Info.text = CTL.OfficialPrivilege.GetRecordStr(data) end end function UIOfficialPrivilegeCommon:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loop_Player or scrollRect == self.loop_Search then if target == cellTable.btn_Privilege and CTL.OfficialPrivilege.CheckOfficialPrivilegeCanUse(self.context) then local acid = self:GetCellDataAcid(data) MDL.OfficialPrivilege.OfficialPrivilegeOptRequest(self.context.RightsID, acid) end elseif scrollRect == self.UIOfficialPrivilegePopUpLeft.loop_Limit then if data == CTL.OfficialPrivilege.LimitType.ConsumeOrOwn then UTL.ItemTips.ShowCommonTipsById(self.context.ItemID) end end end ----------- -- 刷新Tab function UIOfficialPrivilegeCommon:ClickTab(comp, index, isRefresh) if comp == self.group_TabTop then index = index + 1 -- index 从0开始 self.toggleList从1开始 self.curToggleTab = self.toggleList[index] if self.curToggleTab == UIOfficialPrivilegeCommon.tab_Type.Guild then if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Guild) then -- 切换至军团页签时 需要请求一次军团成员数据 MDL.Guild.GetGuildInfoReq() else self:RefreshGuildMembers() end elseif self.curToggleTab == UIOfficialPrivilegeCommon.tab_Type.Stranger then if not isRefresh then self.obj_InputField.text = nil end if string.isNilOrEmpty(self.obj_InputField.text) and self.useRecommendList and (not CTL.Friend.IsInChangeRecommendCD(false) or MDL.Friend.CacheRecommendPlayerInfos == nil) then MDL.Friend.FriendsRecommendReq(true, true) --不在CD时间内,请求刷新 else self:OnButtonClicked(self.btn_Search) UIUtils.SetLabelText(self.lab_SearchEmpty, ids_SearchInit[self.context.RightsID]) end else --需要刷新数据 if self.curToggleTab == UIOfficialPrivilegeCommon.tab_Type.Friend then MDL.Friend.SendRefreshFriendInfos() elseif self.curToggleTab == UIOfficialPrivilegeCommon.tab_Type.Blacklist then MDL.Friend.SendRefreshBlackInfos() end end end end --设置玩家的cell信息 function UIOfficialPrivilegeCommon:SetPlayerCell(cellTable, name, level, title, rank, guildName, isOnline, portraitId, frameId, usedTimesLeft) UIUtils.SetLabel(cellTable.txt_Name, name) if self.context.RightsID == MDL.OfficialPrivilege.OptType.Inquire then UIUtils.SetLabel(cellTable.txt_Privilege_numStr, UIUtils.GetLocalizedTxt(Const_IDS.IDS_OfficialPrivilege_UsedTimesDes1)) cellTable.txt_Privilege_num.text = string.format("%s/%s", usedTimesLeft == 0 and UTL.Color.FormatRedColor(usedTimesLeft) or usedTimesLeft, usedTimesMax) else cellTable.txt_Privilege_numStr.text = nil cellTable.txt_Privilege_num.text = nil end CTL.Character.SetPortraitAndFrame(cellTable.UIHeroHead150, portraitId, frameId, level) if isOnline then UIUtils.SetComponentGray(cellTable.UIHeroHead150.gameObject.transform, false) else UIUtils.SetComponentGray(cellTable.UIHeroHead150.gameObject.transform, true) end UIUtils.SetLabelText(cellTable.txt_Privilege, ids_OptBtn[self.context.RightsID]) if string.isNilOrEmpty(guildName) then UIUtils.SetLabelText(cellTable.txt_Guild, Const_IDS.IDS_OfficialPrivilege_NoGuild) else UIUtils.SetLabel(cellTable.txt_Guild, string.FormatByIdsId(Const_IDS.IDS_OfficialPrivilege_Guild,guildName)) end local _, titleData = DataSheetManager.OfficialPosition:TryGetDataByID(title) if CTL.OfficialPrivilege.GetIsEnableOpt(self.context, title, rank) then if rank and rank > 0 then UIUtils.SetLabel(cellTable.txt_Rank, string.FormatByIdsId(Const_IDS.IDS_OfficialPrivilege_Ranking, rank)) else UIUtils.SetLabel(cellTable.txt_Rank, nil) end if titleData then local titleDesc = string.FormatByIdsId(Const_IDS.IDS_OfficialPrivilege_Grade, UIUtils.GetLocalizedTxt(Const_IDS[titleData.Name1])) UIUtils.SetLabel(cellTable.txt_Office, titleDesc) else cellTable.txt_Office.text = UTL.Color.FormatRedColor(UIUtils.GetLocalizedTxt(Const_IDS.IDS_OfficialPrivilege_NoGrade)) end cellTable.btn_Privilege:SetGray(false) else if rank and rank > 0 then UIUtils.SetLabel(cellTable.txt_Rank, UTL.Color.FormatRedColor(string.FormatByIdsId(Const_IDS.IDS_OfficialPrivilege_Ranking, rank))) else UIUtils.SetLabel(cellTable.txt_Rank, nil) end if titleData then local titleDesc = UTL.Color.FormatRedColor(string.FormatByIdsId(Const_IDS.IDS_OfficialPrivilege_Grade, UIUtils.GetLocalizedTxt(Const_IDS[titleData.Name1]))) UIUtils.SetLabel(cellTable.txt_Office, titleDesc) else cellTable.txt_Office.text = UTL.Color.FormatRedColor(UIUtils.GetLocalizedTxt(Const_IDS.IDS_OfficialPrivilege_NoGrade)) end cellTable.btn_Privilege:SetGray(true) end end function UIOfficialPrivilegeCommon:GetCellDataAcid(data) if self.curToggleTab == UIOfficialPrivilegeCommon.tab_Type.Friend or self.curToggleTab == UIOfficialPrivilegeCommon.tab_Type.Blacklist then return data.acid end if self.curToggleTab == UIOfficialPrivilegeCommon.tab_Type.Stranger then return data.PlayerInfo.PlayerShowInfo.acid end if self.curToggleTab == UIOfficialPrivilegeCommon.tab_Type.Guild then return data.roleInfo.acid end end function UIOfficialPrivilegeCommon:LoadListData(list, emptyIDS) UIUtils.SetActive(self.group_Search, false) if list and #list > 0 then self:OnEmptyShow(false) self.loop_Player:ReloadAll(list) else self:OnEmptyShow(true, emptyIDS) end end function UIOfficialPrivilegeCommon:OnEmptyShow(isEmpty, titleIDS) if isEmpty then self.loop_Player:ClearCells() UIUtils.SetActive(self.group_PlayerEmpty, true) UIUtils.SetLabelText(self.lab_PlayerEmpty, titleIDS) else UIUtils.SetActive(self.group_PlayerEmpty, false) end end function UIOfficialPrivilegeCommon:InitListInfos() self.guildMemberList = {} self.friendList = {} self.strangerList = {} for _, v in ipairs(MDL.Friend.GetSortedList(MDL.Friend.ListType.Friend)) do table.insert(self.friendList, v.acid) end MDL.OfficialPrivilege.OfficialGetInquireInfoReq(self.friendList, MDL.OfficialPrivilege.GetInquireTypeEnum.Friend) end ------------------------ 事件监听方法 ------------------------ function UIOfficialPrivilegeCommon:RefreshConsumeOrOwn() local consumeOrOwnType = CTL.OfficialPrivilege.LimitType.ConsumeOrOwn local index = self.limitIndexList[consumeOrOwnType] if index ~= nil then self.UIOfficialPrivilegePopUpLeft.loop_Limit:UpdateIndex(index) else self.limitIndexList[consumeOrOwnType] = self.UIOfficialPrivilegePopUpLeft.loop_Limit.Count self.UIOfficialPrivilegePopUpLeft.loop_Limit:AddData(consumeOrOwnType, CTL.OfficialPrivilege.LimitUIType.HaveItem) end end function UIOfficialPrivilegeCommon:RefreshOptTimes() local useNumType = CTL.OfficialPrivilege.LimitType.UseNum local optIndex = self.limitIndexList[useNumType] if optIndex ~= nil then self.UIOfficialPrivilegePopUpLeft.loop_Limit:UpdateIndex(optIndex) else self.limitIndexList[useNumType] = self.UIOfficialPrivilegePopUpLeft.loop_Limit.Count self.UIOfficialPrivilegePopUpLeft.loop_Limit:AddData(useNumType, CTL.OfficialPrivilege.LimitUIType.NoItem) end local beUseNumType = CTL.OfficialPrivilege.LimitType.BeUseNum local beOptIndex = self.limitIndexList[beUseNumType] if beOptIndex ~= nil then self.UIOfficialPrivilegePopUpLeft.loop_Limit:UpdateIndex(beOptIndex) else self.limitIndexList[beUseNumType] = self.UIOfficialPrivilegePopUpLeft.loop_Limit.Count self.UIOfficialPrivilegePopUpLeft.loop_Limit:AddData(beUseNumType, CTL.OfficialPrivilege.LimitUIType.NoItem) end end -- 刷新Guild数据 function UIOfficialPrivilegeCommon:RefreshGuildMembers() if self.curToggleTab ~= UIOfficialPrivilegeCommon.tab_Type.Guild then return end self.guildMemberList = {} for _, v in MDL.Guild.GetGuildMembersIterator(false) do table.insert(self.guildMemberList, v.roleInfo.acid) end MDL.OfficialPrivilege.OfficialGetInquireInfoReq(self.guildMemberList, MDL.OfficialPrivilege.GetInquireTypeEnum.Guild) local index = 1 for _, v in MDL.Guild.GetGuildMembersIterator(false) do self.guildMembers[index] = v index = index + 1 end for i = #self.guildMembers, index, -1 do table.remove(self.guildMembers, i) end end function UIOfficialPrivilegeCommon:RefreshDefault() self.isDefault = false table.sort(self.guildMembers, SortRuleGuildMembers) self:LoadListData(self.guildMembers, string.isNilOrEmpty(MDL.Guild.GetMyGuildId()) and Const_IDS.IDS_OfficialPrivilege_JoinGuild or Const_IDS.IDS_OfficialPrivilege_AddGuild) self:InitListInfos() end -- 刷新好友数据 function UIOfficialPrivilegeCommon:RefreshFriendList() if self.curToggleTab == UIOfficialPrivilegeCommon.tab_Type.Friend then local friends = MDL.Friend.GetSortedList(MDL.Friend.ListType.Friend) for _, v in ipairs(friends) do for acid, value in pairs(MDL.OfficialPrivilege.beInquiredNumsFriendList) do if acid == v.acid then v.beInquiredNums = value end end end table.sort(friends, SortRuleFriends) self:LoadListData(friends, Const_IDS.IDS_OfficialPrivilege_AddFriend) elseif self.curToggleTab == UIOfficialPrivilegeCommon.tab_Type.Blacklist then local blacks = MDL.Friend.GetSortedList(MDL.Friend.ListType.Black) self:LoadListData(blacks, Const_IDS.IDS_Friend_NoBlacklist) end end -- 刷新职权记录 function UIOfficialPrivilegeCommon:OnShowLog() local records = MDL.OfficialPrivilege.GetOfficialPrivilegeGetOptRecord() UIUtils.SetActive(self.group_LogTips.gameObject, true) if #records == 0 then UIUtils.SetActive(self.loop_Logs.gameObject, false) UIUtils.SetActive(self.group_LogTipsEmpty.gameObject, true) else UIUtils.SetActive(self.loop_Logs.gameObject, true) UIUtils.SetActive(self.group_LogTipsEmpty.gameObject, false) self.loop_Logs:ReloadAll(records) end end function UIOfficialPrivilegeCommon:OnSearchFinish(infos) UIUtils.SetActive(self.group_PlayerEmpty, false) UIUtils.SetActive(self.group_Search, true) self.searchInfos = infos self.searchList = {} if infos and #infos > 0 then for _, v in ipairs(infos) do table.insert(self.searchList, v.PlayerInfo.PlayerShowInfo.acid) end end MDL.OfficialPrivilege.OfficialGetInquireInfoReq(self.searchList, MDL.OfficialPrivilege.GetInquireTypeEnum.Stranger) self.loop_Player:ClearCells() end function UIOfficialPrivilegeCommon:RefreshStranger() if self.searchInfos and #self.searchInfos > 0 then table.sort(self.searchInfos, SortRuleStrangers) self.loop_Search:ReloadAll(self.searchInfos) UIUtils.SetActive(self.group_SearchEmpty, false) else self.loop_Search:ClearCells() UIUtils.SetActive(self.group_SearchEmpty, true) UIUtils.SetLabelText(self.lab_SearchEmpty, Const_IDS.IDS_OfficialPrivilege_Nobody) end end function UIOfficialPrivilegeCommon:RefreshCurTab() for i, v in ipairs(self.toggleList) do if v == self.curToggleTab then self:ClickTab(self.group_TabTop, i - 1, true) -- curToggleTab从1开始 index从0开始 return end end end ------------------------------------------------------------- --region --传 tab_Type 枚举 function UIOfficialPrivilegeCommon:InitToggles(...) local idsList = {} for i, tp in ipairs({...}) do table.insert(idsList, ids_TabType[tp]) self.toggleList[i] = tp end for i = #self.toggleList, select('#', ...) + 1, -1 do table.remove(self.toggleList, i) end UTL.Toggle.InitToggleGroupByIDS(self.group_TabTop, "lab_First", idsList) self.group_TabTop:SelectIndex(0) end function UIOfficialPrivilegeCommon:SetUseRecommendList(use) self.useRecommendList = use end ---endregion return UIOfficialPrivilegeCommon