1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 12:47:25 +08:00
osu-lazer/osu.Game/Screens/Play/ReplayDownloadButton.cs

56 lines
1.5 KiB
C#
Raw Normal View History

using osu.Framework.Allocation;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online;
using osu.Game.Scoring;
namespace osu.Game.Screens.Play
{
public class ReplayDownloadButton : DownloadTrackingComposite<ScoreInfo, ScoreManager>
{
[Resolved]
private OsuGame game { get; set; }
[Resolved]
private ScoreManager scores { get; set; }
public ReplayDownloadButton(ScoreInfo score)
: base(score)
{
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
AddInternal(new TwoLayerButton
{
BackgroundColour = colours.Yellow,
Icon = FontAwesome.Solid.PlayCircle,
Text = @"Replay",
HoverColour = colours.YellowDark,
Action = onReplay,
});
}
private void onReplay()
{
2019-06-26 23:40:21 +08:00
if (scores.IsAvailableLocally(Model.Value))
{
2019-06-26 23:40:21 +08:00
game.PresentScore(Model.Value);
return;
}
2019-06-26 23:40:21 +08:00
scores.Download(Model.Value);
2019-06-26 23:40:21 +08:00
scores.ItemAdded += score =>
{
2019-06-26 23:40:21 +08:00
if (score.Equals(Model.Value))
// use the newly added score instead of ModelInfo.Score because that won't have the Files property populated
game.PresentScore(score);
//ReplayLoaded?.Invoke(scores.GetScore(score));
};
}
}
}