Files
tbd-station-14/Content.Client/Security/Ui/GenpopLockerMenu.xaml.cs
Nemanja dc9844edd1 Genpop Closets & IDs (#36392)
* Genpop IDs and Lockers

* placeholder generation, no ui yet.

* UI

* Fix time offset

* fix meta.jsons

* big speller

* Scarkyo review

* Add turnstile prototypes

* make IDs recyclable

---------

Co-authored-by: ArtisticRoomba <145879011+ArtisticRoomba@users.noreply.github.com>
Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>
2025-04-24 16:32:11 +02:00

50 lines
1.9 KiB
C#

using Content.Client.Message;
using Content.Client.UserInterface.Controls;
using Content.Shared.Access.Components;
using Content.Shared.Security.Components;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML;
namespace Content.Client.Security.Ui;
[GenerateTypedNameReferences]
public sealed partial class GenpopLockerMenu : FancyWindow
{
public event Action<string, float, string>? OnConfigurationComplete;
public GenpopLockerMenu(EntityUid owner, IEntityManager entMan)
{
RobustXamlLoader.Load(this);
Title = entMan.GetComponent<MetaDataComponent>(owner).EntityName;
NameLabel.SetMarkup(Loc.GetString("genpop-locker-ui-label-name"));
SentenceLabel.SetMarkup(Loc.GetString("genpop-locker-ui-label-sentence"));
CrimeLabel.SetMarkup(Loc.GetString("genpop-locker-ui-label-crime"));
SentenceEdit.Text = "5";
CrimeEdit.Text = Loc.GetString("genpop-prisoner-id-crime-default");
NameEdit.IsValid = val => !string.IsNullOrWhiteSpace(val) && val.Length <= IdCardConsoleComponent.MaxFullNameLength;
SentenceEdit.IsValid = val => float.TryParse(val, out var f) && f >= 0;
CrimeEdit.IsValid = val => !string.IsNullOrWhiteSpace(val) && val.Length <= GenpopLockerComponent.MaxCrimeLength;
NameEdit.OnTextChanged += _ => OnTextEdit();
SentenceEdit.OnTextChanged += _ => OnTextEdit();
CrimeEdit.OnTextChanged += _ => OnTextEdit();
DoneButton.OnPressed += _ =>
{
OnConfigurationComplete?.Invoke(NameEdit.Text, float.Parse(SentenceEdit.Text), CrimeEdit.Text);
};
}
private void OnTextEdit()
{
DoneButton.Disabled = string.IsNullOrWhiteSpace(NameEdit.Text) ||
!float.TryParse(SentenceEdit.Text, out var sentence) ||
sentence < 0 ||
string.IsNullOrWhiteSpace(CrimeEdit.Text);
}
}