diff --git a/Content.Client/PDA/Ringer/RingtoneMenu.xaml.cs b/Content.Client/PDA/Ringer/RingtoneMenu.xaml.cs index 989fe65843..83024c22fb 100644 --- a/Content.Client/PDA/Ringer/RingtoneMenu.xaml.cs +++ b/Content.Client/PDA/Ringer/RingtoneMenu.xaml.cs @@ -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 /// public static bool IsNote(string input) { + if (input.Any(char.IsDigit)) + return false; + input = input.Replace("#", "sharp"); return Enum.TryParse(input, true, out Note _); diff --git a/Content.Server/PDA/Ringer/RingerSystem.cs b/Content.Server/PDA/Ringer/RingerSystem.cs index dbdc5e83f3..b47ca0fde3 100644 --- a/Content.Server/PDA/Ringer/RingerSystem.cs +++ b/Content.Server/PDA/Ringer/RingerSystem.cs @@ -55,7 +55,6 @@ public sealed class RingerSystem : SharedRingerSystem /// private void OnGenerateUplinkCode(Entity ent, ref GenerateUplinkCodeEvent ev) { - // Generate a new uplink code var code = GenerateRingtone(); // Set the code on the component @@ -74,6 +73,10 @@ public sealed class RingerSystem : SharedRingerSystem if (!HasComp(uid)) return false; + // Wasn't generated yet + if (uplink.Code is null) + return false; + // On the server, we always check if the code matches if (!uplink.Code.SequenceEqual(ringtone)) return false; diff --git a/Content.Shared/PDA/Ringer/RingerUplinkComponent.cs b/Content.Shared/PDA/Ringer/RingerUplinkComponent.cs index e3170c84e3..2dbbfb5efc 100644 --- a/Content.Shared/PDA/Ringer/RingerUplinkComponent.cs +++ b/Content.Shared/PDA/Ringer/RingerUplinkComponent.cs @@ -14,7 +14,7 @@ public sealed partial class RingerUplinkComponent : Component /// Set via GenerateUplinkCodeEvent. /// [DataField] - public Note[] Code = new Note[SharedRingerSystem.RingtoneLength]; + public Note[]? Code; /// /// Whether to show the toggle uplink button in PDA settings. diff --git a/Content.Shared/PDA/SharedRingerSystem.cs b/Content.Shared/PDA/SharedRingerSystem.cs index 0fa5a570aa..8a9d8156a3 100644 --- a/Content.Shared/PDA/SharedRingerSystem.cs +++ b/Content.Shared/PDA/SharedRingerSystem.cs @@ -45,8 +45,8 @@ public abstract class SharedRingerSystem : EntitySystem /// public override void Update(float frameTime) { - var ringerQuery = EntityQueryEnumerator(); - while (ringerQuery.MoveNext(out var uid, out var ringer)) + var ringerQuery = EntityQueryEnumerator(); + while (ringerQuery.MoveNext(out var uid, out var ringer, out var xform)) { if (!ringer.Active || !ringer.NextNoteTime.HasValue) continue; @@ -63,10 +63,9 @@ public abstract class SharedRingerSystem : EntitySystem // and play it separately with PlayLocal, so that it's actually predicted if (_net.IsServer) { - var ringerXform = Transform(uid); _audio.PlayEntity( GetSound(ringer.Ringtone[ringer.NoteCount]), - Filter.Empty().AddInRange(_xform.GetMapCoordinates(uid, ringerXform), ringer.Range), + Filter.Empty().AddInRange(_xform.GetMapCoordinates(uid, xform), ringer.Range), uid, true, AudioParams.Default.WithMaxDistance(ringer.Range).WithVolume(ringer.Volume) @@ -257,14 +256,6 @@ public abstract class SharedRingerSystem : EntitySystem return true; } - /// - /// Helper method to determine if the mind is an antagonist. - /// - protected bool IsAntagonist(EntityUid? user) - { - return user != null && _mind.TryGetMind(user.Value, out var mindId, out _) && _role.MindIsAntagonist(mindId); - } - /// /// Gets the sound path for a specific note. ///