Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keybind Search Bar #1005

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Content.Client/Options/UI/Tabs/KeyRebindTab.xaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<Control xmlns="https://spacestation14.io"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls">
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
xmlns:xNamespace="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:Content.Client.Stylesheets">
<BoxContainer Orientation="Vertical">
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc 'ui-options-binds-search'}"
xTheLifex marked this conversation as resolved.
Show resolved Hide resolved
FontColorOverride="{xNamespace:Static s:StyleNano.NanoGold}"
/>
<LineEdit Name="SearchInput" HorizontalExpand="True" SizeFlagsStretchRatio="2"/>
</BoxContainer>
<ScrollContainer VerticalExpand="True">
<BoxContainer Name="KeybindsContainer" Orientation="Vertical" Margin="8 8 8 8">

Expand Down
39 changes: 38 additions & 1 deletion Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public sealed partial class KeyRebindTab : Control

private readonly List<Action> _deferCommands = new();

private string _searchText = "";

private void HandleToggleUSQWERTYCheckbox(BaseButton.ButtonToggledEventArgs args)
{
_cfg.SetCVar(CVars.DisplayUSQWERTYHotkeys, args.Pressed);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand All @@ -153,15 +168,36 @@ 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);
xTheLifex marked this conversation as resolved.
Show resolved Hide resolved
}

bool ShouldDisplayCheckBox(string checkBoxName)
{
if (_searchText == string.Empty)
return true;
var optionText = Loc.GetString(checkBoxName);
xTheLifex marked this conversation as resolved.
Show resolved Hide resolved
return optionText.StartsWith(_searchText, StringComparison.OrdinalIgnoreCase) || _searchText.Contains(optionText, StringComparison.OrdinalIgnoreCase);
xTheLifex marked this conversation as resolved.
Show resolved Hide resolved
}

void AddButton(BoundKeyFunction function)
{
if (!ShouldDisplayButton(function))
return;
xTheLifex marked this conversation as resolved.
Show resolved Hide resolved
var control = new KeyControl(this, function);
KeybindsContainer.AddChild(control);
_keyControls.Add(function, control);
}

void AddCheckBox(string checkBoxName, bool currentState, Action<BaseButton.ButtonToggledEventArgs>? callBackOnClick)
{
if (!ShouldDisplayCheckBox(checkBoxName))
return;
xTheLifex marked this conversation as resolved.
Show resolved Hide resolved
CheckBox newCheckBox = new CheckBox() { Text = Loc.GetString(checkBoxName) };
newCheckBox.Pressed = currentState;
newCheckBox.OnToggled += callBackOnClick;
Expand Down Expand Up @@ -285,6 +321,7 @@ void AddCheckBox(string checkBoxName, bool currentState, Action<BaseButton.Butto
AddButton(EngineKeyFunctions.HideUI);
AddButton(ContentKeyFunctions.InspectEntity);


foreach (var control in _keyControls.Values)
{
UpdateKeyControl(control);
Expand Down
1 change: 1 addition & 0 deletions Resources/Locale/en-US/escape-menu/ui/options-menu.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ ui-options-hud-layout = HUD layout:

ui-options-binds-reset-all = Reset ALL keybinds
ui-options-binds-explanation = Click to change binding, right-click to clear
ui-options-binds-search = Search:
xTheLifex marked this conversation as resolved.
Show resolved Hide resolved
ui-options-unbound = Unbound
ui-options-bind-reset = Reset
ui-options-key-prompt = Press a key...
Expand Down
Loading