1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-26 23:32:55 +08:00
osu-lazer/osu.Game/Screens/Select/Leaderboards/UserTopScoreContainer.cs

102 lines
3.3 KiB
C#
Raw Normal View History

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