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

104 lines
3.0 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
2019-06-29 13:25:30 +08:00
using osu.Framework.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Online;
using osu.Game.Scoring;
2019-06-29 13:25:30 +08:00
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Graphics.UserInterface;
namespace osu.Game.Screens.Play
{
public class ReplayDownloadButton : DownloadTrackingComposite<ScoreInfo, ScoreManager>
{
private OsuDownloadButton button;
2019-06-29 13:25:30 +08:00
private ShakeContainer shakeContainer;
2019-06-30 13:26:20 +08:00
private ReplayAvailability replayAvailability
{
get
{
if (State.Value == DownloadState.LocallyAvailable)
2019-06-30 13:26:20 +08:00
return ReplayAvailability.Local;
if (Model.Value is APILegacyScoreInfo apiScore && apiScore.Replay)
return ReplayAvailability.Online;
return ReplayAvailability.NotAvailable;
}
}
2019-06-29 13:25:30 +08:00
public ReplayDownloadButton(ScoreInfo score)
: base(score)
{
}
2019-06-29 13:25:30 +08:00
[BackgroundDependencyLoader(true)]
2019-07-02 18:43:47 +08:00
private void load(OsuGame game, ScoreManager scores)
{
2019-06-29 13:25:30 +08:00
InternalChild = shakeContainer = new ShakeContainer
{
RelativeSizeAxes = Axes.Both,
Child = button = new OsuDownloadButton
2019-06-29 13:25:30 +08:00
{
RelativeSizeAxes = Axes.Both,
}
2019-06-29 13:25:30 +08:00
};
2019-06-29 13:25:30 +08:00
button.Action = () =>
{
2019-06-29 13:25:30 +08:00
switch (State.Value)
{
case DownloadState.LocallyAvailable:
game?.PresentScore(Model.Value);
2019-06-29 13:25:30 +08:00
break;
case DownloadState.NotDownloaded:
scores.Download(Model.Value);
break;
case DownloadState.Downloaded:
2019-06-29 13:25:30 +08:00
case DownloadState.Downloading:
shakeContainer.Shake();
break;
}
};
2019-06-29 13:25:30 +08:00
2019-07-02 18:43:47 +08:00
State.BindValueChanged(state =>
2019-06-29 13:25:30 +08:00
{
button.State.Value = state.NewValue;
switch (replayAvailability)
2019-06-29 13:25:30 +08:00
{
case ReplayAvailability.Local:
button.TooltipText = @"Watch replay";
2019-06-29 13:25:30 +08:00
break;
case ReplayAvailability.Online:
button.TooltipText = @"Download replay";
2019-06-29 13:25:30 +08:00
break;
default:
button.TooltipText = @"Replay unavailable";
2019-06-29 13:25:30 +08:00
break;
}
}, true);
2019-06-30 13:26:20 +08:00
if (replayAvailability == ReplayAvailability.NotAvailable)
{
button.Enabled.Value = false;
button.Alpha = 0.6f;
}
}
private enum ReplayAvailability
{
Local,
Online,
NotAvailable,
}
}
}