Skip to content

Commit

Permalink
Display an Alert when the User Is Walking or Running. (#528)
Browse files Browse the repository at this point in the history
# Description

First PR. Adds an alert on the user UI whenever they toggle between
walking or running. No more second guessing whether you will slip or not
when walking over that puddle of water, or if your usage of Shift on
chat toggled your movement speed.

The alert is displayed for entities with the component
'CanWalkComponent', which is added to the following prototypes:
- All genetic ancestors (MobBaseAncestor)
- Human controlled mechs (BaseMech, wont display on VIMs or HAMTRs
because rats or hamsters can't walk, and the edge case is not worth the
trouble)
- All human/player species (BaseMobSpeciesOrganic)
- All slimes/geras (BaseMobAdultSlimes)
- Reagent Slimes (ReagentSlime)
- Rat Kings (MobRatKing - yes they can fucking walk lmao)
- Borgs (BaseBorgChassis)
---
<details><summary><h1>Media</h1></summary>
<p>


https://github.com/Simple-Station/Einstein-Engines/assets/159397573/1a60711b-d048-444d-bd08-6a9eadeccc8a


</p>
</details>

---

# Future Stuff

I also wanted to make it toggle the user's speed on click like it would
in ss13, but sadly the majority of the input management/prediction seems
to be done exclusively client-side, making it a hassle to work around
the alert. **Will revisit if there's improvements or refactors to the
movement code.**

---

# Changelog

:cl:
- add: Added an alert on the UI for when the user is walking or running.

---------

Signed-off-by: gluesniffler <[email protected]>
Co-authored-by: DEATHB4DEFEAT <[email protected]>
  • Loading branch information
gluesniffler and DEATHB4DEFEAT authored Jul 16, 2024
1 parent e59c144 commit 62dfbfc
Show file tree
Hide file tree
Showing 17 changed files with 73 additions and 1 deletion.
1 change: 1 addition & 0 deletions Content.Shared/Alert/AlertType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public enum AlertType : byte
Internals,
Toxins,
Muted,
Walking,
VowOfSilence,
VowBroken,
Essence,
Expand Down
11 changes: 11 additions & 0 deletions Content.Shared/Movement/Components/CanWalkComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Robust.Shared.GameStates;

namespace Content.Shared.Movement.Components;

/// <summary>
/// Indicates if the entity can toggle walking or not.
/// </summary>
[NetworkedComponent, RegisterComponent]
public sealed partial class CanWalkComponent : Component
{
}
5 changes: 5 additions & 0 deletions Content.Shared/Movement/Components/InputMoverComponent.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Numerics;
using Content.Shared.Alert;
using Content.Shared.Movement.Systems;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
using Robust.Shared.Timing;
using Robust.Shared.Prototypes;

namespace Content.Shared.Movement.Components
{
Expand Down Expand Up @@ -74,6 +76,9 @@ public sealed partial class InputMoverComponent : Component

[ViewVariables(VVAccess.ReadWrite)]
public bool CanMove = true;

[DataField]
public ProtoId<AlertPrototype> WalkingAlert = "Walking";
}

[Serializable, NetSerializable]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Numerics;
using Content.Shared.Alert;
using Content.Shared.CCVar;
using Content.Shared.Follower.Components;
using Content.Shared.Input;
Expand Down Expand Up @@ -333,6 +334,7 @@ private void OnInputInit(EntityUid uid, InputMoverComponent component, Component

component.RelativeEntity = xform.GridUid ?? xform.MapUid;
component.TargetRelativeRotation = Angle.Zero;
WalkingAlert(uid, !component.Sprinting);
}

private void HandleRunChange(EntityUid uid, ushort subTick, bool walking)
Expand All @@ -344,6 +346,7 @@ private void HandleRunChange(EntityUid uid, ushort subTick, bool walking)
// if we swap to relay then stop our existing input if we ever change back.
if (moverComp != null)
{
WalkingAlert(uid, walking);
SetMoveInput(moverComp, MoveButtons.None);
}

Expand Down Expand Up @@ -460,10 +463,11 @@ private void ResetSubtick(InputMoverComponent component)
component.LastInputSubTick = 0;
}


public void SetSprinting(EntityUid entity, InputMoverComponent component, ushort subTick, bool walking)
{
// Logger.Info($"[{_gameTiming.CurTick}/{subTick}] Sprint: {enabled}");

WalkingAlert(entity, walking);
SetMoveInput(entity, component, subTick, walking, MoveButtons.Walk);
}

