1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 03:42:58 +08:00

Minor refactorings

This commit is contained in:
smoogipoo 2019-03-08 17:18:54 +09:00
parent a40ffcc692
commit 9a05643ec9
3 changed files with 97 additions and 90 deletions

View File

@ -31,8 +31,10 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
{ {
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;
CornerRadius = 3; CornerRadius = 3;
Masking = true; Masking = true;
Children = new Drawable[] Children = new Drawable[]
{ {
background = new Box background = new Box

View File

@ -5,47 +5,50 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
namespace osu.Game.Overlays.BeatmapSet.Scores namespace osu.Game.Overlays.BeatmapSet.Scores
{ {
public class ScoreTable : FillFlowContainer public class ScoreTable : CompositeDrawable
{ {
private IEnumerable<APIScoreInfo> scores; private readonly FillFlowContainer scoresFlow;
public ScoreTable()
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
InternalChild = scoresFlow = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical
};
}
public IEnumerable<APIScoreInfo> Scores public IEnumerable<APIScoreInfo> Scores
{ {
set set
{ {
scores = value; scoresFlow.Clear();
if (value == null || !value.Any())
return;
int maxModsAmount = 0; int maxModsAmount = 0;
foreach (var s in scores) foreach (var s in value)
{ {
var scoreModsAmount = s.Mods.Length; var scoreModsAmount = s.Mods.Length;
if (scoreModsAmount > maxModsAmount) if (scoreModsAmount > maxModsAmount)
maxModsAmount = scoreModsAmount; maxModsAmount = scoreModsAmount;
} }
Add(new ScoreTextLine(maxModsAmount)); scoresFlow.Add(new ScoreTextLine(maxModsAmount));
int index = 0; int index = 0;
foreach (var s in scores) foreach (var s in value)
Add(new DrawableScore(index++, s, maxModsAmount)); scoresFlow.Add(new DrawableScore(index++, s, maxModsAmount));
} }
get => scores;
}
public ScoreTable()
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Direction = FillDirection.Vertical;
}
public void ClearScores()
{
scores = null;
Clear();
} }
} }
} }

View File

@ -17,7 +17,7 @@ using System.Linq;
namespace osu.Game.Overlays.BeatmapSet.Scores namespace osu.Game.Overlays.BeatmapSet.Scores
{ {
public class ScoresContainer : Container public class ScoresContainer : CompositeDrawable
{ {
private const int spacing = 15; private const int spacing = 15;
private const int fade_duration = 200; private const int fade_duration = 200;
@ -28,77 +28,15 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
private readonly DrawableTopScore topScore; private readonly DrawableTopScore topScore;
private readonly LoadingAnimation loadingAnimation; private readonly LoadingAnimation loadingAnimation;
private bool loading [Resolved]
{ private APIAccess api { get; set; }
set => loadingAnimation.FadeTo(value ? 1 : 0, fade_duration);
}
private IEnumerable<APIScoreInfo> scores;
private BeatmapInfo beatmap;
public IEnumerable<APIScoreInfo> Scores
{
get => scores;
set
{
getScoresRequest?.Cancel();
scores = value;
updateDisplay();
}
}
private GetScoresRequest getScoresRequest;
private APIAccess api;
public BeatmapInfo Beatmap
{
get => beatmap;
set
{
beatmap = value;
Scores = null;
if (beatmap?.OnlineBeatmapID.HasValue != true)
return;
loading = true;
getScoresRequest = new GetScoresRequest(beatmap, beatmap.Ruleset);
getScoresRequest.Success += r => Schedule(() => Scores = r.Scores);
api.Queue(getScoresRequest);
}
}
private void updateDisplay()
{
scoreTable.ClearScores();
loading = false;
var scoreCount = scores?.Count() ?? 0;
if (scoreCount == 0)
{
topScore.Hide();
return;
}
topScore.Score = scores.FirstOrDefault();
topScore.Show();
if (scoreCount < 2)
return;
scoreTable.Scores = scores;
}
public ScoresContainer() public ScoresContainer()
{ {
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;
Children = new Drawable[]
InternalChildren = new Drawable[]
{ {
background = new Box background = new Box
{ {
@ -135,12 +73,76 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(APIAccess api, OsuColour colours) private void load(APIAccess api, OsuColour colours)
{ {
this.api = api;
background.Colour = colours.Gray2; background.Colour = colours.Gray2;
updateDisplay(); updateDisplay();
} }
private bool loading
{
set => loadingAnimation.FadeTo(value ? 1 : 0, fade_duration);
}
private GetScoresRequest getScoresRequest;
private IEnumerable<APIScoreInfo> scores;
public IEnumerable<APIScoreInfo> Scores
{
get => scores;
set
{
getScoresRequest?.Cancel();
scores = value;
updateDisplay();
}
}
private BeatmapInfo beatmap;
public BeatmapInfo Beatmap
{
get => beatmap;
set
{
beatmap = value;
Scores = null;
if (beatmap?.OnlineBeatmapID.HasValue != true)
return;
loading = true;
getScoresRequest = new GetScoresRequest(beatmap, beatmap.Ruleset);
getScoresRequest.Success += r => Schedule(() => Scores = r.Scores);
api.Queue(getScoresRequest);
}
}
private void updateDisplay()
{
scoreTable.Scores = Enumerable.Empty<APIScoreInfo>();
loading = false;
var scoreCount = scores?.Count() ?? 0;
if (scoreCount == 0)
{
topScore.Hide();
return;
}
topScore.Score = scores.FirstOrDefault();
topScore.Show();
if (scoreCount < 2)
return;
scoreTable.Scores = scores;
}
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)
{ {
getScoresRequest?.Cancel(); getScoresRequest?.Cancel();