2020-10-13 06:19:32 +00:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
using osu.Framework.Audio.Sample;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Effects;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
using osu.Framework.Utils;
|
|
|
|
using osu.Game.Graphics;
|
2021-02-12 03:14:57 +00:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2020-10-13 06:19:32 +00:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Select.Carousel
|
|
|
|
{
|
|
|
|
public class CarouselHeader : Container
|
|
|
|
{
|
|
|
|
public Container BorderContainer;
|
|
|
|
|
|
|
|
public readonly Bindable<CarouselItemState> State = new Bindable<CarouselItemState>(CarouselItemState.NotSelected);
|
2021-02-18 07:59:43 +00:00
|
|
|
private HoverLayer hoverLayer;
|
2020-10-13 06:19:32 +00:00
|
|
|
|
|
|
|
protected override Container<Drawable> Content { get; } = new Container { RelativeSizeAxes = Axes.Both };
|
|
|
|
|
2021-02-18 07:59:43 +00:00
|
|
|
private const float corner_radius = 10;
|
|
|
|
private const float border_thickness = 2.5f;
|
|
|
|
|
2020-10-13 06:19:32 +00:00
|
|
|
public CarouselHeader()
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
Height = DrawableCarouselItem.MAX_HEIGHT;
|
|
|
|
|
|
|
|
InternalChild = BorderContainer = new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Masking = true,
|
2021-02-18 07:59:43 +00:00
|
|
|
CornerRadius = corner_radius,
|
2020-10-13 06:19:32 +00:00
|
|
|
BorderColour = new Color4(221, 255, 255, 255),
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
Content,
|
2021-02-18 07:59:43 +00:00
|
|
|
hoverLayer = new HoverLayer()
|
2020-10-13 06:19:32 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
State.BindValueChanged(updateState, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateState(ValueChangedEvent<CarouselItemState> state)
|
|
|
|
{
|
|
|
|
switch (state.NewValue)
|
|
|
|
{
|
|
|
|
case CarouselItemState.Collapsed:
|
|
|
|
case CarouselItemState.NotSelected:
|
2021-02-18 07:59:43 +00:00
|
|
|
hoverLayer.InsetForBorder = false;
|
|
|
|
|
2020-10-13 06:19:32 +00:00
|
|
|
BorderContainer.BorderThickness = 0;
|
|
|
|
BorderContainer.EdgeEffect = new EdgeEffectParameters
|
|
|
|
{
|
2020-10-13 11:50:36 +00:00
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
Offset = new Vector2(1),
|
|
|
|
Radius = 10,
|
|
|
|
Colour = Color4.Black.Opacity(100),
|
2020-10-13 06:19:32 +00:00
|
|
|
};
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CarouselItemState.Selected:
|
2021-02-18 07:59:43 +00:00
|
|
|
hoverLayer.InsetForBorder = true;
|
|
|
|
|
|
|
|
BorderContainer.BorderThickness = border_thickness;
|
2020-10-13 06:19:32 +00:00
|
|
|
BorderContainer.EdgeEffect = new EdgeEffectParameters
|
|
|
|
{
|
2020-10-13 11:50:36 +00:00
|
|
|
Type = EdgeEffectType.Glow,
|
|
|
|
Colour = new Color4(130, 204, 255, 150),
|
|
|
|
Radius = 20,
|
|
|
|
Roundness = 10,
|
2020-10-13 06:19:32 +00:00
|
|
|
};
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-12 03:14:57 +00:00
|
|
|
public class HoverLayer : HoverSampleDebounceComponent
|
2020-10-13 06:19:32 +00:00
|
|
|
{
|
2021-02-12 08:22:15 +00:00
|
|
|
private Sample sampleHover;
|
2020-10-13 06:19:32 +00:00
|
|
|
|
2021-02-12 03:14:57 +00:00
|
|
|
private Box box;
|
2020-10-13 06:19:32 +00:00
|
|
|
|
2021-02-12 03:14:57 +00:00
|
|
|
public HoverLayer()
|
2021-01-15 11:16:22 +00:00
|
|
|
{
|
2021-02-12 03:14:57 +00:00
|
|
|
RelativeSizeAxes = Axes.Both;
|
2021-01-15 11:16:22 +00:00
|
|
|
}
|
2020-10-13 06:19:32 +00:00
|
|
|
|
2021-02-12 03:14:57 +00:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(AudioManager audio, OsuColour colours)
|
|
|
|
{
|
|
|
|
InternalChild = box = new Box
|
|
|
|
{
|
|
|
|
Colour = colours.Blue.Opacity(0.1f),
|
|
|
|
Alpha = 0,
|
|
|
|
Blending = BlendingParameters.Additive,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
};
|
2020-10-13 06:19:32 +00:00
|
|
|
|
2021-02-12 03:14:57 +00:00
|
|
|
sampleHover = audio.Samples.Get("SongSelect/song-ping");
|
|
|
|
}
|
|
|
|
|
2021-02-18 07:59:43 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-12 03:14:57 +00:00
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
|
|
|
box.FadeIn(100, Easing.OutQuint);
|
|
|
|
return base.OnHover(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
|
|
|
box.FadeOut(1000, Easing.OutQuint);
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void PlayHoverSample()
|
|
|
|
{
|
|
|
|
if (sampleHover == null) return;
|
|
|
|
|
|
|
|
sampleHover.Frequency.Value = 0.90 + RNG.NextDouble(0.2);
|
|
|
|
sampleHover.Play();
|
|
|
|
}
|
2020-10-13 06:19:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|