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

Implement sheared text box with filter count and use in multi/playlists lounge #29910

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@

#nullable disable

using System;
using System.Linq;
using NUnit.Framework;
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;
Expand All @@ -22,6 +24,7 @@ public partial class TestScenePlaylistsLoungeSubScreen : OnlinePlayTestScene
protected new TestRoomManager RoomManager => (TestRoomManager)base.RoomManager;

private TestLoungeSubScreen loungeScreen;
private IDisposable loadingOperation;

public override void SetUpSteps()
{
Expand Down Expand Up @@ -91,6 +94,30 @@ public void TestEnteringRoomTakesLeaseOnSelection()
AddAssert("selected room is disabled", () => loungeScreen.SelectedRoom.Disabled);
}

[Test]
public void TestFilterTextCount()
{
AddAssert("filter text is 0 matches", () => this.ChildrenOfType<ShearedFilterTextBox>().Single().FilterText.ToString(), () => Is.EqualTo("0 matches"));

AddStep("add 10 rooms", () => RoomManager.AddRooms(10));

AddAssert("filter text is 10 matches", () => this.ChildrenOfType<ShearedFilterTextBox>().Single().FilterText.ToString(), () => Is.EqualTo("10 matches"));

AddStep("search for room 1", () => this.ChildrenOfType<ShearedFilterTextBox>().Single().Current.Value = "room 1");

AddUntilStep("filter text is 1 match", () => this.ChildrenOfType<ShearedFilterTextBox>().Single().FilterText.ToString(), () => Is.EqualTo("1 match"));

AddStep("begin loading operation", () => loadingOperation = OngoingOperationTracker.BeginOperation());

AddAssert("filter text is loading...", () => this.ChildrenOfType<ShearedFilterTextBox>().Single().FilterText.ToString(), () => Is.EqualTo("loading..."));

AddStep("finish loading operation", () =>
{
loadingOperation?.Dispose();
loadingOperation = null;
});
}

private bool checkRoomVisible(DrawableRoom room) =>
loungeScreen.ChildrenOfType<OsuScrollContainer>().First().ScreenSpaceDrawQuad
.Contains(room.ScreenSpaceDrawQuad.Centre);
Expand Down
54 changes: 54 additions & 0 deletions osu.Game/Graphics/UserInterface/ShearedFilterTextBox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Localisation;
using osu.Game.Graphics.Sprites;

namespace osu.Game.Graphics.UserInterface
{
public partial class ShearedFilterTextBox : ShearedSearchTextBox
{
private const float filter_text_size = 12;

public LocalisableString FilterText
{
get => ((InnerFilterTextBox)TextBox).FilterText.Text;
set => ((InnerFilterTextBox)TextBox).FilterText.Text = value;
}

public ShearedFilterTextBox()
{
Height += filter_text_size;
}

protected override InnerSearchTextBox CreateInnerTextBox() => new InnerFilterTextBox();

protected partial class InnerFilterTextBox : InnerSearchTextBox
{
public OsuSpriteText FilterText { get; private set; } = null!;

[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
TextContainer.Add(FilterText = new OsuSpriteText
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.TopLeft,
Font = OsuFont.Default.With(size: filter_text_size, weight: FontWeight.SemiBold),
Margin = new MarginPadding { Top = 2, Left = 2 },
Colour = colours.Yellow
});
}

protected override void LoadComplete()
{
base.LoadComplete();

TextContainer.Height *= (DrawHeight - filter_text_size) / DrawHeight;
TextContainer.Margin = new MarginPadding { Bottom = filter_text_size };
}
}
}
}
44 changes: 24 additions & 20 deletions osu.Game/Graphics/UserInterface/ShearedSearchTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,33 @@ public partial class ShearedSearchTextBox : CompositeDrawable, IHasCurrentValue<
private const float corner_radius = 7;

private readonly Box background;
private readonly SearchTextBox textBox;
protected readonly InnerSearchTextBox TextBox;

