mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 13:47:38 +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,
|
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
|
||||||
{
|
{
|
||||||
|
@ -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,93 +13,44 @@ 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
|
|
||||||
{
|
|
||||||
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 BindableBool Dimmed { get; } = new BindableBool();
|
public BindableBool Dimmed { get; } = new BindableBool();
|
||||||
|
|
||||||
private readonly IBeatmapSetOnlineInfo onlineInfo;
|
|
||||||
|
|
||||||
private readonly Box background;
|
private readonly Box background;
|
||||||
private OnlineBeatmapSetCover? cover;
|
private readonly DelayedLoadUnloadWrapper cover;
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private OverlayColourProvider colourProvider { get; set; } = null!;
|
private OverlayColourProvider colourProvider { get; set; } = null!;
|
||||||
|
|
||||||
public BufferedBackground(IBeatmapSetOnlineInfo onlineInfo)
|
public BeatmapCardContentBackground(IBeatmapSetOnlineInfo onlineInfo)
|
||||||
{
|
{
|
||||||
this.onlineInfo = onlineInfo;
|
InternalChildren = new Drawable[]
|
||||||
|
{
|
||||||
RelativeSizeAxes = Axes.Both;
|
background = new Box
|
||||||
InternalChild = background = new Box
|
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
},
|
||||||
|
cover = new DelayedLoadUnloadWrapper(() => createCover(onlineInfo), 500, 500)
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Colour = Colour4.Transparent
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
private static Drawable createCover(IBeatmapSetOnlineInfo onlineInfo) => new OnlineBeatmapSetCover(onlineInfo)
|
||||||
private void load()
|
|
||||||
{
|
|
||||||
background.Colour = colourProvider.Background2;
|
|
||||||
|
|
||||||
LoadComponentAsync(new OnlineBeatmapSetCover(onlineInfo)
|
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
FillMode = FillMode.Fill
|
FillMode = FillMode.Fill
|
||||||
}, loaded =>
|
};
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(OverlayColourProvider colourProvider)
|
||||||
{
|
{
|
||||||
cover = loaded;
|
background.Colour = colourProvider.Background2;
|
||||||
cover.Colour = Colour4.Transparent;
|
|
||||||
AddInternal(cover);
|
|
||||||
FinishTransforms(true);
|
|
||||||
updateState();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
@ -110,16 +60,12 @@ namespace osu.Game.Beatmaps.Drawables.Cards
|
|||||||
FinishTransforms(true);
|
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);
|
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));
|
var gradient = ColourInfo.GradientHorizontal(Colour4.White.Opacity(0), Colour4.White.Opacity(0.2f));
|
||||||
cover.FadeColour(gradient, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
|
cover.FadeColour(gradient, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
|
||||||
}
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user