Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a scan function to the gas deposit locator #2997

Merged
Merged
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,48 @@
using static Content.Shared._NF.Atmos.Components.GasDepositScannerComponent;

namespace Content.Client._NF.Atmos.UI;

public sealed class GasDepositScannerBoundUserInterface : BoundUserInterface
{
[ViewVariables]
private GasDepositScannerWindow? _window;

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

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

_window = new GasDepositScannerWindow();
_window.OnClose += OnClose;
_window.OpenCenteredLeft();
}

protected override void ReceiveMessage(BoundUserInterfaceMessage message)
{
if (_window == null)
return;
if (message is not GasDepositScannerUserMessage cast)
return;
_window.Populate(cast);
}

/// <summary>
/// Closes UI and tells the server to disable the analyzer
/// </summary>
private void OnClose()
{
SendMessage(new GasDepositScannerDisableMessage());
Close();
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);

if (disposing)
_window?.Dispose();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using Content.Client._NF.Atmos.UI;
using Content.Shared._NF.Atmos.Piping.Binary.Messages;
using Content.Shared.Atmos.Components;
using Content.Shared.Atmos.Piping.Binary.Components;
using Content.Shared.IdentityManagement;
using JetBrains.Annotations;
using Robust.Client.UserInterface;

namespace Content.Client._NF.Atmos.BUI;

/// <summary>
/// Initializes a <see cref="GasPressureBidiPumpWindow"/> and updates it when new server messages are received.
/// </summary>
[UsedImplicitly]
public sealed class GasPressureBidiPumpBoundUserInterface(EntityUid owner, Enum uiKey)
: BoundUserInterface(owner, uiKey)
{
[ViewVariables]
private GasPressureBidiPumpWindow? _window;

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

_window = this.CreateWindow<GasPressureBidiPumpWindow>();

_window.ToggleStatusButtonPressed += OnToggleStatusButtonPressed;
_window.ToggleDirectionButtonPressed += OnToggleDirectionButtonPressed;
_window.PumpOutputPressureChanged += OnPumpOutputPressurePressed;
Update();
}

private void OnToggleStatusButtonPressed()
{
if (_window is null)
return;

SendMessage(new GasPressurePumpToggleStatusMessage(_window.PumpStatus));
}

private void OnToggleDirectionButtonPressed()
{
if (_window is null)
return;

SendMessage(new GasPressurePumpChangePumpDirectionMessage(_window.PumpInwards));
}

private void OnPumpOutputPressurePressed(float value)
{
SendMessage(new GasPressurePumpChangeOutputPressureMessage(value));
}

/// <summary>
/// Update the UI state based on server-sent info
/// </summary>
public override void Update()
{
if (_window == null)
return;

_window.Title = Identity.Name(Owner, EntMan);

if (!EntMan.TryGetComponent(Owner, out GasPressurePumpComponent? pump))
return;

_window.SetPumpStatus(pump.Enabled);
_window.MaxPressure = pump.MaxTargetPressure;
_window.SetOutputPressure(pump.TargetPressure);
_window.SetPumpDirection(pump.PumpingInwards);
}
}
17 changes: 17 additions & 0 deletions Content.Client/_NF/Atmos/UI/GasDepositScannerWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<DefaultWindow xmlns="https://spacestation14.io"
MinSize="270 420"
SetSize="360 420" Title="{Loc 'gas-deposit-scanner-window-name'}">
<BoxContainer Orientation="Vertical" Margin="5 5 5 5">
<BoxContainer Name="TopBox" Orientation="Horizontal"/>
<ScrollContainer VerticalExpand="True">
<BoxContainer HorizontalExpand="True" VerticalExpand="True" Orientation="Vertical">
<SpriteView Name="GridIcon"
MinSize="32 32"
OverrideDirection="North"
RectClipContent="True"/>
<Label Name="MiddlePanelLabel" HorizontalExpand="True" Align="Center"/>
<BoxContainer Name="MiddlePanel" VerticalExpand="True" HorizontalExpand="True" Margin="1 1 1 1" MinSize="315 150" Align="Center" Visible="False"/>
</BoxContainer>
</ScrollContainer>
</BoxContainer>
</DefaultWindow>
175 changes: 175 additions & 0 deletions Content.Client/_NF/Atmos/UI/GasDepositScannerWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
using System.Numerics;
using Content.Client.UserInterface.Controls;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML;
using static Content.Shared._NF.Atmos.Components.GasDepositScannerComponent;

