Skip to content

Commit

Permalink
Bank
Browse files Browse the repository at this point in the history
  • Loading branch information
dvir001 committed Sep 27, 2023
1 parent 283631c commit 43c7d63
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@ protected override void UpdateState(BoundUserInterfaceState state)

_menu?.SetEnabled(bankState.Enabled);
_menu?.SetBalance(bankState.Balance);
_menu?.SetDeposit(bankState.Deposit);
}
}
10 changes: 8 additions & 2 deletions Content.Client/Bank/UI/StationBankATMMenu.xaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<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="480 210"
MinSize="360 210">
SetSize="480 230"
MinSize="360 230">
<BoxContainer Margin="10 2 10 2" Orientation="Vertical">
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc 'bank-atm-menu-balance-label'}"
Expand Down Expand Up @@ -32,6 +32,12 @@
<Button Name="WithdrawButton"
Text="{Loc 'bank-atm-menu-withdraw-button'}"/>
<TextureButton VerticalExpand="True" />
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc 'bank-atm-menu-deposit-label'}"
StyleClasses="LabelKeyText" />
<Label Name="DepositLabel"
Text="{Loc 'bank-atm-menu-no-deposit'}" />
</BoxContainer>
<Button Name="DepositButton"
Text="{Loc 'bank-atm-menu-deposit-button'}"/>
<TextureButton VerticalExpand="True" />
Expand Down
6 changes: 6 additions & 0 deletions Content.Client/Bank/UI/StationBankATMMenu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public void SetBalance(int amount)
BalanceLabel.Text = Loc.GetString("cargo-console-menu-points-amount", ("amount", amount.ToString()));
}

public void SetDeposit(int amount)
{
DepositButton.Disabled = amount <= 0;
DepositLabel.Text = Loc.GetString("cargo-console-menu-points-amount", ("amount", amount.ToString()));
}

public void SetEnabled(bool enabled)
{
WithdrawButton.Disabled = !enabled;
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/_NF/Bank/ATMSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ private void OnDeposit(EntityUid uid, BankATMComponent component, BankDepositMes
new BankATMMenuInterfaceState(bank.Balance, true, 0));
return;
}

private void OnCashSlotChanged(EntityUid uid, BankATMComponent component, ContainerModifiedMessage args)
{

var bankUi = _uiSystem.GetUiOrNull(uid, BankATMMenuUiKey.ATM) ?? _uiSystem.GetUiOrNull(uid, BankATMMenuUiKey.BlackMarket);

var uiUser = bankUi!.SubscribedSessions.FirstOrDefault();
Expand Down
57 changes: 39 additions & 18 deletions Content.Server/_NF/Bank/StationATMSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,17 @@ private void OnDeposit(EntityUid uid, StationBankATMComponent component, Station
// try to deposit the inserted cash into a player's bank acount.
if (args.Amount <= 0)
{
_log.Info($"{args.Amount} is invalid");
ConsolePopup(args.Session, Loc.GetString("bank-atm-menu-transaction-denied"));
PlayDenySound(uid, component);
_log.Info($"{args.Amount} is invalid");
return;
}

if (deposit <= args.Amount)
if (deposit < args.Amount)
{
_log.Info($"{args.Amount} is more then {deposit}");
ConsolePopup(args.Session, Loc.GetString("bank-insufficient-funds"));
PlayDenySound(uid, component);
_log.Info($"{args.Amount} is more then {deposit}");
return;
}

Expand All @@ -196,37 +196,34 @@ private void OnDeposit(EntityUid uid, StationBankATMComponent component, Station

_adminLogger.Add(LogType.ATMUsage, LogImpact.Low, $"{ToPrettyString(player):actor} deposited {args.Amount} to station bank account. '{args.Reason}': {args.Description}");

// yeet and delete the stack in the cash slot after success
_containerSystem.CleanContainer(cashSlot); // TODO: Fix this to remove parts
SetInsertedCashAmount(component, args.Amount, out int leftAmount, out bool empty);

// yeet and delete the stack in the cash slot after success if its worth 0
if (empty)
_containerSystem.CleanContainer(cashSlot);

_uiSystem.SetUiState(bui,
new StationBankATMMenuInterfaceState(stationBank.Balance, _access.IsAllowed(player, uid), 0));
new StationBankATMMenuInterfaceState(stationBank.Balance, _access.IsAllowed(player, uid), leftAmount));
}

private void OnCashSlotChanged(EntityUid uid, StationBankATMComponent component, ContainerModifiedMessage args)
{

var bankUi = _uiSystem.GetUiOrNull(uid, BankATMMenuUiKey.ATM) ?? _uiSystem.GetUiOrNull(uid, BankATMMenuUiKey.BlackMarket);

var uiUser = bankUi!.SubscribedSessions.FirstOrDefault();
GetInsertedCashAmount(component, out var deposit);
var bui = _uiSystem.GetUi(component.Owner, BankATMMenuUiKey.ATM);
var station = _station.GetOwningStation(uid);

if (uiUser?.AttachedEntity is not { Valid: true } player)
{
return;
}

if (!TryComp<StationBankAccountComponent>(player, out var bank))
if (!TryComp<StationBankAccountComponent>(station, out var bank))
{
return;
}

if (component.CashSlot.ContainerSlot?.ContainedEntity is not { Valid: true } cash)
{
_uiSystem.SetUiState(bankUi,
_uiSystem.SetUiState(bui,
new StationBankATMMenuInterfaceState(bank.Balance, true, 0));
}

_uiSystem.SetUiState(bankUi,
_uiSystem.SetUiState(bui,
new StationBankATMMenuInterfaceState(bank.Balance, true, deposit));
}

Expand All @@ -238,6 +235,7 @@ private void OnATMUIOpen(EntityUid uid, StationBankATMComponent component, Bound
GetInsertedCashAmount(component, out var deposit);
var bui = _uiSystem.GetUi(component.Owner, BankATMMenuUiKey.ATM);
var station = _station.GetOwningStation(uid);

if (!TryComp<StationBankAccountComponent>(station, out var stationBank))
{
_log.Info($"{station} has no bank account");
Expand All @@ -249,6 +247,7 @@ private void OnATMUIOpen(EntityUid uid, StationBankATMComponent component, Bound
_uiSystem.SetUiState(bui,
new StationBankATMMenuInterfaceState(stationBank.Balance, _access.IsAllowed(player, uid), deposit));
}

private void GetInsertedCashAmount(StationBankATMComponent component, out int amount)
{
amount = 0;
Expand All @@ -264,6 +263,28 @@ private void GetInsertedCashAmount(StationBankATMComponent component, out int am
return;
}

private void SetInsertedCashAmount(StationBankATMComponent component, int amount, out int leftAmount, out bool empty)
{
leftAmount = 0;
empty = false;
var cashEntity = component.CashSlot.ContainerSlot?.ContainedEntity;

if (!TryComp<StackComponent>(cashEntity, out var cashStack) ||
cashStack.StackTypeId != component.CashType)
{
return;
}

int newAmount = cashStack.Count;
cashStack.Count = newAmount - amount;
leftAmount = cashStack.Count;

if (cashStack.Count <= 0)
empty = true;

return;
}

private void PlayDenySound(EntityUid uid, StationBankATMComponent component)
{
_audio.PlayPvs(_audio.GetSound(component.ErrorSound), uid);
Expand Down

0 comments on commit 43c7d63

Please sign in to comment.