151 lines
5.2 KiB
C#
151 lines
5.2 KiB
C#
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using Games.Item;
|
|||
|
using GCGame;
|
|||
|
using GCGame.Table;
|
|||
|
using Games.ChatHistory;
|
|||
|
|
|||
|
public class ChatLinkItem : ChatLinkBase
|
|||
|
{
|
|||
|
private ulong _ItemGuid;
|
|||
|
private int _ItemDataID;
|
|||
|
private ulong _SenderGuid;
|
|||
|
|
|||
|
public bool _ShowBlackColor = true;
|
|||
|
|
|||
|
private List<ChatInfoLinkMask> _LinkMasks = new List<ChatInfoLinkMask>();
|
|||
|
|
|||
|
public virtual void SetLinkItem(GameItem itemInfo)
|
|||
|
{
|
|||
|
string linkStr = "[" + itemInfo.GetName() + "]";
|
|||
|
_ItemGuid = itemInfo.Guid;
|
|||
|
_ItemDataID = itemInfo.DataID;
|
|||
|
|
|||
|
StrInput = linkStr;
|
|||
|
StrSend = StrSendStart + ((int)ChatLinkType.Item).ToString() + StrSplit + _ItemGuid + StrSplit + _ItemDataID + StrSendEnd;
|
|||
|
}
|
|||
|
|
|||
|
public override void SetLinkBySendStr(Text text, ChatHistoryItem chatHistory, string linkStr, string[] linkParams)
|
|||
|
{
|
|||
|
StrSend = linkStr;
|
|||
|
StrInput = linkStr;
|
|||
|
|
|||
|
if (linkParams.Length != 3)
|
|||
|
return;
|
|||
|
|
|||
|
_ItemGuid = ulong.Parse(linkParams[1]);
|
|||
|
_ItemDataID = int.Parse(linkParams[2]);
|
|||
|
_SenderGuid = chatHistory.SenderGuid;
|
|||
|
|
|||
|
var dataTab = TableManager.GetCommonItemByID(_ItemDataID, 0);
|
|||
|
if (dataTab != null)
|
|||
|
{
|
|||
|
StrShow = Utils.GetItemQualityName(dataTab.Quality, "[" + dataTab.Name + "]", _ShowBlackColor);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
public override void SetLinkAfterLayout(Text text)
|
|||
|
{
|
|||
|
base.SetLinkAfterLayout(text);
|
|||
|
ChatInfoLinkMask lastLinkImage = null;
|
|||
|
for (int i = StartPosInShowText; i < EndPosInShowText; ++i)
|
|||
|
{
|
|||
|
if (text.cachedTextGenerator.characters[i].charWidth == 0)
|
|||
|
continue;
|
|||
|
|
|||
|
if (lastLinkImage != null && Mathf.Abs( text.cachedTextGenerator.characters[i].cursorPos.y * _HeightFixed - lastLinkImage.rectTransform.anchoredPosition.y) < _TextHeightDelta)
|
|||
|
{
|
|||
|
lastLinkImage.rectTransform.sizeDelta += new Vector2(text.cachedTextGenerator.characters[i].charWidth, 0) * _WidthFixed;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
lastLinkImage = GetLinkImage(text);
|
|||
|
if (lastLinkImage == null)
|
|||
|
continue;
|
|||
|
lastLinkImage.Init(LinkClick, 0);
|
|||
|
|
|||
|
lastLinkImage.rectTransform.sizeDelta = new Vector2(text.cachedTextGenerator.characters[i].charWidth * _WidthFixed,
|
|||
|
text.fontSize * text.lineSpacing);
|
|||
|
lastLinkImage.rectTransform.anchoredPosition = new Vector2(text.cachedTextGenerator.characters[i].cursorPos.x * _WidthFixed,
|
|||
|
text.cachedTextGenerator.characters[i].cursorPos.y * _HeightFixed);
|
|||
|
|
|||
|
}
|
|||
|
lastLinkImage.gameObject.SetActive(true);
|
|||
|
lastLinkImage.ShowOutLine(LineColor, text.fontSize, text.color);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
protected ChatInfoLinkMask GetLinkImage(Text text)
|
|||
|
{
|
|||
|
ChatInfoLinkMask maskLink = null;
|
|||
|
GameObject maskObj = null;
|
|||
|
maskLink = ResourcePool.Instance.GetIdleUIItem<ChatInfoLinkMask>("CharLinkImage");
|
|||
|
if (maskLink != null)
|
|||
|
{
|
|||
|
maskObj = maskLink.gameObject;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
maskObj = ResourceManager.InstantiateResource("UI/CharLinkImage", "CharLinkImage") as GameObject;
|
|||
|
if (maskObj == null)
|
|||
|
return null;
|
|||
|
maskLink = maskObj.GetComponent<ChatInfoLinkMask>();
|
|||
|
}
|
|||
|
|
|||
|
//var emojiGO = GameObject.Instantiate(emoji) as GameObject;
|
|||
|
maskObj.transform.SetParent(text.transform);
|
|||
|
maskObj.transform.localScale = Vector3.one;
|
|||
|
maskObj.transform.localPosition = Vector3.zero;
|
|||
|
maskObj.transform.localRotation = Quaternion.Euler(Vector3.zero);
|
|||
|
maskObj.gameObject.SetActive(false);
|
|||
|
|
|||
|
_LinkMasks.Add(maskLink);
|
|||
|
return maskLink;
|
|||
|
}
|
|||
|
|
|||
|
protected virtual void LinkClick(int linkindex)
|
|||
|
{
|
|||
|
if (!Games.GlobeDefine.GlobeVar.IsGUIDValid(_ItemGuid))
|
|||
|
{
|
|||
|
ItemTooltipsLogic.ShowItemTooltip(_ItemDataID, ItemTooltipsLogic.ShowType.Info, Vector3.zero);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
ShowChatItemTooltips(_ItemGuid, _SenderGuid);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public static void ShowChatItemTooltips(ulong guid, ulong senderguid)
|
|||
|
{
|
|||
|
CG_REQ_SHOW_CHAT_APPENDIX_INFO packet = (CG_REQ_SHOW_CHAT_APPENDIX_INFO)PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_SHOW_CHAT_APPENDIX_INFO);
|
|||
|
packet.SetAppendixtype((int)CG_REQ_SHOW_CHAT_APPENDIX_INFO.TYPE.EQUIPMENT);
|
|||
|
packet.SetAppendixguid(guid);
|
|||
|
packet.SetRoleguid(senderguid);
|
|||
|
packet.SendPacket();
|
|||
|
}
|
|||
|
|
|||
|
public override void ClearLink()
|
|||
|
{
|
|||
|
base.ClearLink();
|
|||
|
|
|||
|
foreach (var maskLink in _LinkMasks)
|
|||
|
{
|
|||
|
//GameObject.Destroy(maskLink);
|
|||
|
maskLink.gameObject.SetActive(false);
|
|||
|
ResourcePool.Instance.RecvIldeUIItem(maskLink.gameObject);
|
|||
|
//ResourcePool.Instance.StartCoroutine(RevcEmojiObj(maskLink.gameObject));
|
|||
|
//_IdleLinkMasks.Push(maskLink);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//private IEnumerator RevcEmojiObj(GameObject revcObj)
|
|||
|
//{
|
|||
|
// yield return new WaitForFixedUpdate();
|
|||
|
// revcObj.transform.SetParent(ResourcePool.Instance.transform);
|
|||
|
//}
|
|||
|
}
|