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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
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.Overlays;
|
|
|
|
|
2021-11-10 22:24:36 +08:00
|
|
|
namespace osu.Game.Beatmaps.Drawables.Cards
|
|
|
|
{
|
2021-11-10 23:03:48 +08:00
|
|
|
public partial class BeatmapCardDownloadProgressBar : CompositeDrawable
|
2021-11-10 22:24:36 +08:00
|
|
|
{
|
2021-11-21 01:45:24 +08:00
|
|
|
public IBindable<DownloadState> State => state;
|
|
|
|
private readonly Bindable<DownloadState> state = new Bindable<DownloadState>();
|
|
|
|
|
|
|
|
public IBindable<double> Progress => progress;
|
|
|
|
private readonly BindableDouble progress = new BindableDouble();
|
|
|
|
|
2021-11-10 23:03:48 +08:00
|
|
|
public override bool IsPresent => true;
|
|
|
|
|
2021-11-11 01:38:52 +08:00
|
|
|
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; }
|
|
|
|
|
2021-11-13 22:38:04 +08:00
|
|
|
public BeatmapCardDownloadProgressBar()
|
2021-11-10 23:03:48 +08:00
|
|
|
{
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
2021-11-13 22:38:04 +08:00
|
|
|
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]
|
2021-11-21 01:45:24 +08:00
|
|
|
private void load()
|
2021-11-10 23:03:48 +08:00
|
|
|
{
|
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();
|
|
|
|
|
2021-11-13 22:38:04 +08:00
|
|
|
state.BindValueChanged(_ => stateChanged(), true);
|
|
|
|
progress.BindValueChanged(_ => progressChanged(), true);
|
2021-11-10 23:03:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void stateChanged()
|
|
|
|
{
|
2021-11-13 22:38:04 +08:00
|
|
|
switch (state.Value)
|
2021-11-10 23:03:48 +08:00
|
|
|
{
|
|
|
|
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
|
|
|
break;
|
|
|
|
|
|
|
|
case DownloadState.Importing:
|
2021-12-21 15:26:19 +08:00
|
|
|
foregroundFill.FadeColour(colours.Yellow, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
|
2021-11-10 23:03:48 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void progressChanged()
|
|
|
|
{
|
2021-12-21 15:26:19 +08:00
|
|
|
foreground.ResizeWidthTo((float)progress.Value, progress.Value > 0 ? BeatmapCard.TRANSITION_DURATION : 0, Easing.OutQuint);
|
2021-11-10 23:03:48 +08:00
|
|
|
}
|
2021-11-10 22:24:36 +08:00
|
|
|
}
|
|
|
|
}
|