Predicted internals (#33800)

* Predicted gas pumps

I wanted to try out atmos and first thing I found.

* a

* Atmos device prediction

- Canisters
- Tanks
- Internals

AirMixes aren't predicted so nothing on that front but all the UIs should be a lot closer.

* Remove details range

* Gas tank prediction

* Even more sweeping changes

* Alerts

* rehg

* Popup fix

* Fix merge conflicts

* Fix

* Review
This commit is contained in:
metalgearsloth
2025-05-02 18:22:29 +10:00
committed by GitHub
parent d404422b5c
commit bd69fc612a
94 changed files with 1425 additions and 1167 deletions

View File

@@ -12,6 +12,8 @@ namespace Content.Client.UserInterface.Systems.Alerts.Controls
{
public sealed class AlertControl : BaseButton
{
[Dependency] private readonly IEntityManager _entityManager = default!;
public AlertPrototype Alert { get; }
/// <summary>
@@ -33,8 +35,7 @@ namespace Content.Client.UserInterface.Systems.Alerts.Controls
private (TimeSpan Start, TimeSpan End)? _cooldown;
private short? _severity;
private readonly IGameTiming _gameTiming;
private readonly IEntityManager _entityManager;
private readonly SpriteView _icon;
private readonly CooldownGraphic _cooldownGraphic;
@@ -47,8 +48,10 @@ namespace Content.Client.UserInterface.Systems.Alerts.Controls
/// <param name="severity">severity of alert, null if alert doesn't have severity levels</param>
public AlertControl(AlertPrototype alert, short? severity)
{
_gameTiming = IoCManager.Resolve<IGameTiming>();
_entityManager = IoCManager.Resolve<IEntityManager>();
// Alerts will handle this.
MuteSounds = true;
IoCManager.InjectDependencies(this);
TooltipSupplier = SupplyTooltip;
Alert = alert;
_severity = severity;

View File

@@ -1,4 +1,5 @@
using Content.Shared.Atmos.Components;
using Content.Shared.Atmos.EntitySystems;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
@@ -17,7 +18,7 @@ namespace Content.Client.UserInterface.Systems.Atmos.GasTank
public void SetOutputPressure(float value)
{
SendMessage(new GasTankSetPressureMessage
SendPredictedMessage(new GasTankSetPressureMessage
{
Pressure = value
});
@@ -25,13 +26,14 @@ namespace Content.Client.UserInterface.Systems.Atmos.GasTank
public void ToggleInternals()
{
SendMessage(new GasTankToggleInternalsMessage());
SendPredictedMessage(new GasTankToggleInternalsMessage());
}
protected override void Open()
{
base.Open();
_window = this.CreateWindow<GasTankWindow>();
_window.Entity = Owner;
_window.SetTitle(EntMan.GetComponent<MetaDataComponent>(Owner).EntityName);
_window.OnOutputPressure += SetOutputPressure;
_window.OnToggleInternals += ToggleInternals;
@@ -41,6 +43,12 @@ namespace Content.Client.UserInterface.Systems.Atmos.GasTank
{
base.UpdateState(state);
if (EntMan.TryGetComponent(Owner, out GasTankComponent? component))
{
var canConnect = EntMan.System<SharedGasTankSystem>().CanConnectToInternals((Owner, component));
_window?.Update(canConnect, component.IsConnected, component.OutputPressure);
}
if (state is GasTankBoundUserInterfaceState cast)
_window?.UpdateState(cast);
}

View File

@@ -3,11 +3,14 @@ using Content.Client.Message;
using Content.Client.Resources;
using Content.Client.Stylesheets;
using Content.Shared.Atmos.Components;
using Content.Shared.Atmos.EntitySystems;
using Content.Shared.Timing;
using Robust.Client.Graphics;
using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Timing;
using static Robust.Client.UserInterface.Controls.BoxContainer;
namespace Content.Client.UserInterface.Systems.Atmos.GasTank;
@@ -15,6 +18,7 @@ namespace Content.Client.UserInterface.Systems.Atmos.GasTank;
public sealed class GasTankWindow
: BaseWindow
{
[Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly IResourceCache _cache = default!;
private readonly RichTextLabel _lblPressure;
@@ -23,6 +27,8 @@ public sealed class GasTankWindow
private readonly Button _btnInternals;
private readonly Label _topLabel;
public EntityUid Entity;
public event Action<float>? OnOutputPressure;
public event Action? OnToggleInternals;
@@ -194,12 +200,30 @@ public sealed class GasTankWindow
public void UpdateState(GasTankBoundUserInterfaceState state)
{
_lblPressure.SetMarkup(Loc.GetString("gas-tank-window-tank-pressure-text", ("tankPressure", $"{state.TankPressure:0.##}")));
_btnInternals.Disabled = !state.CanConnectInternals;
}
public void Update(bool canConnectInternals, bool internalsConnected, float outputPressure)
{
_btnInternals.Disabled = !canConnectInternals;
_lblInternals.SetMarkup(Loc.GetString("gas-tank-window-internal-text",
("status", Loc.GetString(state.InternalsConnected ? "gas-tank-window-internal-connected" : "gas-tank-window-internal-disconnected"))));
if (state.OutputPressure.HasValue)
("status", Loc.GetString(internalsConnected ? "gas-tank-window-internal-connected" : "gas-tank-window-internal-disconnected"))));
_spbPressure.Value = outputPressure;
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
// Easier than managing state on any ent changes. Previously this was just ticked on server's GasTankSystem.
if (_entManager.TryGetComponent(Entity, out GasTankComponent? tank))
{
_spbPressure.Value = state.OutputPressure.Value;
var canConnectInternals = _entManager.System<SharedGasTankSystem>().CanConnectToInternals((Entity, tank));
_btnInternals.Disabled = !canConnectInternals;
}
if (!_btnInternals.Disabled)
{
_btnInternals.Disabled = _entManager.System<UseDelaySystem>().IsDelayed(Entity, id: SharedGasTankSystem.GasTankDelay);
}
}