From dba17b1fa6fec3cb7b201f462d880dafc0f4125f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 27 Jan 2026 03:04:09 +0900 Subject: [PATCH] Standardise hover sounds for form elements Closes #36444. --- .../UserInterface/HoverClickSounds.cs | 19 +++---------------- .../Graphics/UserInterface/HoverSounds.cs | 6 ++++++ .../Graphics/UserInterfaceV2/FormButton.cs | 4 ---- .../UserInterfaceV2/FormControlBackground.cs | 6 ++++++ .../Graphics/UserInterfaceV2/FormDropdown.cs | 5 ----- .../Graphics/UserInterfaceV2/FormSliderBar.cs | 3 --- 6 files changed, 15 insertions(+), 28 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/HoverClickSounds.cs b/osu.Game/Graphics/UserInterface/HoverClickSounds.cs index fea33bfa9d..b8f97cab5e 100644 --- a/osu.Game/Graphics/UserInterface/HoverClickSounds.cs +++ b/osu.Game/Graphics/UserInterface/HoverClickSounds.cs @@ -1,13 +1,10 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Linq; using osu.Framework.Allocation; using osu.Framework.Audio; using osu.Framework.Audio.Sample; -using osu.Framework.Bindables; using osu.Framework.Extensions; using osu.Framework.Input.Events; using osu.Framework.Utils; @@ -21,10 +18,8 @@ namespace osu.Game.Graphics.UserInterface /// public partial class HoverClickSounds : HoverSounds { - public Bindable Enabled = new Bindable(true); - - private Sample sampleClick; - private Sample sampleClickDisabled; + private Sample? sampleClick; + private Sample? sampleClickDisabled; private readonly MouseButton[] buttons; @@ -36,7 +31,7 @@ namespace osu.Game.Graphics.UserInterface /// Array of button codes which should trigger the click sound. /// If this optional parameter is omitted or set to null, the click sound will only be played on left click. /// - public HoverClickSounds(HoverSampleSet sampleSet = HoverSampleSet.Default, MouseButton[] buttons = null) + public HoverClickSounds(HoverSampleSet sampleSet = HoverSampleSet.Default, MouseButton[]? buttons = null) : base(sampleSet) { this.buttons = buttons ?? new[] { MouseButton.Left }; @@ -60,14 +55,6 @@ namespace osu.Game.Graphics.UserInterface return base.OnClick(e); } - public override void PlayHoverSample() - { - if (!Enabled.Value) - return; - - base.PlayHoverSample(); - } - public void PlayClickSample() { var channel = Enabled.Value ? sampleClick?.GetChannel() : sampleClickDisabled?.GetChannel(); diff --git a/osu.Game/Graphics/UserInterface/HoverSounds.cs b/osu.Game/Graphics/UserInterface/HoverSounds.cs index 012594b404..cd67a0f935 100644 --- a/osu.Game/Graphics/UserInterface/HoverSounds.cs +++ b/osu.Game/Graphics/UserInterface/HoverSounds.cs @@ -6,6 +6,7 @@ using osu.Framework.Allocation; using osu.Framework.Audio; using osu.Framework.Audio.Sample; +using osu.Framework.Bindables; using osu.Framework.Extensions; using osu.Framework.Graphics; using osu.Framework.Utils; @@ -18,6 +19,8 @@ namespace osu.Game.Graphics.UserInterface /// public partial class HoverSounds : HoverSampleDebounceComponent { + public readonly Bindable Enabled = new Bindable(true); + private Sample sampleHover; protected readonly HoverSampleSet SampleSet; @@ -37,6 +40,9 @@ namespace osu.Game.Graphics.UserInterface public override void PlayHoverSample() { + if (!Enabled.Value) + return; + sampleHover.Frequency.Value = 0.98 + RNG.NextDouble(0.04); sampleHover.Play(); } diff --git a/osu.Game/Graphics/UserInterfaceV2/FormButton.cs b/osu.Game/Graphics/UserInterfaceV2/FormButton.cs index 3b4f0e3448..36c2ad8098 100644 --- a/osu.Game/Graphics/UserInterfaceV2/FormButton.cs +++ b/osu.Game/Graphics/UserInterfaceV2/FormButton.cs @@ -88,10 +88,6 @@ namespace osu.Game.Graphics.UserInterfaceV2 Children = new Drawable[] { background = new FormControlBackground(), - new HoverClickSounds(HoverSampleSet.Button) - { - Enabled = { BindTarget = Enabled }, - }, new Container { RelativeSizeAxes = Axes.X, diff --git a/osu.Game/Graphics/UserInterfaceV2/FormControlBackground.cs b/osu.Game/Graphics/UserInterfaceV2/FormControlBackground.cs index 7b9c5c4992..c576bad0f9 100644 --- a/osu.Game/Graphics/UserInterfaceV2/FormControlBackground.cs +++ b/osu.Game/Graphics/UserInterfaceV2/FormControlBackground.cs @@ -7,6 +7,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; +using osu.Game.Graphics.UserInterface; using osu.Game.Overlays; using osuTK.Graphics; @@ -52,6 +53,8 @@ namespace osu.Game.Graphics.UserInterfaceV2 private readonly Box box; + private readonly HoverSounds sounds; + public FormControlBackground() { RelativeSizeAxes = Axes.Both; @@ -69,6 +72,7 @@ namespace osu.Game.Graphics.UserInterfaceV2 Colour = Color4.White, RelativeSizeAxes = Axes.Both, }, + sounds = new HoverSounds(), }; } @@ -87,6 +91,8 @@ namespace osu.Game.Graphics.UserInterfaceV2 private void updateStyling() { + sounds.Enabled.Value = !styleDisabled; + ColourInfo colour = colourProvider.Background4.Darken(0.1f); ColourInfo borderColour = colourProvider.Light4; diff --git a/osu.Game/Graphics/UserInterfaceV2/FormDropdown.cs b/osu.Game/Graphics/UserInterfaceV2/FormDropdown.cs index e970459037..d7860bab4f 100644 --- a/osu.Game/Graphics/UserInterfaceV2/FormDropdown.cs +++ b/osu.Game/Graphics/UserInterfaceV2/FormDropdown.cs @@ -203,11 +203,6 @@ namespace osu.Game.Graphics.UserInterfaceV2 } }, }; - - AddInternal(new HoverClickSounds - { - Enabled = { BindTarget = Enabled }, - }); } protected override void LoadComplete() diff --git a/osu.Game/Graphics/UserInterfaceV2/FormSliderBar.cs b/osu.Game/Graphics/UserInterfaceV2/FormSliderBar.cs index d6c7c36785..597a22773b 100644 --- a/osu.Game/Graphics/UserInterfaceV2/FormSliderBar.cs +++ b/osu.Game/Graphics/UserInterfaceV2/FormSliderBar.cs @@ -451,7 +451,6 @@ namespace osu.Game.Graphics.UserInterfaceV2 private Box leftBox = null!; private Box rightBox = null!; private InnerSliderNub nub = null!; - private HoverClickSounds sounds = null!; public const float NUB_WIDTH = 10; [Resolved] @@ -496,7 +495,6 @@ namespace osu.Game.Graphics.UserInterfaceV2 ResetToDefault = ResetToDefault, } }, - sounds = new HoverClickSounds() }; } @@ -558,7 +556,6 @@ namespace osu.Game.Graphics.UserInterfaceV2 private void updateState() { - sounds.Enabled.Value = !Current.Disabled; rightBox.Colour = colourProvider.Background5; Color4 leftColour = colourProvider.Light4;