From c19802e923ebe9a066ba78c4f948ef6dc4cbb2de Mon Sep 17 00:00:00 2001 From: Joseph Madamba Date: Mon, 16 Sep 2024 22:34:51 -0700 Subject: [PATCH] Use sheared text box with filter count in multi/playlists lounge --- .../TestScenePlaylistsLoungeSubScreen.cs | 15 ++++++++++ .../Lounge/Components/RoomsContainer.cs | 4 +++ .../OnlinePlay/Lounge/LoungeSubScreen.cs | 29 +++++++++++++++---- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/osu.Game.Tests/Visual/Playlists/TestScenePlaylistsLoungeSubScreen.cs b/osu.Game.Tests/Visual/Playlists/TestScenePlaylistsLoungeSubScreen.cs index 0c536cb1d4..64b088a31c 100644 --- a/osu.Game.Tests/Visual/Playlists/TestScenePlaylistsLoungeSubScreen.cs +++ b/osu.Game.Tests/Visual/Playlists/TestScenePlaylistsLoungeSubScreen.cs @@ -9,6 +9,7 @@ using osu.Framework.Bindables; using osu.Framework.Screens; using osu.Framework.Testing; using osu.Game.Graphics.Containers; +using osu.Game.Graphics.UserInterface; using osu.Game.Online.Rooms; using osu.Game.Screens.OnlinePlay.Lounge.Components; using osu.Game.Screens.OnlinePlay.Playlists; @@ -91,6 +92,20 @@ namespace osu.Game.Tests.Visual.Playlists AddAssert("selected room is disabled", () => loungeScreen.SelectedRoom.Disabled); } + [Test] + public void TestFilterTextCount() + { + AddAssert("filter text is 0 matches", () => this.ChildrenOfType().Single().FilterText.ToString(), () => Is.EqualTo("0 matches")); + + AddStep("add 10 rooms", () => RoomManager.AddRooms(10)); + + AddAssert("filter text is 10 matches", () => this.ChildrenOfType().Single().FilterText.ToString(), () => Is.EqualTo("10 matches")); + + AddStep("search for room 1", () => this.ChildrenOfType().Single().Current.Value = "room 1"); + + AddUntilStep("filter text is 1 match", () => this.ChildrenOfType().Single().FilterText.ToString(), () => Is.EqualTo("1 match")); + } + private bool checkRoomVisible(DrawableRoom room) => loungeScreen.ChildrenOfType().First().ScreenSpaceDrawQuad .Contains(room.ScreenSpaceDrawQuad.Centre); diff --git a/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomsContainer.cs b/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomsContainer.cs index e842f8c436..a3ba89e000 100644 --- a/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomsContainer.cs +++ b/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomsContainer.cs @@ -29,6 +29,8 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components public IReadOnlyList Rooms => roomFlow.FlowingChildren.Cast().ToArray(); + public Bindable VisibleRoomCount = new Bindable(); + private readonly IBindableList rooms = new BindableList(); private readonly FillFlowContainer roomFlow; @@ -94,6 +96,8 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components } }); + VisibleRoomCount.Value = roomFlow.Count(r => r.MatchingFilter); + static bool matchPermissions(DrawableLoungeRoom room, RoomPermissionsFilter accessType) { switch (accessType) diff --git a/osu.Game/Screens/OnlinePlay/Lounge/LoungeSubScreen.cs b/osu.Game/Screens/OnlinePlay/Lounge/LoungeSubScreen.cs index 3792a67896..63fed6e108 100644 --- a/osu.Game/Screens/OnlinePlay/Lounge/LoungeSubScreen.cs +++ b/osu.Game/Screens/OnlinePlay/Lounge/LoungeSubScreen.cs @@ -85,7 +85,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge private PopoverContainer popoverContainer; private LoadingLayer loadingLayer; private RoomsContainer roomsContainer; - private SearchTextBox searchTextBox; + private ShearedFilterTextBox searchTextBox; private Dropdown statusDropdown; [BackgroundDependencyLoader(true)] @@ -135,7 +135,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge { RelativeSizeAxes = Axes.X, Height = Header.HEIGHT, - Child = searchTextBox = new BasicSearchTextBox + Child = searchTextBox = new ShearedFilterTextBox { Anchor = Anchor.CentreRight, Origin = Anchor.CentreRight, @@ -196,10 +196,17 @@ namespace osu.Game.Screens.OnlinePlay.Lounge if (ongoingOperationTracker != null) { operationInProgress.BindTo(ongoingOperationTracker.InProgress); - operationInProgress.BindValueChanged(_ => updateLoadingLayer()); + operationInProgress.BindValueChanged(_ => updateLoadingState()); } - ListingPollingComponent.InitialRoomsReceived.BindValueChanged(_ => updateLoadingLayer(), true); + ListingPollingComponent.InitialRoomsReceived.BindValueChanged(_ => updateLoadingState(), true); + + roomsContainer.VisibleRoomCount.BindValueChanged(_ => + { + if (operationInProgress.Value || !ListingPollingComponent.InitialRoomsReceived.Value) return; + + updateFilterText(); + }, true); updateFilter(); } @@ -382,12 +389,24 @@ namespace osu.Game.Screens.OnlinePlay.Lounge this.Push(CreateRoomSubScreen(room)); } - private void updateLoadingLayer() + private void updateLoadingState() { if (operationInProgress.Value || !ListingPollingComponent.InitialRoomsReceived.Value) + { loadingLayer.Show(); + searchTextBox.FilterText = "loading..."; + } else + { loadingLayer.Hide(); + updateFilterText(); + } + } + + private void updateFilterText() + { + int visibleRoomCount = roomsContainer.VisibleRoomCount.Value; + searchTextBox.FilterText = visibleRoomCount != 1 ? $"{visibleRoomCount:#,0} matches" : $"{visibleRoomCount:#,0} match"; } private void updatePollingRate(bool isCurrentScreen)