361 lines
10 KiB
C#
361 lines
10 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine.UI;
|
|
using System.Linq;
|
|
using Games.ChatHistory;
|
|
using GCGame.Table;
|
|
using GCGame;
|
|
|
|
public class HornPanelCtr : MonoBehaviour
|
|
{
|
|
#region
|
|
|
|
public static void PopHornMessage(ChatHistoryItem history)
|
|
{
|
|
//if (HornPanelCtr.Instance)
|
|
//{
|
|
// HornPanelCtr.Instance.PopHornInfoToList(history/*'[' + history.SenderName + ']' + " : " + history.ChatInfo*/);
|
|
//}
|
|
//else
|
|
{
|
|
UIManager.ShowUI(UIInfo.HornPanel, delegate (bool bSucess, object param)
|
|
{
|
|
if (bSucess)
|
|
{
|
|
HornPanelCtr.Instance.PopHornInfoToList(history/*'[' + history.SenderName + ']' + " : " + history.ChatInfo*/);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
public static HornPanelCtr Instance;
|
|
public GameObject _NormalHorn;
|
|
public GameObject _CrossHorn;
|
|
public GameObject _AllHorn;
|
|
public Transform LandPosition; //初始化位
|
|
//private static float staPosY = 14.0f;
|
|
private bool isMoving = false;
|
|
void Awake()
|
|
{
|
|
Instance = this;
|
|
}
|
|
|
|
void OnEnable()
|
|
{
|
|
this.gameObject.transform.localPosition = Vector3.zero;
|
|
}
|
|
|
|
void OnDestroy()
|
|
{
|
|
Instance = null;
|
|
itemInfoList.Clear();
|
|
}
|
|
|
|
void SetLinksAfterLayout()
|
|
{
|
|
foreach (var link in _LinkLists)
|
|
{
|
|
link.SetLinkAfterLayout(MyShowText);
|
|
}
|
|
}
|
|
|
|
private List<ChatHistoryItem> itemInfoList = new List<ChatHistoryItem>();
|
|
public Text MyShowText;
|
|
protected string _ModifiedStr;
|
|
public void PopHornInfoToList(ChatHistoryItem info)
|
|
{
|
|
if(info._RedPacketID >= 0)
|
|
{
|
|
if (itemInfoList.Count == 0)
|
|
{
|
|
itemInfoList.Add(info);
|
|
}
|
|
else
|
|
{
|
|
itemInfoList.Insert(1, info);
|
|
}
|
|
}else
|
|
{
|
|
itemInfoList.Add(info);
|
|
}
|
|
//if (info._RedPacketID >= 0)
|
|
//{
|
|
// InitIcon(info);
|
|
// InfoList.Insert(0, _ModifiedStr);
|
|
//}
|
|
//else
|
|
//{
|
|
// InfoList.Add(_ModifiedStr); //缓存当前的喇叭信息
|
|
//}
|
|
|
|
if(!isMove) //当前没有信息滚动的时候创建
|
|
{
|
|
CreateHornInfo();
|
|
}
|
|
}
|
|
|
|
protected List<ChatLinkBase> _LinkLists = new List<ChatLinkBase>();
|
|
|
|
protected void ClearAllLinks()
|
|
{
|
|
foreach (var link in _LinkLists)
|
|
{
|
|
link.ClearLink();
|
|
var emojObj = link as ChatLinkEmoji;
|
|
if (emojObj != null)
|
|
emojObj.RemoveEmojiObj();
|
|
}
|
|
_LinkLists.Clear();
|
|
}
|
|
|
|
|
|
public bool _IsShowBlackColor = true;
|
|
void GetAllLinks(ChatHistoryItem history)
|
|
{
|
|
int checkPos = _ModifiedStr.IndexOf(ChatLinkBase.StrSendStart);
|
|
int checkEndPos = -1;
|
|
string checkStr = "";
|
|
while (checkPos >= 0)
|
|
{
|
|
checkEndPos = _ModifiedStr.IndexOf(ChatLinkBase.StrSendEnd, checkPos);
|
|
checkStr = _ModifiedStr.Substring(checkPos, checkEndPos - checkPos);
|
|
if (!string.IsNullOrEmpty(checkStr))
|
|
{
|
|
var chatLink = ChatLinkBase.CreateChatLinkBySendStr(MyShowText, history, checkStr, _IsShowBlackColor);
|
|
chatLink.StartPosInText = checkPos;
|
|
chatLink.EndPosInText = checkEndPos;
|
|
_LinkLists.Add(chatLink);
|
|
}
|
|
|
|
checkPos = _ModifiedStr.IndexOf(ChatLinkBase.StrSendStart, checkEndPos);
|
|
}
|
|
}
|
|
|
|
protected string GetLinkedStr(ChatHistoryItem history)
|
|
{
|
|
int subStrStart = 0;
|
|
int subStrEnd = 0;
|
|
int newInputEnd = 0;
|
|
string newInputText = "";
|
|
for (int i = 0; i < _LinkLists.Count; ++i)
|
|
{
|
|
if (i > 0)
|
|
{
|
|
subStrStart = _LinkLists[i - 1].EndPosInText + 1;
|
|
}
|
|
subStrEnd = _LinkLists[i].StartPosInText;
|
|
|
|
if (subStrEnd > subStrStart)
|
|
{
|
|
newInputText += _ModifiedStr.Substring(subStrStart, subStrEnd - subStrStart);
|
|
}
|
|
_LinkLists[i].StartPosInShowText = newInputText.Length;
|
|
newInputText += _LinkLists[i].StrShow;
|
|
newInputEnd = _LinkLists[i].EndPosInText + 1;
|
|
_LinkLists[i].EndPosInShowText = newInputText.Length;
|
|
}
|
|
newInputText += _ModifiedStr.Substring(newInputEnd, _ModifiedStr.Length - newInputEnd);
|
|
|
|
return newInputText;
|
|
}
|
|
|
|
//初始化的时候取List
|
|
//void OnEnable()
|
|
//{
|
|
// this.gameObject.transform.position = new Vector3(0, 231, 0);
|
|
//}
|
|
|
|
void CreateHornInfo()
|
|
{
|
|
_ModifiedStr = "";
|
|
if (itemInfoList.Count > 0)
|
|
{
|
|
totalDis = 0f;
|
|
if (!itemInfoList[0].IsSystem)
|
|
{
|
|
if(itemInfoList[0].EChannel == GC_CHAT.CHATTYPE.CHAT_TYPE_ALLSERSPEAKER
|
|
|| itemInfoList[0].EChannel == GC_CHAT.CHATTYPE.CHAT_TYPE_CROSSSERSPEAKER)
|
|
_ModifiedStr = "[" + itemInfoList[0].ServerName + "·" + itemInfoList[0].SenderName + "]" + ":" + itemInfoList[0].ChatInfo;
|
|
else
|
|
_ModifiedStr = "[" + itemInfoList[0].SenderName + "]" + ":" + itemInfoList[0].ChatInfo;
|
|
}
|
|
else
|
|
_ModifiedStr = "[" + StrDictionary.GetClientDictionaryString("#{5213}") + "]:" + itemInfoList[0].ChatInfo;
|
|
ClearAllLinks();
|
|
InitHornIcon(itemInfoList[0].EChannel);
|
|
GetAllLinks(itemInfoList[0]);
|
|
_ModifiedStr = GetLinkedStr(itemInfoList[0]);
|
|
SetPrivilegeVIPIcon(itemInfoList[0]);
|
|
SetVIPIcon(itemInfoList[0]);
|
|
itemInfoList.RemoveAt(0);
|
|
}
|
|
else
|
|
{
|
|
OnMoveEnd();
|
|
}
|
|
if(_ModifiedStr == null)
|
|
{
|
|
return;
|
|
}
|
|
//初始化位置
|
|
MyShowText.transform.localPosition = new Vector3(LandPosition.localPosition.x, 0, 0);
|
|
_ModifiedStr = _ModifiedStr.Replace("\n", " ").Replace("\t", " ").Replace("\r", " ");
|
|
MyShowText.text = _ModifiedStr;
|
|
|
|
MoveToTargetPos(); //开始移动
|
|
}
|
|
|
|
public void InitHornIcon(GC_CHAT.CHATTYPE type)
|
|
{
|
|
_NormalHorn.SetActive(type != GC_CHAT.CHATTYPE.CHAT_TYPE_ALLSERSPEAKER && type != GC_CHAT.CHATTYPE.CHAT_TYPE_CROSSSERSPEAKER);
|
|
_CrossHorn.SetActive(type == GC_CHAT.CHATTYPE.CHAT_TYPE_CROSSSERSPEAKER);
|
|
_AllHorn.SetActive(type == GC_CHAT.CHATTYPE.CHAT_TYPE_ALLSERSPEAKER);
|
|
}
|
|
|
|
private bool isMove = false;
|
|
private Vector3 endPos = Vector3.zero;
|
|
public Image ShowPanelBG;
|
|
void MoveToTargetPos()
|
|
{
|
|
isMove = true;
|
|
//计算终止位置
|
|
endPos = new Vector3(LandPosition.position.x - MyShowText.rectTransform.sizeDelta.x - ShowPanelBG.rectTransform.sizeDelta.x, 0);
|
|
}
|
|
|
|
private float dis = 0f;
|
|
public float MoveSpeed = 50f;
|
|
private float totalDis = 0f;
|
|
private float totalRunTime = 0.0f;
|
|
|
|
//1.五秒时间 2.跑完
|
|
public void OnMoveEndOrOutOfTime()
|
|
{
|
|
if (totalDis >= (MyShowText.rectTransform.sizeDelta.x + ShowPanelBG.rectTransform.sizeDelta.x)
|
|
|| totalRunTime >= 5.0f)
|
|
{
|
|
if(itemInfoList.Count > 0)
|
|
{
|
|
dis = 0.0f;
|
|
totalDis = 0.0f;
|
|
totalRunTime = 0.0f;
|
|
CreateHornInfo();
|
|
}else
|
|
{
|
|
if(totalDis >= (MyShowText.rectTransform.sizeDelta.x + ShowPanelBG.rectTransform.sizeDelta.x))
|
|
{
|
|
isMove = false;
|
|
OnMoveEnd();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if(isMove)
|
|
{
|
|
dis = MoveSpeed * Time.deltaTime;
|
|
totalRunTime += Time.deltaTime;
|
|
totalDis += dis;
|
|
MyShowText.transform.localPosition = new Vector3(MyShowText.transform.localPosition.x - dis, 0, 0);
|
|
|
|
//判断当前的状态
|
|
OnMoveEndOrOutOfTime();
|
|
|
|
if(totalDis >= (MyShowText.rectTransform.sizeDelta.x + ShowPanelBG.rectTransform.sizeDelta.x))
|
|
{
|
|
isMove = false;
|
|
totalDis = 0f;
|
|
//关闭当前的窗口
|
|
OnMoveEnd();
|
|
}
|
|
}
|
|
|
|
if (MyShowText.cachedTextGeneratorForLayout.characterCountVisible > 0)
|
|
{
|
|
//SetBGWidth();
|
|
SetLinksAfterLayout();
|
|
}
|
|
}
|
|
|
|
void OnMoveEnd()
|
|
{
|
|
UIManager.CloseUI(UIInfo.HornPanel); //滚屏结束关闭当前的Tip
|
|
}
|
|
|
|
#region red packet
|
|
|
|
public GameObject _NormalIcon;
|
|
public GameObject _RedPacketIcon;
|
|
|
|
private ChatHistoryItem _RedPacketHistory;
|
|
|
|
public void InitIcon(ChatHistoryItem chatHistory)
|
|
{
|
|
if (chatHistory._RedPacketID >= 0)
|
|
{
|
|
_RedPacketIcon.gameObject.SetActive(true);
|
|
_NormalIcon.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
_RedPacketIcon.gameObject.SetActive(false);
|
|
_NormalIcon.gameObject.SetActive(true);
|
|
}
|
|
_RedPacketHistory = chatHistory;
|
|
}
|
|
|
|
public void OnBtnRedPacket()
|
|
{
|
|
if (_RedPacketHistory == null)
|
|
return;
|
|
RedPacket.Instance.PickRedPacket(_RedPacketHistory._RedPacketID, _RedPacketHistory._RedPacketType);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region vipIcon
|
|
|
|
public Image _PrivilegeVipIcon;
|
|
public Image _VipIcon;
|
|
|
|
private void SetPrivilegeVIPIcon(ChatHistoryItem chatItem)
|
|
{
|
|
if (_PrivilegeVipIcon == null)
|
|
return;
|
|
|
|
string priVipIcon = Utils.GetPrivilegeVipIcon(chatItem.SenderPrivilegeVIP);
|
|
if (string.IsNullOrEmpty(priVipIcon))
|
|
{
|
|
_PrivilegeVipIcon.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
_PrivilegeVipIcon.gameObject.SetActive(true);
|
|
LoadAssetBundle.Instance.SetImageSprite(_PrivilegeVipIcon, priVipIcon);
|
|
}
|
|
}
|
|
|
|
private void SetVIPIcon(ChatHistoryItem chatItem)
|
|
{
|
|
if (_VipIcon == null)
|
|
return;
|
|
|
|
string vipIcon = Utils.GetVipIcon(chatItem.SenderVIPLevel);
|
|
if (string.IsNullOrEmpty(vipIcon))
|
|
{
|
|
_VipIcon.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
_VipIcon.gameObject.SetActive(true);
|
|
LoadAssetBundle.Instance.SetImageSprite(_VipIcon, vipIcon);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|