mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Add IClient::ShowMessageBox
To show an error/warning/information message popup with variable title and message. This uses the SDL function `SDL_ShowSimpleMessageBox` to show the message box, because it is simpler than implementing this ourself in the base system, especially because we would have to add an additional explicit dependency on GTK3 to show a message dialog on Linux. This function can be used without SDL being initialized.
This commit is contained in:
parent
c9f68901b7
commit
00b7bc5bfd
|
@ -285,6 +285,14 @@ public:
|
|||
virtual void ShellRegister() = 0;
|
||||
virtual void ShellUnregister() = 0;
|
||||
#endif
|
||||
|
||||
enum EMessageBoxType
|
||||
{
|
||||
MESSAGE_BOX_TYPE_ERROR,
|
||||
MESSAGE_BOX_TYPE_WARNING,
|
||||
MESSAGE_BOX_TYPE_INFO,
|
||||
};
|
||||
virtual void ShowMessageBox(const char *pTitle, const char *pMessage, EMessageBoxType Type = MESSAGE_BOX_TYPE_ERROR) = 0;
|
||||
};
|
||||
|
||||
class IGameClient : public IInterface
|
||||
|
|
|
@ -4960,3 +4960,23 @@ void CClient::ShellUnregister()
|
|||
shell_update();
|
||||
}
|
||||
#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)
|
||||
{
|
||||
SDL_ShowSimpleMessageBox(GetSdlMessageBoxFlags(Type), pTitle, pMessage, nullptr);
|
||||
}
|
||||
|
|
|
@ -550,6 +550,8 @@ public:
|
|||
void ShellRegister() override;
|
||||
void ShellUnregister() override;
|
||||
#endif
|
||||
|
||||
void ShowMessageBox(const char *pTitle, const char *pMessage, EMessageBoxType Type = MESSAGE_BOX_TYPE_ERROR) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue