using Content.Shared.Chemistry;
+using Content.Shared.Chemistry.Components;
using Content.Shared.FixedPoint;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
[UsedImplicitly]
public sealed class TransferAmountBoundUserInterface : BoundUserInterface
{
+ private IEntityManager _entManager;
+ private EntityUid _owner;
[ViewVariables]
private TransferAmountWindow? _window;
public TransferAmountBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
+ _owner = owner;
+ _entManager = IoCManager.Resolve<IEntityManager>();
}
protected override void Open()
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))
<BoxContainer Orientation="Horizontal">
<LineEdit Name="AmountLineEdit" Access="Public" HorizontalExpand="True" PlaceHolder="{Loc 'ui-transfer-amount-line-edit-placeholder'}"/>
</BoxContainer>
+ <BoxContainer Orientation="Horizontal">
+ <Label Name="MinimumAmount" Access="Public" HorizontalExpand="True" />
+ <Label Name="MaximumAmount" Access="Public" />
+ </BoxContainer>
<Button Name="ApplyButton" Access="Public" Text="{Loc 'ui-transfer-amount-apply'}"/>
</BoxContainer>
</DefaultWindow>
[GenerateTypedNameReferences]
public sealed partial class TransferAmountWindow : DefaultWindow
{
+ private int _max = Int32.MaxValue;
+ private int _min = 1;
+
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));
+ }
+
+ 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;
}
}
}
## Displayed after you successfully change a solution's amount using the BUI
comp-solution-transfer-set-amount = Transfer amount set to {$amount}u.
+comp-solution-transfer-set-amount-max = Max: {$amount}u
+comp-solution-transfer-set-amount-min = Min: {$amount}u
+