2019-06-29 14:56:37 +08:00
|
|
|
|
// 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;
|
2019-11-01 14:06:36 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2019-06-12 04:01:57 +08:00
|
|
|
|
using osu.Game.Online;
|
2019-11-01 14:06:36 +08:00
|
|
|
|
using osu.Game.Scoring;
|
2019-11-01 14:32:06 +08:00
|
|
|
|
using osuTK;
|
2019-06-12 04:01:57 +08:00
|
|
|
|
|
2019-11-01 14:06:36 +08:00
|
|
|
|
namespace osu.Game.Screens.Ranking.Pages
|
2019-06-12 04:01:57 +08:00
|
|
|
|
{
|
2019-07-02 18:25:30 +08:00
|
|
|
|
public class ReplayDownloadButton : DownloadTrackingComposite<ScoreInfo, ScoreManager>
|
2019-06-12 04:01:57 +08:00
|
|
|
|
{
|
2019-07-03 11:02:35 +08:00
|
|
|
|
private DownloadButton button;
|
2019-06-29 13:25:30 +08:00
|
|
|
|
private ShakeContainer shakeContainer;
|
2019-06-12 04:01:57 +08:00
|
|
|
|
|
2019-06-30 13:26:20 +08:00
|
|
|
|
private ReplayAvailability replayAvailability
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2019-07-02 18:25:30 +08:00
|
|
|
|
if (State.Value == DownloadState.LocallyAvailable)
|
2019-06-30 13:26:20 +08:00
|
|
|
|
return ReplayAvailability.Local;
|
|
|
|
|
|
2019-12-03 14:28:10 +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-06-12 04:01:57 +08:00
|
|
|
|
{
|
2019-11-01 14:32:06 +08:00
|
|
|
|
Size = new Vector2(50, 30);
|
2019-06-12 04:01:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
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-12 04:01:57 +08:00
|
|
|
|
{
|
2019-06-29 13:25:30 +08:00
|
|
|
|
InternalChild = shakeContainer = new ShakeContainer
|
|
|
|
|
{
|
2019-07-02 18:25:30 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2019-07-03 11:02:35 +08:00
|
|
|
|
Child = button = new DownloadButton
|
2019-06-29 13:25:30 +08:00
|
|
|
|
{
|
2019-07-02 18:25:30 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
}
|
2019-06-29 13:25:30 +08:00
|
|
|
|
};
|
2019-06-12 04:01:57 +08:00
|
|
|
|
|
2019-06-29 13:25:30 +08:00
|
|
|
|
button.Action = () =>
|
2019-06-12 04:01:57 +08:00
|
|
|
|
{
|
2019-06-29 13:25:30 +08:00
|
|
|
|
switch (State.Value)
|
|
|
|
|
{
|
|
|
|
|
case DownloadState.LocallyAvailable:
|
2019-06-29 14:56:37 +08:00
|
|
|
|
game?.PresentScore(Model.Value);
|
2019-06-29 13:25:30 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DownloadState.NotDownloaded:
|
|
|
|
|
scores.Download(Model.Value);
|
|
|
|
|
break;
|
|
|
|
|
|
2019-07-02 18:25:30 +08:00
|
|
|
|
case DownloadState.Downloaded:
|
2019-06-29 13:25:30 +08:00
|
|
|
|
case DownloadState.Downloading:
|
|
|
|
|
shakeContainer.Shake();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-06-12 04:01:57 +08:00
|
|
|
|
};
|
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
|
|
|
|
{
|
2019-07-02 18:25:30 +08:00
|
|
|
|
button.State.Value = state.NewValue;
|
|
|
|
|
|
|
|
|
|
switch (replayAvailability)
|
2019-06-29 13:25:30 +08:00
|
|
|
|
{
|
2019-07-02 18:25:30 +08:00
|
|
|
|
case ReplayAvailability.Local:
|
2020-01-15 03:26:54 +08:00
|
|
|
|
button.TooltipText = @"watch replay";
|
2019-06-29 13:25:30 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2019-07-02 18:25:30 +08:00
|
|
|
|
case ReplayAvailability.Online:
|
2020-01-15 03:26:54 +08:00
|
|
|
|
button.TooltipText = @"download replay";
|
2019-06-29 13:25:30 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2019-07-02 18:25:30 +08:00
|
|
|
|
default:
|
2020-01-15 03:26:54 +08:00
|
|
|
|
button.TooltipText = @"replay unavailable";
|
2019-06-29 13:25:30 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}, true);
|
2019-06-29 15:19:03 +08:00
|
|
|
|
|
2019-07-05 10:17:36 +08:00
|
|
|
|
button.Enabled.Value = replayAvailability != ReplayAvailability.NotAvailable;
|
2019-06-29 15:19:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private enum ReplayAvailability
|
|
|
|
|
{
|
|
|
|
|
Local,
|
|
|
|
|
Online,
|
|
|
|
|
NotAvailable,
|
2019-06-12 04:01:57 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|