fixed scrollbar and prevent key-navigation when all filters are closed, selecting a server entry on filter close and still show the filter add feature in case all filters are closed

This commit is contained in:
oy 2018-11-16 18:06:28 +01:00
parent 4af6b33058
commit 35f7b6a8b9
2 changed files with 34 additions and 35 deletions

View file

@ -647,14 +647,14 @@ bool CMenus::RenderFilterHeader(CUIRect View, int FilterIndex)
RenderTools()->DrawUIRect(&View, vec4(0.0f, 0.0f, 0.0f, 0.25f), CUI::CORNER_ALL, 5.0f); RenderTools()->DrawUIRect(&View, vec4(0.0f, 0.0f, 0.0f, 0.25f), CUI::CORNER_ALL, 5.0f);
CUIRect Button, EditButtons; CUIRect Button, EditButtons;
View.VSplitLeft(20.0f, &Button, &View); if(UI()->DoButtonLogic(&m_lFilters[FilterIndex], "", 0, &View))
Button.Margin(2.0f, &Button);
if(DoButton_SpriteClean(IMAGE_MENUICONS, pFilter->Extended() ? SPRITE_MENU_EXPANDED : SPRITE_MENU_COLLAPSED, &Button)
|| (UI()->MouseInside(&View) && Input()->KeyPress(KEY_MOUSE_1)))
{ {
Switch = true; // switch later, to make sure we haven't clicked one of the filter buttons (edit...) Switch = true; // switch later, to make sure we haven't clicked one of the filter buttons (edit...)
} }
Button.Margin(2.0f, &Button);
View.VSplitLeft(20.0f, &Button, &View);
DoIcon(IMAGE_MENUICONS, pFilter->Extended() ? SPRITE_MENU_EXPANDED : SPRITE_MENU_COLLAPSED, &Button);
// split buttons from label // split buttons from label
View.VSplitLeft(Spacing, 0, &View); View.VSplitLeft(Spacing, 0, &View);
View.VSplitRight((ButtonHeight+Spacing)*4.0f, &View, &EditButtons); View.VSplitRight((ButtonHeight+Spacing)*4.0f, &View, &EditButtons);
@ -1088,11 +1088,19 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)
if(m_lFilters[i].Extended()) if(m_lFilters[i].Extended())
NumServers += m_lFilters[i].NumSortedServers(); NumServers += m_lFilters[i].NumSortedServers();
int SelectedIndex = m_SelectedServer.m_Index;
int SelectedFilter;
for(SelectedFilter = 0; SelectedFilter < m_lFilters.size(); SelectedFilter++)
if(m_lFilters[SelectedFilter].Extended())
break;
if(SelectedFilter == m_lFilters.size()) // no selected filter found
SelectedFilter = -1;
int NumFilters = m_lFilters.size(); int NumFilters = m_lFilters.size();
float ListHeight = NumServers * ms_ListheaderHeight; // add server list height float ListHeight = NumServers * ms_ListheaderHeight; // add server list height
ListHeight += NumFilters * SpacingH; // add filters ListHeight += NumFilters * SpacingH; // add filters
ListHeight += (NumFilters) * ButtonHeight;// add filters spacing ListHeight += (NumFilters) * ButtonHeight;// add filters spacing
if(!m_SidebarActive && m_SelectedServer.m_Index != -1) if(!m_SidebarActive && m_SelectedServer.m_Index != -1 && SelectedFilter != -1)
ListHeight += ms_ListheaderHeight*5; ListHeight += ms_ListheaderHeight*5;
// float LineH = ms_aBrowserCols[0].m_Rect.h; // float LineH = ms_aBrowserCols[0].m_Rect.h;
@ -1116,14 +1124,6 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)
else else
ScrollNum = 0; ScrollNum = 0;
int SelectedIndex = m_SelectedServer.m_Index;
int SelectedFilter;
for(SelectedFilter = 0; SelectedFilter < m_lFilters.size(); SelectedFilter++)
if(m_lFilters[SelectedFilter].Extended())
break;
if(SelectedFilter == m_lFilters.size()) // no selected filter found
SelectedFilter = 0;
if(SelectedFilter > -1) if(SelectedFilter > -1)
{ {
int NewIndex = -1; int NewIndex = -1;

View file

@ -91,10 +91,29 @@ void CMenus::DoPopupMenu()
int CMenus::PopupFilter(CMenus *pMenus, CUIRect View) int CMenus::PopupFilter(CMenus *pMenus, CUIRect View)
{ {
CUIRect ServerFilter = View, FilterHeader; CUIRect ServerFilter = View, FilterHeader, Button, Icon;;
const float FontSize = 10.0f; const float FontSize = 10.0f;
const float LineSize = 16.0f; const float LineSize = 16.0f;
// new filter
ServerFilter.HSplitBottom(LineSize, &ServerFilter, &Button);
Button.VSplitLeft(60.0f, &Button, &Icon);
static char s_aFilterName[32] = { 0 };
static float s_FilterOffset = 0.0f;
static int s_EditFilter = 0;
pMenus->DoEditBox(&s_EditFilter, &Button, s_aFilterName, sizeof(s_aFilterName), FontSize, &s_FilterOffset);
pMenus->RenderTools()->DrawUIRect(&Icon, vec4(1, 1, 1, 0.25f), CUI::CORNER_ALL, 5.0f);
Icon.VSplitLeft(20.0f, &Button, &Icon);
Icon.HMargin(2.0f, &Icon);
pMenus->UI()->DoLabelScaled(&Icon, Localize("New filter"), FontSize, CUI::ALIGN_LEFT);
static CButtonContainer s_AddFilter;
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()));
s_aFilterName[0] = 0;
}
// slected filter // slected filter
CBrowserFilter *pFilter = 0; CBrowserFilter *pFilter = 0;
for(int i = 0; i < pMenus->m_lFilters.size(); ++i) for(int i = 0; i < pMenus->m_lFilters.size(); ++i)
@ -118,7 +137,6 @@ int CMenus::PopupFilter(CMenus *pMenus, CUIRect View)
pMenus->RenderTools()->DrawUIRect(&ServerFilter, vec4(0,0,0,0.15f), CUI::CORNER_B, 4.0f); pMenus->RenderTools()->DrawUIRect(&ServerFilter, vec4(0,0,0,0.15f), CUI::CORNER_B, 4.0f);
FilterHeader.HMargin(2.0f, &FilterHeader); FilterHeader.HMargin(2.0f, &FilterHeader);
pMenus->UI()->DoLabel(&FilterHeader, Localize("Server filter"), FontSize+2.0f, CUI::ALIGN_CENTER); pMenus->UI()->DoLabel(&FilterHeader, Localize("Server filter"), FontSize+2.0f, CUI::ALIGN_CENTER);
CUIRect Button, Icon;
//ServerFilter.VSplitLeft(5.0f, 0, &ServerFilter); //ServerFilter.VSplitLeft(5.0f, 0, &ServerFilter);
//ServerFilter.Margin(3.0f, &ServerFilter); //ServerFilter.Margin(3.0f, &ServerFilter);
@ -348,25 +366,6 @@ int CMenus::PopupFilter(CMenus *pMenus, CUIRect View)
pFilter->SetFilter(&FilterInfo); pFilter->SetFilter(&FilterInfo);
} }
// new filter
ServerFilter.HSplitBottom(LineSize, &ServerFilter, &Button);
Button.VSplitLeft(60.0f, &Button, &Icon);
static char s_aFilterName[32] = {0};
static float s_FilterOffset = 0.0f;
static int s_EditFilter = 0;
pMenus->DoEditBox(&s_EditFilter, &Button, s_aFilterName, sizeof(s_aFilterName), FontSize, &s_FilterOffset);
pMenus->RenderTools()->DrawUIRect(&Icon, vec4(1, 1, 1, 0.25f), CUI::CORNER_ALL, 5.0f);
Icon.VSplitLeft(20.0f, &Button, &Icon);
Icon.HMargin(2.0f, &Icon);
pMenus->UI()->DoLabelScaled(&Icon, Localize("New filter"), FontSize, CUI::ALIGN_LEFT);
static CButtonContainer s_AddFilter;
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()));
s_aFilterName[0] = 0;
}
// reset filter // reset filter
ServerFilter.HSplitBottom(LineSize, &ServerFilter, 0); ServerFilter.HSplitBottom(LineSize, &ServerFilter, 0);
ServerFilter.HSplitBottom(LineSize, &ServerFilter, &Button); ServerFilter.HSplitBottom(LineSize, &ServerFilter, &Button);