Merge pull request #16005 from Susko3/add-ime-sounds

Add sounds for IME composition
This commit is contained in:
Dean Herbert 2021-12-08 19:02:02 +09:00 committed by GitHub
commit b1d78c4284
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -93,7 +93,7 @@ namespace osu.Game.Graphics.UserInterface
if (added.Any(char.IsUpper) && AllowUniqueCharacterSamples)
capsTextAddedSample?.Play();
else
textAddedSamples[RNG.Next(0, 3)]?.Play();
playTextAddedSample();
}
protected override void OnUserTextRemoved(string removed)
@ -117,6 +117,70 @@ namespace osu.Game.Graphics.UserInterface
caretMovedSample?.Play();
}
protected override void OnImeComposition(string newComposition, int removedTextLength, int addedTextLength, bool caretMoved)
{
base.OnImeComposition(newComposition, removedTextLength, addedTextLength, caretMoved);
if (string.IsNullOrEmpty(newComposition))
{
switch (removedTextLength)
{
case 0:
// empty composition event, composition wasn't changed, don't play anything.
return;
case 1:
// composition probably ended by pressing backspace, or was cancelled.
textRemovedSample?.Play();
return;
default:
// longer text removed, composition ended because it was cancelled.
// could be a different sample if desired.
textRemovedSample?.Play();
return;
}
}
if (addedTextLength > 0)
{
// some text was added, probably due to typing new text or by changing the candidate.
playTextAddedSample();
return;
}
if (removedTextLength > 0)
{
// text was probably removed by backspacing.
// it's also possible that a candidate that only removed text was changed to.
textRemovedSample?.Play();
return;
}
if (caretMoved)
{
// only the caret/selection was moved.
caretMovedSample?.Play();
}
}
protected override void OnImeResult(string result, bool successful)
{
base.OnImeResult(result, successful);
if (successful)
{
// composition was successfully completed, usually by pressing the enter key.
textCommittedSample?.Play();
}
else
{
// composition was prematurely ended, eg. by clicking inside the textbox.
// could be a different sample if desired.
textCommittedSample?.Play();
}
}
protected override void OnFocus(FocusEvent e)
{
BorderThickness = 3;
@ -142,6 +206,8 @@ namespace osu.Game.Graphics.UserInterface
SelectionColour = SelectionColour,
};
private void playTextAddedSample() => textAddedSamples[RNG.Next(0, textAddedSamples.Length)]?.Play();
private class OsuCaret : Caret
{
private const float caret_move_time = 60;