1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 13:37:25 +08:00

Add "New collection..." item to dropdown

This commit is contained in:
smoogipoo 2020-09-08 18:25:09 +09:00
parent 070704cba7
commit f581df47c8
3 changed files with 55 additions and 3 deletions

View File

@ -184,6 +184,29 @@ namespace osu.Game.Tests.Visual.SongSelect
AddAssert("button is plus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.PlusSquare));
}
[Test]
public void TestNewCollectionFilterIsNotSelected()
{
addExpandHeaderStep();
AddStep("add collection", () => collectionManager.Collections.Add(new BeatmapCollection { Name = { Value = "1" } }));
AddStep("select collection", () =>
{
InputManager.MoveMouseTo(getCollectionDropdownItems().ElementAt(1));
InputManager.Click(MouseButton.Left);
});
addExpandHeaderStep();
AddStep("click manage collections filter", () =>
{
InputManager.MoveMouseTo(getCollectionDropdownItems().Last());
InputManager.Click(MouseButton.Left);
});
AddAssert("collection filter still selected", () => control.CreateCriteria().Collection?.CollectionName.Value == "1");
}
private void assertCollectionHeaderDisplays(string collectionName, bool shouldDisplay = true)
=> AddAssert($"collection dropdown header displays '{collectionName}'",
() => shouldDisplay == (control.ChildrenOfType<CollectionFilterDropdown.CollectionDropdownHeader>().Single().ChildrenOfType<SpriteText>().First().Text == collectionName));

View File

@ -45,4 +45,21 @@ namespace osu.Game.Screens.Select
public virtual bool ContainsBeatmap(BeatmapInfo beatmap)
=> Collection?.Beatmaps.Any(b => b.Equals(beatmap)) ?? true;
}
public class AllBeatmapCollectionFilter : CollectionFilter
{
public AllBeatmapCollectionFilter()
: base(null)
{
}
}
public class NewCollectionFilter : CollectionFilter
{
public NewCollectionFilter()
: base(null)
{
CollectionName.Value = "New collection...";
}
}
}

View File

@ -29,6 +29,9 @@ namespace osu.Game.Screens.Select
private readonly IBindableList<BeatmapInfo> beatmaps = new BindableList<BeatmapInfo>();
private readonly BindableList<CollectionFilter> filters = new BindableList<CollectionFilter>();
[Resolved(CanBeNull = true)]
private ManageCollectionsDialog manageCollectionsDialog { get; set; }
public CollectionFilterDropdown()
{
ItemSource = filters;
@ -57,10 +60,11 @@ namespace osu.Game.Screens.Select
var selectedItem = SelectedItem?.Value?.Collection;
filters.Clear();
filters.Add(new CollectionFilter(null));
filters.Add(new AllBeatmapCollectionFilter());
filters.AddRange(collections.Select(c => new CollectionFilter(c)));
filters.Add(new NewCollectionFilter());
Current.Value = filters.SingleOrDefault(f => f.Collection == selectedItem) ?? filters[0];
Current.Value = filters.SingleOrDefault(f => f.Collection != null && f.Collection == selectedItem) ?? filters[0];
}
/// <summary>
@ -78,6 +82,14 @@ namespace osu.Game.Screens.Select
beatmaps.BindTo(filter.NewValue.Collection.Beatmaps);
beatmaps.CollectionChanged += filterBeatmapsChanged;
// Never select the manage collection filter - rollback to the previous filter.
// This is done after the above since it is important that bindable is unbound from OldValue, which is lost after forcing it back to the old value.
if (filter.NewValue is NewCollectionFilter)
{
Current.Value = filter.OldValue;
manageCollectionsDialog?.Show();
}
}
/// <summary>
@ -90,7 +102,7 @@ namespace osu.Game.Screens.Select
Current.TriggerChange();
}
protected override string GenerateItemText(CollectionFilter item) => item.Collection?.Name.Value ?? "All beatmaps";
protected override string GenerateItemText(CollectionFilter item) => item.CollectionName.Value;
protected override DropdownHeader CreateHeader() => new CollectionDropdownHeader
{