1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-24 10:43:06 +08:00
osu-lazer/osu.Game/Overlays/Direct/DownloadButton.cs

110 lines
3.9 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
{
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
public DownloadButton(BeatmapSetInfo set, bool noVideo = false)
2018-04-13 17:19:50 +08:00
{
2018-07-13 15:28:18 +08:00
AddRange(new Drawable[]
2018-04-13 17:19:50 +08:00
{
downloader = new BeatmapSetDownloader(set, 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
});
Action = () =>
{
2018-07-13 15:28:18 +08:00
if (downloader.DownloadState == BeatmapSetDownloader.DownloadStatus.Downloading)
{
2018-07-13 15:28:18 +08:00
// 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);
}
2018-07-13 15:28:18 +08:00
else if (downloader.DownloadState == BeatmapSetDownloader.DownloadStatus.Downloaded)
{
// TODO: Jump to song select with this set when the capability is implemented
}
else
{
downloader.Download();
}
};
}
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)]
private void load(OsuColour colours)
{
this.colours = colours;
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
}
}
}