Adds the NetProbe cartridge (#12543)

* Implement NetProbeCartridge

* Add audio and a popup when scanning a device
Add some doc comments

* Set program icon

* Add NetProbe cartridge as rare loot to maintenance loot tool spawner

* Make the maximum amount of saved entries configurable
Add a scrollbar that shows when there are more entries than fit on the screen

* Make device net id names translatable
This commit is contained in:
Julian Giebel
2022-11-13 22:36:00 +01:00
committed by GitHub
parent 4ec37c8bc0
commit 0df65e5c2a
11 changed files with 341 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
using Content.Shared.CartridgeLoader.Cartridges;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
namespace Content.Client.CartridgeLoader.Cartridges;
public sealed class NetProbeUi : CartridgeUI
{
private NetProbeUiFragment? _fragment;
public override Control GetUIFragmentRoot()
{
return _fragment!;
}
public override void Setup(BoundUserInterface userInterface)
{
_fragment = new NetProbeUiFragment();
}
public override void UpdateState(BoundUserInterfaceState state)
{
if (state is not NetProbeUiState netProbeUiState)
return;
_fragment?.UpdateState(netProbeUiState.ProbedDevices);
}
}

View File

@@ -0,0 +1,19 @@
<cartridges:NetProbeUiFragment xmlns:cartridges="clr-namespace:Content.Client.CartridgeLoader.Cartridges"
xmlns="https://spacestation14.io" Margin="1 0 2 0">
<PanelContainer StyleClasses="BackgroundDark"></PanelContainer>
<BoxContainer Orientation="Vertical" HorizontalExpand="True" VerticalExpand="True">
<BoxContainer Orientation="Vertical" MinHeight="32" MaxHeight="32" VerticalAlignment="Top" Margin="3 0">
<PanelContainer Name="HeaderPanel">
<BoxContainer Orientation="Horizontal" HorizontalExpand="True" Margin="4">
<Label HorizontalExpand="True" Text="Name"/>
<Label HorizontalExpand="True" Text="Address"/>
<Label HorizontalExpand="True" Text="Frequency"/>
<Label HorizontalExpand="True" Text="Network"/>
</BoxContainer>
</PanelContainer>
</BoxContainer>
<ScrollContainer Name="ScrollContainer" HorizontalExpand="True" VerticalExpand="True">
<BoxContainer Orientation="Vertical" Name="ProbedDeviceContainer" HorizontalExpand="True" VerticalExpand="True" VerticalAlignment="Top" Margin="3 0"/>
</ScrollContainer>
</BoxContainer>
</cartridges:NetProbeUiFragment>

View File

@@ -0,0 +1,77 @@
using Content.Shared.CartridgeLoader.Cartridges;
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
namespace Content.Client.CartridgeLoader.Cartridges;
[GenerateTypedNameReferences]
public sealed partial class NetProbeUiFragment : BoxContainer
{
private readonly StyleBoxFlat _styleBox = new()
{
BackgroundColor = Color.Transparent,
BorderColor = Color.FromHex("#5a5a5a"),
BorderThickness = new Thickness(0, 0, 0, 1)
};
public NetProbeUiFragment()
{
RobustXamlLoader.Load(this);
Orientation = LayoutOrientation.Vertical;
HorizontalExpand = true;
VerticalExpand = true;
HeaderPanel.PanelOverride = _styleBox;
}
public void UpdateState(List<ProbedNetworkDevice> devices)
{
ProbedDeviceContainer.RemoveAllChildren();
//Reverse the list so the oldest entries appear at the bottom
devices.Reverse();
//Enable scrolling if there are more entries that can fit on the screen
ScrollContainer.HScrollEnabled = devices.Count > 9;
foreach (var device in devices)
{
AddProbedDevice(device);
}
}
private void AddProbedDevice(ProbedNetworkDevice device)
{
var row = new BoxContainer();
row.HorizontalExpand = true;
row.Orientation = LayoutOrientation.Horizontal;
row.Margin = new Thickness(4);
var nameLabel = new Label();
nameLabel.Text = device.Name;
nameLabel.HorizontalExpand = true;
nameLabel.ClipText = true;
row.AddChild(nameLabel);
var addressLabel = new Label();
addressLabel.Text = device.Address;
addressLabel.HorizontalExpand = true;
addressLabel.ClipText = true;
row.AddChild(addressLabel);
var frequencyLabel = new Label();
frequencyLabel.Text = device.Frequency;
frequencyLabel.HorizontalExpand = true;
frequencyLabel.ClipText = true;
row.AddChild(frequencyLabel);
var networkLabel = new Label();
networkLabel.Text = device.NetId;
networkLabel.HorizontalExpand = true;
networkLabel.ClipText = true;
row.AddChild(networkLabel);
ProbedDeviceContainer.AddChild(row);
}
}