fix gas tank UI (#7135)

This commit is contained in:
Leon Friedrich
2022-03-17 10:30:40 +13:00
committed by GitHub
parent 6109e3f6fa
commit 25cf0eac08
3 changed files with 11 additions and 21 deletions

View File

@@ -1,4 +1,5 @@
using Content.Server.Atmos.Components;
using Content.Server.UserInterface;
using Content.Shared.Actions;
using Content.Shared.Interaction.Events;
using Content.Shared.Toggleable;
@@ -19,12 +20,18 @@ namespace Content.Server.Atmos.EntitySystems
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<GasTankComponent, GetVerbsEvent<ActivationVerb>>(AddOpenUIVerb);
SubscribeLocalEvent<GasTankComponent, BeforeActivatableUIOpenEvent>(BeforeUiOpen);
SubscribeLocalEvent<GasTankComponent, GetActionsEvent>(OnGetActions);
SubscribeLocalEvent<GasTankComponent, ToggleActionEvent>(OnActionToggle);
SubscribeLocalEvent<GasTankComponent, DroppedEvent>(OnDropped);
}
private void BeforeUiOpen(EntityUid uid, GasTankComponent component, BeforeActivatableUIOpenEvent args)
{
// Only initial update includes output pressure information, to avoid overwriting client-input as the updates come in.
component.UpdateUserInterface(true);
}
private void OnDropped(EntityUid uid, GasTankComponent component, DroppedEvent args)
{
component.DisconnectFromInternals(args.User);
@@ -45,18 +52,6 @@ namespace Content.Server.Atmos.EntitySystems
args.Handled = true;
}
private void AddOpenUIVerb(EntityUid uid, GasTankComponent component, GetVerbsEvent<ActivationVerb> args)
{
if (!args.CanAccess || !EntityManager.TryGetComponent<ActorComponent?>(args.User, out var actor))
return;
ActivationVerb verb = new();
verb.Act = () => component.OpenInterface(actor.PlayerSession);
verb.Text = Loc.GetString("control-verb-open-control-panel-text");
// TODO VERBS add "open UI" icon?
args.Verbs.Add(verb);
}
public override void Update(float frameTime)
{
base.Update(frameTime);