68 lines
2.3 KiB
C#
68 lines
2.3 KiB
C#
using BrewMonster.Scripts.Task.UI;
|
|
using BrewMonster.Scripts.UI;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.EventSystems;
|
|
using BrewMonster.Network;
|
|
using CSNetwork.GPDataType;
|
|
|
|
namespace BrewMonster.Scripts.ChatUI
|
|
{
|
|
public class ChatMessageView : MonoBehaviour, IPointerClickHandler
|
|
{
|
|
public Image iconImage;
|
|
public EC_UIUtility.TextOutlet messageText;
|
|
|
|
public void Bind(Sprite iconSprite, string message)
|
|
{
|
|
if (iconImage == null)
|
|
{
|
|
iconImage = GetComponent<Image>();
|
|
}
|
|
|
|
iconImage.sprite = iconSprite;
|
|
iconImage.enabled = iconSprite != null;
|
|
|
|
messageText.Set(message);
|
|
GetComponent<IRefreshLayout>().RefreshLayout();
|
|
}
|
|
|
|
public void OnPointerClick(PointerEventData eventData)
|
|
{
|
|
if (messageText == null || messageText.tmp == null) return;
|
|
|
|
int linkIndex = TMP_TextUtilities.FindIntersectingLink(messageText.tmp, eventData.position, eventData.pressEventCamera);
|
|
if (linkIndex != -1)
|
|
{
|
|
TMP_LinkInfo linkInfo = messageText.tmp.textInfo.linkInfo[linkIndex];
|
|
string linkId = linkInfo.GetLinkID();
|
|
if (!string.IsNullOrEmpty(linkId))
|
|
{
|
|
string playerName = linkId;
|
|
int characterId = 0;
|
|
|
|
if (linkId.Contains("|"))
|
|
{
|
|
string[] parts = linkId.Split('|');
|
|
if (parts.Length == 2)
|
|
{
|
|
int.TryParse(parts[0], out characterId);
|
|
playerName = parts[1];
|
|
}
|
|
}
|
|
|
|
var host = EC_Game.GetGameRun()?.GetHostPlayer();
|
|
if (host != null && characterId > 0 && characterId != host.GetCharacterID() && GPDataTypeHelper.ISPLAYERID(characterId))
|
|
{
|
|
CECUIManager.Instance?.ShowPlayerOptionsDialog(characterId, eventData.position + new Vector2(0, 400));
|
|
}
|
|
|
|
Debug.Log("[Cuong] OnWhisper from Chat: name: " + playerName);
|
|
EventBus.Publish(new WhisperPlayerEvent(playerName));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|