2020-02-04 08:00:36 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 08:43:03 +00:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2018-05-14 08:41:35 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 10:04:31 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2020-01-29 03:17:03 +00:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
|
using osu.Framework.Localisation;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Game.Beatmaps;
|
2020-01-29 03:17:03 +00:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Music
|
|
|
|
|
{
|
2020-02-14 06:36:16 +00:00
|
|
|
|
public class PlaylistItem : OsuRearrangeableListItem<BeatmapSetInfo>, IFilterable
|
2020-01-28 08:59:14 +00:00
|
|
|
|
{
|
2020-01-29 03:17:03 +00:00
|
|
|
|
public readonly Bindable<BeatmapSetInfo> SelectedSet = new Bindable<BeatmapSetInfo>();
|
2020-02-06 09:38:00 +00:00
|
|
|
|
|
2020-01-29 03:17:03 +00:00
|
|
|
|
public Action<BeatmapSetInfo> RequestSelection;
|
|
|
|
|
|
|
|
|
|
private TextFlowContainer text;
|
|
|
|
|
private IEnumerable<Drawable> titleSprites;
|
2020-02-18 10:19:04 +00:00
|
|
|
|
|
|
|
|
|
private ILocalisedBindableString title;
|
|
|
|
|
private ILocalisedBindableString artist;
|
2020-01-29 03:17:03 +00:00
|
|
|
|
|
2020-02-14 06:36:16 +00:00
|
|
|
|
private Color4 selectedColour;
|
2020-01-29 03:17:03 +00:00
|
|
|
|
private Color4 artistColour;
|
|
|
|
|
|
2020-01-30 10:23:53 +00:00
|
|
|
|
public PlaylistItem(BeatmapSetInfo item)
|
2020-01-28 08:59:14 +00:00
|
|
|
|
: base(item)
|
|
|
|
|
{
|
2020-01-29 03:17:03 +00:00
|
|
|
|
Padding = new MarginPadding { Left = 5 };
|
|
|
|
|
|
2020-01-30 10:00:59 +00:00
|
|
|
|
FilterTerms = item.Metadata.SearchableTerms;
|
2020-01-28 08:59:14 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-01-29 03:17:03 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours, LocalisationManager localisation)
|
|
|
|
|
{
|
2020-02-14 06:36:16 +00:00
|
|
|
|
selectedColour = colours.Yellow;
|
2020-01-29 03:17:03 +00:00
|
|
|
|
artistColour = colours.Gray9;
|
2020-02-14 06:36:16 +00:00
|
|
|
|
HandleColour = colours.Gray5;
|
2020-01-29 03:17:03 +00:00
|
|
|
|
|
2021-02-25 05:12:59 +00:00
|
|
|
|
title = localisation.GetLocalisedString(new RomanisableString(Model.Metadata.TitleUnicode, Model.Metadata.Title));
|
|
|
|
|
artist = localisation.GetLocalisedString(new RomanisableString(Model.Metadata.ArtistUnicode, Model.Metadata.Artist));
|
2020-01-29 03:17:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2020-02-18 10:19:04 +00:00
|
|
|
|
artist.BindValueChanged(_ => recreateText(), true);
|
|
|
|
|
|
2020-01-29 03:17:03 +00:00
|
|
|
|
SelectedSet.BindValueChanged(set =>
|
|
|
|
|
{
|
2020-02-18 10:19:04 +00:00
|
|
|
|
if (set.OldValue?.Equals(Model) != true && set.NewValue?.Equals(Model) != true)
|
2020-01-29 03:17:03 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
foreach (Drawable s in titleSprites)
|
2020-02-18 10:19:04 +00:00
|
|
|
|
s.FadeColour(set.NewValue.Equals(Model) ? selectedColour : Color4.White, FADE_DURATION);
|
2020-01-29 03:17:03 +00:00
|
|
|
|
}, true);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-14 06:36:16 +00:00
|
|
|
|
protected override Drawable CreateContent() => text = new OsuTextFlowContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
};
|
|
|
|
|
|
2020-01-29 03:17:03 +00:00
|
|
|
|
private void recreateText()
|
|
|
|
|
{
|
|
|
|
|
text.Clear();
|
|
|
|
|
|
2020-05-05 01:31:11 +00:00
|
|
|
|
// space after the title to put a space between the title and artist
|
2020-02-18 10:19:04 +00:00
|
|
|
|
titleSprites = text.AddText(title.Value + @" ", sprite => sprite.Font = OsuFont.GetFont(weight: FontWeight.Regular)).OfType<SpriteText>();
|
2020-01-29 03:17:03 +00:00
|
|
|
|
|
2020-02-18 10:19:04 +00:00
|
|
|
|
text.AddText(artist.Value, sprite =>
|
2020-01-29 03:17:03 +00:00
|
|
|
|
{
|
|
|
|
|
sprite.Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold);
|
|
|
|
|
sprite.Colour = artistColour;
|
|
|
|
|
sprite.Padding = new MarginPadding { Top = 1 };
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
|
|
|
|
{
|
2020-01-30 10:00:59 +00:00
|
|
|
|
RequestSelection?.Invoke(Model);
|
2020-01-29 03:17:03 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-11 07:46:11 +00:00
|
|
|
|
private bool inSelectedCollection = true;
|
|
|
|
|
|
|
|
|
|
public bool InSelectedCollection
|
|
|
|
|
{
|
|
|
|
|
get => inSelectedCollection;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (inSelectedCollection == value)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
inSelectedCollection = value;
|
|
|
|
|
updateFilter();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-28 08:59:14 +00:00
|
|
|
|
public IEnumerable<string> FilterTerms { get; }
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-09-11 07:46:11 +00:00
|
|
|
|
private bool matchingFilter = true;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-01-28 08:59:14 +00:00
|
|
|
|
public bool MatchingFilter
|
|
|
|
|
{
|
2020-09-11 07:46:11 +00:00
|
|
|
|
get => matchingFilter && inSelectedCollection;
|
2020-01-28 08:59:14 +00:00
|
|
|
|
set
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2020-09-11 07:46:11 +00:00
|
|
|
|
if (matchingFilter == value)
|
|
|
|
|
return;
|
2019-03-28 15:29:07 +00:00
|
|
|
|
|
2020-09-11 07:46:11 +00:00
|
|
|
|
matchingFilter = value;
|
|
|
|
|
updateFilter();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-28 08:59:14 +00:00
|
|
|
|
|
2020-09-11 07:46:11 +00:00
|
|
|
|
private void updateFilter() => this.FadeTo(MatchingFilter ? 1 : 0, 200);
|
|
|
|
|
|
2020-01-28 08:59:14 +00:00
|
|
|
|
public bool FilteringActive { get; set; }
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|