1
0

StationMapBeaconControl.xaml.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using Content.Shared.Pinpointer;
  2. using Robust.Client.AutoGenerated;
  3. using Robust.Client.Graphics;
  4. using Robust.Client.UserInterface;
  5. using Robust.Client.UserInterface.XAML;
  6. using Robust.Shared.Map;
  7. namespace Content.Client.Pinpointer.UI;
  8. [GenerateTypedNameReferences]
  9. public sealed partial class StationMapBeaconControl : Control, IComparable<StationMapBeaconControl>
  10. {
  11. public readonly EntityCoordinates BeaconPosition;
  12. public Action<EntityCoordinates>? OnPressed;
  13. public string? Label => BeaconNameLabel.Text;
  14. private StyleBoxFlat _styleBox;
  15. public Color Color => _styleBox.BackgroundColor;
  16. public StationMapBeaconControl(EntityUid mapUid, SharedNavMapSystem.NavMapBeacon beacon)
  17. {
  18. RobustXamlLoader.Load(this);
  19. IoCManager.InjectDependencies(this);
  20. BeaconPosition = new EntityCoordinates(mapUid, beacon.Position);
  21. _styleBox = new StyleBoxFlat { BackgroundColor = beacon.Color };
  22. ColorPanel.PanelOverride = _styleBox;
  23. BeaconNameLabel.Text = beacon.Text;
  24. MainButton.OnPressed += args => OnPressed?.Invoke(BeaconPosition);
  25. }
  26. public int CompareTo(StationMapBeaconControl? other)
  27. {
  28. if (other == null)
  29. return 1;
  30. // Group by color
  31. var colorCompare = Color.ToArgb().CompareTo(other.Color.ToArgb());
  32. if (colorCompare != 0)
  33. {
  34. return colorCompare;
  35. }
  36. // If same color, sort by text
  37. return string.Compare(Label, other.Label);
  38. }
  39. }