mirror of
https://github.com/space-wizards/space-station-14.git
synced 2026-02-14 19:29:53 +01:00
Add an option for hold-to-attack in settings (#42596)
* Initial commit * Separate ranged and melee * Move to controls tab
This commit is contained in:
@@ -15,8 +15,8 @@
|
||||
<ui:OptionSlider Name="SpeechBubbleSpeakerOpacitySlider" Title="{Loc 'ui-options-speech-bubble-speaker-opacity'}" />
|
||||
<ui:OptionSlider Name="SpeechBubbleBackgroundOpacitySlider" Title="{Loc 'ui-options-speech-bubble-background-opacity'}" />
|
||||
<CheckBox Name="AutoFillHighlightsCheckBox" Text="{Loc 'ui-options-auto-fill-highlights'}" />
|
||||
<ui:OptionColorSlider Name="HighlightsColorSlider"
|
||||
Title="{Loc 'ui-options-highlights-color'}"
|
||||
<ui:OptionColorSlider Name="HighlightsColorSlider"
|
||||
Title="{Loc 'ui-options-highlights-color'}"
|
||||
Example="{Loc 'ui-options-highlights-color-example'}"/>
|
||||
<Label Text="{Loc 'ui-options-accessability-header-content'}"
|
||||
StyleClasses="LabelKeyText"/>
|
||||
|
||||
@@ -36,12 +36,6 @@ namespace Content.Client.Options.UI.Tabs
|
||||
|
||||
private readonly List<Action> _deferCommands = new();
|
||||
|
||||
private void HandleToggleUSQWERTYCheckbox(BaseButton.ButtonToggledEventArgs args)
|
||||
{
|
||||
_cfg.SetCVar(CVars.DisplayUSQWERTYHotkeys, args.Pressed);
|
||||
_cfg.SaveToFile();
|
||||
}
|
||||
|
||||
private void InitToggleWalk()
|
||||
{
|
||||
if (_cfg.GetCVar(CCVars.ToggleWalk))
|
||||
@@ -150,8 +144,23 @@ namespace Content.Client.Options.UI.Tabs
|
||||
KeybindsContainer.AddChild(newCheckBox);
|
||||
}
|
||||
|
||||
void AddToggleCvarCheckBox(string checkBoxName, CVarDef<bool> cvar)
|
||||
{
|
||||
CheckBox newCheckBox = new CheckBox() { Text = Loc.GetString(checkBoxName) };
|
||||
newCheckBox.Pressed = _cfg.GetCVar(cvar);
|
||||
newCheckBox.OnToggled += (e) =>
|
||||
{
|
||||
_cfg.SetCVar(cvar, e.Pressed);
|
||||
_cfg.SaveToFile();
|
||||
};
|
||||
|
||||
KeybindsContainer.AddChild(newCheckBox);
|
||||
}
|
||||
|
||||
AddHeader("ui-options-header-general");
|
||||
AddCheckBox("ui-options-hotkey-keymap", _cfg.GetCVar(CVars.DisplayUSQWERTYHotkeys), HandleToggleUSQWERTYCheckbox);
|
||||
AddToggleCvarCheckBox("ui-options-hotkey-keymap", CVars.DisplayUSQWERTYHotkeys);
|
||||
AddToggleCvarCheckBox("ui-options-hold-to-attack-melee", CCVars.ControlHoldToAttackMelee);
|
||||
AddToggleCvarCheckBox("ui-options-hold-to-attack-ranged", CCVars.ControlHoldToAttackRanged);
|
||||
|
||||
AddHeader("ui-options-header-movement");
|
||||
AddButton(EngineKeyFunctions.MoveUp);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Linq;
|
||||
using Content.Client.Gameplay;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.CombatMode;
|
||||
using Content.Shared.Effects;
|
||||
using Content.Shared.Hands.Components;
|
||||
@@ -14,6 +15,7 @@ using Robust.Client.Graphics;
|
||||
using Robust.Client.Input;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Client.State;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Player;
|
||||
@@ -31,6 +33,7 @@ public sealed partial class MeleeWeaponSystem : SharedMeleeWeaponSystem
|
||||
[Dependency] private readonly SharedColorFlashEffectSystem _color = default!;
|
||||
[Dependency] private readonly MapSystem _map = default!;
|
||||
[Dependency] private readonly SpriteSystem _sprite = default!;
|
||||
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
||||
|
||||
private EntityQuery<TransformComponent> _xformQuery;
|
||||
|
||||
@@ -76,7 +79,7 @@ public sealed partial class MeleeWeaponSystem : SharedMeleeWeaponSystem
|
||||
var useDown = _inputSystem.CmdStates.GetState(EngineKeyFunctions.Use);
|
||||
var altDown = _inputSystem.CmdStates.GetState(EngineKeyFunctions.UseSecondary);
|
||||
|
||||
if (weapon.AutoAttack || useDown != BoundKeyState.Down && altDown != BoundKeyState.Down)
|
||||
if (weapon.AutoAttack || useDown != BoundKeyState.Down && altDown != BoundKeyState.Down || _cfg.GetCVar(CCVars.ControlHoldToAttackMelee))
|
||||
{
|
||||
if (weapon.Attacking)
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@ using Content.Client.Gameplay;
|
||||
using Content.Client.Items;
|
||||
using Content.Client.Weapons.Ranged.Components;
|
||||
using Content.Shared.Camera;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.CombatMode;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Weapons.Hitscan.Components;
|
||||
@@ -19,6 +20,7 @@ using Robust.Client.Player;
|
||||
using Robust.Client.State;
|
||||
using Robust.Shared.Animations;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
@@ -38,6 +40,7 @@ public sealed partial class GunSystem : SharedGunSystem
|
||||
[Dependency] private readonly IOverlayManager _overlayManager = default!;
|
||||
[Dependency] private readonly IPlayerManager _player = default!;
|
||||
[Dependency] private readonly IStateManager _state = default!;
|
||||
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
||||
[Dependency] private readonly SharedCameraRecoilSystem _recoil = default!;
|
||||
[Dependency] private readonly SharedMapSystem _maps = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _xform = default!;
|
||||
@@ -203,11 +206,13 @@ public sealed partial class GunSystem : SharedGunSystem
|
||||
|
||||
Log.Debug($"Sending shoot request tick {Timing.CurTick} / {Timing.CurTime}");
|
||||
|
||||
|
||||
RaisePredictiveEvent(new RequestShootEvent
|
||||
{
|
||||
Target = target,
|
||||
Coordinates = GetNetCoordinates(coordinates),
|
||||
Gun = GetNetEntity(gun),
|
||||
Continuous = _cfg.GetCVar(CCVars.ControlHoldToAttackRanged),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -70,4 +70,17 @@ public sealed partial class CCVars
|
||||
/// </summary>
|
||||
public static readonly CVarDef<bool> NestedStorage =
|
||||
CVarDef.Create("control.nested_storage", true, CVar.REPLICATED | CVar.SERVER);
|
||||
|
||||
/// <summary>
|
||||
/// If enabled, melee weapons that have click-to-attack patterns (unarmed, slow weapons) will continue attacking if the button is held.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<bool> ControlHoldToAttackMelee =
|
||||
CVarDef.Create("control.hold_to_attack_melee", false, CVar.CLIENTONLY | CVar.ARCHIVE);
|
||||
|
||||
/// <summary>
|
||||
/// If enabled, ranged weapons that have click-to-attack patterns (burst and semi-auto guns) will continue attacking if the button is held.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<bool> ControlHoldToAttackRanged =
|
||||
CVarDef.Create("control.hold_to_attack_ranged", false, CVar.CLIENTONLY | CVar.ARCHIVE);
|
||||
|
||||
}
|
||||
|
||||
@@ -9,7 +9,24 @@ namespace Content.Shared.Weapons.Ranged.Events;
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class RequestShootEvent : EntityEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// The gun shooting.
|
||||
/// </summary>
|
||||
public NetEntity Gun;
|
||||
|
||||
/// <summary>
|
||||
/// The location the player is shooting at.
|
||||
/// </summary>
|
||||
public NetCoordinates Coordinates;
|
||||
|
||||
/// <summary>
|
||||
/// The target the player is shooting at, if any.
|
||||
/// </summary>
|
||||
public NetEntity? Target;
|
||||
|
||||
/// <summary>
|
||||
/// If the client wants to continuously shoot.
|
||||
/// If true, the gun will continue firing until a stop event is sent from the client.
|
||||
/// </summary>
|
||||
public bool Continuous;
|
||||
}
|
||||
|
||||
@@ -158,6 +158,8 @@ public abstract partial class SharedGunSystem : EntitySystem
|
||||
gun.Comp.ShootCoordinates = GetCoordinates(msg.Coordinates);
|
||||
gun.Comp.Target = GetEntity(msg.Target);
|
||||
AttemptShoot(user.Value, gun);
|
||||
if (msg.Continuous)
|
||||
gun.Comp.ShotCounter = 0;
|
||||
}
|
||||
|
||||
private void OnStopShootRequest(RequestStopShootEvent ev, EntitySessionEventArgs args)
|
||||
|
||||
@@ -108,6 +108,9 @@ ui-options-hud-layout = HUD layout:
|
||||
|
||||
## Controls menu
|
||||
|
||||
ui-options-hold-to-attack-melee = Hold to attack (melee)
|
||||
ui-options-hold-to-attack-ranged = Hold to attack (ranged)
|
||||
|
||||
ui-options-binds-reset-all = Reset ALL keybinds
|
||||
ui-options-binds-explanation = Click to change binding, right-click to clear
|
||||
ui-options-unbound = Unbound
|
||||
|
||||
Reference in New Issue
Block a user