1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-30 21:32:57 +08:00

Make PlaylistItem use Paragraphs

This commit is contained in:
DrabWeb 2017-05-20 01:11:20 -03:00
parent 5d818620c9
commit dcc3dbf5e2

View File

@ -11,6 +11,9 @@ using osu.Game.Graphics.Sprites;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Framework.Localisation; using osu.Framework.Localisation;
using osu.Framework.Graphics.Sprites;
using System.Collections.Generic;
using System.Linq;
namespace osu.Game.Overlays.Music namespace osu.Game.Overlays.Music
{ {
@ -19,9 +22,13 @@ namespace osu.Game.Overlays.Music
private const float fade_duration = 100; private const float fade_duration = 100;
private Color4 hoverColour; private Color4 hoverColour;
private Color4 artistColour;
private TextAwesome handle; private TextAwesome handle;
private OsuSpriteText title; private Paragraph text;
private IEnumerable<SpriteText> titleSprites;
private UnicodeBindableString titleBind;
private UnicodeBindableString artistBind;
public readonly BeatmapSetInfo BeatmapSetInfo; public readonly BeatmapSetInfo BeatmapSetInfo;
@ -37,7 +44,8 @@ namespace osu.Game.Overlays.Music
selected = value; selected = value;
Flush(true); Flush(true);
title.FadeColour(Selected ? hoverColour : Color4.White, fade_duration); foreach (SpriteText s in titleSprites)
s.FadeColour(Selected ? hoverColour : Color4.White, fade_duration);
} }
} }
@ -53,8 +61,10 @@ namespace osu.Game.Overlays.Music
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours, LocalisationEngine localisation) private void load(OsuColour colours, LocalisationEngine localisation)
{ {
BeatmapMetadata metadata = BeatmapSetInfo.Metadata; hoverColour = colours.Yellow;
artistColour = colours.Gray9;
var metadata = BeatmapSetInfo.Metadata;
FilterTerms = metadata.SearchableTerms; FilterTerms = metadata.SearchableTerms;
Children = new Drawable[] Children = new Drawable[]
@ -70,33 +80,46 @@ namespace osu.Game.Overlays.Music
Margin = new MarginPadding { Left = 5 }, Margin = new MarginPadding { Left = 5 },
Padding = new MarginPadding { Top = 2 }, Padding = new MarginPadding { Top = 2 },
}, },
new FillFlowContainer<OsuSpriteText> text = new Paragraph
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
Padding = new MarginPadding { Left = 20 }, Padding = new MarginPadding { Left = 20 },
Spacing = new Vector2(5f, 0f), ContentIndent = 10f,
Children = new []
{
title = new OsuSpriteText
{
TextSize = 16,
Font = @"Exo2.0-Regular",
Current = localisation.GetUnicodePreference(metadata.TitleUnicode, metadata.Title),
},
new OsuSpriteText
{
TextSize = 14,
Font = @"Exo2.0-Bold",
Colour = colours.Gray9,
Padding = new MarginPadding { Top = 1 },
Current = localisation.GetUnicodePreference(metadata.ArtistUnicode, metadata.Artist),
}
}
}, },
}; };
hoverColour = colours.Yellow; titleBind = localisation.GetUnicodePreference(metadata.TitleUnicode, metadata.Title);
artistBind = localisation.GetUnicodePreference(metadata.ArtistUnicode, metadata.Artist);
titleBind.ValueChanged += newText => recreateText();
titleBind.TriggerChange();
}
private void recreateText()
{
text.Clear();
var metadata = BeatmapSetInfo.Metadata;
var t = new List<SpriteText>();
//space after the title to put a space between the title and artist
text.AddText(titleBind.Value + @" ", sprite =>
{
sprite.TextSize = 16;
sprite.Font = @"Exo2.0-Regular";
t.Add(sprite);
});
titleSprites = t;
text.AddText(artistBind.Value, sprite =>
{
sprite.TextSize = 14;
sprite.Font = @"Exo2.0-Bold";
sprite.Colour = artistColour;
sprite.Padding = new MarginPadding { Top = 1 };
});
} }
protected override bool OnHover(Framework.Input.InputState state) protected override bool OnHover(Framework.Input.InputState state)