@@ -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 _);
|
||||
|
||||
@@ -55,7 +55,6 @@ public sealed class RingerSystem : SharedRingerSystem
|
||||
/// </summary>
|
||||
private void OnGenerateUplinkCode(Entity<RingerUplinkComponent> 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<StoreComponent>(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;
|
||||
|
||||
@@ -14,7 +14,7 @@ public sealed partial class RingerUplinkComponent : Component
|
||||
/// Set via GenerateUplinkCodeEvent.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public Note[] Code = new Note[SharedRingerSystem.RingtoneLength];
|
||||
public Note[]? Code;
|
||||
|
||||
/// <summary>
|
||||
/// Whether to show the toggle uplink button in PDA settings.
|
||||
|
||||
@@ -45,8 +45,8 @@ public abstract class SharedRingerSystem : EntitySystem
|
||||
/// <inheritdoc/>
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
var ringerQuery = EntityQueryEnumerator<RingerComponent>();
|
||||
while (ringerQuery.MoveNext(out var uid, out var ringer))
|
||||
var ringerQuery = EntityQueryEnumerator<RingerComponent, TransformComponent>();
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper method to determine if the mind is an antagonist.
|
||||
/// </summary>
|
||||
protected bool IsAntagonist(EntityUid? user)
|
||||
{
|
||||
return user != null && _mind.TryGetMind(user.Value, out var mindId, out _) && _role.MindIsAntagonist(mindId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the sound path for a specific note.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user