1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 03:25:11 +08:00

Rename to CollectionMenuItem

This commit is contained in:
smoogipoo 2020-09-09 23:11:19 +09:00
parent 43525614ad
commit 6b56c6e83f
3 changed files with 21 additions and 31 deletions

View File

@ -231,7 +231,7 @@ namespace osu.Game.Tests.Visual.SongSelect
InputManager.Click(MouseButton.Left);
});
private IEnumerable<Dropdown<CollectionFilter>.DropdownMenu.DrawableDropdownMenuItem> getCollectionDropdownItems()
=> control.ChildrenOfType<CollectionFilterDropdown>().Single().ChildrenOfType<Dropdown<CollectionFilter>.DropdownMenu.DrawableDropdownMenuItem>();
private IEnumerable<Dropdown<CollectionMenuItem>.DropdownMenu.DrawableDropdownMenuItem> getCollectionDropdownItems()
=> control.ChildrenOfType<CollectionFilterDropdown>().Single().ChildrenOfType<Dropdown<CollectionMenuItem>.DropdownMenu.DrawableDropdownMenuItem>();
}
}

View File

@ -21,13 +21,13 @@ using osuTK;
namespace osu.Game.Screens.Select
{
/// <summary>
/// A dropdown to select the <see cref="CollectionFilter"/> to filter beatmaps using.
/// A dropdown to select the <see cref="CollectionMenuItem"/> to filter beatmaps using.
/// </summary>
public class CollectionFilterDropdown : OsuDropdown<CollectionFilter>
public class CollectionFilterDropdown : OsuDropdown<CollectionMenuItem>
{
private readonly IBindableList<BeatmapCollection> collections = new BindableList<BeatmapCollection>();
private readonly IBindableList<BeatmapInfo> beatmaps = new BindableList<BeatmapInfo>();
private readonly BindableList<CollectionFilter> filters = new BindableList<CollectionFilter>();
private readonly BindableList<CollectionMenuItem> filters = new BindableList<CollectionMenuItem>();
[Resolved(CanBeNull = true)]
private ManageCollectionsDialog manageCollectionsDialog { get; set; }
@ -62,17 +62,17 @@ namespace osu.Game.Screens.Select
var selectedItem = SelectedItem?.Value?.Collection;
filters.Clear();
filters.Add(new AllBeatmapCollectionFilter());
filters.AddRange(collections.Select(c => new CollectionFilter(c)));
filters.Add(new ManageCollectionsFilter());
filters.Add(new AllBeatmapsCollectionMenuItem());
filters.AddRange(collections.Select(c => new CollectionMenuItem(c)));
filters.Add(new ManageCollectionsMenuItem());
Current.Value = filters.SingleOrDefault(f => f.Collection != null && f.Collection == selectedItem) ?? filters[0];
}
/// <summary>
/// Occurs when the <see cref="CollectionFilter"/> selection has changed.
/// Occurs when the <see cref="CollectionMenuItem"/> selection has changed.
/// </summary>
private void filterChanged(ValueChangedEvent<CollectionFilter> filter)
private void filterChanged(ValueChangedEvent<CollectionMenuItem> filter)
{
// Binding the beatmaps will trigger a collection change event, which results in an infinite-loop. This is rebound later, when it's safe to do so.
beatmaps.CollectionChanged -= filterBeatmapsChanged;
@ -87,7 +87,7 @@ namespace osu.Game.Screens.Select
// 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 ManageCollectionsFilter)
if (filter.NewValue is ManageCollectionsMenuItem)
{
Current.Value = filter.OldValue;
manageCollectionsDialog?.Show();
@ -104,7 +104,7 @@ namespace osu.Game.Screens.Select
Current.TriggerChange();
}
protected override string GenerateItemText(CollectionFilter item) => item.CollectionName.Value;
protected override string GenerateItemText(CollectionMenuItem item) => item.CollectionName.Value;
protected override DropdownHeader CreateHeader() => new CollectionDropdownHeader
{
@ -115,7 +115,7 @@ namespace osu.Game.Screens.Select
public class CollectionDropdownHeader : OsuDropdownHeader
{
public readonly Bindable<CollectionFilter> SelectedItem = new Bindable<CollectionFilter>();
public readonly Bindable<CollectionMenuItem> SelectedItem = new Bindable<CollectionMenuItem>();
private readonly Bindable<string> collectionName = new Bindable<string>();
protected override string Label
@ -165,7 +165,7 @@ namespace osu.Game.Screens.Select
private class CollectionDropdownMenuItem : OsuDropdownMenu.DrawableOsuDropdownMenuItem
{
[NotNull]
protected new CollectionFilter Item => ((DropdownMenuItem<CollectionFilter>)base.Item).Value;
protected new CollectionMenuItem Item => ((DropdownMenuItem<CollectionMenuItem>)base.Item).Value;
[Resolved]
private OsuColour colours { get; set; }

View File

@ -1,10 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Bindables;
using osu.Game.Beatmaps;
using osu.Game.Collections;
namespace osu.Game.Screens.Select
@ -12,7 +10,7 @@ namespace osu.Game.Screens.Select
/// <summary>
/// A <see cref="BeatmapCollection"/> filter.
/// </summary>
public class CollectionFilter
public class CollectionMenuItem
{
/// <summary>
/// The collection to filter beatmaps from.
@ -28,35 +26,27 @@ namespace osu.Game.Screens.Select
public readonly Bindable<string> CollectionName;
/// <summary>
/// Creates a new <see cref="CollectionFilter"/>.
/// Creates a new <see cref="CollectionMenuItem"/>.
/// </summary>
/// <param name="collection">The collection to filter beatmaps from.</param>
public CollectionFilter([CanBeNull] BeatmapCollection collection)
public CollectionMenuItem([CanBeNull] BeatmapCollection collection)
{
Collection = collection;
CollectionName = Collection?.Name.GetBoundCopy() ?? new Bindable<string>("All beatmaps");
}
/// <summary>
/// Whether the collection contains a given beatmap.
/// </summary>
/// <param name="beatmap">The beatmap to check.</param>
/// <returns>Whether <see cref="Collection"/> contains <paramref name="beatmap"/>.</returns>
public virtual bool ContainsBeatmap(BeatmapInfo beatmap)
=> Collection?.Beatmaps.Any(b => b.Equals(beatmap)) ?? true;
}
public class AllBeatmapCollectionFilter : CollectionFilter
public class AllBeatmapsCollectionMenuItem : CollectionMenuItem
{
public AllBeatmapCollectionFilter()
public AllBeatmapsCollectionMenuItem()
: base(null)
{
}
}
public class ManageCollectionsFilter : CollectionFilter
public class ManageCollectionsMenuItem : CollectionMenuItem
{
public ManageCollectionsFilter()
public ManageCollectionsMenuItem()
: base(null)
{
CollectionName.Value = "Manage collections...";