mirror of
https://github.com/ppy/osu.git
synced 2024-12-05 10:23:20 +08:00
Merge pull request #30743 from peppy/collection-scroll-etc
Further UX improvements to collection management
This commit is contained in:
commit
a529cef28b
@ -12,6 +12,7 @@ using osu.Framework.Platform;
|
||||
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 @@ namespace osu.Game.Tests.Visual.Collections
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Solo]
|
||||
public void TestCollectionRenamedExternal()
|
||||
{
|
||||
BeatmapCollection first = null!;
|
||||
@ -338,10 +338,44 @@ namespace osu.Game.Tests.Visual.Collections
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,12 @@ namespace osu.Game.Collections
|
||||
/// </summary>
|
||||
public partial class DrawableCollectionList : OsuRearrangeableListContainer<Live<BeatmapCollection>>
|
||||
{
|
||||
public new MarginPadding Padding
|
||||
{
|
||||
get => base.Padding;
|
||||
set => base.Padding = value;
|
||||
}
|
||||
|
||||
protected override ScrollContainer<Drawable> CreateScrollContainer() => scroll = new Scroll();
|
||||
|
||||
[Resolved]
|
||||
@ -34,6 +40,12 @@ namespace osu.Game.Collections
|
||||
|
||||
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 }
|
||||
@ -46,6 +58,26 @@ namespace osu.Game.Collections
|
||||
realmSubscription = realm.RegisterForNotifications(r => r.All<BeatmapCollection>().OrderBy(c => c.Name), collectionsChanged);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When non-null, signifies that a new collection was created and should be presented to the user.
|
||||
/// </summary>
|
||||
private Guid? lastCreated;
|
||||
|
||||
protected override void OnItemsChanged()
|
||||
{
|
||||
base.OnItemsChanged();
|
||||
|
||||
if (lastCreated != null)
|
||||
{
|
||||
var createdItem = flow.Children.SingleOrDefault(item => item.Model.Value.ID == lastCreated);
|
||||
|
||||
if (createdItem != null)
|
||||
scroll.ScrollTo(createdItem);
|
||||
|
||||
lastCreated = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void collectionsChanged(IRealmCollection<BeatmapCollection> collections, ChangeSet? changes)
|
||||
{
|
||||
if (changes == null)
|
||||
@ -60,7 +92,11 @@ namespace osu.Game.Collections
|
||||
foreach (int i in changes.InsertedIndices)
|
||||
Items.Insert(i, collections[i].ToLive(realm));
|
||||
|
||||
if (changes.InsertedIndices.Length == 1)
|
||||
lastCreated = collections[changes.InsertedIndices[0]].ID;
|
||||
|
||||
foreach (int i in changes.NewModifiedIndices)
|
||||
|
||||
{
|
||||
var updatedItem = collections[i];
|
||||
|
||||
@ -104,8 +140,7 @@ namespace osu.Game.Collections
|
||||
|
||||
public Scroll()
|
||||
{
|
||||
ScrollbarVisible = false;
|
||||
Padding = new MarginPadding(10);
|
||||
ScrollbarOverlapsContent = false;
|
||||
|
||||
base.Content.Add(new FillFlowContainer
|
||||
{
|
||||
@ -133,7 +168,7 @@ namespace osu.Game.Collections
|
||||
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>
|
||||
@ -179,7 +214,7 @@ namespace osu.Game.Collections
|
||||
/// <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>();
|
||||
|
||||
@ -187,6 +222,8 @@ namespace osu.Game.Collections
|
||||
{
|
||||
Spacing = new Vector2(0, 5);
|
||||
LayoutEasing = Easing.OutQuint;
|
||||
|
||||
Padding = new MarginPadding { Right = 5 };
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
|
@ -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.Shapes;
|
||||
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 @@ namespace osu.Game.Collections
|
||||
|
||||
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.Containers;
|
||||
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 @@ namespace osu.Game.Collections
|
||||
|
||||
private IDisposable? duckOperation;
|
||||
|
||||
private BasicSearchTextBox searchTextBox = null!;
|
||||
private DrawableCollectionList list = null!;
|
||||
|
||||
[Resolved]
|
||||
private MusicController? musicController { get; set; }
|
||||
|
||||
@ -104,10 +108,31 @@ namespace osu.Game.Collections
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = colours.GreySeaFoamDarker
|
||||
},
|
||||
new DrawableCollectionList
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
}
|
||||
Padding = new MarginPadding(10),
|
||||
Children = new Drawable[]
|
||||
{
|
||||
searchTextBox = new BasicSearchTextBox
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Y = 10,
|
||||
Height = 40,
|
||||
ReleaseFocusOnCommit = false,
|
||||
HoldFocus = true,
|
||||
PlaceholderText = HomeStrings.SearchPlaceholder,
|
||||
},
|
||||
list = new DrawableCollectionList
|
||||
{
|
||||
Padding = new MarginPadding
|
||||
{
|
||||
Top = 60,
|
||||
},
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -117,6 +142,16 @@ namespace osu.Game.Collections
|
||||
};
|
||||
}
|
||||
|
||||
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
Block a user