| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using System;
- using Newtonsoft.Json.Linq;
- namespace SmartBow {
- public class BoxFriendList : MonoBehaviour
- {
- void Awake()
- {
- GetMyFriendItemPrefab().SetActive(false);
- }
- void OnEnable()
- {
- Refresh();
- }
- Transform GetMyFriendItemParent()
- {
- return transform.Find("ScrollView/Viewport/Content");
- }
- GameObject GetMyFriendItemPrefab()
- {
- return GetMyFriendItemParent().Find("Item").gameObject;
- }
- //是否删除过好友,该记录可帮助提醒homeView的好友栏刷新
- bool _hasDeleteAnyFriends = false;
- void Refresh()
- {
- for (int i = 1; i < GetMyFriendItemParent().childCount; i++)
- {
- Destroy(GetMyFriendItemParent().GetChild(i).gameObject);
- }
- Action<JArray> cb = delegate (JArray list) {
- if (list.Count > 0)
- {
- foreach (var itemInfo in list)
- {
- int friendID = itemInfo.Value<int>("friendID");
- 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(GetMyFriendItemPrefab(), GetMyFriendItemParent());
- o.SetActive(true);
- o.name = friendID.ToString();
- RoleMgr.SetAvatarToImage(
- o.transform.Find("Avatar/Sprite").GetComponent<Image>(),
- avatarID, avatarUrl);
- o.transform.Find("Name").GetComponent<Text>().text = nickname;
- //在线提示
- Text onlineTip = o.transform.Find("OnlineTip").GetComponent<Text>();
- GameObject onlinePoint = onlineTip.transform.Find("PointOnline").gameObject;
- if (online)
- {
- onlineTip.enabled = false;
- onlinePoint.SetActive(true);
- }
- else
- {
- onlineTip.enabled = true;
- onlineTip.text = TimeUtil.GetOfflineTimeStr(offlineTime, online);
- onlinePoint.SetActive(false);
- }
- //删除按钮
- Button btnDelete = o.transform.Find("BtnDelete").GetComponent<Button>();
- btnDelete.onClick.RemoveAllListeners();
- btnDelete.onClick.AddListener(delegate () {
- AudioMgr.ins.PlayBtn();
- ModalConfirmDeleteFriend modalConfirmDeleteFriend = GetComponentInParent<SocialView>().ShowModalConfirmDeleteFriend(true);
- modalConfirmDeleteFriend.OnConfirm = () =>
- {
- Action<bool> cb = delegate (bool res)
- {
- if (res)
- {
- _hasDeleteAnyFriends = true;
- Destroy(o);
- }
- };
- UserPlayer.ins.call("friendComp.deleteMyFriend", new object[] { friendID }, cb);
- };
- });
- }
- }
- else
- {
- PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("好友列表为空"));
- }
- HomeView.ins?.RenderFriendList(list);
- };
- UserPlayer.ins.call("friendComp.getMyFriends", null, cb);
- PopupMgr.ins.ClearAllTip();
- }
- }
- }
|