1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 17:47:29 +08:00

Make playlist filtering work.

Also standardises searchable terms in beatmap metadata.
This commit is contained in:
Dean Herbert 2017-05-02 10:45:55 +09:00
parent b07af21202
commit 6074cb5979
5 changed files with 60 additions and 16 deletions

View File

@ -22,5 +22,15 @@ namespace osu.Game.Database
public int PreviewTime { get; set; }
public string AudioFile { get; set; }
public string BackgroundFile { get; set; }
public string[] SearchableTerms => new[]
{
Artist,
ArtistUnicode,
Title,
TitleUnicode,
Source,
Tags
};
}
}

View File

@ -15,7 +15,7 @@ using osu.Framework.Localisation;
namespace osu.Game.Overlays.Music
{
internal class PlaylistItem : Container
internal class PlaylistItem : Container, IFilterable
{
private const float fade_duration = 100;
@ -56,6 +56,8 @@ namespace osu.Game.Overlays.Music
{
BeatmapMetadata metadata = BeatmapSetInfo.Metadata;
FilterTerms = metadata.SearchableTerms;
Children = new Drawable[]
{
handle = new TextAwesome
@ -115,5 +117,21 @@ namespace osu.Game.Overlays.Music
OnSelect?.Invoke(BeatmapSetInfo);
return true;
}
public string[] FilterTerms { get; private set; }
private bool matching = true;
public bool MatchingCurrentFilter
{
set
{
if (matching == value) return;
matching = value;
FadeTo(matching ? 1 : 0, 200);
}
}
}
}

View File

@ -29,6 +29,10 @@ namespace osu.Game.Overlays.Music
public Action<BeatmapSetInfo> OnSelect;
private readonly SearchContainer search;
public void Filter(string searchTerm) => search.SearchTerm = searchTerm;
public BeatmapSetInfo SelectedItem
{
get { return items.Children.FirstOrDefault(i => i.Selected)?.BeatmapSetInfo; }
@ -48,14 +52,36 @@ namespace osu.Game.Overlays.Music
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
items = new FillFlowContainer<PlaylistItem>
search = new SearchContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
},
Children = new Drawable[]
{
items = new ItemSearchContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
},
}
}
},
},
};
}
private class ItemSearchContainer : FillFlowContainer<PlaylistItem>, IHasFilterableChildren
{
public string[] FilterTerms => new string[] { };
public bool MatchingCurrentFilter { set { } }
public IEnumerable<IFilterable> FilterableChildren => Children;
public ItemSearchContainer()
{
LayoutDuration = 200;
LayoutEasing = EasingTypes.OutQuint;
}
}
}
}

View File

@ -74,7 +74,7 @@ namespace osu.Game.Overlays.Music
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
ExitRequested = () => State = Visibility.Hidden,
FilterChanged = filterChanged,
FilterChanged = search => list.Filter(search),
Padding = new MarginPadding(10),
},
},
@ -86,11 +86,6 @@ namespace osu.Game.Overlays.Music
beatmapBacking.BindTo(game.Beatmap);
}
private void filterChanged(string newValue)
{
// TODO: implement
}
protected override void LoadComplete()
{
base.LoadComplete();

View File

@ -27,13 +27,8 @@ namespace osu.Game.Screens.Select
bool match = hasCurrentMode;
match &= string.IsNullOrEmpty(SearchText)
|| (set.Metadata.Artist ?? string.Empty).IndexOf(SearchText, StringComparison.InvariantCultureIgnoreCase) != -1
|| (set.Metadata.ArtistUnicode ?? string.Empty).IndexOf(SearchText, StringComparison.InvariantCultureIgnoreCase) != -1
|| (set.Metadata.Title ?? string.Empty).IndexOf(SearchText, StringComparison.InvariantCultureIgnoreCase) != -1
|| (set.Metadata.TitleUnicode ?? string.Empty).IndexOf(SearchText, StringComparison.InvariantCultureIgnoreCase) != -1
|| (set.Metadata.Tags ?? string.Empty).IndexOf(SearchText, StringComparison.InvariantCultureIgnoreCase) != -1
|| (set.Metadata.Source ?? string.Empty).IndexOf(SearchText, StringComparison.InvariantCultureIgnoreCase) != -1;
if (!string.IsNullOrEmpty(SearchText))
match &= set.Metadata.SearchableTerms.Any(term => term.IndexOf(SearchText, StringComparison.InvariantCultureIgnoreCase) >= 0);
switch (g.State)
{