mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-14 03:58:18 +00:00
Exclude DDNet servery by type
This commit is contained in:
parent
3b0f768478
commit
8d945fe968
|
@ -561,17 +561,21 @@ void CServerBrowser::Refresh(int Type)
|
||||||
|
|
||||||
// remove unknown elements of exclude list
|
// remove unknown elements of exclude list
|
||||||
DDNetCountryFilterClean();
|
DDNetCountryFilterClean();
|
||||||
|
DDNetTypeFilterClean();
|
||||||
|
|
||||||
for(int i = 0; i < m_NumDDNetCountries; i++)
|
for(int i = 0; i < m_NumDDNetCountries; i++)
|
||||||
{
|
{
|
||||||
CDDNetCountry *pCntr = &m_aDDNetCountries[i];
|
CDDNetCountry *pCntr = &m_aDDNetCountries[i];
|
||||||
|
|
||||||
// check for filter
|
// check for filter
|
||||||
if (DDNetCountryFiltered(pCntr->m_aName))
|
if(DDNetFiltered(g_Config.m_BrFilterExcludeCountries, pCntr->m_aName))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for(int g = 0; g < pCntr->m_NumServers; g++)
|
for(int g = 0; g < pCntr->m_NumServers; g++)
|
||||||
Set(pCntr->m_aServers[g], IServerBrowser::SET_DDNET_ADD, -1, 0);
|
{
|
||||||
|
if(!DDNetFiltered(g_Config.m_BrFilterExcludeTypes, pCntr->m_aTypes[g]))
|
||||||
|
Set(pCntr->m_aServers[g], IServerBrowser::SET_DDNET_ADD, -1, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -883,6 +887,7 @@ void CServerBrowser::LoadDDNet()
|
||||||
{
|
{
|
||||||
// reset servers / countries
|
// reset servers / countries
|
||||||
m_NumDDNetCountries = 0;
|
m_NumDDNetCountries = 0;
|
||||||
|
m_NumDDNetTypes = 0;
|
||||||
|
|
||||||
// load ddnet server list
|
// load ddnet server list
|
||||||
IStorage *pStorage = Kernel()->RequestInterface<IStorage>();
|
IStorage *pStorage = Kernel()->RequestInterface<IStorage>();
|
||||||
|
@ -906,12 +911,15 @@ void CServerBrowser::LoadDDNet()
|
||||||
{
|
{
|
||||||
// pSrv - { name, flagId, servers }
|
// pSrv - { name, flagId, servers }
|
||||||
const json_value *pSrv = json_array_get(pCountries, i);
|
const json_value *pSrv = json_array_get(pCountries, i);
|
||||||
const json_value *pAddrs = json_object_get(pSrv, "servers");
|
const json_value *pTypes = json_object_get(pSrv, "servers");
|
||||||
const json_value *pName = json_object_get(pSrv, "name");
|
const json_value *pName = json_object_get(pSrv, "name");
|
||||||
const json_value *pFlagID = json_object_get(pSrv, "flagId");
|
const json_value *pFlagID = json_object_get(pSrv, "flagId");
|
||||||
|
|
||||||
if (pSrv->type != json_object || pAddrs->type != json_array || pName->type != json_string || pFlagID->type != json_integer)
|
if (pSrv->type != json_object || pTypes->type != json_object || pName->type != json_string || pFlagID->type != json_integer)
|
||||||
continue; // invalid attributes
|
{
|
||||||
|
dbg_msg("client_srvbrowse", "Invalid attributes");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// build structure
|
// build structure
|
||||||
CDDNetCountry *pCntr = &m_aDDNetCountries[m_NumDDNetCountries];
|
CDDNetCountry *pCntr = &m_aDDNetCountries[m_NumDDNetCountries];
|
||||||
|
@ -921,14 +929,36 @@ void CServerBrowser::LoadDDNet()
|
||||||
str_copy(pCntr->m_aName, json_string_get(pName), sizeof(pCntr->m_aName));
|
str_copy(pCntr->m_aName, json_string_get(pName), sizeof(pCntr->m_aName));
|
||||||
pCntr->m_FlagID = json_int_get(pFlagID);
|
pCntr->m_FlagID = json_int_get(pFlagID);
|
||||||
|
|
||||||
// add addresses
|
// add country
|
||||||
for (int g = 0; g < json_array_length(pAddrs); g++)
|
for (unsigned int t = 0; t < pTypes->u.object.length; t++)
|
||||||
{
|
{
|
||||||
const json_value *pAddr = json_array_get(pAddrs, g);
|
const char *pType = pTypes->u.object.values[t].name;
|
||||||
const char *pStr = json_string_get(pAddr);
|
const json_value *pAddrs = pTypes->u.object.values[t].value;
|
||||||
|
|
||||||
net_addr_from_str(&pCntr->m_aServers[g], pStr);
|
// add type
|
||||||
pCntr->m_NumServers++;
|
if(json_array_length(pAddrs) > 0 && m_NumDDNetTypes < MAX_DDNET_TYPES)
|
||||||
|
{
|
||||||
|
int pos;
|
||||||
|
for(pos = 0; pos < m_NumDDNetTypes; pos++)
|
||||||
|
{
|
||||||
|
if(!str_comp(m_aDDNetTypes[pos], pType))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(pos == m_NumDDNetTypes)
|
||||||
|
{
|
||||||
|
str_copy(m_aDDNetTypes[m_NumDDNetTypes], pType, sizeof(m_aDDNetTypes[m_NumDDNetTypes]));
|
||||||
|
m_NumDDNetTypes++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// add addresses
|
||||||
|
for (int g = 0; g < json_array_length(pAddrs); g++, pCntr->m_NumServers++)
|
||||||
|
{
|
||||||
|
const json_value *pAddr = json_array_get(pAddrs, g);
|
||||||
|
const char* pStr = json_string_get(pAddr);
|
||||||
|
net_addr_from_str(&pCntr->m_aServers[pCntr->m_NumServers], pStr);
|
||||||
|
str_copy(pCntr->m_aTypes[pCntr->m_NumServers], pType, sizeof(pCntr->m_aTypes[pCntr->m_NumServers]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_NumDDNetCountries++;
|
m_NumDDNetCountries++;
|
||||||
|
@ -976,27 +1006,27 @@ void CServerBrowser::ConfigSaveCallback(IConfig *pConfig, void *pUserData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerBrowser::DDNetCountryFilterAdd(const char *pName)
|
void CServerBrowser::DDNetFilterAdd(char *pFilter, const char *pName)
|
||||||
{
|
{
|
||||||
if (DDNetCountryFiltered(pName))
|
if (DDNetFiltered(pFilter, pName))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
char aBuf[256];
|
char aBuf[128];
|
||||||
str_format(aBuf, sizeof(aBuf), ",%s", pName);
|
str_format(aBuf, sizeof(aBuf), ",%s", pName);
|
||||||
str_append(g_Config.m_BrFilterExcludeCountries, aBuf, sizeof(g_Config.m_BrFilterExcludeCountries));
|
str_append(pFilter, aBuf, 128);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerBrowser::DDNetCountryFilterRem(const char *pName)
|
void CServerBrowser::DDNetFilterRem(char *pFilter, const char *pName)
|
||||||
{
|
{
|
||||||
if (!DDNetCountryFiltered(pName))
|
if (!DDNetFiltered(pFilter, pName))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// rewrite exclude/filter list
|
// rewrite exclude/filter list
|
||||||
char aBuf[256];
|
char aBuf[128];
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
str_copy(aBuf, g_Config.m_BrFilterExcludeCountries, sizeof(aBuf));
|
str_copy(aBuf, pFilter, sizeof(aBuf));
|
||||||
g_Config.m_BrFilterExcludeCountries[0] = '\0';
|
pFilter[0] = '\0';
|
||||||
|
|
||||||
p = strtok(aBuf, ",");
|
p = strtok(aBuf, ",");
|
||||||
|
|
||||||
|
@ -1004,21 +1034,21 @@ void CServerBrowser::DDNetCountryFilterRem(const char *pName)
|
||||||
{
|
{
|
||||||
if(str_comp_nocase(pName, p) != 0)
|
if(str_comp_nocase(pName, p) != 0)
|
||||||
{
|
{
|
||||||
char aBuf2[256];
|
char aBuf2[128];
|
||||||
str_format(aBuf2, sizeof(aBuf2), ",%s", p);
|
str_format(aBuf2, sizeof(aBuf2), ",%s", p);
|
||||||
str_append(g_Config.m_BrFilterExcludeCountries, aBuf2, sizeof(g_Config.m_BrFilterExcludeCountries));
|
str_append(pFilter, aBuf2, 128);
|
||||||
}
|
}
|
||||||
|
|
||||||
p = strtok(NULL, ",");
|
p = strtok(NULL, ",");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CServerBrowser::DDNetCountryFiltered(const char *pName)
|
bool CServerBrowser::DDNetFiltered(char *pFilter, const char *pName)
|
||||||
{
|
{
|
||||||
char aBuf[256];
|
char aBuf[128];
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
str_copy(aBuf, g_Config.m_BrFilterExcludeCountries, sizeof(aBuf));
|
str_copy(aBuf, pFilter, sizeof(aBuf));
|
||||||
|
|
||||||
p = strtok(aBuf, ",");
|
p = strtok(aBuf, ",");
|
||||||
|
|
||||||
|
@ -1035,14 +1065,14 @@ bool CServerBrowser::DDNetCountryFiltered(const char *pName)
|
||||||
|
|
||||||
void CServerBrowser::DDNetCountryFilterClean()
|
void CServerBrowser::DDNetCountryFilterClean()
|
||||||
{
|
{
|
||||||
char aNewList[256];
|
char aNewList[128];
|
||||||
|
|
||||||
for(int i = 0; i < m_NumDDNetCountries; i++)
|
for(int i = 0; i < m_NumDDNetCountries; i++)
|
||||||
{
|
{
|
||||||
const char *pName = m_aDDNetCountries[i].m_aName;
|
const char *pName = m_aDDNetCountries[i].m_aName;
|
||||||
if(DDNetCountryFiltered(pName))
|
if(DDNetFiltered(g_Config.m_BrFilterExcludeCountries, pName))
|
||||||
{
|
{
|
||||||
char aBuf[256];
|
char aBuf[128];
|
||||||
str_format(aBuf, sizeof(aBuf), ",%s", pName);
|
str_format(aBuf, sizeof(aBuf), ",%s", pName);
|
||||||
str_append(aNewList, aBuf, sizeof(aNewList));
|
str_append(aNewList, aBuf, sizeof(aNewList));
|
||||||
}
|
}
|
||||||
|
@ -1050,3 +1080,21 @@ void CServerBrowser::DDNetCountryFilterClean()
|
||||||
|
|
||||||
str_copy(g_Config.m_BrFilterExcludeCountries, aNewList, sizeof(g_Config.m_BrFilterExcludeCountries));
|
str_copy(g_Config.m_BrFilterExcludeCountries, aNewList, sizeof(g_Config.m_BrFilterExcludeCountries));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CServerBrowser::DDNetTypeFilterClean()
|
||||||
|
{
|
||||||
|
char aNewList[128];
|
||||||
|
|
||||||
|
for(int i = 0; i < m_NumDDNetTypes; i++)
|
||||||
|
{
|
||||||
|
const char *pName = m_aDDNetTypes[i];
|
||||||
|
if(DDNetFiltered(g_Config.m_BrFilterExcludeTypes, pName))
|
||||||
|
{
|
||||||
|
char aBuf[128];
|
||||||
|
str_format(aBuf, sizeof(aBuf), ",%s", pName);
|
||||||
|
str_append(aNewList, aBuf, sizeof(aNewList));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
str_copy(g_Config.m_BrFilterExcludeTypes, aNewList, sizeof(g_Config.m_BrFilterExcludeTypes));
|
||||||
|
}
|
||||||
|
|
|
@ -34,16 +34,25 @@ public:
|
||||||
char m_aName[256];
|
char m_aName[256];
|
||||||
int m_FlagID;
|
int m_FlagID;
|
||||||
NETADDR m_aServers[MAX_SERVERS];
|
NETADDR m_aServers[MAX_SERVERS];
|
||||||
|
char m_aTypes[MAX_SERVERS][32];
|
||||||
int m_NumServers;
|
int m_NumServers;
|
||||||
|
|
||||||
void Reset() { m_NumServers = 0; m_FlagID = -1; m_aName[0] = '\0'; };
|
void Reset() { m_NumServers = 0; m_FlagID = -1; m_aName[0] = '\0'; };
|
||||||
void Add(NETADDR Addr) { if (m_NumServers < MAX_SERVERS) m_aServers[m_NumServers++] = Addr; };
|
/*void Add(NETADDR Addr, char* pType) {
|
||||||
|
if (m_NumServers < MAX_SERVERS)
|
||||||
|
{
|
||||||
|
m_aServers[m_NumServers] = Addr;
|
||||||
|
str_copy(m_aTypes[m_NumServers], pType, sizeof(m_aTypes[0]));
|
||||||
|
m_NumServers++;
|
||||||
|
}
|
||||||
|
};*/
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
MAX_FAVORITES=2048,
|
MAX_FAVORITES=2048,
|
||||||
MAX_DDNET_COUNTRIES=16,
|
MAX_DDNET_COUNTRIES=16,
|
||||||
|
MAX_DDNET_TYPES=32,
|
||||||
};
|
};
|
||||||
|
|
||||||
CServerBrowser();
|
CServerBrowser();
|
||||||
|
@ -67,10 +76,15 @@ public:
|
||||||
int NumDDNetCountries() { return m_NumDDNetCountries; };
|
int NumDDNetCountries() { return m_NumDDNetCountries; };
|
||||||
int GetDDNetCountryFlag(int Index) { return m_aDDNetCountries[Index].m_FlagID; };
|
int GetDDNetCountryFlag(int Index) { return m_aDDNetCountries[Index].m_FlagID; };
|
||||||
const char *GetDDNetCountryName(int Index) { return m_aDDNetCountries[Index].m_aName; };
|
const char *GetDDNetCountryName(int Index) { return m_aDDNetCountries[Index].m_aName; };
|
||||||
void DDNetCountryFilterAdd(const char *pName);
|
|
||||||
void DDNetCountryFilterRem(const char *pName);
|
int NumDDNetTypes() { return m_NumDDNetTypes; };
|
||||||
bool DDNetCountryFiltered(const char *pName);
|
const char *GetDDNetType(int Index) { return m_aDDNetTypes[Index]; };
|
||||||
|
|
||||||
|
void DDNetFilterAdd(char *pFilter, const char *pName);
|
||||||
|
void DDNetFilterRem(char *pFilter, const char *pName);
|
||||||
|
bool DDNetFiltered(char *pFilter, const char *pName);
|
||||||
void DDNetCountryFilterClean();
|
void DDNetCountryFilterClean();
|
||||||
|
void DDNetTypeFilterClean();
|
||||||
|
|
||||||
//
|
//
|
||||||
void Update(bool ForceResort);
|
void Update(bool ForceResort);
|
||||||
|
@ -100,6 +114,9 @@ private:
|
||||||
CDDNetCountry m_aDDNetCountries[MAX_DDNET_COUNTRIES];
|
CDDNetCountry m_aDDNetCountries[MAX_DDNET_COUNTRIES];
|
||||||
int m_NumDDNetCountries;
|
int m_NumDDNetCountries;
|
||||||
|
|
||||||
|
char m_aDDNetTypes[MAX_DDNET_TYPES][32];
|
||||||
|
int m_NumDDNetTypes;
|
||||||
|
|
||||||
CServerEntry *m_aServerlistIp[256]; // ip hash list
|
CServerEntry *m_aServerlistIp[256]; // ip hash list
|
||||||
|
|
||||||
CServerEntry *m_pFirstReqServer; // request list
|
CServerEntry *m_pFirstReqServer; // request list
|
||||||
|
|
|
@ -107,9 +107,13 @@ public:
|
||||||
virtual int NumDDNetCountries() = 0;
|
virtual int NumDDNetCountries() = 0;
|
||||||
virtual int GetDDNetCountryFlag(int Index) = 0;
|
virtual int GetDDNetCountryFlag(int Index) = 0;
|
||||||
virtual const char *GetDDNetCountryName(int Index) = 0;
|
virtual const char *GetDDNetCountryName(int Index) = 0;
|
||||||
virtual void DDNetCountryFilterAdd(const char *pName) = 0;
|
|
||||||
virtual void DDNetCountryFilterRem(const char *pName) = 0;
|
virtual int NumDDNetTypes() = 0;
|
||||||
virtual bool DDNetCountryFiltered(const char *pName) = 0;
|
virtual const char *GetDDNetType(int Index) = 0;
|
||||||
|
|
||||||
|
virtual void DDNetFilterAdd(char *pFilter, const char *pName) = 0;
|
||||||
|
virtual void DDNetFilterRem(char *pFilter, const char *pName) = 0;
|
||||||
|
virtual bool DDNetFiltered(char *pFilter, const char *pName) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -55,6 +55,7 @@ MACRO_CONFIG_INT(BrFilterPureMap, br_filter_pure_map, 0, 0, 1, CFGFLAG_SAVE|CFGF
|
||||||
MACRO_CONFIG_INT(BrFilterCompatversion, br_filter_compatversion, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Filter out non-compatible servers in browser")
|
MACRO_CONFIG_INT(BrFilterCompatversion, br_filter_compatversion, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Filter out non-compatible servers in browser")
|
||||||
|
|
||||||
MACRO_CONFIG_STR(BrFilterExcludeCountries, br_filter_exclude_countries, 128, "", CFGFLAG_SAVE|CFGFLAG_CLIENT, "Filter out ddnet servers by country")
|
MACRO_CONFIG_STR(BrFilterExcludeCountries, br_filter_exclude_countries, 128, "", CFGFLAG_SAVE|CFGFLAG_CLIENT, "Filter out ddnet servers by country")
|
||||||
|
MACRO_CONFIG_STR(BrFilterExcludeTypes, br_filter_exclude_types, 128, "", CFGFLAG_SAVE|CFGFLAG_CLIENT, "Filter out ddnet servers by type (mod)")
|
||||||
|
|
||||||
MACRO_CONFIG_INT(BrSort, br_sort, 1, 0, 256, CFGFLAG_SAVE|CFGFLAG_CLIENT, "")
|
MACRO_CONFIG_INT(BrSort, br_sort, 1, 0, 256, CFGFLAG_SAVE|CFGFLAG_CLIENT, "")
|
||||||
MACRO_CONFIG_INT(BrSortOrder, br_sort_order, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "")
|
MACRO_CONFIG_INT(BrSortOrder, br_sort_order, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "")
|
||||||
|
|
|
@ -598,7 +598,7 @@ void CMenus::RenderServerbrowserFilters(CUIRect View)
|
||||||
RenderTools()->DrawUIRect(&FilterHeader, vec4(1,1,1,0.25f), CUI::CORNER_T, 4.0f);
|
RenderTools()->DrawUIRect(&FilterHeader, vec4(1,1,1,0.25f), CUI::CORNER_T, 4.0f);
|
||||||
RenderTools()->DrawUIRect(&ServerFilter, vec4(0,0,0,0.15f), CUI::CORNER_B, 4.0f);
|
RenderTools()->DrawUIRect(&ServerFilter, vec4(0,0,0,0.15f), CUI::CORNER_B, 4.0f);
|
||||||
UI()->DoLabelScaled(&FilterHeader, Localize("Server filter"), FontSize+2.0f, 0);
|
UI()->DoLabelScaled(&FilterHeader, Localize("Server filter"), FontSize+2.0f, 0);
|
||||||
CUIRect Button;
|
CUIRect Button, Button2;
|
||||||
|
|
||||||
ServerFilter.VSplitLeft(5.0f, 0, &ServerFilter);
|
ServerFilter.VSplitLeft(5.0f, 0, &ServerFilter);
|
||||||
ServerFilter.Margin(3.0f, &ServerFilter);
|
ServerFilter.Margin(3.0f, &ServerFilter);
|
||||||
|
@ -701,80 +701,164 @@ void CMenus::RenderServerbrowserFilters(CUIRect View)
|
||||||
if (DoButton_CheckBox((char *)&g_Config.m_UiColorizePing, Localize("Colorize ping"), g_Config.m_UiColorizePing, &Button))
|
if (DoButton_CheckBox((char *)&g_Config.m_UiColorizePing, Localize("Colorize ping"), g_Config.m_UiColorizePing, &Button))
|
||||||
g_Config.m_UiColorizePing ^= 1;
|
g_Config.m_UiColorizePing ^= 1;
|
||||||
|
|
||||||
|
CUIRect ResetButton;
|
||||||
|
|
||||||
|
//ServerFilter.HSplitBottom(5.0f, &ServerFilter, 0);
|
||||||
|
ServerFilter.HSplitBottom(ms_ButtonHeight-2.0f, &ServerFilter, &ResetButton);
|
||||||
|
|
||||||
// ddnet country filters
|
// ddnet country filters
|
||||||
if(g_Config.m_UiPage == PAGE_DDNET)
|
if(g_Config.m_UiPage == PAGE_DDNET)
|
||||||
{
|
{
|
||||||
// add more space
|
// add more space
|
||||||
ServerFilter.HSplitTop(10.0f, &Button, &ServerFilter);
|
ServerFilter.HSplitTop(10.0f, 0, &ServerFilter);
|
||||||
|
ServerFilter.HSplitTop(20.0f, &Button, &ServerFilter);
|
||||||
|
ServerFilter.HSplitTop(95.0f, &ServerFilter, 0);
|
||||||
|
|
||||||
ServerFilter.HSplitTop(30.0f, &Button, &ServerFilter);
|
RenderTools()->DrawUIRect(&ServerFilter, ms_ColorTabbarActive, CUI::CORNER_B, 10.0f);
|
||||||
UI()->DoLabelScaled(&Button, Localize("DDNet Countries:"), FontSize, -1);
|
|
||||||
|
|
||||||
vec4 Color(1.0f, 1.0f, 1.0f, 1.0f);
|
Button.VSplitMid(&Button, &Button2);
|
||||||
|
|
||||||
const float FlagWidth = 40.0f;
|
static int s_ActivePage = 0;
|
||||||
const float FlagHeight = 20.0f;
|
|
||||||
|
|
||||||
int MaxFlags = ServerBrowser()->NumDDNetCountries();
|
static int s_CountriesButton = 0;
|
||||||
int NumFlags = ServerBrowser()->NumDDNetCountries();
|
if(DoButton_MenuTab(&s_CountriesButton, Localize("Countries"), s_ActivePage == 0, &Button, CUI::CORNER_TL))
|
||||||
int PerLine = MaxFlags > 9 ? 4 : 3;
|
|
||||||
|
|
||||||
CUIRect FlagsRect;
|
|
||||||
|
|
||||||
static int s_aFlagButtons[64];
|
|
||||||
|
|
||||||
while(NumFlags > 0)
|
|
||||||
{
|
{
|
||||||
ServerFilter.HSplitTop(30.0f, &FlagsRect, &ServerFilter);
|
s_ActivePage = 0;
|
||||||
|
}
|
||||||
|
|
||||||
for(int i = 0; i < PerLine && NumFlags > 0; i++)
|
static int s_TypesButton = 0;
|
||||||
|
if(DoButton_MenuTab(&s_TypesButton, Localize("Types"), s_ActivePage == 1, &Button2, CUI::CORNER_TR))
|
||||||
|
{
|
||||||
|
s_ActivePage = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(s_ActivePage == 1)
|
||||||
|
{
|
||||||
|
int MaxTypes = ServerBrowser()->NumDDNetTypes();
|
||||||
|
int NumTypes = ServerBrowser()->NumDDNetTypes();
|
||||||
|
int PerLine = 3;
|
||||||
|
|
||||||
|
if(MaxTypes <= 12)
|
||||||
|
ServerFilter.HSplitTop(8.0f, 0, &ServerFilter);
|
||||||
|
|
||||||
|
const float TypesWidth = 40.0f;
|
||||||
|
const float TypesHeight = MaxTypes > 12 ? 15.0f : 20.0f;
|
||||||
|
|
||||||
|
CUIRect TypesRect, Left, Right;
|
||||||
|
|
||||||
|
static int s_aTypeButtons[64];
|
||||||
|
|
||||||
|
while(NumTypes > 0)
|
||||||
{
|
{
|
||||||
int CountryIndex = MaxFlags - NumFlags;
|
ServerFilter.HSplitTop(TypesHeight, &TypesRect, &ServerFilter);
|
||||||
const char *pName = ServerBrowser()->GetDDNetCountryName(CountryIndex);
|
TypesRect.VSplitMid(&Left, &Right);
|
||||||
bool Active = !ServerBrowser()->DDNetCountryFiltered(pName);
|
|
||||||
int FlagID = ServerBrowser()->GetDDNetCountryFlag(CountryIndex);
|
|
||||||
|
|
||||||
vec2 Pos = vec2(FlagsRect.x+FlagsRect.w*((i+0.5f)/(float) PerLine), FlagsRect.y);
|
for(int i = 0; i < PerLine && NumTypes > 0; i++, NumTypes--)
|
||||||
|
|
||||||
// correct pos
|
|
||||||
Pos.x -= FlagWidth / 2.0f;
|
|
||||||
Pos.y -= FlagHeight / 2.0f;
|
|
||||||
|
|
||||||
// create button logic
|
|
||||||
CUIRect Rect;
|
|
||||||
|
|
||||||
Rect.x = Pos.x;
|
|
||||||
Rect.y = Pos.y;
|
|
||||||
Rect.w = FlagWidth;
|
|
||||||
Rect.h = FlagHeight;
|
|
||||||
|
|
||||||
if (UI()->DoButtonLogic(&s_aFlagButtons[CountryIndex], "", 0, &Rect))
|
|
||||||
{
|
{
|
||||||
// toggle flag filter
|
int TypeIndex = MaxTypes - NumTypes;
|
||||||
if (Active)
|
const char *pName = ServerBrowser()->GetDDNetType(TypeIndex);
|
||||||
ServerBrowser()->DDNetCountryFilterAdd(pName);
|
bool Active = !ServerBrowser()->DDNetFiltered(g_Config.m_BrFilterExcludeTypes, pName);
|
||||||
else
|
|
||||||
ServerBrowser()->DDNetCountryFilterRem(pName);
|
|
||||||
|
|
||||||
ServerBrowser()->Refresh(IServerBrowser::TYPE_DDNET);
|
vec2 Pos = vec2(TypesRect.x+TypesRect.w*((i+0.5f)/(float) PerLine), TypesRect.y);
|
||||||
|
|
||||||
|
// correct pos
|
||||||
|
Pos.x -= TypesWidth / 2.0f;
|
||||||
|
|
||||||
|
// create button logic
|
||||||
|
CUIRect Rect;
|
||||||
|
|
||||||
|
Rect.x = Pos.x;
|
||||||
|
Rect.y = Pos.y;
|
||||||
|
Rect.w = TypesWidth;
|
||||||
|
Rect.h = TypesHeight;
|
||||||
|
|
||||||
|
if (UI()->DoButtonLogic(&s_aTypeButtons[TypeIndex], "", 0, &Rect))
|
||||||
|
{
|
||||||
|
// toggle flag filter
|
||||||
|
if (Active)
|
||||||
|
ServerBrowser()->DDNetFilterAdd(g_Config.m_BrFilterExcludeTypes, pName);
|
||||||
|
else
|
||||||
|
ServerBrowser()->DDNetFilterRem(g_Config.m_BrFilterExcludeTypes, pName);
|
||||||
|
|
||||||
|
ServerBrowser()->Refresh(IServerBrowser::TYPE_DDNET);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 Color(1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
|
|
||||||
|
if (!Active)
|
||||||
|
Color.a = 0.2f;
|
||||||
|
TextRender()->TextColor(Color.r, Color.g, Color.b, Color.a);
|
||||||
|
UI()->DoLabelScaled(&Rect, pName, FontSize, 0);
|
||||||
|
TextRender()->TextColor(1.0, 1.0, 1.0, 1.0f);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ServerFilter.HSplitTop(17.0f, &ServerFilter, &ServerFilter);
|
||||||
|
|
||||||
vec4 Color(1.0f, 1.0f, 1.0f, 1.0f);
|
vec4 Color(1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
|
|
||||||
if (!Active)
|
const float FlagWidth = 40.0f;
|
||||||
Color.a = 0.2f;
|
const float FlagHeight = 20.0f;
|
||||||
|
|
||||||
m_pClient->m_pCountryFlags->Render(FlagID, &Color, Pos.x, Pos.y, FlagWidth, FlagHeight);
|
int MaxFlags = ServerBrowser()->NumDDNetCountries();
|
||||||
|
int NumFlags = ServerBrowser()->NumDDNetCountries();
|
||||||
|
int PerLine = MaxFlags > 9 ? 4 : 3;
|
||||||
|
|
||||||
NumFlags--;
|
CUIRect FlagsRect;
|
||||||
|
|
||||||
|
static int s_aFlagButtons[64];
|
||||||
|
|
||||||
|
while(NumFlags > 0)
|
||||||
|
{
|
||||||
|
ServerFilter.HSplitTop(30.0f, &FlagsRect, &ServerFilter);
|
||||||
|
|
||||||
|
for(int i = 0; i < PerLine && NumFlags > 0; i++, NumFlags--)
|
||||||
|
{
|
||||||
|
int CountryIndex = MaxFlags - NumFlags;
|
||||||
|
const char *pName = ServerBrowser()->GetDDNetCountryName(CountryIndex);
|
||||||
|
bool Active = !ServerBrowser()->DDNetFiltered(g_Config.m_BrFilterExcludeCountries, pName);
|
||||||
|
int FlagID = ServerBrowser()->GetDDNetCountryFlag(CountryIndex);
|
||||||
|
|
||||||
|
vec2 Pos = vec2(FlagsRect.x+FlagsRect.w*((i+0.5f)/(float) PerLine), FlagsRect.y);
|
||||||
|
|
||||||
|
// correct pos
|
||||||
|
Pos.x -= FlagWidth / 2.0f;
|
||||||
|
Pos.y -= FlagHeight / 2.0f;
|
||||||
|
|
||||||
|
// create button logic
|
||||||
|
CUIRect Rect;
|
||||||
|
|
||||||
|
Rect.x = Pos.x;
|
||||||
|
Rect.y = Pos.y;
|
||||||
|
Rect.w = FlagWidth;
|
||||||
|
Rect.h = FlagHeight;
|
||||||
|
|
||||||
|
if (UI()->DoButtonLogic(&s_aFlagButtons[CountryIndex], "", 0, &Rect))
|
||||||
|
{
|
||||||
|
// toggle flag filter
|
||||||
|
if (Active)
|
||||||
|
ServerBrowser()->DDNetFilterAdd(g_Config.m_BrFilterExcludeCountries, pName);
|
||||||
|
else
|
||||||
|
ServerBrowser()->DDNetFilterRem(g_Config.m_BrFilterExcludeCountries, pName);
|
||||||
|
|
||||||
|
ServerBrowser()->Refresh(IServerBrowser::TYPE_DDNET);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 Color(1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
|
|
||||||
|
if (!Active)
|
||||||
|
Color.a = 0.2f;
|
||||||
|
|
||||||
|
m_pClient->m_pCountryFlags->Render(FlagID, &Color, Pos.x, Pos.y, FlagWidth, FlagHeight);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerFilter.HSplitBottom(5.0f, &ServerFilter, 0);
|
|
||||||
ServerFilter.HSplitBottom(ms_ButtonHeight-2.0f, &ServerFilter, &Button);
|
|
||||||
static int s_ClearButton = 0;
|
static int s_ClearButton = 0;
|
||||||
if(DoButton_Menu(&s_ClearButton, Localize("Reset filter"), 0, &Button))
|
if(DoButton_Menu(&s_ClearButton, Localize("Reset filter"), 0, &ResetButton))
|
||||||
{
|
{
|
||||||
g_Config.m_BrFilterString[0] = 0;
|
g_Config.m_BrFilterString[0] = 0;
|
||||||
g_Config.m_BrExcludeString[0] = 0;
|
g_Config.m_BrExcludeString[0] = 0;
|
||||||
|
|
Loading…
Reference in a new issue