1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-06 15:57:19 +08:00
osu-lazer/osu.Game/Overlays/Direct/PanelDownloadButton.cs

76 lines
2.3 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.
2018-04-13 18:19:50 +09:00
using osu.Framework.Allocation;
2018-04-13 18:19:50 +09:00
using osu.Framework.Graphics;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Containers;
2018-07-13 16:28:18 +09:00
using osu.Game.Graphics.UserInterface;
using osu.Game.Online;
2018-04-13 18:19:50 +09:00
namespace osu.Game.Overlays.Direct
{
public class PanelDownloadButton : BeatmapDownloadTrackingComposite
2018-04-13 18:19:50 +09:00
{
2019-06-27 13:38:21 +09:00
protected bool DownloadEnabled => button.Enabled.Value;
private readonly bool noVideo;
private readonly ShakeContainer shakeContainer;
private readonly DownloadButton button;
public PanelDownloadButton(BeatmapSetInfo beatmapSet, bool noVideo = false)
: base(beatmapSet)
2018-04-13 18:19:50 +09:00
{
this.noVideo = noVideo;
2018-07-17 21:36:33 +09:00
InternalChild = shakeContainer = new ShakeContainer
2018-04-13 18:19:50 +09:00
{
RelativeSizeAxes = Axes.Both,
Child = button = new DownloadButton
{
RelativeSizeAxes = Axes.Both,
},
};
}
protected override void LoadComplete()
{
base.LoadComplete();
button.State.BindTo(State);
2018-07-13 21:19:10 +09:00
FinishTransforms(true);
}
[BackgroundDependencyLoader(true)]
2019-07-02 16:13:47 +05:30
private void load(OsuGame game, BeatmapManager beatmaps)
{
if (BeatmapSet.Value.OnlineInfo.Availability?.DownloadDisabled ?? false)
{
button.Enabled.Value = false;
2019-06-21 16:38:16 +03:00
button.TooltipText = "This beatmap is currently not available for download.";
2019-06-10 21:14:12 +03:00
return;
}
button.Action = () =>
2018-07-17 21:36:33 +09:00
{
switch (State.Value)
2018-07-17 21:36:33 +09:00
{
case DownloadState.Downloading:
case DownloadState.Downloaded:
shakeContainer.Shake();
2018-07-17 21:36:33 +09:00
break;
2019-04-01 12:44:46 +09:00
case DownloadState.LocallyAvailable:
2019-02-21 18:56:34 +09:00
game.PresentBeatmap(BeatmapSet.Value);
2018-07-17 21:36:33 +09:00
break;
2019-04-01 12:44:46 +09:00
2018-07-17 21:36:33 +09:00
default:
2019-02-21 18:56:34 +09:00
beatmaps.Download(BeatmapSet.Value, noVideo);
2018-07-17 21:36:33 +09:00
break;
}
};
2018-04-13 18:19:50 +09:00
}
}
}