using System.Collections.Generic; using BrewMonster.Network; using CSNetwork.GPDataType; namespace BrewMonster.UI { /// /// Code gốc bên C++ /// Class này làm về UI nên trong C# được chia ra /// trong ChatInputHandler và ChatPanelUI /// public static class DlgChat { private static readonly Dictionary ChannelColors = new Dictionary { { 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"; /// /// Formats a message with TextMeshPro color tags based on the channel. /// public static string FormatMessage(string message, ChatChannel channel) { if (string.IsNullOrEmpty(message)) return string.Empty; if (ChannelColors.TryGetValue(channel, out string hexColor)) return $"{message}"; return message; } /// /// Formats a message with a specific hex color tag. /// public static string FormatWithColor(string text, string hexColor) { if (string.IsNullOrEmpty(text)) return string.Empty; return $"{text}"; } /// /// Returns the hex color string for a given channel. /// Mirrors CDlgChat::GetChatColor in C++. /// /// Chat channel /// Sender/recipient role ID — used to check friend status for GP_CHAT_WHISPER 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"; } /// /// Returns a channel icon/image prefix string. /// Currently returns empty — placeholder for future TMP sprite implementation. /// Mirrors GetChatChannelImage() in C++. /// public static string GetChatChannelImage(ChatChannel channel) { // TODO: return TMP sprite tag per channel when assets are ready // e.g. return $""; return string.Empty; } } }