Show extra "Reset filter" button when no servers match filter

Render an additional "Reset filter" button below the "No servers match your filter criteria" message to make it more obvious for new players how to restore the original view of servers, especially when the filter tab is not currently selected.
This commit is contained in:
Robert Müller 2024-01-22 23:04:41 +01:00
parent 6829cd6ef6
commit 1f8a60b8e1
2 changed files with 42 additions and 20 deletions

View file

@ -461,6 +461,7 @@ protected:
void Connect(const char *pAddress);
void PopupConfirmSwitchServer();
void RenderServerbrowserFilters(CUIRect View);
void ResetServerbrowserFilters();
void RenderServerbrowserDDNetFilter(CUIRect View,
IFilterList &Filter,
float ItemHeight, int MaxItems, int ItemsPerRow,

View file

@ -199,11 +199,27 @@ void CMenus::RenderServerbrowserServerList(CUIRect View, bool &WasListboxItemAct
// users misses it
{
if(!ServerBrowser()->NumServers() && ServerBrowser()->IsGettingServerlist())
{
UI()->DoLabel(&View, Localize("Getting server list from master server"), 16.0f, TEXTALIGN_MC);
}
else if(!ServerBrowser()->NumServers())
{
UI()->DoLabel(&View, Localize("No servers found"), 16.0f, TEXTALIGN_MC);
}
else if(ServerBrowser()->NumServers() && !NumServers)
UI()->DoLabel(&View, Localize("No servers match your filter criteria"), 16.0f, TEXTALIGN_MC);
{
CUIRect Label, ResetButton;
View.HMargin((View.h - (16.0f + 18.0f + 8.0f)) / 2.0f, &Label);
Label.HSplitTop(16.0f, &Label, &ResetButton);
ResetButton.HSplitTop(8.0f, nullptr, &ResetButton);
ResetButton.VMargin((ResetButton.w - 200.0f) / 2.0f, &ResetButton);
UI()->DoLabel(&Label, Localize("No servers match your filter criteria"), 16.0f, TEXTALIGN_MC);
static CButtonContainer s_ResetButton;
if(DoButton_Menu(&s_ResetButton, Localize("Reset filter"), 0, &ResetButton))
{
ResetServerbrowserFilters();
}
}
}
s_ListBox.SetActive(!UI()->IsPopupOpen());
@ -767,28 +783,33 @@ void CMenus::RenderServerbrowserFilters(CUIRect View)
static CButtonContainer s_ResetButton;
if(DoButton_Menu(&s_ResetButton, Localize("Reset filter"), 0, &ResetButton))
{
g_Config.m_BrFilterString[0] = '\0';
g_Config.m_BrExcludeString[0] = '\0';
g_Config.m_BrFilterFull = 0;
g_Config.m_BrFilterEmpty = 0;
g_Config.m_BrFilterSpectators = 0;
g_Config.m_BrFilterFriends = 0;
g_Config.m_BrFilterCountry = 0;
g_Config.m_BrFilterCountryIndex = -1;
g_Config.m_BrFilterPw = 0;
g_Config.m_BrFilterGametype[0] = '\0';
g_Config.m_BrFilterGametypeStrict = 0;
g_Config.m_BrFilterConnectingPlayers = 1;
g_Config.m_BrFilterUnfinishedMap = 0;
g_Config.m_BrFilterServerAddress[0] = '\0';
ConfigManager()->Reset("br_filter_exclude_communities");
ConfigManager()->Reset("br_filter_exclude_countries");
ConfigManager()->Reset("br_filter_exclude_types");
Client()->ServerBrowserUpdate();
UpdateCommunityCache(true);
ResetServerbrowserFilters();
}
}
void CMenus::ResetServerbrowserFilters()
{
g_Config.m_BrFilterString[0] = '\0';
g_Config.m_BrExcludeString[0] = '\0';
g_Config.m_BrFilterFull = 0;
g_Config.m_BrFilterEmpty = 0;
g_Config.m_BrFilterSpectators = 0;
g_Config.m_BrFilterFriends = 0;
g_Config.m_BrFilterCountry = 0;
g_Config.m_BrFilterCountryIndex = -1;
g_Config.m_BrFilterPw = 0;
g_Config.m_BrFilterGametype[0] = '\0';
g_Config.m_BrFilterGametypeStrict = 0;
g_Config.m_BrFilterConnectingPlayers = 1;
g_Config.m_BrFilterUnfinishedMap = 0;
g_Config.m_BrFilterServerAddress[0] = '\0';
ConfigManager()->Reset("br_filter_exclude_communities");
ConfigManager()->Reset("br_filter_exclude_countries");
ConfigManager()->Reset("br_filter_exclude_types");
Client()->ServerBrowserUpdate();
UpdateCommunityCache(true);
}
void CMenus::RenderServerbrowserDDNetFilter(CUIRect View,
IFilterList &Filter,
float ItemHeight, int MaxItems, int ItemsPerRow,