6
StarHorizon_Public/Content.Client/_NF/Atmos/UI/GasDepositScannerWindow.xaml.cs
2026-01-13 18:31:02 +02:00

176 lines
6.5 KiB
C#

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,
});
}
}
}
}