2019-01-24 16:43:03 +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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2021-10-25 13:44:49 +08:00
|
|
|
|
using System.Linq;
|
2017-09-08 01:53:53 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2021-10-25 13:44:49 +08:00
|
|
|
|
using osu.Framework.Extensions.LocalisationExtensions;
|
2017-09-08 01:53:53 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2021-08-09 04:00:12 +08:00
|
|
|
|
using osu.Game.Resources.Localisation.Web;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-08 01:53:53 +08:00
|
|
|
|
namespace osu.Game.Screens.Select.Details
|
|
|
|
|
{
|
|
|
|
|
public class UserRatings : Container
|
|
|
|
|
{
|
|
|
|
|
private readonly FillFlowContainer header;
|
|
|
|
|
private readonly Bar ratingsBar;
|
|
|
|
|
private readonly OsuSpriteText negativeRatings, positiveRatings;
|
|
|
|
|
private readonly Container graphContainer;
|
|
|
|
|
private readonly BarGraph graph;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-10-25 13:44:49 +08:00
|
|
|
|
private int[] ratings;
|
2018-04-18 15:04:02 +08:00
|
|
|
|
|
2021-10-25 13:44:49 +08:00
|
|
|
|
public int[] Ratings
|
2017-09-08 01:53:53 +08:00
|
|
|
|
{
|
2021-10-25 13:44:49 +08:00
|
|
|
|
get => ratings;
|
2017-09-08 01:53:53 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
2021-10-25 13:44:49 +08:00
|
|
|
|
if (value == ratings) return;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2021-10-25 13:44:49 +08:00
|
|
|
|
ratings = value;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-11-23 17:09:42 +08:00
|
|
|
|
const int rating_range = 10;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-10-25 13:44:49 +08:00
|
|
|
|
if (ratings == null)
|
2018-04-18 15:04:02 +08:00
|
|
|
|
{
|
2021-08-16 18:46:41 +08:00
|
|
|
|
negativeRatings.Text = 0.ToLocalisableString(@"N0");
|
|
|
|
|
positiveRatings.Text = 0.ToLocalisableString(@"N0");
|
2018-04-18 15:04:02 +08:00
|
|
|
|
ratingsBar.Length = 0;
|
|
|
|
|
graph.Values = new float[rating_range];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-10-25 13:44:49 +08:00
|
|
|
|
var usableRange = Ratings.Skip(1).Take(rating_range); // adjust for API returning weird empty data at 0.
|
2018-04-18 15:04:02 +08:00
|
|
|
|
|
2021-10-27 12:04:41 +08:00
|
|
|
|
int negativeCount = usableRange.Take(rating_range / 2).Sum();
|
|
|
|
|
int totalCount = usableRange.Sum();
|
2018-04-18 15:04:02 +08:00
|
|
|
|
|
2021-08-16 18:46:41 +08:00
|
|
|
|
negativeRatings.Text = negativeCount.ToLocalisableString(@"N0");
|
|
|
|
|
positiveRatings.Text = (totalCount - negativeCount).ToLocalisableString(@"N0");
|
2018-04-18 15:04:02 +08:00
|
|
|
|
ratingsBar.Length = totalCount == 0 ? 0 : (float)negativeCount / totalCount;
|
2021-10-25 13:44:49 +08:00
|
|
|
|
graph.Values = usableRange.Take(rating_range).Select(r => (float)r);
|
2018-04-18 15:04:02 +08:00
|
|
|
|
}
|
2017-09-08 01:53:53 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-08 01:53:53 +08:00
|
|
|
|
public UserRatings()
|
|
|
|
|
{
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
header = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
2021-08-09 04:00:12 +08:00
|
|
|
|
Text = BeatmapsetsStrings.ShowStatsUserRating,
|
2020-02-17 04:43:33 +08:00
|
|
|
|
Font = OsuFont.GetFont(size: 12),
|
|
|
|
|
Margin = new MarginPadding { Bottom = 5 },
|
2017-09-08 01:53:53 +08:00
|
|
|
|
},
|
|
|
|
|
ratingsBar = new Bar
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Height = 5,
|
|
|
|
|
},
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2020-02-17 04:43:33 +08:00
|
|
|
|
Margin = new MarginPadding { Bottom = 10 },
|
2017-09-08 01:53:53 +08:00
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
negativeRatings = new OsuSpriteText
|
|
|
|
|
{
|
2021-08-16 18:46:41 +08:00
|
|
|
|
Text = 0.ToLocalisableString(@"N0"),
|
2020-02-17 04:43:33 +08:00
|
|
|
|
Font = OsuFont.GetFont(size: 12)
|
2017-09-08 01:53:53 +08:00
|
|
|
|
},
|
|
|
|
|
positiveRatings = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
|
Origin = Anchor.TopRight,
|
2021-08-16 18:46:41 +08:00
|
|
|
|
Text = 0.ToLocalisableString(@"N0"),
|
2020-02-17 04:43:33 +08:00
|
|
|
|
Font = OsuFont.GetFont(size: 12)
|
2017-09-08 01:53:53 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
2021-08-09 04:00:12 +08:00
|
|
|
|
Text = BeatmapsetsStrings.ShowStatsRatingSpread,
|
2020-02-17 04:43:33 +08:00
|
|
|
|
Font = OsuFont.GetFont(size: 12),
|
|
|
|
|
Margin = new MarginPadding { Bottom = 5 },
|
2017-09-08 01:53:53 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
graphContainer = new Container
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Child = graph = new BarGraph
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-08 01:53:53 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
ratingsBar.BackgroundColour = colours.Green;
|
|
|
|
|
ratingsBar.AccentColour = colours.Yellow;
|
|
|
|
|
graph.Colour = colours.BlueDark;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-08 01:53:53 +08:00
|
|
|
|
protected override void UpdateAfterChildren()
|
|
|
|
|
{
|
|
|
|
|
base.UpdateAfterChildren();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-08 01:53:53 +08:00
|
|
|
|
graphContainer.Padding = new MarginPadding { Top = header.DrawHeight };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|