/// <summary> /// 添加最近私聊对象。 /// </summary> /// <param name="id">角色ID。</param> /// <param name="name">角色名称。</param> /// <param name="level">角色等级。 /// </param> public void AddRecentPrivateChat(long id, int prof, string name, int level) { RecentPrivateChatInfo info = GetRecentPrivateChat(id); bool add = info == null; if (add) { info = new RecentPrivateChatInfo(); info.RoleID = id; info.Prof = prof; mRecentPrivateChatList.Add(info); } info.Name = name; info.Level = level; info.AddTime = Time.realtimeSinceStartup; mRecentPrivateChatList.Sort(CompareRecentPrivateChat); if (mRecentPrivateChatList.Count > 10) { mRecentPrivateChatList.RemoveRange(10, mRecentPrivateChatList.Count - 10); } if (add) { TriggerEventAddRecent(); } }
/// <summary> /// 比较最近聊天列表(排序用)。 /// </summary> public static int CompareRecentPrivateChat(RecentPrivateChatInfo a, RecentPrivateChatInfo b) { //在线的排前面 if ((a.LastLoginTime == 0 && b.LastLoginTime != 0) || (a.LastLoginTime != 0 && b.LastLoginTime == 0)) { return(a.LastLoginTime == 0 ? -1 : 1); } return((int)(b.AddTime - a.AddTime)); }
/// <summary> /// 置顶最近私聊对象。 /// </summary> /// <param name="id">角色ID。</param> /// </param> public void TopRecentPrivateChat(long id) { RecentPrivateChatInfo info = GetRecentPrivateChat(id); if (info == null) { return; } info.AddTime = Time.realtimeSinceStartup; mRecentPrivateChatList.Sort(CompareRecentPrivateChat); }
/// <summary> /// 添加消息。 /// </summary> /// <param name="chat">消息内容。</param> private void AddMessage(ChatMessage chat) { //插入到频道消息集合 List <ChatMessage> msgs = null; if (chat.Channel == ChatChannel.CHAT_CHANNEL_WHISPER) { if (chat.Content != null) { if (!mPrivateMessage.TryGetValue(chat.SenderID, out msgs)) { msgs = new List <ChatMessage>(); mPrivateMessage.Add(chat.SenderID, msgs); } MsgData_sChat cdata = chat.Content; RecentPrivateChatInfo info = GetRecentPrivateChat(chat.SenderID); if (info == null) { AddRecentPrivateChat(chat.SenderID, cdata.SenderIcon, chat.SenderName, cdata.SenderLevel); } else { info.Name = chat.SenderName; info.Level = cdata.SenderLevel; } } else if (chat.ShowType == 1) { //MsgData_sChatSysNotice notice = chat.Notice; if (!mPrivateMessage.TryGetValue(LastPrivateChatID, out msgs)) { msgs = new List <ChatMessage>(); mPrivateMessage.Add(LastPrivateChatID, msgs); } } } else { if (!mChannelMessage.TryGetValue(chat.Channel, out msgs)) { msgs = new List <ChatMessage>(); mChannelMessage.Add(chat.Channel, msgs); } } if (msgs != null) { msgs.Insert(0, chat); if (msgs.Count > MessageCacheSize) { msgs.RemoveRange(MessageCacheSize, msgs.Count - MessageCacheSize); } } //所有消息列表 mAllMessage.Insert(0, chat); if (mAllMessage.Count > MessageCacheSize) { mAllMessage.RemoveRange(MessageCacheSize, mAllMessage.Count - MessageCacheSize); } }