1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 01:33:21 +08:00
osu-lazer/osu.Game/Overlays/Direct/DownloadButton.cs

113 lines
4.1 KiB
C#
Raw Normal View History

2018-04-13 17:19:50 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables;
2018-04-13 17:19:50 +08:00
using osu.Game.Graphics;
2018-07-13 15:28:18 +08:00
using osu.Game.Graphics.UserInterface;
2018-04-13 17:19:50 +08:00
using OpenTK;
namespace osu.Game.Overlays.Direct
{
2018-07-13 15:28:18 +08:00
public class DownloadButton : OsuAnimatedButton
2018-04-13 17:19:50 +08:00
{
2018-07-17 20:36:33 +08:00
private readonly BeatmapSetInfo beatmapSet;
2018-04-13 17:19:50 +08:00
private readonly SpriteIcon icon;
private readonly SpriteIcon checkmark;
private readonly BeatmapSetDownloader downloader;
private readonly Box background;
private OsuColour colours;
2018-04-13 17:19:50 +08:00
2018-07-17 20:36:33 +08:00
public DownloadButton(BeatmapSetInfo beatmapSet, bool noVideo = false)
2018-04-13 17:19:50 +08:00
{
2018-07-17 20:36:33 +08:00
this.beatmapSet = beatmapSet;
2018-07-13 15:28:18 +08:00
AddRange(new Drawable[]
2018-04-13 17:19:50 +08:00
{
2018-07-17 20:36:33 +08:00
downloader = new BeatmapSetDownloader(beatmapSet, noVideo),
2018-07-13 15:28:18 +08:00
background = new Box
{
RelativeSizeAxes = Axes.Both,
2018-07-13 15:28:18 +08:00
Depth = float.MaxValue
},
2018-04-13 17:19:50 +08:00
icon = new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(13),
Icon = FontAwesome.fa_download,
2018-04-13 17:19:50 +08:00
},
checkmark = new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
X = 8,
Size = Vector2.Zero,
Icon = FontAwesome.fa_check,
}
2018-07-13 15:28:18 +08:00
});
}
protected override void LoadComplete()
{
base.LoadComplete();
2018-07-13 15:28:18 +08:00
downloader.DownloadState.BindValueChanged(updateState, true);
2018-07-13 20:19:10 +08:00
FinishTransforms(true);
}
2018-07-13 15:28:18 +08:00
[BackgroundDependencyLoader(permitNulls: true)]
2018-07-17 20:36:33 +08:00
private void load(OsuColour colours, OsuGame game)
{
this.colours = colours;
2018-07-17 20:36:33 +08:00
Action = () =>
{
switch (downloader.DownloadState.Value)
{
case BeatmapSetDownloader.DownloadStatus.Downloading:
// todo: replace with ShakeContainer after https://github.com/ppy/osu/pull/2909 is merged.
Content.MoveToX(-5, 50, Easing.OutSine).Then()
.MoveToX(5, 100, Easing.InOutSine).Then()
.MoveToX(-5, 100, Easing.InOutSine).Then()
.MoveToX(0, 50, Easing.InSine);
break;
case BeatmapSetDownloader.DownloadStatus.Downloaded:
game.PresentBeatmap(beatmapSet);
break;
default:
downloader.Download();
break;
}
};
2018-04-13 17:19:50 +08:00
}
2018-07-13 15:28:18 +08:00
private void updateState(BeatmapSetDownloader.DownloadStatus state)
2018-04-13 17:19:50 +08:00
{
2018-07-13 15:28:18 +08:00
switch (state)
{
case BeatmapSetDownloader.DownloadStatus.NotDownloaded:
background.FadeColour(colours.Gray4, 500, Easing.InOutExpo);
icon.MoveToX(0, 500, Easing.InOutExpo);
checkmark.ScaleTo(Vector2.Zero, 500, Easing.InOutExpo);
break;
case BeatmapSetDownloader.DownloadStatus.Downloading:
background.FadeColour(colours.Blue, 500, Easing.InOutExpo);
icon.MoveToX(0, 500, Easing.InOutExpo);
checkmark.ScaleTo(Vector2.Zero, 500, Easing.InOutExpo);
break;
case BeatmapSetDownloader.DownloadStatus.Downloaded:
background.FadeColour(colours.Green, 500, Easing.InOutExpo);
icon.MoveToX(-8, 500, Easing.InOutExpo);
checkmark.ScaleTo(new Vector2(13), 500, Easing.InOutExpo);
break;
}
2018-04-13 17:19:50 +08:00
}
}
}