1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-07 03:57:46 +08:00
osu-lazer/osu.Game/Screens/Ranking/ReplayDownloadButton.cs

131 lines
3.8 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.
2022-06-17 16:37:17 +09:00
#nullable disable
using osu.Framework.Allocation;
using osu.Framework.Bindables;
2019-06-29 10:55:30 +05:30
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2019-06-29 10:55:30 +05:30
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online;
using osu.Game.Scoring;
2019-11-01 15:32:06 +09:00
using osuTK;
2020-03-17 17:43:16 +09:00
namespace osu.Game.Screens.Ranking
{
2022-11-24 14:32:20 +09:00
public partial class ReplayDownloadButton : CompositeDrawable
{
public readonly Bindable<ScoreInfo> Score = new Bindable<ScoreInfo>();
protected readonly Bindable<DownloadState> State = new Bindable<DownloadState>();
private DownloadButton button;
2019-06-29 10:55:30 +05:30
private ShakeContainer shakeContainer;
private ScoreDownloadTracker downloadTracker;
2019-06-30 10:56:20 +05:30
private ReplayAvailability replayAvailability
{
get
{
if (State.Value == DownloadState.LocallyAvailable)
2019-06-30 10:56:20 +05:30
return ReplayAvailability.Local;
if (Score.Value?.HasReplay == true)
2019-06-30 10:56:20 +05:30
return ReplayAvailability.Online;
return ReplayAvailability.NotAvailable;
}
}
2019-06-29 10:55:30 +05:30
public ReplayDownloadButton(ScoreInfo score)
{
Score.Value = score;
2019-11-01 15:32:06 +09:00
Size = new Vector2(50, 30);
}
2019-06-29 10:55:30 +05:30
[BackgroundDependencyLoader(true)]
private void load(OsuGame game, ScoreModelDownloader scores)
{
2019-06-29 10:55:30 +05:30
InternalChild = shakeContainer = new ShakeContainer
{
RelativeSizeAxes = Axes.Both,
Child = button = new DownloadButton
2019-06-29 10:55:30 +05:30
{
RelativeSizeAxes = Axes.Both,
}
2019-06-29 10:55:30 +05:30
};
2019-06-29 10:55:30 +05:30
button.Action = () =>
{
2019-06-29 10:55:30 +05:30
switch (State.Value)
{
case DownloadState.LocallyAvailable:
game?.PresentScore(Score.Value, ScorePresentType.Gameplay);
2019-06-29 10:55:30 +05:30
break;
case DownloadState.NotDownloaded:
scores.Download(Score.Value);
2019-06-29 10:55:30 +05:30
break;
case DownloadState.Importing:
2019-06-29 10:55:30 +05:30
case DownloadState.Downloading:
shakeContainer.Shake();
break;
}
};
2019-06-29 10:55:30 +05:30
Score.BindValueChanged(score =>
2019-06-29 10:55:30 +05:30
{
2021-10-27 21:26:26 +09:00
downloadTracker?.RemoveAndDisposeImmediately();
if (score.NewValue != null)
{
AddInternal(downloadTracker = new ScoreDownloadTracker(score.NewValue)
{
State = { BindTarget = State }
});
}
updateState();
}, true);
2019-06-29 10:55:30 +05:30
State.BindValueChanged(state =>
{
button.State.Value = state.NewValue;
updateState();
2019-06-29 10:55:30 +05:30
}, true);
}
private void updateState()
{
switch (replayAvailability)
{
case ReplayAvailability.Local:
button.TooltipText = @"watch replay";
2022-04-06 21:22:56 -07:00
button.Enabled.Value = true;
break;
case ReplayAvailability.Online:
button.TooltipText = @"download replay";
2022-04-06 21:22:56 -07:00
button.Enabled.Value = true;
break;
default:
button.TooltipText = @"replay unavailable";
2022-04-06 21:22:56 -07:00
button.Enabled.Value = false;
break;
}
}
private enum ReplayAvailability
{
Local,
Online,
NotAvailable,
}
}
}