Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add search textbox to friends display #30499

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 48 additions & 10 deletions osu.Game/Overlays/Dashboard/Friends/FriendDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Resources.Localisation.Web;
using osu.Game.Users;
using osuTK;

Expand All @@ -35,14 +38,16 @@ public List<APIUser> Users

private CancellationTokenSource cancellationToken;

private Drawable currentContent;
[CanBeNull]
private SearchContainer currentContent;

private FriendOnlineStreamControl onlineStreamControl;
private Box background;
private Box controlBackground;
private UserListToolbar userListToolbar;
private Container itemsPlaceholder;
private LoadingLayer loading;
private BasicSearchTextBox searchTextBox;

private readonly IBindableList<APIUser> apiFriends = new BindableList<APIUser>();

Expand Down Expand Up @@ -104,7 +109,7 @@ private void load(OverlayColourProvider colourProvider, IAPIProvider api)
Margin = new MarginPadding { Bottom = 20 },
Children = new Drawable[]
{
new Container
new GridContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Expand All @@ -113,11 +118,38 @@ private void load(OverlayColourProvider colourProvider, IAPIProvider api)
Horizontal = 40,
Vertical = 20
},
Child = userListToolbar = new UserListToolbar
ColumnDimensions = new[]
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
}
new Dimension(),
new Dimension(GridSizeMode.Absolute, 50),
new Dimension(GridSizeMode.AutoSize),
},
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
},
Content = new[]
{
new[]
{
searchTextBox = new BasicSearchTextBox
{
RelativeSizeAxes = Axes.X,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Height = 40,
ReleaseFocusOnCommit = false,
HoldFocus = true,
PlaceholderText = HomeStrings.SearchPlaceholder,
},
Empty(),
userListToolbar = new UserListToolbar
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
},
},
},
},
new Container
{
Expand Down Expand Up @@ -155,6 +187,11 @@ protected override void LoadComplete()
onlineStreamControl.Current.BindValueChanged(_ => recreatePanels());
userListToolbar.DisplayStyle.BindValueChanged(_ => recreatePanels());
userListToolbar.SortCriteria.BindValueChanged(_ => recreatePanels());
searchTextBox.Current.BindValueChanged(_ =>
{
if (currentContent.IsNotNull())
currentContent.SearchTerm = searchTextBox.Current.Value;
});
}

private void recreatePanels()
Expand Down Expand Up @@ -188,7 +225,7 @@ private List<APIUser> getUsersInCurrentGroup()
}
}

private void addContentToPlaceholder(Drawable content)
private void addContentToPlaceholder(SearchContainer content)
{
loading.Hide();

Expand All @@ -204,16 +241,17 @@ private void addContentToPlaceholder(Drawable content)
currentContent.FadeIn(200, Easing.OutQuint);
}

private FillFlowContainer createTable(List<APIUser> users)
private SearchContainer createTable(List<APIUser> users)
{
var style = userListToolbar.DisplayStyle.Value;

return new FillFlowContainer
return new SearchContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Spacing = new Vector2(style == OverlayPanelDisplayStyle.Card ? 10 : 2),
Children = users.Select(u => createUserPanel(u, style)).ToList()
Children = users.Select(u => createUserPanel(u, style)).ToList(),
SearchTerm = searchTextBox.Current.Value,
};
}

Expand Down
19 changes: 18 additions & 1 deletion osu.Game/Users/UserPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Overlays;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.UserInterface;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Localisation;
using osu.Framework.Screens;
using osu.Game.Graphics.Containers;
using osu.Game.Online.API;
Expand All @@ -28,7 +30,7 @@

namespace osu.Game.Users
{
public abstract partial class UserPanel : OsuClickableContainer, IHasContextMenu
public abstract partial class UserPanel : OsuClickableContainer, IHasContextMenu, IFilterable
{
public readonly APIUser User;

Expand Down Expand Up @@ -162,5 +164,20 @@ public MenuItem[] ContextMenuItems
return items.ToArray();
}
}

public IEnumerable<LocalisableString> FilterTerms => [User.Username];

public bool MatchingFilter
{
set
{
if (value)
Show();
else
Hide();
}
}

public bool FilteringActive { get; set; }
}
}
Loading