Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make PlaylistItem use Paragraphs #808

Merged
merged 7 commits into from May 20, 2017
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
69 changes: 44 additions & 25 deletions osu.Game/Overlays/Music/PlaylistItem.cs
Expand Up @@ -7,10 +7,10 @@
using osu.Framework.Graphics.Containers;
using osu.Game.Database;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Localisation;
using osu.Framework.Graphics.Sprites;
using System.Collections.Generic;

namespace osu.Game.Overlays.Music
{
Expand All @@ -19,9 +19,13 @@ internal class PlaylistItem : Container, IFilterable
private const float fade_duration = 100;

private Color4 hoverColour;
private Color4 artistColour;

private TextAwesome handle;
private OsuSpriteText title;
private Paragraph text;
private IEnumerable<SpriteText> titleSprites;
private UnicodeBindableString titleBind;
private UnicodeBindableString artistBind;

public readonly BeatmapSetInfo BeatmapSetInfo;

Expand All @@ -37,7 +41,8 @@ public bool Selected
selected = value;

Flush(true);
title.FadeColour(Selected ? hoverColour : Color4.White, fade_duration);
foreach (SpriteText s in titleSprites)
s.FadeColour(Selected ? hoverColour : Color4.White, fade_duration);
}
}

Expand All @@ -53,8 +58,10 @@ public PlaylistItem(BeatmapSetInfo setInfo)
[BackgroundDependencyLoader]
private void load(OsuColour colours, LocalisationEngine localisation)
{
BeatmapMetadata metadata = BeatmapSetInfo.Metadata;
hoverColour = colours.Yellow;
artistColour = colours.Gray9;

var metadata = BeatmapSetInfo.Metadata;
FilterTerms = metadata.SearchableTerms;

Children = new Drawable[]
Expand All @@ -70,33 +77,45 @@ private void load(OsuColour colours, LocalisationEngine localisation)
Margin = new MarginPadding { Left = 5 },
Padding = new MarginPadding { Top = 2 },
},
new FillFlowContainer<OsuSpriteText>
text = new Paragraph
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding { Left = 20 },
Spacing = new Vector2(5f, 0f),
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),
}
}
ContentIndent = 10f,
},
};

hoverColour = colours.Yellow;
titleBind = localisation.GetUnicodePreference(metadata.TitleUnicode, metadata.Title);
artistBind = localisation.GetUnicodePreference(metadata.ArtistUnicode, metadata.Artist);

artistBind.ValueChanged += newText => recreateText();
artistBind.TriggerChange();
}

private void recreateText()
{
text.Clear();

var t = new List<SpriteText>();

//space after the title to put a space between the title and artist
text.AddText(titleBind.Value + @" ", sprite =>

This comment was marked as off-topic.

This comment was marked as off-topic.

{
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)
Expand Down