diff --git a/Assets/PerfectWorld/Scripts/Chat/UI/ChatPanelUI.cs b/Assets/PerfectWorld/Scripts/Chat/UI/ChatPanelUI.cs index 4d85c8bbaf..f3027d924a 100644 --- a/Assets/PerfectWorld/Scripts/Chat/UI/ChatPanelUI.cs +++ b/Assets/PerfectWorld/Scripts/Chat/UI/ChatPanelUI.cs @@ -36,6 +36,8 @@ namespace BrewMonster.Scripts.ChatUI private ObjectPool _pool; private bool _userAtBottom = true; + private ChatChannel _currentFilterChannel = ChatChannel.GP_CHAT_LOCAL; + void Awake() { @@ -84,17 +86,20 @@ namespace BrewMonster.Scripts.ChatUI void OnGetItem(ChatMessageView item) { - item.gameObject.SetActive(true); + if (item != null && item.gameObject != null) + item.gameObject.SetActive(true); } void OnReleaseItem(ChatMessageView item) { - item.gameObject.SetActive(false); + if (item != null && item.gameObject != null) + item.gameObject.SetActive(false); } void OnDestroyItem(ChatMessageView item) { - Destroy(item.gameObject); + if (item != null && item.gameObject != null) + Destroy(item.gameObject); } void OnScrollChanged(Vector2 pos) @@ -123,12 +128,38 @@ namespace BrewMonster.Scripts.ChatUI if (!chatPanelUIGO.activeSelf) return; - AddMessageView(data); + if (ShouldShowMessage(data.channel)) + { + AddMessageView(data); - if (_userAtBottom) - ScrollToBottom(); + if (_userAtBottom) + ScrollToBottom(); + } } + private bool ShouldShowMessage(byte channel) + { + if (_currentFilterChannel == ChatChannel.GP_CHAT_LOCAL) + return true; + if (channel == (byte)ChatChannel.GP_CHAT_MISC) + return true; + return channel == (byte)_currentFilterChannel; + } + + public void SetChannelFilter(ChatChannel filterChannel) + { + if (_currentFilterChannel == filterChannel) + return; + + _currentFilterChannel = filterChannel; + + if (chatPanelUIGO.activeSelf) + { + RefreshVisible(); + } + } + + void AddMessageView(ChatMessageData data) { var view = _pool.Get(); @@ -157,15 +188,25 @@ namespace BrewMonster.Scripts.ChatUI _visibleViews.Clear(); - int start = Mathf.Max(0, _messages.Count - maxVisibleMessages); + // Filter messages based on the current channel selection + var filteredMessages = new List(); + foreach (var msg in _messages) + { + if (ShouldShowMessage(msg.channel)) + { + filteredMessages.Add(msg); + } + } - for (int i = start; i < _messages.Count; i++) + int start = Mathf.Max(0, filteredMessages.Count - maxVisibleMessages); + + for (int i = start; i < filteredMessages.Count; i++) { var view = _pool.Get(); view.transform.SetParent(content, false); view.transform.SetAsLastSibling(); - var data = _messages[i]; + var data = filteredMessages[i]; Sprite icon = _iconCache.ContainsKey(data.channel) ? _iconCache[data.channel] : null; view.Bind(icon, data.message); diff --git a/Assets/PerfectWorld/Scripts/UI/GamePlay/EC_GameUIMan.cs b/Assets/PerfectWorld/Scripts/UI/GamePlay/EC_GameUIMan.cs index 93dcc86fe8..d8615f0de3 100644 --- a/Assets/PerfectWorld/Scripts/UI/GamePlay/EC_GameUIMan.cs +++ b/Assets/PerfectWorld/Scripts/UI/GamePlay/EC_GameUIMan.cs @@ -469,7 +469,7 @@ namespace BrewMonster.UI if (isPlayerChannel && idPlayer > 0) // idPlayer > 0 is equivalent to C++ ISPLAYERID(id) { - // TODO: pszMsg = FilterBadWords(pszMsg); when API is available + CECUIManager.Instance.FilterBadWords(ref pszMsg); } // C++: Booth Message check (cChannel == GP_CHAT_WHISPER && pszMsg ends with "!#") diff --git a/Assets/Prefabs/ChatSystem/prefab_ChatSystemUI.prefab b/Assets/Prefabs/ChatSystem/prefab_ChatSystemUI.prefab index f6db1b6f6a..c7eff41092 100644 --- a/Assets/Prefabs/ChatSystem/prefab_ChatSystemUI.prefab +++ b/Assets/Prefabs/ChatSystem/prefab_ChatSystemUI.prefab @@ -297,6 +297,7 @@ MonoBehaviour: button: {fileID: 1690303811971402318} - channel: 8 button: {fileID: 5620031369785857446} + chatPanelUI: {fileID: 2621697629504226575} --- !u!1 &726262149639511024 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/ChatInputHandler.cs b/Assets/Scripts/ChatInputHandler.cs index 9c9de1ac44..d5b7b77779 100644 --- a/Assets/Scripts/ChatInputHandler.cs +++ b/Assets/Scripts/ChatInputHandler.cs @@ -21,6 +21,7 @@ namespace BrewMonster.Scripts.ChatUI } public List channelButtons = new(); + public ChatPanelUI chatPanelUI; // Reference to ChatPanelUI to relay channel changes private const int MAX_HISTORY = 10; private ChatChannel m_currentChannel = ChatChannel.GP_CHAT_LOCAL; @@ -88,6 +89,12 @@ namespace BrewMonster.Scripts.ChatUI } m_currentChannel = channel; + + if (chatPanelUI != null) + { + chatPanelUI.SetChannelFilter(channel); + } + var config = chatSystem.channelIcons.Find(c => c.channel == channel); if (config.prefix != null) { @@ -96,8 +103,17 @@ namespace BrewMonster.Scripts.ChatUI inputField.text = config.prefix + currentText; } - inputField.ActivateInputField(); - inputField.MoveTextEnd(false); + if (channel == ChatChannel.GP_CHAT_SYSTEM) + { + inputField.interactable = false; + inputField.text = ""; // Xóa text nếu chuyển sang kênh hệ thống + } + else + { + inputField.interactable = true; + inputField.ActivateInputField(); + inputField.MoveTextEnd(false); + } } private string RemoveKnownPrefix(string text) @@ -306,6 +322,20 @@ namespace BrewMonster.Scripts.ChatUI } // Không gõ prefix thủ công thì sẽ dùng m_currentChannel đã được gán ở đầu hàm + if (channel == ChatChannel.GP_CHAT_SYSTEM) + { + Debug.Log("[Cuong] ParseAndSendMessage Ngăn người chơi chat ở GP_CHAT_SYSTEM"); + return channel; + } + + if (channel == ChatChannel.GP_CHAT_WHISPER) + { + // Nếu người chơi đang ở kênh Whisper nhưng (vô tình) xóa mất dấu '/' + // Ta vẫn giả lập thêm '/' vào để parse theo cú pháp "TênNgườiNhận NộiDung" + HandleWhisper("/" + pszMsg, nPack, nSlot); + return channel; + } + SendChat(channel, pszMsg, nPack, nSlot); return channel; } diff --git a/Assets/Scripts/EC_GameRun.cs b/Assets/Scripts/EC_GameRun.cs index 226ecd3065..6b958ca287 100644 --- a/Assets/Scripts/EC_GameRun.cs +++ b/Assets/Scripts/EC_GameRun.cs @@ -876,6 +876,7 @@ public partial class CECGameRun : ITickable if (string.IsNullOrEmpty(pszMsg)) return; + Debug.Log($"[Cuong] AddChatMessage [{cChannel}] {pszMsgOrigion} {pszMsg}"); CECGameUIMan pGameUI = m_pUIManager?.GetInGameUIMan(); if (pGameUI != null) { diff --git a/Assets/Scripts/chat_search.txt b/Assets/Scripts/chat_search.txt new file mode 100644 index 0000000000..c9f9dd1faa Binary files /dev/null and b/Assets/Scripts/chat_search.txt differ diff --git a/Assets/Scripts/chat_search.txt.meta b/Assets/Scripts/chat_search.txt.meta new file mode 100644 index 0000000000..e029e01e3c --- /dev/null +++ b/Assets/Scripts/chat_search.txt.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: f299bbe96fd1b5d45b65642a84b5702a +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: