1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-11 00:02:56 +08:00

Implement detailed download button behaviour

This commit is contained in:
Bartłomiej Dach 2021-10-23 15:51:36 +02:00
parent a60cceeda6
commit 2186b51676
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
2 changed files with 87 additions and 14 deletions

View File

@ -9,9 +9,11 @@ using osu.Framework.Graphics;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables.Cards.Buttons; using osu.Game.Beatmaps.Drawables.Cards.Buttons;
using osu.Game.Configuration;
using osu.Game.Online; using osu.Game.Online;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Resources.Localisation.Web;
using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu;
using osu.Game.Screens.Ranking.Expanded.Accuracy; using osu.Game.Screens.Ranking.Expanded.Accuracy;
using osu.Game.Tests.Resources; using osu.Game.Tests.Resources;
@ -29,15 +31,20 @@ namespace osu.Game.Tests.Visual.Beatmaps
[Resolved] [Resolved]
private BeatmapManager beatmaps { get; set; } private BeatmapManager beatmaps { get; set; }
[Resolved]
private OsuConfigManager config { get; set; }
[Test] [Test]
public void TestDownloadableBeatmap() public void TestDownloadableBeatmap()
{ {
ensureSoleilyRemoved();
createButton(true); createButton(true);
assertDownloadVisible(true); assertDownloadVisible(true);
assertDownloadEnabled(true); assertDownloadEnabled(true);
assertProgressVisible(false); assertProgressVisible(false);
assertPlayVisible(false); assertPlayVisible(false);
AddAssert("tooltip text correct", () => downloadButton.Download.TooltipText == BeatmapsetsStrings.PanelDownloadAll);
AddStep("set downloading state", () => downloadButton.State.Value = DownloadState.Downloading); AddStep("set downloading state", () => downloadButton.State.Value = DownloadState.Downloading);
assertDownloadVisible(false); assertDownloadVisible(false);
@ -54,17 +61,30 @@ namespace osu.Game.Tests.Visual.Beatmaps
assertPlayVisible(true); assertPlayVisible(true);
} }
[Test]
public void TestDownloadableBeatmapWithVideo()
{
createButton(true, true);
assertDownloadEnabled(true);
AddStep("prefer no video", () => config.SetValue(OsuSetting.PreferNoVideo, true));
AddAssert("tooltip text correct", () => downloadButton.Download.TooltipText == BeatmapsetsStrings.PanelDownloadNoVideo);
AddStep("prefer video", () => config.SetValue(OsuSetting.PreferNoVideo, false));
AddAssert("tooltip text correct", () => downloadButton.Download.TooltipText == BeatmapsetsStrings.PanelDownloadVideo);
}
[Test] [Test]
public void TestUndownloadableBeatmap() public void TestUndownloadableBeatmap()
{ {
createButton(false); createButton(false);
assertDownloadEnabled(false); assertDownloadEnabled(false);
AddAssert("tooltip text correct", () => downloadButton.Download.TooltipText == BeatmapsetsStrings.AvailabilityDisabled);
} }
[Test] [Test]
public void TestDownloadState() public void TestDownloadState()
{ {
AddUntilStep("ensure manager loaded", () => beatmaps != null);
ensureSoleilyRemoved(); ensureSoleilyRemoved();
createButtonWithBeatmap(createSoleily()); createButtonWithBeatmap(createSoleily());
AddAssert("button state not downloaded", () => downloadButton.State.Value == DownloadState.NotDownloaded); AddAssert("button state not downloaded", () => downloadButton.State.Value == DownloadState.NotDownloaded);
@ -81,6 +101,7 @@ namespace osu.Game.Tests.Visual.Beatmaps
private void ensureSoleilyRemoved() private void ensureSoleilyRemoved()
{ {
AddUntilStep("ensure manager loaded", () => beatmaps != null);
AddStep("remove soleily", () => AddStep("remove soleily", () =>
{ {
var beatmap = beatmaps.QueryBeatmapSet(b => b.OnlineBeatmapSetID == 241526); var beatmap = beatmaps.QueryBeatmapSet(b => b.OnlineBeatmapSetID == 241526);
@ -119,11 +140,11 @@ namespace osu.Game.Tests.Visual.Beatmaps
}); });
} }
private void createButton(bool downloadable) private void createButton(bool downloadable, bool hasVideo = false)
{ {
AddStep("create button", () => AddStep("create button", () =>
{ {
Child = downloadButton = new TestDownloadButton(downloadable ? getDownloadableBeatmapSet() : getUndownloadableBeatmapSet()) Child = downloadButton = new TestDownloadButton(downloadable ? getDownloadableBeatmapSet(hasVideo) : getUndownloadableBeatmapSet())
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
@ -132,10 +153,10 @@ namespace osu.Game.Tests.Visual.Beatmaps
}); });
} }
private APIBeatmapSet getDownloadableBeatmapSet() private APIBeatmapSet getDownloadableBeatmapSet(bool hasVideo)
{ {
var normal = CreateAPIBeatmapSet(new OsuRuleset().RulesetInfo); var normal = CreateAPIBeatmapSet(new OsuRuleset().RulesetInfo);
normal.HasVideo = true; normal.HasVideo = hasVideo;
normal.HasStoryboard = true; normal.HasStoryboard = true;
return normal; return normal;

View File

@ -1,14 +1,19 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable enable
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
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.Graphics; using osu.Game.Graphics;
using osu.Game.Online; using osu.Game.Online;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Resources.Localisation.Web;
using osu.Game.Screens.Ranking.Expanded.Accuracy; using osu.Game.Screens.Ranking.Expanded.Accuracy;
using osuTK; using osuTK;
@ -23,10 +28,10 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
private readonly SmoothCircularProgress downloadProgress; private readonly SmoothCircularProgress downloadProgress;
[Resolved] [Resolved]
private OsuColour colours { get; set; } private OsuColour colours { get; set; } = null!;
[Resolved] [Resolved]
private OverlayColourProvider colourProvider { get; set; } private OverlayColourProvider colourProvider { get; set; } = null!;
public DownloadButton(APIBeatmapSet beatmapSet) public DownloadButton(APIBeatmapSet beatmapSet)
{ {
@ -37,7 +42,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
InternalChildren = new Drawable[] InternalChildren = new Drawable[]
{ {
Tracker = new BeatmapDownloadTracker(beatmapSet), Tracker = new BeatmapDownloadTracker(beatmapSet),
Download = new DownloadIcon(), Download = new DownloadIcon(beatmapSet),
downloadProgress = new SmoothCircularProgress downloadProgress = new SmoothCircularProgress
{ {
Size = new Vector2(12), Size = new Vector2(12),
@ -45,7 +50,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
Origin = Anchor.Centre, Origin = Anchor.Centre,
InnerRadius = 0.4f, InnerRadius = 0.4f,
}, },
Play = new PlayIcon() Play = new PlayIcon(beatmapSet)
}; };
} }
@ -65,27 +70,74 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
downloadProgress.FadeTo(Tracker.State.Value == DownloadState.Downloading || Tracker.State.Value == DownloadState.Importing ? 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); downloadProgress.FadeColour(Tracker.State.Value == DownloadState.Importing ? colours.Yellow : colourProvider.Highlight1, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
if (Tracker.State.Value == DownloadState.Downloading) if (Tracker.State.Value == DownloadState.Downloading)
downloadProgress.FillTo(Tracker.Progress.Value, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint); downloadProgress.FillTo(Tracker.Progress.Value, Tracker.Progress.Value > 0 ? BeatmapCard.TRANSITION_DURATION : 0, Easing.OutQuint);
Play.FadeTo(Tracker.State.Value == DownloadState.LocallyAvailable ? 1 : 0, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint); Play.FadeTo(Tracker.State.Value == DownloadState.LocallyAvailable ? 1 : 0, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
} }
protected class DownloadIcon : BeatmapCardIconButton protected class DownloadIcon : BeatmapCardIconButton
{ {
public DownloadIcon() private readonly APIBeatmapSet beatmapSet;
private Bindable<bool> preferNoVideo = null!;
[Resolved]
private BeatmapManager beatmaps { get; set; } = null!;
public DownloadIcon(APIBeatmapSet beatmapSet)
{ {
Icon.Icon = FontAwesome.Solid.Download; Icon.Icon = FontAwesome.Solid.Download;
this.beatmapSet = beatmapSet;
}
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
{
preferNoVideo = config.GetBindable<bool>(OsuSetting.PreferNoVideo);
}
protected override void LoadComplete()
{
base.LoadComplete();
preferNoVideo.BindValueChanged(_ => updateState(), true);
}
private void updateState()
{
if (beatmapSet.Availability.DownloadDisabled)
{
Enabled.Value = false;
TooltipText = BeatmapsetsStrings.AvailabilityDisabled;
return;
}
if (!beatmapSet.HasVideo)
TooltipText = BeatmapsetsStrings.PanelDownloadAll;
else
TooltipText = preferNoVideo.Value ? BeatmapsetsStrings.PanelDownloadNoVideo : BeatmapsetsStrings.PanelDownloadVideo;
Action = () => beatmaps.Download(beatmapSet, preferNoVideo.Value);
} }
} }
protected class PlayIcon : BeatmapCardIconButton protected class PlayIcon : BeatmapCardIconButton
{ {
public PlayIcon() private readonly APIBeatmapSet beatmapSet;
public PlayIcon(APIBeatmapSet beatmapSet)
{ {
this.beatmapSet = beatmapSet;
Icon.Icon = FontAwesome.Regular.PlayCircle; Icon.Icon = FontAwesome.Regular.PlayCircle;
TooltipText = "Go to beatmap";
}
[BackgroundDependencyLoader(true)]
private void load(OsuGame? game)
{
if (game != null)
Action = () => game.PresentBeatmap(beatmapSet);
} }
} }
// TODO: implement behaviour
} }
} }