1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-15 15:23:14 +08:00

Add audio feedback for when keys are pressed during key binding

This commit is contained in:
Jamie Taylor 2023-10-20 14:39:36 +09:00
parent 6b28f85615
commit fbf8f52f7d
No known key found for this signature in database
GPG Key ID: 2ACFA8B6370B8C8C
2 changed files with 13 additions and 1 deletions

View File

@ -86,6 +86,7 @@ namespace osu.Game.Graphics.UserInterface
Placeholder.Colour = colourProvider?.Foreground1 ?? new Color4(180, 180, 180, 255);
// Note that `KeyBindingRow` uses similar logic for input feedback, so remember to update there if changing here.
var textAddedSamples = new Sample?[4];
for (int i = 0; i < textAddedSamples.Length; i++)
textAddedSamples[i] = audio.Samples.Get($@"Keyboard/key-press-{1 + i}");

View File

@ -6,6 +6,8 @@ using System.Collections.Generic;
using System.Diagnostics;
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.Extensions.Color4Extensions;
@ -17,6 +19,7 @@ using osu.Framework.Input;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Framework.Utils;
using osu.Game.Database;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
@ -96,6 +99,8 @@ namespace osu.Game.Overlays.Settings.Sections.Input
private KeyButton? bindTarget;
private Sample?[]? keypressSamples;
private const float transition_time = 150;
private const float height = 20;
private const float padding = 5;
@ -118,7 +123,7 @@ namespace osu.Game.Overlays.Settings.Sections.Input
}
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
private void load(OverlayColourProvider colourProvider, AudioManager audioManager)
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
@ -202,6 +207,10 @@ namespace osu.Game.Overlays.Settings.Sections.Input
Scheduler.AddOnce(updateButtons);
updateIsDefaultValue();
}, true);
keypressSamples = new Sample[4];
for (int i = 0; i < keypressSamples.Length; i++)
keypressSamples[i] = audioManager.Samples.Get($@"Keyboard/key-press-{1 + i}");
}
public void RestoreDefaults()
@ -301,6 +310,8 @@ namespace osu.Game.Overlays.Settings.Sections.Input
Debug.Assert(bindTarget != null);
keypressSamples?[RNG.Next(0, keypressSamples.Length)]?.Play();
bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(e.CurrentState), KeyCombination.FromKey(e.Key));
if (!isModifier(e.Key)) finalise();