From: sleepyyapril <123355664+sleepyyapril@users.noreply.github.com> Date: Sun, 7 Dec 2025 19:54:10 +0000 (-0400) Subject: TriggerOnUiOpen/Close (#41718) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=5c70d28927836a7bb671547bac2ea2230c0477a4;p=space-station-14.git TriggerOnUiOpen/Close (#41718) * feat: TriggerOnUiOpen/Close * chore: minor clarification * Update Content.Shared/Trigger/Components/Triggers/TriggerOnUiCloseComponent.cs Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * Update Content.Shared/Trigger/Components/Triggers/TriggerOnUiOpenComponent.cs Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * chore: review --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> --- diff --git a/Content.Shared/Trigger/Components/Triggers/TriggerOnUiCloseComponent.cs b/Content.Shared/Trigger/Components/Triggers/TriggerOnUiCloseComponent.cs new file mode 100644 index 0000000000..695f2965e1 --- /dev/null +++ b/Content.Shared/Trigger/Components/Triggers/TriggerOnUiCloseComponent.cs @@ -0,0 +1,18 @@ +using Robust.Shared.GameStates; + +namespace Content.Shared.Trigger.Components.Triggers; + +/// +/// Triggers when a user closes a UI belonging to the owning entity. +/// The user is the actor that tries to open a UI. +/// +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] +public sealed partial class TriggerOnUiCloseComponent : BaseTriggerOnXComponent +{ + /// + /// If it should only work on specific UIs. + /// Null means it will work on any UI key. + /// + [DataField, AutoNetworkedField] + public HashSet? UiKeys; +} diff --git a/Content.Shared/Trigger/Components/Triggers/TriggerOnUiOpenComponent.cs b/Content.Shared/Trigger/Components/Triggers/TriggerOnUiOpenComponent.cs new file mode 100644 index 0000000000..bf83b7e996 --- /dev/null +++ b/Content.Shared/Trigger/Components/Triggers/TriggerOnUiOpenComponent.cs @@ -0,0 +1,18 @@ +using Robust.Shared.GameStates; + +namespace Content.Shared.Trigger.Components.Triggers; + +/// +/// Triggers when a user opens a UI belonging to the owning entity. +/// The user is the actor that tries to open a UI. +/// +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] +public sealed partial class TriggerOnUiOpenComponent : BaseTriggerOnXComponent +{ + /// + /// If it should only work on specific UIs. + /// Null means it will work on any UI key. + /// + [DataField, AutoNetworkedField] + public HashSet? UiKeys; +} diff --git a/Content.Shared/Trigger/Systems/TriggerSystem.Interaction.cs b/Content.Shared/Trigger/Systems/TriggerSystem.Interaction.cs index 62f483e876..944239ccf8 100644 --- a/Content.Shared/Trigger/Systems/TriggerSystem.Interaction.cs +++ b/Content.Shared/Trigger/Systems/TriggerSystem.Interaction.cs @@ -21,6 +21,9 @@ public sealed partial class TriggerSystem SubscribeLocalEvent(OnThrow); SubscribeLocalEvent(OnThrown); + SubscribeLocalEvent(OnUiOpened); + SubscribeLocalEvent(OnUiClosed); + SubscribeLocalEvent(HandleItemToggleOnTrigger); SubscribeLocalEvent(HandleAnchorOnTrigger); SubscribeLocalEvent(HandleUseDelayOnTrigger); @@ -83,6 +86,22 @@ public sealed partial class TriggerSystem Trigger(ent.Owner, args.User, ent.Comp.KeyOut); } + private void OnUiOpened(Entity ent, ref BoundUIOpenedEvent args) + { + if (ent.Comp.UiKeys == null || ent.Comp.UiKeys.Contains(args.UiKey)) + { + Trigger(ent, args.Actor, ent.Comp.KeyOut); + } + } + + private void OnUiClosed(Entity ent, ref BoundUIClosedEvent args) + { + if (ent.Comp.UiKeys == null || ent.Comp.UiKeys.Contains(args.UiKey)) + { + Trigger(ent, args.Actor, ent.Comp.KeyOut); + } + } + private void HandleItemToggleOnTrigger(Entity ent, ref TriggerEvent args) { if (args.Key != null && !ent.Comp.KeysIn.Contains(args.Key))