1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 10:12:54 +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; content.AutoSizeAxes = AutoSizeAxes;
} }
AddInternal(content); AddRangeInternal(new Drawable[]
Add(CreateHoverSounds(sampleSet)); {
content,
CreateHoverSounds(sampleSet)
});
} }
protected override void ClearInternal(bool disposeChildren = true) => protected override void ClearInternal(bool disposeChildren = true) =>

View File

@ -44,7 +44,7 @@ namespace osu.Game.Graphics.UserInterface
protected override bool OnClick(ClickEvent e) 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(); var channel = Enabled.Value ? sampleClick?.GetChannel() : sampleClickDisabled?.GetChannel();

View File

@ -5,19 +5,22 @@
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Configuration; using osu.Game.Configuration;
using osuTK;
namespace osu.Game.Graphics.UserInterface namespace osu.Game.Graphics.UserInterface
{ {
/// <summary> /// <summary>
/// Handles debouncing hover sounds at a global level to ensure the effects are not overwhelming. /// Handles debouncing hover sounds at a global level to ensure the effects are not overwhelming.
/// </summary> /// </summary>
public abstract partial class HoverSampleDebounceComponent : CompositeDrawable public abstract partial class HoverSampleDebounceComponent : Component
{ {
private Bindable<double?> lastPlaybackTime; private Bindable<double?> lastPlaybackTime;
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Parent?.ReceivePositionalInputAt(screenSpacePos) == true;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(SessionStatics statics) private void load(SessionStatics statics)
{ {

View File

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

View File

@ -121,7 +121,7 @@ namespace osu.Game.Rulesets.Edit
/// </summary> /// </summary>
protected void ApplyDefaultsToHitObject() => HitObject.ApplyDefaults(beatmap.ControlPointInfo, beatmap.Difficulty); 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) protected override bool Handle(UIEvent e)
{ {

View File

@ -46,7 +46,8 @@ namespace osu.Game.Screens.Select.Carousel
Children = new Drawable[] Children = new Drawable[]
{ {
Content, 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!; private Box box = null!;
public HoverLayer() public HoverLayer()
@ -103,7 +102,7 @@ namespace osu.Game.Screens.Select.Carousel
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(AudioManager audio, OsuColour colours) private void load(OsuColour colours)
{ {
InternalChild = box = new Box InternalChild = box = new Box
{ {
@ -112,8 +111,6 @@ namespace osu.Game.Screens.Select.Carousel
Blending = BlendingParameters.Additive, Blending = BlendingParameters.Additive,
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
}; };
sampleHover = audio.Samples.Get("UI/default-hover");
} }
public bool InsetForBorder public bool InsetForBorder
@ -147,6 +144,17 @@ namespace osu.Game.Screens.Select.Carousel
box.FadeOut(1000, Easing.OutQuint); box.FadeOut(1000, Easing.OutQuint);
base.OnHoverLost(e); 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() public override void PlayHoverSample()
{ {