1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 12:53:11 +08:00

Add user top score on selected beatmap

This commit is contained in:
Andrei Zavatski 2019-07-08 11:49:33 +03:00
parent a0efd50f62
commit 67a6abb96c
3 changed files with 41 additions and 26 deletions

View File

@ -23,10 +23,8 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
private Color4 backgroundHoveredColour;
private readonly Box background;
private readonly TopScoreUserSection userSection;
private readonly TopScoreStatisticsSection statisticsSection;
public DrawableTopScore()
public DrawableTopScore(ScoreInfo score, int position = 1)
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
@ -61,16 +59,18 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
{
new Drawable[]
{
userSection = new TopScoreUserSection
new TopScoreUserSection(position)
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Score = score,
},
null,
statisticsSection = new TopScoreStatisticsSection
new TopScoreStatisticsSection
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Score = score,
}
},
},
@ -91,18 +91,6 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
background.Colour = backgroundIdleColour;
}
/// <summary>
/// Sets the score to be displayed.
/// </summary>
public ScoreInfo Score
{
set
{
userSection.Score = value;
statisticsSection.Score = value;
}
}
protected override bool OnHover(HoverEvent e)
{
background.FadeColour(backgroundHoveredColour, fade_duration, Easing.OutQuint);

View File

@ -14,6 +14,7 @@ using osuTK;
using System.Collections.Generic;
using System.Linq;
using osu.Game.Scoring;
using osu.Game.Online.API.Requests.Responses;
namespace osu.Game.Overlays.BeatmapSet.Scores
{
@ -25,7 +26,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
private readonly Box background;
private readonly ScoreTable scoreTable;
private readonly DrawableTopScore topScore;
private readonly FillFlowContainer topScoresContainer;
private readonly LoadingAnimation loadingAnimation;
[Resolved]
@ -54,7 +55,13 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
Margin = new MarginPadding { Vertical = spacing },
Children = new Drawable[]
{
topScore = new DrawableTopScore(),
topScoresContainer = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 5),
},
scoreTable = new ScoreTable
{
Anchor = Anchor.TopCentre,
@ -97,6 +104,20 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
}
}
private APILegacyUserTopScoreInfo userScore;
public APILegacyUserTopScoreInfo UserScore
{
get => userScore;
set
{
getScoresRequest?.Cancel();
userScore = value;
updateDisplay();
}
}
private BeatmapInfo beatmap;
public BeatmapInfo Beatmap
@ -114,7 +135,12 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
loading = true;
getScoresRequest = new GetScoresRequest(beatmap, beatmap.Ruleset);
getScoresRequest.Success += r => Schedule(() => Scores = r.Scores);
getScoresRequest.Success += r => Schedule(() =>
{
scores = r.Scores;
userScore = r.UserScore;
updateDisplay();
});
api.Queue(getScoresRequest);
}
}
@ -122,17 +148,18 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
private void updateDisplay()
{
loading = false;
topScoresContainer.Clear();
scoreTable.Scores = scores?.Count > 1 ? scores : new List<ScoreInfo>();
scoreTable.FadeTo(scores?.Count > 1 ? 1 : 0);
if (scores?.Any() == true)
{
topScore.Score = scores.FirstOrDefault();
topScore.Show();
topScoresContainer.Add(new DrawableTopScore(scores.FirstOrDefault()));
if (userScore != null && userScore.Position != 1)
topScoresContainer.Add(new DrawableTopScore(userScore.Score, userScore.Position));
}
else
topScore.Hide();
}
protected override void Dispose(bool isDisposing)

View File

@ -28,7 +28,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
private readonly SpriteText date;
private readonly UpdateableFlag flag;
public TopScoreUserSection()
public TopScoreUserSection(int position)
{
AutoSizeAxes = Axes.Both;
@ -43,7 +43,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = "#1",
Text = position.ToString(),
Font = OsuFont.GetFont(size: 30, weight: FontWeight.Bold, italics: true)
},
rank = new UpdateableRank(ScoreRank.D)