Files
tbd-station-14/Content.Client/NetworkConfigurator/NetworkConfiguratorDeviceList.xaml.cs
metalgearsloth cbf329a82d Remove some BUI boilerplate (#28399)
* Remove some BUI boilerplate

- The disposals overrides got removed due to the helper method handling it.
- Replace window creation with CreateWindow helper.
- Fixed some stinky code which would cause exceptions.

* More

* moar

* weh

* done

* More BUIs

* More updates

* weh

* moar

* look who it is

* weh

* merge

* weh

* fixes
2024-07-20 15:40:16 +10:00

62 lines
1.6 KiB
C#

using System.Numerics;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
namespace Content.Client.NetworkConfigurator;
[GenerateTypedNameReferences]
public sealed partial class NetworkConfiguratorDeviceList : ScrollContainer
{
public event Action<string>? OnRemoveAddress;
public void UpdateState(HashSet<(string address, string name)> devices, bool ui)
{
DeviceList.RemoveAllChildren();
foreach (var device in devices)
{
DeviceList.AddChild(BuildDeviceListRow(device, ui));
}
}
private BoxContainer BuildDeviceListRow((string address, string name) savedDevice, bool ui)
{
var row = new BoxContainer()
{
Orientation = BoxContainer.LayoutOrientation.Horizontal,
Margin = new Thickness(8)
};
var name = new Label()
{
Text = savedDevice.name[..Math.Min(11, savedDevice.name.Length)],
SetWidth = 84
};
var address = new Label()
{
Text = savedDevice.address,
HorizontalExpand = true,
Align = Label.AlignMode.Center
};
var removeButton = new TextureButton()
{
StyleClasses = { "CrossButtonRed" },
VerticalAlignment = VAlignment.Center,
Scale = new Vector2(0.5f, 0.5f)
};
row.AddChild(name);
row.AddChild(address);
if (ui)
{
row.AddChild(removeButton);
removeButton.OnPressed += _ => OnRemoveAddress?.Invoke(savedDevice.address);
}
return row;
}
}