From 69517956194c8506248af86c0c9749b3620456e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Thu, 19 Oct 2023 21:01:00 +0200 Subject: [PATCH] Add title to engine warnings and make auto-hiding optional Make the title of warnings adjustable, with the default title being "Warning" to preserve existing code. Make auto-hiding configurable, so the automatic closing of warning popups after 10 seconds can be toggled. --- src/engine/warning.h | 18 ++++++++++++------ src/game/client/components/menus.cpp | 2 +- src/game/client/gameclient.cpp | 4 ++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/engine/warning.h b/src/engine/warning.h index 64941b504..0214a6b0f 100644 --- a/src/engine/warning.h +++ b/src/engine/warning.h @@ -3,15 +3,21 @@ struct SWarning { - SWarning() : - m_WasShown(false) {} - SWarning(const char *pMsg) : - m_WasShown(false) + SWarning() {} + SWarning(const char *pMsg) { - str_copy(m_aWarningMsg, pMsg, sizeof(m_aWarningMsg)); + str_copy(m_aWarningTitle, ""); + str_copy(m_aWarningMsg, pMsg); } + SWarning(const char *pTitle, const char *pMsg) + { + str_copy(m_aWarningTitle, pTitle); + str_copy(m_aWarningMsg, pMsg); + } + char m_aWarningTitle[128]; char m_aWarningMsg[256]; - bool m_WasShown; + bool m_WasShown = false; + bool m_AutoHide = true; }; #endif diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index d12523b7c..1d9aeb4bf 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -1786,7 +1786,7 @@ int CMenus::Render() Part.VMargin(120.0f, &Part); static CButtonContainer s_Button; - if(DoButton_Menu(&s_Button, pButtonText, 0, &Part) || UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE) || UI()->ConsumeHotkey(CUI::HOTKEY_ENTER) || (time_get_nanoseconds() - m_PopupWarningLastTime >= m_PopupWarningDuration)) + if(DoButton_Menu(&s_Button, pButtonText, 0, &Part) || UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE) || UI()->ConsumeHotkey(CUI::HOTKEY_ENTER) || (m_PopupWarningDuration > 0s && time_get_nanoseconds() - m_PopupWarningLastTime >= m_PopupWarningDuration)) { m_Popup = POPUP_NONE; SetActive(false); diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index c9e5c7439..e23fb57e1 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -673,9 +673,9 @@ void CGameClient::OnRender() // display gfx & client warnings for(SWarning *pWarning : {Graphics()->GetCurWarning(), Client()->GetCurWarning()}) { - if(pWarning != NULL && m_Menus.CanDisplayWarning()) + if(pWarning != nullptr && m_Menus.CanDisplayWarning()) { - m_Menus.PopupWarning(Localize("Warning"), pWarning->m_aWarningMsg, "Ok", 10s); + m_Menus.PopupWarning(pWarning->m_aWarningTitle[0] == '\0' ? Localize("Warning") : pWarning->m_aWarningTitle, pWarning->m_aWarningMsg, "Ok", pWarning->m_AutoHide ? 10s : 0s); pWarning->m_WasShown = true; } }