From 358f78877f55d139c386abcbbfeba7b7c7c879c5 Mon Sep 17 00:00:00 2001 From: CuongNV <> Date: Mon, 30 Mar 2026 15:14:50 +0700 Subject: [PATCH] clear chat when login out and optimal list chat --- .../Scripts/Chat/UI/ChatPanelUI.cs | 24 ++++++-- Assets/Scripts/EC_GameRun.GameState.cs | 59 ++++++++++--------- 2 files changed, 49 insertions(+), 34 deletions(-) diff --git a/Assets/PerfectWorld/Scripts/Chat/UI/ChatPanelUI.cs b/Assets/PerfectWorld/Scripts/Chat/UI/ChatPanelUI.cs index 4ac404396b..bb34b87847 100644 --- a/Assets/PerfectWorld/Scripts/Chat/UI/ChatPanelUI.cs +++ b/Assets/PerfectWorld/Scripts/Chat/UI/ChatPanelUI.cs @@ -32,6 +32,7 @@ namespace BrewMonster.Scripts.ChatUI private List _messages = new(); private List _visibleViews = new(); + private List _filteredMessagesCache = new(); private ObjectPool _pool; @@ -40,6 +41,7 @@ namespace BrewMonster.Scripts.ChatUI void Awake() { + ClearChat(); _iconCache = new Dictionary(); if (chatSystemSO != null && chatSystemSO.channelIcons != null) { @@ -49,6 +51,7 @@ namespace BrewMonster.Scripts.ChatUI } } + EventBus.Subscribe(OnChatMessageClear); EventBus.Subscribe(OnChatMessageReceived); EventBus.Subscribe(OnChannelFilterChanged); _pool = new ObjectPool( @@ -94,6 +97,15 @@ namespace BrewMonster.Scripts.ChatUI }); } + + private void OnChatMessageClear(OnEventClearChat obj) + { + ChatThreadDispatcher.Instance.Post(() => + { + ClearChat(); + }); + } + ChatMessageView CreateItem() { var item = Instantiate(messagePrefab); @@ -179,24 +191,24 @@ namespace BrewMonster.Scripts.ChatUI _visibleViews.Clear(); - var filteredMessages = new List(); + _filteredMessagesCache.Clear(); foreach (var msg in _messages) { if (ShouldShowMessage(msg)) { - filteredMessages.Add(msg); + _filteredMessagesCache.Add(msg); } } - int start = Mathf.Max(0, filteredMessages.Count - maxVisibleMessages); + int start = Mathf.Max(0, _filteredMessagesCache.Count - maxVisibleMessages); - for (int i = start; i < filteredMessages.Count; i++) + for (int i = start; i < _filteredMessagesCache.Count; i++) { var view = _pool.Get(); view.transform.SetParent(content, false); view.transform.SetAsLastSibling(); - var data = filteredMessages[i]; + var data = _filteredMessagesCache[i]; Sprite icon = _iconCache.ContainsKey(data.channel) ? _iconCache[data.channel] : null; view.Bind(icon, data.message); @@ -232,4 +244,6 @@ namespace BrewMonster.Scripts.ChatUI RefreshVisible(); } } + + public struct OnEventClearChat{} } diff --git a/Assets/Scripts/EC_GameRun.GameState.cs b/Assets/Scripts/EC_GameRun.GameState.cs index 10a124e690..e2295da4cf 100644 --- a/Assets/Scripts/EC_GameRun.GameState.cs +++ b/Assets/Scripts/EC_GameRun.GameState.cs @@ -1,6 +1,7 @@ using BrewMonster; using BrewMonster.Network; + using BrewMonster.Scripts.ChatUI; using UnityEngine; public partial class CECGameRun @@ -8,7 +9,7 @@ int m_iGameState; // Game state // Logout flag (C++: m_iLogoutFlag) private int m_iLogoutFlag = -1; - + // Logout public void Logout() { @@ -18,13 +19,13 @@ BMLogger.LogError($"Logout called but game state is not GS_GAME, current state: {m_iGameState}"); return; } - + // TODO: Check if we need to call OnLogout for UI and cross server here // overlay::GTOverlay::Instance().Logout(); // CECCrossServer::Instance().OnLogout(); bool bExitApp = false; - + EventBus.Publish(new OnEventClearChat()); // if (CECUIConfig::Instance().GetLoginUI().bAvoidLoginUI && m_iLogoutFlag != 1){ if( 1 == 2 && m_iLogoutFlag != 1){ // TODO: check if we need to avoid login UI based on config and logout flag here bExitApp = true; @@ -35,12 +36,12 @@ else if (m_iLogoutFlag == 1) // Logout game and re-select role { UnityGameSession.ReturnToSelectRole(); - + // TODO: Check if we need to send switch game for mini client here - // Origin C++ + // Origin C++ // StartLogin(); StartLogin(); - + // // // ÏÂÔØÆ÷ÏìÓ¦Í˳öÓÎϷ״̬ // if( g_pGame->GetConfigs()->IsMiniClient() ) @@ -70,7 +71,7 @@ else if (m_iLogoutFlag == 2) // Logout game and goto login state { UnityGameSession.LogoutAccount(); - + // TODO: Check if we need to send switch game for mini client here // Origin C++ // StartLogin(); @@ -92,8 +93,8 @@ // ASSERT(NULL); bExitApp = true; } - - + + // if (m_pRandomMapProc) // A3DRELEASE(m_pRandomMapProc); @@ -104,7 +105,7 @@ // ::PostMessage(g_pGame->GetGameInit().hWnd, WM_QUIT, 0, 0); // } } - + // End current game state void EndGameState(bool bReset = true/* true */) { @@ -130,10 +131,10 @@ // if (bReset) // g_pGame.Reset(); - + } - + // Start login interface bool StartLogin() { @@ -164,7 +165,7 @@ // }else{ // m_pLogo->SetLinearFilter(true); // } - // } + // } // if (af_IsFileExist("surfaces\\kr.dds")) // { // if (!m_pClassification){ @@ -175,7 +176,7 @@ // m_pClassification->SetLinearFilter(true); // } // } - // } + // } // // Change cursor to default icon // g_pGame->ChangeCursor(RES_CUR_NORMAL); // // Discard current frame @@ -183,7 +184,7 @@ return true; } - + // End login state void OnEndLoginState() { @@ -201,13 +202,13 @@ void OnEndGameState() { ReleasePendingActions(); - + // Release UI module // m_pUIManager.ChangeCurUIManager(-1); - + // Release shortcuts ReleaseShortcuts(); - + // Release team manager // A3DRELEASE(m_pTeamMan); if (m_pTeamMan != null) @@ -215,23 +216,23 @@ m_pTeamMan.Release(); m_pTeamMan = null; } - + // Release host player before world released // ReleaseHostPlayer(); - + // Release world // ReleaseWorld(); - + // Release message manager // A3DRELEASE(m_pMessageMan); - + // g_pGame.ReleaseInGameRes(); - + // Return the default memory state // m_pMemSimplify.OnEndGameState(); // CECOptimize::Instance().OnEndGameState(); } - + // Release shortcuts void ReleaseShortcuts() { @@ -240,14 +241,14 @@ // A3DRELEASE(m_pTradeSCS); // A3DRELEASE(m_pPoseSCS); // A3DRELEASE(m_pFactionSCS); - + m_pNormalSCS = null; m_pTeamSCS = null; m_pTradeSCS = null; m_pPoseSCS = null; m_pFactionSCS = null; } - + // Release host player void ReleaseHostPlayer() { @@ -259,7 +260,7 @@ // delete m_pHostPlayer; // m_pHostPlayer = NULL; // } - + // Release host player if (m_pHostPlayer) { @@ -268,7 +269,7 @@ m_pHostPlayer = null; } } - + // Release world void ReleaseWorld() { @@ -276,7 +277,7 @@ // m_pInputCtrl->ClearMouFilterStack(); // // g_pGame->GetViewport()->SwitchCamera(false); - + if (m_pWorld != null) { // if (m_pHostPlayer)