5864: refresh serverbrowser when disconnecting / abort r=def- a=luk51

This might be not complete, but this adds the functionality to refresh the server browser list after disconnecting from a server, or after aborting joining a server.

This fixes issue #5863.


## Checklist

- [x] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [x] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Lukas Kitsche <lukaskitsche@posteo.de>
This commit is contained in:
bors[bot] 2022-09-23 23:24:58 +00:00 committed by GitHub
commit 4f3a9cbd0d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 19 deletions

View file

@ -1298,6 +1298,7 @@ int CMenus::Render()
s_Frame++; s_Frame++;
m_DoubleClickIndex = -1; m_DoubleClickIndex = -1;
RefreshBrowserTab(g_Config.m_UiPage);
if(g_Config.m_UiPage == PAGE_INTERNET) if(g_Config.m_UiPage == PAGE_INTERNET)
ServerBrowser()->Refresh(IServerBrowser::TYPE_INTERNET); ServerBrowser()->Refresh(IServerBrowser::TYPE_INTERNET);
else if(g_Config.m_UiPage == PAGE_LAN) else if(g_Config.m_UiPage == PAGE_LAN)
@ -1783,6 +1784,7 @@ int CMenus::Render()
{ {
Client()->Disconnect(); Client()->Disconnect();
m_Popup = POPUP_NONE; m_Popup = POPUP_NONE;
RefreshBrowserTab(g_Config.m_UiPage);
} }
if(Client()->MapDownloadTotalsize() > 0) if(Client()->MapDownloadTotalsize() > 0)
@ -2727,6 +2729,28 @@ void CMenus::SetMenuPage(int NewPage)
g_Config.m_UiPage = 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) bool CMenus::HandleListInputs(const CUIRect &View, float &ScrollValue, const float ScrollAmount, int *pScrollOffset, const float ElemHeight, int &SelectedIndex, const int NumElems)
{ {
if(NumElems == 0) if(NumElems == 0)

View file

@ -705,6 +705,7 @@ public:
private: private:
static int GhostlistFetchCallback(const char *pName, int IsDir, int StorageType, void *pUser); static int GhostlistFetchCallback(const char *pName, int IsDir, int StorageType, void *pUser);
void SetMenuPage(int NewPage); 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); bool HandleListInputs(const CUIRect &View, float &ScrollValue, float ScrollAmount, int *pScrollOffset, float ElemHeight, int &SelectedIndex, int NumElems);
// found in menus_ingame.cpp // found in menus_ingame.cpp

View file

@ -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(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) RefreshBrowserTab(g_Config.m_UiPage);
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;
} }
static int s_JoinButton = 0; static int s_JoinButton = 0;

View file

@ -61,6 +61,7 @@ void CMenus::RenderGame(CUIRect MainView)
else else
{ {
Client()->Disconnect(); Client()->Disconnect();
RefreshBrowserTab(g_Config.m_UiPage);
} }
} }