You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.5 KiB
95 lines
2.5 KiB
4 years ago
|
using UnityEngine.UI;
|
||
|
using UnityEngine;
|
||
|
using System;
|
||
|
using AX.NetworkSystem;
|
||
|
|
||
|
using Assets.Scripts.Common.ChatSystem;
|
||
|
using AX.MessageSystem;
|
||
|
|
||
|
public class UserInfoItemView : MonoBehaviour
|
||
|
{
|
||
|
public Text UserName;
|
||
|
public Text UserRole;
|
||
|
public Toggle Selected;
|
||
|
public GameObject UnRead;
|
||
|
public Text UnReadText;
|
||
|
private UserInfoItemViewModel data;
|
||
|
private PrivateChatPanel parentView;
|
||
|
|
||
|
private void OnEnable()
|
||
|
{
|
||
|
Selected.onValueChanged.AddListener(SelectedUser);
|
||
|
}
|
||
|
private void OnDisable()
|
||
|
{
|
||
|
Selected.onValueChanged.RemoveListener(SelectedUser);
|
||
|
}
|
||
|
private void SelectedUser(bool isOn)
|
||
|
{
|
||
|
data.IsSelected = isOn;
|
||
|
if (isOn)
|
||
|
{
|
||
|
//切换频道,刷新
|
||
|
parentView.SetCurrentChannel(data.ChannelId);
|
||
|
//查看频道是否已经被创建
|
||
|
bool check = ChatManager.Instance.CheckChannel(data.ChannelId);
|
||
|
if (!check)
|
||
|
{
|
||
|
//发送创建频道消息
|
||
|
ChatManager.Instance.CreatePrivateChatChannel(data.UserInfo);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
//刷新聊天框
|
||
|
parentView.RefreshChatLoopList();
|
||
|
}
|
||
|
SetUnReadCount(null);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
parentView.SetCurrentChannel(-1);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
internal void SetItemData(UserInfoItemViewModel itemData)
|
||
|
{
|
||
|
data = itemData;
|
||
|
UserName.text = data.UserInfo.UserInfo.RealName;
|
||
|
UserRole.text = data.UserInfo.Role.ToString();
|
||
|
Selected.isOn = data.IsSelected;
|
||
|
SetUnReadCount(null);
|
||
|
}
|
||
|
|
||
|
internal void Init(PrivateChatPanel privateChatPanel)
|
||
|
{
|
||
|
parentView = privateChatPanel;
|
||
|
MessageDispatcher.AddListener("REFRESH_UNREAD_MSG", SetUnReadCount);
|
||
|
}
|
||
|
private void OnDestroy()
|
||
|
{
|
||
|
MessageDispatcher.RemoveListener("REFRESH_UNREAD_MSG", SetUnReadCount);
|
||
|
}
|
||
|
private void SetUnReadCount(IMessage obj)
|
||
|
{
|
||
|
if (data.IsSelected && parentView.gameObject.activeSelf)
|
||
|
{
|
||
|
//设置消息全部已读
|
||
|
ChatManager.Instance.ClearUnReadMsgByChannelId(data.ChannelId);
|
||
|
}
|
||
|
int unreadCount = ChatManager.Instance.GetUnReadMsgsCount(data.ChannelId);
|
||
|
UnReadText.text = unreadCount.ToString();
|
||
|
if (unreadCount > 0)
|
||
|
{
|
||
|
UnRead.SetActive(true);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
UnRead.SetActive(false);
|
||
|
}
|
||
|
}
|
||
|
public UserData GetItemUserData()
|
||
|
{
|
||
|
return data.UserInfo;
|
||
|
}
|
||
|
}
|