From 6e2f52054257a9d1fe5863a7d76d199013b1bf3b Mon Sep 17 00:00:00 2001 From: xTheLifex Date: Thu, 3 Oct 2024 21:24:14 -0300 Subject: [PATCH 1/3] Options Search Menu --- .../Options/UI/Tabs/KeyRebindTab.xaml | 10 ++++- .../Options/UI/Tabs/KeyRebindTab.xaml.cs | 40 ++++++++++++++++++- .../en-US/escape-menu/ui/options-menu.ftl | 1 + 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml b/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml index 93859099eeb..7c8db4c9853 100644 --- a/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml +++ b/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml @@ -1,6 +1,14 @@  + xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls" + xmlns:xNamespace="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:s="clr-namespace:Content.Client.Stylesheets"> + + diff --git a/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs b/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs index ab4ebd83fa7..87b44231d8f 100644 --- a/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs +++ b/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs @@ -36,6 +36,8 @@ public sealed partial class KeyRebindTab : Control private readonly List _deferCommands = new(); + private string _searchText = ""; + private void HandleToggleUSQWERTYCheckbox(BaseButton.ButtonToggledEventArgs args) { _cfg.SetCVar(CVars.DisplayUSQWERTYHotkeys, args.Pressed); @@ -102,7 +104,7 @@ private void HandleHoldLookUp(BaseButton.ButtonToggledEventArgs args) _cfg.SetCVar(CCVars.HoldLookUp, args.Pressed); _cfg.SaveToFile(); } - + private void HandleDefaultWalk(BaseButton.ButtonToggledEventArgs args) { _cfg.SetCVar(CCVars.DefaultWalk, args.Pressed); @@ -135,7 +137,21 @@ public KeyRebindTab() }); }; + SearchInput.OnTextChanged += _ => + { + _searchText = SearchInput.Text.TrimStart(); + PopulateOptions(); + }; + + PopulateOptions(); + } + + private void PopulateOptions() + { + KeybindsContainer.RemoveAllChildren(); + _keyControls.Clear(); var first = true; + var activeCategory = "general"; void AddHeader(string headerContents) { @@ -153,8 +169,27 @@ void AddHeader(string headerContents) }); } + bool ShouldDisplayButton(BoundKeyFunction function) + { + if (_searchText == string.Empty) + return true; + + var optionText = Loc.GetString($"ui-options-function-{CaseConversion.PascalToKebab(function.FunctionName)}"); + return optionText.StartsWith(_searchText, StringComparison.OrdinalIgnoreCase) || _searchText.Contains(optionText, StringComparison.OrdinalIgnoreCase); + } + + bool ShouldDisplayCheckBox(string checkBoxName) + { + if (_searchText == string.Empty) + return true; + var optionText = Loc.GetString(checkBoxName); + return optionText.StartsWith(_searchText, StringComparison.OrdinalIgnoreCase) || _searchText.Contains(optionText, StringComparison.OrdinalIgnoreCase); + } + void AddButton(BoundKeyFunction function) { + if (!ShouldDisplayButton(function)) + return; var control = new KeyControl(this, function); KeybindsContainer.AddChild(control); _keyControls.Add(function, control); @@ -162,6 +197,8 @@ void AddButton(BoundKeyFunction function) void AddCheckBox(string checkBoxName, bool currentState, Action? callBackOnClick) { + if (!ShouldDisplayCheckBox(checkBoxName)) + return; CheckBox newCheckBox = new CheckBox() { Text = Loc.GetString(checkBoxName) }; newCheckBox.Pressed = currentState; newCheckBox.OnToggled += callBackOnClick; @@ -285,6 +322,7 @@ void AddCheckBox(string checkBoxName, bool currentState, Action Date: Thu, 3 Oct 2024 21:30:15 -0300 Subject: [PATCH 2/3] Remove unused variable from testing --- Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs b/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs index 87b44231d8f..c7e249e9793 100644 --- a/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs +++ b/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs @@ -151,7 +151,6 @@ private void PopulateOptions() KeybindsContainer.RemoveAllChildren(); _keyControls.Clear(); var first = true; - var activeCategory = "general"; void AddHeader(string headerContents) { From ea6d0db71ea177fc53aa10f07610bfe13b5777cc Mon Sep 17 00:00:00 2001 From: TheLife Date: Sun, 20 Oct 2024 10:27:25 -0300 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: DEATHB4DEFEAT <77995199+DEATHB4DEFEAT@users.noreply.github.com> Signed-off-by: TheLife --- Content.Client/Options/UI/Tabs/KeyRebindTab.xaml | 1 + Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs | 9 +++++++-- Resources/Locale/en-US/escape-menu/ui/options-menu.ftl | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml b/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml index 7c8db4c9853..2924979ab24 100644 --- a/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml +++ b/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml @@ -5,6 +5,7 @@