From 2f4849eae1e6d4d1a74b639acace58041596e0e6 Mon Sep 17 00:00:00 2001 From: Rane <60792108+Elijahrane@users.noreply.github.com> Date: Thu, 4 Aug 2022 00:05:17 -0400 Subject: [PATCH] Cloning Rework (#8972) Co-authored-by: fishfish458 --- .../Body/UI/BodyScannerBoundUserInterface.cs | 2 +- .../UI/CloningPodBoundUserInterface.cs | 56 ---- Content.Client/Cloning/UI/CloningPodWindow.cs | 254 ------------------ .../UI/CloningConsoleBoundUserInterface.cs | 51 ++++ .../UI/CloningConsoleWindow.xaml | 65 +++++ .../UI/CloningConsoleWindow.xaml.cs | 113 ++++++++ .../UI/MedicalScannerBoundUserInterface.cs | 51 ---- .../UI/MedicalScannerWindow.xaml | 11 - .../UI/MedicalScannerWindow.xaml.cs | 22 -- .../Components/BodyReassembleComponent.cs | 35 --- .../Body/Systems/BodyReassembleSystem.cs | 229 ---------------- Content.Server/Cloning/AcceptCloningEui.cs | 10 +- .../Cloning/CloningConsoleSystem.cs | 249 +++++++++++++++++ Content.Server/Cloning/CloningSystem.cs | 219 +++++++++------ .../Components/ActiveCloningPodComponent.cs | 9 + .../Components/CloningConsoleComponent.cs | 24 ++ .../Cloning/Components/CloningPodComponent.cs | 198 +------------- .../System/SignalLinkerSystem.cs | 4 + .../Components/MedicalScannerComponent.cs | 6 +- .../Medical/MedicalScannerSystem.cs | 154 +++-------- Content.Server/Mind/Commands/RenameCommand.cs | 9 - .../EntitySystems/PowerReceiverSystem.cs | 13 + .../Cloning/SharedCloningConsole.cs | 64 +++++ .../Cloning/SharedCloningPodComponent.cs | 84 +----- .../MachineLinking/Events/NewLinkEvent.cs | 20 ++ .../SharedMedicalScannerComponent.cs | 22 -- .../components/cloning-pod-component.ftl | 20 -- Resources/Locale/en-US/generic.ftl | 6 +- .../en-US/machine-linking/receiver_ports.ftl | 12 + .../components/cloning-console-component.ftl | 26 ++ .../components/medical-scanner-component.ftl | 10 - Resources/Prototypes/Body/Parts/skeleton.yml | 8 - .../Catalog/Research/technologies.yml | 1 + .../Devices/Circuitboards/computer.yml | 9 + .../Machines/Computers/computers.yml | 36 +++ .../Structures/Machines/cloning_machine.yml | 11 +- .../Entities/Structures/Machines/lathe.yml | 1 + .../Structures/Machines/medical_scanner.yml | 12 +- .../MachineLinking/receiver_ports.yml | 10 + .../MachineLinking/transmitter_ports.yml | 10 + .../Prototypes/Recipes/Lathes/electronics.yml | 9 + 41 files changed, 928 insertions(+), 1227 deletions(-) delete mode 100644 Content.Client/Cloning/UI/CloningPodBoundUserInterface.cs delete mode 100644 Content.Client/Cloning/UI/CloningPodWindow.cs create mode 100644 Content.Client/CloningConsole/UI/CloningConsoleBoundUserInterface.cs create mode 100644 Content.Client/CloningConsole/UI/CloningConsoleWindow.xaml create mode 100644 Content.Client/CloningConsole/UI/CloningConsoleWindow.xaml.cs delete mode 100644 Content.Client/MedicalScanner/UI/MedicalScannerBoundUserInterface.cs delete mode 100644 Content.Client/MedicalScanner/UI/MedicalScannerWindow.xaml delete mode 100644 Content.Client/MedicalScanner/UI/MedicalScannerWindow.xaml.cs delete mode 100644 Content.Server/Body/Components/BodyReassembleComponent.cs delete mode 100644 Content.Server/Body/Systems/BodyReassembleSystem.cs create mode 100644 Content.Server/Cloning/CloningConsoleSystem.cs create mode 100644 Content.Server/Cloning/Components/ActiveCloningPodComponent.cs create mode 100644 Content.Server/Cloning/Components/CloningConsoleComponent.cs create mode 100644 Content.Shared/Cloning/SharedCloningConsole.cs create mode 100644 Content.Shared/MachineLinking/Events/NewLinkEvent.cs delete mode 100644 Resources/Locale/en-US/cloning/components/cloning-pod-component.ftl create mode 100644 Resources/Locale/en-US/medical/components/cloning-console-component.ftl diff --git a/Content.Client/Body/UI/BodyScannerBoundUserInterface.cs b/Content.Client/Body/UI/BodyScannerBoundUserInterface.cs index c340095bd8..2b84e8764e 100644 --- a/Content.Client/Body/UI/BodyScannerBoundUserInterface.cs +++ b/Content.Client/Body/UI/BodyScannerBoundUserInterface.cs @@ -1,4 +1,4 @@ -using System; +using System; using Content.Shared.Body.Components; using JetBrains.Annotations; using Robust.Client.GameObjects; diff --git a/Content.Client/Cloning/UI/CloningPodBoundUserInterface.cs b/Content.Client/Cloning/UI/CloningPodBoundUserInterface.cs deleted file mode 100644 index f6d1933c64..0000000000 --- a/Content.Client/Cloning/UI/CloningPodBoundUserInterface.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System.Collections.Generic; -using JetBrains.Annotations; -using Robust.Client.GameObjects; -using Robust.Shared.GameObjects; -using static Content.Shared.Cloning.SharedCloningPodComponent; - -namespace Content.Client.Cloning.UI -{ - [UsedImplicitly] - public sealed class CloningPodBoundUserInterface : BoundUserInterface - { - public CloningPodBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) - { - } - - private CloningPodWindow? _window; - - protected override void Open() - { - base.Open(); - - - _window = new CloningPodWindow(new Dictionary()); - _window.OnClose += Close; - _window.CloneButton.OnPressed += _ => - { - if (_window.SelectedScan != null) - { - SendMessage(new CloningPodUiButtonPressedMessage(UiButton.Clone, (int) _window.SelectedScan)); - } - }; - _window.EjectButton.OnPressed += _ => - { - SendMessage(new CloningPodUiButtonPressedMessage(UiButton.Eject, null)); - }; - _window.OpenCentered(); - } - - protected override void UpdateState(BoundUserInterfaceState state) - { - base.UpdateState(state); - - _window?.Populate((CloningPodBoundUserInterfaceState) state); - } - - protected override void Dispose(bool disposing) - { - base.Dispose(disposing); - - if (disposing) - { - _window?.Dispose(); - } - } - } -} diff --git a/Content.Client/Cloning/UI/CloningPodWindow.cs b/Content.Client/Cloning/UI/CloningPodWindow.cs deleted file mode 100644 index 3ee31aff99..0000000000 --- a/Content.Client/Cloning/UI/CloningPodWindow.cs +++ /dev/null @@ -1,254 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using Robust.Client.UserInterface; -using Robust.Client.UserInterface.Controls; -using Robust.Client.UserInterface.CustomControls; -using Robust.Shared.IoC; -using Robust.Shared.Localization; -using Robust.Shared.Maths; -using Robust.Shared.Timing; -using static Content.Shared.Cloning.SharedCloningPodComponent; -using static Robust.Client.UserInterface.Controls.BoxContainer; - -namespace Content.Client.Cloning.UI -{ - public sealed class CloningPodWindow : DefaultWindow - { - private Dictionary _scanManager; - - private readonly BoxContainer _scanList; - public readonly Button CloneButton; - public readonly Button EjectButton; - private CloningScanButton? _selectedButton; - private readonly Label _progressLabel; - private readonly ProgressBar _cloningProgressBar; - private readonly Label _mindState; - - private CloningPodBoundUserInterfaceState? _lastUpdate; - - public int? SelectedScan; - - public CloningPodWindow(Dictionary scanManager) - { - SetSize = MinSize = (250, 300); - _scanManager = scanManager; - - Title = Loc.GetString("cloning-pod-window-title"); - - Contents.AddChild(new BoxContainer - { - Orientation = LayoutOrientation.Vertical, - Children = - { - new ScrollContainer - { - MinSize = new Vector2(200.0f, 0.0f), - VerticalExpand = true, - Children = - { - (_scanList = new BoxContainer - { - Orientation = LayoutOrientation.Vertical - }) - } - }, - new BoxContainer - { - Orientation = LayoutOrientation.Vertical, - Children = - { - (CloneButton = new Button - { - Text = Loc.GetString("cloning-pod-clone-button") - }) - } - }, - (_cloningProgressBar = new ProgressBar - { - MinSize = (200, 20), - MinValue = 0, - MaxValue = 120, - Page = 0, - Value = 0.5f, - Children = - { - (_progressLabel = new Label()) - } - }), - (EjectButton = new Button - { - Text = Loc.GetString("cloning-pod-eject-body-button") - }), - new BoxContainer - { - Orientation = LayoutOrientation.Horizontal, - Children = - { - new Label() - { - Text = Loc.GetString($"{Loc.GetString("cloning-pod-neural-interface-label")} ") - }, - (_mindState = new Label() - { - Text = Loc.GetString("cloning-pod-no-activity-text"), - FontColorOverride = Color.Red - }), - } - } - } - }); - - BuildCloneList(); - } - - public void Populate(CloningPodBoundUserInterfaceState state) - { - //Ignore useless updates or we can't interact with the UI - //TODO: come up with a better comparision, probably write a comparator because '.Equals' doesn't work - if (_lastUpdate == null || _lastUpdate.MindIdName.Count != state.MindIdName.Count) - { - _scanManager = state.MindIdName; - BuildCloneList(); - } - _lastUpdate = state; - - _cloningProgressBar.MaxValue = state.Maximum; - UpdateProgress(); - _mindState.Text = Loc.GetString(state.MindPresent ? "cloning-pod-mind-present-text" : "cloning-pod-no-activity-text"); - _mindState.FontColorOverride = state.MindPresent ? Color.LimeGreen : Color.Red; - } - - protected override void FrameUpdate(FrameEventArgs args) - { - base.FrameUpdate(args); - UpdateProgress(); - } - - private void UpdateProgress() - { - if (_lastUpdate == null) - return; - float simulatedProgress = _lastUpdate.Progress; - if (_lastUpdate.Progressing) - { - TimeSpan sinceReference = IoCManager.Resolve().CurTime - _lastUpdate.ReferenceTime; - simulatedProgress += (float) sinceReference.TotalSeconds; - simulatedProgress = MathHelper.Clamp(simulatedProgress, 0f, _lastUpdate.Maximum); - } - var percentage = simulatedProgress / _cloningProgressBar.MaxValue * 100; - _progressLabel.Text = $"{percentage:0}%"; - _cloningProgressBar.Value = simulatedProgress; - } - - private void BuildCloneList() - { - _scanList.RemoveAllChildren(); - _selectedButton = null; - - foreach (var scan in _scanManager) - { - var button = new CloningScanButton - { - Scan = scan.Value ?? string.Empty, - Id = scan.Key - }; - button.ActualButton.OnToggled += OnItemButtonToggled; - var entityLabelText = scan.Value; - - button.EntityLabel.Text = entityLabelText; - - if (scan.Key == SelectedScan) - { - _selectedButton = button; - _selectedButton.ActualButton.Pressed = true; - } - - //TODO: replace with body's face - /*var tex = IconComponent.GetScanIcon(scan, resourceCache); - var rect = button.EntityTextureRect; - if (tex != null) - { - rect.Texture = tex.Default; - } - else - { - rect.Dispose(); - } - - rect.Dispose(); - */ - - _scanList.AddChild(button); - } - - //TODO: set up sort - //_filteredScans.Sort((a, b) => string.Compare(a.ToString(), b.ToString(), StringComparison.Ordinal)); - } - - private void OnItemButtonToggled(BaseButton.ButtonToggledEventArgs args) - { - var item = (CloningScanButton) args.Button.Parent!; - if (_selectedButton == item) - { - _selectedButton = null; - SelectedScan = null; - return; - } - else if (_selectedButton != null) - { - _selectedButton.ActualButton.Pressed = false; - } - - _selectedButton = null; - SelectedScan = null; - - _selectedButton = item; - SelectedScan = item.Id; - } - - [DebuggerDisplay("cloningbutton {" + nameof(Index) + "}")] - private sealed class CloningScanButton : Control - { - public string Scan { get; set; } = default!; - public int Id { get; set; } - public Button ActualButton { get; private set; } - public Label EntityLabel { get; private set; } - public TextureRect EntityTextureRect { get; private set; } - public int Index { get; set; } - - public CloningScanButton() - { - AddChild(ActualButton = new Button - { - HorizontalExpand = true, - VerticalExpand = true, - ToggleMode = true, - }); - - AddChild(new BoxContainer - { - Orientation = LayoutOrientation.Horizontal, - Children = - { - (EntityTextureRect = new TextureRect - { - MinSize = (32, 32), - HorizontalAlignment = HAlignment.Center, - VerticalAlignment = VAlignment.Center, - Stretch = TextureRect.StretchMode.KeepAspectCentered, - CanShrink = true - }), - (EntityLabel = new Label - { - VerticalAlignment = VAlignment.Center, - HorizontalExpand = true, - Text = string.Empty, - ClipText = true - }) - } - }); - } - } - } -} diff --git a/Content.Client/CloningConsole/UI/CloningConsoleBoundUserInterface.cs b/Content.Client/CloningConsole/UI/CloningConsoleBoundUserInterface.cs new file mode 100644 index 0000000000..77b2d9e807 --- /dev/null +++ b/Content.Client/CloningConsole/UI/CloningConsoleBoundUserInterface.cs @@ -0,0 +1,51 @@ +using JetBrains.Annotations; +using Robust.Client.GameObjects; +using Content.Shared.Cloning.CloningConsole; + +namespace Content.Client.CloningConsole.UI +{ + [UsedImplicitly] + public sealed class CloningConsoleBoundUserInterface : BoundUserInterface + { + private CloningConsoleWindow? _window; + + public CloningConsoleBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) + { + } + + protected override void Open() + { + base.Open(); + _window = new CloningConsoleWindow + { + Title = Loc.GetString("cloning-console-window-title") + }; + _window.OnClose += Close; + _window.CloneButton.OnPressed += _ => SendMessage(new UiButtonPressedMessage(UiButton.Clone)); + _window.EjectButton.OnPressed += _ => SendMessage(new UiButtonPressedMessage(UiButton.Eject)); + _window.OpenCentered(); + } + + protected override void UpdateState(BoundUserInterfaceState state) + { + base.UpdateState(state); + + _window?.Populate((CloningConsoleBoundUserInterfaceState) state); + } + + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + if (!disposing) + return; + + if (_window != null) + { + _window.OnClose -= Close; + _window.CloneButton.OnPressed -= _ => SendMessage(new UiButtonPressedMessage(UiButton.Clone)); + _window.EjectButton.OnPressed -= _ => SendMessage(new UiButtonPressedMessage(UiButton.Eject)); + } + _window?.Dispose(); + } + } +} diff --git a/Content.Client/CloningConsole/UI/CloningConsoleWindow.xaml b/Content.Client/CloningConsole/UI/CloningConsoleWindow.xaml new file mode 100644 index 0000000000..7a1886a5af --- /dev/null +++ b/Content.Client/CloningConsole/UI/CloningConsoleWindow.xaml @@ -0,0 +1,65 @@ + + + + + +