diff --git a/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapCardDownloadButton.cs b/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapCardDownloadButton.cs index d93209efe9..068d2bdcbd 100644 --- a/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapCardDownloadButton.cs +++ b/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapCardDownloadButton.cs @@ -1,14 +1,12 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System; using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Game.Beatmaps; using osu.Game.Beatmaps.Drawables.Cards.Buttons; using osu.Game.Configuration; -using osu.Game.Online; using osu.Game.Online.API.Requests.Responses; using osu.Game.Overlays; using osu.Game.Resources.Localisation.Web; @@ -54,22 +52,11 @@ namespace osu.Game.Tests.Visual.Beatmaps { AddStep("create button", () => { - var beatmapSet = downloadable ? getDownloadableBeatmapSet(hasVideo) : getUndownloadableBeatmapSet(); - var downloadTracker = new BeatmapDownloadTracker(beatmapSet); - - Child = new DependencyProvidingContainer + Child = downloadButton = new DownloadButton(downloadable ? getDownloadableBeatmapSet(hasVideo) : getUndownloadableBeatmapSet()) { - RelativeSizeAxes = Axes.Both, - CachedDependencies = new (Type, object)[] - { - (typeof(BeatmapDownloadTracker), downloadTracker) - }, - Child = downloadButton = new DownloadButton(downloadable ? getDownloadableBeatmapSet(hasVideo) : getUndownloadableBeatmapSet()) - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Scale = new Vector2(2) - } + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Scale = new Vector2(2) }; }); } diff --git a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCard.cs b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCard.cs index 48f8e7b9c5..b55fb91e92 100644 --- a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCard.cs +++ b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCard.cs @@ -141,12 +141,14 @@ namespace osu.Game.Beatmaps.Drawables.Cards new DownloadButton(beatmapSet) { Anchor = Anchor.BottomCentre, - Origin = Anchor.BottomCentre + Origin = Anchor.BottomCentre, + State = { BindTarget = downloadTracker.State } }, new GoToBeatmapButton(beatmapSet) { Anchor = Anchor.BottomCentre, - Origin = Anchor.BottomCentre + Origin = Anchor.BottomCentre, + State = { BindTarget = downloadTracker.State } } } } @@ -307,7 +309,9 @@ namespace osu.Game.Beatmaps.Drawables.Cards RelativeSizeAxes = Axes.X, Height = 6, Anchor = Anchor.Centre, - Origin = Anchor.Centre + Origin = Anchor.Centre, + State = { BindTarget = downloadTracker.State }, + Progress = { BindTarget = downloadTracker.Progress } } } } diff --git a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardDownloadProgressBar.cs b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardDownloadProgressBar.cs index a94900b0c7..ffb4e0c540 100644 --- a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardDownloadProgressBar.cs +++ b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardDownloadProgressBar.cs @@ -14,6 +14,12 @@ namespace osu.Game.Beatmaps.Drawables.Cards { public class BeatmapCardDownloadProgressBar : CompositeDrawable { + public IBindable State => state; + private readonly Bindable state = new Bindable(); + + public IBindable Progress => progress; + private readonly BindableDouble progress = new BindableDouble(); + public override bool IsPresent => true; private readonly CircularContainer foreground; @@ -21,9 +27,6 @@ namespace osu.Game.Beatmaps.Drawables.Cards private readonly Box backgroundFill; private readonly Box foregroundFill; - private readonly Bindable state = new Bindable(); - private readonly BindableDouble progress = new BindableDouble(); - [Resolved] private OsuColour colours { get; set; } @@ -56,12 +59,9 @@ namespace osu.Game.Beatmaps.Drawables.Cards } [BackgroundDependencyLoader] - private void load(BeatmapDownloadTracker downloadTracker) + private void load() { backgroundFill.Colour = colourProvider.Background6; - - ((IBindable)state).BindTo(downloadTracker.State); - ((IBindable)progress).BindTo(downloadTracker.Progress); } protected override void LoadComplete() diff --git a/osu.Game/Beatmaps/Drawables/Cards/Buttons/DownloadButton.cs b/osu.Game/Beatmaps/Drawables/Cards/Buttons/DownloadButton.cs index 325181598d..7430fce1c8 100644 --- a/osu.Game/Beatmaps/Drawables/Cards/Buttons/DownloadButton.cs +++ b/osu.Game/Beatmaps/Drawables/Cards/Buttons/DownloadButton.cs @@ -16,8 +16,10 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons { public class DownloadButton : BeatmapCardIconButton { + public IBindable State => state; + private readonly Bindable state = new Bindable(); + private readonly APIBeatmapSet beatmapSet; - private readonly Bindable downloadState = new Bindable(); private Bindable preferNoVideo = null!; @@ -32,23 +34,22 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons } [BackgroundDependencyLoader] - private void load(OsuConfigManager config, BeatmapDownloadTracker downloadTracker) + private void load(OsuConfigManager config) { preferNoVideo = config.GetBindable(OsuSetting.PreferNoVideo); - ((IBindable)downloadState).BindTo(downloadTracker.State); } protected override void LoadComplete() { base.LoadComplete(); preferNoVideo.BindValueChanged(_ => updateState()); - downloadState.BindValueChanged(_ => updateState(), true); + state.BindValueChanged(_ => updateState(), true); FinishTransforms(true); } private void updateState() { - this.FadeTo(downloadState.Value != DownloadState.LocallyAvailable ? 1 : 0, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint); + this.FadeTo(state.Value != DownloadState.LocallyAvailable ? 1 : 0, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint); if (beatmapSet.Availability.DownloadDisabled) { diff --git a/osu.Game/Beatmaps/Drawables/Cards/Buttons/GoToBeatmapButton.cs b/osu.Game/Beatmaps/Drawables/Cards/Buttons/GoToBeatmapButton.cs index 793c02d9c4..9a6a3c01b7 100644 --- a/osu.Game/Beatmaps/Drawables/Cards/Buttons/GoToBeatmapButton.cs +++ b/osu.Game/Beatmaps/Drawables/Cards/Buttons/GoToBeatmapButton.cs @@ -14,8 +14,10 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons { public class GoToBeatmapButton : BeatmapCardIconButton { + public IBindable State => state; + private readonly Bindable state = new Bindable(); + private readonly APIBeatmapSet beatmapSet; - private readonly Bindable downloadState = new Bindable(); public GoToBeatmapButton(APIBeatmapSet beatmapSet) { @@ -26,24 +28,22 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons } [BackgroundDependencyLoader(true)] - private void load(OsuGame? game, BeatmapDownloadTracker downloadTracker) + private void load(OsuGame? game) { Action = () => game?.PresentBeatmap(beatmapSet); - - ((IBindable)downloadState).BindTo(downloadTracker.State); } protected override void LoadComplete() { base.LoadComplete(); - downloadState.BindValueChanged(_ => updateState(), true); + state.BindValueChanged(_ => updateState(), true); FinishTransforms(true); } private void updateState() { - this.FadeTo(downloadState.Value == DownloadState.LocallyAvailable ? 1 : 0, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint); + this.FadeTo(state.Value == DownloadState.LocallyAvailable ? 1 : 0, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint); } } }