1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 19:22:56 +08:00

Rewrite BeatmapCardContentBackground

This commit is contained in:
Bartłomiej Dach 2021-11-03 00:07:03 +01:00
parent f671ee28c5
commit 75e89f17ad
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
2 changed files with 39 additions and 94 deletions

View File

@ -94,10 +94,9 @@ namespace osu.Game.Beatmaps.Drawables.Cards
Masking = true, Masking = true,
Children = new Drawable[] Children = new Drawable[]
{ {
mainContentBackground = new BeatmapCardContentBackground mainContentBackground = new BeatmapCardContentBackground(beatmapSet)
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
BeatmapSet = beatmapSet,
}, },
new FillFlowContainer new FillFlowContainer
{ {

View File

@ -3,7 +3,6 @@
#nullable enable #nullable enable
using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -14,112 +13,59 @@ using osu.Game.Overlays;
namespace osu.Game.Beatmaps.Drawables.Cards namespace osu.Game.Beatmaps.Drawables.Cards
{ {
public class BeatmapCardContentBackground : ModelBackedDrawable<IBeatmapSetOnlineInfo> 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; InternalChildren = new Drawable[]
set => Model = value; {
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; RelativeSizeAxes = Axes.Both,
set => base.Masking = value; Anchor = Anchor.Centre,
} Origin = Anchor.Centre,
FillMode = FillMode.Fill
public BindableBool Dimmed { get; private set; } = new BindableBool(); };
protected override double LoadDelay => 500;
protected override double TransformDuration => 400;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider) private void load(OverlayColourProvider colourProvider)
{ {
InternalChild = new Box background.Colour = colourProvider.Background2;
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background2
};
} }
protected override DelayedLoadWrapper CreateDelayedLoadWrapper(Func<Drawable> createContentFunc, double timeBeforeLoad) protected override void LoadComplete()
=> new DelayedLoadUnloadWrapper(createContentFunc, timeBeforeLoad);
protected override Drawable? CreateDrawable(IBeatmapSetOnlineInfo? model)
{ {
if (model == null) base.LoadComplete();
return null; Dimmed.BindValueChanged(_ => updateState(), true);
FinishTransforms(true);
return new BufferedBackground(model)
{
RelativeSizeAxes = Axes.Both,
Dimmed = { BindTarget = Dimmed }
};
} }
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; var gradient = ColourInfo.GradientHorizontal(Colour4.White.Opacity(0), Colour4.White.Opacity(0.2f));
cover.FadeColour(gradient, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
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);
}
}
} }
} }