Fix AUI interaction checks (#7130)
This commit is contained in:
@@ -33,6 +33,22 @@ namespace Content.Server.UserInterface
|
|||||||
[DataField("verbText")]
|
[DataField("verbText")]
|
||||||
public string VerbText = "ui-verb-toggle-open";
|
public string VerbText = "ui-verb-toggle-open";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether you need a hand to operate this UI. The hand does not need to be free, you just need to have one.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This should probably be true for most machines & computers, but there will still be UIs that represent a
|
||||||
|
/// more generic interaction / configuration that might not require hands.
|
||||||
|
/// </remarks>
|
||||||
|
[DataField("requireHands")]
|
||||||
|
public bool RequireHands = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether spectators (non-admin ghosts) should be allowed to view this UI.
|
||||||
|
/// </summary>
|
||||||
|
[DataField("allowSpectator")]
|
||||||
|
public bool AllowSpectator = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The client channel currently using the object, or null if there's none/not single user.
|
/// The client channel currently using the object, or null if there's none/not single user.
|
||||||
/// NOTE: DO NOT DIRECTLY SET, USE ActivatableUISystem.SetCurrentSingleUser
|
/// NOTE: DO NOT DIRECTLY SET, USE ActivatableUISystem.SetCurrentSingleUser
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
using Content.Server.Administration.Managers;
|
using Content.Server.Administration.Managers;
|
||||||
using Content.Server.Ghost.Components;
|
using Content.Server.Ghost.Components;
|
||||||
using Content.Shared.Actions;
|
|
||||||
using Content.Shared.Actions.ActionTypes;
|
|
||||||
using Content.Shared.Hands;
|
using Content.Shared.Hands;
|
||||||
|
using Content.Shared.Hands.Components;
|
||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
using Content.Shared.Interaction.Events;
|
using Content.Shared.Interaction.Events;
|
||||||
using Content.Shared.Verbs;
|
using Content.Shared.Verbs;
|
||||||
@@ -28,12 +27,25 @@ namespace Content.Server.UserInterface
|
|||||||
// *THIS IS A BLATANT WORKAROUND!* RATIONALE: Microwaves need it
|
// *THIS IS A BLATANT WORKAROUND!* RATIONALE: Microwaves need it
|
||||||
SubscribeLocalEvent<ActivatableUIComponent, EntParentChangedMessage>(OnParentChanged);
|
SubscribeLocalEvent<ActivatableUIComponent, EntParentChangedMessage>(OnParentChanged);
|
||||||
SubscribeLocalEvent<ActivatableUIComponent, BoundUIClosedEvent>(OnUIClose);
|
SubscribeLocalEvent<ActivatableUIComponent, BoundUIClosedEvent>(OnUIClose);
|
||||||
|
SubscribeLocalEvent<BoundUserInterfaceMessageAttempt>(OnBoundInterfaceInteractAttempt);
|
||||||
|
|
||||||
SubscribeLocalEvent<ActivatableUIComponent, GetVerbsEvent<ActivationVerb>>(AddOpenUiVerb);
|
SubscribeLocalEvent<ActivatableUIComponent, GetVerbsEvent<ActivationVerb>>(AddOpenUiVerb);
|
||||||
|
|
||||||
SubscribeLocalEvent<ServerUserInterfaceComponent, OpenUiActionEvent>(OnActionPerform);
|
SubscribeLocalEvent<ServerUserInterfaceComponent, OpenUiActionEvent>(OnActionPerform);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnBoundInterfaceInteractAttempt(BoundUserInterfaceMessageAttempt ev)
|
||||||
|
{
|
||||||
|
if (!TryComp(ev.Target, out ActivatableUIComponent? comp))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!comp.RequireHands)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!TryComp(ev.Sender.AttachedEntity, out SharedHandsComponent? hands) || hands.Hands.Count == 0)
|
||||||
|
ev.Cancel();
|
||||||
|
}
|
||||||
|
|
||||||
private void OnActionPerform(EntityUid uid, ServerUserInterfaceComponent component, OpenUiActionEvent args)
|
private void OnActionPerform(EntityUid uid, ServerUserInterfaceComponent component, OpenUiActionEvent args)
|
||||||
{
|
{
|
||||||
if (args.Handled || args.Key == null)
|
if (args.Handled || args.Key == null)
|
||||||
@@ -57,7 +69,7 @@ namespace Content.Server.UserInterface
|
|||||||
if (component.InHandsOnly && args.Using != uid)
|
if (component.InHandsOnly && args.Using != uid)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!args.CanInteract && !HasComp<GhostComponent>(args.User))
|
if (!args.CanInteract && (!component.AllowSpectator || !HasComp<GhostComponent>(args.User)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ActivationVerb verb = new();
|
ActivationVerb verb = new();
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
components:
|
components:
|
||||||
- type: Instrument
|
- type: Instrument
|
||||||
- type: ActivatableUI
|
- type: ActivatableUI
|
||||||
|
allowSpectator: false # otherwise they can play client-side music
|
||||||
inHandsOnly: false
|
inHandsOnly: false
|
||||||
singleUser: true
|
singleUser: true
|
||||||
verbText: verb-instrument-openui
|
verbText: verb-instrument-openui
|
||||||
|
|||||||
Reference in New Issue
Block a user