2019-01-24 17:43:03 +09: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 18:19:50 +09:00
|
|
|
|
|
|
|
|
|
using System;
|
2018-04-15 23:44:59 +02:00
|
|
|
|
using System.Collections.Generic;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
using System.Linq;
|
2020-03-05 20:11:14 +01:00
|
|
|
|
using Humanizer;
|
2019-02-21 19:04:31 +09:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Users;
|
|
|
|
|
|
2019-04-26 13:49:44 +09:00
|
|
|
|
namespace osu.Game.Overlays.Profile.Header.Components
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
2020-02-07 23:26:35 +03:00
|
|
|
|
public class RankGraph : UserGraph<int, int>
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
|
|
|
|
private const int ranked_days = 88;
|
|
|
|
|
|
2019-08-04 14:35:26 +03:00
|
|
|
|
public readonly Bindable<UserStatistics> Statistics = new Bindable<UserStatistics>();
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2020-02-07 23:26:35 +03:00
|
|
|
|
private readonly OsuSpriteText placeholder;
|
|
|
|
|
|
2018-04-13 18:19:50 +09:00
|
|
|
|
public RankGraph()
|
|
|
|
|
{
|
2020-02-07 23:26:35 +03:00
|
|
|
|
Add(placeholder = new OsuSpriteText
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
2020-02-07 23:26:35 +03:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Text = "No recent plays",
|
|
|
|
|
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Regular)
|
|
|
|
|
});
|
2018-04-13 18:19:50 +09:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-04 14:35:26 +03:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2019-08-05 12:49:54 +03:00
|
|
|
|
Statistics.BindValueChanged(statistics => updateStatistics(statistics.NewValue), true);
|
2019-08-04 14:35:26 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateStatistics(UserStatistics statistics)
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
2020-02-12 20:19:20 +01:00
|
|
|
|
int[] userRanks = statistics?.RankHistory?.Data;
|
2020-03-09 19:42:35 +03:00
|
|
|
|
Data = userRanks?.Select((x, index) => new KeyValuePair<int, int>(index, x)).Where(x => x.Value != 0).ToArray();
|
2020-02-12 20:19:20 +01:00
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2020-02-12 20:19:20 +01:00
|
|
|
|
protected override float GetDataPointHeight(int rank) => -MathF.Log(rank);
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2020-02-12 20:19:20 +01:00
|
|
|
|
protected override void ShowGraph()
|
|
|
|
|
{
|
|
|
|
|
base.ShowGraph();
|
|
|
|
|
placeholder.FadeOut(FADE_DURATION, Easing.Out);
|
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2020-02-12 20:19:20 +01:00
|
|
|
|
protected override void HideGraph()
|
|
|
|
|
{
|
|
|
|
|
base.HideGraph();
|
|
|
|
|
placeholder.FadeIn(FADE_DURATION, Easing.Out);
|
2018-04-13 18:19:50 +09:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-12 19:15:37 +01:00
|
|
|
|
protected override object GetTooltipContent(int index, int rank)
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
2020-02-12 19:15:37 +01:00
|
|
|
|
var days = ranked_days - index + 1;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2020-02-07 23:26:35 +03:00
|
|
|
|
return new TooltipDisplayContent
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
2020-03-05 20:11:14 +01:00
|
|
|
|
Rank = $"#{rank:N0}",
|
|
|
|
|
Time = days == 0 ? "now" : $"{"day".ToQuantity(days)} ago"
|
2020-02-07 23:26:35 +03:00
|
|
|
|
};
|
2019-08-16 19:47:35 +09:00
|
|
|
|
}
|
2018-12-22 21:50:25 +01:00
|
|
|
|
|
2020-02-07 23:26:35 +03:00
|
|
|
|
protected override UserGraphTooltip GetTooltip() => new RankGraphTooltip();
|
2018-12-22 21:50:25 +01:00
|
|
|
|
|
2020-02-07 23:26:35 +03:00
|
|
|
|
private class RankGraphTooltip : UserGraphTooltip
|
2018-12-22 21:50:25 +01:00
|
|
|
|
{
|
2020-03-10 00:50:12 +03:00
|
|
|
|
public RankGraphTooltip()
|
2020-03-21 14:28:23 +01:00
|
|
|
|
: base("Global Ranking")
|
2020-03-10 00:50:12 +03:00
|
|
|
|
{
|
|
|
|
|
}
|
2018-12-22 21:50:25 +01:00
|
|
|
|
|
2020-02-07 23:26:35 +03:00
|
|
|
|
public override bool SetContent(object content)
|
2018-12-22 21:50:25 +01:00
|
|
|
|
{
|
2019-08-16 19:47:35 +09:00
|
|
|
|
if (!(content is TooltipDisplayContent info))
|
|
|
|
|
return false;
|
|
|
|
|
|
2020-02-07 23:26:35 +03:00
|
|
|
|
Counter.Text = info.Rank;
|
|
|
|
|
BottomText.Text = info.Time;
|
2019-08-16 19:47:35 +09:00
|
|
|
|
return true;
|
2018-12-22 21:50:25 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-16 19:47:35 +09:00
|
|
|
|
|
|
|
|
|
private class TooltipDisplayContent
|
|
|
|
|
{
|
|
|
|
|
public string Rank;
|
|
|
|
|
public string Time;
|
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
}
|
|
|
|
|
}
|