mirror of
https://github.com/ppy/osu.git
synced 2025-02-05 05:52:56 +08:00
Add "New collection..." item to dropdown
This commit is contained in:
parent
070704cba7
commit
f581df47c8
@ -184,6 +184,29 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
AddAssert("button is plus", () => getAddOrRemoveButton(1).Icon.Equals(FontAwesome.Solid.PlusSquare));
|
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)
|
private void assertCollectionHeaderDisplays(string collectionName, bool shouldDisplay = true)
|
||||||
=> AddAssert($"collection dropdown header displays '{collectionName}'",
|
=> AddAssert($"collection dropdown header displays '{collectionName}'",
|
||||||
() => shouldDisplay == (control.ChildrenOfType<CollectionFilterDropdown.CollectionDropdownHeader>().Single().ChildrenOfType<SpriteText>().First().Text == collectionName));
|
() => shouldDisplay == (control.ChildrenOfType<CollectionFilterDropdown.CollectionDropdownHeader>().Single().ChildrenOfType<SpriteText>().First().Text == collectionName));
|
||||||
|
@ -45,4 +45,21 @@ namespace osu.Game.Screens.Select
|
|||||||
public virtual bool ContainsBeatmap(BeatmapInfo beatmap)
|
public virtual bool ContainsBeatmap(BeatmapInfo beatmap)
|
||||||
=> Collection?.Beatmaps.Any(b => b.Equals(beatmap)) ?? true;
|
=> 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...";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,9 @@ namespace osu.Game.Screens.Select
|
|||||||
private readonly IBindableList<BeatmapInfo> beatmaps = new BindableList<BeatmapInfo>();
|
private readonly IBindableList<BeatmapInfo> beatmaps = new BindableList<BeatmapInfo>();
|
||||||
private readonly BindableList<CollectionFilter> filters = new BindableList<CollectionFilter>();
|
private readonly BindableList<CollectionFilter> filters = new BindableList<CollectionFilter>();
|
||||||
|
|
||||||
|
[Resolved(CanBeNull = true)]
|
||||||
|
private ManageCollectionsDialog manageCollectionsDialog { get; set; }
|
||||||
|
|
||||||
public CollectionFilterDropdown()
|
public CollectionFilterDropdown()
|
||||||
{
|
{
|
||||||
ItemSource = filters;
|
ItemSource = filters;
|
||||||
@ -57,10 +60,11 @@ namespace osu.Game.Screens.Select
|
|||||||
var selectedItem = SelectedItem?.Value?.Collection;
|
var selectedItem = SelectedItem?.Value?.Collection;
|
||||||
|
|
||||||
filters.Clear();
|
filters.Clear();
|
||||||
filters.Add(new CollectionFilter(null));
|
filters.Add(new AllBeatmapCollectionFilter());
|
||||||
filters.AddRange(collections.Select(c => new CollectionFilter(c)));
|
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>
|
/// <summary>
|
||||||
@ -78,6 +82,14 @@ namespace osu.Game.Screens.Select
|
|||||||
beatmaps.BindTo(filter.NewValue.Collection.Beatmaps);
|
beatmaps.BindTo(filter.NewValue.Collection.Beatmaps);
|
||||||
|
|
||||||
beatmaps.CollectionChanged += filterBeatmapsChanged;
|
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>
|
/// <summary>
|
||||||
@ -90,7 +102,7 @@ namespace osu.Game.Screens.Select
|
|||||||
Current.TriggerChange();
|
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
|
protected override DropdownHeader CreateHeader() => new CollectionDropdownHeader
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user