StationMapWindow.xaml.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System.Numerics;
  2. using Content.Client.UserInterface.Controls;
  3. using Robust.Client.AutoGenerated;
  4. using Robust.Client.UserInterface.XAML;
  5. using Robust.Shared.Map;
  6. using Content.Shared.Pinpointer;
  7. namespace Content.Client.Pinpointer.UI;
  8. [GenerateTypedNameReferences]
  9. public sealed partial class StationMapWindow : FancyWindow
  10. {
  11. [Dependency] private readonly IEntityManager _entMan = default!;
  12. private readonly List<StationMapBeaconControl> _buttons = new();
  13. public StationMapWindow()
  14. {
  15. RobustXamlLoader.Load(this);
  16. IoCManager.InjectDependencies(this);
  17. FilterBar.OnTextChanged += (bar) => OnFilterChanged(bar.Text);
  18. }
  19. public void Set(string stationName, EntityUid? mapUid, EntityUid? trackedEntity)
  20. {
  21. NavMapScreen.MapUid = mapUid;
  22. if (trackedEntity != null)
  23. NavMapScreen.TrackedCoordinates.Add(new EntityCoordinates(trackedEntity.Value, Vector2.Zero), (true, Color.Cyan));
  24. if (!string.IsNullOrEmpty(stationName))
  25. {
  26. StationName.Text = stationName;
  27. }
  28. NavMapScreen.ForceNavMapUpdate();
  29. UpdateBeaconList(mapUid);
  30. }
  31. public void OnFilterChanged(string newFilter)
  32. {
  33. foreach (var button in _buttons)
  34. {
  35. button.Visible = string.IsNullOrEmpty(newFilter) || (
  36. !string.IsNullOrEmpty(button.Label) &&
  37. button.Label.Contains(newFilter, StringComparison.OrdinalIgnoreCase)
  38. );
  39. };
  40. }
  41. public void UpdateBeaconList(EntityUid? mapUid)
  42. {
  43. BeaconButtons.Children.Clear();
  44. _buttons.Clear();
  45. if (!mapUid.HasValue)
  46. return;
  47. if (!_entMan.TryGetComponent<NavMapComponent>(mapUid, out var navMap))
  48. return;
  49. foreach (var beacon in navMap.Beacons.Values)
  50. {
  51. var button = new StationMapBeaconControl(mapUid.Value, beacon);
  52. button.OnPressed += NavMapScreen.CenterToCoordinates;
  53. _buttons.Add(button);
  54. }
  55. _buttons.Sort();
  56. foreach (var button in _buttons)
  57. BeaconButtons.AddChild(button);
  58. }
  59. }