2019-06-29 06:56:37 +00: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;
|
2020-05-28 12:40:01 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2019-06-29 05:25:30 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Containers;
|
2019-11-01 06:06:36 +00:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2019-06-11 20:01:57 +00:00
|
|
|
|
using osu.Game.Online;
|
2019-11-01 06:06:36 +00:00
|
|
|
|
using osu.Game.Scoring;
|
2019-11-01 06:32:06 +00:00
|
|
|
|
using osuTK;
|
2019-06-11 20:01:57 +00:00
|
|
|
|
|
2020-03-17 08:43:16 +00:00
|
|
|
|
namespace osu.Game.Screens.Ranking
|
2019-06-11 20:01:57 +00:00
|
|
|
|
{
|
2019-07-02 10:25:30 +00:00
|
|
|
|
public class ReplayDownloadButton : DownloadTrackingComposite<ScoreInfo, ScoreManager>
|
2019-06-11 20:01:57 +00:00
|
|
|
|
{
|
2020-05-28 12:40:01 +00:00
|
|
|
|
public Bindable<ScoreInfo> Score => Model;
|
|
|
|
|
|
2019-07-03 03:02:35 +00:00
|
|
|
|
private DownloadButton button;
|
2019-06-29 05:25:30 +00:00
|
|
|
|
private ShakeContainer shakeContainer;
|
2019-06-11 20:01:57 +00:00
|
|
|
|
|
2019-06-30 05:26:20 +00:00
|
|
|
|
private ReplayAvailability replayAvailability
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2019-07-02 10:25:30 +00:00
|
|
|
|
if (State.Value == DownloadState.LocallyAvailable)
|
2019-06-30 05:26:20 +00:00
|
|
|
|
return ReplayAvailability.Local;
|
|
|
|
|
|
2020-05-28 12:46:02 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(Model.Value?.Hash))
|
2019-06-30 05:26:20 +00:00
|
|
|
|
return ReplayAvailability.Online;
|
|
|
|
|
|
|
|
|
|
return ReplayAvailability.NotAvailable;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-29 05:25:30 +00:00
|
|
|
|
public ReplayDownloadButton(ScoreInfo score)
|
|
|
|
|
: base(score)
|
2019-06-11 20:01:57 +00:00
|
|
|
|
{
|
2019-11-01 06:32:06 +00:00
|
|
|
|
Size = new Vector2(50, 30);
|
2019-06-11 20:01:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-29 05:25:30 +00:00
|
|
|
|
[BackgroundDependencyLoader(true)]
|
2019-07-02 10:43:47 +00:00
|
|
|
|
private void load(OsuGame game, ScoreManager scores)
|
2019-06-11 20:01:57 +00:00
|
|
|
|
{
|
2019-06-29 05:25:30 +00:00
|
|
|
|
InternalChild = shakeContainer = new ShakeContainer
|
|
|
|
|
{
|
2019-07-02 10:25:30 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2019-07-03 03:02:35 +00:00
|
|
|
|
Child = button = new DownloadButton
|
2019-06-29 05:25:30 +00:00
|
|
|
|
{
|
2019-07-02 10:25:30 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
}
|
2019-06-29 05:25:30 +00:00
|
|
|
|
};
|
2019-06-11 20:01:57 +00:00
|
|
|
|
|
2019-06-29 05:25:30 +00:00
|
|
|
|
button.Action = () =>
|
2019-06-11 20:01:57 +00:00
|
|
|
|
{
|
2019-06-29 05:25:30 +00:00
|
|
|
|
switch (State.Value)
|
|
|
|
|
{
|
|
|
|
|
case DownloadState.LocallyAvailable:
|
2020-06-15 11:23:35 +00:00
|
|
|
|
game?.PresentScore(Model.Value, ScorePresentType.Gameplay);
|
2019-06-29 05:25:30 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DownloadState.NotDownloaded:
|
|
|
|
|
scores.Download(Model.Value);
|
|
|
|
|
break;
|
|
|
|
|
|
2021-01-13 15:04:29 +00:00
|
|
|
|
case DownloadState.Importing:
|
2019-06-29 05:25:30 +00:00
|
|
|
|
case DownloadState.Downloading:
|
|
|
|
|
shakeContainer.Shake();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-06-11 20:01:57 +00:00
|
|
|
|
};
|
2019-06-29 05:25:30 +00:00
|
|
|
|
|
2019-07-02 10:43:47 +00:00
|
|
|
|
State.BindValueChanged(state =>
|
2019-06-29 05:25:30 +00:00
|
|
|
|
{
|
2019-07-02 10:25:30 +00:00
|
|
|
|
button.State.Value = state.NewValue;
|
|
|
|
|
|
2020-08-29 16:33:01 +00:00
|
|
|
|
updateTooltip();
|
|
|
|
|
}, true);
|
2019-06-29 05:25:30 +00:00
|
|
|
|
|
2020-08-29 16:33:01 +00:00
|
|
|
|
Model.BindValueChanged(_ =>
|
|
|
|
|
{
|
|
|
|
|
button.Enabled.Value = replayAvailability != ReplayAvailability.NotAvailable;
|
2019-06-29 05:25:30 +00:00
|
|
|
|
|
2020-08-29 16:33:01 +00:00
|
|
|
|
updateTooltip();
|
2019-06-29 05:25:30 +00:00
|
|
|
|
}, true);
|
2020-08-29 16:33:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateTooltip()
|
|
|
|
|
{
|
|
|
|
|
switch (replayAvailability)
|
|
|
|
|
{
|
|
|
|
|
case ReplayAvailability.Local:
|
|
|
|
|
button.TooltipText = @"watch replay";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ReplayAvailability.Online:
|
|
|
|
|
button.TooltipText = @"download replay";
|
|
|
|
|
break;
|
2019-06-29 07:19:03 +00:00
|
|
|
|
|
2020-08-29 16:33:01 +00:00
|
|
|
|
default:
|
|
|
|
|
button.TooltipText = @"replay unavailable";
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-06-29 07:19:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private enum ReplayAvailability
|
|
|
|
|
{
|
|
|
|
|
Local,
|
|
|
|
|
Online,
|
|
|
|
|
NotAvailable,
|
2019-06-11 20:01:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|