]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Added a directory to station maps (#31156)
authorTGRCDev <tgrc@tgrc.dev>
Sat, 21 Sep 2024 07:33:22 +0000 (00:33 -0700)
committerGitHub <noreply@github.com>
Sat, 21 Sep 2024 07:33:22 +0000 (09:33 +0200)
* Added directory to station maps

* Add null checks to map directory sorting/filtering

* Reworked station map directory to be more readable and responsive

Content.Client/Pinpointer/UI/StationMapBeaconControl.xaml [new file with mode: 0644]
Content.Client/Pinpointer/UI/StationMapBeaconControl.xaml.cs [new file with mode: 0644]
Content.Client/Pinpointer/UI/StationMapBoundUserInterface.cs
Content.Client/Pinpointer/UI/StationMapWindow.xaml
Content.Client/Pinpointer/UI/StationMapWindow.xaml.cs
Resources/Locale/en-US/navmap-beacons/station_map.ftl

diff --git a/Content.Client/Pinpointer/UI/StationMapBeaconControl.xaml b/Content.Client/Pinpointer/UI/StationMapBeaconControl.xaml
new file mode 100644 (file)
index 0000000..e1c5513
--- /dev/null
@@ -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>
diff --git a/Content.Client/Pinpointer/UI/StationMapBeaconControl.xaml.cs b/Content.Client/Pinpointer/UI/StationMapBeaconControl.xaml.cs
new file mode 100644 (file)
index 0000000..a4d4055
--- /dev/null
@@ -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);
+    }
+}
index 91fb4ef71bd6c99d1370d73e3fcb6ce12ea553af..3d1eb1723c31ecdb5abef5271714e8dfec630d7b 100644 (file)
@@ -24,9 +24,16 @@ public sealed class StationMapBoundUserInterface : BoundUserInterface
 
         _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);
     }
 }
index 00424a3566aa42f9c37625aff9e9a5892459beb9..c79fc8f9e7b8d06f12535d676eeba7d9e3a50e68 100644 (file)
@@ -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 -->
index 7cbb8b7d0dbc22e43ab19a21d4df300592cb9269..52ef2ab7da4c0699979db341fe64fc810adf19a0 100644 (file)
@@ -3,24 +3,75 @@ using Content.Client.UserInterface.Controls;
 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);
     }
-}
+}
\ No newline at end of file
index 1563e0abaf25f8bb65596602761493284c545832..e252851556639c74015945c130dcb96125d102ee 100644 (file)
@@ -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