mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 05:22:54 +08:00
Merge pull request #16005 from Susko3/add-ime-sounds
Add sounds for IME composition
This commit is contained in:
commit
b1d78c4284
@ -93,7 +93,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
if (added.Any(char.IsUpper) && AllowUniqueCharacterSamples)
|
if (added.Any(char.IsUpper) && AllowUniqueCharacterSamples)
|
||||||
capsTextAddedSample?.Play();
|
capsTextAddedSample?.Play();
|
||||||
else
|
else
|
||||||
textAddedSamples[RNG.Next(0, 3)]?.Play();
|
playTextAddedSample();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnUserTextRemoved(string removed)
|
protected override void OnUserTextRemoved(string removed)
|
||||||
@ -117,6 +117,70 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
caretMovedSample?.Play();
|
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)
|
protected override void OnFocus(FocusEvent e)
|
||||||
{
|
{
|
||||||
BorderThickness = 3;
|
BorderThickness = 3;
|
||||||
@ -142,6 +206,8 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
SelectionColour = SelectionColour,
|
SelectionColour = SelectionColour,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private void playTextAddedSample() => textAddedSamples[RNG.Next(0, textAddedSamples.Length)]?.Play();
|
||||||
|
|
||||||
private class OsuCaret : Caret
|
private class OsuCaret : Caret
|
||||||
{
|
{
|
||||||
private const float caret_move_time = 60;
|
private const float caret_move_time = 60;
|
||||||
|
Loading…
Reference in New Issue
Block a user