mirror of
https://github.com/osukey/osukey.git
synced 2025-08-03 22:56:36 +09:00
Make BeatmapSetOverlay accept nulls everywhere
This commit is contained in:
@ -2,15 +2,15 @@
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Online.API;
|
||||
|
||||
namespace osu.Game.Overlays.BeatmapSet.Scores
|
||||
{
|
||||
@ -22,49 +22,75 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
|
||||
private readonly FillFlowContainer flow;
|
||||
private readonly DrawableTopScore topScore;
|
||||
private readonly LoadingAnimation loadingAnimation;
|
||||
private readonly Box foreground;
|
||||
|
||||
private bool isLoading;
|
||||
public bool IsLoading
|
||||
private bool loading
|
||||
{
|
||||
get { return isLoading; }
|
||||
set
|
||||
{
|
||||
if (isLoading == value) return;
|
||||
isLoading = value;
|
||||
|
||||
foreground.FadeTo(isLoading ? 1 : 0, fade_duration);
|
||||
loadingAnimation.FadeTo(isLoading ? 1 : 0, fade_duration);
|
||||
}
|
||||
set => loadingAnimation.FadeTo(value ? 1 : 0, fade_duration);
|
||||
}
|
||||
|
||||
private IEnumerable<OnlineScore> scores;
|
||||
private BeatmapInfo beatmap;
|
||||
|
||||
public IEnumerable<OnlineScore> Scores
|
||||
{
|
||||
get { return scores; }
|
||||
set
|
||||
{
|
||||
getScoresRequest?.Cancel();
|
||||
scores = value;
|
||||
var scoresAmount = scores.Count();
|
||||
if (scoresAmount == 0)
|
||||
{
|
||||
CleanAllScores();
|
||||
return;
|
||||
}
|
||||
|
||||
topScore.Score = scores.FirstOrDefault();
|
||||
topScore.Show();
|
||||
|
||||
flow.Clear();
|
||||
|
||||
if (scoresAmount < 2)
|
||||
return;
|
||||
|
||||
for (int i = 1; i < scoresAmount; i++)
|
||||
flow.Add(new DrawableScore(i, scores.ElementAt(i)));
|
||||
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 => Scores = r.Scores;
|
||||
api.Queue(getScoresRequest);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateDisplay()
|
||||
{
|
||||
loading = false;
|
||||
|
||||
var scoreCount = scores?.Count() ?? 0;
|
||||
|
||||
if (scoreCount == 0)
|
||||
{
|
||||
topScore.Hide();
|
||||
flow.Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
topScore.Score = scores.FirstOrDefault();
|
||||
topScore.Show();
|
||||
|
||||
flow.Clear();
|
||||
|
||||
if (scoreCount < 2)
|
||||
return;
|
||||
|
||||
for (int i = 1; i < scoreCount; i++)
|
||||
flow.Add(new DrawableScore(i, scores.ElementAt(i)));
|
||||
}
|
||||
|
||||
public ScoresContainer()
|
||||
{
|
||||
RelativeSizeAxes = Axes.X;
|
||||
@ -93,23 +119,19 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
|
||||
},
|
||||
}
|
||||
},
|
||||
foreground = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Color4.Black.Opacity(0.7f),
|
||||
Alpha = 0,
|
||||
},
|
||||
loadingAnimation = new LoadingAnimation
|
||||
{
|
||||
Alpha = 0,
|
||||
Margin = new MarginPadding(20)
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
public void CleanAllScores()
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(APIAccess api)
|
||||
{
|
||||
topScore.Hide();
|
||||
flow.Clear();
|
||||
this.api = api;
|
||||
updateDisplay();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user