Skip to content

Commit

Permalink
withdrawals
Browse files Browse the repository at this point in the history
  • Loading branch information
LankLTE committed Jul 12, 2023
1 parent 25882b3 commit 8350038
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 137 deletions.
51 changes: 51 additions & 0 deletions Content.Client/Bank/BUI/WithdrawlBankATMMenuBoundUserInterface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Content.Client.Bank.UI;
using Content.Shared.Bank.BUI;
using Content.Shared.Bank.Events;
using Robust.Client.GameObjects;

namespace Content.Client.Cargo.BUI;

public sealed class WithdrawBankATMMenuBoundUserInterface : BoundUserInterface
{
private WithdrawBankATMMenu? _menu;

public WithdrawBankATMMenuBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) {}

protected override void Open()
{
base.Open();

_menu = new WithdrawBankATMMenu();
_menu.WithdrawRequest += OnWithdraw;
_menu.OnClose += Close;
_menu.OpenCentered();
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
_menu?.Dispose();
}
}

private void OnWithdraw()
{
if (_menu?.Amount is not int amount)
return;

SendMessage(new BankWithdrawMessage(amount));
}

protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);

if (state is not BankATMMenuInterfaceState bankState)
return;

_menu?.SetEnabled(bankState.Enabled);
_menu?.SetBalance(bankState.Balance);
}
}
44 changes: 44 additions & 0 deletions Content.Client/Bank/UI/WithdrawBankATMMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Content.Client.UserInterface.Controls;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;

namespace Content.Client.Bank.UI;

[GenerateTypedNameReferences]
public sealed partial class WithdrawBankATMMenu : FancyWindow
{
public Action? WithdrawRequest;
public Action? DepositRequest;
public int Amount;
public WithdrawBankATMMenu()
{
RobustXamlLoader.Load(this);
WithdrawButton.OnPressed += OnWithdrawPressed;
Title = Loc.GetString("bank-atm-menu-title");
WithdrawEdit.OnTextChanged += OnAmountChanged;
}

public void SetBalance(int amount)
{
BalanceLabel.Text = Loc.GetString("cargo-console-menu-points-amount", ("amount", amount.ToString()));
}

public void SetEnabled(bool enabled)
{
WithdrawButton.Disabled = !enabled;
}

private void OnWithdrawPressed(BaseButton.ButtonEventArgs obj)
{
WithdrawRequest?.Invoke();
}

private void OnAmountChanged(LineEdit.LineEditEventArgs args)
{
if (int.TryParse(args.Text, out var amount))
{
Amount = amount;
}
}
}
17 changes: 17 additions & 0 deletions Content.Client/Bank/UI/WithdrawBankATMMenu.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<controls:FancyWindow xmlns="https://spacestation14.io"
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
SetSize="300 120"
MinSize="300 120">
<BoxContainer Margin="10 2 10 2" Orientation="Vertical">
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc 'bank-atm-menu-balance-label'}"
StyleClasses="LabelKeyText" />
<Label Name="BalanceLabel"
Text="{Loc 'bank-atm-menu-no-bank'}" />
</BoxContainer>
<LineEdit Name="WithdrawEdit" MinSize="80 0" />
<Button Name="WithdrawButton"
Text="{Loc 'bank-atm-menu-withdraw-button'}"/>
</BoxContainer>
</controls:FancyWindow>
3 changes: 2 additions & 1 deletion Content.Shared/_NF/Bank/SharedBankSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace Content.Shared.Bank;
public enum BankATMMenuUiKey : byte
{
ATM,
StationATM
StationATM,
WithdrawATM
}

public sealed partial class SharedBankSystem : EntitySystem
Expand Down
Loading

0 comments on commit 8350038

Please sign in to comment.