1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-23 16:47:26 +08:00
osu-lazer/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardContentBackground.cs

72 lines
2.4 KiB
C#
Raw Normal View History

// 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.
#nullable enable
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Overlays;
namespace osu.Game.Beatmaps.Drawables.Cards
{
2021-11-03 07:07:03 +08:00
public class BeatmapCardContentBackground : CompositeDrawable
{
2021-11-03 07:07:03 +08:00
public BindableBool Dimmed { get; } = new BindableBool();
2021-11-03 07:07:03 +08:00
private readonly Box background;
private readonly DelayedLoadUnloadWrapper cover;
2021-11-03 07:07:03 +08:00
[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;
2021-11-03 07:07:03 +08:00
public BeatmapCardContentBackground(IBeatmapSetOnlineInfo onlineInfo)
{
2021-11-03 07:07:03 +08:00
InternalChildren = new Drawable[]
{
2021-11-03 07:07:03 +08:00
background = new Box
{
RelativeSizeAxes = Axes.Both,
},
cover = new DelayedLoadUnloadWrapper(() => createCover(onlineInfo), 500, 500)
{
RelativeSizeAxes = Axes.Both,
Colour = Colour4.Transparent
}
};
}
2021-11-03 07:07:03 +08:00
private static Drawable createCover(IBeatmapSetOnlineInfo onlineInfo) => new OnlineBeatmapSetCover(onlineInfo)
{
2021-11-03 07:07:03 +08:00
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
FillMode = FillMode.Fill
};
2021-11-03 07:07:03 +08:00
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
background.Colour = colourProvider.Background2;
}
2021-11-03 07:07:03 +08:00
protected override void LoadComplete()
{
2021-11-03 07:07:03 +08:00
base.LoadComplete();
Dimmed.BindValueChanged(_ => updateState(), true);
FinishTransforms(true);
}
2021-11-03 07:07:03 +08:00
private void updateState() => Schedule(() =>
{
background.FadeColour(Dimmed.Value ? colourProvider.Background4 : colourProvider.Background2, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
2021-11-03 07:07:03 +08:00
var gradient = ColourInfo.GradientHorizontal(Colour4.White.Opacity(0), Colour4.White.Opacity(0.2f));
cover.FadeColour(gradient, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
});
}
}