From 7b4ceb9d0c776905e374621f99b9ded04c13023f Mon Sep 17 00:00:00 2001 From: Keiku <41867291+Keikiru@users.noreply.github.com> Date: Wed, 18 Oct 2023 22:59:00 +0200 Subject: [PATCH] Add checkbox for toggle walking (#20926) Co-authored-by: onoira LGTM! --- .../Options/UI/Tabs/KeyRebindTab.xaml.cs | 58 +++++++++++++++++++ Content.Shared/CCVar/CCVars.cs | 6 ++ .../en-US/escape-menu/ui/options-menu.ftl | 1 + 3 files changed, 65 insertions(+) diff --git a/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs b/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs index 188fe7740c..c68e7f3af9 100644 --- a/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs +++ b/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs @@ -1,5 +1,6 @@ using System.Numerics; using Content.Client.Stylesheets; +using Content.Shared.CCVar; using Content.Shared.Input; using Robust.Client.AutoGenerated; using Robust.Client.Input; @@ -41,6 +42,61 @@ namespace Content.Client.Options.UI.Tabs _cfg.SaveToFile(); } + private void InitToggleWalk() + { + if (_cfg.GetCVar(CCVars.ToggleWalk)) + { + ToggleFunctions.Add(EngineKeyFunctions.Walk); + } + else + { + ToggleFunctions.Remove(EngineKeyFunctions.Walk); + } + } + + private void HandleToggleWalk(BaseButton.ButtonToggledEventArgs args) + { + _cfg.SetCVar(CCVars.ToggleWalk, args.Pressed); + _cfg.SaveToFile(); + InitToggleWalk(); + + if (!_keyControls.TryGetValue(EngineKeyFunctions.Walk, out var keyControl)) + { + return; + } + + var bindingType = args.Pressed ? KeyBindingType.Toggle : KeyBindingType.State; + for (var i = 0; i <= 1; i++) + { + var binding = (i == 0 ? keyControl.BindButton1 : keyControl.BindButton2).Binding; + if (binding == null) + { + continue; + } + + var registration = new KeyBindingRegistration + { + Function = EngineKeyFunctions.Walk, + BaseKey = binding.BaseKey, + Mod1 = binding.Mod1, + Mod2 = binding.Mod2, + Mod3 = binding.Mod3, + Priority = binding.Priority, + Type = bindingType, + CanFocus = binding.CanFocus, + CanRepeat = binding.CanRepeat, + }; + + _deferCommands.Add(() => + { + _inputManager.RemoveBinding(binding); + _inputManager.RegisterBinding(registration); + }); + } + + _deferCommands.Add(_inputManager.SaveToUserData); + } + public KeyRebindTab() { IoCManager.InjectDependencies(this); @@ -98,6 +154,8 @@ namespace Content.Client.Options.UI.Tabs AddButton(EngineKeyFunctions.MoveDown); AddButton(EngineKeyFunctions.MoveRight); AddButton(EngineKeyFunctions.Walk); + AddCheckBox("ui-options-hotkey-toggle-walk", _cfg.GetCVar(CCVars.ToggleWalk), HandleToggleWalk); + InitToggleWalk(); AddHeader("ui-options-header-camera"); AddButton(EngineKeyFunctions.CameraRotateLeft); diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index 0cf374fe4d..eb74a4994f 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -1617,6 +1617,12 @@ namespace Content.Shared.CCVar public static readonly CVarDef DragDropDeadZone = CVarDef.Create("control.drag_dead_zone", 12f, CVar.CLIENTONLY | CVar.ARCHIVE); + /// + /// Toggles whether the walking key is a toggle or a held key. + /// + public static readonly CVarDef ToggleWalk = + CVarDef.Create("control.toggle_walk", false, CVar.CLIENTONLY | CVar.ARCHIVE); + /* * UPDATE */ diff --git a/Resources/Locale/en-US/escape-menu/ui/options-menu.ftl b/Resources/Locale/en-US/escape-menu/ui/options-menu.ftl index 10db378ab4..97d1da949b 100644 --- a/Resources/Locale/en-US/escape-menu/ui/options-menu.ftl +++ b/Resources/Locale/en-US/escape-menu/ui/options-menu.ftl @@ -82,6 +82,7 @@ ui-options-header-dev = Development ui-options-header-general = General ui-options-hotkey-keymap = Use US QWERTY Keys +ui-options-hotkey-toggle-walk = Toggle Walk ui-options-function-move-up = Move Up ui-options-function-move-left = Move Left -- 2.51.2