1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 17:17:24 +08:00
osu-lazer/osu.Game/Screens/Ranking/ReplayDownloadButton.cs

114 lines
3.2 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;
using osu.Framework.Bindables;
2019-06-29 13:25:30 +08:00
using osu.Framework.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online;
using osu.Game.Scoring;
2019-11-01 14:32:06 +08:00
using osuTK;
2020-03-17 16:43:16 +08:00
namespace osu.Game.Screens.Ranking
{
public class ReplayDownloadButton : DownloadTrackingComposite<ScoreInfo, ScoreManager>
{
public Bindable<ScoreInfo> Score => Model;
private DownloadButton 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;
2020-05-28 20:46:02 +08:00
if (!string.IsNullOrEmpty(Model.Value?.Hash))
2019-06-30 13:26:20 +08:00
return ReplayAvailability.Online;
return ReplayAvailability.NotAvailable;
}
}
2019-06-29 13:25:30 +08:00
public ReplayDownloadButton(ScoreInfo score)
: base(score)
{
2019-11-01 14:32:06 +08:00
Size = new Vector2(50, 30);
}
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 DownloadButton
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, ScorePresentType.Gameplay);
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;
updateTooltip();
}, true);
2019-06-29 13:25:30 +08:00
Model.BindValueChanged(_ =>
{
button.Enabled.Value = replayAvailability != ReplayAvailability.NotAvailable;
2019-06-29 13:25:30 +08:00
updateTooltip();
2019-06-29 13:25:30 +08:00
}, true);
}
private void updateTooltip()
{
switch (replayAvailability)
{
case ReplayAvailability.Local:
button.TooltipText = @"watch replay";
break;
case ReplayAvailability.Online:
button.TooltipText = @"download replay";
break;
default:
button.TooltipText = @"replay unavailable";
break;
}
}
private enum ReplayAvailability
{
Local,
Online,
NotAvailable,
}
}
}