Files
tbd-station-14/Content.Client/Security/Ui/GenpopLockerMenu.xaml.cs
āda de24413bd5 HumanoidCharacterProfile and IdCardConsoleComponent constants moved to cvar. Sync id card length with character name length (#35407)
* commit

* mark TODOs

* compiles

* cleanup

* cleanup

* oops

* changed my mind

* requested changes

* genpop fix
2025-05-17 15:27:39 +10:00

59 lines
2.1 KiB
C#

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<string, float, string>? OnConfigurationComplete;
// CCVar.
private int _maxIdJobLength;
public GenpopLockerMenu(EntityUid owner, IEntityManager entMan)
{
RobustXamlLoader.Load(this);
_maxIdJobLength = _cfgManager.GetCVar(CCVars.MaxIdJobLength);
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 <= _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);
}
}