@@ -1,3 +1,4 @@
|
|||||||
|
using System.Linq;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using Content.Client.UserInterface.Controls;
|
using Content.Client.UserInterface.Controls;
|
||||||
using Robust.Client.AutoGenerated;
|
using Robust.Client.AutoGenerated;
|
||||||
@@ -29,48 +30,47 @@ namespace Content.Client.PDA.Ringer
|
|||||||
{
|
{
|
||||||
var input = RingerNoteInputs[i];
|
var input = RingerNoteInputs[i];
|
||||||
var index = 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 =>
|
input.OnTextChanged += args =>
|
||||||
{
|
{
|
||||||
// Convert to uppercase
|
if (input.Text.Length <= 0)
|
||||||
var upperText = args.Text.ToUpper();
|
return;
|
||||||
|
|
||||||
// Filter to only valid notes
|
input.Text = args.Text.ToUpper();
|
||||||
var newText = upperText;
|
|
||||||
if (!IsNote(newText))
|
var isValid = IsNote(input.Text);
|
||||||
|
|
||||||
|
if (!isValid)
|
||||||
{
|
{
|
||||||
newText = PreviousNoteInputs[index];
|
input.Text = PreviousNoteInputs[index];
|
||||||
input.AddStyleClass("Caution");
|
input.AddStyleClass("Caution");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PreviousNoteInputs[index] = newText;
|
PreviousNoteInputs[index] = input.Text;
|
||||||
input.RemoveStyleClass("Caution");
|
input.RemoveStyleClass("Caution");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only update if there's a change
|
input.CursorPosition = input.Text.Length;
|
||||||
if (newText != input.Text)
|
};
|
||||||
input.Text = newText;
|
|
||||||
|
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>
|
/// </summary>
|
||||||
public static bool IsNote(string input)
|
public static bool IsNote(string input)
|
||||||
{
|
{
|
||||||
|
if (input.Any(char.IsDigit))
|
||||||
|
return false;
|
||||||
|
|
||||||
input = input.Replace("#", "sharp");
|
input = input.Replace("#", "sharp");
|
||||||
|
|
||||||
return Enum.TryParse(input, true, out Note _);
|
return Enum.TryParse(input, true, out Note _);
|
||||||
|
|||||||
@@ -55,7 +55,6 @@ public sealed class RingerSystem : SharedRingerSystem
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void OnGenerateUplinkCode(Entity<RingerUplinkComponent> ent, ref GenerateUplinkCodeEvent ev)
|
private void OnGenerateUplinkCode(Entity<RingerUplinkComponent> ent, ref GenerateUplinkCodeEvent ev)
|
||||||
{
|
{
|
||||||
// Generate a new uplink code
|
|
||||||
var code = GenerateRingtone();
|
var code = GenerateRingtone();
|
||||||
|
|
||||||
// Set the code on the component
|
// Set the code on the component
|
||||||
@@ -74,6 +73,10 @@ public sealed class RingerSystem : SharedRingerSystem
|
|||||||
if (!HasComp<StoreComponent>(uid))
|
if (!HasComp<StoreComponent>(uid))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// Wasn't generated yet
|
||||||
|
if (uplink.Code is null)
|
||||||
|
return false;
|
||||||
|
|
||||||
// On the server, we always check if the code matches
|
// On the server, we always check if the code matches
|
||||||
if (!uplink.Code.SequenceEqual(ringtone))
|
if (!uplink.Code.SequenceEqual(ringtone))
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public sealed partial class RingerUplinkComponent : Component
|
|||||||
/// Set via GenerateUplinkCodeEvent.
|
/// Set via GenerateUplinkCodeEvent.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField]
|
[DataField]
|
||||||
public Note[] Code = new Note[SharedRingerSystem.RingtoneLength];
|
public Note[]? Code;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether to show the toggle uplink button in PDA settings.
|
/// Whether to show the toggle uplink button in PDA settings.
|
||||||
|
|||||||
@@ -45,8 +45,8 @@ public abstract class SharedRingerSystem : EntitySystem
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override void Update(float frameTime)
|
public override void Update(float frameTime)
|
||||||
{
|
{
|
||||||
var ringerQuery = EntityQueryEnumerator<RingerComponent>();
|
var ringerQuery = EntityQueryEnumerator<RingerComponent, TransformComponent>();
|
||||||
while (ringerQuery.MoveNext(out var uid, out var ringer))
|
while (ringerQuery.MoveNext(out var uid, out var ringer, out var xform))
|
||||||
{
|
{
|
||||||
if (!ringer.Active || !ringer.NextNoteTime.HasValue)
|
if (!ringer.Active || !ringer.NextNoteTime.HasValue)
|
||||||
continue;
|
continue;
|
||||||
@@ -63,10 +63,9 @@ public abstract class SharedRingerSystem : EntitySystem
|
|||||||
// and play it separately with PlayLocal, so that it's actually predicted
|
// and play it separately with PlayLocal, so that it's actually predicted
|
||||||
if (_net.IsServer)
|
if (_net.IsServer)
|
||||||
{
|
{
|
||||||
var ringerXform = Transform(uid);
|
|
||||||
_audio.PlayEntity(
|
_audio.PlayEntity(
|
||||||
GetSound(ringer.Ringtone[ringer.NoteCount]),
|
GetSound(ringer.Ringtone[ringer.NoteCount]),
|
||||||
Filter.Empty().AddInRange(_xform.GetMapCoordinates(uid, ringerXform), ringer.Range),
|
Filter.Empty().AddInRange(_xform.GetMapCoordinates(uid, xform), ringer.Range),
|
||||||
uid,
|
uid,
|
||||||
true,
|
true,
|
||||||
AudioParams.Default.WithMaxDistance(ringer.Range).WithVolume(ringer.Volume)
|
AudioParams.Default.WithMaxDistance(ringer.Range).WithVolume(ringer.Volume)
|
||||||
@@ -257,14 +256,6 @@ public abstract class SharedRingerSystem : EntitySystem
|
|||||||
return true;
|
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>
|
/// <summary>
|
||||||
/// Gets the sound path for a specific note.
|
/// Gets the sound path for a specific note.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user