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;
|
2020-05-28 20:40:01 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2019-06-29 13:25:30 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2021-10-27 19:49:15 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2023-06-20 15:29:15 +08:00
|
|
|
|
using osu.Framework.Input.Bindings;
|
|
|
|
|
using osu.Framework.Input.Events;
|
2019-06-29 13:25:30 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2019-11-01 14:06:36 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2023-06-20 15:29:15 +08:00
|
|
|
|
using osu.Game.Input.Bindings;
|
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
|
|
|
|
|
2020-03-17 16:43:16 +08:00
|
|
|
|
namespace osu.Game.Screens.Ranking
|
2019-06-12 04:01:57 +08:00
|
|
|
|
{
|
2023-06-20 15:29:15 +08:00
|
|
|
|
public partial class ReplayDownloadButton : CompositeDrawable, IKeyBindingHandler<GlobalAction>
|
2019-06-12 04:01:57 +08:00
|
|
|
|
{
|
2021-10-27 19:49:15 +08:00
|
|
|
|
public readonly Bindable<ScoreInfo> Score = new Bindable<ScoreInfo>();
|
|
|
|
|
|
|
|
|
|
protected readonly Bindable<DownloadState> State = new Bindable<DownloadState>();
|
2020-05-28 20:40:01 +08:00
|
|
|
|
|
2023-06-20 15:29:15 +08:00
|
|
|
|
private DownloadButton button = null!;
|
|
|
|
|
private ShakeContainer shakeContainer = null!;
|
2019-06-12 04:01:57 +08:00
|
|
|
|
|
2023-06-20 15:29:15 +08:00
|
|
|
|
private ScoreDownloadTracker? downloadTracker;
|
2021-10-27 19:49:15 +08:00
|
|
|
|
|
2023-06-20 15:38:30 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private ScoreManager scoreManager { get; set; } = null!;
|
|
|
|
|
|
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;
|
|
|
|
|
|
2023-10-27 18:39:54 +08:00
|
|
|
|
if (Score.Value?.HasOnlineReplay == true)
|
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)
|
2019-06-12 04:01:57 +08:00
|
|
|
|
{
|
2021-10-27 19:49:15 +08:00
|
|
|
|
Score.Value = score;
|
2019-11-01 14:32:06 +08:00
|
|
|
|
Size = new Vector2(50, 30);
|
2019-06-12 04:01:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-20 15:29:15 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2023-06-20 15:38:30 +08:00
|
|
|
|
private void load(OsuGame? game, ScoreModelDownloader scoreDownloader)
|
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:
|
2021-10-27 19:49:15 +08:00
|
|
|
|
game?.PresentScore(Score.Value, ScorePresentType.Gameplay);
|
2019-06-29 13:25:30 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DownloadState.NotDownloaded:
|
2023-06-20 15:38:30 +08:00
|
|
|
|
scoreDownloader.Download(Score.Value);
|
2019-06-29 13:25:30 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2021-01-13 23:04:29 +08:00
|
|
|
|
case DownloadState.Importing:
|
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
|
|
|
|
|
2021-10-27 19:49:15 +08:00
|
|
|
|
Score.BindValueChanged(score =>
|
2019-06-29 13:25:30 +08:00
|
|
|
|
{
|
2023-07-30 15:41:45 +08:00
|
|
|
|
// An export may be pending from the last score.
|
|
|
|
|
// Reset this to meet user expectations (a new score which has just been switched to shouldn't export)
|
|
|
|
|
State.ValueChanged -= exportWhenReady;
|
|
|
|
|
|
2021-10-27 20:26:26 +08:00
|
|
|
|
downloadTracker?.RemoveAndDisposeImmediately();
|
2021-10-27 19:49:15 +08:00
|
|
|
|
|
|
|
|
|
if (score.NewValue != null)
|
|
|
|
|
{
|
|
|
|
|
AddInternal(downloadTracker = new ScoreDownloadTracker(score.NewValue)
|
|
|
|
|
{
|
|
|
|
|
State = { BindTarget = State }
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-07-02 18:25:30 +08:00
|
|
|
|
|
2022-04-05 16:04:19 +08:00
|
|
|
|
updateState();
|
2020-08-30 00:33:01 +08:00
|
|
|
|
}, true);
|
2019-06-29 13:25:30 +08:00
|
|
|
|
|
2021-10-27 19:49:15 +08:00
|
|
|
|
State.BindValueChanged(state =>
|
2020-08-30 00:33:01 +08:00
|
|
|
|
{
|
2021-10-27 19:49:15 +08:00
|
|
|
|
button.State.Value = state.NewValue;
|
2022-04-05 16:04:19 +08:00
|
|
|
|
updateState();
|
2019-06-29 13:25:30 +08:00
|
|
|
|
}, true);
|
2020-08-30 00:33:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-21 16:48:12 +08:00
|
|
|
|
#region Export via hotkey logic (also in SaveFailedScoreButton)
|
|
|
|
|
|
2023-06-20 15:29:15 +08:00
|
|
|
|
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
|
|
|
|
{
|
2023-07-26 14:12:02 +08:00
|
|
|
|
if (e.Repeat)
|
|
|
|
|
return false;
|
|
|
|
|
|
2023-06-20 15:29:15 +08:00
|
|
|
|
switch (e.Action)
|
|
|
|
|
{
|
|
|
|
|
case GlobalAction.SaveReplay:
|
|
|
|
|
button.TriggerClick();
|
|
|
|
|
return true;
|
2023-06-20 15:38:30 +08:00
|
|
|
|
|
|
|
|
|
case GlobalAction.ExportReplay:
|
2023-07-30 15:41:33 +08:00
|
|
|
|
if (State.Value == DownloadState.LocallyAvailable)
|
|
|
|
|
{
|
|
|
|
|
State.BindValueChanged(exportWhenReady, true);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// A download needs to be performed before we can export this replay.
|
2023-06-21 16:48:12 +08:00
|
|
|
|
button.TriggerClick();
|
2023-07-30 15:41:33 +08:00
|
|
|
|
if (button.Enabled.Value)
|
|
|
|
|
State.BindValueChanged(exportWhenReady, true);
|
|
|
|
|
}
|
2023-06-20 15:38:30 +08:00
|
|
|
|
|
|
|
|
|
return true;
|
2023-06-20 15:29:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-21 16:48:12 +08:00
|
|
|
|
private void exportWhenReady(ValueChangedEvent<DownloadState> state)
|
|
|
|
|
{
|
|
|
|
|
if (state.NewValue != DownloadState.LocallyAvailable) return;
|
|
|
|
|
|
|
|
|
|
scoreManager.Export(Score.Value);
|
|
|
|
|
|
|
|
|
|
State.ValueChanged -= exportWhenReady;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2022-04-05 16:04:19 +08:00
|
|
|
|
private void updateState()
|
2020-08-30 00:33:01 +08:00
|
|
|
|
{
|
|
|
|
|
switch (replayAvailability)
|
|
|
|
|
{
|
|
|
|
|
case ReplayAvailability.Local:
|
|
|
|
|
button.TooltipText = @"watch replay";
|
2022-04-07 12:22:56 +08:00
|
|
|
|
button.Enabled.Value = true;
|
2020-08-30 00:33:01 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ReplayAvailability.Online:
|
|
|
|
|
button.TooltipText = @"download replay";
|
2022-04-07 12:22:56 +08:00
|
|
|
|
button.Enabled.Value = true;
|
2020-08-30 00:33:01 +08:00
|
|
|
|
break;
|
2019-06-29 15:19:03 +08:00
|
|
|
|
|
2020-08-30 00:33:01 +08:00
|
|
|
|
default:
|
|
|
|
|
button.TooltipText = @"replay unavailable";
|
2022-04-07 12:22:56 +08:00
|
|
|
|
button.Enabled.Value = false;
|
2020-08-30 00:33:01 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2019-06-29 15:19:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private enum ReplayAvailability
|
|
|
|
|
{
|
|
|
|
|
Local,
|
|
|
|
|
Online,
|
|
|
|
|
NotAvailable,
|
2019-06-12 04:01:57 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|