From 288236891d0bc55559f74d72ebf8c6c5fddac008 Mon Sep 17 00:00:00 2001 From: Jordy Ruiz Date: Mon, 10 Dec 2018 17:23:53 +0100 Subject: [PATCH 1/3] Language/Theme listboxes now always render selection, despite not always accepting inputs --- src/game/client/components/menus.cpp | 4 +-- src/game/client/components/menus.h | 2 +- src/game/client/components/menus_settings.cpp | 26 +++---------------- 3 files changed, 7 insertions(+), 25 deletions(-) diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index e01278da5..de4f9bf1a 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -944,7 +944,7 @@ CMenus::CListboxItem CMenus::UiDoListboxNextRow(CListBoxState* pState) return Item; } -CMenus::CListboxItem CMenus::UiDoListboxNextItem(CListBoxState* pState, const void *pId, bool Selected) +CMenus::CListboxItem CMenus::UiDoListboxNextItem(CListBoxState* pState, const void *pId, bool Selected, bool ProcessInput) { int ThisItemIndex = pState->m_ListBoxItemIndex; if(Selected) @@ -962,7 +962,7 @@ CMenus::CListboxItem CMenus::UiDoListboxNextItem(CListBoxState* pState, const vo // process input, regard selected index if(pState->m_ListBoxSelectedIndex == ThisItemIndex) { - if(!pState->m_ListBoxDoneEvents) + if(ProcessInput && !pState->m_ListBoxDoneEvents) { pState->m_ListBoxDoneEvents = 1; diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index 5e66386a2..22740313f 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -128,7 +128,7 @@ private: void UiDoListboxHeader(CListBoxState* pState, const CUIRect *pRect, const char *pTitle, float HeaderHeight, float Spacing); void UiDoListboxStart(CListBoxState* pState, const void *pID, float RowHeight, const char *pBottomText, int NumItems, int ItemsPerRow, int SelectedIndex, const CUIRect *pRect=0, bool Background=true); - CListboxItem UiDoListboxNextItem(CListBoxState* pState, const void *pID, bool Selected = false); + CListboxItem UiDoListboxNextItem(CListBoxState* pState, const void *pID, bool Selected = false, bool ProcessInput = true); CListboxItem UiDoListboxNextRow(CListBoxState* pState); int UiDoListboxEnd(CListBoxState* pState, bool *pItemActivated); diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index b8f3294ae..147187008 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -713,7 +713,6 @@ void CMenus::RenderLanguageSelection(CUIRect MainView, bool Header) { static int s_LanguageList = 0; static int s_SelectedLanguage = -1; - static int s_OldSelected = -1; static sorted_array s_Languages; static CListBoxState s_ListBoxState; @@ -729,16 +728,8 @@ void CMenus::RenderLanguageSelection(CUIRect MainView, bool Header) } } - if(s_SelectedLanguage != -1 && m_ActiveListBox != ACTLB_LANG) - { - s_OldSelected = s_SelectedLanguage; - s_SelectedLanguage = -1; - } - if(s_SelectedLanguage == -1 && UI()->MouseInside(&MainView)) - { - s_SelectedLanguage = s_OldSelected; + if(m_ActiveListBox != ACTLB_LANG && UI()->MouseInside(&MainView)) m_ActiveListBox = ACTLB_LANG; - } int OldSelected = s_SelectedLanguage; if(Header) @@ -747,7 +738,7 @@ void CMenus::RenderLanguageSelection(CUIRect MainView, bool Header) for(sorted_array::range r = s_Languages.all(); !r.empty(); r.pop_front()) { - CListboxItem Item = UiDoListboxNextItem(&s_ListBoxState, &r.front()); + CListboxItem Item = UiDoListboxNextItem(&s_ListBoxState, &r.front(), false, m_ActiveListBox == ACTLB_LANG); if(Item.m_Visible) { @@ -785,7 +776,6 @@ void CMenus::RenderThemeSelection(CUIRect MainView, bool Header) { static int s_ThemeList = 0; static int s_SelectedTheme = -1; - static int s_OldSelected = -1; static CListBoxState s_ListBoxState_Theme; if(m_lThemes.size() == 0) // not loaded yet @@ -801,16 +791,8 @@ void CMenus::RenderThemeSelection(CUIRect MainView, bool Header) } } - if(s_SelectedTheme != -1 && m_ActiveListBox != ACTLB_THEME) - { - s_OldSelected = s_SelectedTheme; - s_SelectedTheme = -1; - } - if(s_SelectedTheme == -1 && UI()->MouseInside(&MainView)) - { - s_SelectedTheme = s_OldSelected; + if(m_ActiveListBox != ACTLB_THEME && UI()->MouseInside(&MainView)) m_ActiveListBox = ACTLB_THEME; - } int OldSelected = s_SelectedTheme; if(Header) @@ -819,7 +801,7 @@ void CMenus::RenderThemeSelection(CUIRect MainView, bool Header) for(sorted_array::range r = m_lThemes.all(); !r.empty(); r.pop_front()) { - CListboxItem Item = UiDoListboxNextItem(&s_ListBoxState_Theme, &r.front()); + CListboxItem Item = UiDoListboxNextItem(&s_ListBoxState_Theme, &r.front(), false, m_ActiveListBox == ACTLB_THEME); if(Item.m_Visible) { From d8392baa40a2971f1310e48031c74bcb24a50ca7 Mon Sep 17 00:00:00 2001 From: Jordy Ruiz Date: Mon, 10 Dec 2018 17:50:37 +0100 Subject: [PATCH 2/3] Default general settings listboxes to none selected --- src/game/client/components/menus.cpp | 2 +- src/game/client/components/menus.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index de4f9bf1a..fd47bb297 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -80,7 +80,7 @@ CMenus::CMenus() m_SelectedServer.m_Filter = -1; m_SelectedServer.m_Index = -1; - m_ActiveListBox = ACTLB_THEME; + m_ActiveListBox = ACTLB_NONE; } float CMenus::ButtonFade(CButtonContainer *pBC, float Seconds, int Checked) diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index 22740313f..5f256823c 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -176,7 +176,8 @@ private: SETTINGS_GRAPHICS, SETTINGS_SOUND, - ACTLB_LANG=0, + ACTLB_NONE=0, + ACTLB_LANG, ACTLB_THEME, }; From 6139aaf42b8b458609d78f9032f1ebca1b8270f7 Mon Sep 17 00:00:00 2001 From: Jordy Ruiz Date: Tue, 11 Dec 2018 12:10:30 +0100 Subject: [PATCH 3/3] General settings listboxes now only process inputs after being clicked on --- src/game/client/components/menus.cpp | 9 +++++++-- src/game/client/components/menus.h | 2 +- src/game/client/components/menus_settings.cpp | 14 ++++++++------ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index fd47bb297..a8a160dd5 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -944,7 +944,7 @@ CMenus::CListboxItem CMenus::UiDoListboxNextRow(CListBoxState* pState) return Item; } -CMenus::CListboxItem CMenus::UiDoListboxNextItem(CListBoxState* pState, const void *pId, bool Selected, bool ProcessInput) +CMenus::CListboxItem CMenus::UiDoListboxNextItem(CListBoxState* pState, const void *pId, bool Selected, bool* pActive) { int ThisItemIndex = pState->m_ListBoxItemIndex; if(Selected) @@ -957,7 +957,12 @@ CMenus::CListboxItem CMenus::UiDoListboxNextItem(CListBoxState* pState, const vo CListboxItem Item = UiDoListboxNextRow(pState); if(Item.m_Visible && UI()->DoButtonLogic(pId, "", pState->m_ListBoxSelectedIndex == pState->m_ListBoxItemIndex, &Item.m_HitRect)) + { pState->m_ListBoxNewSelected = ThisItemIndex; + if(pActive) + *pActive = true; + } + const bool ProcessInput = !pActive || *pActive; // process input, regard selected index if(pState->m_ListBoxSelectedIndex == ThisItemIndex) @@ -1008,7 +1013,7 @@ CMenus::CListboxItem CMenus::UiDoListboxNextItem(CListBoxState* pState, const vo //selected_index = i; CUIRect r = Item.m_Rect; - RenderTools()->DrawUIRect(&r, vec4(1,1,1,0.5f), CUI::CORNER_ALL, 5.0f); + RenderTools()->DrawUIRect(&r, vec4(1,1,1,ProcessInput?0.5f:0.33f), CUI::CORNER_ALL, 5.0f); } return Item; diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index 5f256823c..abb183e3a 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -128,7 +128,7 @@ private: void UiDoListboxHeader(CListBoxState* pState, const CUIRect *pRect, const char *pTitle, float HeaderHeight, float Spacing); void UiDoListboxStart(CListBoxState* pState, const void *pID, float RowHeight, const char *pBottomText, int NumItems, int ItemsPerRow, int SelectedIndex, const CUIRect *pRect=0, bool Background=true); - CListboxItem UiDoListboxNextItem(CListBoxState* pState, const void *pID, bool Selected = false, bool ProcessInput = true); + CListboxItem UiDoListboxNextItem(CListBoxState* pState, const void *pID, bool Selected = false, bool* pActive = NULL); CListboxItem UiDoListboxNextRow(CListBoxState* pState); int UiDoListboxEnd(CListBoxState* pState, bool *pItemActivated); diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index 147187008..7473cc312 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -728,8 +728,6 @@ void CMenus::RenderLanguageSelection(CUIRect MainView, bool Header) } } - if(m_ActiveListBox != ACTLB_LANG && UI()->MouseInside(&MainView)) - m_ActiveListBox = ACTLB_LANG; int OldSelected = s_SelectedLanguage; if(Header) @@ -738,7 +736,10 @@ void CMenus::RenderLanguageSelection(CUIRect MainView, bool Header) for(sorted_array::range r = s_Languages.all(); !r.empty(); r.pop_front()) { - CListboxItem Item = UiDoListboxNextItem(&s_ListBoxState, &r.front(), false, m_ActiveListBox == ACTLB_LANG); + bool IsActive = m_ActiveListBox == ACTLB_LANG; + CListboxItem Item = UiDoListboxNextItem(&s_ListBoxState, &r.front(), false, &IsActive); + if(IsActive) + m_ActiveListBox = ACTLB_LANG; if(Item.m_Visible) { @@ -791,8 +792,6 @@ void CMenus::RenderThemeSelection(CUIRect MainView, bool Header) } } - if(m_ActiveListBox != ACTLB_THEME && UI()->MouseInside(&MainView)) - m_ActiveListBox = ACTLB_THEME; int OldSelected = s_SelectedTheme; if(Header) @@ -801,7 +800,10 @@ void CMenus::RenderThemeSelection(CUIRect MainView, bool Header) for(sorted_array::range r = m_lThemes.all(); !r.empty(); r.pop_front()) { - CListboxItem Item = UiDoListboxNextItem(&s_ListBoxState_Theme, &r.front(), false, m_ActiveListBox == ACTLB_THEME); + bool IsActive = m_ActiveListBox == ACTLB_THEME; + CListboxItem Item = UiDoListboxNextItem(&s_ListBoxState_Theme, &r.front(), false, &IsActive); + if(IsActive) + m_ActiveListBox = ACTLB_THEME; if(Item.m_Visible) {