diff --git a/Content.Shared/Movement/Components/InputMoverComponent.cs b/Content.Shared/Movement/Components/InputMoverComponent.cs index 1a987a9b29ffc2..dc17eebc8d97d6 100644 --- a/Content.Shared/Movement/Components/InputMoverComponent.cs +++ b/Content.Shared/Movement/Components/InputMoverComponent.cs @@ -3,6 +3,8 @@ using Robust.Shared.GameStates; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom; using Robust.Shared.Timing; +using Robust.Shared.Prototypes; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; namespace Content.Shared.Movement.Components { @@ -72,5 +74,14 @@ public sealed partial class InputMoverComponent : Component [ViewVariables(VVAccess.ReadWrite)] public bool CanMove { get; set; } = true; + + [DataField("moveModeToggleAction", customTypeSerializer: typeof(PrototypeIdSerializer))] + public string MoveModeToggleAction = "ActionMoveModeToggle"; + + [DataField("moveModeToggleActionEntity")] + public EntityUid? MoveModeToggleActionEntity; + + [ViewVariables(VVAccess.ReadWrite)] + public bool SprintMove { get; set; } = true; } } diff --git a/Content.Shared/Movement/Systems/SharedMoverController.Input.cs b/Content.Shared/Movement/Systems/SharedMoverController.Input.cs index 9d150a0652becf..77951f518d2163 100644 --- a/Content.Shared/Movement/Systems/SharedMoverController.Input.cs +++ b/Content.Shared/Movement/Systems/SharedMoverController.Input.cs @@ -1,4 +1,5 @@ using System.Numerics; +using Content.Shared.Actions; using Content.Shared.CCVar; using Content.Shared.Follower.Components; using Content.Shared.Input; @@ -19,6 +20,8 @@ namespace Content.Shared.Movement.Systems /// public abstract partial class SharedMoverController { + [Dependency] private readonly SharedActionsSystem _actionsSystem = default!; + public bool CameraRotationLocked { get; set; } private void InitializeInput() @@ -52,6 +55,7 @@ private void InitializeInput() SubscribeLocalEvent(OnInputGetState); SubscribeLocalEvent(OnInputHandleState); SubscribeLocalEvent(OnInputParentChange); + SubscribeLocalEvent(OnActionPerform); SubscribeLocalEvent(OnAutoParentChange); @@ -261,6 +265,25 @@ private void OnInputParentChange(EntityUid uid, InputMoverComponent component, r Dirty(uid, component); } + private void OnActionPerform(EntityUid uid, InputMoverComponent component, ToggleMoveModeActionEvent args) + { + if (args.Handled) + return; + + var movementSpeed = EnsureComp(uid); + (movementSpeed.BaseSprintSpeed, movementSpeed.BaseWalkSpeed) = (movementSpeed.BaseWalkSpeed, movementSpeed.BaseSprintSpeed); + + component.SprintMove = !component.SprintMove; + + if (component.MoveModeToggleActionEntity != null) + _actionsSystem.SetToggled(component.MoveModeToggleActionEntity, component.SprintMove); + + Dirty(uid, component); + Dirty(uid, movementSpeed); + + args.Handled = true; + } + private void HandleDirChange(EntityUid entity, Direction dir, ushort subTick, bool state) { // Relayed movement just uses the same keybinds given we're moving the relayed entity @@ -311,6 +334,8 @@ private void OnInputInit(EntityUid uid, InputMoverComponent component, Component component.RelativeEntity = xform.GridUid ?? xform.MapUid; component.TargetRelativeRotation = Angle.Zero; + + _actionsSystem.AddAction(uid, ref component.MoveModeToggleActionEntity, component.MoveModeToggleAction); } private void HandleRunChange(EntityUid uid, ushort subTick, bool walking) @@ -638,4 +663,5 @@ public enum ShuttleButtons : byte Brake = 1 << 6, } + public sealed partial class ToggleMoveModeActionEvent : InstantActionEvent { } } 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 e2ff7bc411aad7..911a399e5da58f 100644 --- a/Resources/Locale/en-US/escape-menu/ui/options-menu.ftl +++ b/Resources/Locale/en-US/escape-menu/ui/options-menu.ftl @@ -87,7 +87,7 @@ ui-options-function-move-up = Move Up ui-options-function-move-left = Move Left ui-options-function-move-down = Move Down ui-options-function-move-right = Move Right -ui-options-function-walk = Walk +ui-options-function-walk = Walk/Sprint ui-options-function-camera-rotate-left = Rotate left ui-options-function-camera-rotate-right = Rotate right diff --git a/Resources/Locale/en-US/ss14-ru/prototypes/actions/types.ftl b/Resources/Locale/en-US/ss14-ru/prototypes/actions/types.ftl index 2537cfa71334a6..df0d4b4c885bf4 100644 --- a/Resources/Locale/en-US/ss14-ru/prototypes/actions/types.ftl +++ b/Resources/Locale/en-US/ss14-ru/prototypes/actions/types.ftl @@ -61,3 +61,6 @@ ent-ActionWake = Wake up ent-ActionActivateHonkImplant = Honk .desc = Activates your honking implant, which will produce the signature sound of the clown. .suffix = { "" } +ent-ActionMoveModeToggle = Toggle sprint + .desc = Settings walk/sprint move mode by default. + .suffix = { "" } diff --git a/Resources/Locale/ru-RU/escape-menu/ui/options-menu.ftl b/Resources/Locale/ru-RU/escape-menu/ui/options-menu.ftl index 3f79340d5cb4e7..80a75ebcef88ec 100644 --- a/Resources/Locale/ru-RU/escape-menu/ui/options-menu.ftl +++ b/Resources/Locale/ru-RU/escape-menu/ui/options-menu.ftl @@ -84,7 +84,7 @@ ui-options-function-move-up = Двигаться вверх ui-options-function-move-left = Двигаться налево ui-options-function-move-down = Двигаться вниз ui-options-function-move-right = Двигаться направо -ui-options-function-walk = Идти +ui-options-function-walk = Идти/Бежать ui-options-function-camera-rotate-left = Повернуть налево ui-options-function-camera-rotate-right = Повернуть направо ui-options-function-camera-reset = Сбросить камеру diff --git a/Resources/Locale/ru-RU/ss14-ru/prototypes/actions/types.ftl b/Resources/Locale/ru-RU/ss14-ru/prototypes/actions/types.ftl index d2f066136fb7e4..7f0bd4e171fb31 100644 --- a/Resources/Locale/ru-RU/ss14-ru/prototypes/actions/types.ftl +++ b/Resources/Locale/ru-RU/ss14-ru/prototypes/actions/types.ftl @@ -61,3 +61,6 @@ ent-ActionWake = Проснуться ent-ActionActivateHonkImplant = Хонк .desc = Активирует ваш хонкающий имплантат, который будет издавать фирменный звук клоуна. .suffix = { "" } +ent-ActionMoveModeToggle = Переключение ходьба/бег + .desc = Устанавливает ходьбу/бег по умолчанию. + .suffix = { "" } diff --git a/Resources/Prototypes/Actions/types.yml b/Resources/Prototypes/Actions/types.yml index 1092181bf89ef9..1b82458c8a1348 100644 --- a/Resources/Prototypes/Actions/types.yml +++ b/Resources/Prototypes/Actions/types.yml @@ -254,3 +254,16 @@ icon: { sprite: Objects/Fun/bikehorn.rsi, state: icon } event: !type:ActivateImplantEvent useDelay: 1 + +- type: entity + id: ActionMoveModeToggle + name: "Toggle sprint" + description: Toggles walk/sprint mode by default + noSpawn: true + components: + - type: InstantAction + checkCanInteract: false + icon: Interface/Actions/running.png + iconOn: Interface/Actions/walking.png + event: !type:ToggleMoveModeActionEvent + priority: -20 diff --git a/Resources/Textures/Interface/Actions/running.png b/Resources/Textures/Interface/Actions/running.png new file mode 100644 index 00000000000000..5a45a37bbb4435 Binary files /dev/null and b/Resources/Textures/Interface/Actions/running.png differ diff --git a/Resources/Textures/Interface/Actions/walking.png b/Resources/Textures/Interface/Actions/walking.png new file mode 100644 index 00000000000000..80e170177d2f90 Binary files /dev/null and b/Resources/Textures/Interface/Actions/walking.png differ