using System.Numerics; using Content.Client.UserInterface.Controls; using Robust.Client.AutoGenerated; 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 : FancyWindow { public string[] PreviousNoteInputs = new[] { "A", "A", "A", "A", "A", "A" }; public LineEdit[] RingerNoteInputs; public event Action? SetRingtoneButtonPressed; public event Action? TestRingtoneButtonPressed; public RingtoneMenu() { RobustXamlLoader.Load(this); SetRingerButton.OnPressed += _ => SetRingtoneButtonPressed?.Invoke(); TestRingerButton.OnPressed += _ => TestRingtoneButtonPressed?.Invoke(); RingerNoteInputs = new[] { RingerNoteOneInput, RingerNoteTwoInput, RingerNoteThreeInput, RingerNoteFourInput, RingerNoteFiveInput, RingerNoteSixInput }; for (var i = 0; i < RingerNoteInputs.Length; ++i) { 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(); // Filter to only valid notes var newText = upperText; if (!IsNote(newText)) { newText = PreviousNoteInputs[index]; input.AddStyleClass("Caution"); } else { PreviousNoteInputs[index] = newText; input.RemoveStyleClass("Caution"); } // Only update if there's a change if (newText != input.Text) input.Text = newText; }; } } 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 _); } } }