LogProbeUiFragment.xaml.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using Content.Shared.CartridgeLoader.Cartridges;
  2. using Robust.Client.AutoGenerated;
  3. using Robust.Client.UserInterface.Controls;
  4. using Robust.Client.UserInterface.XAML;
  5. namespace Content.Client.CartridgeLoader.Cartridges;
  6. [GenerateTypedNameReferences]
  7. public sealed partial class LogProbeUiFragment : BoxContainer
  8. {
  9. /// <summary>
  10. /// Action invoked when the print button gets pressed.
  11. /// </summary>
  12. public Action? OnPrintPressed;
  13. public LogProbeUiFragment()
  14. {
  15. RobustXamlLoader.Load(this);
  16. PrintButton.OnPressed += _ => OnPrintPressed?.Invoke();
  17. }
  18. public void UpdateState(string name, List<PulledAccessLog> logs)
  19. {
  20. EntityName.Text = name;
  21. PrintButton.Disabled = string.IsNullOrEmpty(name);
  22. ProbedDeviceContainer.RemoveAllChildren();
  23. var count = 1;
  24. foreach (var log in logs)
  25. {
  26. AddAccessLog(log, count);
  27. count++;
  28. }
  29. }
  30. private void AddAccessLog(PulledAccessLog log, int numberLabelText)
  31. {
  32. var timeLabelText = TimeSpan.FromSeconds(Math.Truncate(log.Time.TotalSeconds)).ToString();
  33. var accessorLabelText = log.Accessor;
  34. var entry = new LogProbeUiEntry(numberLabelText, timeLabelText, accessorLabelText);
  35. ProbedDeviceContainer.AddChild(entry);
  36. }
  37. }