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; } /// /// Determines whether or not the characters inputed are authorized /// public static bool IsNote(string input) { input = input.Replace("#", "sharp"); return Enum.TryParse(input, true, out Note _); } } }