1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-07 18:07:28 +08:00
osu-lazer/osu.Game/Overlays/Direct/DownloadButton.cs

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