]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add a Walking alert (#32954)
authorSlamBamActionman <83650252+SlamBamActionman@users.noreply.github.com>
Sat, 9 Nov 2024 00:28:24 +0000 (01:28 +0100)
committerGitHub <noreply@github.com>
Sat, 9 Nov 2024 00:28:24 +0000 (18:28 -0600)
* Initial commit

* Review feedback changes

* ProtoId

* TempCommit

* First attempt to have client alerts

* Review changes

Content.Client/Alerts/ClientAlertsSystem.cs
Content.Client/Physics/Controllers/MoverController.cs
Content.Server/Alert/ServerAlertsSystem.cs
Content.Shared/Alert/AlertsComponent.cs
Content.Shared/Movement/Systems/SharedMoverController.Input.cs
Resources/Locale/en-US/alerts/alerts.ftl
Resources/Prototypes/Alerts/alerts.yml
Resources/Textures/Interface/Alerts/walking.rsi/meta.json [new file with mode: 0644]
Resources/Textures/Interface/Alerts/walking.rsi/walking.png [new file with mode: 0644]

index 525ef1f018fc9c4b1bd0eda9b12e9229c312ff61..c5ec254c0ccc5e05b1209480675a63d3cb9edddb 100644 (file)
@@ -2,6 +2,7 @@ using System.Linq;
 using Content.Shared.Alert;
 using JetBrains.Annotations;
 using Robust.Client.Player;
+using Robust.Shared.GameStates;
 using Robust.Shared.Player;
 using Robust.Shared.Prototypes;
 
@@ -24,8 +25,7 @@ public sealed class ClientAlertsSystem : AlertsSystem
 
         SubscribeLocalEvent<AlertsComponent, LocalPlayerAttachedEvent>(OnPlayerAttached);
         SubscribeLocalEvent<AlertsComponent, LocalPlayerDetachedEvent>(OnPlayerDetached);
-
-        SubscribeLocalEvent<AlertsComponent, AfterAutoHandleStateEvent>(ClientAlertsHandleState);
+        SubscribeLocalEvent<AlertsComponent, ComponentHandleState>(OnHandleState);
     }
     protected override void LoadPrototypes()
     {
@@ -47,17 +47,22 @@ public sealed class ClientAlertsSystem : AlertsSystem
         }
     }
 
-    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);
     }
index c97110b208e58f22fb461d97c89db76176156b72..d2ac0cdefdc1312f0a4a48bb05a50f6c97bcdd35 100644 (file)
@@ -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;
@@ -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()
     {
@@ -135,4 +140,15 @@ public sealed class MoverController : SharedMoverController
     {
         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);
+    }
 }
index b7b80f732105b1561ec2638b83655251eb831831..5af2b0621883ba616d43d5decb6ec1abc3580301 100644 (file)
@@ -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);
+    }
 }
index 05b11e19efbaa5f80cbd1c0f998ec14d0dc5e71e..16827e9cdff1f3cf24303a5faf4dfe210661ea24 100644 (file)
@@ -1,4 +1,5 @@
 using Robust.Shared.GameStates;
+using Robust.Shared.Serialization;
 
 namespace Content.Shared.Alert;
 
@@ -6,12 +7,23 @@ namespace Content.Shared.Alert;
 ///     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;
+    }
+}
index 9dda249423e2e069a1265bc3265aab54b6d55493..c11df709f631ba14b22ef14ce859c135ce46c9b5 100644 (file)
@@ -1,4 +1,5 @@
 using System.Numerics;
+using Content.Shared.Alert;
 using Content.Shared.CCVar;
 using Content.Shared.Follower.Components;
 using Content.Shared.Input;
@@ -8,6 +9,7 @@ using Robust.Shared.GameStates;
 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;
@@ -21,6 +23,8 @@ namespace Content.Shared.Movement.Systems
     {
         public bool CameraRotationLocked { get; set; }
 
+        public static ProtoId<AlertPrototype> WalkingAlert = "Walking";
+
         private void InitializeInput()
         {
             var moveUpCmdHandler = new MoverDirInputCmdHandler(this, Direction.North);
@@ -460,7 +464,7 @@ namespace Content.Shared.Movement.Systems
             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}");
 
index 37af416c3a1758f1af456959f7fa933e8fbbf2f2..1748798beaef34bb43d16848408cb676e43c790f 100644 (file)
@@ -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.
 
index 80fcc44a559e02e478703ba685c1455e8064cfac..859f223730bad56b618561ea02f5e26fcdcf3f30 100644 (file)
@@ -13,6 +13,7 @@
     - alertType: Ensnared
     - category: Buckled
     - alertType: Pulling
+    - alertType: Walking
     - category: Piloting
     - alertType: Corporeal
     - alertType: Stun
   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:
diff --git a/Resources/Textures/Interface/Alerts/walking.rsi/meta.json b/Resources/Textures/Interface/Alerts/walking.rsi/meta.json
new file mode 100644 (file)
index 0000000..88238a6
--- /dev/null
@@ -0,0 +1,14 @@
+{
+    "version": 1,
+    "license": "CC-BY-SA-3.0",
+    "copyright": "Created by SlamBamActionman",
+    "size": {
+        "x": 32,
+        "y": 32
+    },
+    "states": [
+        {
+            "name": "walking"
+        }
+    ]
+}
diff --git a/Resources/Textures/Interface/Alerts/walking.rsi/walking.png b/Resources/Textures/Interface/Alerts/walking.rsi/walking.png
new file mode 100644 (file)
index 0000000..a016936
Binary files /dev/null and b/Resources/Textures/Interface/Alerts/walking.rsi/walking.png differ