diff --git a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCard.cs b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCard.cs index b1fe381410..20c5359320 100644 --- a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCard.cs +++ b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCard.cs @@ -94,10 +94,9 @@ namespace osu.Game.Beatmaps.Drawables.Cards Masking = true, Children = new Drawable[] { - mainContentBackground = new BeatmapCardContentBackground + mainContentBackground = new BeatmapCardContentBackground(beatmapSet) { RelativeSizeAxes = Axes.Both, - BeatmapSet = beatmapSet, }, new FillFlowContainer { diff --git a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardContentBackground.cs b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardContentBackground.cs index 88c9d771ac..392f5d1bfa 100644 --- a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardContentBackground.cs +++ b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardContentBackground.cs @@ -3,7 +3,6 @@ #nullable enable -using System; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; @@ -14,112 +13,59 @@ using osu.Game.Overlays; namespace osu.Game.Beatmaps.Drawables.Cards { - public class BeatmapCardContentBackground : ModelBackedDrawable + public class BeatmapCardContentBackground : CompositeDrawable { - public IBeatmapSetOnlineInfo BeatmapSet + public BindableBool Dimmed { get; } = new BindableBool(); + + private readonly Box background; + private readonly DelayedLoadUnloadWrapper cover; + + [Resolved] + private OverlayColourProvider colourProvider { get; set; } = null!; + + public BeatmapCardContentBackground(IBeatmapSetOnlineInfo onlineInfo) { - get => Model; - set => Model = value; + InternalChildren = new Drawable[] + { + background = new Box + { + RelativeSizeAxes = Axes.Both, + }, + cover = new DelayedLoadUnloadWrapper(() => createCover(onlineInfo), 500, 500) + { + RelativeSizeAxes = Axes.Both, + Colour = Colour4.Transparent + } + }; } - public new bool Masking + private static Drawable createCover(IBeatmapSetOnlineInfo onlineInfo) => new OnlineBeatmapSetCover(onlineInfo) { - get => base.Masking; - set => base.Masking = value; - } - - public BindableBool Dimmed { get; private set; } = new BindableBool(); - - protected override double LoadDelay => 500; - - protected override double TransformDuration => 400; + RelativeSizeAxes = Axes.Both, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + FillMode = FillMode.Fill + }; [BackgroundDependencyLoader] private void load(OverlayColourProvider colourProvider) { - InternalChild = new Box - { - RelativeSizeAxes = Axes.Both, - Colour = colourProvider.Background2 - }; + background.Colour = colourProvider.Background2; } - protected override DelayedLoadWrapper CreateDelayedLoadWrapper(Func createContentFunc, double timeBeforeLoad) - => new DelayedLoadUnloadWrapper(createContentFunc, timeBeforeLoad); - - protected override Drawable? CreateDrawable(IBeatmapSetOnlineInfo? model) + protected override void LoadComplete() { - if (model == null) - return null; - - return new BufferedBackground(model) - { - RelativeSizeAxes = Axes.Both, - Dimmed = { BindTarget = Dimmed } - }; + base.LoadComplete(); + Dimmed.BindValueChanged(_ => updateState(), true); + FinishTransforms(true); } - private class BufferedBackground : BufferedContainer + private void updateState() => Schedule(() => { - public BindableBool Dimmed { get; } = new BindableBool(); + background.FadeColour(Dimmed.Value ? colourProvider.Background4 : colourProvider.Background2, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint); - private readonly IBeatmapSetOnlineInfo onlineInfo; - - private readonly Box background; - private OnlineBeatmapSetCover? cover; - - [Resolved] - private OverlayColourProvider colourProvider { get; set; } = null!; - - public BufferedBackground(IBeatmapSetOnlineInfo onlineInfo) - { - this.onlineInfo = onlineInfo; - - RelativeSizeAxes = Axes.Both; - InternalChild = background = new Box - { - RelativeSizeAxes = Axes.Both, - }; - } - - [BackgroundDependencyLoader] - private void load() - { - background.Colour = colourProvider.Background2; - - LoadComponentAsync(new OnlineBeatmapSetCover(onlineInfo) - { - RelativeSizeAxes = Axes.Both, - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - FillMode = FillMode.Fill - }, loaded => - { - cover = loaded; - cover.Colour = Colour4.Transparent; - AddInternal(cover); - FinishTransforms(true); - updateState(); - }); - } - - protected override void LoadComplete() - { - base.LoadComplete(); - Dimmed.BindValueChanged(_ => updateState(), true); - FinishTransforms(true); - } - - private void updateState() - { - if (cover == null) - return; - - background.FadeColour(Dimmed.Value ? colourProvider.Background4 : colourProvider.Background2, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint); - - var gradient = ColourInfo.GradientHorizontal(Colour4.White.Opacity(0), Colour4.White.Opacity(0.2f)); - cover.FadeColour(gradient, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint); - } - } + var gradient = ColourInfo.GradientHorizontal(Colour4.White.Opacity(0), Colour4.White.Opacity(0.2f)); + cover.FadeColour(gradient, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint); + }); } }