From f581df47c8edcf03771ae1e019323f0a23301995 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 8 Sep 2020 18:25:09 +0900 Subject: [PATCH] Add "New collection..." item to dropdown --- .../SongSelect/TestSceneFilterControl.cs | 23 +++++++++++++++++++ osu.Game/Screens/Select/CollectionFilter.cs | 17 ++++++++++++++ .../Select/CollectionFilterDropdown.cs | 18 ++++++++++++--- 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs index 4606c7b0c3..955fe04c8c 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestSceneFilterControl.cs @@ -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().Single().ChildrenOfType().First().Text == collectionName)); diff --git a/osu.Game/Screens/Select/CollectionFilter.cs b/osu.Game/Screens/Select/CollectionFilter.cs index 7628ed391e..9e36e3e089 100644 --- a/osu.Game/Screens/Select/CollectionFilter.cs +++ b/osu.Game/Screens/Select/CollectionFilter.cs @@ -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..."; + } + } } diff --git a/osu.Game/Screens/Select/CollectionFilterDropdown.cs b/osu.Game/Screens/Select/CollectionFilterDropdown.cs index 4e9e12fcaf..5e5c684fe2 100644 --- a/osu.Game/Screens/Select/CollectionFilterDropdown.cs +++ b/osu.Game/Screens/Select/CollectionFilterDropdown.cs @@ -29,6 +29,9 @@ namespace osu.Game.Screens.Select private readonly IBindableList beatmaps = new BindableList(); private readonly BindableList filters = new BindableList(); + [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]; } /// @@ -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(); + } } /// @@ -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 {