]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
add(TransferAmountWindow): QoL stuff (#30464)
authorBrandon Hu <103440971+Brandon-Huu@users.noreply.github.com>
Fri, 2 Aug 2024 01:20:36 +0000 (01:20 +0000)
committerGitHub <noreply@github.com>
Fri, 2 Aug 2024 01:20:36 +0000 (11:20 +1000)
* ugh

Content.Client/Chemistry/UI/TransferAmountBoundUserInterface.cs
Content.Client/Chemistry/UI/TransferAmountWindow.xaml
Content.Client/Chemistry/UI/TransferAmountWindow.xaml.cs
Resources/Locale/en-US/chemistry/components/solution-transfer-component.ftl

index f1cb27a62a4217957e4a4ff6ccf65b0139550c43..1bc1c0dba9abd8a46d3cdd50ebaf02377e0e792a 100644 (file)
@@ -1,4 +1,5 @@
 using Content.Shared.Chemistry;
+using Content.Shared.Chemistry.Components;
 using Content.Shared.FixedPoint;
 using JetBrains.Annotations;
 using Robust.Client.GameObjects;
@@ -9,11 +10,15 @@ namespace Content.Client.Chemistry.UI
     [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()
@@ -21,6 +26,9 @@ namespace Content.Client.Chemistry.UI
             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))
index 3d787c69c104e93641e19914712690913a456432..c73d86b10f1536e890352ee438548ee171da36f0 100644 (file)
@@ -6,6 +6,10 @@
         <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>
index 767e5cc8230d40c07ad8e488cb99cbe87604c4b4..6bae04444155e8fab29024f65e2f5ad531336231 100644 (file)
@@ -8,9 +8,29 @@ namespace Content.Client.Chemistry.UI
     [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; 
         }
     }
 }
index 601392069b09fb002c94e183d30edf09d15018fe..b966a9cc61d2bd52452f4cd03c299316557702a6 100644 (file)
@@ -15,3 +15,6 @@ comp-solution-transfer-verb-toggle = Toggle to {$amount}u
 
 ## 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
+