2019-09-19 06:44:05 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-07-14 09:34:12 +00:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
2019-09-19 06:38:40 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading;
|
2019-12-03 06:28:10 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-07-14 09:40:54 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2019-07-14 09:34:12 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2019-12-03 06:28:10 +00:00
|
|
|
|
using osu.Game.Rulesets;
|
2019-09-19 06:44:05 +00:00
|
|
|
|
using osuTK;
|
2019-07-14 09:34:12 +00:00
|
|
|
|
|
2020-08-31 10:54:22 +00:00
|
|
|
|
namespace osu.Game.Online.Leaderboards
|
2019-07-14 09:34:12 +00:00
|
|
|
|
{
|
2020-08-31 10:54:22 +00:00
|
|
|
|
public class UserTopScoreContainer<TScoreInfo> : VisibilityContainer
|
2019-07-14 09:34:12 +00:00
|
|
|
|
{
|
2019-09-19 06:23:33 +00:00
|
|
|
|
private const int duration = 500;
|
2019-07-14 09:34:12 +00:00
|
|
|
|
|
2020-08-31 10:54:22 +00:00
|
|
|
|
public Bindable<TScoreInfo> Score = new Bindable<TScoreInfo>();
|
2019-07-14 09:34:12 +00:00
|
|
|
|
|
2020-08-31 10:54:22 +00:00
|
|
|
|
private readonly Container scoreContainer;
|
|
|
|
|
private readonly Func<TScoreInfo, LeaderboardScore> createScoreDelegate;
|
2019-07-15 09:30:42 +00:00
|
|
|
|
|
2019-07-14 09:34:12 +00:00
|
|
|
|
protected override bool StartHidden => true;
|
|
|
|
|
|
2019-12-03 06:28:10 +00:00
|
|
|
|
[Resolved]
|
|
|
|
|
private RulesetStore rulesets { get; set; }
|
|
|
|
|
|
2020-08-31 10:54:22 +00:00
|
|
|
|
public UserTopScoreContainer(Func<TScoreInfo, LeaderboardScore> createScoreDelegate)
|
2019-07-14 09:34:12 +00:00
|
|
|
|
{
|
2020-08-31 10:54:22 +00:00
|
|
|
|
this.createScoreDelegate = createScoreDelegate;
|
2020-08-31 11:08:36 +00:00
|
|
|
|
|
2019-07-14 09:34:12 +00:00
|
|
|
|
RelativeSizeAxes = Axes.X;
|
2019-09-19 06:34:46 +00:00
|
|
|
|
AutoSizeAxes = Axes.Y;
|
2019-07-22 14:13:48 +00:00
|
|
|
|
|
2019-09-19 06:34:46 +00:00
|
|
|
|
Margin = new MarginPadding { Vertical = 5 };
|
2019-07-22 14:13:48 +00:00
|
|
|
|
|
2019-07-14 09:34:12 +00:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2019-09-19 06:34:46 +00:00
|
|
|
|
new FillFlowContainer
|
2019-07-14 09:34:12 +00:00
|
|
|
|
{
|
2019-07-22 22:14:45 +00:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2019-09-19 06:34:46 +00:00
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
2019-09-19 06:44:05 +00:00
|
|
|
|
Spacing = new Vector2(5),
|
2019-07-14 09:34:12 +00:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
2019-07-22 14:26:11 +00:00
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
2019-07-14 09:34:12 +00:00
|
|
|
|
Text = @"your personal best".ToUpper(),
|
|
|
|
|
Font = OsuFont.GetFont(size: 15, weight: FontWeight.Bold),
|
|
|
|
|
},
|
|
|
|
|
scoreContainer = new Container
|
|
|
|
|
{
|
2019-09-19 06:34:46 +00:00
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
2019-07-14 09:34:12 +00:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2019-07-14 09:40:54 +00:00
|
|
|
|
|
2019-07-22 14:13:48 +00:00
|
|
|
|
Score.BindValueChanged(onScoreChanged);
|
2019-07-14 09:40:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-22 14:21:07 +00:00
|
|
|
|
private CancellationTokenSource loadScoreCancellation;
|
|
|
|
|
|
2020-08-31 10:54:22 +00:00
|
|
|
|
private void onScoreChanged(ValueChangedEvent<TScoreInfo> score)
|
2019-07-14 09:40:54 +00:00
|
|
|
|
{
|
2019-07-22 14:13:48 +00:00
|
|
|
|
var newScore = score.NewValue;
|
|
|
|
|
|
2019-07-22 14:21:07 +00:00
|
|
|
|
scoreContainer.Clear();
|
|
|
|
|
loadScoreCancellation?.Cancel();
|
|
|
|
|
|
2019-09-19 06:23:33 +00:00
|
|
|
|
if (newScore == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-08-31 10:54:22 +00:00
|
|
|
|
LoadComponentAsync(createScoreDelegate(newScore), drawableScore =>
|
2019-07-22 14:21:07 +00:00
|
|
|
|
{
|
|
|
|
|
scoreContainer.Child = drawableScore;
|
2019-09-19 06:44:00 +00:00
|
|
|
|
drawableScore.FadeInFromZero(duration, Easing.OutQuint);
|
2019-07-22 14:21:07 +00:00
|
|
|
|
}, (loadScoreCancellation = new CancellationTokenSource()).Token);
|
2019-07-14 09:34:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-19 06:34:46 +00:00
|
|
|
|
protected override void PopIn() => this.FadeIn(duration, Easing.OutQuint);
|
2019-07-14 09:34:12 +00:00
|
|
|
|
|
2019-09-19 06:34:46 +00:00
|
|
|
|
protected override void PopOut() => this.FadeOut(duration, Easing.OutQuint);
|
2019-07-14 09:34:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|