1
0

CrewMonitoringNavMapControl.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using Content.Client.Pinpointer.UI;
  2. using Robust.Client.Graphics;
  3. using Robust.Client.UserInterface.Controls;
  4. using Robust.Shared.Timing;
  5. namespace Content.Client.Medical.CrewMonitoring;
  6. public sealed partial class CrewMonitoringNavMapControl : NavMapControl
  7. {
  8. public NetEntity? Focus;
  9. public Dictionary<NetEntity, string> LocalizedNames = new();
  10. private Label _trackedEntityLabel;
  11. private PanelContainer _trackedEntityPanel;
  12. public CrewMonitoringNavMapControl() : base()
  13. {
  14. WallColor = new Color(192, 122, 196);
  15. TileColor = new(71, 42, 72);
  16. BackgroundColor = Color.FromSrgb(TileColor.WithAlpha(BackgroundOpacity));
  17. _trackedEntityLabel = new Label
  18. {
  19. Margin = new Thickness(10f, 8f),
  20. HorizontalAlignment = HAlignment.Center,
  21. VerticalAlignment = VAlignment.Center,
  22. Modulate = Color.White,
  23. };
  24. _trackedEntityPanel = new PanelContainer
  25. {
  26. PanelOverride = new StyleBoxFlat
  27. {
  28. BackgroundColor = BackgroundColor,
  29. },
  30. Margin = new Thickness(5f, 10f),
  31. HorizontalAlignment = HAlignment.Left,
  32. VerticalAlignment = VAlignment.Bottom,
  33. Visible = false,
  34. };
  35. _trackedEntityPanel.AddChild(_trackedEntityLabel);
  36. this.AddChild(_trackedEntityPanel);
  37. }
  38. protected override void FrameUpdate(FrameEventArgs args)
  39. {
  40. base.FrameUpdate(args);
  41. if (Focus == null)
  42. {
  43. _trackedEntityLabel.Text = string.Empty;
  44. _trackedEntityPanel.Visible = false;
  45. return;
  46. }
  47. foreach ((var netEntity, var blip) in TrackedEntities)
  48. {
  49. if (netEntity != Focus)
  50. continue;
  51. if (!LocalizedNames.TryGetValue(netEntity, out var name))
  52. name = "Unknown";
  53. var message = name + "\nLocation: [x = " + MathF.Round(blip.Coordinates.X) + ", y = " + MathF.Round(blip.Coordinates.Y) + "]";
  54. _trackedEntityLabel.Text = message;
  55. _trackedEntityPanel.Visible = true;
  56. return;
  57. }
  58. _trackedEntityLabel.Text = string.Empty;
  59. _trackedEntityPanel.Visible = false;
  60. }
  61. }