From: SlamBamActionman <83650252+SlamBamActionman@users.noreply.github.com> Date: Sat, 9 Nov 2024 00:28:24 +0000 (+0100) Subject: Add a Walking alert (#32954) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=1e368ae30076606501332f34ab786c14e25c477a;p=space-station-14.git Add a Walking alert (#32954) * Initial commit * Review feedback changes * ProtoId * TempCommit * First attempt to have client alerts * Review changes --- 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 0000000000..a0169368a6 Binary files /dev/null and b/Resources/Textures/Interface/Alerts/walking.rsi/walking.png differ