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
|
|
|
|
|
|
|
|
|
using System;
|
2018-04-16 05:44:59 +08:00
|
|
|
|
using System.Collections.Generic;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using System.Linq;
|
2020-03-06 03:11:14 +08:00
|
|
|
|
using Humanizer;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2021-08-29 20:00:28 +08:00
|
|
|
|
using osu.Framework.Extensions.LocalisationExtensions;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2021-07-17 21:25:45 +08:00
|
|
|
|
using osu.Game.Resources.Localisation.Web;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Users;
|
|
|
|
|
|
2019-04-26 12:49:44 +08:00
|
|
|
|
namespace osu.Game.Overlays.Profile.Header.Components
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-02-08 04:26:35 +08:00
|
|
|
|
public class RankGraph : UserGraph<int, int>
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
private const int ranked_days = 88;
|
|
|
|
|
|
2019-08-04 19:35:26 +08:00
|
|
|
|
public readonly Bindable<UserStatistics> Statistics = new Bindable<UserStatistics>();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-02-08 04:26:35 +08:00
|
|
|
|
private readonly OsuSpriteText placeholder;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public RankGraph()
|
|
|
|
|
{
|
2020-02-08 04:26:35 +08:00
|
|
|
|
Add(placeholder = new OsuSpriteText
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-02-08 04:26:35 +08:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2021-07-17 21:25:45 +08:00
|
|
|
|
Text = UsersStrings.ShowExtraUnranked,
|
2020-02-08 04:26:35 +08:00
|
|
|
|
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Regular)
|
|
|
|
|
});
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-04 19:35:26 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2019-08-05 17:49:54 +08:00
|
|
|
|
Statistics.BindValueChanged(statistics => updateStatistics(statistics.NewValue), true);
|
2019-08-04 19:35:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateStatistics(UserStatistics statistics)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-02-13 03:19:20 +08:00
|
|
|
|
int[] userRanks = statistics?.RankHistory?.Data;
|
2020-03-10 00:42:35 +08:00
|
|
|
|
Data = userRanks?.Select((x, index) => new KeyValuePair<int, int>(index, x)).Where(x => x.Value != 0).ToArray();
|
2020-02-13 03:19:20 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-02-13 03:19:20 +08:00
|
|
|
|
protected override float GetDataPointHeight(int rank) => -MathF.Log(rank);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-02-13 03:19:20 +08:00
|
|
|
|
protected override void ShowGraph()
|
|
|
|
|
{
|
|
|
|
|
base.ShowGraph();
|
|
|
|
|
placeholder.FadeOut(FADE_DURATION, Easing.Out);
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-02-13 03:19:20 +08:00
|
|
|
|
protected override void HideGraph()
|
|
|
|
|
{
|
|
|
|
|
base.HideGraph();
|
|
|
|
|
placeholder.FadeIn(FADE_DURATION, Easing.Out);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-29 00:11:44 +08:00
|
|
|
|
protected override UserGraphTooltipContent GetTooltipContent(int index, int rank)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-02-13 02:15:37 +08:00
|
|
|
|
var days = ranked_days - index + 1;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-08-29 00:11:44 +08:00
|
|
|
|
return new UserGraphTooltipContent
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-08-29 00:11:44 +08:00
|
|
|
|
Name = UsersStrings.ShowRankGlobalSimple,
|
|
|
|
|
Count = rank.ToLocalisableString("\\##,##0"),
|
2020-03-06 03:11:14 +08:00
|
|
|
|
Time = days == 0 ? "now" : $"{"day".ToQuantity(days)} ago"
|
2020-02-08 04:26:35 +08:00
|
|
|
|
};
|
2019-08-16 18:47:35 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|