Raise an attempt-event when receiving client BUI messages. (#6113)

This commit is contained in:
Leon Friedrich
2022-01-31 04:26:07 +13:00
committed by GitHub
parent 2208a51a1e
commit 83d29ce38d
4 changed files with 47 additions and 41 deletions

View File

@@ -1,9 +1,11 @@
using System.Linq;
using Content.Server.Administration.Managers;
using Content.Server.Ghost.Components;
using Content.Shared.ActionBlocker;
using Content.Shared.Hands;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Content.Shared.Verbs;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Server.Player;
@@ -30,6 +32,23 @@ namespace Content.Server.UserInterface
// *THIS IS A BLATANT WORKAROUND!* RATIONALE: Microwaves need it
SubscribeLocalEvent<ActivatableUIComponent, EntParentChangedMessage>(OnParentChanged);
SubscribeLocalEvent<ActivatableUIComponent, BoundUIClosedEvent>(OnUIClose);
SubscribeLocalEvent<ActivatableUIComponent, GetActivationVerbsEvent>(AddOpenUiVerb);
}
private void AddOpenUiVerb(EntityUid uid, ActivatableUIComponent component, GetActivationVerbsEvent args)
{
if (!args.CanAccess)
return;
if (!args.CanInteract && !HasComp<GhostComponent>(args.User))
return;
Verb verb = new();
verb.Act = () => InteractUI(args.User, component);
verb.Text = Loc.GetString("ui-verb-toggle-open");
// TODO VERBS add "open UI" icon?
args.Verbs.Add(verb);
}
private void OnActivate(EntityUid uid, ActivatableUIComponent component, ActivateInWorldEvent args)
@@ -63,7 +82,7 @@ namespace Content.Server.UserInterface
if (aui.AdminOnly && !_adminManager.IsAdmin(actor.PlayerSession)) return false;
if (!_actionBlockerSystem.CanInteract(user))
if (!HasComp<GhostComponent>(user) && !_actionBlockerSystem.CanInteract(user))
{
user.PopupMessageCursor(Loc.GetString("base-computer-ui-component-cannot-interact"));
return true;
@@ -103,27 +122,6 @@ namespace Content.Server.UserInterface
RaiseLocalEvent(uid, new ActivatableUIPlayerChangedEvent(), false);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
foreach (var component in EntityManager.EntityQuery<ActivatableUIComponent>(true))
{
var ui = component.UserInterface;
if (ui == null) continue;
// Done to skip an allocation on anything that's not in use.
if (ui.SubscribedSessions.Count == 0) continue;
// Must ToList in order to close things safely.
foreach (var session in ui.SubscribedSessions.ToArray())
{
if (session.AttachedEntity == null || !_actionBlockerSystem.CanInteract(session.AttachedEntity.Value))
{
ui.Close(session);
}
}
}
}
public void CloseAll(EntityUid uid, ActivatableUIComponent? aui = null)
{
if (!Resolve(uid, ref aui, false)) return;