public Bindable<string> Current
{
get => textBox.Current;
set => textBox.Current = value;
get => TextBox.Current;
set => TextBox.Current = value;
}

public bool HoldFocus
{
get => textBox.HoldFocus;
set => textBox.HoldFocus = value;
get => TextBox.HoldFocus;
set => TextBox.HoldFocus = value;
}

public LocalisableString PlaceholderText
{
get => textBox.PlaceholderText;
set => textBox.PlaceholderText = value;
get => TextBox.PlaceholderText;
set => TextBox.PlaceholderText = value;
}

public new bool HasFocus => textBox.HasFocus;
public new bool HasFocus => TextBox.HasFocus;

public void TakeFocus() => textBox.TakeFocus();
public void TakeFocus() => TextBox.TakeFocus();

public void KillFocus() => textBox.KillFocus();
public void KillFocus() => TextBox.KillFocus();

public bool SelectAll() => textBox.SelectAll();
public bool SelectAll() => TextBox.SelectAll();

public ShearedSearchTextBox()
{
Expand All @@ -69,13 +69,7 @@ public ShearedSearchTextBox()
{
new Drawable[]
{
textBox = new InnerSearchTextBox
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
RelativeSizeAxes = Axes.Both,
Size = Vector2.One
},
TextBox = CreateInnerTextBox(),
new SpriteIcon
{
Icon = FontAwesome.Solid.Search,
Expand All @@ -101,10 +95,20 @@ private void load(OverlayColourProvider colourProvider)
background.Colour = colourProvider.Background3;
}

public override bool HandleNonPositionalInput => textBox.HandleNonPositionalInput;
public override bool HandleNonPositionalInput => TextBox.HandleNonPositionalInput;

protected virtual InnerSearchTextBox CreateInnerTextBox() => new InnerSearchTextBox();

private partial class InnerSearchTextBox : SearchTextBox
protected partial class InnerSearchTextBox : SearchTextBox
{
public InnerSearchTextBox()
{
Anchor = Anchor.CentreLeft;
Origin = Anchor.CentreLeft;
RelativeSizeAxes = Axes.Both;
Size = Vector2.One;
}

[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public partial class RoomsContainer : CompositeDrawable, IKeyBindingHandler<Glob

public IReadOnlyList<DrawableRoom> Rooms => roomFlow.FlowingChildren.Cast<DrawableRoom>().ToArray();

public Bindable<int> VisibleRoomCount = new Bindable<int>();

private readonly IBindableList<Room> rooms = new BindableList<Room>();
private readonly FillFlowContainer<DrawableLoungeRoom> roomFlow;

Expand Down Expand Up @@ -94,6 +96,8 @@ private void applyFilterCriteria(FilterCriteria criteria)
}
});

VisibleRoomCount.Value = roomFlow.Count(r => r.MatchingFilter);

static bool matchPermissions(DrawableLoungeRoom room, RoomPermissionsFilter accessType)
{
switch (accessType)
Expand Down
29 changes: 24 additions & 5 deletions osu.Game/Screens/OnlinePlay/Lounge/LoungeSubScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public abstract partial class LoungeSubScreen : OnlinePlaySubScreen
private PopoverContainer popoverContainer;
private LoadingLayer loadingLayer;
private RoomsContainer roomsContainer;
private SearchTextBox searchTextBox;
private ShearedFilterTextBox searchTextBox;
private Dropdown<RoomStatusFilter> statusDropdown;

[BackgroundDependencyLoader(true)]
Expand Down Expand Up @@ -135,7 +135,7 @@ private void load([CanBeNull] IdleTracker idleTracker)
{
RelativeSizeAxes = Axes.X,
Height = Header.HEIGHT,
Child = searchTextBox = new BasicSearchTextBox
Child = searchTextBox = new ShearedFilterTextBox
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Expand Down Expand Up @@ -196,10 +196,17 @@ protected override void LoadComplete()
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();
}
Expand Down Expand Up @@ -382,12 +389,24 @@ protected virtual void OpenNewRoom(Room room)
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)
Expand Down
Loading