@@ -1,3 +1,4 @@
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using Content.Client.UserInterface.Controls;
|
||||
using Robust.Client.AutoGenerated;
|
||||
@@ -29,48 +30,47 @@ namespace Content.Client.PDA.Ringer
|
||||
{
|
||||
var input = RingerNoteInputs[i];
|
||||
var index = i;
|
||||
var foo = () => // Prevents unauthorized characters from being entered into the LineEdit
|
||||
{
|
||||
input.Text = input.Text.ToUpper();
|
||||
|
||||
if (!IsNote(input.Text))
|
||||
{
|
||||
input.Text = PreviousNoteInputs[index];
|
||||
}
|
||||
else
|
||||
PreviousNoteInputs[index] = input.Text;
|
||||
|
||||
input.RemoveStyleClass("Caution");
|
||||
};
|
||||
|
||||
input.OnFocusExit += _ => foo();
|
||||
input.OnTextEntered += _ =>
|
||||
{
|
||||
foo();
|
||||
input.CursorPosition = input.Text.Length; // Resets caret position to the end of the typed input
|
||||
};
|
||||
|
||||
input.OnTextChanged += args =>
|
||||
{
|
||||
// Convert to uppercase
|
||||
var upperText = args.Text.ToUpper();
|
||||
if (input.Text.Length <= 0)
|
||||
return;
|
||||
|
||||
// Filter to only valid notes
|
||||
var newText = upperText;
|
||||
if (!IsNote(newText))
|
||||
input.Text = args.Text.ToUpper();
|
||||
|
||||
var isValid = IsNote(input.Text);
|
||||
|
||||
if (!isValid)
|
||||
{
|
||||
newText = PreviousNoteInputs[index];
|
||||
input.Text = PreviousNoteInputs[index];
|
||||
input.AddStyleClass("Caution");
|
||||
}
|
||||
else
|
||||
{
|
||||
PreviousNoteInputs[index] = newText;
|
||||
PreviousNoteInputs[index] = input.Text;
|
||||
input.RemoveStyleClass("Caution");
|
||||
}
|
||||
|
||||
// Only update if there's a change
|
||||
if (newText != input.Text)
|
||||
input.Text = newText;
|
||||
input.CursorPosition = input.Text.Length;
|
||||
};
|
||||
|
||||
input.OnFocusExit += _ =>
|
||||
{
|
||||
if (!IsNote(input.Text))
|
||||
{
|
||||
input.Text = PreviousNoteInputs[index];
|
||||
input.RemoveStyleClass("Caution");
|
||||
}
|
||||
};
|
||||
|
||||
input.OnTextEntered += _ =>
|
||||
{
|
||||
if (!IsNote(input.Text))
|
||||
{
|
||||
input.Text = PreviousNoteInputs[index];
|
||||
input.RemoveStyleClass("Caution");
|
||||
}
|
||||
input.CursorPosition = input.Text.Length;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -86,6 +86,9 @@ namespace Content.Client.PDA.Ringer
|
||||
/// </summary>
|
||||
public static bool IsNote(string input)
|
||||
{
|
||||
if (input.Any(char.IsDigit))
|
||||
return false;
|
||||
|
||||
input = input.Replace("#", "sharp");
|
||||
|
||||
return Enum.TryParse(input, true, out Note _);
|
||||
|
||||
Reference in New Issue
Block a user