Files
wwdpublic/Content.Client/PDA/Ringer/RingtoneMenu.xaml.cs
DEATHB4DEFEAT 32f538d2ba Fix Buttons Being Yellow Instead of Red (#2129)
# Description

I changed something so long ago but didn't make sure others were changed
to follow.

---

<details><summary><h1>Media</h1></summary>
<p>

![image](https://github.com/user-attachments/assets/9328cf6f-907f-4051-a972-5ae6579e6b01)

![image](https://github.com/user-attachments/assets/fa9e3e7d-3d0a-4193-b51f-20449c068751)

![image](https://github.com/user-attachments/assets/301debf9-0623-4a69-8334-0205ac8ae2a0)

![image](https://github.com/user-attachments/assets/afcc12a4-8068-4091-aa3f-427559b7d1ac)

![image](https://github.com/user-attachments/assets/77c62f0c-8356-4772-ab01-8af543b0f050)

</p>
</details>

---

# Changelog

🆑
- fix: Fixed many buttons being yellow instead of red

---------

Signed-off-by: DEATHB4DEFEAT <77995199+DEATHB4DEFEAT@users.noreply.github.com>
Co-authored-by: Timfa <timfalken@hotmail.com>
(cherry picked from commit ca703ab8d367bbdfc4ab115af4a01964ff597e5f)
2025-04-04 14:31:36 +03:00

75 lines
2.5 KiB
C#

using System.Numerics;
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[] { "A", "A", "A", "A", "A", "A" };
public LineEdit[] RingerNoteInputs = default!;
public RingtoneMenu()
{
RobustXamlLoader.Load(this);
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("Danger");
};
input.OnFocusExit += _ => foo();
input.OnTextEntered += _ =>
{
foo();
input.CursorPosition = input.Text.Length; // Resets caret position to the end of the typed input
};
input.OnTextChanged += _ =>
{
input.Text = input.Text.ToUpper();
if (!IsNote(input.Text))
input.AddStyleClass("Danger");
else
input.RemoveStyleClass("Danger");
};
}
}
protected override DragMode GetDragModeFor(Vector2 relativeMousePos)
{
//Prevents the ringtone window from being resized
return DragMode.Move;
}
/// <summary>
/// Determines whether or not the characters inputed are authorized
/// </summary>
public static bool IsNote(string input)
{
input = input.Replace("#", "sharp");
return Enum.TryParse(input, true, out Note _);
}
}
}