Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Content.Shared.Atmos.Piping.Trinary.Components;
using Content.Shared.Atmos.Piping.Trinary.EntitySystems;
using Robust.Client.GameObjects;

namespace Content.Client.Atmos.Piping.Trinary.EntitySystems;

public sealed class GasFilterSystem : SharedGasFilterSystem
{
[Dependency] private readonly UserInterfaceSystem _ui = default!;

public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<GasFilterComponent, AfterAutoHandleStateEvent>(OnFilterState);
}

protected override void UpdateUi(Entity<GasFilterComponent> ent)
{
if (_ui.TryGetOpenUi(ent.Owner, GasFilterUiKey.Key, out var bui))
bui.Update();
}

private void OnFilterState(Entity<GasFilterComponent> ent, ref AfterAutoHandleStateEvent args)
{
UpdateUi(ent);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Content.Shared.Atmos.Piping.Trinary.Components;
using Content.Shared.Atmos.Piping.Trinary.EntitySystems;
using Robust.Client.GameObjects;

namespace Content.Client.Atmos.Piping.Trinary.EntitySystems;

public sealed class GasMixerSystem : SharedGasMixerSystem
{
[Dependency] private readonly UserInterfaceSystem _ui = default!;

public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<GasMixerComponent, AfterAutoHandleStateEvent>(OnMixerState);
}

protected override void UpdateUi(Entity<GasMixerComponent> ent)
{
if (_ui.TryGetOpenUi(ent.Owner, GasMixerUiKey.Key, out var bui))
bui.Update();
}

private void OnMixerState(Entity<GasMixerComponent> ent, ref AfterAutoHandleStateEvent args)
{
UpdateUi(ent);
}
}
135 changes: 61 additions & 74 deletions Content.Client/Atmos/UI/GasFilterBoundUserInterface.cs
Original file line number Diff line number Diff line change
@@ -1,103 +1,90 @@
using Content.Client.Atmos.EntitySystems;
using Content.Client.Atmos.EntitySystems;
using Content.Shared.Atmos;
using Content.Shared.Atmos.Piping.Trinary.Components;
using Content.Shared.Localizations;
using JetBrains.Annotations;
using Robust.Client.UserInterface;

namespace Content.Client.Atmos.UI
namespace Content.Client.Atmos.UI;

/// <summary>
/// Initializes a <see cref="GasFilterWindow"/> and updates it from the entity's <see cref="GasFilterComponent"/>.
/// </summary>
[UsedImplicitly]
public sealed class GasFilterBoundUserInterface : BoundUserInterface
{
/// <summary>
/// Initializes a <see cref="GasFilterWindow"/> and updates it when new server messages are received.
/// </summary>
[UsedImplicitly]
public sealed class GasFilterBoundUserInterface : BoundUserInterface
[Dependency] private readonly AtmosphereSystem _atmosphere = default!;

[ViewVariables]
private GasFilterWindow? _window;

public GasFilterBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
[ViewVariables]
private const float MaxTransferRate = Atmospherics.MaxTransferRate;
}

[ViewVariables]
private GasFilterWindow? _window;
protected override void Open()
{
base.Open();

public GasFilterBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}
_window = this.CreateWindow<GasFilterWindow>();
_window.PopulateGasList(_atmosphere.Gases);

protected override void Open()
{
base.Open();
_window.ToggleStatusButtonPressed += OnToggleStatusButtonPressed;
_window.FilterTransferRateChanged += OnFilterTransferRatePressed;
_window.SelectGasPressed += OnSelectGasPressed;

var atmosSystem = EntMan.System<AtmosphereSystem>();
Update();
}

_window = this.CreateWindow<GasFilterWindow>();
_window.PopulateGasList(atmosSystem.Gases);
private void OnToggleStatusButtonPressed(bool status)
{
SendPredictedMessage(new GasFilterToggleStatusMessage(status));
}

_window.ToggleStatusButtonPressed += OnToggleStatusButtonPressed;
_window.FilterTransferRateChanged += OnFilterTransferRatePressed;
_window.SelectGasPressed += OnSelectGasPressed;
}
private void OnFilterTransferRatePressed(string value)
{
var rate = UserInputParser.TryFloat(value, out var parsed) ? parsed : 0f;

private void OnToggleStatusButtonPressed(bool status)
{
SendMessage(new GasFilterToggleStatusMessage(status));
}
SendPredictedMessage(new GasFilterChangeRateMessage(rate));
}

