Files
tbd-station-14/Content.Client/PDA/Ringer/RingtoneMenu.xaml.cs
2022-05-20 13:15:36 +10:00

56 lines
1.9 KiB
C#

using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Content.Shared.PDA;
using Robust.Client.UserInterface.Controls;
namespace Content.Client.PDA.Ringer
{
[GenerateTypedNameReferences]
public sealed partial class RingtoneMenu : DefaultWindow
{
public string[] PreviousNoteInputs = new string[] { "A", "A", "A", "A"};
public LineEdit[] RingerNoteInputs = default!;
public RingtoneMenu()
{
RobustXamlLoader.Load(this);
RingerNoteInputs = new LineEdit[] { RingerNoteOneInput, RingerNoteTwoInput, RingerNoteThreeInput, RingerNoteFourInput };
for (int i = 0; i < RingerNoteInputs.Length; i++)
{
var input = RingerNoteInputs[i];
int index = i;
input.OnTextChanged += _ => //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.CursorPosition = input.Text.Length; //Resets caret position to the end of the typed input
};
}
}
protected override DragMode GetDragModeFor(Vector2 relativeMousePos)
{
//Prevents the ringtone window from being resized
return DragMode.Move;
}
/// <summary>
/// Determines whether or not the characters inputed are authorized
/// </summary>
public static bool IsNote(string input)
{
input = input.Replace("#", "sharp");
return Enum.TryParse(input, true, out Note _);
}
}
}