| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using System;
- using Newtonsoft.Json.Linq;
- public class BoxFriendRequest : MonoBehaviour
- {
- void Awake()
- {
- GetFriendRequestItemPrefab().SetActive(false);
- }
- void OnEnable()
- {
- Refresh();
- }
- Transform GetFriendRequestItemParent()
- {
- return transform.Find("ScrollView/Viewport/Content");
- }
- GameObject GetFriendRequestItemPrefab()
- {
- return GetFriendRequestItemParent().Find("Item").gameObject;
- }
- //是否同意过好友添加请求,该记录可帮助提醒homeView的好友栏刷新
- bool _hasAcceptAnyFriends = false;
- void Refresh()
- {
- for (int i = 1; i < GetFriendRequestItemParent().childCount; i++)
- {
- Destroy(GetFriendRequestItemParent().GetChild(i).gameObject);
- }
- Action<JArray> cb = delegate (JArray list) {
- if (list.Count > 0)
- {
- foreach (var itemInfo in list)
- {
- int otherID = itemInfo.Value<int>("otherID");
- int avatarID = itemInfo.Value<int>("avatarID");
- string avatarUrl = itemInfo.Value<string>("avatarUrl");
- string nickname = itemInfo.Value<string>("nickname");
- bool online = itemInfo.Value<bool>("online");
- long offlineTime = itemInfo.Value<long>("offlineTime");
- GameObject o = Instantiate(GetFriendRequestItemPrefab(), GetFriendRequestItemParent());
- o.SetActive(true);
- o.name = otherID.ToString();
- RoleMgr.SetAvatarToImage(
- o.transform.Find("Avatar/Sprite").GetComponent<Image>(),
- avatarID, avatarUrl);
- o.transform.Find("Name").GetComponent<Text>().text = nickname;
- Button btnNo = o.transform.Find("BtnIgnore").GetComponent<Button>();
- btnNo.onClick.RemoveAllListeners();
- btnNo.onClick.AddListener(delegate () {
- AudioMgr.ins.PlayBtn();
- UserPlayer.ins.call("friendComp.decideAddFriend", new object[] { false, otherID });
- Destroy(o);
- UserPlayer.ins.tempData.hasFriendRequest = GetFriendRequestItemParent().childCount - 1 > 1;
- });
- Button btnYes = o.transform.Find("BtnAgree").GetComponent<Button>();
- btnYes.onClick.RemoveAllListeners();
- btnYes.onClick.AddListener(delegate () {
- AudioMgr.ins.PlayBtn();
- UserPlayer.ins.call("friendComp.decideAddFriend", new object[] { true, otherID });
- Destroy(o);
- _hasAcceptAnyFriends = true;
- UserPlayer.ins.tempData.hasFriendRequest = GetFriendRequestItemParent().childCount - 1 > 1;
- });
- }
- }
- else
- {
- PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("好友请求列表为空"));
- }
- };
- UserPlayer.ins.call("friendComp.getFriendRequestList", null, cb);
- PopupMgr.ins.ClearAllTip();
- }
- }
|