using Content.Client.Message; using Content.Client.UserInterface.Controls; using Content.Shared.Access.Components; using Content.Shared.CCVar; using Content.Shared.Security.Components; using Robust.Client.AutoGenerated; using Robust.Client.UserInterface.XAML; using Robust.Shared.Configuration; namespace Content.Client.Security.Ui; [GenerateTypedNameReferences] public sealed partial class GenpopLockerMenu : FancyWindow { [Dependency] private readonly IConfigurationManager _cfgManager = default!; public event Action? OnConfigurationComplete; // CCVar. private int _maxIdJobLength; public GenpopLockerMenu(EntityUid owner, IEntityManager entMan) { RobustXamlLoader.Load(this); _maxIdJobLength = _cfgManager.GetCVar(CCVars.MaxIdJobLength); Title = entMan.GetComponent(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 <= _maxIdJobLength; 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); } }