]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add ActionPerformedEvent, ActionsSystem.SetIfBiggerCooldown, action id to action...
authorDrSmugleaf <10968691+DrSmugleaf@users.noreply.github.com>
Sat, 11 May 2024 00:04:01 +0000 (17:04 -0700)
committerGitHub <noreply@github.com>
Sat, 11 May 2024 00:04:01 +0000 (20:04 -0400)
* Add ActionPerformedEvent and ActionsSystem.SetIfBiggerCooldown

* Add action id to action events and backgroundon field to action component

Content.Client/Actions/ActionsSystem.cs
Content.Client/UserInterface/Systems/Actions/ActionUIController.cs
Content.Client/UserInterface/Systems/Actions/Controls/ActionButton.cs
Content.Server/Actions/ActionOnInteractSystem.cs
Content.Shared/Actions/ActionEvents.cs
Content.Shared/Actions/BaseActionComponent.cs
Content.Shared/Actions/Events/ActionPerformedEvent.cs [new file with mode: 0644]
Content.Shared/Actions/SharedActionsSystem.cs

index 5ff003452ab72f822659ee23cd26d730d8ac2ccb..aff6c1ff7be6edb00486cd192a482ec3f7d7ab0c 100644 (file)
@@ -247,7 +247,10 @@ namespace Content.Client.Actions
             if (action.ClientExclusive)
             {
                 if (instantAction.Event != null)
+                {
                     instantAction.Event.Performer = user;
+                    instantAction.Event.Action = actionId;
+                }
 
                 PerformAction(user, actions, actionId, instantAction, instantAction.Event, GameTiming.CurTime);
             }
index 5d9706452c9ea9823daab16a4bb45e6ec65e5911..69ac3ab0230f496aea0cb0df8bc9434f4097693f 100644 (file)
@@ -217,6 +217,7 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
             {
                 action.Event.Target = coords;
                 action.Event.Performer = user;
+                action.Event.Action = actionId;
             }
 
             _actionsSystem.PerformAction(user, actionComp, actionId, action, action.Event, _timing.CurTime);
@@ -251,6 +252,7 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
             {
                 action.Event.Target = entity;
                 action.Event.Performer = user;
+                action.Event.Action = actionId;
             }
 
             _actionsSystem.PerformAction(user, actionComp, actionId, action, action.Event, _timing.CurTime);
index 2cdd4cb79bd6fdcde5d25c3fea53dc526bbff14b..6be41af0d89e25998b1fe2d1b8444af9dafe5c39 100644 (file)
@@ -285,10 +285,19 @@ public sealed class ActionButton : Control, IEntityControl
 
         _controller ??= UserInterfaceManager.GetUIController<ActionUIController>();
         _spriteSys ??= _entities.System<SpriteSystem>();
-        if ((_controller.SelectingTargetFor == ActionId || _action.Toggled) && _action.IconOn != null)
-            SetActionIcon(_spriteSys.Frame0(_action.IconOn));
+        if ((_controller.SelectingTargetFor == ActionId || _action.Toggled))
+        {
+            if (_action.IconOn != null)
+                SetActionIcon(_spriteSys.Frame0(_action.IconOn));
+
+            if (_action.BackgroundOn != null)
+                _buttonBackgroundTexture = _spriteSys.Frame0(_action.BackgroundOn);
+        }
         else
+        {
             SetActionIcon(_action.Icon != null ? _spriteSys.Frame0(_action.Icon) : null);
+            _buttonBackgroundTexture = Theme.ResolveTexture("SlotBackground");
+        }
     }
 
     public void UpdateBackground()
index eb35d411962c2a8946e1a1def5121e9376dc3d99..657ab46d60ca8d8c8b95d8dca0caf320944912b2 100644 (file)
@@ -47,7 +47,10 @@ public sealed class ActionOnInteractSystem : EntitySystem
 
         var (actId, act) = _random.Pick(options);
         if (act.Event != null)
+        {
             act.Event.Performer = args.User;
+            act.Event.Action = actId;
+        }
 
         _actions.PerformAction(args.User, null, actId, act, act.Event, _timing.CurTime, false);
         args.Handled = true;
@@ -75,6 +78,7 @@ public sealed class ActionOnInteractSystem : EntitySystem
                 if (entAct.Event != null)
                 {
                     entAct.Event.Performer = args.User;
+                    entAct.Event.Action = entActId;
                     entAct.Event.Target = args.Target.Value;
                 }
 
