using System; using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; namespace Snxxz.UI { public class ChatRecently : MonoBehaviour { [SerializeField] ScrollerController m_RecentlyControl; FriendsModel m_FriendModel; FriendsModel friendModel { get { return m_FriendModel ?? (m_FriendModel = ModelCenter.Instance.GetModel()); } } private void OnEnable() { UpdatePlayer(); DisplayRecently(); friendModel.RefreshFriendCntEvent += RefreshFriendCntEvent; friendModel.RefreshFriendModel += DisplayRecently; } private void OnDisable() { friendModel.RefreshFriendCntEvent -= RefreshFriendCntEvent; friendModel.RefreshFriendModel -= DisplayRecently; } private void DisplayRecently() { m_RecentlyControl.Refresh(); var _dict = friendModel.GetFriendInfoDict((byte)GroupType.RecentContact); if (_dict != null) { if (friendModel.tempFriendData != null && !_dict.ContainsKey(friendModel.tempFriendData.PlayerID)) { m_RecentlyControl.AddCell(ScrollerDataType.Header, (int)friendModel.tempFriendData.PlayerID, OnClickFriend); } foreach (var _id in _dict.Keys) { m_RecentlyControl.AddCell(ScrollerDataType.Header, (int)_id, OnClickFriend); } } else if (friendModel.tempFriendData != null) { m_RecentlyControl.AddCell(ScrollerDataType.Header, (int)friendModel.tempFriendData.PlayerID, OnClickFriend); } m_RecentlyControl.Restart(); } private void OnClickFriend(CellView _cell) { if(_cell.index!= ChatCtrl.Inst.PteChatID) { ChatCtrl.Inst.PteChatID = _cell.index; m_RecentlyControl.m_Scorller.RefreshActiveCellViews(); } } private void RefreshFriendCntEvent(GroupType _type, bool arg2) { if (_type == GroupType.RecentContact) { DisplayRecently(); } } private void UpdatePlayer() { if (friendModel.tempFriendData != null) { ChatCtrl.Inst.PteChatID = (int)friendModel.tempFriendData.PlayerID; return; } var _dict = friendModel.GetFriendInfoDict((byte)GroupType.RecentContact); if (_dict != null && _dict.Count > 0) { ChatCtrl.Inst.PteChatID = (int)_dict.Keys.First(); } } } }