2020-03-17 16:25:24 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
using System.Globalization;
|
|
|
|
using osu.Framework.Allocation;
|
2021-05-08 17:55:07 +08:00
|
|
|
using osu.Framework.Bindables;
|
2020-03-17 16:25:24 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2021-05-08 17:55:07 +08:00
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2020-03-17 16:25:24 +08:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Graphics;
|
2021-05-10 15:16:52 +08:00
|
|
|
using osu.Game.Graphics.Containers;
|
2020-03-17 16:25:24 +08:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Ranking.Expanded
|
|
|
|
{
|
2020-03-17 16:34:16 +08:00
|
|
|
/// <summary>
|
|
|
|
/// A pill that displays the star rating of a <see cref="BeatmapInfo"/>.
|
|
|
|
/// </summary>
|
2021-05-14 21:01:25 +08:00
|
|
|
public class StarRatingDisplay : CompositeDrawable, IHasCurrentValue<StarDifficulty>
|
2020-03-17 16:25:24 +08:00
|
|
|
{
|
2021-05-08 17:55:07 +08:00
|
|
|
private Box background;
|
2021-05-10 15:16:52 +08:00
|
|
|
private OsuTextFlowContainer textFlow;
|
2021-05-08 17:55:07 +08:00
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private OsuColour colours { get; set; }
|
|
|
|
|
2021-05-14 21:01:25 +08:00
|
|
|
private readonly BindableWithCurrent<StarDifficulty> current = new BindableWithCurrent<StarDifficulty>();
|
2021-05-08 17:55:07 +08:00
|
|
|
|
2021-05-14 21:01:25 +08:00
|
|
|
public Bindable<StarDifficulty> Current
|
2021-05-08 17:55:07 +08:00
|
|
|
{
|
|
|
|
get => current.Current;
|
|
|
|
set => current.Current = value;
|
|
|
|
}
|
2020-10-22 01:05:14 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Creates a new <see cref="StarRatingDisplay"/> using an already computed <see cref="StarDifficulty"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="starDifficulty">The already computed <see cref="StarDifficulty"/> to display the star difficulty of.</param>
|
2021-05-09 02:13:18 +08:00
|
|
|
public StarRatingDisplay(StarDifficulty starDifficulty)
|
2020-10-22 01:05:14 +08:00
|
|
|
{
|
2021-05-08 17:55:07 +08:00
|
|
|
Current.Value = starDifficulty;
|
2020-03-17 16:25:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2020-11-06 12:14:23 +08:00
|
|
|
private void load(OsuColour colours, BeatmapDifficultyCache difficultyCache)
|
2020-03-17 16:25:24 +08:00
|
|
|
{
|
2020-10-22 01:05:14 +08:00
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
2020-03-17 16:25:24 +08:00
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
new CircularContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Masking = true,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2021-05-08 17:55:07 +08:00
|
|
|
background = new Box
|
2020-03-17 16:25:24 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Padding = new MarginPadding { Horizontal = 8, Vertical = 4 },
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Spacing = new Vector2(2, 0),
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new SpriteIcon
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Size = new Vector2(7),
|
|
|
|
Icon = FontAwesome.Solid.Star,
|
|
|
|
Colour = Color4.Black
|
|
|
|
},
|
2021-05-10 15:16:52 +08:00
|
|
|
textFlow = new OsuTextFlowContainer(s => s.Font = OsuFont.Numeric.With(weight: FontWeight.Black))
|
2020-03-17 16:25:24 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Horizontal,
|
2021-05-10 15:16:52 +08:00
|
|
|
TextAnchor = Anchor.BottomLeft,
|
2021-05-08 17:55:07 +08:00
|
|
|
}
|
2020-03-17 16:25:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2021-05-08 17:55:07 +08:00
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
2021-05-09 02:13:18 +08:00
|
|
|
|
|
|
|
Current.BindValueChanged(_ => updateDisplay(), true);
|
2021-05-08 17:55:07 +08:00
|
|
|
}
|
|
|
|
|
2021-05-09 02:13:18 +08:00
|
|
|
private void updateDisplay()
|
2021-05-08 17:55:07 +08:00
|
|
|
{
|
2021-05-14 21:01:25 +08:00
|
|
|
var starRatingParts = Current.Value.Stars.ToString("0.00", CultureInfo.InvariantCulture).Split('.');
|
2021-05-10 15:16:52 +08:00
|
|
|
string wholePart = starRatingParts[0];
|
|
|
|
string fractionPart = starRatingParts[1];
|
|
|
|
string separator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
|
2021-05-08 17:55:07 +08:00
|
|
|
|
2021-05-14 21:01:25 +08:00
|
|
|
var rating = Current.Value.DifficultyRating;
|
2021-05-08 17:55:07 +08:00
|
|
|
|
2021-07-01 18:37:21 +08:00
|
|
|
background.Colour = colours.ForDifficultyRating(rating, true);
|
2021-05-09 02:13:18 +08:00
|
|
|
|
2021-05-10 15:16:52 +08:00
|
|
|
textFlow.Clear();
|
|
|
|
textFlow.AddText($"{wholePart}", s =>
|
|
|
|
{
|
|
|
|
s.Colour = Color4.Black;
|
|
|
|
s.Font = s.Font.With(size: 14);
|
|
|
|
s.UseFullGlyphHeight = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
textFlow.AddText($"{separator}{fractionPart}", s =>
|
|
|
|
{
|
|
|
|
s.Colour = Color4.Black;
|
|
|
|
s.Font = s.Font.With(size: 7);
|
|
|
|
s.UseFullGlyphHeight = false;
|
|
|
|
});
|
2021-05-08 17:55:07 +08:00
|
|
|
}
|
2020-03-17 16:25:24 +08:00
|
|
|
}
|
|
|
|
}
|