1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-27 17:53:15 +08:00

Use BindTarget from card rather than caching & resolving download tracker

This commit is contained in:
Bartłomiej Dach 2021-11-20 18:45:24 +01:00
parent b3606f4a21
commit 297de27a6a
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
5 changed files with 30 additions and 38 deletions

View File

@ -1,14 +1,12 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables.Cards.Buttons; using osu.Game.Beatmaps.Drawables.Cards.Buttons;
using osu.Game.Configuration; using osu.Game.Configuration;
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.Resources.Localisation.Web; using osu.Game.Resources.Localisation.Web;
@ -54,22 +52,11 @@ namespace osu.Game.Tests.Visual.Beatmaps
{ {
AddStep("create button", () => AddStep("create button", () =>
{ {
var beatmapSet = downloadable ? getDownloadableBeatmapSet(hasVideo) : getUndownloadableBeatmapSet(); Child = downloadButton = new DownloadButton(downloadable ? getDownloadableBeatmapSet(hasVideo) : getUndownloadableBeatmapSet())
var downloadTracker = new BeatmapDownloadTracker(beatmapSet);
Child = new DependencyProvidingContainer
{ {
RelativeSizeAxes = Axes.Both, Anchor = Anchor.Centre,
CachedDependencies = new (Type, object)[] Origin = Anchor.Centre,
{ Scale = new Vector2(2)
(typeof(BeatmapDownloadTracker), downloadTracker)
},
Child = downloadButton = new DownloadButton(downloadable ? getDownloadableBeatmapSet(hasVideo) : getUndownloadableBeatmapSet())
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(2)
}
}; };
}); });
} }

View File

@ -141,12 +141,14 @@ namespace osu.Game.Beatmaps.Drawables.Cards
new DownloadButton(beatmapSet) new DownloadButton(beatmapSet)
{ {
Anchor = Anchor.BottomCentre, Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre Origin = Anchor.BottomCentre,
State = { BindTarget = downloadTracker.State }
}, },
new GoToBeatmapButton(beatmapSet) new GoToBeatmapButton(beatmapSet)
{ {
Anchor = Anchor.BottomCentre, 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, RelativeSizeAxes = Axes.X,
Height = 6, Height = 6,
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre Origin = Anchor.Centre,
State = { BindTarget = downloadTracker.State },
Progress = { BindTarget = downloadTracker.Progress }
} }
} }
} }

View File

@ -14,6 +14,12 @@ namespace osu.Game.Beatmaps.Drawables.Cards
{ {
public class BeatmapCardDownloadProgressBar : CompositeDrawable public class BeatmapCardDownloadProgressBar : CompositeDrawable
{ {
public IBindable<DownloadState> State => state;
private readonly Bindable<DownloadState> state = new Bindable<DownloadState>();
public IBindable<double> Progress => progress;
private readonly BindableDouble progress = new BindableDouble();
public override bool IsPresent => true; public override bool IsPresent => true;
private readonly CircularContainer foreground; private readonly CircularContainer foreground;
@ -21,9 +27,6 @@ namespace osu.Game.Beatmaps.Drawables.Cards
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; }
@ -56,12 +59,9 @@ namespace osu.Game.Beatmaps.Drawables.Cards
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(BeatmapDownloadTracker downloadTracker) private void load()
{ {
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()

View File

@ -16,8 +16,10 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
{ {
public class DownloadButton : BeatmapCardIconButton public class DownloadButton : BeatmapCardIconButton
{ {
public IBindable<DownloadState> State => state;
private readonly Bindable<DownloadState> state = new Bindable<DownloadState>();
private readonly APIBeatmapSet beatmapSet; private readonly APIBeatmapSet beatmapSet;
private readonly Bindable<DownloadState> downloadState = new Bindable<DownloadState>();
private Bindable<bool> preferNoVideo = null!; private Bindable<bool> preferNoVideo = null!;
@ -32,23 +34,22 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuConfigManager config, BeatmapDownloadTracker downloadTracker) private void load(OsuConfigManager config)
{ {
preferNoVideo = config.GetBindable<bool>(OsuSetting.PreferNoVideo); preferNoVideo = config.GetBindable<bool>(OsuSetting.PreferNoVideo);
((IBindable<DownloadState>)downloadState).BindTo(downloadTracker.State);
} }
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
preferNoVideo.BindValueChanged(_ => updateState()); preferNoVideo.BindValueChanged(_ => updateState());
downloadState.BindValueChanged(_ => updateState(), true); state.BindValueChanged(_ => updateState(), true);
FinishTransforms(true); FinishTransforms(true);
} }
private void updateState() 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) if (beatmapSet.Availability.DownloadDisabled)
{ {

View File

@ -14,8 +14,10 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
{ {
public class GoToBeatmapButton : BeatmapCardIconButton public class GoToBeatmapButton : BeatmapCardIconButton
{ {
public IBindable<DownloadState> State => state;
private readonly Bindable<DownloadState> state = new Bindable<DownloadState>();
private readonly APIBeatmapSet beatmapSet; private readonly APIBeatmapSet beatmapSet;
private readonly Bindable<DownloadState> downloadState = new Bindable<DownloadState>();
public GoToBeatmapButton(APIBeatmapSet beatmapSet) public GoToBeatmapButton(APIBeatmapSet beatmapSet)
{ {
@ -26,24 +28,22 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
} }
[BackgroundDependencyLoader(true)] [BackgroundDependencyLoader(true)]
private void load(OsuGame? game, BeatmapDownloadTracker downloadTracker) private void load(OsuGame? game)
{ {
Action = () => game?.PresentBeatmap(beatmapSet); Action = () => game?.PresentBeatmap(beatmapSet);
((IBindable<DownloadState>)downloadState).BindTo(downloadTracker.State);
} }
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
downloadState.BindValueChanged(_ => updateState(), true); state.BindValueChanged(_ => updateState(), true);
FinishTransforms(true); FinishTransforms(true);
} }
private void updateState() 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);
} }
} }
} }