mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 10:47:28 +08:00
Rewrite BeatmapCardContentBackground
This commit is contained in:
parent
f671ee28c5
commit
75e89f17ad
@ -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
|
||||
{
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
@ -14,93 +13,44 @@ using osu.Game.Overlays;
|
||||
|
||||
namespace osu.Game.Beatmaps.Drawables.Cards
|
||||
{
|
||||
public class BeatmapCardContentBackground : ModelBackedDrawable<IBeatmapSetOnlineInfo>
|
||||
{
|
||||
public IBeatmapSetOnlineInfo BeatmapSet
|
||||
{
|
||||
get => Model;
|
||||
set => Model = value;
|
||||
}
|
||||
|
||||
public new bool Masking
|
||||
{
|
||||
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;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OverlayColourProvider colourProvider)
|
||||
{
|
||||
InternalChild = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = colourProvider.Background2
|
||||
};
|
||||
}
|
||||
|
||||
protected override DelayedLoadWrapper CreateDelayedLoadWrapper(Func<Drawable> createContentFunc, double timeBeforeLoad)
|
||||
=> new DelayedLoadUnloadWrapper(createContentFunc, timeBeforeLoad);
|
||||
|
||||
protected override Drawable? CreateDrawable(IBeatmapSetOnlineInfo? model)
|
||||
{
|
||||
if (model == null)
|
||||
return null;
|
||||
|
||||
return new BufferedBackground(model)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Dimmed = { BindTarget = Dimmed }
|
||||
};
|
||||
}
|
||||
|
||||
private class BufferedBackground : BufferedContainer
|
||||
public class BeatmapCardContentBackground : CompositeDrawable
|
||||
{
|
||||
public BindableBool Dimmed { get; } = new BindableBool();
|
||||
|
||||
private readonly IBeatmapSetOnlineInfo onlineInfo;
|
||||
|
||||
private readonly Box background;
|
||||
private OnlineBeatmapSetCover? cover;
|
||||
private readonly DelayedLoadUnloadWrapper cover;
|
||||
|
||||
[Resolved]
|
||||
private OverlayColourProvider colourProvider { get; set; } = null!;
|
||||
|
||||
public BufferedBackground(IBeatmapSetOnlineInfo onlineInfo)
|
||||
public BeatmapCardContentBackground(IBeatmapSetOnlineInfo onlineInfo)
|
||||
{
|
||||
this.onlineInfo = onlineInfo;
|
||||
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
InternalChild = background = new Box
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
background = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
cover = new DelayedLoadUnloadWrapper(() => createCover(onlineInfo), 500, 500)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Colour4.Transparent
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
background.Colour = colourProvider.Background2;
|
||||
|
||||
LoadComponentAsync(new OnlineBeatmapSetCover(onlineInfo)
|
||||
private static Drawable createCover(IBeatmapSetOnlineInfo onlineInfo) => new OnlineBeatmapSetCover(onlineInfo)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
FillMode = FillMode.Fill
|
||||
}, loaded =>
|
||||
};
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OverlayColourProvider colourProvider)
|
||||
{
|
||||
cover = loaded;
|
||||
cover.Colour = Colour4.Transparent;
|
||||
AddInternal(cover);
|
||||
FinishTransforms(true);
|
||||
updateState();
|
||||
});
|
||||
background.Colour = colourProvider.Background2;
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
@ -110,16 +60,12 @@ namespace osu.Game.Beatmaps.Drawables.Cards
|
||||
FinishTransforms(true);
|
||||
}
|
||||
|
||||
private void updateState()
|
||||
private void updateState() => Schedule(() =>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user