Skip to content

Commit

Permalink
Added a directory to station maps (#31156)
Browse files Browse the repository at this point in the history
* Added directory to station maps

* Add null checks to map directory sorting/filtering

* Reworked station map directory to be more readable and responsive
  • Loading branch information
TGRCdev committed Sep 21, 2024
1 parent 29e56be commit d32c42f
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 7 deletions.
19 changes: 19 additions & 0 deletions Content.Client/Pinpointer/UI/StationMapBeaconControl.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Control xmlns="https://spacestation14.io" HorizontalExpand="True">
<BoxContainer Name="MainContainer"
Orientation="Horizontal"
HorizontalExpand="True">
<PanelContainer Name="ColorPanel"
VerticalExpand="True"
SetWidth="7"
Margin="0 1 0 0" />
<Button Name="MainButton"
HorizontalExpand="True"
VerticalExpand="True"
StyleClasses="ButtonSquare"
Margin="-1 0 0 0">
<BoxContainer Orientation="Horizontal" HorizontalExpand="True">
<Label Name="BeaconNameLabel" />
</BoxContainer>
</Button>
</BoxContainer>
</Control>
50 changes: 50 additions & 0 deletions Content.Client/Pinpointer/UI/StationMapBeaconControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Content.Shared.Pinpointer;
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Map;

namespace Content.Client.Pinpointer.UI;

[GenerateTypedNameReferences]
public sealed partial class StationMapBeaconControl : Control, IComparable<StationMapBeaconControl>
{
[Dependency] private readonly IEntityManager _entMan = default!;

public readonly EntityCoordinates BeaconPosition;
public Action<EntityCoordinates>? OnPressed;
public string? Label => BeaconNameLabel.Text;
private StyleBoxFlat _styleBox;
public Color Color => _styleBox.BackgroundColor;

public StationMapBeaconControl(EntityUid mapUid, SharedNavMapSystem.NavMapBeacon beacon)
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);

BeaconPosition = new EntityCoordinates(mapUid, beacon.Position);

_styleBox = new StyleBoxFlat { BackgroundColor = beacon.Color };
ColorPanel.PanelOverride = _styleBox;
BeaconNameLabel.Text = beacon.Text;

MainButton.OnPressed += args => OnPressed?.Invoke(BeaconPosition);
}

public int CompareTo(StationMapBeaconControl? other)
{
if (other == null)
return 1;

// Group by color
var colorCompare = Color.ToArgb().CompareTo(other.Color.ToArgb());
if (colorCompare != 0)
{
return colorCompare;
}

// If same color, sort by text
return string.Compare(Label, other.Label);
}
}
11 changes: 9 additions & 2 deletions Content.Client/Pinpointer/UI/StationMapBoundUserInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,16 @@ protected override void Open()

_window = this.CreateWindow<StationMapWindow>();
_window.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName;

string stationName = string.Empty;
if(EntMan.TryGetComponent<MetaDataComponent>(gridUid, out var gridMetaData))
{
stationName = gridMetaData.EntityName;
}

if (EntMan.TryGetComponent<StationMapComponent>(Owner, out var comp) && comp.ShowLocation)
_window.Set(gridUid, Owner);
_window.Set(stationName, gridUid, Owner);
else
_window.Set(gridUid, null);
_window.Set(stationName, gridUid, null);
}
}
23 changes: 20 additions & 3 deletions Content.Client/Pinpointer/UI/StationMapWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,28 @@
xmlns:ui="clr-namespace:Content.Client.Pinpointer.UI"
Title="{Loc 'station-map-window-title'}"
Resizable="False"
SetSize="668 713"
MinSize="668 713">
SetSize="868 748"
MinSize="868 748">
<BoxContainer Orientation="Vertical">
<BoxContainer Orientation="Horizontal" HorizontalExpand="True" Margin="0 8 0 10" VerticalAlignment="Top">
<!-- Station name -->
<controls:StripeBack>
<PanelContainer>
<Label Name="StationName" Text="Unknown station" StyleClasses="LabelBig" Align="Center"/>
</PanelContainer>
</controls:StripeBack>

<BoxContainer Orientation="Horizontal" HorizontalExpand="True" VerticalAlignment="Top">
<ui:NavMapControl Name="NavMapScreen"/>

<BoxContainer Orientation="Vertical" SetWidth="200">
<!-- Search bar -->
<LineEdit Name="FilterBar" PlaceHolder="{Loc 'station-map-filter-placeholder'}" Margin="0 0 10 10" HorizontalExpand="True"/>

<ScrollContainer HorizontalExpand="True" VerticalExpand="True">
<!-- Beacon Buttons (filled by code) -->
<BoxContainer Name="BeaconButtons" Orientation="Vertical" HorizontalExpand="True" />
</ScrollContainer>
</BoxContainer>
</BoxContainer>

<!-- Footer -->
Expand Down
55 changes: 53 additions & 2 deletions Content.Client/Pinpointer/UI/StationMapWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,75 @@
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Map;
using Content.Shared.Pinpointer;

namespace Content.Client.Pinpointer.UI;

[GenerateTypedNameReferences]
public sealed partial class StationMapWindow : FancyWindow
{
[Dependency] private readonly IEntityManager _entMan = default!;

private readonly List<StationMapBeaconControl> _buttons = new();

public StationMapWindow()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);

FilterBar.OnTextChanged += (bar) => OnFilterChanged(bar.Text);
}

public void Set(EntityUid? mapUid, EntityUid? trackedEntity)
public void Set(string stationName, EntityUid? mapUid, EntityUid? trackedEntity)
{
NavMapScreen.MapUid = mapUid;

if (trackedEntity != null)
NavMapScreen.TrackedCoordinates.Add(new EntityCoordinates(trackedEntity.Value, Vector2.Zero), (true, Color.Cyan));

if (!string.IsNullOrEmpty(stationName))
{
StationName.Text = stationName;
}

NavMapScreen.ForceNavMapUpdate();
UpdateBeaconList(mapUid);
}

public void OnFilterChanged(string newFilter)
{
foreach (var button in _buttons)
{
button.Visible = string.IsNullOrEmpty(newFilter) || (
!string.IsNullOrEmpty(button.Label) &&
button.Label.Contains(newFilter, StringComparison.OrdinalIgnoreCase)
);
};
}

public void UpdateBeaconList(EntityUid? mapUid)
{
BeaconButtons.Children.Clear();
_buttons.Clear();

if (!mapUid.HasValue)
return;

if (!_entMan.TryGetComponent<NavMapComponent>(mapUid, out var navMap))
return;

foreach (var beacon in navMap.Beacons.Values)
{
var button = new StationMapBeaconControl(mapUid.Value, beacon);

button.OnPressed += NavMapScreen.CenterToCoordinates;

_buttons.Add(button);
}

_buttons.Sort();

foreach (var button in _buttons)
BeaconButtons.AddChild(button);
}
}
}
1 change: 1 addition & 0 deletions Resources/Locale/en-US/navmap-beacons/station_map.ftl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
station-map-window-title = Station map
station-map-user-interface-flavor-left = Don't panic
station-map-user-interface-flavor-right = v1.42
station-map-filter-placeholder = Search by name
nav-beacon-window-title = Station Beacon
nav-beacon-toggle-visible = Visible
Expand Down

0 comments on commit d32c42f

Please sign in to comment.