From 00a7adcdca53ccc475372b5f9d5221944d17a696 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 30 Jan 2020 19:21:24 +0900 Subject: [PATCH] Further refactorings --- .../UserInterface/TestScenePlaylistOverlay.cs | 4 +- ...laylistList.cs => DrawablePlaylistItem.cs} | 48 +---- osu.Game/Overlays/Music/Playlist.cs | 46 +++++ osu.Game/Overlays/Music/PlaylistItem.cs | 183 ------------------ osu.Game/Overlays/Music/PlaylistOverlay.cs | 4 +- 5 files changed, 53 insertions(+), 232 deletions(-) rename osu.Game/Overlays/Music/{PlaylistList.cs => DrawablePlaylistItem.cs} (75%) create mode 100644 osu.Game/Overlays/Music/Playlist.cs delete mode 100644 osu.Game/Overlays/Music/PlaylistItem.cs diff --git a/osu.Game.Tests/Visual/UserInterface/TestScenePlaylistOverlay.cs b/osu.Game.Tests/Visual/UserInterface/TestScenePlaylistOverlay.cs index 986cf458ab..7476b52b49 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestScenePlaylistOverlay.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestScenePlaylistOverlay.cs @@ -16,10 +16,10 @@ namespace osu.Game.Tests.Visual.UserInterface { public class TestScenePlaylistOverlay : OsuTestScene { - public override IReadOnlyList RequiredTypes => new Type[] + public override IReadOnlyList RequiredTypes => new[] { typeof(PlaylistOverlay), - typeof(PlaylistList) + typeof(Playlist) }; private readonly BindableList beatmapSets = new BindableList(); diff --git a/osu.Game/Overlays/Music/PlaylistList.cs b/osu.Game/Overlays/Music/DrawablePlaylistItem.cs similarity index 75% rename from osu.Game/Overlays/Music/PlaylistList.cs rename to osu.Game/Overlays/Music/DrawablePlaylistItem.cs index e183c14f10..e3dd72ae8b 100644 --- a/osu.Game/Overlays/Music/PlaylistList.cs +++ b/osu.Game/Overlays/Music/DrawablePlaylistItem.cs @@ -1,4 +1,4 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; @@ -19,49 +19,7 @@ using osuTK.Graphics; namespace osu.Game.Overlays.Music { - public class PlaylistList : RearrangeableListContainer - { - public Action RequestSelection; - - public readonly Bindable SelectedSet = new Bindable(); - - public new MarginPadding Padding - { - get => base.Padding; - set => base.Padding = value; - } - - public void Filter(string searchTerm) => ((PlaylistListFlowContainer)ListContainer).SearchTerm = searchTerm; - - public BeatmapSetInfo FirstVisibleSet => ListContainer.FlowingChildren.Cast().FirstOrDefault(i => i.MatchingFilter)?.Model; - - private void removeBeatmapSets(IEnumerable sets) => Schedule(() => - { - foreach (var item in sets) - Items.Remove(ListContainer.Children.Select(d => d.Model).FirstOrDefault(m => m == item)); - }); - - protected override DrawableRearrangeableListItem CreateDrawable(BeatmapSetInfo 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, - }; - } - - public class PlaylistListFlowContainer : SearchContainer> - { - } - - public class DrawablePlaylistListItem : DrawableRearrangeableListItem, IFilterable + public class DrawablePlaylistItem : RearrangeableListItem, IFilterable { private const float fade_duration = 100; @@ -77,7 +35,7 @@ namespace osu.Game.Overlays.Music private Color4 hoverColour; private Color4 artistColour; - public DrawablePlaylistListItem(BeatmapSetInfo item) + public DrawablePlaylistItem(BeatmapSetInfo item) : base(item) { RelativeSizeAxes = Axes.X; diff --git a/osu.Game/Overlays/Music/Playlist.cs b/osu.Game/Overlays/Music/Playlist.cs new file mode 100644 index 0000000000..ba9aaf03d4 --- /dev/null +++ b/osu.Game/Overlays/Music/Playlist.cs @@ -0,0 +1,46 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Linq; +using osu.Framework.Bindables; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Game.Beatmaps; +using osu.Game.Graphics.Containers; +using osuTK; + +namespace osu.Game.Overlays.Music +{ + public class Playlist : RearrangeableListContainer + { + public Action RequestSelection; + + public readonly Bindable SelectedSet = new Bindable(); + + public new MarginPadding Padding + { + get => base.Padding; + set => base.Padding = value; + } + + public void Filter(string searchTerm) => ((SearchContainer>)ListContainer).SearchTerm = searchTerm; + + public BeatmapSetInfo FirstVisibleSet => Items.FirstOrDefault(i => ((DrawablePlaylistItem)ItemMap[i]).MatchingFilter); + + protected override RearrangeableListItem CreateDrawable(BeatmapSetInfo item) => new DrawablePlaylistItem(item) + { + SelectedSet = { BindTarget = SelectedSet }, + RequestSelection = set => RequestSelection?.Invoke(set) + }; + + protected override ScrollContainer CreateScrollContainer() => new OsuScrollContainer(); + + protected override FillFlowContainer> CreateListFillFlowContainer() => new SearchContainer> + { + Spacing = new Vector2(0, 3), + LayoutDuration = 200, + LayoutEasing = Easing.OutQuint, + }; + } +} diff --git a/osu.Game/Overlays/Music/PlaylistItem.cs b/osu.Game/Overlays/Music/PlaylistItem.cs deleted file mode 100644 index d40f391982..0000000000 --- a/osu.Game/Overlays/Music/PlaylistItem.cs +++ /dev/null @@ -1,183 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using System; -using System.Collections.Generic; -using System.Linq; -using osuTK.Graphics; -using osu.Framework.Allocation; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -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; - -namespace osu.Game.Overlays.Music -{ - public class PlaylistItem : Container, IFilterable, IDraggable - { - private const float fade_duration = 100; - - private Color4 hoverColour; - private Color4 artistColour; - - private SpriteIcon handle; - private TextFlowContainer text; - private IEnumerable titleSprites; - private ILocalisedBindableString titleBind; - private ILocalisedBindableString artistBind; - - public readonly BeatmapSetInfo BeatmapSetInfo; - - public Action OnSelect; - - public bool IsDraggable { get; private set; } - - protected override bool OnMouseDown(MouseDownEvent e) - { - IsDraggable = handle.IsHovered; - return base.OnMouseDown(e); - } - - protected override void OnMouseUp(MouseUpEvent e) - { - IsDraggable = false; - base.OnMouseUp(e); - } - - private bool selected; - - public bool Selected - { - get => selected; - set - { - if (value == selected) return; - - selected = value; - - FinishTransforms(true); - foreach (Drawable s in titleSprites) - s.FadeColour(Selected ? hoverColour : Color4.White, fade_duration); - } - } - - public PlaylistItem(BeatmapSetInfo setInfo) - { - BeatmapSetInfo = setInfo; - - RelativeSizeAxes = Axes.X; - AutoSizeAxes = Axes.Y; - Padding = new MarginPadding { Top = 3, Bottom = 3 }; - } - - [BackgroundDependencyLoader] - private void load(OsuColour colours, LocalisationManager localisation) - { - hoverColour = colours.Yellow; - artistColour = colours.Gray9; - - var metadata = BeatmapSetInfo.Metadata; - FilterTerms = metadata.SearchableTerms; - - Children = new Drawable[] - { - handle = new PlaylistItemHandle - { - Colour = colours.Gray5 - }, - text = new OsuTextFlowContainer - { - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Padding = new MarginPadding { Left = 20 }, - ContentIndent = 10f, - }, - }; - - titleBind = localisation.GetLocalisedString(new LocalisedString((metadata.TitleUnicode, metadata.Title))); - artistBind = localisation.GetLocalisedString(new LocalisedString((metadata.ArtistUnicode, metadata.Artist))); - - artistBind.BindValueChanged(_ => recreateText(), 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 OnHover(HoverEvent e) - { - handle.FadeIn(fade_duration); - - return base.OnHover(e); - } - - protected override void OnHoverLost(HoverLostEvent e) - { - handle.FadeOut(fade_duration); - } - - protected override bool OnClick(ClickEvent e) - { - OnSelect?.Invoke(BeatmapSetInfo); - return true; - } - - public IEnumerable FilterTerms { get; private set; } - - private bool matching = true; - - public bool MatchingFilter - { - get => matching; - set - { - if (matching == value) return; - - matching = value; - - this.FadeTo(matching ? 1 : 0, 200); - } - } - - public bool FilteringActive { get; set; } - - private class PlaylistItemHandle : SpriteIcon - { - public PlaylistItemHandle() - { - Anchor = Anchor.CentreLeft; - Origin = Anchor.CentreLeft; - Size = new Vector2(12); - Icon = FontAwesome.Solid.Bars; - Alpha = 0f; - Margin = new MarginPadding { Left = 5 }; - } - - public override bool HandlePositionalInput => IsPresent; - } - } - - public interface IDraggable : IDrawable - { - /// - /// Whether this can be dragged in its current state. - /// - bool IsDraggable { get; } - } -} diff --git a/osu.Game/Overlays/Music/PlaylistOverlay.cs b/osu.Game/Overlays/Music/PlaylistOverlay.cs index a814712907..7c391e27f9 100644 --- a/osu.Game/Overlays/Music/PlaylistOverlay.cs +++ b/osu.Game/Overlays/Music/PlaylistOverlay.cs @@ -29,7 +29,7 @@ namespace osu.Game.Overlays.Music private BeatmapManager beatmaps; private FilterControl filter; - private PlaylistList list; + private Playlist list; [BackgroundDependencyLoader] private void load(OsuColour colours, Bindable beatmap, BeatmapManager beatmaps) @@ -57,7 +57,7 @@ namespace osu.Game.Overlays.Music Colour = colours.Gray3, RelativeSizeAxes = Axes.Both, }, - list = new PlaylistList + list = new Playlist { RelativeSizeAxes = Axes.Both, Padding = new MarginPadding { Top = 95, Bottom = 10, Right = 10 },