Show download progress on card body rather than in button

This commit is contained in:
Bartłomiej Dach
2021-11-10 16:03:48 +01:00
parent f090e5ca75
commit 91baaa73f3
5 changed files with 148 additions and 47 deletions

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}

View File

@ -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);
}