Refactor `HoverSampleDebounceComponent` to inherit `Component`

This commit is contained in:
Joseph Madamba 2023-02-03 00:29:25 -08:00
parent f27bf3ca20
commit 5a76c1ab9c
2 changed files with 17 additions and 9 deletions

View File

@ -5,7 +5,7 @@
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics;
using osu.Framework.Input.Events;
using osu.Game.Configuration;
using osuTK;
@ -15,7 +15,7 @@ namespace osu.Game.Graphics.UserInterface
/// <summary>
/// Handles debouncing hover sounds at a global level to ensure the effects are not overwhelming.
/// </summary>
public abstract partial class HoverSampleDebounceComponent : CompositeDrawable
public abstract partial class HoverSampleDebounceComponent : Component
{
private Bindable<double?> lastPlaybackTime;

View File

@ -46,7 +46,8 @@ public CarouselHeader()
Children = new Drawable[]
{
Content,
hoverLayer = new HoverLayer()
hoverLayer = new HoverLayer(),
new HeaderSounds(),
}
};
}
@ -91,10 +92,8 @@ private void updateState(ValueChangedEvent<CarouselItemState> state)
}
}
public partial class HoverLayer : HoverSampleDebounceComponent
public partial class HoverLayer : CompositeDrawable
{
private Sample? sampleHover;
private Box box = null!;
public HoverLayer()
@ -103,7 +102,7 @@ public HoverLayer()
}
[BackgroundDependencyLoader]
private void load(AudioManager audio, OsuColour colours)
private void load(OsuColour colours)
{
InternalChild = box = new Box
{
@ -112,8 +111,6 @@ private void load(AudioManager audio, OsuColour colours)
Blending = BlendingParameters.Additive,
RelativeSizeAxes = Axes.Both,
};
sampleHover = audio.Samples.Get("UI/default-hover");
}
public bool InsetForBorder
@ -147,6 +144,17 @@ protected override void OnHoverLost(HoverLostEvent e)
box.FadeOut(1000, Easing.OutQuint);
base.OnHoverLost(e);
}
}
private partial class HeaderSounds : HoverSampleDebounceComponent
{
private Sample? sampleHover;
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
sampleHover = audio.Samples.Get("UI/default-hover");
}
public override void PlayHoverSample()
{