1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 07:42:57 +08:00

Merge pull request #22505 from Joehuu/fix-hover-click-sounds

Fix some clickable elements having no hover and click sounds
This commit is contained in:
Dean Herbert 2023-02-06 16:52:19 +09:00 committed by GitHub
commit ddcc02fdfe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 14 deletions

View File

@ -44,8 +44,11 @@ namespace osu.Game.Graphics.Containers
content.AutoSizeAxes = AutoSizeAxes;
}
AddInternal(content);
Add(CreateHoverSounds(sampleSet));
AddRangeInternal(new Drawable[]
{
content,
CreateHoverSounds(sampleSet)
});
}
protected override void ClearInternal(bool disposeChildren = true) =>

View File

@ -44,7 +44,7 @@ namespace osu.Game.Graphics.UserInterface
protected override bool OnClick(ClickEvent e)
{
if (buttons.Contains(e.Button) && Contains(e.ScreenSpaceMousePosition))
if (buttons.Contains(e.Button))
{
var channel = Enabled.Value ? sampleClick?.GetChannel() : sampleClickDisabled?.GetChannel();

View File

@ -5,19 +5,22 @@
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;
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;
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Parent?.ReceivePositionalInputAt(screenSpacePos) == true;
[BackgroundDependencyLoader]
private void load(SessionStatics statics)
{

View File

@ -116,7 +116,7 @@ namespace osu.Game.Graphics.UserInterface
});
if (hoverSounds.HasValue)
Add(new HoverClickSounds(hoverSounds.Value) { Enabled = { BindTarget = Enabled } });
AddInternal(new HoverClickSounds(hoverSounds.Value) { Enabled = { BindTarget = Enabled } });
}
[BackgroundDependencyLoader]

View File

@ -121,7 +121,7 @@ namespace osu.Game.Rulesets.Edit
/// </summary>
protected void ApplyDefaultsToHitObject() => HitObject.ApplyDefaults(beatmap.ControlPointInfo, beatmap.Difficulty);
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Parent?.ReceivePositionalInputAt(screenSpacePos) ?? false;
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Parent?.ReceivePositionalInputAt(screenSpacePos) == true;
protected override bool Handle(UIEvent e)
{

View File

@ -46,7 +46,8 @@ namespace osu.Game.Screens.Select.Carousel
Children = new Drawable[]
{
Content,
hoverLayer = new HoverLayer()
hoverLayer = new HoverLayer(),
new HeaderSounds(),
}
};
}
@ -91,10 +92,8 @@ namespace osu.Game.Screens.Select.Carousel
}
}
public partial class HoverLayer : HoverSampleDebounceComponent
public partial class HoverLayer : CompositeDrawable
{
private Sample? sampleHover;
private Box box = null!;
public HoverLayer()
@ -103,7 +102,7 @@ namespace osu.Game.Screens.Select.Carousel
}
[BackgroundDependencyLoader]
private void load(AudioManager audio, OsuColour colours)
private void load(OsuColour colours)
{
InternalChild = box = new Box
{
@ -112,8 +111,6 @@ namespace osu.Game.Screens.Select.Carousel
Blending = BlendingParameters.Additive,
RelativeSizeAxes = Axes.Both,
};
sampleHover = audio.Samples.Get("UI/default-hover");
}
public bool InsetForBorder
@ -147,6 +144,17 @@ namespace osu.Game.Screens.Select.Carousel
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()
{