Make the country/type selection more intuitive

I watched a live stream where someone struggled with this, not knowing
that right click has different functionality from left click, and had to
manually click on each entry to remove them all except one.
This commit is contained in:
def 2021-08-05 11:28:31 +02:00
parent 4a77882fcc
commit 20f0078206

View file

@ -870,25 +870,44 @@ void CMenus::RenderServerbrowserFilters(CUIRect View)
Rect.h = TypesHeight; Rect.h = TypesHeight;
int Button = UI()->DoButtonLogic(&s_aTypeButtons[TypeIndex], "", 0, &Rect); int Button = UI()->DoButtonLogic(&s_aTypeButtons[TypeIndex], "", 0, &Rect);
if(Button == 1) if(Button == 1 || Button == 2)
{ {
// left click to toggle flag filter // left/right click to toggle filter
if(Active) if(pFilterExcludeTypes[0] == '\0')
ServerBrowser()->DDNetFilterAdd(pFilterExcludeTypes, pName);
else
ServerBrowser()->DDNetFilterRem(pFilterExcludeTypes, pName);
ServerBrowser()->Refresh(ServerBrowser()->GetCurrentType());
}
else if(Button == 2)
{
// right click to exclusively activate one
pFilterExcludeTypes[0] = '\0';
for(int j = 0; j < MaxTypes; ++j)
{ {
if(j != TypeIndex) // when all are active, only activate one
ServerBrowser()->DDNetFilterAdd(pFilterExcludeTypes, ServerBrowser()->GetType(Network, j)); for(int j = 0; j < MaxTypes; ++j)
{
if(j != TypeIndex)
ServerBrowser()->DDNetFilterAdd(pFilterExcludeTypes, ServerBrowser()->GetType(Network, j));
}
} }
else
{
bool AllFilteredExceptUs = true;
for(int j = 0; j < MaxTypes; ++j)
{
if(j != TypeIndex && !ServerBrowser()->DDNetFiltered(pFilterExcludeTypes, ServerBrowser()->GetType(Network, j)))
{
AllFilteredExceptUs = false;
break;
}
}
// when last one is removed, reset (re-enable all)
if(AllFilteredExceptUs)
{
pFilterExcludeTypes[0] = '\0';
}
else if(Active)
{
ServerBrowser()->DDNetFilterAdd(pFilterExcludeTypes, pName);
}
else
{
ServerBrowser()->DDNetFilterRem(pFilterExcludeTypes, pName);
}
}
ServerBrowser()->Refresh(ServerBrowser()->GetCurrentType()); ServerBrowser()->Refresh(ServerBrowser()->GetCurrentType());
} }
else if(Button == 3) else if(Button == 3)
@ -946,25 +965,44 @@ void CMenus::RenderServerbrowserFilters(CUIRect View)
Rect.h = FlagHeight; Rect.h = FlagHeight;
int Button = UI()->DoButtonLogic(&s_aFlagButtons[CountryIndex], "", 0, &Rect); int Button = UI()->DoButtonLogic(&s_aFlagButtons[CountryIndex], "", 0, &Rect);
if(Button == 1) if(Button == 1 || Button == 2)
{ {
// left click to toggle flag filter // left/right click to toggle filter
if(Active) if(pFilterExcludeCountries[0] == '\0')
ServerBrowser()->DDNetFilterAdd(pFilterExcludeCountries, pName);
else
ServerBrowser()->DDNetFilterRem(pFilterExcludeCountries, pName);
ServerBrowser()->Refresh(ServerBrowser()->GetCurrentType());
}
else if(Button == 2)
{
// right click to exclusively activate one
pFilterExcludeCountries[0] = '\0';
for(int j = 0; j < MaxFlags; ++j)
{ {
if(j != CountryIndex) // when all are active, only activate one
ServerBrowser()->DDNetFilterAdd(pFilterExcludeCountries, ServerBrowser()->GetCountryName(Network, j)); for(int j = 0; j < MaxFlags; ++j)
{
if(j != CountryIndex)
ServerBrowser()->DDNetFilterAdd(pFilterExcludeCountries, ServerBrowser()->GetCountryName(Network, j));
}
} }
else
{
bool AllFilteredExceptUs = true;
for(int j = 0; j < MaxFlags; ++j)
{
if(j != CountryIndex && !ServerBrowser()->DDNetFiltered(pFilterExcludeCountries, ServerBrowser()->GetCountryName(Network, j)))
{
AllFilteredExceptUs = false;
break;
}
}
// when last one is removed, reset (re-enable all)
if(AllFilteredExceptUs)
{
pFilterExcludeCountries[0] = '\0';
}
else if(Active)
{
ServerBrowser()->DDNetFilterAdd(pFilterExcludeCountries, pName);
}
else
{
ServerBrowser()->DDNetFilterRem(pFilterExcludeCountries, pName);
}
}
ServerBrowser()->Refresh(ServerBrowser()->GetCurrentType()); ServerBrowser()->Refresh(ServerBrowser()->GetCurrentType());
} }
else if(Button == 3) else if(Button == 3)