diff --git a/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml b/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml index 93859099eeb..2924979ab24 100644 --- a/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml +++ b/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml @@ -1,6 +1,15 @@  + 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 a11f77dc4f4..e39c9cdc53e 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); @@ -135,6 +137,19 @@ public KeyRebindTab() }); }; + SearchInput.OnTextChanged += _ => + { + _searchText = SearchInput.Text.TrimStart(); + PopulateOptions(); + }; + + PopulateOptions(); + } + + private void PopulateOptions() + { + KeybindsContainer.RemoveAllChildren(); + _keyControls.Clear(); var first = true; void AddHeader(string headerContents) @@ -153,8 +168,31 @@ 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 +200,9 @@ 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; @@ -304,6 +345,7 @@ void AddCheckBox(string checkBoxName, bool currentState, Action