Show a spinner instead of the download button on the new card during beatmap download

This commit is contained in:
Dean Herbert
2021-11-26 15:32:33 +09:00
parent 8e16ff7f72
commit 5de2f6211d
2 changed files with 47 additions and 15 deletions

View File

@ -54,6 +54,8 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
protected readonly SpriteIcon Icon; protected readonly SpriteIcon Icon;
protected override Container<Drawable> Content => content;
private readonly Container content; private readonly Container content;
protected BeatmapCardIconButton() protected BeatmapCardIconButton()
@ -61,7 +63,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
Origin = Anchor.Centre; Origin = Anchor.Centre;
Anchor = Anchor.Centre; Anchor = Anchor.Centre;
Child = content = new Container base.Content.Add(content = new Container
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Masking = true, Masking = true,
@ -75,7 +77,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
Anchor = Anchor.Centre Anchor = Anchor.Centre
} }
} }
}; });
Size = new Vector2(24); Size = new Vector2(24);
IconSize = 12; IconSize = 12;

View File

@ -3,14 +3,17 @@
#nullable enable #nullable enable
using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online; using osu.Game.Online;
using osu.Game.Resources.Localisation.Web; using osu.Game.Resources.Localisation.Web;
using osuTK;
namespace osu.Game.Beatmaps.Drawables.Cards.Buttons namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
{ {
@ -23,6 +26,8 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
private Bindable<bool> preferNoVideo = null!; private Bindable<bool> preferNoVideo = null!;
private readonly LoadingSpinner spinner;
[Resolved] [Resolved]
private BeatmapModelDownloader beatmaps { get; set; } = null!; private BeatmapModelDownloader beatmaps { get; set; } = null!;
@ -30,6 +35,8 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
{ {
Icon.Icon = FontAwesome.Solid.Download; Icon.Icon = FontAwesome.Solid.Download;
Content.Add(spinner = new LoadingSpinner { Size = new Vector2(IconSize) });
this.beatmapSet = beatmapSet; this.beatmapSet = beatmapSet;
} }
@ -49,21 +56,44 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
private void updateState() private void updateState()
{ {
this.FadeTo(state.Value != DownloadState.LocallyAvailable ? 1 : 0, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint); switch (state.Value)
if (beatmapSet.Availability.DownloadDisabled)
{ {
Enabled.Value = false; case DownloadState.Downloading:
TooltipText = BeatmapsetsStrings.AvailabilityDisabled; case DownloadState.Importing:
return; Action = null;
TooltipText = string.Empty;
spinner.Show();
Icon.Hide();
return;
case DownloadState.LocallyAvailable:
Action = null;
TooltipText = string.Empty;
this.FadeOut(BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
break;
case DownloadState.NotDownloaded:
if (beatmapSet.Availability.DownloadDisabled)
{
Enabled.Value = false;
TooltipText = BeatmapsetsStrings.AvailabilityDisabled;
return;
}
Action = () => beatmaps.Download(beatmapSet, preferNoVideo.Value);
this.FadeIn(BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
spinner.Hide();
Icon.Show();
if (!beatmapSet.HasVideo)
TooltipText = BeatmapsetsStrings.PanelDownloadAll;
else
TooltipText = preferNoVideo.Value ? BeatmapsetsStrings.PanelDownloadNoVideo : BeatmapsetsStrings.PanelDownloadVideo;
break;
default:
throw new InvalidOperationException($"Unknown {nameof(DownloadState)} specified.");
} }
if (!beatmapSet.HasVideo)
TooltipText = BeatmapsetsStrings.PanelDownloadAll;
else
TooltipText = preferNoVideo.Value ? BeatmapsetsStrings.PanelDownloadNoVideo : BeatmapsetsStrings.PanelDownloadVideo;
Action = () => beatmaps.Download(beatmapSet, preferNoVideo.Value);
} }
} }
} }