mirror of https://github.com/ppy/osu
Add search bar to collection management dialog
This commit is contained in:
parent
a570863854
commit
5ce1f7679b
|
@ -12,6 +12,7 @@
|
|||
using osu.Framework.Testing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Collections;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.Dialog;
|
||||
using osu.Game.Rulesets;
|
||||
|
@ -265,7 +266,6 @@ public void TestCollectionNotRemovedWhenDialogCancelled()
|
|||
}
|
||||
|
||||
[Test]
|
||||
[Solo]
|
||||
public void TestCollectionRenamedExternal()
|
||||
{
|
||||
BeatmapCollection first = null!;
|
||||
|
@ -338,10 +338,44 @@ public void TestCollectionRenamedOnTextChange(bool commitWithEnter)
|
|||
AddUntilStep("collection has new name", () => first.Name == "First");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSearch()
|
||||
{
|
||||
BeatmapCollection first = null!;
|
||||
|
||||
AddStep("add two collections", () =>
|
||||
{
|
||||
Realm.Write(r =>
|
||||
{
|
||||
r.Add(new[]
|
||||
{
|
||||
first = new BeatmapCollection(name: "1"),
|
||||
new BeatmapCollection(name: "2"),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
assertCollectionName(0, "1");
|
||||
assertCollectionName(1, "2");
|
||||
|
||||
AddStep("search for 1", () => dialog.ChildrenOfType<SearchTextBox>().Single().Current.Value = "1");
|
||||
|
||||
assertCollectionCount(1);
|
||||
|
||||
AddStep("change first collection name", () => Realm.Write(_ => first.Name = "First"));
|
||||
|
||||
assertCollectionCount(0);
|
||||
|
||||
AddStep("search for first", () => dialog.ChildrenOfType<SearchTextBox>().Single().Current.Value = "firs");
|
||||
|
||||
assertCollectionCount(1);
|
||||
}
|
||||
|
||||
private void assertCollectionCount(int count)
|
||||
=> AddUntilStep($"{count} collections shown", () => dialog.ChildrenOfType<DrawableCollectionListItem>().Count() == count + 1); // +1 for placeholder
|
||||
=> AddUntilStep($"{count} collections shown", () => dialog.ChildrenOfType<DrawableCollectionListItem>().Count(i => i.IsPresent) == count + 1); // +1 for placeholder
|
||||
|
||||
private void assertCollectionName(int index, string name)
|
||||
=> AddUntilStep($"item {index + 1} has correct name", () => dialog.ChildrenOfType<DrawableCollectionList>().Single().OrderedItems.ElementAt(index).ChildrenOfType<TextBox>().First().Text == name);
|
||||
=> AddUntilStep($"item {index + 1} has correct name",
|
||||
() => dialog.ChildrenOfType<DrawableCollectionList>().Single().OrderedItems.ElementAt(index).ChildrenOfType<TextBox>().First().Text == name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,12 @@ public partial class DrawableCollectionList : OsuRearrangeableListContainer<Live
|
|||
|
||||
public IEnumerable<Drawable> OrderedItems => flow.FlowingChildren;
|
||||
|
||||
public string SearchTerm
|
||||
{
|
||||
get => flow.SearchTerm;
|
||||
set => flow.SearchTerm = value;
|
||||
}
|
||||
|
||||
protected override FillFlowContainer<RearrangeableListItem<Live<BeatmapCollection>>> CreateListFillFlowContainer() => flow = new Flow
|
||||
{
|
||||
DragActive = { BindTarget = DragActive }
|
||||
|
@ -128,7 +134,6 @@ private partial class Scroll : OsuScrollContainer
|
|||
|
||||
public Scroll()
|
||||
{
|
||||
Padding = new MarginPadding(10);
|
||||
ScrollbarOverlapsContent = false;
|
||||
|
||||
base.Content.Add(new FillFlowContainer
|
||||
|
@ -157,7 +162,7 @@ protected override void Update()
|
|||
base.Update();
|
||||
|
||||
// AutoSizeAxes cannot be used as the height should represent the post-layout-transform height at all times, so that the placeholder doesn't bounce around.
|
||||
content.Height = ((Flow)Child).Children.Sum(c => c.DrawHeight + 5);
|
||||
content.Height = ((Flow)Child).Children.Sum(c => c.IsPresent ? c.DrawHeight + 5 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -203,7 +208,7 @@ protected override void LoadComplete()
|
|||
/// <summary>
|
||||
/// The flow of <see cref="DrawableCollectionListItem"/>. Disables layout easing unless a drag is in progress.
|
||||
/// </summary>
|
||||
private partial class Flow : FillFlowContainer<RearrangeableListItem<Live<BeatmapCollection>>>
|
||||
private partial class Flow : SearchContainer<RearrangeableListItem<Live<BeatmapCollection>>>
|
||||
{
|
||||
public readonly IBindable<bool> DragActive = new Bindable<bool>();
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
|
@ -10,6 +11,7 @@
|
|||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
|
@ -23,7 +25,7 @@ namespace osu.Game.Collections
|
|||
/// <summary>
|
||||
/// Visualises a <see cref="BeatmapCollection"/> inside a <see cref="DrawableCollectionList"/>.
|
||||
/// </summary>
|
||||
public partial class DrawableCollectionListItem : OsuRearrangeableListItem<Live<BeatmapCollection>>
|
||||
public partial class DrawableCollectionListItem : OsuRearrangeableListItem<Live<BeatmapCollection>>, IFilterable
|
||||
{
|
||||
private const float item_height = 35;
|
||||
private const float button_width = item_height * 0.75f;
|
||||
|
@ -207,5 +209,25 @@ protected override bool OnClick(ClickEvent e)
|
|||
|
||||
private void deleteCollection() => collection.PerformWrite(c => c.Realm!.Remove(c));
|
||||
}
|
||||
|
||||
public IEnumerable<LocalisableString> FilterTerms => [(LocalisableString)Model.Value.Name];
|
||||
|
||||
private bool matchingFilter = true;
|
||||
|
||||
public bool MatchingFilter
|
||||
{
|
||||
get => matchingFilter;
|
||||
set
|
||||
{
|
||||
matchingFilter = value;
|
||||
|
||||
if (matchingFilter)
|
||||
this.FadeIn(200);
|
||||
else
|
||||
Hide();
|
||||
}
|
||||
}
|
||||
|
||||
public bool FilteringActive { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Resources.Localisation.Web;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Collections
|
||||
|
@ -26,6 +27,9 @@ public partial class ManageCollectionsDialog : OsuFocusedOverlayContainer
|
|||
|
||||
private IDisposable? duckOperation;
|
||||
|
||||
private BasicSearchTextBox searchTextBox = null!;
|
||||
private DrawableCollectionList list = null!;
|
||||
|
||||
[Resolved]
|
||||
private MusicController? musicController { get; set; }
|
||||
|
||||
|
@ -104,10 +108,29 @@ private void load(OsuColour colours)
|
|||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = colours.GreySeaFoamDarker
|
||||
},
|
||||
new DrawableCollectionList
|
||||
new FillFlowContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
}
|
||||
Direction = FillDirection.Vertical,
|
||||
Padding = new MarginPadding(10),
|
||||
Spacing = new Vector2(0, 10),
|
||||
Children = new Drawable[]
|
||||
{
|
||||
searchTextBox = new BasicSearchTextBox
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Y = 10,
|
||||
Height = 40,
|
||||
ReleaseFocusOnCommit = false,
|
||||
HoldFocus = true,
|
||||
PlaceholderText = HomeStrings.SearchPlaceholder,
|
||||
},
|
||||
list = new DrawableCollectionList
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -117,6 +140,16 @@ private void load(OsuColour colours)
|
|||
};
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
searchTextBox.Current.BindValueChanged(_ =>
|
||||
{
|
||||
list.SearchTerm = searchTextBox.Current.Value;
|
||||
});
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
|
|
Loading…
Reference in New Issue