using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Linq;
|
using UnityEngine;
|
namespace vnxbqy.UI
|
{
|
public class ChatRecently : MonoBehaviour
|
{
|
[SerializeField] ScrollerController m_RecentlyControl;
|
|
FriendsModel m_FriendModel;
|
FriendsModel friendModel
|
{
|
get
|
{
|
return m_FriendModel ?? (m_FriendModel = ModelCenter.Instance.GetModel<FriendsModel>());
|
}
|
}
|
|
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;
|
var _dict = friendModel.GetFriendInfoDict((byte)GroupType.RecentContact);
|
if (friendModel.tempFriendData != null
|
&& ChatCtrl.Inst.PteChatID == friendModel.tempFriendData.PlayerID)
|
{
|
ChatCtrl.Inst.PteChatName = friendModel.tempFriendData.PlayerName;
|
LanguageVerify.toPlayerLevel = friendModel.tempFriendData.LV;
|
}
|
else
|
{
|
ChatCtrl.Inst.PteChatName = _dict != null && _dict.ContainsKey((uint)ChatCtrl.Inst.PteChatID) ?
|
_dict[(uint)ChatCtrl.Inst.PteChatID].PlayerName : string.Empty;
|
LanguageVerify.toPlayerLevel = _dict != null && _dict.ContainsKey((uint)ChatCtrl.Inst.PteChatID) ?
|
_dict[(uint)ChatCtrl.Inst.PteChatID].LV : 0;
|
}
|
ChatCtrl.Inst.SelectRecentlyChat(ChatCtrl.Inst.PteChatID);
|
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;
|
ChatCtrl.Inst.PteChatName = friendModel.tempFriendData.PlayerName;
|
LanguageVerify.toPlayerLevel = friendModel.tempFriendData.LV;
|
ChatCtrl.Inst.SelectRecentlyChat(ChatCtrl.Inst.PteChatID);
|
return;
|
}
|
var _dict = friendModel.GetFriendInfoDict((byte)GroupType.RecentContact);
|
if (_dict != null && _dict.Count > 0)
|
{
|
ChatCtrl.Inst.PteChatID = (int)_dict.Keys.First();
|
ChatCtrl.Inst.PteChatName = _dict[(uint)ChatCtrl.Inst.PteChatID].PlayerName;
|
LanguageVerify.toPlayerLevel = _dict[(uint)ChatCtrl.Inst.PteChatID].LV;
|
ChatCtrl.Inst.SelectRecentlyChat(ChatCtrl.Inst.PteChatID);
|
}
|
}
|
}
|
}
|