From 23d8acd96c47dbe61ee45468cbce1c8d14740793 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sun, 21 May 2023 21:17:08 +0200 Subject: [PATCH] Replace country server filter fullscreen popup with smaller popup Replace the large hard-coded popup to select the country for the server filter with a small overlay popup for better usability. --- src/game/client/components/menus.cpp | 65 -------------------- src/game/client/components/menus.h | 8 ++- src/game/client/components/menus_browser.cpp | 62 ++++++++++++++++++- 3 files changed, 68 insertions(+), 67 deletions(-) diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 8ee92ce38..fa79962fa 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -1801,71 +1801,6 @@ int CMenus::Render() if(DoButton_Menu(&s_Button, Localize("Ok"), 0, &Button) || UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE) || UI()->ConsumeHotkey(CUI::HOTKEY_ENTER) || Activated) m_Popup = POPUP_FIRST_LAUNCH; } - else if(m_Popup == POPUP_COUNTRY) - { - CUIRect ButtonBar; - Screen.Margin(150.0f, &Box); - Box.HSplitTop(20.0f, nullptr, &Box); - Box.HSplitBottom(20.0f, &Box, nullptr); - Box.HSplitBottom(24.0f, &Box, &ButtonBar); - Box.HSplitBottom(20.0f, &Box, nullptr); - Box.VMargin(20.0f, &Box); - ButtonBar.VMargin(100.0f, &ButtonBar); - - static int s_CurSelection = -2; - if(s_CurSelection == -2) - s_CurSelection = g_Config.m_BrFilterCountryIndex; - - static CListBox s_ListBox; - int OldSelected = -1; - s_ListBox.DoStart(50.0f, m_pClient->m_CountryFlags.Num(), 10, 1, OldSelected, &Box); - - for(size_t i = 0; i < m_pClient->m_CountryFlags.Num(); ++i) - { - const CCountryFlags::CCountryFlag *pEntry = m_pClient->m_CountryFlags.GetByIndex(i); - if(pEntry->m_CountryCode == s_CurSelection) - OldSelected = i; - - const CListboxItem Item = s_ListBox.DoNextItem(pEntry, OldSelected >= 0 && (size_t)OldSelected == i); - if(!Item.m_Visible) - continue; - - CUIRect FlagRect, Label; - Item.m_Rect.Margin(5.0f, &FlagRect); - FlagRect.HSplitBottom(12.0f, &FlagRect, &Label); - Label.HSplitTop(2.0f, nullptr, &Label); - const float OldWidth = FlagRect.w; - FlagRect.w = FlagRect.h * 2.0f; - FlagRect.x += (OldWidth - FlagRect.w) / 2.0f; - ColorRGBA Color(1.0f, 1.0f, 1.0f, 1.0f); - m_pClient->m_CountryFlags.Render(pEntry->m_CountryCode, &Color, FlagRect.x, FlagRect.y, FlagRect.w, FlagRect.h); - - UI()->DoLabel(&Label, pEntry->m_aCountryCodeString, 10.0f, TEXTALIGN_ML); - } - - const int NewSelected = s_ListBox.DoEnd(); - if(OldSelected != NewSelected) - s_CurSelection = m_pClient->m_CountryFlags.GetByIndex(NewSelected)->m_CountryCode; - - CUIRect CancelButton, OkButton; - ButtonBar.VSplitMid(&CancelButton, &OkButton, 40.0f); - - static CButtonContainer s_CancelButton; - if(DoButton_Menu(&s_CancelButton, Localize("Cancel"), 0, &CancelButton) || UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE)) - { - s_CurSelection = g_Config.m_BrFilterCountryIndex; - m_Popup = POPUP_NONE; - } - - static CButtonContainer s_OkButton; - if(DoButton_Menu(&s_OkButton, Localize("Ok"), 0, &OkButton) || UI()->ConsumeHotkey(CUI::HOTKEY_ENTER) || s_ListBox.WasItemActivated()) - { - g_Config.m_BrFilterCountry = 1; - g_Config.m_BrFilterCountryIndex = s_CurSelection; - Client()->ServerBrowserUpdate(); - m_Popup = POPUP_NONE; - } - } else if(m_Popup == POPUP_RENAME_DEMO) { CUIRect Label, TextBox, Ok, Abort; diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index fca954d3e..01f28cb05 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -557,6 +557,13 @@ protected: void PopupConfirmSwitchServer(); void RenderServerbrowserServerDetail(CUIRect View); void RenderServerbrowserFilters(CUIRect View); + struct SPopupCountrySelectionContext + { + CMenus *m_pMenus; + int m_Selection; + bool m_New; + }; + static CUI::EPopupMenuFunctionResult PopupCountrySelection(void *pContext, CUIRect View, bool Active); void RenderServerbrowserFriends(CUIRect View); void PopupConfirmRemoveFriend(); void RenderServerbrowser(CUIRect MainView); @@ -739,7 +746,6 @@ public: POPUP_CONNECTING, POPUP_DISCONNECTED, POPUP_LANGUAGE, - POPUP_COUNTRY, POPUP_RENAME_DEMO, POPUP_RENDER_DEMO, POPUP_PASSWORD, diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index 1036d9562..345462727 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -679,7 +679,14 @@ void CMenus::RenderServerbrowserFilters(CUIRect View) m_pClient->m_CountryFlags.Render(g_Config.m_BrFilterCountryIndex, &Color, Rect.x, Rect.y, Rect.w, Rect.h); if(UI()->DoButtonLogic(&g_Config.m_BrFilterCountryIndex, 0, &Rect)) - m_Popup = POPUP_COUNTRY; + { + static SPopupMenuId s_PopupCountryId; + static SPopupCountrySelectionContext s_PopupCountryContext; + s_PopupCountryContext.m_pMenus = this; + s_PopupCountryContext.m_Selection = g_Config.m_BrFilterCountryIndex; + s_PopupCountryContext.m_New = true; + UI()->DoPopupMenu(&s_PopupCountryId, Rect.x, Rect.y + Rect.h, 490, 210, &s_PopupCountryContext, PopupCountrySelection); + } } ServerFilter.HSplitTop(20.0f, &Button, &ServerFilter); @@ -960,6 +967,59 @@ void CMenus::RenderServerbrowserFilters(CUIRect View) } } +CUI::EPopupMenuFunctionResult CMenus::PopupCountrySelection(void *pContext, CUIRect View, bool Active) +{ + SPopupCountrySelectionContext *pPopupContext = static_cast(pContext); + CMenus *pMenus = pPopupContext->m_pMenus; + + bool ListBoxUsed = Active; + + static CListBox s_ListBox; + int OldSelected = -1; + s_ListBox.DoStart(50.0f, pMenus->m_pClient->m_CountryFlags.Num(), 8, 1, OldSelected, &View, false, &ListBoxUsed); + + if(pPopupContext->m_New) + { + pPopupContext->m_New = false; + s_ListBox.ScrollToSelected(); + } + + for(size_t i = 0; i < pMenus->m_pClient->m_CountryFlags.Num(); ++i) + { + const CCountryFlags::CCountryFlag *pEntry = pMenus->m_pClient->m_CountryFlags.GetByIndex(i); + if(pEntry->m_CountryCode == pPopupContext->m_Selection) + OldSelected = i; + + const CListboxItem Item = s_ListBox.DoNextItem(pEntry, OldSelected >= 0 && (size_t)OldSelected == i, &ListBoxUsed); + if(!Item.m_Visible) + continue; + + CUIRect FlagRect, Label; + Item.m_Rect.Margin(5.0f, &FlagRect); + FlagRect.HSplitBottom(12.0f, &FlagRect, &Label); + Label.HSplitTop(2.0f, nullptr, &Label); + const float OldWidth = FlagRect.w; + FlagRect.w = FlagRect.h * 2.0f; + FlagRect.x += (OldWidth - FlagRect.w) / 2.0f; + ColorRGBA Color(1.0f, 1.0f, 1.0f, 1.0f); + pMenus->m_pClient->m_CountryFlags.Render(pEntry->m_CountryCode, &Color, FlagRect.x, FlagRect.y, FlagRect.w, FlagRect.h); + + pMenus->UI()->DoLabel(&Label, pEntry->m_aCountryCodeString, 10.0f, TEXTALIGN_MC); + } + + const int NewSelected = s_ListBox.DoEnd(); + pPopupContext->m_Selection = pMenus->m_pClient->m_CountryFlags.GetByIndex(NewSelected)->m_CountryCode; + if(s_ListBox.WasItemSelected() || s_ListBox.WasItemActivated()) + { + g_Config.m_BrFilterCountry = 1; + g_Config.m_BrFilterCountryIndex = pPopupContext->m_Selection; + pMenus->Client()->ServerBrowserUpdate(); + return CUI::POPUP_CLOSE_CURRENT; + } + + return CUI::POPUP_KEEP_OPEN; +} + void CMenus::RenderServerbrowserServerDetail(CUIRect View) { CUIRect ServerDetails = View;