NetProbeUiFragment.xaml.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using Content.Shared.CartridgeLoader.Cartridges;
  2. using Robust.Client.AutoGenerated;
  3. using Robust.Client.Graphics;
  4. using Robust.Client.UserInterface.Controls;
  5. using Robust.Client.UserInterface.XAML;
  6. namespace Content.Client.CartridgeLoader.Cartridges;
  7. [GenerateTypedNameReferences]
  8. public sealed partial class NetProbeUiFragment : BoxContainer
  9. {
  10. private readonly StyleBoxFlat _styleBox = new()
  11. {
  12. BackgroundColor = Color.Transparent,
  13. BorderColor = Color.FromHex("#5a5a5a"),
  14. BorderThickness = new Thickness(0, 0, 0, 1)
  15. };
  16. public NetProbeUiFragment()
  17. {
  18. RobustXamlLoader.Load(this);
  19. Orientation = LayoutOrientation.Vertical;
  20. HorizontalExpand = true;
  21. VerticalExpand = true;
  22. HeaderPanel.PanelOverride = _styleBox;
  23. }
  24. public void UpdateState(List<ProbedNetworkDevice> devices)
  25. {
  26. ProbedDeviceContainer.RemoveAllChildren();
  27. //Reverse the list so the oldest entries appear at the bottom
  28. devices.Reverse();
  29. //Enable scrolling if there are more entries that can fit on the screen
  30. ScrollContainer.HScrollEnabled = devices.Count > 9;
  31. foreach (var device in devices)
  32. {
  33. AddProbedDevice(device);
  34. }
  35. }
  36. private void AddProbedDevice(ProbedNetworkDevice device)
  37. {
  38. var row = new BoxContainer();
  39. row.HorizontalExpand = true;
  40. row.Orientation = LayoutOrientation.Horizontal;
  41. row.Margin = new Thickness(4);
  42. var nameLabel = new Label();
  43. nameLabel.Text = device.Name;
  44. nameLabel.HorizontalExpand = true;
  45. nameLabel.ClipText = true;
  46. row.AddChild(nameLabel);
  47. var addressLabel = new Label();
  48. addressLabel.Text = device.Address;
  49. addressLabel.HorizontalExpand = true;
  50. addressLabel.ClipText = true;
  51. row.AddChild(addressLabel);
  52. var frequencyLabel = new Label();
  53. frequencyLabel.Text = device.Frequency;
  54. frequencyLabel.HorizontalExpand = true;
  55. frequencyLabel.ClipText = true;
  56. row.AddChild(frequencyLabel);
  57. var networkLabel = new Label();
  58. networkLabel.Text = device.NetId;
  59. networkLabel.HorizontalExpand = true;
  60. networkLabel.ClipText = true;
  61. row.AddChild(networkLabel);
  62. ProbedDeviceContainer.AddChild(row);
  63. }
  64. }