diff --git a/osu.Game.Tests/Visual/UserInterface/TestScenePlaylistOverlay.cs b/osu.Game.Tests/Visual/UserInterface/TestScenePlaylistOverlay.cs index a470244f53..986cf458ab 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestScenePlaylistOverlay.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestScenePlaylistOverlay.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Collections.Generic; using NUnit.Framework; using osu.Framework.Bindables; using osu.Framework.Graphics; @@ -15,6 +16,12 @@ namespace osu.Game.Tests.Visual.UserInterface { public class TestScenePlaylistOverlay : OsuTestScene { + public override IReadOnlyList RequiredTypes => new Type[] + { + typeof(PlaylistOverlay), + typeof(PlaylistList) + }; + private readonly BindableList beatmapSets = new BindableList(); [SetUp] diff --git a/osu.Game/Overlays/Music/PlaylistList.cs b/osu.Game/Overlays/Music/PlaylistList.cs index 5c091a21db..f7be69e1f2 100644 --- a/osu.Game/Overlays/Music/PlaylistList.cs +++ b/osu.Game/Overlays/Music/PlaylistList.cs @@ -8,14 +8,23 @@ using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.UserInterface; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Input.Events; +using osu.Framework.Localisation; using osu.Game.Beatmaps; +using osu.Game.Graphics; +using osu.Game.Graphics.Containers; +using osuTK; +using osuTK.Graphics; namespace osu.Game.Overlays.Music { - public class PlaylistList2 : BasicRearrangeableListContainer + public class PlaylistList : RearrangeableListContainer { - public readonly BindableList BeatmapSets = new BindableList(); + public Action RequestSelection; + + public readonly Bindable SelectedSet = new Bindable(); + public readonly IBindableList BeatmapSets = new BindableList(); public new MarginPadding Padding { @@ -23,21 +32,35 @@ namespace osu.Game.Overlays.Music set => base.Padding = value; } + private readonly HashSet existingItems = new HashSet(); + [BackgroundDependencyLoader] private void load() { BeatmapSets.ItemsAdded += addBeatmapSets; BeatmapSets.ItemsRemoved += removeBeatmapSets; + + foreach (var item in BeatmapSets) + addBeatmapSet(item); } public void Filter(string searchTerm) => ((PlaylistListFlowContainer)ListContainer).SearchTerm = searchTerm; public BeatmapSetInfo FirstVisibleSet => ListContainer.FlowingChildren.Cast().FirstOrDefault(i => i.MatchingFilter)?.Model.BeatmapSetInfo; - private void addBeatmapSets(IEnumerable sets) => Schedule(() => + private void addBeatmapSets(IEnumerable sets) { - foreach (var item in sets) - AddItem(new PlaylistListItem(item)); + 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); }); private void removeBeatmapSets(IEnumerable sets) => Schedule(() => @@ -46,16 +69,23 @@ namespace osu.Game.Overlays.Music RemoveItem(ListContainer.Children.Select(d => d.Model).FirstOrDefault(m => m.BeatmapSetInfo == item)); }); - protected override BasicDrawableRearrangeableListItem CreateBasicItem(PlaylistListItem item) => new DrawablePlaylistListItem(item); - - protected override FillFlowContainer CreateListFillFlowContainer() => new PlaylistListFlowContainer + protected override DrawableRearrangeableListItem CreateDrawable(PlaylistListItem item) => new DrawablePlaylistListItem(item) { + SelectedSet = { BindTarget = SelectedSet }, + RequestSelection = set => RequestSelection?.Invoke(set) + }; + + protected override ScrollContainer CreateScrollContainer() => new OsuScrollContainer(); + + protected override FillFlowContainer> CreateListFillFlowContainer() => new PlaylistListFlowContainer + { + Spacing = new Vector2(0, 3), LayoutDuration = 200, - LayoutEasing = Easing.OutQuint + LayoutEasing = Easing.OutQuint, }; } - public class PlaylistListFlowContainer : SearchContainer.DrawableRearrangeableListItem> + public class PlaylistListFlowContainer : SearchContainer> { } @@ -73,14 +103,118 @@ namespace osu.Game.Overlays.Music public bool Equals(PlaylistListItem other) => BeatmapSetInfo.Equals(other?.BeatmapSetInfo); } - public class DrawablePlaylistListItem : BasicRearrangeableListContainer.BasicDrawableRearrangeableListItem, IFilterable + public class DrawablePlaylistListItem : DrawableRearrangeableListItem, IFilterable { + private const float fade_duration = 100; + + public readonly Bindable SelectedSet = new Bindable(); + public Action RequestSelection; + + private PlaylistItemHandle handle; + private TextFlowContainer text; + private IEnumerable titleSprites; + private ILocalisedBindableString titleBind; + private ILocalisedBindableString artistBind; + + private Color4 hoverColour; + private Color4 artistColour; + public DrawablePlaylistListItem(PlaylistListItem item) : base(item) { + RelativeSizeAxes = Axes.X; + AutoSizeAxes = Axes.Y; + + Padding = new MarginPadding { Left = 5 }; + FilterTerms = item.BeatmapSetInfo.Metadata.SearchableTerms; } + [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(); + + 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); + public IEnumerable FilterTerms { get; } private bool matching = true; @@ -99,5 +233,44 @@ namespace osu.Game.Overlays.Music } public bool FilteringActive { get; set; } + + 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); + } + } } } diff --git a/osu.Game/Overlays/Music/PlaylistOverlay.cs b/osu.Game/Overlays/Music/PlaylistOverlay.cs index ff1b26e335..87abbd142c 100644 --- a/osu.Game/Overlays/Music/PlaylistOverlay.cs +++ b/osu.Game/Overlays/Music/PlaylistOverlay.cs @@ -21,14 +21,14 @@ namespace osu.Game.Overlays.Music private const float transition_duration = 600; private const float playlist_height = 510; - public readonly BindableList BeatmapSets = new BindableList(); + public readonly IBindableList BeatmapSets = new BindableList(); private readonly Bindable beatmap = new Bindable(); private BeatmapManager beatmaps; private FilterControl filter; - private PlaylistList2 list; - + private PlaylistList list; + [BackgroundDependencyLoader] private void load(OsuColour colours, Bindable beatmap, BeatmapManager beatmaps) { @@ -55,11 +55,11 @@ namespace osu.Game.Overlays.Music Colour = colours.Gray3, RelativeSizeAxes = Axes.Both, }, - list = new PlaylistList2 + list = new PlaylistList { RelativeSizeAxes = Axes.Both, Padding = new MarginPadding { Top = 95, Bottom = 10, Right = 10 }, - // Selected = itemSelected, + RequestSelection = itemSelected }, filter = new FilterControl { @@ -84,6 +84,8 @@ namespace osu.Game.Overlays.Music beatmap.Value.Track.Restart(); } }; + + beatmap.BindValueChanged(working => list.SelectedSet.Value = working.NewValue.BeatmapSetInfo, true); } protected override void PopIn() diff --git a/osu.Game/Overlays/NowPlayingOverlay.cs b/osu.Game/Overlays/NowPlayingOverlay.cs index 042e95c6d7..dfcf99d30c 100644 --- a/osu.Game/Overlays/NowPlayingOverlay.cs +++ b/osu.Game/Overlays/NowPlayingOverlay.cs @@ -183,6 +183,7 @@ namespace osu.Game.Overlays } }; + playlist.BeatmapSets.BindTo(musicController.BeatmapSets); playlist.State.ValueChanged += s => playlistButton.FadeColour(s.NewValue == Visibility.Visible ? colours.Yellow : Color4.White, 200, Easing.OutQuint); }