From f6ba98eec0f1087d9d7214681f41b8a35c1c47bd Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 30 Jan 2020 19:00:59 +0900 Subject: [PATCH] Apply refactorings for framework-side changes --- osu.Game/Overlays/Music/PlaylistList.cs | 70 +++++----------------- osu.Game/Overlays/Music/PlaylistOverlay.cs | 6 +- 2 files changed, 18 insertions(+), 58 deletions(-) diff --git a/osu.Game/Overlays/Music/PlaylistList.cs b/osu.Game/Overlays/Music/PlaylistList.cs index f7be69e1f2..e183c14f10 100644 --- a/osu.Game/Overlays/Music/PlaylistList.cs +++ b/osu.Game/Overlays/Music/PlaylistList.cs @@ -19,12 +19,11 @@ using osuTK.Graphics; namespace osu.Game.Overlays.Music { - public class PlaylistList : RearrangeableListContainer + public class PlaylistList : RearrangeableListContainer { public Action RequestSelection; public readonly Bindable SelectedSet = new Bindable(); - public readonly IBindableList BeatmapSets = new BindableList(); public new MarginPadding Padding { @@ -32,44 +31,17 @@ 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) - { - 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); - }); + public BeatmapSetInfo FirstVisibleSet => ListContainer.FlowingChildren.Cast().FirstOrDefault(i => i.MatchingFilter)?.Model; private void removeBeatmapSets(IEnumerable sets) => Schedule(() => { foreach (var item in sets) - RemoveItem(ListContainer.Children.Select(d => d.Model).FirstOrDefault(m => m.BeatmapSetInfo == item)); + Items.Remove(ListContainer.Children.Select(d => d.Model).FirstOrDefault(m => m == item)); }); - protected override DrawableRearrangeableListItem CreateDrawable(PlaylistListItem item) => new DrawablePlaylistListItem(item) + protected override DrawableRearrangeableListItem CreateDrawable(BeatmapSetInfo item) => new DrawablePlaylistListItem(item) { SelectedSet = { BindTarget = SelectedSet }, RequestSelection = set => RequestSelection?.Invoke(set) @@ -77,7 +49,7 @@ namespace osu.Game.Overlays.Music protected override ScrollContainer CreateScrollContainer() => new OsuScrollContainer(); - protected override FillFlowContainer> CreateListFillFlowContainer() => new PlaylistListFlowContainer + protected override FillFlowContainer> CreateListFillFlowContainer() => new PlaylistListFlowContainer { Spacing = new Vector2(0, 3), LayoutDuration = 200, @@ -85,25 +57,11 @@ namespace osu.Game.Overlays.Music }; } - public class PlaylistListFlowContainer : SearchContainer> + public class PlaylistListFlowContainer : SearchContainer> { } - public class PlaylistListItem : IEquatable - { - public readonly BeatmapSetInfo BeatmapSetInfo; - - public PlaylistListItem(BeatmapSetInfo beatmapSetInfo) - { - BeatmapSetInfo = beatmapSetInfo; - } - - public override string ToString() => BeatmapSetInfo.ToString(); - - public bool Equals(PlaylistListItem other) => BeatmapSetInfo.Equals(other?.BeatmapSetInfo); - } - - public class DrawablePlaylistListItem : DrawableRearrangeableListItem, IFilterable + public class DrawablePlaylistListItem : DrawableRearrangeableListItem, IFilterable { private const float fade_duration = 100; @@ -119,7 +77,7 @@ namespace osu.Game.Overlays.Music private Color4 hoverColour; private Color4 artistColour; - public DrawablePlaylistListItem(PlaylistListItem item) + public DrawablePlaylistListItem(BeatmapSetInfo item) : base(item) { RelativeSizeAxes = Axes.X; @@ -127,7 +85,7 @@ namespace osu.Game.Overlays.Music Padding = new MarginPadding { Left = 5 }; - FilterTerms = item.BeatmapSetInfo.Metadata.SearchableTerms; + FilterTerms = item.Metadata.SearchableTerms; } [BackgroundDependencyLoader] @@ -164,8 +122,8 @@ namespace osu.Game.Overlays.Music 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))); + titleBind = localisation.GetLocalisedString(new LocalisedString((Model.Metadata.TitleUnicode, Model.Metadata.Title))); + artistBind = localisation.GetLocalisedString(new LocalisedString((Model.Metadata.ArtistUnicode, Model.Metadata.Artist))); artistBind.BindValueChanged(_ => recreateText(), true); } @@ -176,11 +134,11 @@ namespace osu.Game.Overlays.Music SelectedSet.BindValueChanged(set => { - if (set.OldValue != Model.BeatmapSetInfo && set.NewValue != Model.BeatmapSetInfo) + if (set.OldValue != Model && set.NewValue != Model) return; foreach (Drawable s in titleSprites) - s.FadeColour(set.NewValue == Model.BeatmapSetInfo ? hoverColour : Color4.White, fade_duration); + s.FadeColour(set.NewValue == Model ? hoverColour : Color4.White, fade_duration); }, true); } @@ -201,7 +159,7 @@ namespace osu.Game.Overlays.Music protected override bool OnClick(ClickEvent e) { - RequestSelection?.Invoke(Model.BeatmapSetInfo); + RequestSelection?.Invoke(Model); return true; } diff --git a/osu.Game/Overlays/Music/PlaylistOverlay.cs b/osu.Game/Overlays/Music/PlaylistOverlay.cs index 87abbd142c..a814712907 100644 --- a/osu.Game/Overlays/Music/PlaylistOverlay.cs +++ b/osu.Game/Overlays/Music/PlaylistOverlay.cs @@ -21,7 +21,9 @@ namespace osu.Game.Overlays.Music private const float transition_duration = 600; private const float playlist_height = 510; - public readonly IBindableList BeatmapSets = new BindableList(); + public IBindableList BeatmapSets => beatmapSets; + + private readonly BindableList beatmapSets = new BindableList(); private readonly Bindable beatmap = new Bindable(); private BeatmapManager beatmaps; @@ -72,7 +74,7 @@ namespace osu.Game.Overlays.Music }, }; - list.BeatmapSets.BindTo(BeatmapSets); + list.Items.BindTo(beatmapSets); filter.Search.OnCommit = (sender, newText) => {