mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Merge pull request #7502 from Robyt3/Browser-CommunityFilter-Fixes
Prevent community filters excluding all elements, fix server browser update on community filter change via console
This commit is contained in:
commit
b4567d6e25
|
@ -1233,11 +1233,17 @@ void CServerBrowser::LoadDDNetServers()
|
|||
m_CommunityServersByAddr.clear();
|
||||
|
||||
if(!m_pDDNetInfo)
|
||||
{
|
||||
CleanFilters();
|
||||
return;
|
||||
}
|
||||
|
||||
const json_value &Communities = (*m_pDDNetInfo)["communities"];
|
||||
if(Communities.type != json_array)
|
||||
{
|
||||
CleanFilters();
|
||||
return;
|
||||
}
|
||||
|
||||
for(unsigned CommunityIndex = 0; CommunityIndex < Communities.u.array.length; ++CommunityIndex)
|
||||
{
|
||||
|
@ -1524,6 +1530,7 @@ bool CFilterList::Empty() const
|
|||
|
||||
void CFilterList::Clean(const std::vector<const char *> &vpAllowedElements)
|
||||
{
|
||||
size_t NumFiltered = 0;
|
||||
char aNewList[512];
|
||||
aNewList[0] = '\0';
|
||||
|
||||
|
@ -1534,10 +1541,15 @@ void CFilterList::Clean(const std::vector<const char *> &vpAllowedElements)
|
|||
if(aNewList[0] != '\0')
|
||||
str_append(aNewList, ",");
|
||||
str_append(aNewList, pElement);
|
||||
++NumFiltered;
|
||||
}
|
||||
}
|
||||
|
||||
str_copy(m_pFilter, aNewList, m_FilterSize);
|
||||
// Prevent filter that would exclude all allowed elements
|
||||
if(NumFiltered == vpAllowedElements.size())
|
||||
m_pFilter[0] = '\0';
|
||||
else
|
||||
str_copy(m_pFilter, aNewList, m_FilterSize);
|
||||
}
|
||||
|
||||
void CServerBrowser::CleanFilters()
|
||||
|
|
|
@ -688,8 +688,6 @@ void CMenus::RenderServerbrowserFilters(CUIRect View)
|
|||
// community filter
|
||||
if((g_Config.m_UiPage == PAGE_INTERNET || g_Config.m_UiPage == PAGE_FAVORITES) && !ServerBrowser()->Communities().empty())
|
||||
{
|
||||
ServerBrowser()->CleanFilters();
|
||||
|
||||
CUIRect Row;
|
||||
View.HSplitTop(6.0f, nullptr, &View);
|
||||
View.HSplitTop(19.0f, &Row, &View);
|
||||
|
@ -1742,8 +1740,13 @@ void CMenus::ConchainFavoritesUpdate(IConsole::IResult *pResult, void *pUserData
|
|||
void CMenus::ConchainCommunitiesUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
|
||||
{
|
||||
pfnCallback(pResult, pCallbackUserData);
|
||||
CMenus *pThis = static_cast<CMenus *>(pUserData);
|
||||
if(pResult->NumArguments() >= 1 && (g_Config.m_UiPage == PAGE_INTERNET || g_Config.m_UiPage == PAGE_FAVORITES))
|
||||
((CMenus *)pUserData)->UpdateCommunityCache(true);
|
||||
{
|
||||
pThis->ServerBrowser()->CleanFilters();
|
||||
pThis->UpdateCommunityCache(true);
|
||||
pThis->Client()->ServerBrowserUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
void CMenus::UpdateCommunityCache(bool Force)
|
||||
|
|
Loading…
Reference in a new issue