-- 推荐好友界面 local UIFriendRecommendation = UIViewClass() -------------------- function UIFriendRecommendation:OnCreated() self.isInCommend = true end function UIFriendRecommendation:OnOpened(context) UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS.IDS_Friend_RecommendedFriends) self:RegistSystemEvent(EventID.UI_UpdateFriendRecommend, self.RefreshInfo) self:RegistSystemEvent(EventID.UI_UpdateFriendSearch, self.RefreshInfo) self:RegistSystemEvent(EventID.UI_UpdateBlack, self.ForceRefresh) self:OpenRecommend(true) end function UIFriendRecommendation:ForceRefresh() MDL.Friend.FriendsRecommendReq(true, false) end function UIFriendRecommendation:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUp.btn_Close) end function UIFriendRecommendation:OnButtonClicked(comp) if comp == self.UICommonPopUp.btn_Close then self:CloseView() elseif comp == self.btn_Search then self:OpenSearch() elseif comp == self.event_Refresh then if self.isInCommend then if not CTL.Friend.IsInChangeRecommendCD(true) then MDL.Friend.FriendsRecommendReq(true, true) end else self:OpenRecommend(false) end end end function UIFriendRecommendation:OnCellInit(scrollRect, index, cellTable, data) UIUtils.SetActive(cellTable.img_AddIcon, false) UIUtils.SetLabel(cellTable.txt_PlayerName, data.PlayerInfo.PlayerShowInfo.name) CTL.Character.SetPortraitAndFrame( cellTable.UIHeroHead150, data.PlayerInfo.PlayerShowInfo.PortraitId, data.PlayerInfo.PlayerShowInfo.FrameId, data.PlayerInfo.PlayerShowInfo.level ) CTL.Player.OperateGenderImage(cellTable.image_Gender, data.PlayerInfo.PlayerShowInfo.sex) local tagData = CTL.Friend.GetPlayerTagData(data) for i, v in ipairs(cellTable.group_Tag) do local data = tagData[i] if data then UIUtils.SetActive(v.gameObject, true) UIUtils.SetLabelText(v.txt_PlayerTag, Const_IDS[data.Name]) UIUtils.SetImageColor(v.bg_PlayerTag, data.FloorColor) else UIUtils.SetActive(v.gameObject, false) end end end function UIFriendRecommendation:OnCellClicked(scrollRect, index, cellTable, target, data) if target == cellTable.btn_Add then UIUtils.SetActive(cellTable.img_AddIcon, true) MDL.Friend.SendApplyFriend(data.PlayerInfo.PlayerShowInfo.acid) elseif target == cellTable.UIHeroHead150.img_PlayerAvatarBg then CTL.PlayerInteract.OpenFriendInteractView(data.PlayerInfo.PlayerShowInfo.acid) end end -------------------- function UIFriendRecommendation:OpenSearch() self.isInCommend = false self.event_Refresh:SetText(Const_IDS.IDS_Friend_BackToRecommended) local msg = self.obj_InputField.text if string.isNilOrEmpty(msg) or msg == BattleDataGetter.GetAcID() or msg == BattleDataGetter.GetPlayerName() then self:RefreshInfo(nil) else MDL.Friend.PrecisePlayerSearchReq(msg) end end function UIFriendRecommendation:OpenRecommend(isReq) if isReq then if not CTL.Friend.IsInChangeRecommendCD(false) or MDL.Friend.CacheRecommendPlayerInfos == nil then -- 不在CD时间内 或者 推荐列表为空,则请求刷新 MDL.Friend.FriendsRecommendReq(true, true) else self:RefreshInfo(MDL.Friend.CacheRecommendPlayerInfos) end else self:RefreshInfo(MDL.Friend.CacheRecommendPlayerInfos) end self.isInCommend = true self.event_Refresh:SetText(Const_IDS.IDS_Friend_Change) end function UIFriendRecommendation:RefreshInfo(infos) if infos and #infos > 0 then UIUtils.SetActive(self.group_Empty, false) UIUtils.SetActive(self.group_PlayerAdd, true) self.group_PlayerAdd:ReloadAll(infos) else UIUtils.SetActive(self.group_Empty, true) UIUtils.SetActive(self.group_PlayerAdd, false) UIUtils.SetLabelText(self.lab_Empty, Const_IDS[self.isInCommend and "IDS_Friend_NoRecommendedFriends" or "IDS_Friend_NoSearch"]) end end return UIFriendRecommendation