diff --git a/Assets/PerfectWorld/Scripts/Network/CSNetwork/AUICommon.cs b/Assets/PerfectWorld/Scripts/Network/CSNetwork/AUICommon.cs index 49e29e4a5f..2cc27dfac0 100644 --- a/Assets/PerfectWorld/Scripts/Network/CSNetwork/AUICommon.cs +++ b/Assets/PerfectWorld/Scripts/Network/CSNetwork/AUICommon.cs @@ -321,52 +321,6 @@ namespace CSNetwork return sb.ToString(); } - /// - /// Chuyển đổi định dạng printf (C-style: %s, %d) sang string.Format (C#-style: {0}, {1}) - /// - public static string ConvertPrintfToCSharpFormat(string format) - { - if (string.IsNullOrEmpty(format)) return ""; - - StringBuilder sb = new StringBuilder(); - int argIndex = 0; - for (int i = 0; i < format.Length; i++) - { - if (format[i] == '%' && i + 1 < format.Length) - { - char next = format[i + 1]; - if (next == '%') // Trường hợp %% -> % - { - sb.Append('%'); - i++; - } - else - { - sb.Append('{').Append(argIndex++).Append('}'); - - i++; - // Nhảy qua các ký tự định dạng (ví dụ: %02d, %ls, %f) - while (i < format.Length && (char.IsDigit(format[i]) || format[i] == '.' || format[i] == 'l' || format[i] == 'u' || format[i] == 'd' || format[i] == 's' || format[i] == 'f' || format[i] == 'x')) - { - // Nếu gặp ký tự kết thúc định dạng (s, d, f, ...) thì dừng lại sau ký tự đó - char c = format[i]; - if (c == 's' || c == 'd' || c == 'f' || c == 'u' || c == 'x' || c == 'g') - { - // i++; // Đã ở đúng vị trí để vòng lặp cha thực hiện i++ tiếp theo - break; - } - i++; - } - } - } - else - { - sb.Append(format[i]); - } - } - return sb.ToString(); - } - /// /// [Port] CECGameUIMan::FilterInvalidTags (EC_GameUIMan.cpp:6424) /// Lọc bỏ các tag đặc biệt không hợp lệ trong nội dung chat nhận từ server. diff --git a/Assets/PerfectWorld/Scripts/Network/CSNetwork/GameSession.cs b/Assets/PerfectWorld/Scripts/Network/CSNetwork/GameSession.cs index 934c224f0b..8b4ba6c6a3 100644 --- a/Assets/PerfectWorld/Scripts/Network/CSNetwork/GameSession.cs +++ b/Assets/PerfectWorld/Scripts/Network/CSNetwork/GameSession.cs @@ -1962,7 +1962,8 @@ namespace CSNetwork string szName = pHost.GetName(); char[] szText = new char[80]; AUICommon.AUI_ConvertChatString(ref szName, ref szText, false); - string fmt = AUICommon.ConvertPrintfToCSharpFormat(pStrTab.GetWideString((int)FixedMsg.FIXMSG_CHAT)); + Debug.Log($"[Cuong] {szText}"); + string fmt = AUIDialog.FormatPrintf(pStrTab.GetWideString((int)FixedMsg.FIXMSG_CHAT)); string str; try { str = string.Format(fmt, szName, szMsg); @@ -2057,8 +2058,8 @@ namespace CSNetwork string strMsg = Encoding.Unicode.GetString(p.Msg.ToArray()); string strSrcName = Encoding.Unicode.GetString(p.Name.ToArray()); - - string fmt = AUICommon.ConvertPrintfToCSharpFormat(pStrTab.GetWideString((int)FixedMsg.FIXMSG_CHAT)); + Debug.Log($"[Cuong] {strMsg}"); + string fmt = AUIDialog.FormatPrintf(pStrTab.GetWideString((int)FixedMsg.FIXMSG_CHAT)); string formatted; try { formatted = string.Format(fmt, strSrcName, strMsg); @@ -2208,13 +2209,14 @@ namespace CSNetwork { char[] szText = new char[80]; AUICommon.AUI_ConvertChatString(ref szName,ref szText, false); - - string fmt = AUICommon.ConvertPrintfToCSharpFormat(pStrTab.GetWideString((int)FixedMsg.FIXMSG_CHAT)); + Debug.Log($"[Cuong] {szText}"); + string fmt = AUIDialog.FormatPrintf(pStrTab.GetWideString((int)FixedMsg.FIXMSG_CHAT), szText); string str = string.Format( fmt, szName, szMsg ); + Debug.Log($"[Cuong] {str} {fmt}"); // [Port] Gọi AddChatMessage để hiển thị lên UI Chat Box. // AddChatMessage bên trong đã tự publish ChatMessageEvent (cho ChatPanelUI) // VÀ EventChatMessageOnTopPlayer (cho Head Bubble) nếu channel thuộc nhóm @@ -2231,8 +2233,7 @@ namespace CSNetwork if (pNPC != null) { - string str; - string template = AUICommon.ConvertPrintfToCSharpFormat(pStrTab.GetWideString((int)FixedMsg.FIXMSG_CHAT2)); + string template = AUIDialog.FormatPrintf(pStrTab.GetWideString((int)FixedMsg.FIXMSG_CHAT2)); string message = string.Format( template, @@ -2275,7 +2276,7 @@ namespace CSNetwork if (p.Channel == 0 /* CHANNEL_NORMAL */ || p.Channel == 1 /* CHANNEL_NORMALRE */) { // Format: "[Name] whispers to [You]: [Message]" - string fmt = AUICommon.ConvertPrintfToCSharpFormat(pStrTab.GetWideString((int)FixedMsg.FIXMSG_PRIVATECHAT1)); + string fmt = AUIDialog.FormatPrintf(pStrTab.GetWideString((int)FixedMsg.FIXMSG_PRIVATECHAT1)); BMLogger.Log($"[Cuong] OnPrtcPrivateChat {fmt}"); string formatted; try { diff --git a/Assets/Scripts/CECHostPlayer.cs b/Assets/Scripts/CECHostPlayer.cs index 9d94d64bc5..bd12ed5487 100644 --- a/Assets/Scripts/CECHostPlayer.cs +++ b/Assets/Scripts/CECHostPlayer.cs @@ -649,7 +649,7 @@ namespace BrewMonster cmd_pickup_money pCmd = GPDataTypeHelper.FromBytes(data); AddMoneyAmount(pCmd.amount); CECGameRun pGameRun = EC_Game.GetGameRun(); - pGameRun.AddFixedMessage((int)FixedMsg.FIXMSG_PICKUPMONEY); + pGameRun.AddFixedMessage((int)FixedMsg.FIXMSG_PICKUPMONEY, pCmd.amount); BubbleText((int)BubbleTextType.BUBBLE_MONEY, (uint)pCmd.amount); } diff --git a/Assets/Scripts/ChatInputHandler.cs b/Assets/Scripts/ChatInputHandler.cs index 09226d7ebf..b696e24255 100644 --- a/Assets/Scripts/ChatInputHandler.cs +++ b/Assets/Scripts/ChatInputHandler.cs @@ -457,7 +457,7 @@ namespace BrewMonster.Scripts.ChatUI // Tránh truyền "&target&" vì kết quả sẽ là "&&target&&" → regex chỉ match "target" // nhưng để lại & dư ở ngoài → UI hiển thị "&target&" thay vì link sạch. CECStringTab pStrTab = EC_Game.GetFixedMsgs(); - string fmt = AUICommon.ConvertPrintfToCSharpFormat(pStrTab.GetWideString((int)FixedMsg.FIXMSG_PRIVATECHAT2)); + string fmt = AUIDialog.FormatPrintf(pStrTab.GetWideString((int)FixedMsg.FIXMSG_PRIVATECHAT2)); string localMsg; try { diff --git a/Assets/Scripts/EC_GameRun.cs b/Assets/Scripts/EC_GameRun.cs index 0932be7aba..71b267d14b 100644 --- a/Assets/Scripts/EC_GameRun.cs +++ b/Assets/Scripts/EC_GameRun.cs @@ -773,23 +773,19 @@ public partial class CECGameRun : ITickable return; } - // Format the message with provided arguments + // fixed_msg.txt uses printf-style (%d, %s); not C# {0} placeholders string szFormattedMsg; try { if (args != null && args.Length > 0) - { - szFormattedMsg = string.Format(szFixMsg, args); - } + szFormattedMsg = AUIDialog.FormatPrintf(szFixMsg, args); else - { szFormattedMsg = szFixMsg; - } } - catch (System.FormatException ex) + catch (Exception ex) { Debug.LogError($"[AddFixedMessage] Format error for message {iMsg}: {ex.Message}"); - szFormattedMsg = szFixMsg; // Use unformatted message as fallback + szFormattedMsg = szFixMsg; } // Try to add to in-game UI chat @@ -828,23 +824,19 @@ public partial class CECGameRun : ITickable return; } - // Format the message with provided arguments + // fixed_msg.txt uses printf-style (%d, %s); not C# {0} placeholders string szFormattedMsg; try { if (args != null && args.Length > 0) - { - szFormattedMsg = string.Format(szFixMsg, args); - } + szFormattedMsg = AUIDialog.FormatPrintf(szFixMsg, args); else - { szFormattedMsg = szFixMsg; - } } - catch (System.FormatException ex) + catch (Exception ex) { Debug.LogError($"[AddFixedChannelMsg] Format error for message {iMsg}: {ex.Message}"); - szFormattedMsg = szFixMsg; // Use unformatted message as fallback + szFormattedMsg = szFixMsg; } // Try to add to in-game UI chat with specific channel