Add checkbox for toggle walking (#20926)
Co-authored-by: onoira <onoira@psiko.zone> LGTM!
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using Content.Client.Stylesheets;
|
using Content.Client.Stylesheets;
|
||||||
|
using Content.Shared.CCVar;
|
||||||
using Content.Shared.Input;
|
using Content.Shared.Input;
|
||||||
using Robust.Client.AutoGenerated;
|
using Robust.Client.AutoGenerated;
|
||||||
using Robust.Client.Input;
|
using Robust.Client.Input;
|
||||||
@@ -41,6 +42,61 @@ namespace Content.Client.Options.UI.Tabs
|
|||||||
_cfg.SaveToFile();
|
_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()
|
public KeyRebindTab()
|
||||||
{
|
{
|
||||||
IoCManager.InjectDependencies(this);
|
IoCManager.InjectDependencies(this);
|
||||||
@@ -98,6 +154,8 @@ namespace Content.Client.Options.UI.Tabs
|
|||||||
AddButton(EngineKeyFunctions.MoveDown);
|
AddButton(EngineKeyFunctions.MoveDown);
|
||||||
AddButton(EngineKeyFunctions.MoveRight);
|
AddButton(EngineKeyFunctions.MoveRight);
|
||||||
AddButton(EngineKeyFunctions.Walk);
|
AddButton(EngineKeyFunctions.Walk);
|
||||||
|
AddCheckBox("ui-options-hotkey-toggle-walk", _cfg.GetCVar(CCVars.ToggleWalk), HandleToggleWalk);
|
||||||
|
InitToggleWalk();
|
||||||
|
|
||||||
AddHeader("ui-options-header-camera");
|
AddHeader("ui-options-header-camera");
|
||||||
AddButton(EngineKeyFunctions.CameraRotateLeft);
|
AddButton(EngineKeyFunctions.CameraRotateLeft);
|
||||||
|
|||||||
@@ -1617,6 +1617,12 @@ namespace Content.Shared.CCVar
|
|||||||
public static readonly CVarDef<float> DragDropDeadZone =
|
public static readonly CVarDef<float> DragDropDeadZone =
|
||||||
CVarDef.Create("control.drag_dead_zone", 12f, CVar.CLIENTONLY | CVar.ARCHIVE);
|
CVarDef.Create("control.drag_dead_zone", 12f, CVar.CLIENTONLY | CVar.ARCHIVE);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Toggles whether the walking key is a toggle or a held key.
|
||||||
|
/// </summary>
|
||||||
|
public static readonly CVarDef<bool> ToggleWalk =
|
||||||
|
CVarDef.Create("control.toggle_walk", false, CVar.CLIENTONLY | CVar.ARCHIVE);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* UPDATE
|
* UPDATE
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ ui-options-header-dev = Development
|
|||||||
ui-options-header-general = General
|
ui-options-header-general = General
|
||||||
|
|
||||||
ui-options-hotkey-keymap = Use US QWERTY Keys
|
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-up = Move Up
|
||||||
ui-options-function-move-left = Move Left
|
ui-options-function-move-left = Move Left
|
||||||
|
|||||||
Reference in New Issue
Block a user