Skip to content

Commit

Permalink
Back action move mode changer
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr0maks committed Sep 17, 2023
1 parent b83c43a commit ea7541f
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 4 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;
}
}
43 changes: 41 additions & 2 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 @@ -49,9 +52,11 @@ private void InitializeInput()
.Register<SharedMoverController>();

SubscribeLocalEvent<InputMoverComponent, ComponentInit>(OnInputInit);
SubscribeLocalEvent<InputMoverComponent, MapInitEvent>(OnInputMapInit);
SubscribeLocalEvent<InputMoverComponent, ComponentGetState>(OnInputGetState);
SubscribeLocalEvent<InputMoverComponent, ComponentHandleState>(OnInputHandleState);
SubscribeLocalEvent<InputMoverComponent, EntParentChangedMessage>(OnInputParentChange);
SubscribeLocalEvent<InputMoverComponent, ToggleMoveModeActionEvent>(OnActionPerform);

SubscribeLocalEvent<AutoOrientComponent, EntParentChangedMessage>(OnAutoParentChange);

Expand Down Expand Up @@ -89,6 +94,9 @@ private void OnInputHandleState(EntityUid uid, InputMoverComponent component, re
component.TargetRelativeRotation = state.TargetRelativeRotation;
component.RelativeEntity = EnsureEntity<InputMoverComponent>(state.RelativeEntity, uid);
component.LerpTarget = state.LerpAccumulator;
if (state.ActionEntity is not null)
component.MoveModeToggleActionEntity = EnsureEntity<ActionsComponent>(state.ActionEntity, uid);
component.SprintMove = state.SprintMove;
}

private void OnInputGetState(EntityUid uid, InputMoverComponent component, ref ComponentGetState args)
Expand All @@ -99,7 +107,9 @@ private void OnInputGetState(EntityUid uid, InputMoverComponent component, ref C
component.RelativeRotation,
component.TargetRelativeRotation,
GetNetEntity(component.RelativeEntity),
component.LerpTarget);
component.LerpTarget,
GetNetEntity(component.MoveModeToggleActionEntity),
component.SprintMove);
}

private void ShutdownInput()
Expand Down Expand Up @@ -261,6 +271,24 @@ 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, 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 @@ -313,6 +341,11 @@ private void OnInputInit(EntityUid uid, InputMoverComponent component, Component
component.TargetRelativeRotation = Angle.Zero;
}

private void OnInputMapInit(EntityUid uid, InputMoverComponent component, MapInitEvent args)
{
_actionsSystem.AddAction(uid, ref component.MoveModeToggleActionEntity, component.MoveModeToggleAction);
}

private void HandleRunChange(EntityUid uid, ushort subTick, bool walking)
{
MoverQuery.TryGetComponent(uid, out var moverComp);
Expand Down Expand Up @@ -582,14 +615,19 @@ private sealed class InputMoverComponentState : ComponentState
public NetEntity? RelativeEntity;
public TimeSpan LerpAccumulator;

public InputMoverComponentState(MoveButtons buttons, bool canMove, Angle relativeRotation, Angle targetRelativeRotation, NetEntity? relativeEntity, TimeSpan lerpTarget)
public NetEntity? ActionEntity;
public bool SprintMove;

public InputMoverComponentState(MoveButtons buttons, bool canMove, Angle relativeRotation, Angle targetRelativeRotation, NetEntity? relativeEntity, TimeSpan lerpTarget, NetEntity? actionEntity, bool sprintMove)
{
Buttons = buttons;
CanMove = canMove;
RelativeRotation = relativeRotation;
TargetRelativeRotation = targetRelativeRotation;
RelativeEntity = relativeEntity;
LerpAccumulator = lerpTarget;
ActionEntity = actionEntity;
SprintMove = sprintMove;
}
}

Expand Down Expand Up @@ -638,4 +676,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 ea7541f

Please sign in to comment.