Add audio feedback for Esc/Back clearing text from a FocusedTextBox

This commit is contained in:
Jamie Taylor 2022-09-07 13:17:04 +09:00
parent 13efa819ae
commit cb1d886c9c
No known key found for this signature in database
GPG Key ID: 2ACFA8B6370B8C8C
2 changed files with 20 additions and 19 deletions

View File

@ -88,6 +88,7 @@ namespace osu.Game.Graphics.UserInterface
if (Text.Length > 0) if (Text.Length > 0)
{ {
Text = string.Empty; Text = string.Empty;
PlayFeedbackSample(FeedbackSampleType.TextRemove);
return true; return true;
} }
} }

View File

@ -47,7 +47,7 @@ namespace osu.Game.Graphics.UserInterface
private bool selectionStarted; private bool selectionStarted;
private double sampleLastPlaybackTime; private double sampleLastPlaybackTime;
private enum FeedbackSampleType protected enum FeedbackSampleType
{ {
TextAdd, TextAdd,
TextAddCaps, TextAddCaps,
@ -117,30 +117,30 @@ namespace osu.Game.Graphics.UserInterface
return; return;
if (added.Any(char.IsUpper) && AllowUniqueCharacterSamples) if (added.Any(char.IsUpper) && AllowUniqueCharacterSamples)
playSample(FeedbackSampleType.TextAddCaps); PlayFeedbackSample(FeedbackSampleType.TextAddCaps);
else else
playSample(FeedbackSampleType.TextAdd); PlayFeedbackSample(FeedbackSampleType.TextAdd);
} }
protected override void OnUserTextRemoved(string removed) protected override void OnUserTextRemoved(string removed)
{ {
base.OnUserTextRemoved(removed); base.OnUserTextRemoved(removed);
playSample(FeedbackSampleType.TextRemove); PlayFeedbackSample(FeedbackSampleType.TextRemove);
} }
protected override void NotifyInputError() protected override void NotifyInputError()
{ {
base.NotifyInputError(); base.NotifyInputError();
playSample(FeedbackSampleType.TextInvalid); PlayFeedbackSample(FeedbackSampleType.TextInvalid);
} }
protected override void OnTextCommitted(bool textChanged) protected override void OnTextCommitted(bool textChanged)
{ {
base.OnTextCommitted(textChanged); base.OnTextCommitted(textChanged);
playSample(FeedbackSampleType.TextConfirm); PlayFeedbackSample(FeedbackSampleType.TextConfirm);
} }
protected override void OnCaretMoved(bool selecting) protected override void OnCaretMoved(bool selecting)
@ -148,7 +148,7 @@ namespace osu.Game.Graphics.UserInterface
base.OnCaretMoved(selecting); base.OnCaretMoved(selecting);
if (!selecting) if (!selecting)
playSample(FeedbackSampleType.CaretMove); PlayFeedbackSample(FeedbackSampleType.CaretMove);
} }
protected override void OnTextSelectionChanged(TextSelectionType selectionType) protected override void OnTextSelectionChanged(TextSelectionType selectionType)
@ -158,15 +158,15 @@ namespace osu.Game.Graphics.UserInterface
switch (selectionType) switch (selectionType)
{ {
case TextSelectionType.Character: case TextSelectionType.Character:
playSample(FeedbackSampleType.SelectCharacter); PlayFeedbackSample(FeedbackSampleType.SelectCharacter);
break; break;
case TextSelectionType.Word: case TextSelectionType.Word:
playSample(selectionStarted ? FeedbackSampleType.SelectCharacter : FeedbackSampleType.SelectWord); PlayFeedbackSample(selectionStarted ? FeedbackSampleType.SelectCharacter : FeedbackSampleType.SelectWord);
break; break;
case TextSelectionType.All: case TextSelectionType.All:
playSample(FeedbackSampleType.SelectAll); PlayFeedbackSample(FeedbackSampleType.SelectAll);
break; break;
} }
@ -179,7 +179,7 @@ namespace osu.Game.Graphics.UserInterface
if (!selectionStarted) return; if (!selectionStarted) return;
playSample(FeedbackSampleType.Deselect); PlayFeedbackSample(FeedbackSampleType.Deselect);
selectionStarted = false; selectionStarted = false;
} }
@ -198,13 +198,13 @@ namespace osu.Game.Graphics.UserInterface
case 1: case 1:
// composition probably ended by pressing backspace, or was cancelled. // composition probably ended by pressing backspace, or was cancelled.
playSample(FeedbackSampleType.TextRemove); PlayFeedbackSample(FeedbackSampleType.TextRemove);
return; return;
default: default:
// longer text removed, composition ended because it was cancelled. // longer text removed, composition ended because it was cancelled.
// could be a different sample if desired. // could be a different sample if desired.
playSample(FeedbackSampleType.TextRemove); PlayFeedbackSample(FeedbackSampleType.TextRemove);
return; return;
} }
} }
@ -212,7 +212,7 @@ namespace osu.Game.Graphics.UserInterface
if (addedTextLength > 0) if (addedTextLength > 0)
{ {
// some text was added, probably due to typing new text or by changing the candidate. // some text was added, probably due to typing new text or by changing the candidate.
playSample(FeedbackSampleType.TextAdd); PlayFeedbackSample(FeedbackSampleType.TextAdd);
return; return;
} }
@ -220,14 +220,14 @@ namespace osu.Game.Graphics.UserInterface
{ {
// text was probably removed by backspacing. // text was probably removed by backspacing.
// it's also possible that a candidate that only removed text was changed to. // it's also possible that a candidate that only removed text was changed to.
playSample(FeedbackSampleType.TextRemove); PlayFeedbackSample(FeedbackSampleType.TextRemove);
return; return;
} }
if (caretMoved) if (caretMoved)
{ {
// only the caret/selection was moved. // only the caret/selection was moved.
playSample(FeedbackSampleType.CaretMove); PlayFeedbackSample(FeedbackSampleType.CaretMove);
} }
} }
@ -238,13 +238,13 @@ namespace osu.Game.Graphics.UserInterface
if (successful) if (successful)
{ {
// composition was successfully completed, usually by pressing the enter key. // composition was successfully completed, usually by pressing the enter key.
playSample(FeedbackSampleType.TextConfirm); PlayFeedbackSample(FeedbackSampleType.TextConfirm);
} }
else else
{ {
// composition was prematurely ended, eg. by clicking inside the textbox. // composition was prematurely ended, eg. by clicking inside the textbox.
// could be a different sample if desired. // could be a different sample if desired.
playSample(FeedbackSampleType.TextConfirm); PlayFeedbackSample(FeedbackSampleType.TextConfirm);
} }
} }
@ -283,7 +283,7 @@ namespace osu.Game.Graphics.UserInterface
return samples[RNG.Next(0, samples.Length)]?.GetChannel(); return samples[RNG.Next(0, samples.Length)]?.GetChannel();
} }
private void playSample(FeedbackSampleType feedbackSample) => Schedule(() => protected void PlayFeedbackSample(FeedbackSampleType feedbackSample) => Schedule(() =>
{ {
if (Time.Current < sampleLastPlaybackTime + 15) return; if (Time.Current < sampleLastPlaybackTime + 15) return;