// Copyright (c) ppy Pty Ltd . 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; using osu.Game.Graphics.UserInterface; using osuTK; using osuTK.Graphics; namespace osu.Game.Screens.Select.Carousel { public class CarouselHeader : Container { public Container BorderContainer; public readonly Bindable State = new Bindable(CarouselItemState.NotSelected); protected override Container Content { get; } = new Container { RelativeSizeAxes = Axes.Both }; public CarouselHeader() { RelativeSizeAxes = Axes.X; Height = DrawableCarouselItem.MAX_HEIGHT; InternalChild = BorderContainer = new Container { RelativeSizeAxes = Axes.Both, Masking = true, CornerRadius = 10, BorderColour = new Color4(221, 255, 255, 255), Children = new Drawable[] { Content, new HoverLayer() } }; } protected override void LoadComplete() { base.LoadComplete(); State.BindValueChanged(updateState, true); } private void updateState(ValueChangedEvent state) { switch (state.NewValue) { case CarouselItemState.Collapsed: case CarouselItemState.NotSelected: BorderContainer.BorderThickness = 0; BorderContainer.EdgeEffect = new EdgeEffectParameters { Type = EdgeEffectType.Shadow, Offset = new Vector2(1), Radius = 10, Colour = Color4.Black.Opacity(100), }; break; case CarouselItemState.Selected: BorderContainer.BorderThickness = 2.5f; BorderContainer.EdgeEffect = new EdgeEffectParameters { Type = EdgeEffectType.Glow, Colour = new Color4(130, 204, 255, 150), Radius = 20, Roundness = 10, }; break; } } public class HoverLayer : HoverSampleDebounceComponent { private Sample sampleHover; private Box box; public HoverLayer() { RelativeSizeAxes = Axes.Both; } [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, }; sampleHover = audio.Samples.Get("SongSelect/song-ping"); } 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(); } } } }