1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 10:47:28 +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,
Children = new Drawable[]
{
mainContentBackground = new BeatmapCardContentBackground
mainContentBackground = new BeatmapCardContentBackground(beatmapSet)
{
RelativeSizeAxes = Axes.Both,
BeatmapSet = beatmapSet,
},
new FillFlowContainer
{

View File

@ -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<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;
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<Drawable> 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);
});
}
}