From e5f3943f6ede9aa6e4bbc1cfc7116d27c1839ee8 Mon Sep 17 00:00:00 2001 From: Lukas Kitsche Date: Thu, 22 Sep 2022 19:24:20 +0200 Subject: [PATCH 1/3] refresh serverbrowser when disconnecting / abort --- src/game/client/components/menus.cpp | 18 ++++++++++++++++++ src/game/client/components/menus_ingame.cpp | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index a6c3a4f4b..92a00c37b 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -1783,6 +1783,24 @@ int CMenus::Render() { Client()->Disconnect(); m_Popup = POPUP_NONE; + if(g_Config.m_UiPage == PAGE_INTERNET) + ServerBrowser()->Refresh(IServerBrowser::TYPE_INTERNET); + else if(g_Config.m_UiPage == PAGE_LAN) + ServerBrowser()->Refresh(IServerBrowser::TYPE_LAN); + else if(g_Config.m_UiPage == PAGE_FAVORITES) + ServerBrowser()->Refresh(IServerBrowser::TYPE_FAVORITES); + else if(g_Config.m_UiPage == PAGE_DDNET) + { + // start a new server list request + Client()->RequestDDNetInfo(); + ServerBrowser()->Refresh(IServerBrowser::TYPE_DDNET); + } + else if(g_Config.m_UiPage == PAGE_KOG) + { + // start a new server list request + Client()->RequestDDNetInfo(); + ServerBrowser()->Refresh(IServerBrowser::TYPE_KOG); + } } if(Client()->MapDownloadTotalsize() > 0) diff --git a/src/game/client/components/menus_ingame.cpp b/src/game/client/components/menus_ingame.cpp index a82447be1..b23c70660 100644 --- a/src/game/client/components/menus_ingame.cpp +++ b/src/game/client/components/menus_ingame.cpp @@ -61,6 +61,24 @@ void CMenus::RenderGame(CUIRect MainView) else { Client()->Disconnect(); + if(g_Config.m_UiPage == PAGE_INTERNET) + ServerBrowser()->Refresh(IServerBrowser::TYPE_INTERNET); + else if(g_Config.m_UiPage == PAGE_LAN) + ServerBrowser()->Refresh(IServerBrowser::TYPE_LAN); + else if(g_Config.m_UiPage == PAGE_FAVORITES) + ServerBrowser()->Refresh(IServerBrowser::TYPE_FAVORITES); + else if(g_Config.m_UiPage == PAGE_DDNET) + { + // start a new server list request + Client()->RequestDDNetInfo(); + ServerBrowser()->Refresh(IServerBrowser::TYPE_DDNET); + } + else if(g_Config.m_UiPage == PAGE_KOG) + { + // start a new server list request + Client()->RequestDDNetInfo(); + ServerBrowser()->Refresh(IServerBrowser::TYPE_KOG); + } } } From 43aae1bd829411c59931e6dd9f6ef1c1e84f768b Mon Sep 17 00:00:00 2001 From: Lukas Kitsche Date: Fri, 23 Sep 2022 19:59:18 +0200 Subject: [PATCH 2/3] move refresh logic of browsertab into helper function --- src/game/client/components/menus.cpp | 42 +++++++++++--------- src/game/client/components/menus.h | 1 + src/game/client/components/menus_browser.cpp | 20 +--------- src/game/client/components/menus_ingame.cpp | 19 +-------- 4 files changed, 27 insertions(+), 55 deletions(-) diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 92a00c37b..a87e72359 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -1298,6 +1298,7 @@ int CMenus::Render() s_Frame++; m_DoubleClickIndex = -1; + RefreshBrowserTab(g_Config.m_UiPage); if(g_Config.m_UiPage == PAGE_INTERNET) ServerBrowser()->Refresh(IServerBrowser::TYPE_INTERNET); else if(g_Config.m_UiPage == PAGE_LAN) @@ -1783,24 +1784,7 @@ int CMenus::Render() { Client()->Disconnect(); m_Popup = POPUP_NONE; - if(g_Config.m_UiPage == PAGE_INTERNET) - ServerBrowser()->Refresh(IServerBrowser::TYPE_INTERNET); - else if(g_Config.m_UiPage == PAGE_LAN) - ServerBrowser()->Refresh(IServerBrowser::TYPE_LAN); - else if(g_Config.m_UiPage == PAGE_FAVORITES) - ServerBrowser()->Refresh(IServerBrowser::TYPE_FAVORITES); - else if(g_Config.m_UiPage == PAGE_DDNET) - { - // start a new server list request - Client()->RequestDDNetInfo(); - ServerBrowser()->Refresh(IServerBrowser::TYPE_DDNET); - } - else if(g_Config.m_UiPage == PAGE_KOG) - { - // start a new server list request - Client()->RequestDDNetInfo(); - ServerBrowser()->Refresh(IServerBrowser::TYPE_KOG); - } + RefreshBrowserTab(g_Config.m_UiPage); } if(Client()->MapDownloadTotalsize() > 0) @@ -2745,6 +2729,28 @@ void CMenus::SetMenuPage(int NewPage) g_Config.m_UiPage = NewPage; } +void CMenus::RefreshBrowserTab(int UiPage) +{ + if(UiPage == PAGE_INTERNET) + ServerBrowser()->Refresh(IServerBrowser::TYPE_INTERNET); + else if(UiPage == PAGE_LAN) + ServerBrowser()->Refresh(IServerBrowser::TYPE_LAN); + else if(UiPage == PAGE_FAVORITES) + ServerBrowser()->Refresh(IServerBrowser::TYPE_FAVORITES); + else if(UiPage == PAGE_DDNET) + { + // start a new server list request + Client()->RequestDDNetInfo(); + ServerBrowser()->Refresh(IServerBrowser::TYPE_DDNET); + } + else if(UiPage == PAGE_KOG) + { + // start a new server list request + Client()->RequestDDNetInfo(); + ServerBrowser()->Refresh(IServerBrowser::TYPE_KOG); + } +} + bool CMenus::HandleListInputs(const CUIRect &View, float &ScrollValue, const float ScrollAmount, int *pScrollOffset, const float ElemHeight, int &SelectedIndex, const int NumElems) { if(NumElems == 0) diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index 99be4f151..5dbf08683 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -705,6 +705,7 @@ public: private: static int GhostlistFetchCallback(const char *pName, int IsDir, int StorageType, void *pUser); void SetMenuPage(int NewPage); + void RefreshBrowserTab(int UiPage); bool HandleListInputs(const CUIRect &View, float &ScrollValue, float ScrollAmount, int *pScrollOffset, float ElemHeight, int &SelectedIndex, int NumElems); // found in menus_ingame.cpp diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index f07068969..0cbbefcba 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -631,25 +631,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) if(DoButtonMenu(m_RefreshButton, &s_RefreshButton, Func, 0, &ButtonRefresh, true, false, IGraphics::CORNER_ALL) || Input()->KeyPress(KEY_F5) || (Input()->KeyPress(KEY_R) && Input()->ModifierIsPressed())) { - if(g_Config.m_UiPage == PAGE_INTERNET) - ServerBrowser()->Refresh(IServerBrowser::TYPE_INTERNET); - else if(g_Config.m_UiPage == PAGE_LAN) - ServerBrowser()->Refresh(IServerBrowser::TYPE_LAN); - else if(g_Config.m_UiPage == PAGE_FAVORITES) - ServerBrowser()->Refresh(IServerBrowser::TYPE_FAVORITES); - else if(g_Config.m_UiPage == PAGE_DDNET) - { - // start a new server list request - Client()->RequestDDNetInfo(); - ServerBrowser()->Refresh(IServerBrowser::TYPE_DDNET); - } - else if(g_Config.m_UiPage == PAGE_KOG) - { - // start a new server list request - Client()->RequestDDNetInfo(); - ServerBrowser()->Refresh(IServerBrowser::TYPE_KOG); - } - m_DoubleClickIndex = -1; + RefreshBrowserTab(g_Config.m_UiPage); } static int s_JoinButton = 0; diff --git a/src/game/client/components/menus_ingame.cpp b/src/game/client/components/menus_ingame.cpp index b23c70660..ed543c67b 100644 --- a/src/game/client/components/menus_ingame.cpp +++ b/src/game/client/components/menus_ingame.cpp @@ -61,24 +61,7 @@ void CMenus::RenderGame(CUIRect MainView) else { Client()->Disconnect(); - if(g_Config.m_UiPage == PAGE_INTERNET) - ServerBrowser()->Refresh(IServerBrowser::TYPE_INTERNET); - else if(g_Config.m_UiPage == PAGE_LAN) - ServerBrowser()->Refresh(IServerBrowser::TYPE_LAN); - else if(g_Config.m_UiPage == PAGE_FAVORITES) - ServerBrowser()->Refresh(IServerBrowser::TYPE_FAVORITES); - else if(g_Config.m_UiPage == PAGE_DDNET) - { - // start a new server list request - Client()->RequestDDNetInfo(); - ServerBrowser()->Refresh(IServerBrowser::TYPE_DDNET); - } - else if(g_Config.m_UiPage == PAGE_KOG) - { - // start a new server list request - Client()->RequestDDNetInfo(); - ServerBrowser()->Refresh(IServerBrowser::TYPE_KOG); - } + RefreshBrowserTab(g_Config.m_UiPage); } } From 599eb18245bfc355241aa4a3ee8812501c515808 Mon Sep 17 00:00:00 2001 From: Lukas Kitsche Date: Sat, 24 Sep 2022 00:56:43 +0200 Subject: [PATCH 3/3] fix linting, will be squashed later --- src/game/client/components/menus.cpp | 34 ++++++++++++++-------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index a87e72359..4056562b2 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -2732,23 +2732,23 @@ void CMenus::SetMenuPage(int NewPage) void CMenus::RefreshBrowserTab(int UiPage) { if(UiPage == PAGE_INTERNET) - ServerBrowser()->Refresh(IServerBrowser::TYPE_INTERNET); - else if(UiPage == PAGE_LAN) - ServerBrowser()->Refresh(IServerBrowser::TYPE_LAN); - else if(UiPage == PAGE_FAVORITES) - ServerBrowser()->Refresh(IServerBrowser::TYPE_FAVORITES); - else if(UiPage == PAGE_DDNET) - { - // start a new server list request - Client()->RequestDDNetInfo(); - ServerBrowser()->Refresh(IServerBrowser::TYPE_DDNET); - } - else if(UiPage == PAGE_KOG) - { - // start a new server list request - Client()->RequestDDNetInfo(); - ServerBrowser()->Refresh(IServerBrowser::TYPE_KOG); - } + ServerBrowser()->Refresh(IServerBrowser::TYPE_INTERNET); + else if(UiPage == PAGE_LAN) + ServerBrowser()->Refresh(IServerBrowser::TYPE_LAN); + else if(UiPage == PAGE_FAVORITES) + ServerBrowser()->Refresh(IServerBrowser::TYPE_FAVORITES); + else if(UiPage == PAGE_DDNET) + { + // start a new server list request + Client()->RequestDDNetInfo(); + ServerBrowser()->Refresh(IServerBrowser::TYPE_DDNET); + } + else if(UiPage == PAGE_KOG) + { + // start a new server list request + Client()->RequestDDNetInfo(); + ServerBrowser()->Refresh(IServerBrowser::TYPE_KOG); + } } bool CMenus::HandleListInputs(const CUIRect &View, float &ScrollValue, const float ScrollAmount, int *pScrollOffset, const float ElemHeight, int &SelectedIndex, const int NumElems)