mirror of
https://github.com/ppy/osu.git
synced 2025-01-30 01:32:55 +08:00
Refactoring part 5.
This commit is contained in:
parent
580cf93147
commit
c1d0aea217
@ -23,29 +23,28 @@ namespace osu.Game.Overlays.Music
|
|||||||
private readonly TextAwesome icon;
|
private readonly TextAwesome icon;
|
||||||
private readonly IEnumerable<OsuSpriteText> title, artist;
|
private readonly IEnumerable<OsuSpriteText> title, artist;
|
||||||
|
|
||||||
public readonly int Index;
|
public readonly BeatmapSetInfo BeatmapSetInfo;
|
||||||
public readonly BeatmapSetInfo RepresentedSet;
|
|
||||||
public Action<BeatmapSetInfo, int> OnSelect;
|
|
||||||
|
|
||||||
private bool current;
|
public Action<BeatmapSetInfo> OnSelect;
|
||||||
public bool Current
|
|
||||||
|
private bool selected;
|
||||||
|
public bool Selected
|
||||||
{
|
{
|
||||||
get { return current; }
|
get { return selected; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value == current) return;
|
if (value == selected) return;
|
||||||
current = value;
|
selected = value;
|
||||||
|
|
||||||
Flush(true);
|
Flush(true);
|
||||||
foreach (OsuSpriteText t in title)
|
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;
|
BeatmapSetInfo = setInfo;
|
||||||
RepresentedSet = set;
|
|
||||||
|
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
AutoSizeAxes = Axes.Y;
|
AutoSizeAxes = Axes.Y;
|
||||||
@ -74,8 +73,8 @@ namespace osu.Game.Overlays.Music
|
|||||||
textContainer,
|
textContainer,
|
||||||
};
|
};
|
||||||
|
|
||||||
textContainer.Add(title = splitText(RepresentedSet.Metadata.Title, 16, @"Exo2.0-Regular", new MarginPadding(0)));
|
textContainer.Add(title = splitText(BeatmapSetInfo.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(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)
|
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)
|
protected override bool OnClick(Framework.Input.InputState state)
|
||||||
{
|
{
|
||||||
OnSelect?.Invoke(RepresentedSet, Index);
|
OnSelect?.Invoke(BeatmapSetInfo);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
@ -17,34 +18,24 @@ namespace osu.Game.Overlays.Music
|
|||||||
{
|
{
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
List<PlaylistItem> newItems = new List<PlaylistItem>();
|
items.Children = value.Select(item => new PlaylistItem(item) { OnSelect = itemSelected }).ToList();
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
foreach (var item in value)
|
|
||||||
{
|
|
||||||
newItems.Add(new PlaylistItem(item, i++)
|
|
||||||
{
|
|
||||||
OnSelect = (b, idx) => OnSelect?.Invoke(b, idx)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
items.Children = newItems;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Action<BeatmapSetInfo, int> OnSelect;
|
private void itemSelected(BeatmapSetInfo b)
|
||||||
|
|
||||||
private BeatmapSetInfo current;
|
|
||||||
public BeatmapSetInfo Current
|
|
||||||
{
|
{
|
||||||
get { return current; }
|
OnSelect?.Invoke(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Action<BeatmapSetInfo> OnSelect;
|
||||||
|
|
||||||
|
public BeatmapSetInfo SelectedItem
|
||||||
|
{
|
||||||
|
get { return items.Children.FirstOrDefault(i => i.Selected)?.BeatmapSetInfo; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value == current) return;
|
|
||||||
current = value;
|
|
||||||
|
|
||||||
foreach (PlaylistItem s in items.Children)
|
foreach (PlaylistItem s in items.Children)
|
||||||
s.Current = s.RepresentedSet.ID == value.ID;
|
s.Selected = s.BeatmapSetInfo.ID == value?.ID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ namespace osu.Game.Overlays.Music
|
|||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
beatmapBacking.ValueChanged += b => list.Current = b?.BeatmapSetInfo;
|
beatmapBacking.ValueChanged += b => list.SelectedItem = b?.BeatmapSetInfo;
|
||||||
beatmapBacking.TriggerChange();
|
beatmapBacking.TriggerChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +97,6 @@ namespace osu.Game.Overlays.Music
|
|||||||
filter.Search.HoldFocus = true;
|
filter.Search.HoldFocus = true;
|
||||||
filter.Search.TriggerFocus();
|
filter.Search.TriggerFocus();
|
||||||
|
|
||||||
|
|
||||||
ResizeTo(new Vector2(1, playlist_height), transition_duration, EasingTypes.OutQuint);
|
ResizeTo(new Vector2(1, playlist_height), transition_duration, EasingTypes.OutQuint);
|
||||||
FadeIn(transition_duration, EasingTypes.OutQuint);
|
FadeIn(transition_duration, EasingTypes.OutQuint);
|
||||||
}
|
}
|
||||||
@ -111,7 +110,7 @@ namespace osu.Game.Overlays.Music
|
|||||||
FadeOut(transition_duration);
|
FadeOut(transition_duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void itemSelected(BeatmapSetInfo set, int index)
|
private void itemSelected(BeatmapSetInfo set)
|
||||||
{
|
{
|
||||||
if (set.ID == (beatmapBacking.Value?.BeatmapSetInfo?.ID ?? -1))
|
if (set.ID == (beatmapBacking.Value?.BeatmapSetInfo?.ID ?? -1))
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user