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

101 lines
2.9 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;
2019-06-29 10:55:30 +05:30
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 15:32:06 +09:00
using osuTK;
2020-03-17 17:43:16 +09:00
namespace osu.Game.Screens.Ranking
{
public class ReplayDownloadButton : DownloadTrackingComposite<ScoreInfo, ScoreManager>
{
private DownloadButton button;
2019-06-29 10:55:30 +05:30
private ShakeContainer shakeContainer;
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 (!string.IsNullOrEmpty(Model.Value.Hash))
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)
: base(score)
{
2019-11-01 15:32:06 +09:00
Size = new Vector2(50, 30);
}
2019-06-29 10:55:30 +05:30
[BackgroundDependencyLoader(true)]
2019-07-02 16:13:47 +05:30
private void load(OsuGame game, ScoreManager 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(Model.Value);
2019-06-29 10:55:30 +05:30
break;
case DownloadState.NotDownloaded:
scores.Download(Model.Value);
break;
case DownloadState.Downloaded:
2019-06-29 10:55:30 +05:30
case DownloadState.Downloading:
shakeContainer.Shake();
break;
}
};
2019-06-29 10:55:30 +05:30
2019-07-02 16:13:47 +05:30
State.BindValueChanged(state =>
2019-06-29 10:55:30 +05:30
{
button.State.Value = state.NewValue;
switch (replayAvailability)
2019-06-29 10:55:30 +05:30
{
case ReplayAvailability.Local:
2020-01-14 14:26:54 -05:00
button.TooltipText = @"watch replay";
2019-06-29 10:55:30 +05:30
break;
case ReplayAvailability.Online:
2020-01-14 14:26:54 -05:00
button.TooltipText = @"download replay";
2019-06-29 10:55:30 +05:30
break;
default:
2020-01-14 14:26:54 -05:00
button.TooltipText = @"replay unavailable";
2019-06-29 10:55:30 +05:30
break;
}
}, true);
2019-07-05 05:17:36 +03:00
button.Enabled.Value = replayAvailability != ReplayAvailability.NotAvailable;
}
private enum ReplayAvailability
{
Local,
Online,
NotAvailable,
}
}
}