mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 22:48:18 +00:00
added reset filter feature
This commit is contained in:
parent
a063f8d428
commit
ffba1d05c2
|
@ -2336,14 +2336,14 @@ void CMenus::OnConsoleInit()
|
|||
{
|
||||
// put it on top
|
||||
int Pos = m_lFilters.size();
|
||||
m_lFilters.add(CBrowserFilter(CBrowserFilter::FILTER_STANDARD, "Teeworlds", ServerBrowser(), IServerBrowser::FILTER_COMPAT_VERSION | IServerBrowser::FILTER_PURE | IServerBrowser::FILTER_PURE_MAP | IServerBrowser::FILTER_PING, 999, -1, "", ""));
|
||||
m_lFilters.add(CBrowserFilter(CBrowserFilter::FILTER_STANDARD, "Teeworlds", ServerBrowser()));
|
||||
for(; Pos > 0; --Pos)
|
||||
Move(true, Pos);
|
||||
}
|
||||
if(!FilterFav)
|
||||
m_lFilters.add(CBrowserFilter(CBrowserFilter::FILTER_FAVORITES, Localize("Favorites"), ServerBrowser(), IServerBrowser::FILTER_FAVORITE | IServerBrowser::FILTER_PING, 999, -1, "", ""));
|
||||
m_lFilters.add(CBrowserFilter(CBrowserFilter::FILTER_FAVORITES, Localize("Favorites"), ServerBrowser()));
|
||||
if(!FilterAll)
|
||||
m_lFilters.add(CBrowserFilter(CBrowserFilter::FILTER_ALL, Localize("All"), ServerBrowser(), IServerBrowser::FILTER_PING, 999, -1, "", ""));
|
||||
m_lFilters.add(CBrowserFilter(CBrowserFilter::FILTER_ALL, Localize("All"), ServerBrowser()));
|
||||
}
|
||||
|
||||
void CMenus::OnShutdown()
|
||||
|
|
|
@ -370,6 +370,10 @@ private:
|
|||
int m_Filter;
|
||||
class IServerBrowser *m_pServerBrowser;
|
||||
|
||||
static class CServerFilterInfo ms_FilterStandard;
|
||||
static class CServerFilterInfo ms_FilterFavorites;
|
||||
static class CServerFilterInfo ms_FilterAll;
|
||||
|
||||
public:
|
||||
|
||||
enum
|
||||
|
@ -383,7 +387,7 @@ private:
|
|||
int m_SwitchButton;
|
||||
|
||||
CBrowserFilter() {}
|
||||
CBrowserFilter(int Custom, const char* pName, IServerBrowser *pServerBrowser, int Filter, int Ping, int Country, const char* pGametype, const char* pServerAddress);
|
||||
CBrowserFilter(int Custom, const char* pName, IServerBrowser *pServerBrowser);
|
||||
void Switch();
|
||||
bool Extended() const;
|
||||
int Custom() const;
|
||||
|
@ -397,6 +401,7 @@ private:
|
|||
const CServerInfo *SortedGet(int Index) const;
|
||||
const void *ID(int Index) const;
|
||||
|
||||
void Reset();
|
||||
void GetFilter(class CServerFilterInfo *pFilterInfo) const;
|
||||
void SetFilter(const class CServerFilterInfo *pFilterInfo);
|
||||
};
|
||||
|
|
|
@ -40,6 +40,10 @@ CMenus::CColumn CMenus::ms_aFriendCols[] = {
|
|||
{COL_FRIEND_DELETE, -1, "", 1, 20.0f, 0, {0}, {0}},
|
||||
};
|
||||
|
||||
CServerFilterInfo CMenus::CBrowserFilter::ms_FilterStandard = {IServerBrowser::FILTER_COMPAT_VERSION|IServerBrowser::FILTER_PURE|IServerBrowser::FILTER_PURE_MAP, 999, -1, 0, {0}, 0};
|
||||
CServerFilterInfo CMenus::CBrowserFilter::ms_FilterFavorites = {IServerBrowser::FILTER_COMPAT_VERSION|IServerBrowser::FILTER_FAVORITE, 999, -1, 0, {0}, 0};
|
||||
CServerFilterInfo CMenus::CBrowserFilter::ms_FilterAll = {IServerBrowser::FILTER_COMPAT_VERSION, 999, -1, 0, {0}, 0};
|
||||
|
||||
class SortWrap
|
||||
{
|
||||
typedef bool (CMenus::*SortFunc)(int, int) const;
|
||||
|
@ -51,27 +55,43 @@ public:
|
|||
};
|
||||
|
||||
// filters
|
||||
CMenus::CBrowserFilter::CBrowserFilter(int Custom, const char* pName, IServerBrowser *pServerBrowser, int Filter, int Ping, int Country, const char* pGametype, const char* pServerAddress)
|
||||
: m_pServerBrowser(pServerBrowser)
|
||||
CMenus::CBrowserFilter::CBrowserFilter(int Custom, const char* pName, IServerBrowser *pServerBrowser)
|
||||
{
|
||||
m_Extended = false;
|
||||
m_Custom = Custom;
|
||||
str_copy(m_aName, pName, sizeof(m_aName));
|
||||
//Todo: fix Filter
|
||||
CServerFilterInfo FilterInfo;
|
||||
FilterInfo.m_SortHash = Filter;
|
||||
FilterInfo.m_Ping = Ping;
|
||||
FilterInfo.m_Country = Country;
|
||||
for(int i = 1; i < CServerFilterInfo::MAX_GAMETYPES; ++i)
|
||||
FilterInfo.m_aGametype[i][0] = 0;
|
||||
str_copy(FilterInfo.m_aGametype[0], pGametype, sizeof(FilterInfo.m_aGametype[0]));
|
||||
str_copy(FilterInfo.m_aAddress, pServerAddress, sizeof(FilterInfo.m_aAddress));
|
||||
m_Filter = pServerBrowser->AddFilter(&FilterInfo);
|
||||
m_pServerBrowser = pServerBrowser;
|
||||
switch(m_Custom)
|
||||
{
|
||||
case CBrowserFilter::FILTER_STANDARD:
|
||||
m_Filter = m_pServerBrowser->AddFilter(&ms_FilterStandard);
|
||||
break;
|
||||
case CBrowserFilter::FILTER_FAVORITES:
|
||||
m_Filter = m_pServerBrowser->AddFilter(&ms_FilterFavorites);
|
||||
break;
|
||||
default:
|
||||
m_Filter = m_pServerBrowser->AddFilter(&ms_FilterAll);
|
||||
}
|
||||
|
||||
// init buttons
|
||||
m_SwitchButton = 0;
|
||||
}
|
||||
|
||||
void CMenus::CBrowserFilter::Reset()
|
||||
{
|
||||
switch(m_Custom)
|
||||
{
|
||||
case CBrowserFilter::FILTER_STANDARD:
|
||||
m_pServerBrowser->SetFilter(m_Filter, &ms_FilterStandard);
|
||||
break;
|
||||
case CBrowserFilter::FILTER_FAVORITES:
|
||||
m_pServerBrowser->SetFilter(m_Filter, &ms_FilterFavorites);
|
||||
break;
|
||||
default:
|
||||
m_pServerBrowser->SetFilter(m_Filter, &ms_FilterAll);
|
||||
}
|
||||
}
|
||||
|
||||
void CMenus::CBrowserFilter::Switch()
|
||||
{
|
||||
m_Extended ^= 1;
|
||||
|
@ -211,7 +231,7 @@ void CMenus::LoadFilters()
|
|||
}
|
||||
|
||||
// add filter
|
||||
m_lFilters.add(CBrowserFilter(Type, pName, ServerBrowser(), 0, 999, -1, "", ""));
|
||||
m_lFilters.add(CBrowserFilter(Type, pName, ServerBrowser()));
|
||||
if(Type == CBrowserFilter::FILTER_STANDARD) // make sure the pure filter is enabled in the Teeworlds-filter
|
||||
FilterInfo.m_SortHash |= IServerBrowser::FILTER_PURE;
|
||||
m_lFilters[i].SetFilter(&FilterInfo);
|
||||
|
|
|
@ -337,6 +337,7 @@ int CMenus::PopupFilter(CMenus *pMenus, CUIRect View)
|
|||
pFilter->SetFilter(&FilterInfo);
|
||||
}
|
||||
|
||||
// new filter
|
||||
ServerFilter.HSplitBottom(LineSize, &ServerFilter, &Button);
|
||||
Button.VSplitLeft(60.0f, &Button, &Icon);
|
||||
static char s_aFilterName[32] = {0};
|
||||
|
@ -351,9 +352,19 @@ int CMenus::PopupFilter(CMenus *pMenus, CUIRect View)
|
|||
if(s_aFilterName[0] && pMenus->DoButton_SpriteCleanID(&s_AddFilter, IMAGE_FRIENDICONS, SPRITE_FRIEND_PLUS_A, &Button, true))
|
||||
{
|
||||
CServerFilterInfo NewFilterInfo;
|
||||
pMenus->m_lFilters.add(CBrowserFilter(CBrowserFilter::FILTER_CUSTOM, s_aFilterName, pMenus->ServerBrowser(), 0, 999, -1, "", ""));
|
||||
pMenus->m_lFilters.add(CBrowserFilter(CBrowserFilter::FILTER_CUSTOM, s_aFilterName, pMenus->ServerBrowser()));
|
||||
s_aFilterName[0] = 0;
|
||||
}
|
||||
|
||||
// reset filter
|
||||
ServerFilter.HSplitBottom(LineSize, &ServerFilter, 0);
|
||||
ServerFilter.HSplitBottom(LineSize, &ServerFilter, &Button);
|
||||
Button.VMargin((Button.w-80.0f)/2, &Button);
|
||||
static CButtonContainer s_ResetButton;
|
||||
if(pMenus->DoButton_Menu(&s_ResetButton, Localize("Reset filter"), 0, &Button))
|
||||
{
|
||||
pFilter->Reset();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue