Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Walking alert #32954

Merged
merged 7 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions Content.Client/Alerts/ClientAlertsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Content.Shared.Alert;
using JetBrains.Annotations;
using Robust.Client.Player;
using Robust.Shared.GameStates;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;

Expand All @@ -24,8 +25,7 @@ public override void Initialize()

SubscribeLocalEvent<AlertsComponent, LocalPlayerAttachedEvent>(OnPlayerAttached);
SubscribeLocalEvent<AlertsComponent, LocalPlayerDetachedEvent>(OnPlayerDetached);

SubscribeLocalEvent<AlertsComponent, AfterAutoHandleStateEvent>(ClientAlertsHandleState);
SubscribeLocalEvent<AlertsComponent, ComponentHandleState>(OnHandleState);
}
protected override void LoadPrototypes()
{
Expand All @@ -47,17 +47,22 @@ public IReadOnlyDictionary<AlertKey, AlertState>? ActiveAlerts
}
}

protected override void AfterShowAlert(Entity<AlertsComponent> alerts)
private void OnHandleState(Entity<AlertsComponent> alerts, ref ComponentHandleState args)
{
if (args.Current is not AlertComponentState cast)
return;

alerts.Comp.Alerts = cast.Alerts;

UpdateHud(alerts);
}

protected override void AfterClearAlert(Entity<AlertsComponent> alerts)
protected override void AfterShowAlert(Entity<AlertsComponent> alerts)
{
UpdateHud(alerts);
}

private void ClientAlertsHandleState(Entity<AlertsComponent> alerts, ref AfterAutoHandleStateEvent args)
protected override void AfterClearAlert(Entity<AlertsComponent> alerts)
{
UpdateHud(alerts);
}
Expand Down
16 changes: 16 additions & 0 deletions Content.Client/Physics/Controllers/MoverController.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using Content.Shared.Alert;
using Content.Shared.CCVar;
using Content.Shared.Movement.Components;
using Content.Shared.Movement.Pulling.Components;
using Content.Shared.Movement.Systems;
using Robust.Client.GameObjects;
using Robust.Client.Physics;
using Robust.Client.Player;
using Robust.Shared.Configuration;
using Robust.Shared.Physics.Components;
using Robust.Shared.Player;
using Robust.Shared.Timing;
Expand All @@ -14,6 +17,8 @@ public sealed class MoverController : SharedMoverController
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly AlertsSystem _alerts = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;

public override void Initialize()
{
Expand Down Expand Up @@ -135,4 +140,15 @@ protected override bool CanSound()
{
return _timing is { IsFirstTimePredicted: true, InSimulation: true };
}

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

if (walking && _cfg.GetCVar(CCVars.ToggleWalk))
_alerts.ShowAlert(entity, WalkingAlert, showCooldown: false, autoRemove: false);
else
_alerts.ClearAlert(entity, WalkingAlert);
}
}
12 changes: 12 additions & 0 deletions Content.Server/Alert/ServerAlertsSystem.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
using Content.Shared.Alert;
using Robust.Shared.GameStates;

namespace Content.Server.Alert;

internal sealed class ServerAlertsSystem : AlertsSystem
{
public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<AlertsComponent, ComponentGetState>(OnGetState);
}

private void OnGetState(Entity<AlertsComponent> alerts, ref ComponentGetState args)
{
args.State = new AlertComponentState(alerts.Comp.Alerts);
}
}
16 changes: 14 additions & 2 deletions Content.Shared/Alert/AlertsComponent.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;

namespace Content.Shared.Alert;

/// <summary>
/// Handles the icons on the right side of the screen.
/// Should only be used for player-controlled entities.
/// </summary>
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)]
// Component is not AutoNetworked due to supporting clientside-only alerts.
// Component state is handled manually to avoid the server overwriting the client list.
[RegisterComponent, NetworkedComponent]
public sealed partial class AlertsComponent : Component
{
[ViewVariables]
[AutoNetworkedField]
public Dictionary<AlertKey, AlertState> Alerts = new();

public override bool SendOnlyToOwner => true;
}

[Serializable, NetSerializable]
public sealed class AlertComponentState : ComponentState
{
public Dictionary<AlertKey, AlertState> Alerts { get; }
public AlertComponentState(Dictionary<AlertKey, AlertState> alerts)
{
Alerts = alerts;
}
}
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 All @@ -8,6 +9,7 @@
using Robust.Shared.Input;
using Robust.Shared.Input.Binding;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
Expand All @@ -21,6 +23,8 @@ public abstract partial class SharedMoverController
{
public bool CameraRotationLocked { get; set; }

public static ProtoId<AlertPrototype> WalkingAlert = "Walking";

private void InitializeInput()
{
var moveUpCmdHandler = new MoverDirInputCmdHandler(this, Direction.North);
Expand Down Expand Up @@ -460,7 +464,7 @@ private void ResetSubtick(InputMoverComponent component)
component.LastInputSubTick = 0;
}

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

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 @@ -27,6 +27,9 @@ alerts-weightless-desc =
Gravity has ceased affecting you, and you're floating around aimlessly. Find something sturdy to hold onto, or throw or shoot something in a direction opposite of you.
Mag-boots or jetpacks would help you move with more control.

alerts-walking-name = Walking
alerts-walking-desc = You are walking, moving at a slow pace.

alerts-stunned-name = [color=yellow]Stunned[/color]
alerts-stunned-desc = You're [color=yellow]stunned[/color]! Something is impairing your ability to move or interact with objects.

Expand Down
9 changes: 9 additions & 0 deletions Resources/Prototypes/Alerts/alerts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- alertType: Ensnared
- category: Buckled
- alertType: Pulling
- alertType: Walking
- category: Piloting
- alertType: Corporeal
- alertType: Stun
Expand Down Expand Up @@ -126,6 +127,14 @@
name: alerts-weightless-name
description: alerts-weightless-desc

- type: alert
id: Walking
icons:
- sprite: /Textures/Interface/Alerts/walking.rsi
state: walking
name: alerts-walking-name
description: alerts-walking-desc

- type: alert
id: Stun
icons:
Expand Down
14 changes: 14 additions & 0 deletions Resources/Textures/Interface/Alerts/walking.rsi/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "Created by SlamBamActionman",
"size": {
"x": 32,
"y": 32
},
"states": [
{
"name": "walking"
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading