Merge pull request #8504 from MilkeeyCat/pr_ddnet_trim_strings_in_search_and_exclude_inputs

Trim Strings on Search/Exclude Filter & Add Tooltip
This commit is contained in:
Robert Müller 2024-06-23 13:13:31 +00:00 committed by GitHub
commit 80ff5157d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 15 deletions

View file

@ -484,22 +484,26 @@ void CServerBrowser::Filter()
const char *pStr = g_Config.m_BrFilterString;
char aFilterStr[sizeof(g_Config.m_BrFilterString)];
char aFilterStrTrimmed[sizeof(g_Config.m_BrFilterString)];
while((pStr = str_next_token(pStr, IServerBrowser::SEARCH_EXCLUDE_TOKEN, aFilterStr, sizeof(aFilterStr))))
{
if(aFilterStr[0] == '\0')
str_copy(aFilterStrTrimmed, str_utf8_skip_whitespaces(aFilterStr));
str_utf8_trim_right(aFilterStrTrimmed);
if(aFilterStrTrimmed[0] == '\0')
{
continue;
}
auto MatchesFn = matchesPart;
const int FilterLen = str_length(aFilterStr);
if(aFilterStr[0] == '"' && aFilterStr[FilterLen - 1] == '"')
const int FilterLen = str_length(aFilterStrTrimmed);
if(aFilterStrTrimmed[0] == '"' && aFilterStrTrimmed[FilterLen - 1] == '"')
{
aFilterStr[FilterLen - 1] = '\0';
aFilterStrTrimmed[FilterLen - 1] = '\0';
MatchesFn = matchesExactly;
}
// match against server name
if(MatchesFn(Info.m_aName, aFilterStr))
if(MatchesFn(Info.m_aName, aFilterStrTrimmed))
{
Info.m_QuickSearchHit |= IServerBrowser::QUICK_SERVERNAME;
}
@ -507,8 +511,8 @@ void CServerBrowser::Filter()
// match against players
for(int p = 0; p < minimum(Info.m_NumClients, (int)MAX_CLIENTS); p++)
{
if(MatchesFn(Info.m_aClients[p].m_aName, aFilterStr) ||
MatchesFn(Info.m_aClients[p].m_aClan, aFilterStr))
if(MatchesFn(Info.m_aClients[p].m_aName, aFilterStrTrimmed) ||
MatchesFn(Info.m_aClients[p].m_aClan, aFilterStrTrimmed))
{
if(g_Config.m_BrFilterConnectingPlayers &&
str_comp(Info.m_aClients[p].m_aName, "(connecting)") == 0 &&
@ -522,7 +526,7 @@ void CServerBrowser::Filter()
}
// match against map
if(MatchesFn(Info.m_aMap, aFilterStr))
if(MatchesFn(Info.m_aMap, aFilterStrTrimmed))
{
Info.m_QuickSearchHit |= IServerBrowser::QUICK_MAPNAME;
}
@ -536,36 +540,40 @@ void CServerBrowser::Filter()
{
const char *pStr = g_Config.m_BrExcludeString;
char aExcludeStr[sizeof(g_Config.m_BrExcludeString)];
char aExcludeStrTrimmed[sizeof(g_Config.m_BrExcludeString)];
while((pStr = str_next_token(pStr, IServerBrowser::SEARCH_EXCLUDE_TOKEN, aExcludeStr, sizeof(aExcludeStr))))
{
if(aExcludeStr[0] == '\0')
str_copy(aExcludeStrTrimmed, str_utf8_skip_whitespaces(aExcludeStr));
str_utf8_trim_right(aExcludeStrTrimmed);
if(aExcludeStrTrimmed[0] == '\0')
{
continue;
}
auto MatchesFn = matchesPart;
const int FilterLen = str_length(aExcludeStr);
if(aExcludeStr[0] == '"' && aExcludeStr[FilterLen - 1] == '"')
const int FilterLen = str_length(aExcludeStrTrimmed);
if(aExcludeStrTrimmed[0] == '"' && aExcludeStrTrimmed[FilterLen - 1] == '"')
{
aExcludeStr[FilterLen - 1] = '\0';
aExcludeStrTrimmed[FilterLen - 1] = '\0';
MatchesFn = matchesExactly;
}
// match against server name
if(MatchesFn(Info.m_aName, aExcludeStr))
if(MatchesFn(Info.m_aName, aExcludeStrTrimmed))
{
Filtered = true;
break;
}
// match against map
if(MatchesFn(Info.m_aMap, aExcludeStr))
if(MatchesFn(Info.m_aMap, aExcludeStrTrimmed))
{
Filtered = true;
break;
}
// match against gametype
if(MatchesFn(Info.m_aGameType, aExcludeStr))
if(MatchesFn(Info.m_aGameType, aExcludeStrTrimmed))
{
Filtered = true;
break;

View file

@ -502,6 +502,9 @@ void CMenus::RenderServerbrowserStatusBox(CUIRect StatusBox, bool WasListboxItem
QuickSearch.VSplitLeft(5.0f, nullptr, &QuickSearch);
static CLineInput s_FilterInput(g_Config.m_BrFilterString, sizeof(g_Config.m_BrFilterString));
static char s_aTooltipText[64];
str_format(s_aTooltipText, sizeof(s_aTooltipText), "%s: \"solo; nameless tee; kobra 2\"", Localize("Example of usage"));
GameClient()->m_Tooltips.DoToolTip(&s_FilterInput, &QuickSearch, s_aTooltipText);
if(!Ui()->IsPopupOpen() && Input()->KeyPress(KEY_F) && Input()->ModifierIsPressed())
{
Ui()->SetActiveItem(&s_FilterInput);
@ -528,6 +531,9 @@ void CMenus::RenderServerbrowserStatusBox(CUIRect StatusBox, bool WasListboxItem
QuickExclude.VSplitLeft(5.0f, nullptr, &QuickExclude);
static CLineInput s_ExcludeInput(g_Config.m_BrExcludeString, sizeof(g_Config.m_BrExcludeString));
static char s_aTooltipText[64];
str_format(s_aTooltipText, sizeof(s_aTooltipText), "%s: \"CHN; [A]\"", Localize("Example of usage"));
GameClient()->m_Tooltips.DoToolTip(&s_ExcludeInput, &QuickSearch, s_aTooltipText);
if(!Ui()->IsPopupOpen() && Input()->KeyPress(KEY_X) && Input()->ShiftIsPressed() && Input()->ModifierIsPressed())
{
Ui()->SetActiveItem(&s_ExcludeInput);