Files
JJBB/Assets/Project/Script/GUI/Chat/ChatEmojiLogic.cs

290 lines
8.7 KiB
C#
Raw Normal View History

2024-08-23 15:49:34 +08:00

using UnityEngine;
using UnityEngine.UI;
using System;
using System.Collections;
using System.Collections.Generic;
using Games.GlobeDefine;
using Games.ChatHistory;
using Games.Item;
using GCGame.Table;
using GCGame;
using Module.Log;
using Google.ProtocolBuffers;
using Games.Fellow;
public class ChatEmojiLogic : UIControllerBase<ChatEmojiLogic>
{
public static void ShowChatEmoji(InputField inputText, List<ChatLinkBase> chatLinks, ShowPosCallBack showPosCallback, CloseEmojiCallBack closeEmojiCallBack, float anchorLeft = 0, bool showHideBtn = true)
{
Hashtable hash = new Hashtable();
hash.Add("InputText", inputText);
hash.Add("ChatLinks", chatLinks);
hash.Add("ShowPosCallBack", showPosCallback);
hash.Add("CloseEmojiCallBack", closeEmojiCallBack);
hash.Add("AnchorLeft", anchorLeft);
hash.Add("ShowHideBtn", showHideBtn);
UIManager.ShowUI(UIInfo.ChatEmojiRoot, ShowChatEmojiOver, hash);
}
public static void ShowChatEmojiOver(bool isSucess, object param)
{
if (!isSucess)
return;
Hashtable hashParam = param as Hashtable;
ChatEmojiLogic.Instance().OnShowEmojiPanel((InputField)hashParam["InputText"], (List<ChatLinkBase>)hashParam["ChatLinks"], (ShowPosCallBack)hashParam["ShowPosCallBack"], (CloseEmojiCallBack)hashParam["CloseEmojiCallBack"]);
ChatEmojiLogic.Instance()._TranslateRect.SetSizeWithCurrentAnchors( RectTransform.Axis.Horizontal, ChatEmojiLogic.Instance()._BaseRect.rect.width - (float)hashParam["AnchorLeft"] - 24);
ChatEmojiLogic.Instance()._HideBtn.SetActive((bool)hashParam["ShowHideBtn"]);
bool onlyEmoji = (float)hashParam["AnchorLeft"] == 0;
if (onlyEmoji)
{
ChatEmojiLogic.Instance()._TagPanel._Tags[1].gameObject.SetActive(false);
ChatEmojiLogic.Instance()._TagPanel._Tags[2].gameObject.SetActive(false);
ChatEmojiLogic.Instance()._TagPanel._Tags[3].gameObject.SetActive(false);
}
else
{
ChatEmojiLogic.Instance()._TagPanel._Tags[1].gameObject.SetActive(true);
ChatEmojiLogic.Instance()._TagPanel._Tags[2].gameObject.SetActive(true);
ChatEmojiLogic.Instance()._TagPanel._Tags[3].gameObject.SetActive(true);
}
}
void OnEnable()
{
SetInstance(this);
}
void OnDisable()
{
SetInstance(null);
}
#region chat insert
private const int MAX_TEXTNUM = 128;
public UIContainerBase _InsertItemPage;
public UIContainerBase _InsertPetPage;
public GameObject _EmojiPanel;
public UIContainerBase _EmojiContainer;
public UITagPanel _TagPanel;
public RectTransform _BaseRect;
public RectTransform _TranslateRect;
public GameObject _HideBtn;
private InputField _InputText;
private List<ChatLinkBase> _ChatLinks = new List<ChatLinkBase>();
public delegate void ShowPosCallBack(string posStr);
private ShowPosCallBack _ShowPosCallBack;
public delegate void CloseEmojiCallBack();
private CloseEmojiCallBack _CloseEmojiCallBack;
public void OnShowEmojiPanel(InputField inputText, List<ChatLinkBase> chatLinks, ShowPosCallBack showPosCallBack, CloseEmojiCallBack closeEmojiCallBack)
{
if (inputText == null || _ChatLinks == null)
{
CloseWindow();
}
_CloseEmojiCallBack = closeEmojiCallBack;
_ShowPosCallBack = showPosCallBack;
_InputText = inputText;
_ChatLinks = chatLinks;
_TagPanel.ShowPage(0);
OnShowEmojiPage();
CancelInvoke();
}
public void CloseWindow()
{
UIManager.CloseUI(UIInfo.ChatEmojiRoot);
if (_CloseEmojiCallBack != null)
{
_CloseEmojiCallBack.Invoke();
}
}
public void OnEmojiClick(int emojiID)
{
var chatLink = ChatLinkBase.CreateChatLink(emojiID);
if (_InputText.text.Length + chatLink.StrInput.Length > _InputText.characterLimit)
{
return;
}
else
{
_ChatLinks.Add(chatLink);
chatLink.StartPosInText = _InputText.text.Length;
_InputText.text += chatLink.StrInput;
chatLink.EndPosInText = _InputText.text.Length;
}
}
public void OnShowLinkPage(int page)
{
switch (page)
{
case 0://表情页
OnShowEmojiPage();
break;
case 1:
OnShowPetPage();
break;
case 2://物品页
OnShowItemPage();
break;
case 3:
OnShowPos();
break;
}
}
public int _EmojiCnt = 30;
private bool _IsInit = false;
private void OnShowEmojiPage()
{
if (_IsInit)
return;
_IsInit = true;
List<int> emojiIds = new List<int>();
for (int i = 1; i < _EmojiCnt; ++i)
{
emojiIds.Add(i);
}
_EmojiContainer.InitContentItem(emojiIds, EmojiItemClick);
}
private void EmojiItemClick(object emojiGO)
{
int emojiID = (int)emojiGO;
OnEmojiClick(emojiID);
}
private void OnShowItemPage()
{
GameItemContainer EquipPack = GameManager.gameManager.PlayerDataPool.EquipPack;
List<GameItem> itemlist = ItemTool.ItemFilter(EquipPack, 0);
GameItemContainer MagicPack = GameManager.gameManager.PlayerDataPool.MagicPack;
foreach (var itemInfo in MagicPack.GetList())
{
if (itemInfo.IsValid())
{
itemlist.Add(itemInfo);
}
}
GameItemContainer AdvancePack = GameManager.gameManager.PlayerDataPool.AdvancePack;
foreach (var itemInfo in AdvancePack.GetList())
{
if (itemInfo.IsValid())
{
itemlist.Add(itemInfo);
}
}
GameItemContainer BackPack = GameManager.gameManager.PlayerDataPool.BackPack;
List<GameItem> backpackItems = ItemTool.ItemFilter(BackPack, 0);
itemlist.AddRange(backpackItems);
//foreach (var backItem in BackPack.GetList())
//{
// if (backItem.IsValid())
// {
// itemlist.Add(backItem);
// }
//}
if (null != itemlist)
{
_InsertItemPage.InitContentItem(itemlist, OnShowItemClick, null);
}
}
private void OnShowItemClick(object itemObj)
{
LogModule.DebugLog("OnShowItemClick");
GameItem gameItem = itemObj as GameItem;
if (gameItem == null)
return;
var chatLink = ChatLinkBase.CreateChatLink(gameItem);
if (_InputText.text.Length + chatLink.StrInput.Length > _InputText.characterLimit)
{
return;
}
else
{
_ChatLinks.Add(chatLink);
chatLink.StartPosInText = _InputText.text.Length;
_InputText.text += chatLink.StrInput;
chatLink.EndPosInText = _InputText.text.Length;
}
}
private void OnShowPetPage()
{
List<Fellow> pets = new List<Fellow>();
for (int i = 0; i < GameManager.gameManager.PlayerDataPool.FellowContainer.ContainerSize; i++)
{
Fellow pet = GameManager.gameManager.PlayerDataPool.FellowContainer.GetFellowByIndex(i);
if (pet.IsValid())
{
pets.Add(pet);
}
}
_InsertPetPage.InitContentItem(pets, OnShowPetClick);
}
private void OnShowPetClick(object itemObj)
{
LogModule.DebugLog("OnShowItemClick");
Fellow petInfo = itemObj as Fellow;
if (petInfo == null)
return;
var chatLink = ChatLinkBase.CreateChatLink(petInfo);
if (_InputText.text.Length + chatLink.StrInput.Length > _InputText.characterLimit)
{
return;
}
else
{
_ChatLinks.Add(chatLink);
chatLink.StartPosInText = _InputText.text.Length;
_InputText.text += chatLink.StrInput;
chatLink.EndPosInText = _InputText.text.Length;
}
}
public void OnShowPos()
{
if (Singleton<ObjManager>.GetInstance().MainPlayer == null)
return;
int sceneID = GameManager.gameManager.RunningScene;
var pos = Singleton<ObjManager>.GetInstance().MainPlayer.transform.localPosition;
int channel = SceneData.SceneInst + 1;
var chatLink = ChatLinkBase.CreateChatLink(sceneID, channel, pos);
string text = Utils.StrFilter_Chat(chatLink.StrSend);
if (_ShowPosCallBack != null)
{
_ShowPosCallBack(text);
}
}
#endregion
}