From 43739ea9aa685b91907df93bbbc0d2c4af759cc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Thu, 3 Aug 2023 17:13:00 +0200 Subject: [PATCH] When quitting/restarting client clear screen and render message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When quitting or restarting the client, clear the screen and render a message "Quitting. Please wait…" or "Restarting. Please wait…" respectively. Previously the last frame would keep getting shown while the client is busy with cleanup tasks. Rendering a final message before the client window stops being updated provides a cleaner user experience. --- src/game/client/gameclient.cpp | 21 +++++++++++++++++++++ src/game/client/gameclient.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 524a55c1b..48678be2a 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -915,6 +915,8 @@ void CGameClient::OnStateChange(int NewState, int OldState) void CGameClient::OnShutdown() { + RenderShutdownMessage(); + for(auto &pComponent : m_vpAll) pComponent->OnShutdown(); } @@ -972,6 +974,25 @@ void CGameClient::OnLanguageChange() UI()->OnLanguageChange(); } +void CGameClient::RenderShutdownMessage() +{ + const char *pMessage = nullptr; + if(Client()->State() == IClient::STATE_QUITTING) + pMessage = Localize("Quitting. Please wait…"); + else if(Client()->State() == IClient::STATE_RESTARTING) + pMessage = Localize("Restarting. Please wait…"); + else + dbg_assert(false, "Invalid client state for quitting message"); + + // This function only gets called after the render loop has already terminated, so we have to call Swap manually. + Graphics()->Clear(0.0f, 0.0f, 0.0f); + UI()->MapScreen(); + TextRender()->TextColor(TextRender()->DefaultTextColor()); + UI()->DoLabel(UI()->Screen(), pMessage, 16.0f, TEXTALIGN_MC); + Graphics()->Swap(); + Graphics()->Clear(0.0f, 0.0f, 0.0f); +} + void CGameClient::OnRconType(bool UsernameReq) { m_GameConsole.RequireUsername(UsernameReq); diff --git a/src/game/client/gameclient.h b/src/game/client/gameclient.h index 0dad73e20..088f45942 100644 --- a/src/game/client/gameclient.h +++ b/src/game/client/gameclient.h @@ -489,6 +489,8 @@ public: void OnLanguageChange(); + void RenderShutdownMessage(); + const char *GetItemName(int Type) const override; const char *Version() const override; const char *NetVersion() const override;