diff --git a/src/engine/client.h b/src/engine/client.h index ab4c28920..a3fb3af2e 100644 --- a/src/engine/client.h +++ b/src/engine/client.h @@ -335,7 +335,6 @@ public: virtual void DummyResetInput() = 0; virtual void Echo(const char *pString) = 0; virtual bool CanDisplayWarning() const = 0; - virtual bool IsDisplayingWarning() const = 0; virtual CNetObjHandler *GetNetObjHandler() = 0; }; diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 5b984c643..76712514e 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -2981,28 +2981,11 @@ void CClient::Run() AutoStatScreenshot_Cleanup(); AutoCSV_Cleanup(); - // check conditions - if(State() == IClient::STATE_QUITTING || State() == IClient::STATE_RESTARTING) - { - static bool s_SavedConfig = false; - if(!s_SavedConfig) - { - // write down the config and quit - if(!m_pConfigManager->Save()) - { - char aWarning[128]; - str_format(aWarning, sizeof(aWarning), Localize("Saving settings to '%s' failed"), CONFIG_FILE); - m_vWarnings.emplace_back(aWarning); - } - s_SavedConfig = true; - } - - if(m_vWarnings.empty() && !GameClient()->IsDisplayingWarning()) - break; - } - m_Fifo.Update(); + if(State() == IClient::STATE_QUITTING || State() == IClient::STATE_RESTARTING) + break; + // beNice auto Now = time_get_nanoseconds(); decltype(Now) SleepTimeInNanoSeconds{0}; @@ -3050,6 +3033,13 @@ void CClient::Run() m_GlobalTime = (time_get() - m_GlobalStartTime) / (float)time_freq(); } + if(!m_pConfigManager->Save()) + { + char aError[128]; + str_format(aError, sizeof(aError), Localize("Saving settings to '%s' failed"), CONFIG_FILE); + m_vQuittingWarnings.emplace_back(Localize("Error saving settings"), aError); + } + m_Fifo.Shutdown(); GameClient()->OnShutdown(); @@ -4172,6 +4162,26 @@ static bool SaveUnknownCommandCallback(const char *pCommand, void *pUser) return true; } +static Uint32 GetSdlMessageBoxFlags(IClient::EMessageBoxType Type) +{ + switch(Type) + { + case IClient::MESSAGE_BOX_TYPE_ERROR: + return SDL_MESSAGEBOX_ERROR; + case IClient::MESSAGE_BOX_TYPE_WARNING: + return SDL_MESSAGEBOX_WARNING; + case IClient::MESSAGE_BOX_TYPE_INFO: + return SDL_MESSAGEBOX_INFORMATION; + } + dbg_assert(false, "Type invalid"); + return 0; +} + +static void ShowMessageBox(const char *pTitle, const char *pMessage, IClient::EMessageBoxType Type = IClient::MESSAGE_BOX_TYPE_ERROR) +{ + SDL_ShowSimpleMessageBox(GetSdlMessageBoxFlags(Type), pTitle, pMessage, nullptr); +} + /* Server Time Client Mirror Time @@ -4490,8 +4500,15 @@ int main(int argc, const char **argv) pStorage->GetBinaryPath(PLAT_CLIENT_EXEC, aRestartBinaryPath, sizeof(aRestartBinaryPath)); } + std::vector vQuittingWarnings = pClient->QuittingWarnings(); + PerformCleanup(); + for(const SWarning &Warning : vQuittingWarnings) + { + ::ShowMessageBox(Warning.m_aWarningTitle, Warning.m_aWarningMsg); + } + if(Restarting) { shell_execute(aRestartBinaryPath, EShellExecuteWindowState::FOREGROUND); @@ -4708,25 +4725,10 @@ void CClient::ShellUnregister() } #endif -static Uint32 GetSdlMessageBoxFlags(IClient::EMessageBoxType Type) -{ - switch(Type) - { - case IClient::MESSAGE_BOX_TYPE_ERROR: - return SDL_MESSAGEBOX_ERROR; - case IClient::MESSAGE_BOX_TYPE_WARNING: - return SDL_MESSAGEBOX_WARNING; - case IClient::MESSAGE_BOX_TYPE_INFO: - return SDL_MESSAGEBOX_INFORMATION; - } - dbg_assert(false, "Type invalid"); - return 0; -} - void CClient::ShowMessageBox(const char *pTitle, const char *pMessage, EMessageBoxType Type) { if(m_pGraphics == nullptr || !m_pGraphics->ShowMessageBox(GetSdlMessageBoxFlags(Type), pTitle, pMessage)) - SDL_ShowSimpleMessageBox(GetSdlMessageBoxFlags(Type), pTitle, pMessage, nullptr); + ::ShowMessageBox(pTitle, pMessage, Type); } void CClient::GetGPUInfoString(char (&aGPUInfo)[256]) diff --git a/src/engine/client/client.h b/src/engine/client/client.h index e392f55c3..e8676d1a1 100644 --- a/src/engine/client/client.h +++ b/src/engine/client/client.h @@ -228,6 +228,7 @@ class CClient : public IClient, public CDemoPlayer::IListener } m_VersionInfo; std::vector m_vWarnings; + std::vector m_vQuittingWarnings; CFifo m_Fifo; @@ -495,6 +496,7 @@ public: void AddWarning(const SWarning &Warning) override; SWarning *GetCurWarning() override; + std::vector &&QuittingWarnings() { return std::move(m_vQuittingWarnings); } CChecksumData *ChecksumData() override { return &m_Checksum.m_Data; } int UdpConnectivity(int NetType) override; diff --git a/src/engine/shared/config.cpp b/src/engine/shared/config.cpp index d30467072..f5dac6985 100644 --- a/src/engine/shared/config.cpp +++ b/src/engine/shared/config.cpp @@ -445,6 +445,7 @@ bool CConfigManager::Save() return false; } + log_info("config", "saved to " CONFIG_FILE); return true; } diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index 49639c5b9..077c0043b 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -731,7 +731,6 @@ public: void UpdateOwnGhost(CGhostItem Item); void DeleteGhostItem(int Index); - int GetCurPopup() const { return m_Popup; } bool CanDisplayWarning() const; void PopupWarning(const char *pTopic, const char *pBody, const char *pButton, std::chrono::nanoseconds Duration); diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 4ecf093b6..c5d20a4cb 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -3520,11 +3520,6 @@ bool CGameClient::CanDisplayWarning() const return m_Menus.CanDisplayWarning(); } -bool CGameClient::IsDisplayingWarning() const -{ - return m_Menus.GetCurPopup() == CMenus::POPUP_WARNING; -} - CNetObjHandler *CGameClient::GetNetObjHandler() { return &m_NetObjHandler; diff --git a/src/game/client/gameclient.h b/src/game/client/gameclient.h index 69a2b374b..aaf18ae96 100644 --- a/src/game/client/gameclient.h +++ b/src/game/client/gameclient.h @@ -555,7 +555,6 @@ public: int SwitchStateTeam() const; bool IsLocalCharSuper() const; bool CanDisplayWarning() const override; - bool IsDisplayingWarning() const override; CNetObjHandler *GetNetObjHandler() override; void LoadGameSkin(const char *pPath, bool AsDir = false);