Refactoring part 5.

This commit is contained in:
Dean Herbert 2017-05-01 15:09:14 +09:00
parent 580cf93147
commit c1d0aea217
3 changed files with 28 additions and 39 deletions

View File

@ -23,29 +23,28 @@ namespace osu.Game.Overlays.Music
private readonly TextAwesome icon;
private readonly IEnumerable<OsuSpriteText> title, artist;
public readonly int Index;
public readonly BeatmapSetInfo RepresentedSet;
public Action<BeatmapSetInfo, int> OnSelect;
public readonly BeatmapSetInfo BeatmapSetInfo;
private bool current;
public bool Current
public Action<BeatmapSetInfo> 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<OsuSpriteText> 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;
}
}

View File

@ -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<PlaylistItem> newItems = new List<PlaylistItem>();
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<BeatmapSetInfo, int> OnSelect;
private BeatmapSetInfo current;
public BeatmapSetInfo Current
private void itemSelected(BeatmapSetInfo b)
{
get { return current; }
OnSelect?.Invoke(b);
}
public Action<BeatmapSetInfo> 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;
}
}

View File

@ -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))
{