Merge pull request #7967 from Robyt3/Browser-None-Placeholder-Country-Type

Add placeholder country/type for servers without community, fix filter excluding all items when right-clicking the only entry
This commit is contained in:
Dennis Felsing 2024-02-11 21:54:03 +00:00 committed by GitHub
commit 2d9a0c8b7a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 15 deletions

View file

@ -27,6 +27,9 @@
#include <engine/http.h> #include <engine/http.h>
#include <engine/storage.h> #include <engine/storage.h>
static constexpr const char *COMMUNITY_COUNTRY_NONE = "none";
static constexpr const char *COMMUNITY_TYPE_NONE = "None";
class CSortWrap class CSortWrap
{ {
typedef bool (CServerBrowser::*SortFunc)(int, int) const; typedef bool (CServerBrowser::*SortFunc)(int, int) const;
@ -1497,7 +1500,12 @@ void CServerBrowser::LoadDDNetServers()
} }
// Add default none community // 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 // Remove unknown elements from exclude lists
CleanFilters(); CleanFilters();
@ -1543,8 +1551,8 @@ void CServerBrowser::UpdateServerCommunity(CServerInfo *pInfo) const
} }
} }
str_copy(pInfo->m_aCommunityId, COMMUNITY_NONE); str_copy(pInfo->m_aCommunityId, COMMUNITY_NONE);
str_copy(pInfo->m_aCommunityCountry, ""); str_copy(pInfo->m_aCommunityCountry, COMMUNITY_COUNTRY_NONE);
str_copy(pInfo->m_aCommunityType, ""); str_copy(pInfo->m_aCommunityType, COMMUNITY_TYPE_NONE);
} }
void CServerBrowser::UpdateServerRank(CServerInfo *pInfo) const void CServerBrowser::UpdateServerRank(CServerInfo *pInfo) const
@ -1876,11 +1884,6 @@ void CExcludedCommunityCountryFilterList::Clear()
bool CExcludedCommunityCountryFilterList::Filtered(const char *pCountryName) const 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(); const auto Communities = m_CurrentCommunitiesGetter();
return std::none_of(Communities.begin(), Communities.end(), [&](const CCommunity *pCommunity) { return std::none_of(Communities.begin(), Communities.end(), [&](const CCommunity *pCommunity) {
if(!pCommunity->HasCountry(pCountryName)) if(!pCommunity->HasCountry(pCountryName))
@ -2020,11 +2023,6 @@ void CExcludedCommunityTypeFilterList::Clear()
bool CExcludedCommunityTypeFilterList::Filtered(const char *pTypeName) const 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(); const auto Communities = m_CurrentCommunitiesGetter();
return std::none_of(Communities.begin(), Communities.end(), [&](const CCommunity *pCommunity) { return std::none_of(Communities.begin(), Communities.end(), [&](const CCommunity *pCommunity) {
if(!pCommunity->HasType(pTypeName)) if(!pCommunity->HasType(pTypeName))

View file

@ -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 ColorActive = ColorRGBA(0.0f, 0.0f, 0.0f, 0.3f);
const ColorRGBA ColorInactive = ColorRGBA(0.0f, 0.0f, 0.0f, 0.15f); const ColorRGBA ColorInactive = ColorRGBA(0.0f, 0.0f, 0.0f, 0.15f);
@ -858,9 +860,12 @@ void CMenus::RenderServerbrowserDDNetFilter(CUIRect View,
else if(Click == 2) else if(Click == 2)
{ {
// Right click: when all are active, only deactivate one // Right click: when all are active, only deactivate one
if(MaxItems >= 2)
{
Filter.Add(GetItemName(ItemIndex)); Filter.Add(GetItemName(ItemIndex));
} }
} }
}
else else
{ {
bool AllFilteredExceptUs = true; bool AllFilteredExceptUs = true;