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,4 @@
using Content.Shared.Atmos.Components; using Content.Shared.Atmos.Components;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
@@ -38,7 +38,8 @@ namespace Content.Client.UserInterface.Atmos.GasTank
{ {
base.UpdateState(state); base.UpdateState(state);
_window?.UpdateState((GasTankBoundUserInterfaceState) state); if (state is GasTankBoundUserInterfaceState cast)
_window?.UpdateState(cast);
} }
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)

View File

@@ -91,12 +91,6 @@ namespace Content.Server.Atmos.Components
} }
} }
public void OpenInterface(IPlayerSession session)
{
_userInterface?.Open(session);
UpdateUserInterface(true);
}
public void Examine(FormattedMessage message, bool inDetailsRange) public void Examine(FormattedMessage message, bool inDetailsRange)
{ {
message.AddMarkup(Loc.GetString("comp-gas-tank-examine", ("pressure", Math.Round(Air?.Pressure ?? 0)))); message.AddMarkup(Loc.GetString("comp-gas-tank-examine", ("pressure", Math.Round(Air?.Pressure ?? 0))));

View File

@@ -1,4 +1,5 @@
using Content.Server.Atmos.Components; using Content.Server.Atmos.Components;
using Content.Server.UserInterface;
using Content.Shared.Actions; using Content.Shared.Actions;
using Content.Shared.Interaction.Events; using Content.Shared.Interaction.Events;
using Content.Shared.Toggleable; using Content.Shared.Toggleable;
@@ -19,12 +20,18 @@ namespace Content.Server.Atmos.EntitySystems
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
SubscribeLocalEvent<GasTankComponent, GetVerbsEvent<ActivationVerb>>(AddOpenUIVerb); SubscribeLocalEvent<GasTankComponent, BeforeActivatableUIOpenEvent>(BeforeUiOpen);
SubscribeLocalEvent<GasTankComponent, GetActionsEvent>(OnGetActions); SubscribeLocalEvent<GasTankComponent, GetActionsEvent>(OnGetActions);
SubscribeLocalEvent<GasTankComponent, ToggleActionEvent>(OnActionToggle); SubscribeLocalEvent<GasTankComponent, ToggleActionEvent>(OnActionToggle);
SubscribeLocalEvent<GasTankComponent, DroppedEvent>(OnDropped); 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) private void OnDropped(EntityUid uid, GasTankComponent component, DroppedEvent args)
{ {
component.DisconnectFromInternals(args.User); component.DisconnectFromInternals(args.User);
@@ -45,18 +52,6 @@ namespace Content.Server.Atmos.EntitySystems
args.Handled = true; 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) public override void Update(float frameTime)
{ {
base.Update(frameTime); base.Update(frameTime);