From 14b17aff6d9c9f8a61960eb78c99190daf133565 Mon Sep 17 00:00:00 2001 From: Ataman Date: Mon, 19 Jan 2026 23:29:22 +0100 Subject: [PATCH] Add events on animation starts (#6382) * added AnimationStartedEvent * added AnimationStarted event to Control * reordered Control.AnimationStarted above Control.AnimationCompleted * fixed comment * switched to internal constructor and proxy method --- .../EntitySystems/AnimationPlayerSystem.cs | 31 +++++++++++++++++++ .../UserInterface/Control.Animations.cs | 2 ++ 2 files changed, 33 insertions(+) diff --git a/Robust.Client/GameObjects/EntitySystems/AnimationPlayerSystem.cs b/Robust.Client/GameObjects/EntitySystems/AnimationPlayerSystem.cs index 3ae746d59..34b9f5f9f 100644 --- a/Robust.Client/GameObjects/EntitySystems/AnimationPlayerSystem.cs +++ b/Robust.Client/GameObjects/EntitySystems/AnimationPlayerSystem.cs @@ -154,6 +154,9 @@ namespace Robust.Client.GameObjects } ent.Comp.PlayingAnimations.Add(key, playback); + + var startedEvent = new AnimationStartedEvent(ent.Owner, ent.Comp, key); + RaiseLocalEvent(ent.Owner, startedEvent, true); } public bool HasRunningAnimation(EntityUid uid, string key) @@ -199,6 +202,34 @@ namespace Robust.Client.GameObjects } } + /// + /// Raised whenever an animation started playing. + /// + public sealed class AnimationStartedEvent : EntityEventArgs + { + /// + /// The entity associated with the event. + /// + public EntityUid Uid { get; init; } + + /// + /// The animation player component associated with the entity this event was raised on. + /// + public AnimationPlayerComponent AnimationPlayer { get; init; } + + /// + /// The key associated with the animation that was started. + /// + public string Key { get; init; } = string.Empty; + + internal AnimationStartedEvent(EntityUid uid, AnimationPlayerComponent animationPlayer, string key) + { + Uid = uid; + AnimationPlayer = animationPlayer; + Key = key; + } + } + /// /// Raised whenever an animation stops, either due to running its course or being stopped manually. /// diff --git a/Robust.Client/UserInterface/Control.Animations.cs b/Robust.Client/UserInterface/Control.Animations.cs index 0d94d0a15..6169d30fd 100644 --- a/Robust.Client/UserInterface/Control.Animations.cs +++ b/Robust.Client/UserInterface/Control.Animations.cs @@ -12,6 +12,7 @@ namespace Robust.Client.UserInterface { private Dictionary? _playingAnimations; + public Action? AnimationStarted; public Action? AnimationCompleted; /// @@ -27,6 +28,7 @@ namespace Robust.Client.UserInterface _playingAnimations ??= new Dictionary(); _playingAnimations.Add(key, playback); + AnimationStarted?.Invoke(key); } public bool HasRunningAnimation(string key)