Update for framework-side changes.

This commit is contained in:
Jamie Taylor
2022-08-24 22:19:32 +09:00
parent 41408a3106
commit dc829334a1

View File

@ -56,6 +56,14 @@ namespace osu.Game.Graphics.UserInterface
private bool selectionStarted; private bool selectionStarted;
private double sampleLastPlaybackTime; private double sampleLastPlaybackTime;
private enum SelectionSampleType
{
Character,
Word,
All,
Deselect
}
public OsuTextBox() public OsuTextBox()
{ {
Height = 40; Height = 40;
@ -133,16 +141,19 @@ namespace osu.Game.Graphics.UserInterface
{ {
base.OnTextSelectionChanged(selectionType); base.OnTextSelectionChanged(selectionType);
if (selectionType == TextSelectionType.Word) switch (selectionType)
{ {
if (!selectionStarted) case TextSelectionType.Character:
playSelectSample(selectionType); playSelectSample(SelectionSampleType.Character);
else break;
playSelectSample();
} case TextSelectionType.Word:
else playSelectSample(selectionStarted ? SelectionSampleType.Character : SelectionSampleType.Word);
{ break;
playSelectSample(selectionType);
case TextSelectionType.All:
playSelectSample(SelectionSampleType.All);
break;
} }
selectionStarted = true; selectionStarted = true;
@ -150,15 +161,16 @@ namespace osu.Game.Graphics.UserInterface
protected override void OnTextDeselected() protected override void OnTextDeselected()
{ {
if (selectionStarted) base.OnTextDeselected();
playSelectSample(TextSelectionType.Deselect);
if (!selectionStarted) return;
playSelectSample(SelectionSampleType.Deselect);
selectionStarted = false; selectionStarted = false;
base.OnTextDeselected();
} }
private void playSelectSample(TextSelectionType selectionType = TextSelectionType.Character) private void playSelectSample(SelectionSampleType selectionType)
{ {
if (Time.Current < sampleLastPlaybackTime + 15) return; if (Time.Current < sampleLastPlaybackTime + 15) return;
@ -167,15 +179,15 @@ namespace osu.Game.Graphics.UserInterface
switch (selectionType) switch (selectionType)
{ {
case TextSelectionType.All: case SelectionSampleType.All:
channel = selectAllSample?.GetChannel(); channel = selectAllSample?.GetChannel();
break; break;
case TextSelectionType.Word: case SelectionSampleType.Word:
channel = selectWordSample?.GetChannel(); channel = selectWordSample?.GetChannel();
break; break;
case TextSelectionType.Deselect: case SelectionSampleType.Deselect:
channel = deselectSample?.GetChannel(); channel = deselectSample?.GetChannel();
break; break;