mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 08:49:59 +09:00
Remove necessity of BeatmapSetDownloader
This commit is contained in:
@ -5,103 +5,114 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Beatmaps.Drawables;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Overlays.Direct
|
||||
{
|
||||
public class DownloadButton : OsuAnimatedButton
|
||||
public class DownloadButton : DownloadTrackingComposite
|
||||
{
|
||||
private readonly BeatmapSetInfo beatmapSet;
|
||||
private readonly bool noVideo;
|
||||
private readonly SpriteIcon icon;
|
||||
private readonly SpriteIcon checkmark;
|
||||
private readonly BeatmapSetDownloader downloader;
|
||||
private readonly Box background;
|
||||
|
||||
private OsuColour colours;
|
||||
|
||||
public DownloadButton(BeatmapSetInfo beatmapSet, bool noVideo = false)
|
||||
{
|
||||
this.beatmapSet = beatmapSet;
|
||||
private readonly ShakeContainer shakeContainer;
|
||||
|
||||
AddRange(new Drawable[]
|
||||
private readonly OsuAnimatedButton button;
|
||||
|
||||
public DownloadButton(BeatmapSetInfo beatmapSet, bool noVideo = false)
|
||||
: base(beatmapSet)
|
||||
{
|
||||
this.noVideo = noVideo;
|
||||
|
||||
InternalChild = shakeContainer = new ShakeContainer
|
||||
{
|
||||
downloader = new BeatmapSetDownloader(beatmapSet, noVideo),
|
||||
background = new Box
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = button = new OsuAnimatedButton
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Depth = float.MaxValue
|
||||
},
|
||||
icon = new SpriteIcon
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Size = new Vector2(13),
|
||||
Icon = FontAwesome.fa_download,
|
||||
},
|
||||
checkmark = new SpriteIcon
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
X = 8,
|
||||
Size = Vector2.Zero,
|
||||
Icon = FontAwesome.fa_check,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
background = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Depth = float.MaxValue
|
||||
},
|
||||
icon = new SpriteIcon
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Size = new Vector2(13),
|
||||
Icon = FontAwesome.fa_download,
|
||||
},
|
||||
checkmark = new SpriteIcon
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
X = 8,
|
||||
Size = Vector2.Zero,
|
||||
Icon = FontAwesome.fa_check,
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
downloader.DownloadState.BindValueChanged(updateState, true);
|
||||
|
||||
State.BindValueChanged(updateState, true);
|
||||
FinishTransforms(true);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader(permitNulls: true)]
|
||||
private void load(OsuColour colours, OsuGame game)
|
||||
private void load(OsuColour colours, OsuGame game, BeatmapManager beatmaps)
|
||||
{
|
||||
this.colours = colours;
|
||||
|
||||
Action = () =>
|
||||
button.Action = () =>
|
||||
{
|
||||
switch (downloader.DownloadState.Value)
|
||||
switch (State.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);
|
||||
case DownloadState.Downloading:
|
||||
case DownloadState.Downloaded:
|
||||
shakeContainer.Shake();
|
||||
break;
|
||||
case BeatmapSetDownloader.DownloadStatus.Downloaded:
|
||||
game.PresentBeatmap(beatmapSet);
|
||||
case DownloadState.LocallyAvailable:
|
||||
game.PresentBeatmap(BeatmapSet);
|
||||
break;
|
||||
default:
|
||||
downloader.Download();
|
||||
beatmaps.Download(BeatmapSet, noVideo);
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void updateState(BeatmapSetDownloader.DownloadStatus state)
|
||||
private void updateState(DownloadState state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case BeatmapSetDownloader.DownloadStatus.NotDownloaded:
|
||||
case DownloadState.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:
|
||||
case DownloadState.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:
|
||||
case DownloadState.Downloaded:
|
||||
background.FadeColour(colours.Yellow, 500, Easing.InOutExpo);
|
||||
break;
|
||||
case DownloadState.LocallyAvailable:
|
||||
background.FadeColour(colours.Green, 500, Easing.InOutExpo);
|
||||
icon.MoveToX(-8, 500, Easing.InOutExpo);
|
||||
checkmark.ScaleTo(new Vector2(13), 500, Easing.InOutExpo);
|
||||
|
Reference in New Issue
Block a user