Expand Down
12 changes: 12 additions & 0 deletions Content.Shared/Movement/Systems/SharedMoverController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using Content.Shared.Alert;
using Content.Shared.Bed.Sleep;
using Content.Shared.CCVar;
using Content.Shared.Friction;
Expand All @@ -25,6 +26,7 @@
using Robust.Shared.Utility;
using PullableComponent = Content.Shared.Movement.Pulling.Components.PullableComponent;


namespace Content.Shared.Movement.Systems
{
/// <summary>
Expand All @@ -33,6 +35,7 @@ namespace Content.Shared.Movement.Systems
/// </summary>
public abstract partial class SharedMoverController : VirtualController
{
[Dependency] private readonly AlertsSystem _alerts = default!;
[Dependency] private readonly IConfigurationManager _configManager = default!;
[Dependency] protected readonly IGameTiming Timing = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
Expand Down Expand Up @@ -165,6 +168,7 @@ protected void HandleMobMovement(
var (walkDir, sprintDir) = GetVelocityInput(mover);
var touching = false;


// Handle wall-pushes.
if (weightless)
{
Expand Down Expand Up @@ -285,6 +289,14 @@ protected void HandleMobMovement(
PhysicsSystem.SetAngularVelocity(physicsUid, 0, body: physicsComponent);
}

public void WalkingAlert(EntityUid player, bool walking)
{
if (HasComp<CanWalkComponent>(player))
{
_alerts.ShowAlert(player, AlertType.Walking, walking ? (short) 0 : (short) 1);
}
}

public void LerpRotation(EntityUid uid, InputMoverComponent mover, float frameTime)
{
var angleDiff = Angle.ShortestDistance(mover.RelativeRotation, mover.TargetRelativeRotation);
Expand Down
3 changes: 3 additions & 0 deletions Resources/Locale/en-US/alerts/alerts.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,8 @@ alerts-revenant-essence-desc = The power of souls. It sustains you and is used f
alerts-revenant-corporeal-name = Corporeal
alerts-revenant-corporeal-desc = You have manifested physically. People around you can see and hurt you.
alerts-walking-name = Walking
alerts-walking-desc = Indicates how fast you're moving.
alerts-offer-name = Offer
alerts-offer-desc = Someone offers you an item.
12 changes: 12 additions & 0 deletions Resources/Prototypes/Alerts/alerts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,18 @@
name: alerts-pacified-name
description: alerts-pacified-desc

- type: alert
id: Walking
icons:
- sprite: /Textures/Interface/Alerts/walking.rsi
state: walking0
- sprite: /Textures/Interface/Alerts/walking.rsi
state: walking1
name: alerts-walking-name
description: alerts-walking-desc
minSeverity: 0
maxSeverity: 1

- type: alert
id: Debug1
icons:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@
understands:
- GalacticCommon
- RobotTalk
- type: CanWalk

- type: entity
id: BaseBorgChassisNT
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/Entities/Mobs/NPCs/animals.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,7 @@
tags:
- VimPilot
- DoorBumpOpener
- type: CanWalk

- type: entity
name: monkey
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/Entities/Mobs/NPCs/elemental.yml
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@
solution: bloodstream
- type: DrainableSolution
solution: bloodstream
- type: CanWalk

- type: entity
name: Reagent Slime Spawner
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/Entities/Mobs/NPCs/regalrat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
understands:
- GalacticCommon
- Mouse
- type: CanWalk

- type: entity
id: MobRatKingBuff
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/Entities/Mobs/NPCs/slimes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
speechSounds: Slime
- type: TypingIndicator
proto: slime
- type: CanWalk

- type: entity
name: blue slime
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/Entities/Mobs/Species/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@
- CanPilot
- FootstepSound
- DoorBumpOpener
- type: CanWalk

- type: entity
save: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
- type: GuideHelp
guides:
- Robotics
- type: CanWalk

- type: entity
id: MechRipley
Expand Down
17 changes: 17 additions & 0 deletions Resources/Textures/Interface/Alerts/walking.rsi/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "Walking/Running icons modified by Mocho, original taken from /tg/station https://github.com/tgstation/tgstation/pull/52691/commits/6a1261187c108c8f151c99ebfa567bd1ec34044c",
"size": {
"x": 32,
"y": 32
},
"states": [
{
"name": "walking0"
},
{
"name": "walking1"
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 62dfbfc

Please sign in to comment.