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>
This commit is contained in:
parent
142f2f54e4
commit
a43a971461
|
|
@ -0,0 +1,18 @@
|
|||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Trigger.Components.Triggers;
|
||||
|
||||
/// <summary>
|
||||
/// Triggers when a user closes a UI belonging to the owning entity.
|
||||
/// The user is the actor that tries to open a UI.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||
public sealed partial class TriggerOnUiCloseComponent : BaseTriggerOnXComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// If it should only work on specific UIs.
|
||||
/// Null means it will work on any UI key.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public HashSet<Enum>? UiKeys;
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Trigger.Components.Triggers;
|
||||
|
||||
/// <summary>
|
||||
/// Triggers when a user opens a UI belonging to the owning entity.
|
||||
/// The user is the actor that tries to open a UI.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||
public sealed partial class TriggerOnUiOpenComponent : BaseTriggerOnXComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// If it should only work on specific UIs.
|
||||
/// Null means it will work on any UI key.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public HashSet<Enum>? UiKeys;
|
||||
}
|
||||
|
|
@ -21,6 +21,9 @@ public sealed partial class TriggerSystem
|
|||
SubscribeLocalEvent<TriggerOnThrowComponent, ThrowEvent>(OnThrow);
|
||||
SubscribeLocalEvent<TriggerOnThrownComponent, ThrownEvent>(OnThrown);
|
||||
|
||||
SubscribeLocalEvent<TriggerOnUiOpenComponent, BoundUIOpenedEvent>(OnUiOpened);
|
||||
SubscribeLocalEvent<TriggerOnUiCloseComponent, BoundUIClosedEvent>(OnUiClosed);
|
||||
|
||||
SubscribeLocalEvent<ItemToggleOnTriggerComponent, TriggerEvent>(HandleItemToggleOnTrigger);
|
||||
SubscribeLocalEvent<AnchorOnTriggerComponent, TriggerEvent>(HandleAnchorOnTrigger);
|
||||
SubscribeLocalEvent<UseDelayOnTriggerComponent, TriggerEvent>(HandleUseDelayOnTrigger);
|
||||
|
|
@ -83,6 +86,22 @@ public sealed partial class TriggerSystem
|
|||
Trigger(ent.Owner, args.User, ent.Comp.KeyOut);
|
||||
}
|
||||
|
||||
private void OnUiOpened(Entity<TriggerOnUiOpenComponent> 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<TriggerOnUiCloseComponent> 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<ItemToggleOnTriggerComponent> ent, ref TriggerEvent args)
|
||||
{
|
||||
if (args.Key != null && !ent.Comp.KeysIn.Contains(args.Key))
|
||||
|
|
|
|||
Loading…
Reference in New Issue