1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 11:07:52 +08:00

Merge pull request #11821 from peppy/fix-carousel-border-additive-alplha

Fix carousel items' borders getting blown out when selected and hovered
This commit is contained in:
Dan Balasescu 2021-02-18 17:45:58 +09:00 committed by GitHub
commit 46b67dd7bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,8 +25,13 @@ namespace osu.Game.Screens.Select.Carousel
public readonly Bindable<CarouselItemState> State = new Bindable<CarouselItemState>(CarouselItemState.NotSelected); public readonly Bindable<CarouselItemState> State = new Bindable<CarouselItemState>(CarouselItemState.NotSelected);
private readonly HoverLayer hoverLayer;
protected override Container<Drawable> Content { get; } = new Container { RelativeSizeAxes = Axes.Both }; protected override Container<Drawable> Content { get; } = new Container { RelativeSizeAxes = Axes.Both };
private const float corner_radius = 10;
private const float border_thickness = 2.5f;
public CarouselHeader() public CarouselHeader()
{ {
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
@ -36,12 +41,12 @@ namespace osu.Game.Screens.Select.Carousel
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Masking = true, Masking = true,
CornerRadius = 10, CornerRadius = corner_radius,
BorderColour = new Color4(221, 255, 255, 255), BorderColour = new Color4(221, 255, 255, 255),
Children = new Drawable[] Children = new Drawable[]
{ {
Content, Content,
new HoverLayer() hoverLayer = new HoverLayer()
} }
}; };
} }
@ -59,6 +64,8 @@ namespace osu.Game.Screens.Select.Carousel
{ {
case CarouselItemState.Collapsed: case CarouselItemState.Collapsed:
case CarouselItemState.NotSelected: case CarouselItemState.NotSelected:
hoverLayer.InsetForBorder = false;
BorderContainer.BorderThickness = 0; BorderContainer.BorderThickness = 0;
BorderContainer.EdgeEffect = new EdgeEffectParameters BorderContainer.EdgeEffect = new EdgeEffectParameters
{ {
@ -70,7 +77,9 @@ namespace osu.Game.Screens.Select.Carousel
break; break;
case CarouselItemState.Selected: case CarouselItemState.Selected:
BorderContainer.BorderThickness = 2.5f; hoverLayer.InsetForBorder = true;
BorderContainer.BorderThickness = border_thickness;
BorderContainer.EdgeEffect = new EdgeEffectParameters BorderContainer.EdgeEffect = new EdgeEffectParameters
{ {
Type = EdgeEffectType.Glow, Type = EdgeEffectType.Glow,
@ -107,6 +116,26 @@ namespace osu.Game.Screens.Select.Carousel
sampleHover = audio.Samples.Get("SongSelect/song-ping"); sampleHover = audio.Samples.Get("SongSelect/song-ping");
} }
public bool InsetForBorder
{
set
{
if (value)
{
// apply same border as above to avoid applying additive overlay to it (and blowing out the colour).
Masking = true;
CornerRadius = corner_radius;
BorderThickness = border_thickness;
}
else
{
BorderThickness = 0;
CornerRadius = 0;
Masking = false;
}
}
}
protected override bool OnHover(HoverEvent e) protected override bool OnHover(HoverEvent e)
{ {
box.FadeIn(100, Easing.OutQuint); box.FadeIn(100, Easing.OutQuint);