From 499e9f9a0fa9b5387174cc91fa7c97c9437b2cf0 Mon Sep 17 00:00:00 2001 From: slarticodefast <161409025+slarticodefast@users.noreply.github.com> Date: Thu, 15 Jan 2026 18:17:00 +0100 Subject: [PATCH] Predict TransferAmountBoundUserInterface (#42358) prediction!!! --- .../UI/TransferAmountBoundUserInterface.cs | 46 +++++++---------- .../Chemistry/UI/TransferAmountWindow.xaml.cs | 49 +++++++++---------- .../Components/SolutionTransferComponent.cs | 31 +++++------- .../EntitySystems/SolutionTransferSystem.cs | 2 +- .../Chemistry/SharedTransferAmount.cs | 28 +++-------- 5 files changed, 63 insertions(+), 93 deletions(-) diff --git a/Content.Client/Chemistry/UI/TransferAmountBoundUserInterface.cs b/Content.Client/Chemistry/UI/TransferAmountBoundUserInterface.cs index 1bc1c0dba9..884a5db9da 100644 --- a/Content.Client/Chemistry/UI/TransferAmountBoundUserInterface.cs +++ b/Content.Client/Chemistry/UI/TransferAmountBoundUserInterface.cs @@ -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(); - public TransferAmountBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) - { - _owner = owner; - _entManager = IoCManager.Resolve(); - } + if (EntMan.TryGetComponent(Owner, out var comp)) + _window.SetBounds(comp.MinimumTransferAmount.Int(), comp.MaximumTransferAmount.Int()); - protected override void Open() + _window.ApplyButton.OnPressed += _ => { - base.Open(); - _window = this.CreateWindow(); - - if (_entManager.TryGetComponent(_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(); + } + }; } } diff --git a/Content.Client/Chemistry/UI/TransferAmountWindow.xaml.cs b/Content.Client/Chemistry/UI/TransferAmountWindow.xaml.cs index 6bae044441..2d01098213 100644 --- a/Content.Client/Chemistry/UI/TransferAmountWindow.xaml.cs +++ b/Content.Client/Chemistry/UI/TransferAmountWindow.xaml.cs @@ -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; } } diff --git a/Content.Shared/Chemistry/Components/SolutionTransferComponent.cs b/Content.Shared/Chemistry/Components/SolutionTransferComponent.cs index 2b862a83ac..149fe3f643 100644 --- a/Content.Shared/Chemistry/Components/SolutionTransferComponent.cs +++ b/Content.Shared/Chemistry/Components/SolutionTransferComponent.cs @@ -12,43 +12,36 @@ public sealed partial class SolutionTransferComponent : Component /// /// The amount of solution to be transferred from this solution when clicking on other solutions with it. /// - [DataField("transferAmount")] - [ViewVariables(VVAccess.ReadWrite)] - [AutoNetworkedField] - public FixedPoint2 TransferAmount { get; set; } = FixedPoint2.New(5); + [DataField, AutoNetworkedField] + public FixedPoint2 TransferAmount = FixedPoint2.New(5); /// /// The minimum amount of solution that can be transferred at once from this solution. /// - [DataField("minTransferAmount")] - [ViewVariables(VVAccess.ReadWrite)] - public FixedPoint2 MinimumTransferAmount { get; set; } = FixedPoint2.New(5); + [DataField("minTransferAmount"), AutoNetworkedField] + public FixedPoint2 MinimumTransferAmount = FixedPoint2.New(5); /// /// The maximum amount of solution that can be transferred at once from this solution. /// - [DataField("maxTransferAmount")] - [ViewVariables(VVAccess.ReadWrite)] - public FixedPoint2 MaximumTransferAmount { get; set; } = FixedPoint2.New(100); + [DataField("maxTransferAmount"), AutoNetworkedField] + public FixedPoint2 MaximumTransferAmount = FixedPoint2.New(100); /// /// Can this entity take reagent from reagent tanks? /// - [DataField("canReceive")] - [ViewVariables(VVAccess.ReadWrite)] - public bool CanReceive { get; set; } = true; + [DataField, AutoNetworkedField] + public bool CanReceive = true; /// /// Can this entity give reagent to other reagent containers? /// - [DataField("canSend")] - [ViewVariables(VVAccess.ReadWrite)] - public bool CanSend { get; set; } = true; + [DataField, AutoNetworkedField] + public bool CanSend = true; /// /// Whether you're allowed to change the transfer amount. /// - [DataField("canChangeTransferAmount")] - [ViewVariables(VVAccess.ReadWrite)] - public bool CanChangeTransferAmount { get; set; } = false; + [DataField, AutoNetworkedField] + public bool CanChangeTransferAmount = false; } diff --git a/Content.Shared/Chemistry/EntitySystems/SolutionTransferSystem.cs b/Content.Shared/Chemistry/EntitySystems/SolutionTransferSystem.cs index 4d78ab4647..8fe17368cc 100644 --- a/Content.Shared/Chemistry/EntitySystems/SolutionTransferSystem.cs +++ b/Content.Shared/Chemistry/EntitySystems/SolutionTransferSystem.cs @@ -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); } diff --git a/Content.Shared/Chemistry/SharedTransferAmount.cs b/Content.Shared/Chemistry/SharedTransferAmount.cs index 1d95d2d687..c535f5d307 100644 --- a/Content.Shared/Chemistry/SharedTransferAmount.cs +++ b/Content.Shared/Chemistry/SharedTransferAmount.cs @@ -3,28 +3,16 @@ using Robust.Shared.Serialization; namespace Content.Shared.Chemistry { + /// + /// Send by the client when setting the transfer amount using the BUI. + /// [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; - } + /// + /// The new transfer amount. + /// + public FixedPoint2 Value = value; } [Serializable, NetSerializable] -- 2.52.0