private void OnFilterTransferRatePressed(string value)
{
var rate = UserInputParser.TryFloat(value, out var parsed) ? parsed : 0f;
private void OnSelectGasPressed()
{
if (_window is null)
return;

SendMessage(new GasFilterChangeRateMessage(rate));
if (_window.SelectedGas is null)
{
SendPredictedMessage(new GasFilterSelectGasMessage(null));
}

private void OnSelectGasPressed()
else
{
if (_window is null)
if (!Enum.TryParse<Gas>(_window.SelectedGas, out var gas))
return;

if (_window.SelectedGas is null)
{
SendMessage(new GasFilterSelectGasMessage(null));
}
else
{
if (!Enum.TryParse<Gas>(_window.SelectedGas, out var gas))
return;

SendMessage(new GasFilterSelectGasMessage(gas));
}
SendPredictedMessage(new GasFilterSelectGasMessage(gas));
}
}

/// <summary>
/// Update the UI state based on server-sent info
/// </summary>
/// <param name="state"></param>
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
if (_window == null || state is not GasFilterBoundUserInterfaceState cast)
return;
public override void Update()
{
base.Update();

_window.Title = (cast.FilterLabel);
_window.SetFilterStatus(cast.Enabled);
_window.SetTransferRate(cast.TransferRate);
if (cast.FilteredGas is not null)
{
var atmos = EntMan.System<AtmosphereSystem>();
var gas = atmos.GetGas((Gas) cast.FilteredGas);
var gasName = Loc.GetString(gas.Name);
_window.SetGasFiltered(gas.ID, gasName);
}
else
{
_window.SetGasFiltered(null, Loc.GetString("comp-gas-filter-ui-filter-gas-none"));
}
}
if (_window == null || !EntMan.TryGetComponent(Owner, out GasFilterComponent? filter))
return;

protected override void Dispose(bool disposing)
_window.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName;
_window.SetFilterStatus(filter.Enabled);
_window.SetTransferRate(filter.TransferRate);

if (filter.FilteredGas is { } filtered)
{
var gas = _atmosphere.GetGas(filtered);
_window.SetGasFiltered(gas.ID, Loc.GetString(gas.Name));
}
else
{
base.Dispose(disposing);
if (!disposing) return;
_window?.Dispose();
_window.SetGasFiltered(null, Loc.GetString("comp-gas-filter-ui-filter-gas-none"));
}
}
}
79 changes: 0 additions & 79 deletions Content.Client/Atmos/UI/GasMixerBoundUserInteface.cs

This file was deleted.

71 changes: 71 additions & 0 deletions Content.Client/Atmos/UI/GasMixerBoundUserInterface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using Content.Shared.Atmos.Piping.Trinary.Components;
using Content.Shared.Localizations;
using JetBrains.Annotations;
using Robust.Client.UserInterface;

namespace Content.Client.Atmos.UI;

/// <summary>
/// Initializes a <see cref="GasMixerWindow"/> and updates it from the entity's <see cref="GasMixerComponent"/>.
/// </summary>
[UsedImplicitly]
public sealed class GasMixerBoundUserInterface : BoundUserInterface
{
[ViewVariables]
private GasMixerWindow? _window;

public GasMixerBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}

protected override void Open()
{
base.Open();

_window = this.CreateWindow<GasMixerWindow>();

_window.ToggleStatusButtonPressed += OnToggleStatusButtonPressed;
_window.MixerOutputPressureChanged += OnMixerOutputPressurePressed;
_window.MixerNodePercentageChanged += OnMixerSetPercentagePressed;

Update();
}

private void OnToggleStatusButtonPressed(bool status)
{
SendPredictedMessage(new GasMixerToggleStatusMessage(status));
}

private void OnMixerOutputPressurePressed(string value)
{
var pressure = UserInputParser.TryFloat(value, out var parsed) ? parsed : 0f;

SendPredictedMessage(new GasMixerChangeOutputPressureMessage(pressure));
}

private void OnMixerSetPercentagePressed(string value)
{
// We don't need to send both nodes because it's just 100.0f - node
var node = UserInputParser.TryFloat(value, out var parsed) ? parsed : 1.0f;

node = Math.Clamp(node, 0f, 100.0f);

if (_window is not null)
node = _window.NodeOneLastEdited ? node : 100.0f - node;

SendPredictedMessage(new GasMixerChangeNodePercentageMessage(node));
}

public override void Update()
{
base.Update();

if (_window == null || !EntMan.TryGetComponent(Owner, out GasMixerComponent? mixer))
return;

_window.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName;
_window.SetMixerStatus(mixer.Enabled);
_window.SetOutputPressure(mixer.TargetPressure);
_window.SetNodePercentages(mixer.InletOneConcentration);
}
}
Loading
Loading