Skip to content

Commit

Permalink
Made action for swap movement modes.
Browse files Browse the repository at this point in the history
Sprites by wax#5037
  • Loading branch information
Mr0maks committed Sep 16, 2023
1 parent df95395 commit e335f46
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 2 deletions.
11 changes: 11 additions & 0 deletions Content.Shared/Movement/Components/InputMoverComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -72,5 +74,14 @@ public sealed partial class InputMoverComponent : Component

[ViewVariables(VVAccess.ReadWrite)]
public bool CanMove { get; set; } = true;

[DataField("moveModeToggleAction", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string MoveModeToggleAction = "ActionMoveModeToggle";

[DataField("moveModeToggleActionEntity")]
public EntityUid? MoveModeToggleActionEntity;

[ViewVariables(VVAccess.ReadWrite)]
public bool SprintMove { get; set; } = true;
}
}
26 changes: 26 additions & 0 deletions Content.Shared/Movement/Systems/SharedMoverController.Input.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Numerics;
using Content.Shared.Actions;
using Content.Shared.CCVar;
using Content.Shared.Follower.Components;
using Content.Shared.Input;
Expand All @@ -19,6 +20,8 @@ namespace Content.Shared.Movement.Systems
/// </summary>
public abstract partial class SharedMoverController
{
[Dependency] private readonly SharedActionsSystem _actionsSystem = default!;

public bool CameraRotationLocked { get; set; }

private void InitializeInput()
Expand Down Expand Up @@ -52,6 +55,7 @@ private void InitializeInput()
SubscribeLocalEvent<InputMoverComponent, ComponentGetState>(OnInputGetState);
SubscribeLocalEvent<InputMoverComponent, ComponentHandleState>(OnInputHandleState);
SubscribeLocalEvent<InputMoverComponent, EntParentChangedMessage>(OnInputParentChange);
SubscribeLocalEvent<InputMoverComponent, ToggleMoveModeActionEvent>(OnActionPerform);

SubscribeLocalEvent<AutoOrientComponent, EntParentChangedMessage>(OnAutoParentChange);

Expand Down Expand Up @@ -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<MovementSpeedModifierComponent>(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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -638,4 +663,5 @@ public enum ShuttleButtons : byte
Brake = 1 << 6,
}

public sealed partial class ToggleMoveModeActionEvent : InstantActionEvent { }
}
2 changes: 1 addition & 1 deletion Resources/Locale/en-US/escape-menu/ui/options-menu.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Resources/Locale/en-US/ss14-ru/prototypes/actions/types.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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 = { "" }
2 changes: 1 addition & 1 deletion Resources/Locale/ru-RU/escape-menu/ui/options-menu.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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 = Сбросить камеру
Expand Down
3 changes: 3 additions & 0 deletions Resources/Locale/ru-RU/ss14-ru/prototypes/actions/types.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@ ent-ActionWake = Проснуться
ent-ActionActivateHonkImplant = Хонк
.desc = Активирует ваш хонкающий имплантат, который будет издавать фирменный звук клоуна.
.suffix = { "" }
ent-ActionMoveModeToggle = Переключение ходьба/бег
.desc = Устанавливает ходьбу/бег по умолчанию.
.suffix = { "" }
13 changes: 13 additions & 0 deletions Resources/Prototypes/Actions/types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Binary file added Resources/Textures/Interface/Actions/running.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/Textures/Interface/Actions/walking.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e335f46

Please sign in to comment.