namespace Content.Client._NF.Atmos.UI
{
[GenerateTypedNameReferences]
public sealed partial class GasDepositScannerWindow : DefaultWindow
{
private NetEntity _currentEntity = NetEntity.Invalid;

public GasDepositScannerWindow()
{
RobustXamlLoader.Load(this);
}

public void Populate(GasDepositScannerUserMessage msg)
{
if (msg.Error != null)
{
TopBox.AddChild(new Label
{
Text = Loc.GetString("gas-analyzer-window-error-text", ("errorText", msg.Error)),
FontColorOverride = Color.Red
});
MiddlePanel.Visible = false;
return;
}

if (msg.Gases.Length == 0)
{
TopBox.AddChild(new Label
{
Text = Loc.GetString("gas-analyzer-window-no-data")
});
MiddlePanel.Visible = false;
MinSize = new Vector2(TopBox.DesiredSize.X + 40, MinSize.Y);
return;
}

// Device Tab
if (_currentEntity != msg.DepositUid)
_currentEntity = msg.DepositUid;

GridIcon.SetEntity(IoCManager.Resolve<IEntityManager>().GetEntity(msg.DepositUid));
MiddlePanel.RemoveAllChildren();

MiddlePanelLabel.Text = Loc.GetString("gas-deposit-scanner-window-deposit-title-capitalized");
MiddlePanel.Visible = true;

GenerateGasDisplay(msg.Gases, MiddlePanel);

//MinSize = new Vector2(CDeviceGrid.DesiredSize.X + 40, MinSize.Y);
}

private void GenerateGasDisplay(GasEntry[] gases, Control parent)
{
var panel = new PanelContainer
{
VerticalExpand = true,
HorizontalExpand = true,
Margin = new Thickness(4),
PanelOverride = new StyleBoxFlat { BorderColor = Color.FromHex("#4f4f4f"), BorderThickness = new Thickness(1) }
};
var dataContainer = new BoxContainer { Orientation = BoxContainer.LayoutOrientation.Vertical, VerticalExpand = true, Margin = new Thickness(4) };


parent.AddChild(panel);
panel.AddChild(dataContainer);

// Separator
dataContainer.AddChild(new Control
{
MinSize = new Vector2(0, 10)
});

if (gases == null || gases?.Length == 0)
{
// Add a label that there are no gases so it's less confusing
dataContainer.AddChild(new Label
{
Text = Loc.GetString("gas-analyzer-window-no-gas-text"),
FontColorOverride = Color.Gray
});
// return, everything below is for the fancy gas display stuff
return;
}

// Add a table with all the gases
var tableKey = new BoxContainer
{
Orientation = BoxContainer.LayoutOrientation.Vertical
};
var tableVal = new BoxContainer
{
Orientation = BoxContainer.LayoutOrientation.Vertical,
MinSize = new Vector2(0, 90)
};
dataContainer.AddChild(new BoxContainer
{
Orientation = BoxContainer.LayoutOrientation.Horizontal,
Children =
{
tableKey,
new Control
{
MinSize = new Vector2(10, 0),
HorizontalExpand = true
},
tableVal
}
});
// Separator
dataContainer.AddChild(new Control
{
MinSize = new Vector2(0, 10),
VerticalExpand = true
});

tableKey.AddChild(new Label { Text = Loc.GetString("gas-analyzer-window-gas-column-name"), Align = Label.AlignMode.Center });
tableVal.AddChild(new Label { Text = Loc.GetString("gas-deposit-scanner-window-density-column-name"), Align = Label.AlignMode.Center });

tableKey.AddChild(new StripeBack());
tableVal.AddChild(new StripeBack());

for (var j = 0; j < gases!.Length; j++)
{
var gas = gases[j];
Color densityColor;
string densityText;
switch (gas.Amount)
{
case ApproximateGasDepositSize.Trace:
default:
densityColor = Color.Gray;
densityText = Loc.GetString("gas-deposit-scanner-window-deposit-size-trace");
break;
case ApproximateGasDepositSize.Small:
densityColor = Color.Red;
densityText = Loc.GetString("gas-deposit-scanner-window-deposit-size-small");
break;
case ApproximateGasDepositSize.Medium:
densityColor = Color.Yellow;
densityText = Loc.GetString("gas-deposit-scanner-window-deposit-size-medium");
break;
case ApproximateGasDepositSize.Large:
densityColor = Color.Green;
densityText = Loc.GetString("gas-deposit-scanner-window-deposit-size-large");
break;
case ApproximateGasDepositSize.Enormous:
densityColor = Color.DeepSkyBlue;
densityText = Loc.GetString("gas-deposit-scanner-window-deposit-size-enormous");
break;
}
// Add to the table
tableKey.AddChild(new Label
{
Text = Loc.GetString(gas.Name)
});
tableVal.AddChild(new Label
{
Text = densityText,
FontColorOverride = densityColor,
Align = Label.AlignMode.Right,
});
}
}
}
}

This file was deleted.

Loading
Loading