mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 23:24:04 +09:00
General refactorings
This commit is contained in:
@ -52,7 +52,7 @@ namespace osu.Game.Screens.Select.Carousel
|
||||
private BeatmapCollectionManager collectionManager { get; set; }
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
private ManageCollectionDialog manageCollectionDialog { get; set; }
|
||||
private ManageCollectionsDialog manageCollectionsDialog { get; set; }
|
||||
|
||||
private IBindable<StarDifficulty> starDifficultyBindable;
|
||||
private CancellationTokenSource starDifficultyCancellationSource;
|
||||
@ -227,9 +227,9 @@ namespace osu.Game.Screens.Select.Carousel
|
||||
if (beatmap.OnlineBeatmapID.HasValue && beatmapOverlay != null)
|
||||
items.Add(new OsuMenuItem("Details", MenuItemType.Standard, () => beatmapOverlay.FetchAndShowBeatmap(beatmap.OnlineBeatmapID.Value)));
|
||||
|
||||
var collectionItems = collectionManager.Collections.OrderByDescending(c => c.LastModifyTime).Take(3).Select(createCollectionMenuItem).ToList();
|
||||
if (manageCollectionDialog != null)
|
||||
collectionItems.Add(new OsuMenuItem("More...", MenuItemType.Standard, manageCollectionDialog.Show));
|
||||
var collectionItems = collectionManager.Collections.OrderByDescending(c => c.LastModifyDate).Take(3).Select(createCollectionMenuItem).ToList();
|
||||
if (manageCollectionsDialog != null)
|
||||
collectionItems.Add(new OsuMenuItem("More...", MenuItemType.Standard, manageCollectionsDialog.Show));
|
||||
|
||||
items.Add(new OsuMenuItem("Add to...") { Items = collectionItems });
|
||||
|
||||
|
@ -39,7 +39,7 @@ namespace osu.Game.Screens.Select.Carousel
|
||||
private BeatmapCollectionManager collectionManager { get; set; }
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
private ManageCollectionDialog manageCollectionDialog { get; set; }
|
||||
private ManageCollectionsDialog manageCollectionsDialog { get; set; }
|
||||
|
||||
private readonly BeatmapSetInfo beatmapSet;
|
||||
|
||||
@ -148,9 +148,9 @@ namespace osu.Game.Screens.Select.Carousel
|
||||
if (dialogOverlay != null)
|
||||
items.Add(new OsuMenuItem("Delete", MenuItemType.Destructive, () => dialogOverlay.Push(new BeatmapDeleteDialog(beatmapSet))));
|
||||
|
||||
var collectionItems = collectionManager.Collections.OrderByDescending(c => c.LastModifyTime).Take(3).Select(createCollectionMenuItem).ToList();
|
||||
if (manageCollectionDialog != null)
|
||||
collectionItems.Add(new OsuMenuItem("More...", MenuItemType.Standard, manageCollectionDialog.Show));
|
||||
var collectionItems = collectionManager.Collections.OrderByDescending(c => c.LastModifyDate).Take(3).Select(createCollectionMenuItem).ToList();
|
||||
if (manageCollectionsDialog != null)
|
||||
collectionItems.Add(new OsuMenuItem("More...", MenuItemType.Standard, manageCollectionsDialog.Show));
|
||||
|
||||
items.Add(new OsuMenuItem("Add all to...") { Items = collectionItems });
|
||||
|
||||
|
@ -3,21 +3,45 @@
|
||||
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Collections;
|
||||
|
||||
namespace osu.Game.Screens.Select
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="BeatmapCollection"/> filter.
|
||||
/// </summary>
|
||||
public class CollectionFilter
|
||||
{
|
||||
/// <summary>
|
||||
/// The collection to filter beatmaps from.
|
||||
/// May be null to not filter by collection (include all beatmaps).
|
||||
/// </summary>
|
||||
[CanBeNull]
|
||||
public readonly BeatmapCollection Collection;
|
||||
|
||||
/// <summary>
|
||||
/// The name of the collection.
|
||||
/// </summary>
|
||||
[NotNull]
|
||||
public readonly Bindable<string> CollectionName;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="CollectionFilter"/>.
|
||||
/// </summary>
|
||||
/// <param name="collection">The collection to filter beatmaps from.</param>
|
||||
public CollectionFilter([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;
|
||||
}
|
||||
|
@ -19,6 +19,9 @@ using osuTK;
|
||||
|
||||
namespace osu.Game.Screens.Select
|
||||
{
|
||||
/// <summary>
|
||||
/// A dropdown to select the <see cref="CollectionFilter"/> to filter beatmaps using.
|
||||
/// </summary>
|
||||
public class CollectionFilterDropdown : OsuDropdown<CollectionFilter>
|
||||
{
|
||||
private readonly IBindableList<BeatmapCollection> collections = new BindableList<BeatmapCollection>();
|
||||
@ -64,6 +67,7 @@ namespace osu.Game.Screens.Select
|
||||
/// </summary>
|
||||
private void filterChanged(ValueChangedEvent<CollectionFilter> 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;
|
||||
|
||||
if (filter.OldValue?.Collection != null)
|
||||
@ -122,7 +126,7 @@ namespace osu.Game.Screens.Select
|
||||
private void updateBindable()
|
||||
{
|
||||
collectionName.UnbindAll();
|
||||
collectionName.BindTo(SelectedItem.Value.Collection?.Name ?? new Bindable<string>("All beatmaps"));
|
||||
collectionName.BindTo(SelectedItem.Value.CollectionName);
|
||||
collectionName.BindValueChanged(_ => updateText(), true);
|
||||
}
|
||||
|
||||
@ -164,7 +168,7 @@ namespace osu.Game.Screens.Select
|
||||
: base(item)
|
||||
{
|
||||
collectionBeatmaps = Item.Collection?.Beatmaps.GetBoundCopy();
|
||||
collectionName = Item.Collection?.Name.GetBoundCopy() ?? new Bindable<string>("All beatmaps");
|
||||
collectionName = Item.CollectionName.GetBoundCopy();
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
|
@ -4,6 +4,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Screens.Select.Filter;
|
||||
@ -51,6 +52,10 @@ namespace osu.Game.Screens.Select
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The collection to filter beatmaps from.
|
||||
/// </summary>
|
||||
[CanBeNull]
|
||||
public CollectionFilter Collection;
|
||||
|
||||
public struct OptionalRange<T> : IEquatable<OptionalRange<T>>
|
||||
|
Reference in New Issue
Block a user