mirror of
https://github.com/ppy/osu
synced 2024-12-14 10:57:41 +00:00
Split filter control into separate class
This commit is contained in:
parent
120dfd50a6
commit
c1d255a04c
24
osu.Game/Screens/Select/CollectionFilter.cs
Normal file
24
osu.Game/Screens/Select/CollectionFilter.cs
Normal file
@ -0,0 +1,24 @@
|
||||
// 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.Game.Beatmaps;
|
||||
using osu.Game.Collections;
|
||||
|
||||
namespace osu.Game.Screens.Select
|
||||
{
|
||||
public class CollectionFilter
|
||||
{
|
||||
[CanBeNull]
|
||||
public readonly BeatmapCollection Collection;
|
||||
|
||||
public CollectionFilter([CanBeNull] BeatmapCollection collection)
|
||||
{
|
||||
Collection = collection;
|
||||
}
|
||||
|
||||
public virtual bool ContainsBeatmap(BeatmapInfo beatmap)
|
||||
=> Collection?.Beatmaps.Any(b => b.Equals(beatmap)) ?? true;
|
||||
}
|
||||
}
|
@ -19,11 +19,11 @@ using osuTK;
|
||||
|
||||
namespace osu.Game.Screens.Select
|
||||
{
|
||||
public class CollectionFilterDropdown : OsuDropdown<FilterControl.CollectionFilter>
|
||||
public class CollectionFilterDropdown : OsuDropdown<CollectionFilter>
|
||||
{
|
||||
private readonly IBindableList<BeatmapCollection> collections = new BindableList<BeatmapCollection>();
|
||||
private readonly IBindableList<BeatmapInfo> beatmaps = new BindableList<BeatmapInfo>();
|
||||
private readonly BindableList<FilterControl.CollectionFilter> filters = new BindableList<FilterControl.CollectionFilter>();
|
||||
private readonly BindableList<CollectionFilter> filters = new BindableList<CollectionFilter>();
|
||||
|
||||
public CollectionFilterDropdown()
|
||||
{
|
||||
@ -53,16 +53,16 @@ namespace osu.Game.Screens.Select
|
||||
var selectedItem = SelectedItem?.Value?.Collection;
|
||||
|
||||
filters.Clear();
|
||||
filters.Add(new FilterControl.CollectionFilter(null));
|
||||
filters.AddRange(collections.Select(c => new FilterControl.CollectionFilter(c)));
|
||||
filters.Add(new CollectionFilter(null));
|
||||
filters.AddRange(collections.Select(c => new CollectionFilter(c)));
|
||||
|
||||
Current.Value = filters.SingleOrDefault(f => f.Collection == selectedItem) ?? filters[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the <see cref="FilterControl.CollectionFilter"/> selection has changed.
|
||||
/// Occurs when the <see cref="CollectionFilter"/> selection has changed.
|
||||
/// </summary>
|
||||
private void filterChanged(ValueChangedEvent<FilterControl.CollectionFilter> filter)
|
||||
private void filterChanged(ValueChangedEvent<CollectionFilter> filter)
|
||||
{
|
||||
beatmaps.CollectionChanged -= filterBeatmapsChanged;
|
||||
|
||||
@ -85,7 +85,7 @@ namespace osu.Game.Screens.Select
|
||||
Current.TriggerChange();
|
||||
}
|
||||
|
||||
protected override string GenerateItemText(FilterControl.CollectionFilter item) => item.Collection?.Name.Value ?? "All beatmaps";
|
||||
protected override string GenerateItemText(CollectionFilter item) => item.Collection?.Name.Value ?? "All beatmaps";
|
||||
|
||||
protected override DropdownHeader CreateHeader() => new CollectionDropdownHeader
|
||||
{
|
||||
@ -96,7 +96,7 @@ namespace osu.Game.Screens.Select
|
||||
|
||||
private class CollectionDropdownHeader : OsuDropdownHeader
|
||||
{
|
||||
public readonly Bindable<FilterControl.CollectionFilter> SelectedItem = new Bindable<FilterControl.CollectionFilter>();
|
||||
public readonly Bindable<CollectionFilter> SelectedItem = new Bindable<CollectionFilter>();
|
||||
private readonly Bindable<string> collectionName = new Bindable<string>();
|
||||
|
||||
protected override string Label
|
||||
@ -143,7 +143,7 @@ namespace osu.Game.Screens.Select
|
||||
private class CollectionDropdownMenuItem : OsuDropdownMenu.DrawableOsuDropdownMenuItem
|
||||
{
|
||||
[NotNull]
|
||||
protected new FilterControl.CollectionFilter Item => ((DropdownMenuItem<FilterControl.CollectionFilter>)base.Item).Value;
|
||||
protected new CollectionFilter Item => ((DropdownMenuItem<CollectionFilter>)base.Item).Value;
|
||||
|
||||
[Resolved]
|
||||
private OsuColour colours { get; set; }
|
||||
|
@ -2,16 +2,12 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Collections;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
@ -199,20 +195,6 @@ namespace osu.Game.Screens.Select
|
||||
updateCriteria();
|
||||
}
|
||||
|
||||
public class CollectionFilter
|
||||
{
|
||||
[CanBeNull]
|
||||
public readonly BeatmapCollection Collection;
|
||||
|
||||
public CollectionFilter([CanBeNull] BeatmapCollection collection)
|
||||
{
|
||||
Collection = collection;
|
||||
}
|
||||
|
||||
public virtual bool ContainsBeatmap(BeatmapInfo beatmap)
|
||||
=> Collection?.Beatmaps.Any(b => b.Equals(beatmap)) ?? true;
|
||||
}
|
||||
|
||||
public void Deactivate()
|
||||
{
|
||||
searchTextBox.ReadOnly = true;
|
||||
|
@ -51,7 +51,7 @@ namespace osu.Game.Screens.Select
|
||||
}
|
||||
}
|
||||
|
||||
public FilterControl.CollectionFilter Collection;
|
||||
public CollectionFilter Collection;
|
||||
|
||||
public struct OptionalRange<T> : IEquatable<OptionalRange<T>>
|
||||
where T : struct
|
||||
|
Loading…
Reference in New Issue
Block a user