Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Station Bank Deposits #361

Merged
merged 4 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Content.Client/Bank/BUI/StationBankATMMenuBoundUserInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ protected override void Open()

_menu = new StationBankATMMenu();
_menu.WithdrawRequest += OnWithdraw;
_menu.DepositRequest += OnDeposit;
_menu.OnClose += Close;
_menu.PopulateReasons();
_menu.OpenCentered();
Expand All @@ -40,6 +41,14 @@ private void OnWithdraw()
SendMessage(new StationBankWithdrawMessage(amount, _menu.Reason, _menu.Description));
}

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

SendMessage(new StationBankDepositMessage(amount, _menu.Reason, _menu.Description));
}

protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
Expand All @@ -49,5 +58,6 @@ protected override void UpdateState(BoundUserInterfaceState state)

_menu?.SetEnabled(bankState.Enabled);
_menu?.SetBalance(bankState.Balance);
_menu?.SetDeposit(bankState.Deposit);
}
}
15 changes: 12 additions & 3 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 180"
MinSize="360 180">
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 All @@ -27,10 +27,19 @@
<Label Text="{Loc 'bank-atm-description-label'}"
StyleClasses="LabelKeyText"
MinSize="100 0" />
<LineEdit Name="WithdrawDescription" MinSize="120 0" HorizontalExpand="True"/>
<LineEdit Name="AmountDescription" MinSize="120 0" HorizontalExpand="True"/>
</BoxContainer>
<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" />
</BoxContainer>
</controls:FancyWindow>
16 changes: 15 additions & 1 deletion Content.Client/Bank/UI/StationBankATMMenu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Content.Client.Bank.UI;
public sealed partial class StationBankATMMenu : FancyWindow
{
public Action? WithdrawRequest;
public Action? DepositRequest;
public int Amount;
private readonly List<string> _reasonStrings = new();
public string? Reason;
Expand All @@ -17,10 +18,11 @@ public StationBankATMMenu()
{
RobustXamlLoader.Load(this);
WithdrawButton.OnPressed += OnWithdrawPressed;
DepositButton.OnPressed += OnDepositPressed;
Title = Loc.GetString("station-bank-atm-menu-title");
WithdrawEdit.OnTextChanged += OnAmountChanged;
Reasons.OnItemSelected += OnReasonSelected;
WithdrawDescription.OnTextChanged += OnDescChanged;
AmountDescription.OnTextChanged += OnDescChanged;
}

private void SetReasonText(int id)
Expand All @@ -37,16 +39,28 @@ 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;
DepositButton.Disabled = !enabled;
}

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

private void OnDepositPressed(BaseButton.ButtonEventArgs obj)
{
DepositRequest?.Invoke();
}

private void OnAmountChanged(LineEdit.LineEditEventArgs args)
{
if (int.TryParse(args.Text, out var amount))
Expand Down
6 changes: 6 additions & 0 deletions Content.Server/Cargo/Systems/CargoSystem.Orders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,12 @@ public void DeductFunds(StationBankAccountComponent component, int amount)
Dirty(component);
}

public void IncreaseFunds(StationBankAccountComponent component, int amount)
{
component.Balance = Math.Max(0, component.Balance + amount);
Dirty(component);
}

dvir001 marked this conversation as resolved.
Show resolved Hide resolved
#region Station

private StationBankAccountComponent? GetBankAccount(EntityUid uid, CargoOrderConsoleComponent _)
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
1 change: 1 addition & 0 deletions Content.Server/_NF/Bank/BankSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Content.Shared.Preferences;
using Robust.Shared.GameStates;
using Robust.Shared.Network;
using Content.Server.Cargo.Components;

namespace Content.Server.Bank;

Expand Down
Loading
Loading