]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Added search bar to warp points (#23978)
authorCrotalus <Crotalus@users.noreply.github.com>
Fri, 12 Jan 2024 20:34:11 +0000 (21:34 +0100)
committerGitHub <noreply@github.com>
Fri, 12 Jan 2024 20:34:11 +0000 (13:34 -0700)
Content.Client/UserInterface/Systems/Ghost/Controls/GhostTargetWindow.xaml
Content.Client/UserInterface/Systems/Ghost/Controls/GhostTargetWindow.xaml.cs

index df42f22c47e27b288647b4667d19c00f149f623f..86fd09b2c80747ca4ddef74b93218ef5e97a267e 100644 (file)
@@ -1,15 +1,10 @@
-<DefaultWindow xmlns="https://spacestation14.io"
-            Title="{Loc 'ghost-target-window-title'}"
-            MinSize="450 450"
-            SetSize="450 450">
-    <ScrollContainer VerticalExpand="True"
-                     HorizontalExpand="True"
-                                        HScrollEnabled="False">
-        <BoxContainer Name="ButtonContainer"
-                      Orientation="Vertical"
-                      VerticalExpand="True"
-                      SeparationOverride="5">
-            <!-- Target buttons get added here by code -->
-        </BoxContainer>
-    </ScrollContainer>
+<DefaultWindow xmlns="https://spacestation14.io" Title="{Loc 'ghost-target-window-title'}" MinSize="450 450" SetSize="450 450">
+    <BoxContainer Orientation="Vertical" HorizontalExpand="True" SizeFlagsStretchRatio="0.4">
+        <LineEdit Name="SearchBar" PlaceHolder="Search" HorizontalExpand="True" Margin="0 4" />
+        <ScrollContainer VerticalExpand="True" HorizontalExpand="True" HScrollEnabled="False">
+            <BoxContainer Name="ButtonContainer" Orientation="Vertical" VerticalExpand="True" SeparationOverride="5">
+                <!-- Target buttons get added here by code -->
+            </BoxContainer>
+        </ScrollContainer>
+    </BoxContainer>
 </DefaultWindow>
index 3d86266df81b90a457eab560d49238b97c812e5d..3c17697c250c3798b4a9bbbf050494b2e4f885a1 100644 (file)
@@ -12,12 +12,14 @@ namespace Content.Client.UserInterface.Systems.Ghost.Controls
     public sealed partial class GhostTargetWindow : DefaultWindow
     {
         private List<(string, NetEntity)> _warps = new();
+        private string _searchText = string.Empty;
 
         public event Action<NetEntity>? WarpClicked;
 
         public GhostTargetWindow()
         {
             RobustXamlLoader.Load(this);
+            SearchBar.OnTextChanged += OnSearchTextChanged;
         }
 
         public void UpdateWarps(IEnumerable<GhostWarp> warps)
@@ -60,9 +62,31 @@ namespace Content.Client.UserInterface.Systems.Ghost.Controls
                 };
 
                 currentButtonRef.OnPressed += _ => WarpClicked?.Invoke(warpTarget);
+                currentButtonRef.Visible = ButtonIsVisible(currentButtonRef);
 
                 ButtonContainer.AddChild(currentButtonRef);
             }
         }
+
+        private bool ButtonIsVisible(Button button)
+        {
+            return string.IsNullOrEmpty(_searchText) || button.Text == null || button.Text.Contains(_searchText, StringComparison.OrdinalIgnoreCase);
+        }
+
+        private void UpdateVisibleButtons()
+        {
+            foreach (var child in ButtonContainer.Children)
+            {
+                if (child is Button button)
+                    button.Visible = ButtonIsVisible(button);
+            }
+        }
+
+        private void OnSearchTextChanged(LineEdit.LineEditEventArgs args)
+        {
+            _searchText = args.Text;
+
+            UpdateVisibleButtons();
+        }
     }
 }