SiliconLawContainer.xaml.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using Content.Shared.Silicons.Laws;
  2. using Robust.Client.AutoGenerated;
  3. using Robust.Client.UserInterface.Controls;
  4. using Robust.Client.UserInterface.XAML;
  5. using Robust.Shared.Utility;
  6. namespace Content.Client.Silicons.Laws.SiliconLawEditUi;
  7. [GenerateTypedNameReferences]
  8. public sealed partial class SiliconLawContainer : BoxContainer
  9. {
  10. public const string StyleClassSiliconLawPositionLabel = "SiliconLawPositionLabel";
  11. public static readonly string CorruptedString =
  12. Loc.GetString("ion-storm-law-scrambled-number", ("length", 5));
  13. private SiliconLaw? _law;
  14. public event Action<SiliconLaw>? MoveLawUp;
  15. public event Action<SiliconLaw>? MoveLawDown;
  16. public event Action<SiliconLaw>? DeleteAction;
  17. public SiliconLawContainer()
  18. {
  19. RobustXamlLoader.Load(this);
  20. MoveUp.OnPressed += _ => MoveLawUp?.Invoke(_law!);
  21. MoveDown.OnPressed += _ => MoveLawDown?.Invoke(_law!);
  22. Corrupted.OnPressed += _ =>
  23. {
  24. if (Corrupted.Pressed)
  25. {
  26. _law!.LawIdentifierOverride = CorruptedString;
  27. }
  28. else
  29. {
  30. _law!.LawIdentifierOverride = null;
  31. }
  32. };
  33. LawContent.OnTextChanged += _ => _law!.LawString = Rope.Collapse(LawContent.TextRope).Trim();
  34. LawContent.Placeholder = new Rope.Leaf(Loc.GetString("silicon-law-ui-placeholder"));
  35. Delete.OnPressed += _ => DeleteAction?.Invoke(_law!);
  36. }
  37. public void SetLaw(SiliconLaw law)
  38. {
  39. _law = law;
  40. LawContent.TextRope = new Rope.Leaf(Loc.GetString(law.LawString));
  41. PositionText.Text = law.Order.ToString();
  42. if (!string.IsNullOrEmpty(law.LawIdentifierOverride))
  43. {
  44. Corrupted.Pressed = true;
  45. }
  46. else
  47. {
  48. Corrupted.Pressed = false;
  49. }
  50. }
  51. }