2019-01-24 16:43:03 +08:00
|
|
|
|
// 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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
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;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2020-01-29 11:17:03 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
|
using osu.Framework.Localisation;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2020-01-29 11:17:03 +08:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Music
|
|
|
|
|
{
|
2020-01-29 11:17:03 +08:00
|
|
|
|
public class PlaylistList : RearrangeableListContainer<PlaylistListItem>
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-01-29 11:17:03 +08:00
|
|
|
|
public Action<BeatmapSetInfo> RequestSelection;
|
|
|
|
|
|
|
|
|
|
public readonly Bindable<BeatmapSetInfo> SelectedSet = new Bindable<BeatmapSetInfo>();
|
|
|
|
|
public readonly IBindableList<BeatmapSetInfo> BeatmapSets = new BindableList<BeatmapSetInfo>();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
public new MarginPadding Padding
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => base.Padding;
|
|
|
|
|
set => base.Padding = value;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-29 11:17:03 +08:00
|
|
|
|
private readonly HashSet<BeatmapSetInfo> existingItems = new HashSet<BeatmapSetInfo>();
|
|
|
|
|
|
2020-01-28 16:59:14 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-01-28 16:59:14 +08:00
|
|
|
|
BeatmapSets.ItemsAdded += addBeatmapSets;
|
|
|
|
|
BeatmapSets.ItemsRemoved += removeBeatmapSets;
|
2020-01-29 11:17:03 +08:00
|
|
|
|
|
|
|
|
|
foreach (var item in BeatmapSets)
|
|
|
|
|
addBeatmapSet(item);
|
2020-01-28 16:59:14 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-01-28 16:59:14 +08:00
|
|
|
|
public void Filter(string searchTerm) => ((PlaylistListFlowContainer)ListContainer).SearchTerm = searchTerm;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-01-28 16:59:14 +08:00
|
|
|
|
public BeatmapSetInfo FirstVisibleSet => ListContainer.FlowingChildren.Cast<DrawablePlaylistListItem>().FirstOrDefault(i => i.MatchingFilter)?.Model.BeatmapSetInfo;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-01-29 11:17:03 +08:00
|
|
|
|
private void addBeatmapSets(IEnumerable<BeatmapSetInfo> sets)
|
2020-01-28 16:59:14 +08:00
|
|
|
|
{
|
2020-01-29 11:17:03 +08:00
|
|
|
|
foreach (var set in sets)
|
|
|
|
|
addBeatmapSet(set);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addBeatmapSet(BeatmapSetInfo set) => Schedule(() =>
|
|
|
|
|
{
|
|
|
|
|
if (existingItems.Contains(set))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
AddItem(new PlaylistListItem(set));
|
|
|
|
|
existingItems.Add(set);
|
2020-01-28 16:59:14 +08:00
|
|
|
|
});
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-01-28 16:59:14 +08:00
|
|
|
|
private void removeBeatmapSets(IEnumerable<BeatmapSetInfo> sets) => Schedule(() =>
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in sets)
|
|
|
|
|
RemoveItem(ListContainer.Children.Select(d => d.Model).FirstOrDefault(m => m.BeatmapSetInfo == item));
|
|
|
|
|
});
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-01-29 11:17:03 +08:00
|
|
|
|
protected override DrawableRearrangeableListItem<PlaylistListItem> CreateDrawable(PlaylistListItem item) => new DrawablePlaylistListItem(item)
|
|
|
|
|
{
|
|
|
|
|
SelectedSet = { BindTarget = SelectedSet },
|
|
|
|
|
RequestSelection = set => RequestSelection?.Invoke(set)
|
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-01-29 11:17:03 +08:00
|
|
|
|
protected override ScrollContainer<Drawable> CreateScrollContainer() => new OsuScrollContainer();
|
|
|
|
|
|
|
|
|
|
protected override FillFlowContainer<DrawableRearrangeableListItem<PlaylistListItem>> CreateListFillFlowContainer() => new PlaylistListFlowContainer
|
2020-01-28 16:59:14 +08:00
|
|
|
|
{
|
2020-01-29 11:17:03 +08:00
|
|
|
|
Spacing = new Vector2(0, 3),
|
2020-01-28 16:59:14 +08:00
|
|
|
|
LayoutDuration = 200,
|
2020-01-29 11:17:03 +08:00
|
|
|
|
LayoutEasing = Easing.OutQuint,
|
2020-01-28 16:59:14 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-01-29 11:17:03 +08:00
|
|
|
|
public class PlaylistListFlowContainer : SearchContainer<DrawableRearrangeableListItem<PlaylistListItem>>
|
2020-01-28 16:59:14 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-01-28 16:59:14 +08:00
|
|
|
|
public class PlaylistListItem : IEquatable<PlaylistListItem>
|
|
|
|
|
{
|
|
|
|
|
public readonly BeatmapSetInfo BeatmapSetInfo;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-01-28 16:59:14 +08:00
|
|
|
|
public PlaylistListItem(BeatmapSetInfo beatmapSetInfo)
|
|
|
|
|
{
|
|
|
|
|
BeatmapSetInfo = beatmapSetInfo;
|
|
|
|
|
}
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2020-01-28 16:59:14 +08:00
|
|
|
|
public override string ToString() => BeatmapSetInfo.ToString();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-01-28 16:59:14 +08:00
|
|
|
|
public bool Equals(PlaylistListItem other) => BeatmapSetInfo.Equals(other?.BeatmapSetInfo);
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-01-29 11:17:03 +08:00
|
|
|
|
public class DrawablePlaylistListItem : DrawableRearrangeableListItem<PlaylistListItem>, IFilterable
|
2020-01-28 16:59:14 +08:00
|
|
|
|
{
|
2020-01-29 11:17:03 +08:00
|
|
|
|
private const float fade_duration = 100;
|
|
|
|
|
|
|
|
|
|
public readonly Bindable<BeatmapSetInfo> SelectedSet = new Bindable<BeatmapSetInfo>();
|
|
|
|
|
public Action<BeatmapSetInfo> RequestSelection;
|
|
|
|
|
|
|
|
|
|
private PlaylistItemHandle handle;
|
|
|
|
|
private TextFlowContainer text;
|
|
|
|
|
private IEnumerable<Drawable> titleSprites;
|
|
|
|
|
private ILocalisedBindableString titleBind;
|
|
|
|
|
private ILocalisedBindableString artistBind;
|
|
|
|
|
|
|
|
|
|
private Color4 hoverColour;
|
|
|
|
|
private Color4 artistColour;
|
|
|
|
|
|
2020-01-28 16:59:14 +08:00
|
|
|
|
public DrawablePlaylistListItem(PlaylistListItem item)
|
|
|
|
|
: base(item)
|
|
|
|
|
{
|
2020-01-29 11:17:03 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
|
|
Padding = new MarginPadding { Left = 5 };
|
|
|
|
|
|
2020-01-28 16:59:14 +08:00
|
|
|
|
FilterTerms = item.BeatmapSetInfo.Metadata.SearchableTerms;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-01-29 11:17:03 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours, LocalisationManager localisation)
|
|
|
|
|
{
|
|
|
|
|
hoverColour = colours.Yellow;
|
|
|
|
|
artistColour = colours.Gray9;
|
|
|
|
|
|
|
|
|
|
InternalChild = new GridContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Content = new[]
|
|
|
|
|
{
|
|
|
|
|
new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
handle = new PlaylistItemHandle
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Size = new Vector2(12),
|
|
|
|
|
Colour = colours.Gray5,
|
|
|
|
|
Alpha = 0
|
|
|
|
|
},
|
|
|
|
|
text = new OsuTextFlowContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Padding = new MarginPadding { Left = 5 },
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
ColumnDimensions = new[] { new Dimension(GridSizeMode.AutoSize) },
|
|
|
|
|
RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize) }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
titleBind = localisation.GetLocalisedString(new LocalisedString((Model.BeatmapSetInfo.Metadata.TitleUnicode, Model.BeatmapSetInfo.Metadata.Title)));
|
|
|
|
|
artistBind = localisation.GetLocalisedString(new LocalisedString((Model.BeatmapSetInfo.Metadata.ArtistUnicode, Model.BeatmapSetInfo.Metadata.Artist)));
|
|
|
|
|
|
|
|
|
|
artistBind.BindValueChanged(_ => recreateText(), true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
SelectedSet.BindValueChanged(set =>
|
|
|
|
|
{
|
|
|
|
|
if (set.OldValue != Model.BeatmapSetInfo && set.NewValue != Model.BeatmapSetInfo)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
foreach (Drawable s in titleSprites)
|
|
|
|
|
s.FadeColour(set.NewValue == Model.BeatmapSetInfo ? hoverColour : Color4.White, fade_duration);
|
|
|
|
|
}, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void recreateText()
|
|
|
|
|
{
|
|
|
|
|
text.Clear();
|
|
|
|
|
|
|
|
|
|
//space after the title to put a space between the title and artist
|
|
|
|
|
titleSprites = text.AddText(titleBind.Value + @" ", sprite => sprite.Font = OsuFont.GetFont(weight: FontWeight.Regular)).OfType<SpriteText>();
|
|
|
|
|
|
|
|
|
|
text.AddText(artistBind.Value, sprite =>
|
|
|
|
|
{
|
|
|
|
|
sprite.Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold);
|
|
|
|
|
sprite.Colour = artistColour;
|
|
|
|
|
sprite.Padding = new MarginPadding { Top = 1 };
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
|
|
|
|
{
|
|
|
|
|
RequestSelection?.Invoke(Model.BeatmapSetInfo);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool IsDraggableAt(Vector2 screenSpacePos) => handle.HandlingDrag;
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
|
{
|
|
|
|
|
handle.UpdateHoverState(true);
|
|
|
|
|
return base.OnHover(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e) => handle.UpdateHoverState(false);
|
|
|
|
|
|
2020-01-28 16:59:14 +08:00
|
|
|
|
public IEnumerable<string> FilterTerms { get; }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-01-28 16:59:14 +08:00
|
|
|
|
private bool matching = true;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-01-28 16:59:14 +08:00
|
|
|
|
public bool MatchingFilter
|
|
|
|
|
{
|
|
|
|
|
get => matching;
|
|
|
|
|
set
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-01-28 16:59:14 +08:00
|
|
|
|
if (matching == value) return;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-01-28 16:59:14 +08:00
|
|
|
|
matching = value;
|
2019-03-28 23:29:07 +08:00
|
|
|
|
|
2020-01-28 16:59:14 +08:00
|
|
|
|
this.FadeTo(matching ? 1 : 0, 200);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-28 16:59:14 +08:00
|
|
|
|
|
|
|
|
|
public bool FilteringActive { get; set; }
|
2020-01-29 11:17:03 +08:00
|
|
|
|
|
|
|
|
|
private class PlaylistItemHandle : SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
public bool HandlingDrag { get; private set; }
|
|
|
|
|
private bool isHovering;
|
|
|
|
|
|
|
|
|
|
public PlaylistItemHandle()
|
|
|
|
|
{
|
|
|
|
|
Icon = FontAwesome.Solid.Bars;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnMouseDown(MouseDownEvent e)
|
|
|
|
|
{
|
|
|
|
|
base.OnMouseDown(e);
|
|
|
|
|
|
|
|
|
|
HandlingDrag = true;
|
|
|
|
|
UpdateHoverState(isHovering);
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnMouseUp(MouseUpEvent e)
|
|
|
|
|
{
|
|
|
|
|
base.OnMouseUp(e);
|
|
|
|
|
|
|
|
|
|
HandlingDrag = false;
|
|
|
|
|
UpdateHoverState(isHovering);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateHoverState(bool hovering)
|
|
|
|
|
{
|
|
|
|
|
isHovering = hovering;
|
|
|
|
|
|
|
|
|
|
if (isHovering || HandlingDrag)
|
|
|
|
|
this.FadeIn(fade_duration);
|
|
|
|
|
else
|
|
|
|
|
this.FadeOut(fade_duration);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|