mirror of
https://github.com/ppy/osu
synced 2024-12-26 00:32:52 +00:00
Hook up now playing overlay to collections
This commit is contained in:
parent
a6a76de7a9
commit
fcc8683629
@ -7,13 +7,15 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Effects;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Game.Collections;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
|
||||
namespace osu.Game.Overlays.Music
|
||||
{
|
||||
public class CollectionsDropdown<T> : OsuDropdown<T>
|
||||
/// <summary>
|
||||
/// A <see cref="CollectionFilterDropdown"/> for use in the <see cref="NowPlayingOverlay"/>.
|
||||
/// </summary>
|
||||
public class CollectionDropdown : CollectionFilterDropdown
|
||||
{
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
@ -21,11 +23,11 @@ namespace osu.Game.Overlays.Music
|
||||
AccentColour = colours.Gray6;
|
||||
}
|
||||
|
||||
protected override DropdownHeader CreateHeader() => new CollectionsHeader();
|
||||
protected override CollectionDropdownHeader CreateCollectionHeader() => new CollectionsHeader();
|
||||
|
||||
protected override DropdownMenu CreateMenu() => new CollectionsMenu();
|
||||
protected override CollectionDropdownMenu CreateCollectionMenu() => new CollectionsMenu();
|
||||
|
||||
private class CollectionsMenu : OsuDropdownMenu
|
||||
private class CollectionsMenu : CollectionDropdownMenu
|
||||
{
|
||||
public CollectionsMenu()
|
||||
{
|
||||
@ -40,7 +42,7 @@ namespace osu.Game.Overlays.Music
|
||||
}
|
||||
}
|
||||
|
||||
private class CollectionsHeader : OsuDropdownHeader
|
||||
private class CollectionsHeader : CollectionDropdownHeader
|
||||
{
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
@ -8,13 +8,15 @@ using osu.Game.Graphics.UserInterface;
|
||||
using osuTK;
|
||||
using System;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
|
||||
namespace osu.Game.Overlays.Music
|
||||
{
|
||||
public class FilterControl : Container
|
||||
{
|
||||
public Action<FilterCriteria> FilterChanged;
|
||||
|
||||
public readonly FilterTextBox Search;
|
||||
private readonly CollectionDropdown collectionDropdown;
|
||||
|
||||
public FilterControl()
|
||||
{
|
||||
@ -32,21 +34,27 @@ namespace osu.Game.Overlays.Music
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = 40,
|
||||
},
|
||||
new CollectionsDropdown<PlaylistCollection>
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Items = new[] { PlaylistCollection.All },
|
||||
}
|
||||
collectionDropdown = new CollectionDropdown { RelativeSizeAxes = Axes.X }
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Search.Current.ValueChanged += current_ValueChanged;
|
||||
}
|
||||
|
||||
private void current_ValueChanged(ValueChangedEvent<string> e) => FilterChanged?.Invoke(e.NewValue);
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
public Action<string> FilterChanged;
|
||||
Search.Current.BindValueChanged(_ => updateCriteria());
|
||||
collectionDropdown.Current.BindValueChanged(_ => updateCriteria(), true);
|
||||
}
|
||||
|
||||
private void updateCriteria() => FilterChanged?.Invoke(createCriteria());
|
||||
|
||||
private FilterCriteria createCriteria() => new FilterCriteria
|
||||
{
|
||||
SearchText = Search.Text,
|
||||
Collection = collectionDropdown.Current.Value?.Collection
|
||||
};
|
||||
|
||||
public class FilterTextBox : SearchTextBox
|
||||
{
|
||||
|
22
osu.Game/Overlays/Music/FilterCriteria.cs
Normal file
22
osu.Game/Overlays/Music/FilterCriteria.cs
Normal file
@ -0,0 +1,22 @@
|
||||
// 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 JetBrains.Annotations;
|
||||
using osu.Game.Collections;
|
||||
|
||||
namespace osu.Game.Overlays.Music
|
||||
{
|
||||
public class FilterCriteria
|
||||
{
|
||||
/// <summary>
|
||||
/// The search text.
|
||||
/// </summary>
|
||||
public string SearchText;
|
||||
|
||||
/// <summary>
|
||||
/// The collection to filter beatmaps from.
|
||||
/// </summary>
|
||||
[CanBeNull]
|
||||
public BeatmapCollection Collection;
|
||||
}
|
||||
}
|
@ -24,7 +24,15 @@ namespace osu.Game.Overlays.Music
|
||||
set => base.Padding = value;
|
||||
}
|
||||
|
||||
public void Filter(string searchTerm) => ((SearchContainer<RearrangeableListItem<BeatmapSetInfo>>)ListContainer).SearchTerm = searchTerm;
|
||||
public void Filter(FilterCriteria criteria)
|
||||
{
|
||||
var items = (SearchContainer<RearrangeableListItem<BeatmapSetInfo>>)ListContainer;
|
||||
|
||||
foreach (var item in items.OfType<PlaylistItem>())
|
||||
item.InSelectedCollection = criteria.Collection?.Beatmaps.Any(b => b.BeatmapSet.Equals(item.Model)) ?? true;
|
||||
|
||||
items.SearchTerm = criteria.SearchText;
|
||||
}
|
||||
|
||||
public BeatmapSetInfo FirstVisibleSet => Items.FirstOrDefault(i => ((PlaylistItem)ItemMap[i]).MatchingFilter);
|
||||
|
||||
|
@ -95,23 +95,40 @@ namespace osu.Game.Overlays.Music
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool inSelectedCollection = true;
|
||||
|
||||
public bool InSelectedCollection
|
||||
{
|
||||
get => inSelectedCollection;
|
||||
set
|
||||
{
|
||||
if (inSelectedCollection == value)
|
||||
return;
|
||||
|
||||
inSelectedCollection = value;
|
||||
updateFilter();
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<string> FilterTerms { get; }
|
||||
|
||||
private bool matching = true;
|
||||
private bool matchingFilter = true;
|
||||
|
||||
public bool MatchingFilter
|
||||
{
|
||||
get => matching;
|
||||
get => matchingFilter && inSelectedCollection;
|
||||
set
|
||||
{
|
||||
if (matching == value) return;
|
||||
if (matchingFilter == value)
|
||||
return;
|
||||
|
||||
matching = value;
|
||||
|
||||
this.FadeTo(matching ? 1 : 0, 200);
|
||||
matchingFilter = value;
|
||||
updateFilter();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateFilter() => this.FadeTo(MatchingFilter ? 1 : 0, 200);
|
||||
|
||||
public bool FilteringActive { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ namespace osu.Game.Overlays.Music
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
FilterChanged = search => list.Filter(search),
|
||||
FilterChanged = criteria => list.Filter(criteria),
|
||||
Padding = new MarginPadding(10),
|
||||
},
|
||||
},
|
||||
@ -124,10 +124,4 @@ namespace osu.Game.Overlays.Music
|
||||
beatmap.Value.Track.Restart();
|
||||
}
|
||||
}
|
||||
|
||||
//todo: placeholder
|
||||
public enum PlaylistCollection
|
||||
{
|
||||
All
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user