]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Predict TransferAmountBoundUserInterface (#42358)
authorslarticodefast <161409025+slarticodefast@users.noreply.github.com>
Thu, 15 Jan 2026 17:17:00 +0000 (18:17 +0100)
committerGitHub <noreply@github.com>
Thu, 15 Jan 2026 17:17:00 +0000 (17:17 +0000)
prediction!!!

Content.Client/Chemistry/UI/TransferAmountBoundUserInterface.cs
Content.Client/Chemistry/UI/TransferAmountWindow.xaml.cs
Content.Shared/Chemistry/Components/SolutionTransferComponent.cs
Content.Shared/Chemistry/EntitySystems/SolutionTransferSystem.cs
Content.Shared/Chemistry/SharedTransferAmount.cs

index 1bc1c0dba9abd8a46d3cdd50ebaf02377e0e792a..884a5db9da05a1abd3de9ac9e6334554b0aa9120 100644 (file)
@@ -2,41 +2,31 @@ using Content.Shared.Chemistry;
 using Content.Shared.Chemistry.Components;
 using Content.Shared.FixedPoint;
 using JetBrains.Annotations;
-using Robust.Client.GameObjects;
 using Robust.Client.UserInterface;
 
-namespace Content.Client.Chemistry.UI
+namespace Content.Client.Chemistry.UI;
+
+[UsedImplicitly]
+public sealed class TransferAmountBoundUserInterface(EntityUid owner, Enum uiKey) : BoundUserInterface(owner, uiKey)
 {
-    [UsedImplicitly]
-    public sealed class TransferAmountBoundUserInterface : BoundUserInterface
+    [ViewVariables]
+    private TransferAmountWindow? _window;
+
+    protected override void Open()
     {
-        private IEntityManager _entManager;
-        private EntityUid _owner;
-        [ViewVariables]
-        private TransferAmountWindow? _window;
+        base.Open();
+        _window = this.CreateWindow<TransferAmountWindow>();
 
-        public TransferAmountBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
-        {
-          _owner = owner;
-          _entManager = IoCManager.Resolve<IEntityManager>();
-        }
+        if (EntMan.TryGetComponent<SolutionTransferComponent>(Owner, out var comp))
+            _window.SetBounds(comp.MinimumTransferAmount.Int(), comp.MaximumTransferAmount.Int());
 
-        protected override void Open()
+        _window.ApplyButton.OnPressed += _ =>
         {
-            base.Open();
-            _window = this.CreateWindow<TransferAmountWindow>();
-
-            if (_entManager.TryGetComponent<SolutionTransferComponent>(_owner, out var comp))
-                _window.SetBounds(comp.MinimumTransferAmount.Int(), comp.MaximumTransferAmount.Int());
-
-            _window.ApplyButton.OnPressed += _ =>
+            if (int.TryParse(_window.AmountLineEdit.Text, out var i))
             {
-                if (int.TryParse(_window.AmountLineEdit.Text, out var i))
-                {
-                    SendMessage(new TransferAmountSetValueMessage(FixedPoint2.New(i)));
-                    _window.Close();
-                }
-            };
-        }
+                SendPredictedMessage(new TransferAmountSetValueMessage(FixedPoint2.New(i)));
+                _window.Close();
+            }
+        };
     }
 }
index 6bae04444155e8fab29024f65e2f5ad531336231..2d010982138510da46cb70a4863591607fa519c7 100644 (file)
@@ -3,34 +3,33 @@ using Robust.Client.UserInterface.Controls;
 using Robust.Client.UserInterface.CustomControls;
 using Robust.Client.UserInterface.XAML;
 