@@ -100,6 +104,7 @@ public sealed class ActionOnInteractSystem : EntitySystem
         if (act.Event != null)
         {
             act.Event.Performer = args.User;
+            act.Event.Action = actId;
             act.Event.Target = args.ClickLocation;
         }
 
index cddb70f74d2afe8a223559f0d83ec92856f6e669..c6002d0d4ad370454400b3f760d41ce6077ebf65 100644 (file)
@@ -155,4 +155,9 @@ public abstract partial class BaseActionEvent : HandledEntityEventArgs
     ///     The user performing the action.
     /// </summary>
     public EntityUid Performer;
+
+    /// <summary>
+    ///     The action that was performed.
+    /// </summary>
+    public EntityUid Action;
 }
index 6d9242acc1da35e77267566fd56c1e3ebd5e00ab..57c145a0ecf3c6300d5243c37238017dd4e740a6 100644 (file)
@@ -1,5 +1,4 @@
-using Content.Shared.Mobs;
-using Robust.Shared.Audio;
+using Robust.Shared.Audio;
 using Robust.Shared.Serialization;
 using Robust.Shared.Utility;
 
@@ -25,6 +24,11 @@ public abstract partial class BaseActionComponent : Component
     /// </summary>
     [DataField("iconOn")] public SpriteSpecifier? IconOn;
 
+    /// <summary>
+    ///     For toggle actions only, background to show when toggled on.
+    /// </summary>
+    [DataField] public SpriteSpecifier? BackgroundOn;
+
     /// <summary>
     ///     If not null, this color will modulate the action icon color.
     /// </summary>
diff --git a/Content.Shared/Actions/Events/ActionPerformedEvent.cs b/Content.Shared/Actions/Events/ActionPerformedEvent.cs
new file mode 100644 (file)
index 0000000..530d7c9
--- /dev/null
@@ -0,0 +1,8 @@
+namespace Content.Shared.Actions.Events;
+
+/// <summary>
+///     Raised on the action entity when it is used and <see cref="BaseActionEvent.Handled"/>.
+/// </summary>
+/// <param name="Performer">The entity that performed this action.</param>
+[ByRefEvent]
+public readonly record struct ActionPerformedEvent(EntityUid Performer);
index e1b76f517e46ecf17ee0d479af76d07584c17142..315d2725b2e268e57293ec2f96129494fcbd05b5 100644 (file)
@@ -144,9 +144,6 @@ public abstract class SharedActionsSystem : EntitySystem
 
     public void SetCooldown(EntityUid? actionId, TimeSpan start, TimeSpan end)
     {
-        if (actionId == null)
-            return;
-
         if (!TryGetActionData(actionId, out var action))
             return;
 
@@ -162,9 +159,6 @@ public abstract class SharedActionsSystem : EntitySystem
 
     public void ClearCooldown(EntityUid? actionId)
     {
-        if (actionId == null)
-            return;
-
         if (!TryGetActionData(actionId, out var action))
             return;
 
@@ -175,6 +169,27 @@ public abstract class SharedActionsSystem : EntitySystem
         Dirty(actionId.Value, action);
     }
 
+    /// <summary>
+    ///     Sets the cooldown for this action only if it is bigger than the one it already has.
+    /// </summary>
+    public void SetIfBiggerCooldown(EntityUid? actionId, TimeSpan? cooldown)
+    {
+        if (cooldown == null ||
+            cooldown.Value <= TimeSpan.Zero ||
+            !TryGetActionData(actionId, out var action))
+        {
+            return;
+        }
+
+        var start = GameTiming.CurTime;
+        var end = start + cooldown;
+        if (action.Cooldown?.End > end)
+            return;
+
+        action.Cooldown = (start, end.Value);
+        Dirty(actionId.Value, action);
+    }
+
     public void StartUseDelay(EntityUid? actionId)
     {
         if (actionId == null)
@@ -438,7 +453,10 @@ public abstract class SharedActionsSystem : EntitySystem
         }
 
         if (performEvent != null)
+        {
             performEvent.Performer = user;
+            performEvent.Action = actionEnt;
+        }
 
         // All checks passed. Perform the action!
         PerformAction(user, component, actionEnt, action, performEvent, curTime);
@@ -580,6 +598,9 @@ public abstract class SharedActionsSystem : EntitySystem
 
         if (dirty && component != null)
             Dirty(performer, component);
+
+        var ev = new ActionPerformedEvent(performer);
+        RaiseLocalEvent(actionId, ref ev);
     }
     #endregion