mirror of
https://github.com/ppy/osu.git
synced 2025-01-26 18:52:55 +08:00
Restructure card to use single tracker at the top level
This commit is contained in:
parent
be3f225d4b
commit
b58fe2d80a
@ -178,8 +178,7 @@ namespace osu.Game.Tests.Visual.Beatmaps
|
|||||||
|
|
||||||
private class TestDownloadButton : DownloadButton
|
private class TestDownloadButton : DownloadButton
|
||||||
{
|
{
|
||||||
public readonly Bindable<DownloadState> State = new Bindable<DownloadState>();
|
public new Bindable<DownloadState> State => base.State;
|
||||||
public readonly BindableNumber<double> Progress = new BindableNumber<double>();
|
|
||||||
|
|
||||||
public new BeatmapCardIconButton Download => base.Download;
|
public new BeatmapCardIconButton Download => base.Download;
|
||||||
public new BeatmapCardIconButton Play => base.Play;
|
public new BeatmapCardIconButton Play => base.Play;
|
||||||
@ -187,8 +186,6 @@ namespace osu.Game.Tests.Visual.Beatmaps
|
|||||||
public TestDownloadButton(APIBeatmapSet beatmapSet)
|
public TestDownloadButton(APIBeatmapSet beatmapSet)
|
||||||
: base(beatmapSet)
|
: base(beatmapSet)
|
||||||
{
|
{
|
||||||
Tracker.State.BindTo(State);
|
|
||||||
Tracker.Progress.BindTo(Progress);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ using osu.Game.Graphics;
|
|||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
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.Overlays.BeatmapSet;
|
using osu.Game.Overlays.BeatmapSet;
|
||||||
@ -38,6 +39,9 @@ namespace osu.Game.Beatmaps.Drawables.Cards
|
|||||||
private readonly APIBeatmapSet beatmapSet;
|
private readonly APIBeatmapSet beatmapSet;
|
||||||
private readonly Bindable<BeatmapSetFavouriteState> favouriteState;
|
private readonly Bindable<BeatmapSetFavouriteState> favouriteState;
|
||||||
|
|
||||||
|
[Cached]
|
||||||
|
private readonly BeatmapDownloadTracker downloadTracker;
|
||||||
|
|
||||||
private UpdateableOnlineBeatmapSetCover leftCover;
|
private UpdateableOnlineBeatmapSetCover leftCover;
|
||||||
private FillFlowContainer leftIconArea;
|
private FillFlowContainer leftIconArea;
|
||||||
|
|
||||||
@ -61,6 +65,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards
|
|||||||
{
|
{
|
||||||
this.beatmapSet = beatmapSet;
|
this.beatmapSet = beatmapSet;
|
||||||
favouriteState = new Bindable<BeatmapSetFavouriteState>(new BeatmapSetFavouriteState(beatmapSet.HasFavourited, beatmapSet.FavouriteCount));
|
favouriteState = new Bindable<BeatmapSetFavouriteState>(new BeatmapSetFavouriteState(beatmapSet.HasFavourited, beatmapSet.FavouriteCount));
|
||||||
|
downloadTracker = new BeatmapDownloadTracker(beatmapSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
@ -73,6 +78,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards
|
|||||||
|
|
||||||
InternalChildren = new Drawable[]
|
InternalChildren = new Drawable[]
|
||||||
{
|
{
|
||||||
|
downloadTracker,
|
||||||
new Box
|
new Box
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
@ -270,7 +276,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
downloadProgressBar = new BeatmapCardDownloadProgressBar(beatmapSet)
|
downloadProgressBar = new BeatmapCardDownloadProgressBar
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
Height = 6,
|
Height = 6,
|
||||||
@ -314,7 +320,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards
|
|||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
downloadProgressBar.IsActive.BindValueChanged(_ => updateState(), true);
|
downloadTracker.State.BindValueChanged(_ => updateState(), true);
|
||||||
FinishTransforms(true);
|
FinishTransforms(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -367,8 +373,10 @@ namespace osu.Game.Beatmaps.Drawables.Cards
|
|||||||
statisticsContainer.FadeTo(IsHovered ? 1 : 0, TRANSITION_DURATION, Easing.OutQuint);
|
statisticsContainer.FadeTo(IsHovered ? 1 : 0, TRANSITION_DURATION, Easing.OutQuint);
|
||||||
rightButtonArea.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);
|
bool showProgress = downloadTracker.State.Value == DownloadState.Downloading || downloadTracker.State.Value == DownloadState.Importing;
|
||||||
downloadProgressBar.FadeTo(downloadProgressBar.IsActive.Value ? 1 : 0, TRANSITION_DURATION, Easing.OutQuint);
|
|
||||||
|
idleBottomContent.FadeTo(showProgress ? 0 : 1, TRANSITION_DURATION, Easing.OutQuint);
|
||||||
|
downloadProgressBar.FadeTo(showProgress ? 1 : 0, TRANSITION_DURATION, Easing.OutQuint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,37 +8,33 @@ using osu.Framework.Graphics.Containers;
|
|||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Online;
|
using osu.Game.Online;
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
|
|
||||||
namespace osu.Game.Beatmaps.Drawables.Cards
|
namespace osu.Game.Beatmaps.Drawables.Cards
|
||||||
{
|
{
|
||||||
public class BeatmapCardDownloadProgressBar : CompositeDrawable
|
public class BeatmapCardDownloadProgressBar : CompositeDrawable
|
||||||
{
|
{
|
||||||
private readonly BindableBool isActive = new BindableBool();
|
|
||||||
public IBindable<bool> IsActive => isActive;
|
|
||||||
|
|
||||||
public override bool IsPresent => true;
|
public override bool IsPresent => true;
|
||||||
|
|
||||||
private readonly BeatmapDownloadTracker tracker;
|
|
||||||
private readonly CircularContainer background;
|
|
||||||
private readonly CircularContainer foreground;
|
private readonly CircularContainer foreground;
|
||||||
|
|
||||||
private readonly Box backgroundFill;
|
private readonly Box backgroundFill;
|
||||||
private readonly Box foregroundFill;
|
private readonly Box foregroundFill;
|
||||||
|
|
||||||
|
private readonly Bindable<DownloadState> state = new Bindable<DownloadState>();
|
||||||
|
private readonly BindableDouble progress = new BindableDouble();
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private OsuColour colours { get; set; }
|
private OsuColour colours { get; set; }
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private OverlayColourProvider colourProvider { get; set; }
|
private OverlayColourProvider colourProvider { get; set; }
|
||||||
|
|
||||||
public BeatmapCardDownloadProgressBar(APIBeatmapSet beatmapSet)
|
public BeatmapCardDownloadProgressBar()
|
||||||
{
|
{
|
||||||
InternalChildren = new Drawable[]
|
InternalChildren = new Drawable[]
|
||||||
{
|
{
|
||||||
tracker = new BeatmapDownloadTracker(beatmapSet),
|
new CircularContainer
|
||||||
background = new CircularContainer
|
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Masking = true,
|
Masking = true,
|
||||||
@ -60,44 +56,40 @@ namespace osu.Game.Beatmaps.Drawables.Cards
|
|||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load(BeatmapDownloadTracker downloadTracker)
|
||||||
{
|
{
|
||||||
backgroundFill.Colour = colourProvider.Background6;
|
backgroundFill.Colour = colourProvider.Background6;
|
||||||
|
|
||||||
|
((IBindable<DownloadState>)state).BindTo(downloadTracker.State);
|
||||||
|
((IBindable<double>)progress).BindTo(downloadTracker.Progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
tracker.State.BindValueChanged(_ => stateChanged(), true);
|
state.BindValueChanged(_ => stateChanged(), true);
|
||||||
tracker.Progress.BindValueChanged(_ => progressChanged(), true);
|
progress.BindValueChanged(_ => progressChanged(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stateChanged()
|
private void stateChanged()
|
||||||
{
|
{
|
||||||
switch (tracker.State.Value)
|
switch (state.Value)
|
||||||
{
|
{
|
||||||
case DownloadState.Downloading:
|
case DownloadState.Downloading:
|
||||||
FinishTransforms(true);
|
FinishTransforms(true);
|
||||||
foregroundFill.Colour = colourProvider.Highlight1;
|
foregroundFill.Colour = colourProvider.Highlight1;
|
||||||
isActive.Value = true;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DownloadState.Importing:
|
case DownloadState.Importing:
|
||||||
foregroundFill.FadeColour(colours.Yellow, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
|
foregroundFill.FadeColour(colours.Yellow, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
|
||||||
isActive.Value = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
isActive.Value = false;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void progressChanged()
|
private void progressChanged()
|
||||||
{
|
{
|
||||||
double progress = tracker.Progress.Value;
|
foreground.ResizeWidthTo((float)progress.Value, progress.Value > 0 ? BeatmapCard.TRANSITION_DURATION : 0, Easing.OutQuint);
|
||||||
foreground.ResizeWidthTo((float)progress, progress > 0 ? BeatmapCard.TRANSITION_DURATION : 0, Easing.OutQuint);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
|
|||||||
{
|
{
|
||||||
protected readonly DownloadIcon Download;
|
protected readonly DownloadIcon Download;
|
||||||
protected readonly PlayIcon Play;
|
protected readonly PlayIcon Play;
|
||||||
protected readonly BeatmapDownloadTracker Tracker;
|
protected readonly Bindable<DownloadState> State = new Bindable<DownloadState>();
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private OsuColour colours { get; set; } = null!;
|
private OsuColour colours { get; set; } = null!;
|
||||||
@ -37,27 +37,32 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
|
|||||||
|
|
||||||
InternalChildren = new Drawable[]
|
InternalChildren = new Drawable[]
|
||||||
{
|
{
|
||||||
Tracker = new BeatmapDownloadTracker(beatmapSet),
|
|
||||||
Download = new DownloadIcon(beatmapSet),
|
Download = new DownloadIcon(beatmapSet),
|
||||||
Play = new PlayIcon(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()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
Tracker.Progress.BindValueChanged(_ => updateState());
|
State.BindValueChanged(_ => updateState(), true);
|
||||||
Tracker.State.BindValueChanged(_ => updateState(), true);
|
|
||||||
FinishTransforms(true);
|
FinishTransforms(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateState()
|
private void updateState()
|
||||||
{
|
{
|
||||||
Download.FadeTo(Tracker.State.Value != DownloadState.LocallyAvailable ? 1 : 0, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
|
Download.FadeTo(State.Value != DownloadState.LocallyAvailable ? 1 : 0, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
|
||||||
Download.Enabled.Value = Tracker.State.Value == DownloadState.NotDownloaded;
|
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
|
protected class DownloadIcon : BeatmapCardIconButton
|
||||||
|
Loading…
Reference in New Issue
Block a user