1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 18:23:04 +08:00

Restructure card to use single tracker at the top level

This commit is contained in:
Bartłomiej Dach 2021-11-13 15:38:04 +01:00
parent be3f225d4b
commit b58fe2d80a
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
4 changed files with 38 additions and 36 deletions

View File

@ -178,8 +178,7 @@ namespace osu.Game.Tests.Visual.Beatmaps
private class TestDownloadButton : DownloadButton
{
public readonly Bindable<DownloadState> State = new Bindable<DownloadState>();
public readonly BindableNumber<double> Progress = new BindableNumber<double>();
public new Bindable<DownloadState> State => base.State;
public new BeatmapCardIconButton Download => base.Download;
public new BeatmapCardIconButton Play => base.Play;
@ -187,8 +186,6 @@ namespace osu.Game.Tests.Visual.Beatmaps
public TestDownloadButton(APIBeatmapSet beatmapSet)
: base(beatmapSet)
{
Tracker.State.BindTo(State);
Tracker.Progress.BindTo(Progress);
}
}
}

View File

@ -16,6 +16,7 @@ using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays;
using osu.Game.Overlays.BeatmapSet;
@ -38,6 +39,9 @@ namespace osu.Game.Beatmaps.Drawables.Cards
private readonly APIBeatmapSet beatmapSet;
private readonly Bindable<BeatmapSetFavouriteState> favouriteState;
[Cached]
private readonly BeatmapDownloadTracker downloadTracker;
private UpdateableOnlineBeatmapSetCover leftCover;
private FillFlowContainer leftIconArea;
@ -61,6 +65,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards
{
this.beatmapSet = beatmapSet;
favouriteState = new Bindable<BeatmapSetFavouriteState>(new BeatmapSetFavouriteState(beatmapSet.HasFavourited, beatmapSet.FavouriteCount));
downloadTracker = new BeatmapDownloadTracker(beatmapSet);
}
[BackgroundDependencyLoader]
@ -73,6 +78,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards
InternalChildren = new Drawable[]
{
downloadTracker,
new Box
{
RelativeSizeAxes = Axes.Both,
@ -270,7 +276,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards
}
}
},
downloadProgressBar = new BeatmapCardDownloadProgressBar(beatmapSet)
downloadProgressBar = new BeatmapCardDownloadProgressBar
{
RelativeSizeAxes = Axes.X,
Height = 6,
@ -314,7 +320,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards
{
base.LoadComplete();
downloadProgressBar.IsActive.BindValueChanged(_ => updateState(), true);
downloadTracker.State.BindValueChanged(_ => updateState(), true);
FinishTransforms(true);
}
@ -367,8 +373,10 @@ namespace osu.Game.Beatmaps.Drawables.Cards
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.FadeTo(downloadProgressBar.IsActive.Value ? 1 : 0, TRANSITION_DURATION, Easing.OutQuint);
bool showProgress = downloadTracker.State.Value == DownloadState.Downloading || downloadTracker.State.Value == DownloadState.Importing;
idleBottomContent.FadeTo(showProgress ? 0 : 1, TRANSITION_DURATION, Easing.OutQuint);
downloadProgressBar.FadeTo(showProgress ? 1 : 0, TRANSITION_DURATION, Easing.OutQuint);
}
}
}

View File

@ -8,37 +8,33 @@ 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 : CompositeDrawable
{
private readonly BindableBool isActive = new BindableBool();
public IBindable<bool> IsActive => isActive;
public override bool IsPresent => true;
private readonly BeatmapDownloadTracker tracker;
private readonly CircularContainer background;
private readonly CircularContainer foreground;
private readonly Box backgroundFill;
private readonly Box foregroundFill;
private readonly Bindable<DownloadState> state = new Bindable<DownloadState>();
private readonly BindableDouble progress = new BindableDouble();
[Resolved]
private OsuColour colours { get; set; }
[Resolved]
private OverlayColourProvider colourProvider { get; set; }
public BeatmapCardDownloadProgressBar(APIBeatmapSet beatmapSet)
public BeatmapCardDownloadProgressBar()
{
InternalChildren = new Drawable[]
{
tracker = new BeatmapDownloadTracker(beatmapSet),
background = new CircularContainer
new CircularContainer
{
RelativeSizeAxes = Axes.Both,
Masking = true,
@ -60,44 +56,40 @@ namespace osu.Game.Beatmaps.Drawables.Cards
}
[BackgroundDependencyLoader]
private void load()
private void load(BeatmapDownloadTracker downloadTracker)
{
backgroundFill.Colour = colourProvider.Background6;
((IBindable<DownloadState>)state).BindTo(downloadTracker.State);
((IBindable<double>)progress).BindTo(downloadTracker.Progress);
}
protected override void LoadComplete()
{
base.LoadComplete();
tracker.State.BindValueChanged(_ => stateChanged(), true);
tracker.Progress.BindValueChanged(_ => progressChanged(), true);
state.BindValueChanged(_ => stateChanged(), true);
progress.BindValueChanged(_ => progressChanged(), true);
}
private void stateChanged()
{
switch (tracker.State.Value)
switch (state.Value)
{
case DownloadState.Downloading:
FinishTransforms(true);
foregroundFill.Colour = colourProvider.Highlight1;
isActive.Value = true;
break;
case DownloadState.Importing:
foregroundFill.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);
foreground.ResizeWidthTo((float)progress.Value, progress.Value > 0 ? BeatmapCard.TRANSITION_DURATION : 0, Easing.OutQuint);
}
}
}

View File

@ -21,7 +21,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
{
protected readonly DownloadIcon Download;
protected readonly PlayIcon Play;
protected readonly BeatmapDownloadTracker Tracker;
protected readonly Bindable<DownloadState> State = new Bindable<DownloadState>();
[Resolved]
private OsuColour colours { get; set; } = null!;
@ -37,27 +37,32 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
InternalChildren = new Drawable[]
{
Tracker = new BeatmapDownloadTracker(beatmapSet),
Download = new DownloadIcon(beatmapSet),
Play = new PlayIcon(beatmapSet)
};
}
[BackgroundDependencyLoader(true)]
private void load(BeatmapDownloadTracker? tracker)
{
if (tracker != null)
((IBindable<DownloadState>)State).BindTo(tracker.State);
}
protected override void LoadComplete()
{
base.LoadComplete();
Tracker.Progress.BindValueChanged(_ => updateState());
Tracker.State.BindValueChanged(_ => updateState(), true);
State.BindValueChanged(_ => updateState(), true);
FinishTransforms(true);
}
private void updateState()
{
Download.FadeTo(Tracker.State.Value != DownloadState.LocallyAvailable ? 1 : 0, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
Download.Enabled.Value = Tracker.State.Value == DownloadState.NotDownloaded;
Download.FadeTo(State.Value != DownloadState.LocallyAvailable ? 1 : 0, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
Download.Enabled.Value = State.Value == DownloadState.NotDownloaded;
Play.FadeTo(Tracker.State.Value == DownloadState.LocallyAvailable ? 1 : 0, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
Play.FadeTo(State.Value == DownloadState.LocallyAvailable ? 1 : 0, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
}
protected class DownloadIcon : BeatmapCardIconButton