Files
2026-04-02 11:42:34 +07:00

96 lines
4.0 KiB
C#

using System.Collections.Generic;
using BrewMonster.Network;
using CSNetwork.GPDataType;
namespace BrewMonster.UI
{
/// <summary>
/// Code gốc bên C++
/// Class này làm về UI nên trong C# được chia ra
/// trong ChatInputHandler và ChatPanelUI
/// </summary>
public static class DlgChat
{
private static readonly Dictionary<ChatChannel, string> ChannelColors = new Dictionary<ChatChannel, string>
{
{ ChatChannel.GP_CHAT_LOCAL, "FFFFFF" },
{ ChatChannel.GP_CHAT_FARCRY, "FFE400" },
{ ChatChannel.GP_CHAT_TEAM, "00FF00" },
{ ChatChannel.GP_CHAT_FACTION, "00FFFC" },
{ ChatChannel.GP_CHAT_WHISPER, "0065FE" },
{ ChatChannel.GP_CHAT_DAMAGE, "C0C0C0" },
{ ChatChannel.GP_CHAT_FIGHT, "FF7E00" },
{ ChatChannel.GP_CHAT_TRADE, "FF742E" },
{ ChatChannel.GP_CHAT_SYSTEM, "BED293" },
{ ChatChannel.GP_CHAT_BROADCAST, "FF3600" },
{ ChatChannel.GP_CHAT_MISC, "9AA6FF" },
{ ChatChannel.GP_CHAT_INSTANCE, "EC0D3C" },
{ ChatChannel.GP_CHAT_SUPERFARCRY, "ff9b3e" },
{ ChatChannel.GP_CHAT_BATTLE, "FFFFFF" },
{ ChatChannel.GP_CHAT_COUNTRY, "FFFFFF" }
};
public const string NPC_COLOR = "C8FF64";
public const string KING_COLOR = "8A2BE2";
// [Port] C++: CDlgChat::m_pszWhisperFriendColor = "^FF4AB0"
// Màu hồng cho whisper từ/tới bạn bè trong danh sách
public const string WHISPER_FRIEND_COLOR = "FF4AB0";
/// <summary>
/// Formats a message with TextMeshPro color tags based on the channel.
/// </summary>
public static string FormatMessage(string message, ChatChannel channel)
{
if (string.IsNullOrEmpty(message)) return string.Empty;
if (ChannelColors.TryGetValue(channel, out string hexColor))
return $"<color=#{hexColor}>{message}</color>";
return message;
}
/// <summary>
/// Formats a message with a specific hex color tag.
/// </summary>
public static string FormatWithColor(string text, string hexColor)
{
if (string.IsNullOrEmpty(text)) return string.Empty;
return $"<color=#{hexColor}>{text}</color>";
}
/// <summary>
/// Returns the hex color string for a given channel.
/// Mirrors CDlgChat::GetChatColor in C++.
/// </summary>
/// <param name="channel">Chat channel</param>
/// <param name="idPlayer">Sender/recipient role ID — used to check friend status for GP_CHAT_WHISPER</param>
public static string GetChatColor(ChatChannel channel, int idPlayer = -1)
{
// [Port] C++: DlgChat.cpp dòng 142-157
// if (iChannel == GP_CHAT_WHISPER && pFriendMan->GetFriendByID(idPlayer))
// return m_pszWhisperFriendColor; // "^FF4AB0" (hồng)
if (channel == ChatChannel.GP_CHAT_WHISPER && idPlayer > 0)
{
var host = EC_Game.GetGameRun()?.GetHostPlayer();
var friendMan = host?.GetFriendMan();
if (friendMan != null && friendMan.GetFriendByID(idPlayer).HasValue)
return WHISPER_FRIEND_COLOR;
}
if (ChannelColors.TryGetValue(channel, out string hexColor))
return hexColor;
return "FFFFFF";
}
/// <summary>
/// Returns a channel icon/image prefix string.
/// Currently returns empty — placeholder for future TMP sprite implementation.
/// Mirrors GetChatChannelImage() in C++.
/// </summary>
public static string GetChatChannelImage(ChatChannel channel)
{
// TODO: return TMP sprite tag per channel when assets are ready
// e.g. return $"<sprite name=\"chat_icon_{channel}\">";
return string.Empty;
}
}
}