From a45f833afaa07a7bb70a39b3aae074545f176de8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Wed, 30 Nov 2022 23:41:32 +0100 Subject: [PATCH] Replace `POPUP_SWITCH_SERVER` with generic confirmation popup --- src/game/client/components/menus.cpp | 28 ---------------- src/game/client/components/menus.h | 3 +- src/game/client/components/menus_browser.cpp | 34 +++++++++++--------- 3 files changed, 20 insertions(+), 45 deletions(-) diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index dde570c08..22ece69c2 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -1618,11 +1618,6 @@ int CMenus::Render() pButtonText = m_aMessageButton; ExtraAlign = -1; } - else if(m_Popup == POPUP_SWITCH_SERVER) - { - pTitle = Localize("Disconnect"); - pExtraText = Localize("Are you sure that you want to disconnect and switch to a different server?"); - } CUIRect Box, Part; Box = Screen; @@ -2159,29 +2154,6 @@ int CMenus::Render() SetActive(false); } } - else if(m_Popup == POPUP_SWITCH_SERVER) - { - CUIRect Yes, No; - Box.HSplitBottom(20.f, &Box, &Part); - Box.HSplitBottom(24.f, &Box, &Part); - - // buttons - Part.VMargin(80.0f, &Part); - Part.VSplitMid(&No, &Yes); - Yes.VMargin(20.0f, &Yes); - No.VMargin(20.0f, &No); - - static CButtonContainer s_ButtonAbort; - if(DoButton_Menu(&s_ButtonAbort, Localize("No"), 0, &No) || UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE)) - { - m_Popup = POPUP_NONE; - m_aNextServer[0] = '\0'; - } - - static CButtonContainer s_ButtonTryAgain; - if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || UI()->ConsumeHotkey(CUI::HOTKEY_ENTER)) - Client()->Connect(m_aNextServer); - } else { Box.HSplitBottom(20.f, &Box, &Part); diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index 49e679a15..e92347d48 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -544,6 +544,8 @@ protected: int m_DoubleClickIndex; int m_ScrollOffset; void RenderServerbrowserServerList(CUIRect View); + void Connect(const char *pAddress); + void PopupConfirmSwitchServer(); void RenderServerbrowserServerDetail(CUIRect View); void RenderServerbrowserFilters(CUIRect View); void RenderServerbrowserFriends(CUIRect View); @@ -731,7 +733,6 @@ public: POPUP_PASSWORD, POPUP_QUIT, POPUP_WARNING, - POPUP_SWITCH_SERVER, // demo player states DEMOPLAYER_NONE = 0, diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index acbb41dba..bd3bd345d 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -509,15 +509,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) const CServerInfo *pItem = ServerBrowser()->SortedGet(NewSelected); str_copy(g_Config.m_UiServerAddress, pItem->m_aAddress); if(DoubleClicked && Input()->MouseDoubleClick()) - { - if(Client()->State() == IClient::STATE_ONLINE && Client()->GetCurrentRaceTime() / 60 >= g_Config.m_ClConfirmDisconnectTime && g_Config.m_ClConfirmDisconnectTime >= 0) - { - m_Popup = POPUP_SWITCH_SERVER; - str_copy(m_aNextServer, g_Config.m_UiServerAddress); - } - else - Client()->Connect(g_Config.m_UiServerAddress); - } + Connect(g_Config.m_UiServerAddress); } //Status.Draw(ms_ColorTabbarActive, IGraphics::CORNER_B, 5.0f); @@ -668,17 +660,27 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) m_ConnectButton, &s_JoinButton, []() -> const char * { return Localize("Connect"); }, 0, &ButtonConnect, false, false, IGraphics::CORNER_ALL, 5, 0, vec4(0.7f, 1, 0.7f, 0.1f), vec4(0.7f, 1, 0.7f, 0.2f)) || UI()->ConsumeHotkey(CUI::HOTKEY_ENTER)) { - if(Client()->State() == IClient::STATE_ONLINE && Client()->GetCurrentRaceTime() / 60 >= g_Config.m_ClConfirmDisconnectTime && g_Config.m_ClConfirmDisconnectTime >= 0) - { - m_Popup = POPUP_SWITCH_SERVER; - str_copy(m_aNextServer, g_Config.m_UiServerAddress); - } - else - Client()->Connect(g_Config.m_UiServerAddress); + Connect(g_Config.m_UiServerAddress); } } } +void CMenus::Connect(const char *pAddress) +{ + if(Client()->State() == IClient::STATE_ONLINE && Client()->GetCurrentRaceTime() / 60 >= g_Config.m_ClConfirmDisconnectTime && g_Config.m_ClConfirmDisconnectTime >= 0) + { + str_copy(m_aNextServer, pAddress); + PopupConfirm(Localize("Disconnect"), Localize("Are you sure that you want to disconnect and switch to a different server?"), Localize("Yes"), Localize("No"), &CMenus::PopupConfirmSwitchServer); + } + else + Client()->Connect(pAddress); +} + +void CMenus::PopupConfirmSwitchServer() +{ + Client()->Connect(m_aNextServer); +} + void CMenus::RenderServerbrowserFilters(CUIRect View) { CUIRect ServerFilter = View, FilterHeader;