From 91baaa73f37c42d0adaf95aad2893c902f7f1019 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Wed, 10 Nov 2021 16:03:48 +0100 Subject: [PATCH] Show download progress on card body rather than in button --- .../Visual/Beatmaps/TestSceneBeatmapCard.cs | 17 ++++ .../TestSceneBeatmapCardDownloadButton.cs | 15 ++-- .../Beatmaps/Drawables/Cards/BeatmapCard.cs | 60 +++++++++---- .../Cards/BeatmapCardDownloadProgressBar.cs | 84 ++++++++++++++++++- .../Drawables/Cards/Buttons/DownloadButton.cs | 19 +---- 5 files changed, 148 insertions(+), 47 deletions(-) diff --git a/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapCard.cs b/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapCard.cs index 0feaa8f480..29a1e349c4 100644 --- a/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapCard.cs +++ b/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapCard.cs @@ -27,6 +27,9 @@ namespace osu.Game.Tests.Visual.Beatmaps private APIBeatmapSet[] testCases; + [Resolved] + private BeatmapManager beatmaps { get; set; } + #region Test case generation [BackgroundDependencyLoader] @@ -35,6 +38,7 @@ namespace osu.Game.Tests.Visual.Beatmaps var normal = CreateAPIBeatmapSet(Ruleset.Value); normal.HasVideo = true; normal.HasStoryboard = true; + normal.OnlineID = 241526; var withStatistics = CreateAPIBeatmapSet(Ruleset.Value); withStatistics.Title = withStatistics.TitleUnicode = "play favourite stats"; @@ -180,6 +184,19 @@ namespace osu.Game.Tests.Visual.Beatmaps request.TriggerSuccess(); return true; }); + + ensureSoleilyRemoved(); + } + + private void ensureSoleilyRemoved() + { + AddUntilStep("ensure manager loaded", () => beatmaps != null); + AddStep("remove soleily", () => + { + var beatmap = beatmaps.QueryBeatmapSet(b => b.OnlineBeatmapSetID == 241526); + + if (beatmap != null) beatmaps.Delete(beatmap); + }); } private Drawable createContent(OverlayColourScheme colourScheme, Func creationFunc) diff --git a/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapCardDownloadButton.cs b/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapCardDownloadButton.cs index 11eb93c5ac..82ab55cf0e 100644 --- a/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapCardDownloadButton.cs +++ b/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapCardDownloadButton.cs @@ -6,7 +6,6 @@ using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; -using osu.Framework.Testing; using osu.Game.Beatmaps; using osu.Game.Beatmaps.Drawables.Cards.Buttons; using osu.Game.Configuration; @@ -15,7 +14,6 @@ using osu.Game.Online.API.Requests.Responses; using osu.Game.Overlays; using osu.Game.Resources.Localisation.Web; using osu.Game.Rulesets.Osu; -using osu.Game.Screens.Ranking.Expanded.Accuracy; using osu.Game.Tests.Resources; using osuTK; @@ -42,22 +40,21 @@ namespace osu.Game.Tests.Visual.Beatmaps assertDownloadVisible(true); assertDownloadEnabled(true); - assertProgressVisible(false); assertPlayVisible(false); AddAssert("tooltip text correct", () => downloadButton.Download.TooltipText == BeatmapsetsStrings.PanelDownloadAll); AddStep("set downloading state", () => downloadButton.State.Value = DownloadState.Downloading); - assertDownloadVisible(false); - assertProgressVisible(true); + assertDownloadVisible(true); + assertDownloadEnabled(false); assertPlayVisible(false); - AddStep("set progress to 30%", () => downloadButton.Progress.Value = 0.3f); - AddStep("set progress to 100%", () => downloadButton.Progress.Value = 1f); AddStep("set importing state", () => downloadButton.State.Value = DownloadState.Importing); + assertDownloadVisible(true); + assertDownloadEnabled(false); + assertPlayVisible(false); AddStep("set locally available state", () => downloadButton.State.Value = DownloadState.LocallyAvailable); assertDownloadVisible(false); - assertProgressVisible(false); assertPlayVisible(true); } @@ -113,8 +110,6 @@ namespace osu.Game.Tests.Visual.Beatmaps private void assertDownloadVisible(bool visible) => AddUntilStep($"download {(visible ? "visible" : "not visible")}", () => downloadButton.Download.IsPresent == visible); private void assertDownloadEnabled(bool enabled) => AddAssert($"download {(enabled ? "enabled" : "disabled")}", () => downloadButton.Download.Enabled.Value == enabled); - private void assertProgressVisible(bool visible) => AddUntilStep($"progress {(visible ? "visible" : "not visible")}", () => downloadButton.ChildrenOfType().Single().IsPresent == visible); - private void assertPlayVisible(bool visible) => AddUntilStep($"play {(visible ? "visible" : "not visible")}", () => downloadButton.Play.IsPresent == visible); private static APIBeatmapSet createSoleily() => new APIBeatmapSet diff --git a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCard.cs b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCard.cs index 3202ac4b3c..fe25d3dc36 100644 --- a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCard.cs +++ b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCard.cs @@ -50,6 +50,9 @@ namespace osu.Game.Beatmaps.Drawables.Cards private GridContainer artistContainer; private FillFlowContainer statisticsContainer; + private FillFlowContainer idleBottomContent; + private BeatmapCardDownloadProgressBar downloadProgressBar; + [Resolved] private OverlayColourProvider colourProvider { get; set; } @@ -218,34 +221,51 @@ namespace osu.Game.Beatmaps.Drawables.Cards } } }, - new FillFlowContainer + new Container { Name = @"Bottom content", RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, - Direction = FillDirection.Horizontal, - Padding = new MarginPadding - { - Horizontal = 10, - Vertical = 4 - }, - Spacing = new Vector2(4, 0), Anchor = Anchor.BottomLeft, Origin = Anchor.BottomLeft, Children = new Drawable[] { - new BeatmapSetOnlineStatusPill + idleBottomContent = new FillFlowContainer { - AutoSizeAxes = Axes.Both, - Status = beatmapSet.Status, - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Direction = FillDirection.Horizontal, + Padding = new MarginPadding + { + Horizontal = 10, + Vertical = 4 + }, + Spacing = new Vector2(4, 0), + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft, + Children = new Drawable[] + { + new BeatmapSetOnlineStatusPill + { + AutoSizeAxes = Axes.Both, + Status = beatmapSet.Status, + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft + }, + new DifficultySpectrumDisplay(beatmapSet) + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + DotSize = new Vector2(6, 12) + } + } }, - new DifficultySpectrumDisplay(beatmapSet) + downloadProgressBar = new BeatmapCardDownloadProgressBar(beatmapSet) { - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - DotSize = new Vector2(6, 12) + RelativeSizeAxes = Axes.X, + Height = 0, + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft } } } @@ -283,7 +303,8 @@ namespace osu.Game.Beatmaps.Drawables.Cards protected override void LoadComplete() { base.LoadComplete(); - updateState(); + + downloadProgressBar.IsActive.BindValueChanged(_ => updateState(), true); FinishTransforms(true); } @@ -335,6 +356,9 @@ namespace osu.Game.Beatmaps.Drawables.Cards leftCover.FadeColour(IsHovered ? OsuColour.Gray(0.2f) : Color4.White, TRANSITION_DURATION, Easing.OutQuint); statisticsContainer.FadeTo(IsHovered ? 1 : 0, TRANSITION_DURATION, Easing.OutQuint); rightButtonArea.FadeTo(IsHovered ? 1 : 0, TRANSITION_DURATION, Easing.OutQuint); + + idleBottomContent.FadeTo(downloadProgressBar.IsActive.Value ? 0 : 1, TRANSITION_DURATION, Easing.OutQuint); + downloadProgressBar.ResizeHeightTo(downloadProgressBar.IsActive.Value ? 8 : 0, TRANSITION_DURATION, Easing.OutQuint); } } } diff --git a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardDownloadProgressBar.cs b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardDownloadProgressBar.cs index 56e23f920b..a016f99b20 100644 --- a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardDownloadProgressBar.cs +++ b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardDownloadProgressBar.cs @@ -1,10 +1,90 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +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; + namespace osu.Game.Beatmaps.Drawables.Cards { - public class BeatmapCardDownloadProgressBar + public class BeatmapCardDownloadProgressBar : CompositeDrawable { - + private readonly BindableBool isActive = new BindableBool(); + public IBindable IsActive => isActive; + + public override bool IsPresent => true; + + private readonly BeatmapDownloadTracker tracker; + private readonly Box background; + private readonly Box foreground; + + [Resolved] + private OsuColour colours { get; set; } + + [Resolved] + private OverlayColourProvider colourProvider { get; set; } + + public BeatmapCardDownloadProgressBar(APIBeatmapSet beatmapSet) + { + InternalChildren = new Drawable[] + { + tracker = new BeatmapDownloadTracker(beatmapSet), + background = new Box + { + RelativeSizeAxes = Axes.Both + }, + foreground = new Box + { + RelativeSizeAxes = Axes.Both + } + }; + } + + [BackgroundDependencyLoader] + private void load() + { + background.Colour = colourProvider.Background6; + } + + 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); + foreground.Colour = colourProvider.Highlight1; + isActive.Value = true; + break; + + case DownloadState.Importing: + foreground.FadeColour(colours.Yellow, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint); + 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); + } } } diff --git a/osu.Game/Beatmaps/Drawables/Cards/Buttons/DownloadButton.cs b/osu.Game/Beatmaps/Drawables/Cards/Buttons/DownloadButton.cs index df765e1e69..85e2988614 100644 --- a/osu.Game/Beatmaps/Drawables/Cards/Buttons/DownloadButton.cs +++ b/osu.Game/Beatmaps/Drawables/Cards/Buttons/DownloadButton.cs @@ -14,8 +14,6 @@ using osu.Game.Graphics; using osu.Game.Online; using osu.Game.Overlays; using osu.Game.Resources.Localisation.Web; -using osu.Game.Screens.Ranking.Expanded.Accuracy; -using osuTK; namespace osu.Game.Beatmaps.Drawables.Cards.Buttons { @@ -25,8 +23,6 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons protected readonly PlayIcon Play; protected readonly BeatmapDownloadTracker Tracker; - private readonly SmoothCircularProgress downloadProgress; - [Resolved] private OsuColour colours { get; set; } = null!; @@ -43,13 +39,6 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons { Tracker = new BeatmapDownloadTracker(beatmapSet), Download = new DownloadIcon(beatmapSet), - downloadProgress = new SmoothCircularProgress - { - Size = new Vector2(12), - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - InnerRadius = 0.4f, - }, Play = new PlayIcon(beatmapSet) }; } @@ -65,12 +54,8 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons private void updateState() { - Download.FadeTo(Tracker.State.Value == DownloadState.NotDownloaded ? 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); - if (Tracker.State.Value == DownloadState.Downloading) - downloadProgress.FillTo(Tracker.Progress.Value, Tracker.Progress.Value > 0 ? BeatmapCard.TRANSITION_DURATION : 0, Easing.OutQuint); + Download.FadeTo(Tracker.State.Value != DownloadState.LocallyAvailable ? 1 : 0, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint); + Download.Enabled.Value = Tracker.State.Value == DownloadState.NotDownloaded; Play.FadeTo(Tracker.State.Value == DownloadState.LocallyAvailable ? 1 : 0, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint); }