Add cancel button to country popup, confirm with list item activation

Add "Cancel" button to country/region picker popup. It's already possible to cancel with the Escape key, so there should also be a button, which keeps the current selection.

Delegate the listbox activation (enter / double click on item) to the popup to confirm it. Enter was previously working but then broken by the logic that ensures that every hotkey is only consumed once. Now both enter and double click confirm the popup.

From teeworlds/teeworlds#2961.
This commit is contained in:
Robert Müller 2022-12-03 13:21:41 +01:00
parent 5994812a1c
commit 5903c25799

View file

@ -1885,23 +1885,27 @@ int CMenus::Render()
}
}
const int NewSelected = UiDoListboxEnd(&s_ScrollValue, 0);
bool Activated = false;
const int NewSelected = UiDoListboxEnd(&s_ScrollValue, &Activated);
if(OldSelected != NewSelected)
s_CurSelection = m_pClient->m_CountryFlags.GetByIndex(NewSelected)->m_CountryCode;
Part.VMargin(120.0f, &Part);
CUIRect CancelButton, OkButton;
Part.VMargin(100.0f, &Part);
Part.VSplitMid(&CancelButton, &OkButton, 40.0f);
static CButtonContainer s_Button;
if(DoButton_Menu(&s_Button, Localize("Ok"), 0, &Part) || UI()->ConsumeHotkey(CUI::HOTKEY_ENTER))
static CButtonContainer s_CancelButton;
if(DoButton_Menu(&s_CancelButton, Localize("Cancel"), 0, &CancelButton) || UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE))
{
g_Config.m_BrFilterCountryIndex = s_CurSelection;
Client()->ServerBrowserUpdate();
s_CurSelection = g_Config.m_BrFilterCountryIndex;
m_Popup = POPUP_NONE;
}
if(UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE))
static CButtonContainer s_OkButton;
if(DoButton_Menu(&s_OkButton, Localize("Ok"), 0, &OkButton) || UI()->ConsumeHotkey(CUI::HOTKEY_ENTER) || Activated)
{
s_CurSelection = g_Config.m_BrFilterCountryIndex;
g_Config.m_BrFilterCountryIndex = s_CurSelection;
Client()->ServerBrowserUpdate();
m_Popup = POPUP_NONE;
}
}