Skip to content

Commit

Permalink
Added search bar to warp points (#23978)
Browse files Browse the repository at this point in the history
(cherry picked from commit 668d0eca2276b731730af930024ae66ccfdda11e)
  • Loading branch information
Crotalus authored and DebugOk committed Jan 26, 2024
1 parent 5467965 commit 43de08b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -60,9 +62,31 @@ private void AddButtons()
};

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();
}
}
}

0 comments on commit 43de08b

Please sign in to comment.