diff --git a/Content.Client/Silicons/Laws/SiliconLawEditUi/SiliconLawContainer.xaml b/Content.Client/Silicons/Laws/SiliconLawEditUi/SiliconLawContainer.xaml new file mode 100644 index 0000000000..1bcac4bca6 --- /dev/null +++ b/Content.Client/Silicons/Laws/SiliconLawEditUi/SiliconLawContainer.xaml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/Content.Client/Silicons/Laws/SiliconLawEditUi/SiliconLawContainer.xaml.cs b/Content.Client/Silicons/Laws/SiliconLawEditUi/SiliconLawContainer.xaml.cs new file mode 100644 index 0000000000..2e44b820df --- /dev/null +++ b/Content.Client/Silicons/Laws/SiliconLawEditUi/SiliconLawContainer.xaml.cs @@ -0,0 +1,61 @@ +using Content.Shared.Silicons.Laws; +using Robust.Client.AutoGenerated; +using Robust.Client.UserInterface.Controls; +using Robust.Client.UserInterface.XAML; +using Robust.Shared.Utility; + +namespace Content.Client.Silicons.Laws.SiliconLawEditUi; + +[GenerateTypedNameReferences] +public sealed partial class SiliconLawContainer : BoxContainer +{ + public const string StyleClassSiliconLawPositionLabel = "SiliconLawPositionLabel"; + + public static readonly string CorruptedString = + Loc.GetString("ion-storm-law-scrambled-number", ("length", 5)); + + private SiliconLaw? _law; + + public event Action? MoveLawUp; + public event Action? MoveLawDown; + public event Action? DeleteAction; + + + public SiliconLawContainer() + { + RobustXamlLoader.Load(this); + + MoveUp.OnPressed += _ => MoveLawUp?.Invoke(_law!); + MoveDown.OnPressed += _ => MoveLawDown?.Invoke(_law!); + Corrupted.OnPressed += _ => + { + if (Corrupted.Pressed) + { + _law!.LawIdentifierOverride = CorruptedString; + } + else + { + _law!.LawIdentifierOverride = null; + } + }; + + LawContent.OnTextChanged += _ => _law!.LawString = Rope.Collapse(LawContent.TextRope).Trim(); + LawContent.Placeholder = new Rope.Leaf(Loc.GetString("silicon-law-ui-placeholder")); + Delete.OnPressed += _ => DeleteAction?.Invoke(_law!); + } + + public void SetLaw(SiliconLaw law) + { + _law = law; + LawContent.TextRope = new Rope.Leaf(Loc.GetString(law.LawString)); + PositionText.Text = law.Order.ToString(); + if (!string.IsNullOrEmpty(law.LawIdentifierOverride)) + { + Corrupted.Pressed = true; + } + else + { + Corrupted.Pressed = false; + } + } +} diff --git a/Content.Client/Silicons/Laws/SiliconLawEditUi/SiliconLawEui.cs b/Content.Client/Silicons/Laws/SiliconLawEditUi/SiliconLawEui.cs new file mode 100644 index 0000000000..a4d59d1f31 --- /dev/null +++ b/Content.Client/Silicons/Laws/SiliconLawEditUi/SiliconLawEui.cs @@ -0,0 +1,38 @@ +using Content.Client.Eui; +using Content.Shared.Eui; +using Content.Shared.Silicons.Laws; + +namespace Content.Client.Silicons.Laws.SiliconLawEditUi; + +public sealed class SiliconLawEui : BaseEui +{ + public readonly EntityManager _entityManager = default!; + + private SiliconLawUi _siliconLawUi; + private EntityUid _target; + + public SiliconLawEui() + { + _entityManager = IoCManager.Resolve(); + + _siliconLawUi = new SiliconLawUi(); + _siliconLawUi.OnClose += () => SendMessage(new CloseEuiMessage()); + _siliconLawUi.Save.OnPressed += _ => SendMessage(new SiliconLawsSaveMessage(_siliconLawUi.GetLaws(), _entityManager.GetNetEntity(_target))); + } + + public override void HandleState(EuiStateBase state) + { + if (state is not SiliconLawsEuiState s) + { + return; + } + + _target = _entityManager.GetEntity(s.Target); + _siliconLawUi.SetLaws(s.Laws); + } + + public override void Opened() + { + _siliconLawUi.OpenCentered(); + } +} diff --git a/Content.Client/Silicons/Laws/SiliconLawEditUi/SiliconLawUi.xaml b/Content.Client/Silicons/Laws/SiliconLawEditUi/SiliconLawUi.xaml new file mode 100644 index 0000000000..19dcbac620 --- /dev/null +++ b/Content.Client/Silicons/Laws/SiliconLawEditUi/SiliconLawUi.xaml @@ -0,0 +1,22 @@ + + + this shit does not layout properly unless I put the horizontal boxcontainer inside of a vertical one + ???? + + + + + + + + + + + + + diff --git a/Content.Client/Silicons/Laws/SiliconLawEditUi/SiliconLawUi.xaml.cs b/Content.Client/Silicons/Laws/SiliconLawEditUi/SiliconLawUi.xaml.cs new file mode 100644 index 0000000000..372961ea9a --- /dev/null +++ b/Content.Client/Silicons/Laws/SiliconLawEditUi/SiliconLawUi.xaml.cs @@ -0,0 +1,89 @@ +using System.Linq; +using Content.Client.UserInterface.Controls; +using Content.Shared.FixedPoint; +using Content.Shared.Silicons.Laws; +using Robust.Client.AutoGenerated; +using Robust.Client.UserInterface.XAML; + +namespace Content.Client.Silicons.Laws.SiliconLawEditUi; + +[GenerateTypedNameReferences] +public sealed partial class SiliconLawUi : FancyWindow +{ + private List _laws = new(); + + public SiliconLawUi() + { + RobustXamlLoader.Load(this); + NewLawButton.OnPressed += _ => AddNewLaw(); + } + + private void AddNewLaw() + { + var newLaw = new SiliconLaw(); + newLaw.Order = FixedPoint2.New(_laws.Count + 1); + _laws.Add(newLaw); + SetLaws(_laws); + } + + public void SetLaws(List sLaws) + { + _laws = sLaws; + LawContainer.RemoveAllChildren(); + foreach (var law in sLaws.OrderBy(l => l.Order)) + { + var lawControl = new SiliconLawContainer(); + lawControl.SetLaw(law); + lawControl.MoveLawDown += MoveLawDown; + lawControl.MoveLawUp += MoveLawUp; + lawControl.DeleteAction += DeleteLaw; + + LawContainer.AddChild(lawControl); + } + } + + public void DeleteLaw(SiliconLaw law) + { + _laws.Remove(law); + SetLaws(_laws); + } + + public void MoveLawDown(SiliconLaw law) + { + if (_laws.Count == 0) + { + return; + } + + var index = _laws.IndexOf(law); + if (index == -1) + { + return; + } + + _laws[index].Order += FixedPoint2.New(1); + SetLaws(_laws); + } + + public void MoveLawUp(SiliconLaw law) + { + if (_laws.Count == 0) + { + return; + } + + var index = _laws.IndexOf(law); + if (index == -1) + { + return; + } + + _laws[index].Order += FixedPoint2.New(-1); + SetLaws(_laws); + } + + public List GetLaws() + { + return _laws; + } +} diff --git a/Content.Client/Stylesheets/StyleNano.cs b/Content.Client/Stylesheets/StyleNano.cs index 0c04a55059..0bd75003a2 100644 --- a/Content.Client/Stylesheets/StyleNano.cs +++ b/Content.Client/Stylesheets/StyleNano.cs @@ -4,6 +4,7 @@ using Content.Client.ContextMenu.UI; using Content.Client.Examine; using Content.Client.PDA; using Content.Client.Resources; +using Content.Client.Silicons.Laws.SiliconLawEditUi; using Content.Client.UserInterface.Controls; using Content.Client.UserInterface.Controls.FancyTree; using Content.Client.Verbs.UI; @@ -1613,6 +1614,10 @@ namespace Content.Client.Stylesheets { BackgroundColor = FancyTreeSelectedRowColor, }), + + // Silicon law edit ui + Element