From e4e42277094a5ab090761741a713fd97f1e3c150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sun, 11 Feb 2024 17:21:54 +0100 Subject: [PATCH 1/2] Fix filter excluding all items when right-clicking the only entry It was possible to create a community/country/type filter excluding all entries when the list only contains one entry and right-click is used to deselect it. --- src/game/client/components/menus_browser.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index 5d826e289..adc1af8dd 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -858,7 +858,10 @@ void CMenus::RenderServerbrowserDDNetFilter(CUIRect View, else if(Click == 2) { // Right click: when all are active, only deactivate one - Filter.Add(GetItemName(ItemIndex)); + if(MaxItems >= 2) + { + Filter.Add(GetItemName(ItemIndex)); + } } } else From f0e71219a94fd74fbd2f4add9c2f3ad5f06de11e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sun, 11 Feb 2024 13:35:46 +0100 Subject: [PATCH 2/2] Add placeholder country/type for servers without community Add a country "none" with tee flag (code `-1`) and a type "None" for all servers without community. Previously, the country and type for these servers was unset and their handling special-cased, so any non-empty country/type filter would exclude servers without country/type information. Now individual countries/types can be excluded without also excluding all servers without community. Closes #7961. --- src/engine/client/serverbrowser.cpp | 24 +++++++++----------- src/game/client/components/menus_browser.cpp | 4 +++- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/engine/client/serverbrowser.cpp b/src/engine/client/serverbrowser.cpp index 73d1e2f25..dc0a664c0 100644 --- a/src/engine/client/serverbrowser.cpp +++ b/src/engine/client/serverbrowser.cpp @@ -27,6 +27,9 @@ #include #include +static constexpr const char *COMMUNITY_COUNTRY_NONE = "none"; +static constexpr const char *COMMUNITY_TYPE_NONE = "None"; + class CSortWrap { typedef bool (CServerBrowser::*SortFunc)(int, int) const; @@ -1497,7 +1500,12 @@ void CServerBrowser::LoadDDNetServers() } // Add default none community - m_vCommunities.emplace_back(COMMUNITY_NONE, "None", SHA256_ZEROED, ""); + { + CCommunity NoneCommunity(COMMUNITY_NONE, "None", SHA256_ZEROED, ""); + NoneCommunity.m_vCountries.emplace_back(COMMUNITY_COUNTRY_NONE, -1); + NoneCommunity.m_vTypes.emplace_back(COMMUNITY_TYPE_NONE); + m_vCommunities.push_back(std::move(NoneCommunity)); + } // Remove unknown elements from exclude lists CleanFilters(); @@ -1543,8 +1551,8 @@ void CServerBrowser::UpdateServerCommunity(CServerInfo *pInfo) const } } str_copy(pInfo->m_aCommunityId, COMMUNITY_NONE); - str_copy(pInfo->m_aCommunityCountry, ""); - str_copy(pInfo->m_aCommunityType, ""); + str_copy(pInfo->m_aCommunityCountry, COMMUNITY_COUNTRY_NONE); + str_copy(pInfo->m_aCommunityType, COMMUNITY_TYPE_NONE); } void CServerBrowser::UpdateServerRank(CServerInfo *pInfo) const @@ -1876,11 +1884,6 @@ void CExcludedCommunityCountryFilterList::Clear() bool CExcludedCommunityCountryFilterList::Filtered(const char *pCountryName) const { - // If the needle is not defined, we exclude it if there is any other - // exclusion, i.e. we only show those elements when the filter is empty. - if(pCountryName[0] == '\0') - return !Empty(); - const auto Communities = m_CurrentCommunitiesGetter(); return std::none_of(Communities.begin(), Communities.end(), [&](const CCommunity *pCommunity) { if(!pCommunity->HasCountry(pCountryName)) @@ -2020,11 +2023,6 @@ void CExcludedCommunityTypeFilterList::Clear() bool CExcludedCommunityTypeFilterList::Filtered(const char *pTypeName) const { - // If the needle is not defined, we exclude it if there is any other - // exclusion, i.e. we only show those elements when the filter is empty. - if(pTypeName[0] == '\0') - return !Empty(); - const auto Communities = m_CurrentCommunitiesGetter(); return std::none_of(Communities.begin(), Communities.end(), [&](const CCommunity *pCommunity) { if(!pCommunity->HasType(pTypeName)) diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index adc1af8dd..b501af976 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -724,7 +724,9 @@ void CMenus::RenderServerbrowserFilters(CUIRect View) } } - if(!m_CommunityCache.m_vpSelectableCountries.empty() || !m_CommunityCache.m_vpSelectableTypes.empty()) + // countries and types filters (not shown if there are no countries and types, or if only the none community is selected) + if((!m_CommunityCache.m_vpSelectableCountries.empty() || !m_CommunityCache.m_vpSelectableTypes.empty()) && + (m_CommunityCache.m_vpSelectedCommunities.size() != 1 || str_comp(m_CommunityCache.m_vpSelectedCommunities[0]->Id(), IServerBrowser::COMMUNITY_NONE) != 0)) { const ColorRGBA ColorActive = ColorRGBA(0.0f, 0.0f, 0.0f, 0.3f); const ColorRGBA ColorInactive = ColorRGBA(0.0f, 0.0f, 0.0f, 0.15f);