2020-02-04 16:00:36 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 16:43:03 +08:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2017-05-01 14:03:11 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2022-05-16 13:09:37 +08:00
|
|
|
|
using System.Linq;
|
2018-05-14 16:41:35 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2017-05-01 14:03:11 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2020-01-29 11:17:03 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
|
using osu.Framework.Localisation;
|
2017-07-26 12:22:46 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2022-01-26 11:19:05 +08:00
|
|
|
|
using osu.Game.Database;
|
2020-01-29 11:17:03 +08:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-05-01 14:03:11 +08:00
|
|
|
|
namespace osu.Game.Overlays.Music
|
|
|
|
|
{
|
2022-01-26 14:12:01 +08:00
|
|
|
|
public partial class PlaylistItem : OsuRearrangeableListItem<Live<BeatmapSetInfo>>, IFilterable
|
2020-01-28 16:59:14 +08:00
|
|
|
|
{
|
2022-01-26 14:12:01 +08:00
|
|
|
|
public readonly Bindable<Live<BeatmapSetInfo>> SelectedSet = new Bindable<Live<BeatmapSetInfo>>();
|
2020-02-06 17:38:00 +08:00
|
|
|
|
|
2022-01-26 14:12:01 +08:00
|
|
|
|
public Action<Live<BeatmapSetInfo>> RequestSelection;
|
2020-01-29 11:17:03 +08:00
|
|
|
|
|
|
|
|
|
private TextFlowContainer text;
|
2021-08-01 23:12:04 +08:00
|
|
|
|
private ITextPart titlePart;
|
2020-02-18 18:19:04 +08:00
|
|
|
|
|
2021-11-03 06:19:45 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private OsuColour colours { get; set; }
|
2020-01-29 11:17:03 +08:00
|
|
|
|
|
2022-01-26 14:12:01 +08:00
|
|
|
|
public PlaylistItem(Live<BeatmapSetInfo> item)
|
2020-01-28 16:59:14 +08:00
|
|
|
|
: base(item)
|
|
|
|
|
{
|
2020-01-29 11:17:03 +08:00
|
|
|
|
Padding = new MarginPadding { Left = 5 };
|
2020-01-28 16:59:14 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-01-29 11:17:03 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2021-11-03 06:19:45 +08:00
|
|
|
|
private void load()
|
2020-01-29 11:17:03 +08:00
|
|
|
|
{
|
2020-02-14 14:36:16 +08:00
|
|
|
|
HandleColour = colours.Gray5;
|
2020-01-29 11:17:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2022-01-26 11:19:05 +08:00
|
|
|
|
Model.PerformRead(m =>
|
|
|
|
|
{
|
|
|
|
|
var metadata = m.Metadata;
|
2022-01-22 00:18:29 +08:00
|
|
|
|
|
2022-01-26 11:19:05 +08:00
|
|
|
|
var title = new RomanisableString(metadata.TitleUnicode, metadata.Title);
|
|
|
|
|
var artist = new RomanisableString(metadata.ArtistUnicode, metadata.Artist);
|
2022-01-22 00:18:29 +08:00
|
|
|
|
|
2022-01-26 11:19:05 +08:00
|
|
|
|
titlePart = text.AddText(title, sprite => sprite.Font = OsuFont.GetFont(weight: FontWeight.Regular));
|
2023-04-20 09:34:35 +08:00
|
|
|
|
titlePart.DrawablePartsRecreated += _ => updateSelectionState(SelectedSet.Value, instant: true);
|
2022-01-22 00:18:29 +08:00
|
|
|
|
|
2022-01-26 11:19:05 +08:00
|
|
|
|
text.AddText(@" "); // to separate the title from the artist.
|
|
|
|
|
text.AddText(artist, sprite =>
|
|
|
|
|
{
|
|
|
|
|
sprite.Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold);
|
|
|
|
|
sprite.Colour = colours.Gray9;
|
|
|
|
|
sprite.Padding = new MarginPadding { Top = 1 };
|
|
|
|
|
});
|
2022-01-22 00:18:29 +08:00
|
|
|
|
|
2023-04-20 09:34:35 +08:00
|
|
|
|
SelectedSet.BindValueChanged(set => updateSelectionState(set.NewValue, instant: false));
|
|
|
|
|
updateSelectionState(SelectedSet.Value, instant: true);
|
2022-01-26 11:19:05 +08:00
|
|
|
|
});
|
2020-01-29 11:17:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-22 00:49:07 +08:00
|
|
|
|
private bool selected;
|
|
|
|
|
|
2023-04-20 09:34:35 +08:00
|
|
|
|
private void updateSelectionState(Live<BeatmapSetInfo> selectedSet, bool instant)
|
2021-08-01 23:12:04 +08:00
|
|
|
|
{
|
2023-04-20 09:34:35 +08:00
|
|
|
|
bool newSelected = selectedSet?.Equals(Model) == true;
|
|
|
|
|
|
|
|
|
|
if (newSelected == selected && !instant) // instant updates should forcibly set correct state regardless of previous state.
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
selected = newSelected;
|
|
|
|
|
|
2021-08-01 23:12:04 +08:00
|
|
|
|
foreach (Drawable s in titlePart.Drawables)
|
2022-01-22 00:49:07 +08:00
|
|
|
|
s.FadeColour(selected ? colours.Yellow : Color4.White, instant ? 0 : FADE_DURATION);
|
2021-08-01 23:12:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-22 00:49:07 +08:00
|
|
|
|
protected override Drawable CreateContent() => new DelayedLoadWrapper(text = new OsuTextFlowContainer
|
2020-02-14 14:36:16 +08:00
|
|
|
|
{
|
2021-11-03 06:19:45 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2022-01-22 00:49:07 +08:00
|
|
|
|
});
|
2021-11-03 06:19:45 +08:00
|
|
|
|
|
2020-01-29 11:17:03 +08:00
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
|
|
|
|
{
|
2020-01-30 18:00:59 +08:00
|
|
|
|
RequestSelection?.Invoke(Model);
|
2020-01-29 11:17:03 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-11 15:46:11 +08:00
|
|
|
|
private bool inSelectedCollection = true;
|
|
|
|
|
|
|
|
|
|
public bool InSelectedCollection
|
|
|
|
|
{
|
|
|
|
|
get => inSelectedCollection;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (inSelectedCollection == value)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
inSelectedCollection = value;
|
|
|
|
|
updateFilter();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-16 13:09:37 +08:00
|
|
|
|
public IEnumerable<LocalisableString> FilterTerms => Model.PerformRead(m => m.Metadata.GetSearchableTerms()).Select(s => (LocalisableString)s).ToArray();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-09-11 15:46:11 +08:00
|
|
|
|
private bool matchingFilter = true;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-01-28 16:59:14 +08:00
|
|
|
|
public bool MatchingFilter
|
|
|
|
|
{
|
2020-09-11 15:46:11 +08:00
|
|
|
|
get => matchingFilter && inSelectedCollection;
|
2020-01-28 16:59:14 +08:00
|
|
|
|
set
|
2017-05-02 09:45:55 +08:00
|
|
|
|
{
|
2020-09-11 15:46:11 +08:00
|
|
|
|
if (matchingFilter == value)
|
|
|
|
|
return;
|
2019-03-28 23:29:07 +08:00
|
|
|
|
|
2020-09-11 15:46:11 +08:00
|
|
|
|
matchingFilter = value;
|
|
|
|
|
updateFilter();
|
2017-05-02 09:45:55 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-28 16:59:14 +08:00
|
|
|
|
|
2020-09-11 15:46:11 +08:00
|
|
|
|
private void updateFilter() => this.FadeTo(MatchingFilter ? 1 : 0, 200);
|
|
|
|
|
|
2020-01-28 16:59:14 +08:00
|
|
|
|
public bool FilteringActive { get; set; }
|
2017-05-01 14:03:11 +08:00
|
|
|
|
}
|
2017-09-05 09:29:51 +08:00
|
|
|
|
}
|