2017-05-01 14:03:11 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Database;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using OpenTK.Graphics;
|
2017-05-01 16:14:59 +08:00
|
|
|
|
using osu.Framework.Localisation;
|
2017-05-20 12:11:20 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using System.Collections.Generic;
|
2017-05-01 14:03:11 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Music
|
|
|
|
|
{
|
2017-05-02 09:45:55 +08:00
|
|
|
|
internal class PlaylistItem : Container, IFilterable
|
2017-05-01 14:03:11 +08:00
|
|
|
|
{
|
|
|
|
|
private const float fade_duration = 100;
|
|
|
|
|
|
2017-05-01 16:14:59 +08:00
|
|
|
|
private Color4 hoverColour;
|
2017-05-20 12:11:20 +08:00
|
|
|
|
private Color4 artistColour;
|
2017-05-01 16:14:59 +08:00
|
|
|
|
|
|
|
|
|
private TextAwesome handle;
|
2017-05-20 12:11:20 +08:00
|
|
|
|
private Paragraph text;
|
|
|
|
|
private IEnumerable<SpriteText> titleSprites;
|
|
|
|
|
private UnicodeBindableString titleBind;
|
|
|
|
|
private UnicodeBindableString artistBind;
|
2017-05-01 14:03:11 +08:00
|
|
|
|
|
2017-05-01 14:09:14 +08:00
|
|
|
|
public readonly BeatmapSetInfo BeatmapSetInfo;
|
2017-05-01 14:03:11 +08:00
|
|
|
|
|
2017-05-01 14:09:14 +08:00
|
|
|
|
public Action<BeatmapSetInfo> OnSelect;
|
|
|
|
|
|
|
|
|
|
private bool selected;
|
|
|
|
|
public bool Selected
|
2017-05-01 14:03:11 +08:00
|
|
|
|
{
|
2017-05-01 14:09:14 +08:00
|
|
|
|
get { return selected; }
|
2017-05-01 14:03:11 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
2017-05-01 14:09:14 +08:00
|
|
|
|
if (value == selected) return;
|
|
|
|
|
selected = value;
|
2017-05-01 14:03:11 +08:00
|
|
|
|
|
|
|
|
|
Flush(true);
|
2017-05-20 12:11:20 +08:00
|
|
|
|
foreach (SpriteText s in titleSprites)
|
|
|
|
|
s.FadeColour(Selected ? hoverColour : Color4.White, fade_duration);
|
2017-05-01 14:03:11 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-01 14:09:14 +08:00
|
|
|
|
public PlaylistItem(BeatmapSetInfo setInfo)
|
2017-05-01 14:03:11 +08:00
|
|
|
|
{
|
2017-05-01 14:09:14 +08:00
|
|
|
|
BeatmapSetInfo = setInfo;
|
2017-05-01 14:03:11 +08:00
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
Padding = new MarginPadding { Top = 3, Bottom = 3 };
|
2017-05-01 16:14:59 +08:00
|
|
|
|
}
|
2017-05-01 14:03:11 +08:00
|
|
|
|
|
2017-05-01 16:14:59 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours, LocalisationEngine localisation)
|
|
|
|
|
{
|
2017-05-20 12:11:20 +08:00
|
|
|
|
hoverColour = colours.Yellow;
|
|
|
|
|
artistColour = colours.Gray9;
|
2017-05-20 12:17:04 +08:00
|
|
|
|
|
2017-05-20 12:11:20 +08:00
|
|
|
|
var metadata = BeatmapSetInfo.Metadata;
|
2017-05-02 09:45:55 +08:00
|
|
|
|
FilterTerms = metadata.SearchableTerms;
|
|
|
|
|
|
2017-05-01 14:03:11 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-05-01 16:14:59 +08:00
|
|
|
|
handle = new TextAwesome
|
2017-05-01 14:03:11 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopLeft,
|
|
|
|
|
Origin = Anchor.TopLeft,
|
|
|
|
|
TextSize = 12,
|
2017-05-01 16:14:59 +08:00
|
|
|
|
Colour = colours.Gray5,
|
2017-05-01 14:03:11 +08:00
|
|
|
|
Icon = FontAwesome.fa_bars,
|
|
|
|
|
Alpha = 0f,
|
|
|
|
|
Margin = new MarginPadding { Left = 5 },
|
|
|
|
|
Padding = new MarginPadding { Top = 2 },
|
|
|
|
|
},
|
2017-05-20 12:11:20 +08:00
|
|
|
|
text = new Paragraph
|
2017-05-01 14:03:11 +08:00
|
|
|
|
{
|
2017-05-01 16:14:59 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Padding = new MarginPadding { Left = 20 },
|
2017-05-20 12:11:20 +08:00
|
|
|
|
ContentIndent = 10f,
|
2017-05-01 16:14:59 +08:00
|
|
|
|
},
|
|
|
|
|
};
|
2017-05-01 14:03:11 +08:00
|
|
|
|
|
2017-05-20 12:11:20 +08:00
|
|
|
|
titleBind = localisation.GetUnicodePreference(metadata.TitleUnicode, metadata.Title);
|
|
|
|
|
artistBind = localisation.GetUnicodePreference(metadata.ArtistUnicode, metadata.Artist);
|
|
|
|
|
|
2017-05-20 12:25:42 +08:00
|
|
|
|
artistBind.ValueChanged += newText => recreateText();
|
2017-05-20 13:05:13 +08:00
|
|
|
|
artistBind.TriggerChange();
|
2017-05-20 12:11:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void recreateText()
|
|
|
|
|
{
|
|
|
|
|
text.Clear();
|
|
|
|
|
|
2017-05-20 14:14:22 +08:00
|
|
|
|
//space after the title to put a space between the title and artist
|
|
|
|
|
titleSprites = text.AddText(titleBind.Value + @" ", sprite =>
|
2017-05-20 12:11:20 +08:00
|
|
|
|
{
|
|
|
|
|
sprite.TextSize = 16;
|
|
|
|
|
sprite.Font = @"Exo2.0-Regular";
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
text.AddText(artistBind.Value, sprite =>
|
|
|
|
|
{
|
|
|
|
|
sprite.TextSize = 14;
|
|
|
|
|
sprite.Font = @"Exo2.0-Bold";
|
|
|
|
|
sprite.Colour = artistColour;
|
|
|
|
|
sprite.Padding = new MarginPadding { Top = 1 };
|
|
|
|
|
});
|
2017-05-01 14:03:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(Framework.Input.InputState state)
|
|
|
|
|
{
|
2017-05-01 16:14:59 +08:00
|
|
|
|
handle.FadeIn(fade_duration);
|
2017-05-01 14:03:11 +08:00
|
|
|
|
|
|
|
|
|
return base.OnHover(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(Framework.Input.InputState state)
|
|
|
|
|
{
|
2017-05-01 16:14:59 +08:00
|
|
|
|
handle.FadeOut(fade_duration);
|
2017-05-01 14:03:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnClick(Framework.Input.InputState state)
|
|
|
|
|
{
|
2017-05-01 14:09:14 +08:00
|
|
|
|
OnSelect?.Invoke(BeatmapSetInfo);
|
2017-05-01 14:03:11 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-05-02 09:45:55 +08:00
|
|
|
|
|
|
|
|
|
public string[] FilterTerms { get; private set; }
|
|
|
|
|
|
|
|
|
|
private bool matching = true;
|
|
|
|
|
|
|
|
|
|
public bool MatchingCurrentFilter
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (matching == value) return;
|
|
|
|
|
|
|
|
|
|
matching = value;
|
|
|
|
|
|
|
|
|
|
FadeTo(matching ? 1 : 0, 200);
|
|
|
|
|
}
|
2017-05-05 12:59:24 +08:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return matching;
|
|
|
|
|
}
|
2017-05-02 09:45:55 +08:00
|
|
|
|
}
|
2017-05-01 14:03:11 +08:00
|
|
|
|
}
|
|
|
|
|
}
|