Add audio feedback for invalid textbox input

This commit is contained in:
Jamie Taylor 2022-08-31 17:23:22 +09:00
parent cc9dc604a0
commit 212d76a11f
No known key found for this signature in database
GPG Key ID: 2ACFA8B6370B8C8C

View File

@ -53,6 +53,7 @@ namespace osu.Game.Graphics.UserInterface
TextAddCaps, TextAddCaps,
TextRemove, TextRemove,
TextConfirm, TextConfirm,
TextInvalid,
CaretMove, CaretMove,
SelectCharacter, SelectCharacter,
SelectWord, SelectWord,
@ -95,6 +96,7 @@ namespace osu.Game.Graphics.UserInterface
{ FeedbackSampleType.TextAddCaps, new[] { audio.Samples.Get(@"Keyboard/key-caps") } }, { FeedbackSampleType.TextAddCaps, new[] { audio.Samples.Get(@"Keyboard/key-caps") } },
{ FeedbackSampleType.TextRemove, new[] { audio.Samples.Get(@"Keyboard/key-delete") } }, { FeedbackSampleType.TextRemove, new[] { audio.Samples.Get(@"Keyboard/key-delete") } },
{ FeedbackSampleType.TextConfirm, new[] { audio.Samples.Get(@"Keyboard/key-confirm") } }, { FeedbackSampleType.TextConfirm, new[] { audio.Samples.Get(@"Keyboard/key-confirm") } },
{ FeedbackSampleType.TextInvalid, new[] { audio.Samples.Get(@"Keyboard/key-invalid") } },
{ FeedbackSampleType.CaretMove, new[] { audio.Samples.Get(@"Keyboard/key-movement") } }, { FeedbackSampleType.CaretMove, new[] { audio.Samples.Get(@"Keyboard/key-movement") } },
{ FeedbackSampleType.SelectCharacter, new[] { audio.Samples.Get(@"Keyboard/select-char") } }, { FeedbackSampleType.SelectCharacter, new[] { audio.Samples.Get(@"Keyboard/select-char") } },
{ FeedbackSampleType.SelectWord, new[] { audio.Samples.Get(@"Keyboard/select-word") } }, { FeedbackSampleType.SelectWord, new[] { audio.Samples.Get(@"Keyboard/select-word") } },
@ -111,6 +113,9 @@ namespace osu.Game.Graphics.UserInterface
{ {
base.OnUserTextAdded(added); base.OnUserTextAdded(added);
if (!added.Any(CanAddCharacter))
return;
if (added.Any(char.IsUpper) && AllowUniqueCharacterSamples) if (added.Any(char.IsUpper) && AllowUniqueCharacterSamples)
playSample(FeedbackSampleType.TextAddCaps); playSample(FeedbackSampleType.TextAddCaps);
else else
@ -124,6 +129,13 @@ namespace osu.Game.Graphics.UserInterface
playSample(FeedbackSampleType.TextRemove); playSample(FeedbackSampleType.TextRemove);
} }
protected override void NotifyInputError()
{
base.NotifyInputError();
playSample(FeedbackSampleType.TextInvalid);
}
protected override void OnTextCommitted(bool textChanged) protected override void OnTextCommitted(bool textChanged)
{ {
base.OnTextCommitted(textChanged); base.OnTextCommitted(textChanged);