From c1d0aea217f39d12b1e2e5db3c459f0cd56fe3e8 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 1 May 2017 15:09:14 +0900 Subject: [PATCH] Refactoring part 5. --- osu.Game/Overlays/Music/PlaylistItem.cs | 29 +++++++++---------- osu.Game/Overlays/Music/PlaylistList.cs | 33 ++++++++-------------- osu.Game/Overlays/Music/PlaylistOverlay.cs | 5 ++-- 3 files changed, 28 insertions(+), 39 deletions(-) diff --git a/osu.Game/Overlays/Music/PlaylistItem.cs b/osu.Game/Overlays/Music/PlaylistItem.cs index 083de99f51..681dd7672f 100644 --- a/osu.Game/Overlays/Music/PlaylistItem.cs +++ b/osu.Game/Overlays/Music/PlaylistItem.cs @@ -23,29 +23,28 @@ namespace osu.Game.Overlays.Music private readonly TextAwesome icon; private readonly IEnumerable title, artist; - public readonly int Index; - public readonly BeatmapSetInfo RepresentedSet; - public Action OnSelect; + public readonly BeatmapSetInfo BeatmapSetInfo; - private bool current; - public bool Current + public Action OnSelect; + + private bool selected; + public bool Selected { - get { return current; } + get { return selected; } set { - if (value == current) return; - current = value; + if (value == selected) return; + selected = value; Flush(true); foreach (OsuSpriteText t in title) - t.FadeColour(Current ? currentColour : Color4.White, fade_duration); + t.FadeColour(Selected ? currentColour : Color4.White, fade_duration); } } - public PlaylistItem(BeatmapSetInfo set, int index) + public PlaylistItem(BeatmapSetInfo setInfo) { - Index = index; - RepresentedSet = set; + BeatmapSetInfo = setInfo; RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; @@ -74,8 +73,8 @@ namespace osu.Game.Overlays.Music textContainer, }; - textContainer.Add(title = splitText(RepresentedSet.Metadata.Title, 16, @"Exo2.0-Regular", new MarginPadding(0))); - textContainer.Add(artist = splitText(RepresentedSet.Metadata.Artist, 14, @"Exo2.0-Bold", new MarginPadding { Top = 1 })); + textContainer.Add(title = splitText(BeatmapSetInfo.Metadata.Title, 16, @"Exo2.0-Regular", new MarginPadding(0))); + textContainer.Add(artist = splitText(BeatmapSetInfo.Metadata.Artist, 14, @"Exo2.0-Bold", new MarginPadding { Top = 1 })); } private IEnumerable splitText(string text, int textSize, string font, MarginPadding padding) @@ -120,7 +119,7 @@ namespace osu.Game.Overlays.Music protected override bool OnClick(Framework.Input.InputState state) { - OnSelect?.Invoke(RepresentedSet, Index); + OnSelect?.Invoke(BeatmapSetInfo); return true; } } diff --git a/osu.Game/Overlays/Music/PlaylistList.cs b/osu.Game/Overlays/Music/PlaylistList.cs index b085515400..5d95bb1b4a 100644 --- a/osu.Game/Overlays/Music/PlaylistList.cs +++ b/osu.Game/Overlays/Music/PlaylistList.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Linq; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Database; @@ -17,34 +18,24 @@ namespace osu.Game.Overlays.Music { set { - List newItems = new List(); - - int i = 0; - foreach (var item in value) - { - newItems.Add(new PlaylistItem(item, i++) - { - OnSelect = (b, idx) => OnSelect?.Invoke(b, idx) - }); - } - - items.Children = newItems; + items.Children = value.Select(item => new PlaylistItem(item) { OnSelect = itemSelected }).ToList(); } } - public Action OnSelect; - - private BeatmapSetInfo current; - public BeatmapSetInfo Current + private void itemSelected(BeatmapSetInfo b) { - get { return current; } + OnSelect?.Invoke(b); + } + + public Action OnSelect; + + public BeatmapSetInfo SelectedItem + { + get { return items.Children.FirstOrDefault(i => i.Selected)?.BeatmapSetInfo; } set { - if (value == current) return; - current = value; - foreach (PlaylistItem s in items.Children) - s.Current = s.RepresentedSet.ID == value.ID; + s.Selected = s.BeatmapSetInfo.ID == value?.ID; } } diff --git a/osu.Game/Overlays/Music/PlaylistOverlay.cs b/osu.Game/Overlays/Music/PlaylistOverlay.cs index b556b595ec..434f534e5f 100644 --- a/osu.Game/Overlays/Music/PlaylistOverlay.cs +++ b/osu.Game/Overlays/Music/PlaylistOverlay.cs @@ -88,7 +88,7 @@ namespace osu.Game.Overlays.Music protected override void LoadComplete() { base.LoadComplete(); - beatmapBacking.ValueChanged += b => list.Current = b?.BeatmapSetInfo; + beatmapBacking.ValueChanged += b => list.SelectedItem = b?.BeatmapSetInfo; beatmapBacking.TriggerChange(); } @@ -97,7 +97,6 @@ namespace osu.Game.Overlays.Music filter.Search.HoldFocus = true; filter.Search.TriggerFocus(); - ResizeTo(new Vector2(1, playlist_height), transition_duration, EasingTypes.OutQuint); FadeIn(transition_duration, EasingTypes.OutQuint); } @@ -111,7 +110,7 @@ namespace osu.Game.Overlays.Music FadeOut(transition_duration); } - private void itemSelected(BeatmapSetInfo set, int index) + private void itemSelected(BeatmapSetInfo set) { if (set.ID == (beatmapBacking.Value?.BeatmapSetInfo?.ID ?? -1)) {