-namespace Content.Client.Chemistry.UI
+namespace Content.Client.Chemistry.UI;
+
+[GenerateTypedNameReferences]
+public sealed partial class TransferAmountWindow : DefaultWindow
 {
-    [GenerateTypedNameReferences]
-    public sealed partial class TransferAmountWindow : DefaultWindow
-    {
-        private int _max = Int32.MaxValue;
-        private int _min = 1;
+    private int _max = Int32.MaxValue;
+    private int _min = 1;
 
-        public TransferAmountWindow()
-        {
-            RobustXamlLoader.Load(this);
-            AmountLineEdit.OnTextChanged += OnValueChanged;
-        }
+    public TransferAmountWindow()
+    {
+        RobustXamlLoader.Load(this);
+        AmountLineEdit.OnTextChanged += OnValueChanged;
+    }
 
-        public void SetBounds(int min, int max)
-        {
-          _min = min;
-          _max = max;
-          MinimumAmount.Text = Loc.GetString("comp-solution-transfer-set-amount-min", ("amount", _min));
-          MaximumAmount.Text = Loc.GetString("comp-solution-transfer-set-amount-max", ("amount", _max));
-        }
+    public void SetBounds(int min, int max)
+    {
+        _min = min;
+        _max = max;
+        MinimumAmount.Text = Loc.GetString("comp-solution-transfer-set-amount-min", ("amount", _min));
+        MaximumAmount.Text = Loc.GetString("comp-solution-transfer-set-amount-max", ("amount", _max));
+    }
 
-        private void OnValueChanged(LineEdit.LineEditEventArgs args)
-        {
-            if (!int.TryParse(AmountLineEdit.Text, out var amount)  || amount > _max || amount < _min)
-                ApplyButton.Disabled = true;
-            else 
-                ApplyButton.Disabled = false; 
-        }
+    private void OnValueChanged(LineEdit.LineEditEventArgs args)
+    {
+        if (!int.TryParse(AmountLineEdit.Text, out var amount) || amount > _max || amount < _min)
+            ApplyButton.Disabled = true;
+        else
+            ApplyButton.Disabled = false;
     }
 }
index 2b862a83ac83c354c080cfb271bbeb71058e6fd4..149fe3f643e9a59f93c93e2318236c6faec3d536 100644 (file)
@@ -12,43 +12,36 @@ public sealed partial class SolutionTransferComponent : Component
     /// <summary>
     ///     The amount of solution to be transferred from this solution when clicking on other solutions with it.
     /// </summary>
-    [DataField("transferAmount")]
-    [ViewVariables(VVAccess.ReadWrite)]
-    [AutoNetworkedField]
-    public FixedPoint2 TransferAmount { get; set; } = FixedPoint2.New(5);
+    [DataField, AutoNetworkedField]
+    public FixedPoint2 TransferAmount = FixedPoint2.New(5);
 
     /// <summary>
     ///     The minimum amount of solution that can be transferred at once from this solution.
     /// </summary>
-    [DataField("minTransferAmount")]
-    [ViewVariables(VVAccess.ReadWrite)]
-    public FixedPoint2 MinimumTransferAmount { get; set; } = FixedPoint2.New(5);
+    [DataField("minTransferAmount"), AutoNetworkedField]
+    public FixedPoint2 MinimumTransferAmount = FixedPoint2.New(5);
 
     /// <summary>
     ///     The maximum amount of solution that can be transferred at once from this solution.
     /// </summary>
-    [DataField("maxTransferAmount")]
-    [ViewVariables(VVAccess.ReadWrite)]
-    public FixedPoint2 MaximumTransferAmount { get; set; } = FixedPoint2.New(100);
+    [DataField("maxTransferAmount"), AutoNetworkedField]
+    public FixedPoint2 MaximumTransferAmount = FixedPoint2.New(100);
 
     /// <summary>
     ///     Can this entity take reagent from reagent tanks?
     /// </summary>
-    [DataField("canReceive")]
-    [ViewVariables(VVAccess.ReadWrite)]
-    public bool CanReceive { get; set; } = true;
+    [DataField, AutoNetworkedField]
+    public bool CanReceive = true;
 
     /// <summary>
     ///     Can this entity give reagent to other reagent containers?
     /// </summary>
-    [DataField("canSend")]
-    [ViewVariables(VVAccess.ReadWrite)]
-    public bool CanSend { get; set; } = true;
+    [DataField, AutoNetworkedField]
+    public bool CanSend = true;
 
     /// <summary>
     /// Whether you're allowed to change the transfer amount.
     /// </summary>
-    [DataField("canChangeTransferAmount")]
-    [ViewVariables(VVAccess.ReadWrite)]
-    public bool CanChangeTransferAmount { get; set; } = false;
+    [DataField, AutoNetworkedField]
+    public bool CanChangeTransferAmount = false;
 }
index 4d78ab464707b43dad3ceb115218450726d07dd3..8fe17368cc0e4d90e288b6037f37e6c7771ce690 100644 (file)
@@ -99,7 +99,7 @@ public sealed class SolutionTransferSystem : EntitySystem
         ent.Comp.TransferAmount = newTransferAmount;
 
         if (message.Actor is { Valid: true } user)
-            _popup.PopupEntity(Loc.GetString("comp-solution-transfer-set-amount", ("amount", newTransferAmount)), ent.Owner, user);
+            _popup.PopupClient(Loc.GetString("comp-solution-transfer-set-amount", ("amount", newTransferAmount)), ent.Owner, user);
 
         Dirty(ent.Owner, ent.Comp);
     }
index 1d95d2d687d20c54364ea176479d9a997d02f124..c535f5d3072607b26ae82de5ef9188eb43500478 100644 (file)
@@ -3,28 +3,16 @@ using Robust.Shared.Serialization;
 
 namespace Content.Shared.Chemistry
 {
+    /// <summary>
+    /// Send by the client when setting the transfer amount using the BUI.
+    /// </summary>
     [Serializable, NetSerializable]
-    public sealed class TransferAmountBoundInterfaceState : BoundUserInterfaceState
+    public sealed class TransferAmountSetValueMessage(FixedPoint2 value) : BoundUserInterfaceMessage
     {
-        public FixedPoint2 Max;
-        public FixedPoint2 Min;
-
-        public TransferAmountBoundInterfaceState(FixedPoint2 max, FixedPoint2 min)
-        {
-            Max = max;
-            Min = min;
-        }
-    }
-
-    [Serializable, NetSerializable]
-    public sealed class TransferAmountSetValueMessage : BoundUserInterfaceMessage
-    {
-        public FixedPoint2 Value;
-
-        public TransferAmountSetValueMessage(FixedPoint2 value)
-        {
-            Value = value;
-        }
+        /// <summary>
+        /// The new transfer amount.
+        /// </summary>
+        public FixedPoint2 Value = value;
     }
 
     [Serializable, NetSerializable]