2021-11-10 22:24:36 +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-11-10 23:03:48 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Online;
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
|
|
|
using osu.Game.Overlays;
|
|
|
|
|
2021-11-10 22:24:36 +08:00
|
|
|
namespace osu.Game.Beatmaps.Drawables.Cards
|
|
|
|
{
|
2021-11-10 23:03:48 +08:00
|
|
|
public class BeatmapCardDownloadProgressBar : CompositeDrawable
|
2021-11-10 22:24:36 +08:00
|
|
|
{
|
2021-11-10 23:03:48 +08:00
|
|
|
private readonly BindableBool isActive = new BindableBool();
|
|
|
|
public IBindable<bool> IsActive => isActive;
|
|
|
|
|
|
|
|
public override bool IsPresent => true;
|
|
|
|
|
|
|
|
private readonly BeatmapDownloadTracker tracker;
|
2021-11-11 01:38:52 +08:00
|
|
|
private readonly CircularContainer background;
|
|
|
|
private readonly CircularContainer foreground;
|
|
|
|
|
|
|
|
private readonly Box backgroundFill;
|
|
|
|
private readonly Box foregroundFill;
|
2021-11-10 23:03:48 +08:00
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private OsuColour colours { get; set; }
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private OverlayColourProvider colourProvider { get; set; }
|
|
|
|
|
|
|
|
public BeatmapCardDownloadProgressBar(APIBeatmapSet beatmapSet)
|
|
|
|
{
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
tracker = new BeatmapDownloadTracker(beatmapSet),
|
2021-11-11 01:38:52 +08:00
|
|
|
background = new CircularContainer
|
2021-11-10 23:03:48 +08:00
|
|
|
{
|
2021-11-11 01:38:52 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Masking = true,
|
|
|
|
Child = backgroundFill = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
}
|
2021-11-10 23:03:48 +08:00
|
|
|
},
|
2021-11-11 01:38:52 +08:00
|
|
|
foreground = new CircularContainer
|
2021-11-10 23:03:48 +08:00
|
|
|
{
|
2021-11-11 01:38:52 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Masking = true,
|
|
|
|
Child = foregroundFill = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
}
|
2021-11-10 23:03:48 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2021-11-11 01:38:52 +08:00
|
|
|
backgroundFill.Colour = colourProvider.Background6;
|
2021-11-10 23:03:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
tracker.State.BindValueChanged(_ => stateChanged(), true);
|
|
|
|
tracker.Progress.BindValueChanged(_ => progressChanged(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void stateChanged()
|
|
|
|
{
|
|
|
|
switch (tracker.State.Value)
|
|
|
|
{
|
|
|
|
case DownloadState.Downloading:
|
|
|
|
FinishTransforms(true);
|
2021-11-11 01:38:52 +08:00
|
|
|
foregroundFill.Colour = colourProvider.Highlight1;
|
2021-11-10 23:03:48 +08:00
|
|
|
isActive.Value = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DownloadState.Importing:
|
2021-11-11 01:38:52 +08:00
|
|
|
foregroundFill.FadeColour(colours.Yellow, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
|
2021-11-10 23:03:48 +08:00
|
|
|
isActive.Value = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
isActive.Value = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void progressChanged()
|
|
|
|
{
|
|
|
|
double progress = tracker.Progress.Value;
|
|
|
|
foreground.ResizeWidthTo((float)progress, progress > 0 ? BeatmapCard.TRANSITION_DURATION : 0, Easing.OutQuint);
|
|
|
|
}
|
2021-11-10 22:24:36 +08:00
|
|
|
}
|
|
|
|
}
|