From 1e368ae30076606501332f34ab786c14e25c477a Mon Sep 17 00:00:00 2001 From: SlamBamActionman <83650252+SlamBamActionman@users.noreply.github.com> Date: Sat, 9 Nov 2024 01:28:24 +0100 Subject: [PATCH] Add a Walking alert (#32954) * Initial commit * Review feedback changes * ProtoId * TempCommit * First attempt to have client alerts * Review changes --- Content.Client/Alerts/ClientAlertsSystem.cs | 15 ++++++++++----- .../Physics/Controllers/MoverController.cs | 16 ++++++++++++++++ Content.Server/Alert/ServerAlertsSystem.cs | 12 ++++++++++++ Content.Shared/Alert/AlertsComponent.cs | 16 ++++++++++++++-- .../Systems/SharedMoverController.Input.cs | 6 +++++- Resources/Locale/en-US/alerts/alerts.ftl | 3 +++ Resources/Prototypes/Alerts/alerts.yml | 9 +++++++++ .../Interface/Alerts/walking.rsi/meta.json | 14 ++++++++++++++ .../Interface/Alerts/walking.rsi/walking.png | Bin 0 -> 15838 bytes 9 files changed, 83 insertions(+), 8 deletions(-) create mode 100644 Resources/Textures/Interface/Alerts/walking.rsi/meta.json create mode 100644 Resources/Textures/Interface/Alerts/walking.rsi/walking.png diff --git a/Content.Client/Alerts/ClientAlertsSystem.cs b/Content.Client/Alerts/ClientAlertsSystem.cs index 525ef1f018..c5ec254c0c 100644 --- a/Content.Client/Alerts/ClientAlertsSystem.cs +++ b/Content.Client/Alerts/ClientAlertsSystem.cs @@ -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(OnPlayerAttached); SubscribeLocalEvent(OnPlayerDetached); - - SubscribeLocalEvent(ClientAlertsHandleState); + SubscribeLocalEvent(OnHandleState); } protected override void LoadPrototypes() { @@ -47,17 +47,22 @@ public sealed class ClientAlertsSystem : AlertsSystem } } - protected override void AfterShowAlert(Entity alerts) + private void OnHandleState(Entity alerts, ref ComponentHandleState args) { + if (args.Current is not AlertComponentState cast) + return; + + alerts.Comp.Alerts = cast.Alerts; + UpdateHud(alerts); } - protected override void AfterClearAlert(Entity alerts) + protected override void AfterShowAlert(Entity alerts) { UpdateHud(alerts); } - private void ClientAlertsHandleState(Entity alerts, ref AfterAutoHandleStateEvent args) + protected override void AfterClearAlert(Entity alerts) { UpdateHud(alerts); } diff --git a/Content.Client/Physics/Controllers/MoverController.cs b/Content.Client/Physics/Controllers/MoverController.cs index c97110b208..d2ac0cdefd 100644 --- a/Content.Client/Physics/Controllers/MoverController.cs +++ b/Content.Client/Physics/Controllers/MoverController.cs @@ -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 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); + } } diff --git a/Content.Server/Alert/ServerAlertsSystem.cs b/Content.Server/Alert/ServerAlertsSystem.cs index b7b80f7321..5af2b06218 100644 --- a/Content.Server/Alert/ServerAlertsSystem.cs +++ b/Content.Server/Alert/ServerAlertsSystem.cs @@ -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(OnGetState); + } + + private void OnGetState(Entity alerts, ref ComponentGetState args) + { + args.State = new AlertComponentState(alerts.Comp.Alerts); + } } diff --git a/Content.Shared/Alert/AlertsComponent.cs b/Content.Shared/Alert/AlertsComponent.cs index 05b11e19ef..16827e9cdf 100644 --- a/Content.Shared/Alert/AlertsComponent.cs +++ b/Content.Shared/Alert/AlertsComponent.cs @@ -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. /// -[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 Alerts = new(); public override bool SendOnlyToOwner => true; } + +[Serializable, NetSerializable] +public sealed class AlertComponentState : ComponentState +{ + public Dictionary Alerts { get; } + public AlertComponentState(Dictionary alerts) + { + Alerts = alerts; + } +} diff --git a/Content.Shared/Movement/Systems/SharedMoverController.Input.cs b/Content.Shared/Movement/Systems/SharedMoverController.Input.cs index 9dda249423..c11df709f6 100644 --- a/Content.Shared/Movement/Systems/SharedMoverController.Input.cs +++ b/Content.Shared/Movement/Systems/SharedMoverController.Input.cs @@ -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 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 entity, ushort subTick, bool walking) + public virtual void SetSprinting(Entity entity, ushort subTick, bool walking) { // Logger.Info($"[{_gameTiming.CurTick}/{subTick}] Sprint: {enabled}"); diff --git a/Resources/Locale/en-US/alerts/alerts.ftl b/Resources/Locale/en-US/alerts/alerts.ftl index 37af416c3a..1748798bea 100644 --- a/Resources/Locale/en-US/alerts/alerts.ftl +++ b/Resources/Locale/en-US/alerts/alerts.ftl @@ -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. diff --git a/Resources/Prototypes/Alerts/alerts.yml b/Resources/Prototypes/Alerts/alerts.yml index 80fcc44a55..859f223730 100644 --- a/Resources/Prototypes/Alerts/alerts.yml +++ b/Resources/Prototypes/Alerts/alerts.yml @@ -13,6 +13,7 @@ - alertType: Ensnared - category: Buckled - alertType: Pulling + - alertType: Walking - category: Piloting - alertType: Corporeal - alertType: Stun @@ -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: diff --git a/Resources/Textures/Interface/Alerts/walking.rsi/meta.json b/Resources/Textures/Interface/Alerts/walking.rsi/meta.json new file mode 100644 index 0000000000..88238a60e3 --- /dev/null +++ b/Resources/Textures/Interface/Alerts/walking.rsi/meta.json @@ -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 index 0000000000000000000000000000000000000000..a0169368a6051afd1675f6f2cd17a06b7dfa3d4e GIT binary patch literal 15838 zcmeI3e~c968OPtlXwN%ABcx}W8rJ0`2+q#0ox9uV?vm^6;hwN~Jr?eWY3l6EySGzz zXV#tB+vQ5r<45sKt08JCA=*&*qZ%8qS|SPrilSmF#r9eXE!NhW6tO@oDTT(`clPJp zdwXwawQ1VCo9vJ0ectc$%zU2reP;HLd9Z)^T{Bxg-vR)b*%yrrpl^@!ZoUqETBD;E z(bx6a=xPgq*4fUx32b}f7687uRgVwZL$PJDYG!R~+MWa) z){T(&{Jw);kFJHhgHnu(WqV*skB;WxiqYk9b##py(7cPoEy1FU0%V}Ac#4^{Vadgi zw-i@Kznx*$>nTmK*Mz*?PD0O6tl!gP=AcLNbucQ|(dp?7_;{(a)8BcgN8osgaT2dZ}EUBbJR>+&O?X1kQg+jqs5PfEDnB@b30LuxiATVeK zW34r8rN|i8ymF9goCvhkoSwCH)9^TPm4unMLtd|wsP?LyS0-CaWLOn;h$355vMlf8 z*hV5vt!c9PT)K2K1u22x2 ztK5@=if!iNrkM_xS6P1*p{J*(w5mJ{26aO-3)US$7MIlPU5^GMiVed8C-@m2Ek+^E zcgegYOMyk4Aak56NO>j}BW7xPa&3bc5-0P5JBDi}9s}(kO|g}$isGK@ileD=(#&NP zJFI7vVaR5U;UHTdbj_@-D!Io@n>ln?Ff0byM#C;uX{E`1hGi>;3i~2qG~m;9O%?<` zA&F`y6X26cMoaqrOhOS=rb7@FG091iUx6ivv6x#v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