]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Bug fixes for Store UIs with multiple currencies (#33565)
authorTGRCDev <tgrc@tgrc.dev>
Mon, 16 Dec 2024 11:57:11 +0000 (06:57 -0500)
committerGitHub <noreply@github.com>
Mon, 16 Dec 2024 11:57:11 +0000 (14:57 +0300)
Fixed stores with multiple currencies having bad formatting and non-functional withdraw screens

Content.Client/Store/Ui/StoreMenu.xaml.cs
Content.Client/Store/Ui/StoreWithdrawWindow.xaml.cs

index ae38be1115ad7e125444092581d2f2d9d20737be..260bcfe4f260fc1be0dd80b55858d6c31ebae085 100644 (file)
@@ -54,7 +54,7 @@ public sealed partial class StoreMenu : DefaultWindow
         foreach (var ((_, amount), proto) in currency)
         {
             balanceStr += Loc.GetString("store-ui-balance-display", ("amount", amount),
-                ("currency", Loc.GetString(proto.DisplayName, ("amount", 1))));
+                ("currency", Loc.GetString(proto.DisplayName, ("amount", 1)))) + "\n";
         }
 
         BalanceInfo.SetMarkup(balanceStr.TrimEnd());
@@ -63,7 +63,10 @@ public sealed partial class StoreMenu : DefaultWindow
         foreach (var type in currency)
         {
             if (type.Value.CanWithdraw && type.Value.Cash != null && type.Key.Item2 > 0)
+            {
                 disabled = false;
+                break;
+            }
         }
 
         WithdrawButton.Disabled = disabled;
index 793685575621b9bc1898fa37076536ecd8c9c9de..a8b93cd2b3a010a8831821bf7b276ad124a51555 100644 (file)
@@ -18,7 +18,7 @@ public sealed partial class StoreWithdrawWindow : DefaultWindow
 {
     [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
 
-    private Dictionary<FixedPoint2, CurrencyPrototype> _validCurrencies = new();
+    private Dictionary<CurrencyPrototype, FixedPoint2> _validCurrencies = new();
     private HashSet<CurrencyWithdrawButton> _buttons = new();
     public event Action<BaseButton.ButtonEventArgs, string, int>? OnWithdrawAttempt;
 
@@ -36,7 +36,7 @@ public sealed partial class StoreWithdrawWindow : DefaultWindow
             if (!_prototypeManager.TryIndex(currency.Key, out var proto))
                 continue;
 
-            _validCurrencies.Add(currency.Value, proto);
+            _validCurrencies.Add(proto, currency.Value);
         }
 
         //this shouldn't ever happen but w/e
@@ -47,14 +47,17 @@ public sealed partial class StoreWithdrawWindow : DefaultWindow
         _buttons.Clear();
         foreach (var currency in _validCurrencies)
         {
+            if (!currency.Key.CanWithdraw)
+                continue;
+
             var button = new CurrencyWithdrawButton()
             {
-                Id = currency.Value.ID,
-                Amount = currency.Key,
+                Id = currency.Key.ID,
+                Amount = currency.Value,
                 MinHeight = 20,
-                Text = Loc.GetString("store-withdraw-button-ui", ("currency",Loc.GetString(currency.Value.DisplayName, ("amount", currency.Key)))),
+                Text = Loc.GetString("store-withdraw-button-ui", ("currency",Loc.GetString(currency.Key.DisplayName, ("amount", currency.Value)))),
+                Disabled = false,
             };
-            button.Disabled = false;
             button.OnPressed += args =>
             {
                 OnWithdrawAttempt?.Invoke(args, button.Id, WithdrawSlider.Value);
@@ -65,7 +68,7 @@ public sealed partial class StoreWithdrawWindow : DefaultWindow
             ButtonContainer.AddChild(button);
         }
 
-        var maxWithdrawAmount = _validCurrencies.Keys.Max().Int();
+        var maxWithdrawAmount = _validCurrencies.Values.Max().Int();
 
         // setup withdraw slider
         WithdrawSlider.MinValue = 1;