Add filter ui chat
This commit is contained in:
@@ -36,6 +36,8 @@ namespace BrewMonster.Scripts.ChatUI
|
||||
private ObjectPool<ChatMessageView> _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<ChatMessageData>();
|
||||
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);
|
||||
|
||||
|
||||
@@ -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 "!#")
|
||||
|
||||
@@ -297,6 +297,7 @@ MonoBehaviour:
|
||||
button: {fileID: 1690303811971402318}
|
||||
- channel: 8
|
||||
button: {fileID: 5620031369785857446}
|
||||
chatPanelUI: {fileID: 2621697629504226575}
|
||||
--- !u!1 &726262149639511024
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace BrewMonster.Scripts.ChatUI
|
||||
}
|
||||
|
||||
public List<ChannelButtonMapping> 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;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f299bbe96fd1b5d45b65642a84b5702a
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user