2021-10-18 03:34:31 +08:00
|
|
|
// 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.
|
|
|
|
|
2021-10-23 21:01:53 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-10-18 03:34:31 +08:00
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2021-10-23 21:27:04 +08:00
|
|
|
using osu.Game.Graphics;
|
2021-10-23 21:01:53 +08:00
|
|
|
using osu.Game.Online;
|
|
|
|
using osu.Game.Overlays;
|
2021-10-23 21:27:04 +08:00
|
|
|
using osu.Game.Screens.Ranking.Expanded.Accuracy;
|
2021-10-23 21:01:53 +08:00
|
|
|
using osuTK;
|
2021-10-18 03:34:31 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
|
|
|
|
{
|
2021-10-23 21:01:53 +08:00
|
|
|
public class DownloadButton : CompositeDrawable
|
2021-10-18 03:34:31 +08:00
|
|
|
{
|
2021-10-23 21:01:53 +08:00
|
|
|
protected readonly DownloadIcon Download;
|
|
|
|
protected readonly PlayIcon Play;
|
|
|
|
protected readonly BeatmapDownloadTracker Tracker;
|
|
|
|
|
2021-10-23 21:27:04 +08:00
|
|
|
private readonly SmoothCircularProgress downloadProgress;
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private OsuColour colours { get; set; }
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private OverlayColourProvider colourProvider { get; set; }
|
2021-10-23 21:01:53 +08:00
|
|
|
|
2021-10-18 03:34:31 +08:00
|
|
|
public DownloadButton(APIBeatmapSet beatmapSet)
|
|
|
|
{
|
2021-10-23 21:01:53 +08:00
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
Origin = Anchor.Centre;
|
2021-10-23 21:27:04 +08:00
|
|
|
AutoSizeAxes = Axes.Both;
|
2021-10-23 21:01:53 +08:00
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
Tracker = new BeatmapDownloadTracker(beatmapSet),
|
|
|
|
Download = new DownloadIcon(),
|
2021-10-23 21:27:04 +08:00
|
|
|
downloadProgress = new SmoothCircularProgress
|
2021-10-23 21:01:53 +08:00
|
|
|
{
|
2021-10-23 21:27:04 +08:00
|
|
|
Size = new Vector2(12),
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
InnerRadius = 0.4f,
|
2021-10-23 21:01:53 +08:00
|
|
|
},
|
|
|
|
Play = new PlayIcon()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-10-23 21:27:04 +08:00
|
|
|
protected override void LoadComplete()
|
2021-10-23 21:01:53 +08:00
|
|
|
{
|
2021-10-23 21:27:04 +08:00
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
Tracker.Progress.BindValueChanged(_ => updateState());
|
|
|
|
Tracker.State.BindValueChanged(_ => updateState(), true);
|
|
|
|
FinishTransforms(true);
|
2021-10-23 21:01:53 +08:00
|
|
|
}
|
|
|
|
|
2021-10-23 21:27:04 +08:00
|
|
|
private void updateState()
|
2021-10-23 21:01:53 +08:00
|
|
|
{
|
2021-10-23 21:27:04 +08:00
|
|
|
Download.FadeTo(Tracker.State.Value == DownloadState.NotDownloaded ? 1 : 0, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
|
|
|
|
|
|
|
|
downloadProgress.FadeTo(Tracker.State.Value == DownloadState.Downloading || Tracker.State.Value == DownloadState.Importing ? 1 : 0, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
|
|
|
|
downloadProgress.FadeColour(Tracker.State.Value == DownloadState.Importing ? colours.Yellow : colourProvider.Highlight1, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
|
|
|
|
if (Tracker.State.Value == DownloadState.Downloading)
|
|
|
|
downloadProgress.FillTo(Tracker.Progress.Value, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
|
|
|
|
|
|
|
|
Play.FadeTo(Tracker.State.Value == DownloadState.LocallyAvailable ? 1 : 0, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
|
2021-10-23 21:01:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected class DownloadIcon : BeatmapCardIconButton
|
|
|
|
{
|
|
|
|
public DownloadIcon()
|
|
|
|
{
|
|
|
|
Icon.Icon = FontAwesome.Solid.Download;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected class PlayIcon : BeatmapCardIconButton
|
|
|
|
{
|
|
|
|
public PlayIcon()
|
|
|
|
{
|
|
|
|
Icon.Icon = FontAwesome.Regular.PlayCircle;
|
|
|
|
}
|
2021-10-18 03:34:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: implement behaviour
|
|
|
|
}
|
|
|
|
}
|