Files
JJBB/Assets/Project/Script/GUI/FriendAndMail/FriendRootLogic.cs
2024-08-23 15:49:34 +08:00

612 lines
20 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using GCGame.Table;
using System;
using Games.GlobeDefine;
using Games.ChatHistory;
using GCGame;
using Module.Log;
public class FriendRootLogic : MonoBehaviour
{
void Awake()
{
_FriendTags = new List<string>(){
StrDictionary.GetClientDictionaryString("#{5200}"), //最近
StrDictionary.GetClientDictionaryString("#{5201}"), //联系人
StrDictionary.GetClientDictionaryString("#{5202}"), //添加
};
}
void OnEnable()
{
InitFriends(); //初始化好友
InitTag(); //初始化标签
GUIData.delFriendDataUpdate += UpdateBySelect; //
GUIData.delPlayerFindResult += FindPlayerResult; //
UpdateCheckTip();
}
void OnDisable()
{
GUIData.delFriendDataUpdate -= UpdateBySelect;
GUIData.delPlayerFindResult -= FindPlayerResult;
}
/// <summary>
/// 初始化标签
/// </summary>
void InitTag()
{
_TagPanel.ShowPage(0);
UpdateTell();
HideChat();
}
public void OnShowPage(int page)
{
switch (page)
{
case 0:
curType = GC_CHAT.CHATTYPE.CHAT_TYPE_TELL;
HideChat();
UpdateTell();
break;
case 1:
curType = GC_CHAT.CHATTYPE.CHAT_TYPE_FRIEND;
HideChat();
UpdateBySelect();
break;
case 2:
InitSearch();
_ChatPanel.SetActive(false);
_NoneChatPanel.SetActive(false);
break;
}
}
#region friend List
public UITagPanel _TagPanel;
public GameObject _FriendListPanel;
public GameObject _SearchPanel;
public UIContainerSelect _FriendContainer;
public UIContainerSelect _ChatFriends;
public GameObject _FriendClassPanel;
public Text _SelectGroupName;
private int _SelectedGroupIdx = 0;
private ulong _SelectedGuid;
private FriendChat _SelectChat;
private List<string> _FriendTags;
private bool _IsInitFriendClass = false;
/// <summary>
/// 初始化好友
/// </summary>
public void InitFriends()
{
//UpdateTell();
ReqUpdateFriendUserInfo();
}
void ReqUpdateFriendUserInfo()
{
if (null != Singleton<ObjManager>.GetInstance().MainPlayer)
{
CG_REQ_FRIEND_USERINFO packet = (CG_REQ_FRIEND_USERINFO)PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_FRIEND_USERINFO);
packet.Guid = GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Guid;
packet.SendPacket();
}
}
public void UpdateFriend()
{
if (_TagPanel.GetShowingPage() == 1)
{
if (!_FriendContainer.isActiveAndEnabled)
return;
// 好友排序
GameManager.gameManager.PlayerDataPool.FriendList.SortRelation();
List<Relation> _FriendList = new List<Relation>();
foreach (KeyValuePair<UInt64, Relation> _relation in GameManager.gameManager.PlayerDataPool.FriendList.RelationDataList)
{
if (!string.IsNullOrEmpty(_relation.Value.Name))
{
_FriendList.Add(_relation.Value);
}
}
_FriendContainer.InitSelectContent(_FriendList, null, ChatWithFriend);
}
else if (_TagPanel.GetShowingPage() == 2)
{
InitSearch();
}
}
public void UpdateGuild()
{
if (!_FriendContainer.isActiveAndEnabled)
return;
GameManager.gameManager.PlayerDataPool.GuildFriendList.SortByRelationState((int)CharacterDefine.RELATION_TYPE.ONLINE);
//先排在线的
List<Relation> _FriendList = new List<Relation>();
foreach (KeyValuePair<UInt64, Relation> _relation in GameManager.gameManager.PlayerDataPool.GuildFriendList.RelationDataList)
{
if (!string.IsNullOrEmpty(_relation.Value.Name))
{
_FriendList.Add(_relation.Value);
}
}
_FriendContainer.InitSelectContent(_FriendList, null, ChatWithFriend);
}
public void UpdateBlack()
{
if (!_FriendContainer.isActiveAndEnabled)
return;
_FriendContainer.InitSelectContent(GameManager.gameManager.PlayerDataPool.BlackList.RelationDataList.Values, null, ChatWithFriend);
}
public void UpdateHate()
{
if (!_FriendContainer.gameObject.activeInHierarchy)
return;
_FriendContainer.InitSelectContent(GameManager.gameManager.PlayerDataPool.HateList.RelationDataList.Values, null, ChatWithFriend);
}
public void UpdateTell()
{
if (!_ChatFriends.gameObject.activeInHierarchy)
return;
//_ChatFriends.InitSelectContent(GameManager.gameManager.PlayerDataPool.ChatHistory.FriendChatList, null, ChatWithFriend);//初始化
#region 线线
CG_REQ_LAST_CONTACT packet = (CG_REQ_LAST_CONTACT)PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_LAST_CONTACT);
List<ulong> friendGuids = new List<ulong>();
foreach (var friendInfo in GameManager.gameManager.PlayerDataPool.ChatHistory.FriendChatList)
{
if (GlobeVar.IsGUIDValid(friendInfo.ChatGuid))
{
packet.AddGuid(friendInfo.ChatGuid);
}
}
packet.SendPacket(); //发送状态(在线 离线)
#endregion
}
public void UpdateTell(GC_RET_LAST_CONTACT packet)
{
for (int i = 0; i < packet.guidCount; ++i)
{
var friendInfo = GameManager.gameManager.PlayerDataPool.ChatHistory.FriendChatList.Find((chatInfo) =>
{
if (chatInfo.ChatGuid == packet.GetGuid(i) )
{
return true; //显示最近联系的好友
}
return false;
});
if (friendInfo == null)
continue;
friendInfo.OnlineState = packet.GetState(i);
if (friendInfo.OnlineState != (int)CharacterDefine.RELATION_TYPE.OFFLINE)
{
friendInfo.ChatName = packet.GetName(i);
friendInfo.ChatLevel = packet.GetLevel(i);
friendInfo.ChatIcon = Utils.GetProfessionSpriteName(packet.GetProf(i));
friendInfo.ChatCombat = packet.GetCombat(i);
}
}
_ChatFriends.InitSelectContent(GameManager.gameManager.PlayerDataPool.ChatHistory.FriendChatList, null, ChatWithFriend);
}
private void UpdateBySelect()
{
if (_TagPanel.GetShowingPage() == 1)
RefreshList(_SelectedGroupIdx);
else if (_TagPanel.GetShowingPage() == 2)
{
_ApplyContainer.InitContentItem(GameManager.gameManager.PlayerDataPool.FriendApplyList.RelationDataList.Values);
_SearchContainer.RefreshItems();
}
}
public void UpdateChatFriendInfo(GC_RET_OTHER_ROLE_BASE_INFO packet)
{
UpdateChatingPlayer(packet);
FriendChat friendInfo = GameManager.gameManager.PlayerDataPool.ChatHistory.GetFriendChat(packet.Guid);
if (friendInfo != null)
{
if (friendInfo.ChatLevel != packet.Lvl)
{
friendInfo.ChatLevel = packet.Lvl;
if (!_ChatFriends.gameObject.activeInHierarchy)
return;
_ChatFriends.InitSelectContent(GameManager.gameManager.PlayerDataPool.ChatHistory.FriendChatList,
new List<FriendChat>() { friendInfo }, ChatWithFriend);
}
}
}
public void ClearChat()
{
if (_SelectChat == null)
return;
MessageBoxLogic.OpenOKCancelBox(StrDictionary.GetClientDictionaryString("#{5210}", _SelectChat.ChatName), "", ClearChatOK);
}
public void ClearChatOK()
{
if (_SelectChat == null)
return;
//GameManager.gameManager.PlayerDataPool.ChatHistory.FriendChatList.Remove(_SelectedGuid);
_SelectChat.ClearChatRecord();
UpdateTell();
_ChatHistoryLogic.ClearHistory();
}
public void OnBtnClassShow()
{
_FriendClassPanel.SetActive(true);
}
public void OnBtnClassHide()
{
_FriendClassPanel.SetActive(false);
}
public void OnBtnClassSelect(int select)
{
RefreshList(select);
OnBtnClassHide();
}
public void RefreshList(int select)
{
_SelectedGroupIdx = select;
switch (select)
{
case 0:
_SelectGroupName.text = StrDictionary.GetClientDictionaryString("#{5207}");
UpdateFriend();
break;
//case 1:
// _SelectGroupName.text = StrDictionary.GetClientDictionaryString("#{5208}");
// UpdateGuild();
// break;
case 2:
_SelectGroupName.text = StrDictionary.GetClientDictionaryString("#{5209}");
UpdateHate();
break;
case 3:
_SelectGroupName.text = StrDictionary.GetClientDictionaryString("#{1056}");
UpdateBlack();
break;
}
}
#endregion
#region chat
public Text _WarningText;
public Text _ChatWithName;
public Text _ChatWithFriendValue;
public ChatInputLogic _ChatInputLogic;
public ChatHistoryLogic _ChatHistoryLogic;
public GameObject _ChatPanel;
public GameObject _NoneChatPanel;
public Text _FriendPont;
private GC_CHAT.CHATTYPE curType = GC_CHAT.CHATTYPE.CHAT_TYPE_TELL;
private void Start()
{
InitWarning();
}
public void InitWarning()
{
_WarningText.text = StrDictionary.GetClientDictionaryString("#{79216}");
}
public void ChatWithFriend(object friendGO)
{
Relation relationData = friendGO as Relation;
if (relationData != null)
{
if (relationData.Guid == 0)
{
_FriendPont.text = "";
_ChatInputLogic.gameObject.SetActive(false);
}
else if (relationData.Guid == 1)
{
_FriendPont.text = "";
_ChatInputLogic.gameObject.SetActive(false);
UIManager.ShowUI(UIInfo.ChatHelperRoot);
FriendAndMailRoot.Instance().CloseWindow();
}
else
{
//数据没刷新的问题
var friendPoint = 0;
if (GameManager.gameManager.PlayerDataPool.FriendList.RelationDataList.ContainsKey(relationData.Guid))
{
friendPoint = GameManager.gameManager.PlayerDataPool.FriendList.RelationDataList[relationData.Guid].FriendPoint;
}
_FriendPont.text = StrDictionary.GetClientDictionaryString("#{5221}", friendPoint);
_ChatInputLogic.gameObject.SetActive(true);
}
ChatWithFriend(relationData.Guid, relationData.Name);
_SelectChat = GameManager.gameManager.PlayerDataPool.ChatHistory.GetFriendChat(relationData.Guid);
return;
}
FriendChat friendChat = friendGO as FriendChat;
if (friendChat != null)
{
_SelectChat = friendChat;
if (friendChat.ChatGuid == 0)
{
_FriendPont.text = "";
_ChatInputLogic.gameObject.SetActive(false);
}
else if (friendChat.ChatGuid == 1)
{
_FriendPont.text = "";
_ChatInputLogic.gameObject.SetActive(false);
UIManager.ShowUI(UIInfo.ChatHelperRoot);
FriendAndMailRoot.Instance().CloseWindow();
}
else
{
int friendPoint = 1;
if (GameManager.gameManager.PlayerDataPool.FriendList.RelationDataList.ContainsKey(friendChat.ChatGuid))
{
friendPoint = GameManager.gameManager.PlayerDataPool.FriendList.RelationDataList[friendChat.ChatGuid].FriendPoint;
}
_FriendPont.text = StrDictionary.GetClientDictionaryString("#{5221}", friendPoint.ToString());
_ChatInputLogic.gameObject.SetActive(true);
}
ChatWithFriend(friendChat.ChatGuid, friendChat.ChatName);
return;
}
}
public void ShowUIChat(UInt64 guid, string name, string icon, int level)
{
_SelectChat = GameManager.gameManager.PlayerDataPool.ChatHistory.GetFriendChat(guid);
if (_SelectChat == null)
{
_SelectChat = new FriendChat();
_SelectChat.ChatGuid = guid;
CG_REQ_OTHER_ROLE_BASE_INFO askPak = (CG_REQ_OTHER_ROLE_BASE_INFO)PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_OTHER_ROLE_BASE_INFO);
askPak.SetGuid(guid);
askPak.SendPacket();
}
else
{
_ChatFriends.SetSelect(new List<FriendChat>() { _SelectChat });
ChatWithFriend(guid, name);
}
}
public void UpdateChatingPlayer(GC_RET_OTHER_ROLE_BASE_INFO playerInfo)
{
if (_SelectChat == null)
return;
if (_SelectChat.ChatGuid == playerInfo.Guid)
{
GameManager.gameManager.PlayerDataPool.ChatHistory.AddFriendChat(playerInfo.Guid, playerInfo.Rolename,
GCGame.Utils.GetProfessionSpriteName(playerInfo.Prof), playerInfo.Lvl, playerInfo.Guid, 0, 0, null);
ChatWithFriend(playerInfo.Guid, playerInfo.Rolename);
}
}
public void ChatWithFriend(UInt64 guid, string name)
{
_SelectedGuid = guid;
_ChatPanel.SetActive(true);
_NoneChatPanel.SetActive(false);
if (guid == 0 || guid == 1)
{
_ChatWithName.text = "";
}
else
{
_ChatWithName.text = StrDictionary.GetClientDictionaryString("#{5203}", name);
}
_ChatInputLogic.SetCurChannelType((int)curType);
_ChatInputLogic.FriendChatReceiverGuid = guid;
_ChatInputLogic.FriendChatReceiverName = name;
_ChatHistoryLogic.ShowHistory(guid);
}
public void HideChat()
{
_ChatPanel.SetActive(false);
_NoneChatPanel.SetActive(true);
}
public void OnReceiveChat()
{
_ChatHistoryLogic.OnReceiveChat();
int HistoryCount = GameManager.gameManager.PlayerDataPool.ChatHistory.ChatHistoryList.Count;
ChatHistoryItem LastHistory = GameManager.gameManager.PlayerDataPool.ChatHistory.ChatHistoryList[HistoryCount - 1];
if ((LastHistory.EChannel == GC_CHAT.CHATTYPE.CHAT_TYPE_FRIEND
|| LastHistory.EChannel == GC_CHAT.CHATTYPE.CHAT_TYPE_TELL
|| LastHistory.EChannel == (GC_CHAT.CHATTYPE)CG_CHAT.CHATTYPE.CHAT_TYPE_FRIEND_GUILD))
{
if (GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Guid != LastHistory.SenderGuid)
{
_ChatFriends.ForeachActiveItem<FriendChatItem>(
(item) =>
{
if (item.ChaterGuid == LastHistory.SenderGuid)
{
item.Refresh();
}
});
// - old -
//_ChatFriends.RefreshItems();
// - --- -
}
}
//_ChatFriends.RefreshItems();
if (_SelectChat != null)
_SelectChat.SetNewRecordChecked(true);
}
#endregion
#region findFriend
public UIContainerBase _ApplyContainer;
public UIContainerBase _SearchContainer;
public GameObject _FindNoneObj;
public InputField _NameInput;
public UIButtonTime _BtnSearchTime;
public void InitSearch()
{
_ApplyContainer.InitContentItem(GameManager.gameManager.PlayerDataPool.FriendApplyList.RelationDataList.Values);
_NameInput.text = "";
_SearchContainer.InitContentItem(null);
_FindNoneObj.SetActive(false);
GameManager.gameManager.PlayerDataPool.NewApplyCheck = false;
FriendAndMailRoot.Instance().UpdateRedCheck();
ChatFrameLogic.Instance().UpdateRedDotTip();
UpdateCheckTip();
}
public void SearchPlayer()
{
CG_FINDPLAYER msg = (CG_FINDPLAYER)PacketDistributed.CreatePacket(MessageID.PACKET_CG_FINDPLAYER);
msg.Guid = 0;
msg.Name = "";
ulong guid = 0;
//if (ulong.TryParse(_NameInput.text, out guid))
//{
// msg.Guid = guid;
//}
//else
{
msg.Name = _NameInput.text;
}
LogModule.DebugLog("Find player guid:" + guid + ", Name:" + msg.Name);
msg.SendPacket();
_BtnSearchTime.SetBtnDisableTime(3);
}
public void ClearApply()
{
if (GameManager.gameManager.PlayerDataPool.FriendApplyList.RelationDataList.Count == 0)
return;
CG_CLEAN_ADD_FRIEND_APPLY_LIST msg = (CG_CLEAN_ADD_FRIEND_APPLY_LIST)PacketDistributed.CreatePacket(MessageID.PACKET_CG_CLEAN_ADD_FRIEND_APPLY_LIST);
msg.ByteFlag = 1;
msg.SendPacket();
GameManager.gameManager.PlayerDataPool.FriendApplyList.RelationDataList.Clear();
UpdateBySelect();
GameManager.gameManager.PlayerDataPool.NewApplyCheck = false;
UpdateCheckTip();
}
public void FindPlayerResult(GC_FINDPLAYER packet)
{
List<Relation> findRelation = new List<Relation>();
for (int i = 0; i < packet.guidCount; ++i)
{
Relation relation = new Relation();
relation.Guid = packet.guidList[i];
relation.Name = packet.NameList[i];
relation.Level = packet.LevelList[i];
relation.Profession = packet.ProfList[i];
relation.State = packet.stateList[i];
findRelation.Add(relation);
}
if (findRelation.Count > 0)
{
_FindNoneObj.SetActive(false);
_SearchContainer.InitContentItem(findRelation);
}
else
{
_FindNoneObj.SetActive(true);
_SearchContainer.InitContentItem(null);
}
}
#endregion
#region red dot tips
public GameObject _NewMessageTip;
public Text _NewMessageCountText;
public GameObject _NewApplyTip;
public Text _NewApplyCountText;
public void UpdateCheckTip()
{
if (GameManager.gameManager.PlayerDataPool.ChatHistory.IsHaveUnCheckChat())
{
_NewMessageTip.SetActive(true);
var newMessageCount = GameManager.gameManager.PlayerDataPool.ChatHistory.GetAllUnCheckedChatCount();
_NewMessageCountText.text = (newMessageCount >= 99 ? 99 : newMessageCount).ToString();
}
else
{
_NewMessageTip.SetActive(false);
}
if (GameManager.gameManager.PlayerDataPool.NewApplyCheck
&& GameManager.gameManager.PlayerDataPool.GetNewApplyListCount() > 0)
{
_NewApplyTip.SetActive(true);
var newApplyCount = GameManager.gameManager.PlayerDataPool.GetNewApplyListCount();
_NewApplyCountText.text = (newApplyCount >= 99 ? 99 : newApplyCount).ToString();
}
else
{
_NewApplyTip.SetActive(false);
}
_ChatFriends.RefreshItems();
}
#endregion
}