mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-18 22:18:19 +00:00
Merge pull request #7945 from Robyt3/Client-Config-Error-Popup
Show warnings after client close instead of preventing quitting
This commit is contained in:
commit
1e012af2fd
|
@ -335,7 +335,6 @@ public:
|
||||||
virtual void DummyResetInput() = 0;
|
virtual void DummyResetInput() = 0;
|
||||||
virtual void Echo(const char *pString) = 0;
|
virtual void Echo(const char *pString) = 0;
|
||||||
virtual bool CanDisplayWarning() const = 0;
|
virtual bool CanDisplayWarning() const = 0;
|
||||||
virtual bool IsDisplayingWarning() const = 0;
|
|
||||||
|
|
||||||
virtual CNetObjHandler *GetNetObjHandler() = 0;
|
virtual CNetObjHandler *GetNetObjHandler() = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -2981,28 +2981,11 @@ void CClient::Run()
|
||||||
AutoStatScreenshot_Cleanup();
|
AutoStatScreenshot_Cleanup();
|
||||||
AutoCSV_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();
|
m_Fifo.Update();
|
||||||
|
|
||||||
|
if(State() == IClient::STATE_QUITTING || State() == IClient::STATE_RESTARTING)
|
||||||
|
break;
|
||||||
|
|
||||||
// beNice
|
// beNice
|
||||||
auto Now = time_get_nanoseconds();
|
auto Now = time_get_nanoseconds();
|
||||||
decltype(Now) SleepTimeInNanoSeconds{0};
|
decltype(Now) SleepTimeInNanoSeconds{0};
|
||||||
|
@ -3050,6 +3033,13 @@ void CClient::Run()
|
||||||
m_GlobalTime = (time_get() - m_GlobalStartTime) / (float)time_freq();
|
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();
|
m_Fifo.Shutdown();
|
||||||
|
|
||||||
GameClient()->OnShutdown();
|
GameClient()->OnShutdown();
|
||||||
|
@ -4172,6 +4162,26 @@ static bool SaveUnknownCommandCallback(const char *pCommand, void *pUser)
|
||||||
return true;
|
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
|
Server Time
|
||||||
Client Mirror Time
|
Client Mirror Time
|
||||||
|
@ -4490,8 +4500,15 @@ int main(int argc, const char **argv)
|
||||||
pStorage->GetBinaryPath(PLAT_CLIENT_EXEC, aRestartBinaryPath, sizeof(aRestartBinaryPath));
|
pStorage->GetBinaryPath(PLAT_CLIENT_EXEC, aRestartBinaryPath, sizeof(aRestartBinaryPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<SWarning> vQuittingWarnings = pClient->QuittingWarnings();
|
||||||
|
|
||||||
PerformCleanup();
|
PerformCleanup();
|
||||||
|
|
||||||
|
for(const SWarning &Warning : vQuittingWarnings)
|
||||||
|
{
|
||||||
|
::ShowMessageBox(Warning.m_aWarningTitle, Warning.m_aWarningMsg);
|
||||||
|
}
|
||||||
|
|
||||||
if(Restarting)
|
if(Restarting)
|
||||||
{
|
{
|
||||||
shell_execute(aRestartBinaryPath, EShellExecuteWindowState::FOREGROUND);
|
shell_execute(aRestartBinaryPath, EShellExecuteWindowState::FOREGROUND);
|
||||||
|
@ -4708,25 +4725,10 @@ void CClient::ShellUnregister()
|
||||||
}
|
}
|
||||||
#endif
|
#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)
|
void CClient::ShowMessageBox(const char *pTitle, const char *pMessage, EMessageBoxType Type)
|
||||||
{
|
{
|
||||||
if(m_pGraphics == nullptr || !m_pGraphics->ShowMessageBox(GetSdlMessageBoxFlags(Type), pTitle, pMessage))
|
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])
|
void CClient::GetGPUInfoString(char (&aGPUInfo)[256])
|
||||||
|
|
|
@ -228,6 +228,7 @@ class CClient : public IClient, public CDemoPlayer::IListener
|
||||||
} m_VersionInfo;
|
} m_VersionInfo;
|
||||||
|
|
||||||
std::vector<SWarning> m_vWarnings;
|
std::vector<SWarning> m_vWarnings;
|
||||||
|
std::vector<SWarning> m_vQuittingWarnings;
|
||||||
|
|
||||||
CFifo m_Fifo;
|
CFifo m_Fifo;
|
||||||
|
|
||||||
|
@ -495,6 +496,7 @@ public:
|
||||||
|
|
||||||
void AddWarning(const SWarning &Warning) override;
|
void AddWarning(const SWarning &Warning) override;
|
||||||
SWarning *GetCurWarning() override;
|
SWarning *GetCurWarning() override;
|
||||||
|
std::vector<SWarning> &&QuittingWarnings() { return std::move(m_vQuittingWarnings); }
|
||||||
|
|
||||||
CChecksumData *ChecksumData() override { return &m_Checksum.m_Data; }
|
CChecksumData *ChecksumData() override { return &m_Checksum.m_Data; }
|
||||||
int UdpConnectivity(int NetType) override;
|
int UdpConnectivity(int NetType) override;
|
||||||
|
|
|
@ -445,6 +445,7 @@ bool CConfigManager::Save()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log_info("config", "saved to " CONFIG_FILE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -731,7 +731,6 @@ public:
|
||||||
void UpdateOwnGhost(CGhostItem Item);
|
void UpdateOwnGhost(CGhostItem Item);
|
||||||
void DeleteGhostItem(int Index);
|
void DeleteGhostItem(int Index);
|
||||||
|
|
||||||
int GetCurPopup() const { return m_Popup; }
|
|
||||||
bool CanDisplayWarning() const;
|
bool CanDisplayWarning() const;
|
||||||
|
|
||||||
void PopupWarning(const char *pTopic, const char *pBody, const char *pButton, std::chrono::nanoseconds Duration);
|
void PopupWarning(const char *pTopic, const char *pBody, const char *pButton, std::chrono::nanoseconds Duration);
|
||||||
|
|
|
@ -3520,11 +3520,6 @@ bool CGameClient::CanDisplayWarning() const
|
||||||
return m_Menus.CanDisplayWarning();
|
return m_Menus.CanDisplayWarning();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CGameClient::IsDisplayingWarning() const
|
|
||||||
{
|
|
||||||
return m_Menus.GetCurPopup() == CMenus::POPUP_WARNING;
|
|
||||||
}
|
|
||||||
|
|
||||||
CNetObjHandler *CGameClient::GetNetObjHandler()
|
CNetObjHandler *CGameClient::GetNetObjHandler()
|
||||||
{
|
{
|
||||||
return &m_NetObjHandler;
|
return &m_NetObjHandler;
|
||||||
|
|
|
@ -555,7 +555,6 @@ public:
|
||||||
int SwitchStateTeam() const;
|
int SwitchStateTeam() const;
|
||||||
bool IsLocalCharSuper() const;
|
bool IsLocalCharSuper() const;
|
||||||
bool CanDisplayWarning() const override;
|
bool CanDisplayWarning() const override;
|
||||||
bool IsDisplayingWarning() const override;
|
|
||||||
CNetObjHandler *GetNetObjHandler() override;
|
CNetObjHandler *GetNetObjHandler() override;
|
||||||
|
|
||||||
void LoadGameSkin(const char *pPath, bool AsDir = false);
|
void LoadGameSkin(const char *pPath, bool AsDir = false);
|
||||||
|
|
Loading…
Reference in a new issue