Skip to content

Commit

Permalink
Bug fixes for Store UIs with multiple currencies (space-wizards#33565)
Browse files Browse the repository at this point in the history
Fixed stores with multiple currencies having bad formatting and non-functional withdraw screens
  • Loading branch information
TGRCdev authored Dec 16, 2024
1 parent 51a45ae commit 1266b05
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
5 changes: 4 additions & 1 deletion Content.Client/Store/Ui/StoreMenu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void UpdateBalance(Dictionary<ProtoId<CurrencyPrototype>, FixedPoint2> ba
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());
Expand All @@ -63,7 +63,10 @@ public void UpdateBalance(Dictionary<ProtoId<CurrencyPrototype>, FixedPoint2> ba
foreach (var type in currency)
{
if (type.Value.CanWithdraw && type.Value.Cash != null && type.Key.Item2 > 0)
{
disabled = false;
break;
}
}

WithdrawButton.Disabled = disabled;
Expand Down
17 changes: 10 additions & 7 deletions Content.Client/Store/Ui/StoreWithdrawWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -36,7 +36,7 @@ public void CreateCurrencyButtons(Dictionary<ProtoId<CurrencyPrototype>, FixedPo
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
Expand All @@ -47,14 +47,17 @@ public void CreateCurrencyButtons(Dictionary<ProtoId<CurrencyPrototype>, FixedPo
_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);
Expand All @@ -65,7 +68,7 @@ public void CreateCurrencyButtons(Dictionary<ProtoId<CurrencyPrototype>, FixedPo
ButtonContainer.AddChild(button);
}

var maxWithdrawAmount = _validCurrencies.Keys.Max().Int();
var maxWithdrawAmount = _validCurrencies.Values.Max().Int();

// setup withdraw slider
WithdrawSlider.MinValue = 1;
Expand Down

0 comments on commit 1266b05

Please sign in to comment.