update logic chatsystem

This commit is contained in:
CuongNV
2026-04-01 16:50:38 +07:00
parent a82337f617
commit 56923e1b40
5 changed files with 48 additions and 9 deletions
@@ -3,10 +3,13 @@ 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
public class ChatMessageView : MonoBehaviour, IPointerClickHandler
{
public Image iconImage;
public EC_UIUtility.TextOutlet messageText;
@@ -24,5 +27,41 @@ namespace BrewMonster.Scripts.ChatUI
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));
}
}
}
}
}
@@ -2132,7 +2132,7 @@ namespace CSNetwork
break;
case 18: case 19: case 20: case 21: case 22: // Auction Message
// pGameUI.AddSysAuctionMessage(...)
Debug.Log("[Auction] " + strTemp);
Debug.Log("[Cuong] Auction " + strTemp);
EventBus.Publish(new ChatMessageEvent(strTemp, p.Channel));
break;
case 24: // Task Message
@@ -2252,7 +2252,7 @@ namespace CSNetwork
{
// Format: "[Name] whispers to [You]: [Message]"
string fmt = AUICommon.ConvertPrintfToCSharpFormat(pStrTab.GetWideString((int)FixedMsg.FIXMSG_PRIVATECHAT1));
BMLogger.Log($"[Cuong] OnPrtcPrivateChat {fmt}");
string formatted;
try {
formatted = string.Format(fmt, strSrcName, strMsg);
@@ -91,9 +91,9 @@ namespace BrewMonster.UI
void OnWhisper(int characterId)
{
string name = EC_ManMessageMono.Instance?.GetECManPlayer?.GetElsePlayer(characterId)?.GetName() ?? "";
Debug.Log("OnWhisper: " + characterId + " name: " + name);
EventBus.Publish(new BrewMonster.Scripts.ChatUI.WhisperPlayerEvent(name));
Debug.Log("[Cuong] OnWhisper: " + characterId + " name: " + name);
EventBus.Publish(new Scripts.ChatUI.WhisperPlayerEvent(name));
}
void PositionAtMouse()
@@ -516,11 +516,11 @@ namespace BrewMonster.UI
string parsedMsg = pszMsg;
if (parsedMsg.Contains("&"))
{
// Convert &Cuong& into <color=#HexColor>Cuong</color>
// Convert &Cuong& into <color=#HexColor><link="idPlayer|Cuong">Cuong</link></color>
parsedMsg = System.Text.RegularExpressions.Regex.Replace(
parsedMsg,
@"&([^&]+)&",
$"<color=#{colorHex}>$1</color>"
$"<color=#{colorHex}><u><link=\"{idPlayer}|$1\">$1</link></u></color>"
);
}
else
+1 -1
View File
@@ -429,7 +429,7 @@ namespace BrewMonster.Scripts.ChatUI
private void SendPrivateChat(string target, string msg, int pack, int slot)
{
Debug.Log($"Whisper to {target}: {msg}");
BMLogger.Log($"[Cuong] Whisper to {target}: {msg}");
// [Port] C++: CDlgChat::OnCommand_speak → privatechat branch
// Gửi tin nhắn mật (whisper) lên server qua GameSession.