Added search bar to warp points (#23978)

This commit is contained in:
Crotalus
2024-01-12 21:34:11 +01:00
committed by GitHub
parent f8f5524fd5
commit 668d0eca22
2 changed files with 33 additions and 14 deletions

View File

@@ -1,15 +1,10 @@
<DefaultWindow xmlns="https://spacestation14.io" <DefaultWindow xmlns="https://spacestation14.io" Title="{Loc 'ghost-target-window-title'}" MinSize="450 450" SetSize="450 450">
Title="{Loc 'ghost-target-window-title'}" <BoxContainer Orientation="Vertical" HorizontalExpand="True" SizeFlagsStretchRatio="0.4">
MinSize="450 450" <LineEdit Name="SearchBar" PlaceHolder="Search" HorizontalExpand="True" Margin="0 4" />
SetSize="450 450"> <ScrollContainer VerticalExpand="True" HorizontalExpand="True" HScrollEnabled="False">
<ScrollContainer VerticalExpand="True" <BoxContainer Name="ButtonContainer" Orientation="Vertical" VerticalExpand="True" SeparationOverride="5">
HorizontalExpand="True" <!-- Target buttons get added here by code -->
HScrollEnabled="False"> </BoxContainer>
<BoxContainer Name="ButtonContainer" </ScrollContainer>
Orientation="Vertical" </BoxContainer>
VerticalExpand="True"
SeparationOverride="5">
<!-- Target buttons get added here by code -->
</BoxContainer>
</ScrollContainer>
</DefaultWindow> </DefaultWindow>

View File

@@ -12,12 +12,14 @@ namespace Content.Client.UserInterface.Systems.Ghost.Controls
public sealed partial class GhostTargetWindow : DefaultWindow public sealed partial class GhostTargetWindow : DefaultWindow
{ {
private List<(string, NetEntity)> _warps = new(); private List<(string, NetEntity)> _warps = new();
private string _searchText = string.Empty;
public event Action<NetEntity>? WarpClicked; public event Action<NetEntity>? WarpClicked;
public GhostTargetWindow() public GhostTargetWindow()
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
SearchBar.OnTextChanged += OnSearchTextChanged;
} }
public void UpdateWarps(IEnumerable<GhostWarp> warps) public void UpdateWarps(IEnumerable<GhostWarp> warps)
@@ -60,9 +62,31 @@ namespace Content.Client.UserInterface.Systems.Ghost.Controls
}; };
currentButtonRef.OnPressed += _ => WarpClicked?.Invoke(warpTarget); currentButtonRef.OnPressed += _ => WarpClicked?.Invoke(warpTarget);
currentButtonRef.Visible = ButtonIsVisible(currentButtonRef);
ButtonContainer.AddChild(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();
}
} }
} }