mirror of
https://github.com/ppy/osu.git
synced 2025-01-26 18:52:55 +08:00
Show download progress on card body rather than in button
This commit is contained in:
parent
f090e5ca75
commit
91baaa73f3
@ -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<APIBeatmapSet, Drawable> creationFunc)
|
||||
|
@ -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<SmoothCircularProgress>().Single().IsPresent == visible);
|
||||
|
||||
private void assertPlayVisible(bool visible) => AddUntilStep($"play {(visible ? "visible" : "not visible")}", () => downloadButton.Play.IsPresent == visible);
|
||||
|
||||
private static APIBeatmapSet createSoleily() => new APIBeatmapSet
|
||||
|
@ -50,6 +50,9 @@ namespace osu.Game.Beatmaps.Drawables.Cards
|
||||
private GridContainer artistContainer;
|
||||
private FillFlowContainer<BeatmapCardStatistic> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,90 @@
|
||||
// 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.
|
||||
|
||||
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<bool> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user