163 lines
5.4 KiB
C#
163 lines
5.4 KiB
C#
using Content.Client.UserInterface.Controls;
|
|
using Content.Shared._NF.Bank;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
|
|
namespace Content.Client._NF.Bank.UI;
|
|
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class StationAdminConsoleMenu : FancyWindow
|
|
{
|
|
// TODO: reduce redundancy
|
|
public Action? WithdrawRequest;
|
|
public string? WithdrawalReason;
|
|
public string? WithdrawalDescription;
|
|
private readonly List<string> _withdrawalReasonStrings = new();
|
|
public int WithdrawalAmount;
|
|
public Action? DepositRequest;
|
|
public string? DepositReason;
|
|
public string? DepositDescription;
|
|
private readonly List<string> _depositReasonStrings = new();
|
|
public int DepositAmount;
|
|
public bool Enabled;
|
|
|
|
public static (string, string)[] WithdrawalReasonArray = {
|
|
("default", Loc.GetString("station-bank-required")),
|
|
("payroll", Loc.GetString("station-bank-payroll")),
|
|
("workorder", Loc.GetString("station-bank-work-order")),
|
|
("supplies", Loc.GetString("station-bank-supplies")),
|
|
("bounty", Loc.GetString("station-bank-bounty")),
|
|
("other", Loc.GetString("station-bank-other"))
|
|
};
|
|
|
|
public static (string, string)[] DepositReasonArray = {
|
|
("default", Loc.GetString("station-bank-required")),
|
|
("fines", Loc.GetString("station-bank-fines")),
|
|
("donation", Loc.GetString("station-bank-donation")),
|
|
("assetssold", Loc.GetString("station-bank-assets-sold")),
|
|
("other", Loc.GetString("station-bank-other"))
|
|
};
|
|
public StationAdminConsoleMenu()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
DepositButton.OnPressed += OnDepositPressed;
|
|
DepositReasons.OnItemSelected += OnDepositReasonSelected;
|
|
DepositAmountDescription.OnTextChanged += OnDepositDescChanged;
|
|
|
|
Title = Loc.GetString("station-bank-atm-menu-title");
|
|
|
|
WithdrawButton.OnPressed += OnWithdrawPressed;
|
|
WithdrawalReasons.OnItemSelected += OnWithdrawalReasonSelected;
|
|
WithdrawalAmountDescription.OnTextChanged += OnWithdrawalDescChanged;
|
|
WithdrawEdit.OnTextChanged += OnWithdrawalAmountChanged;
|
|
|
|
// Update button status to default state.
|
|
UpdateWithdrawalButtonStatus();
|
|
UpdateDepositButtonStatus();
|
|
}
|
|
|
|
private void SetWithdrawalReasonText(int id)
|
|
{
|
|
WithdrawalReason = id == 0 ? null : _withdrawalReasonStrings[id];
|
|
WithdrawalReasons.SelectId(id);
|
|
}
|
|
private void SetDepositReasonText(int id)
|
|
{
|
|
DepositReason = id == 0 ? null : _depositReasonStrings[id];
|
|
DepositReasons.SelectId(id);
|
|
}
|
|
private void OnWithdrawalReasonSelected(OptionButton.ItemSelectedEventArgs args)
|
|
{
|
|
SetWithdrawalReasonText(args.Id);
|
|
UpdateWithdrawalButtonStatus();
|
|
}
|
|
private void OnDepositReasonSelected(OptionButton.ItemSelectedEventArgs args)
|
|
{
|
|
SetDepositReasonText(args.Id);
|
|
UpdateDepositButtonStatus();
|
|
}
|
|
private void OnWithdrawalDescChanged(LineEdit.LineEditEventArgs args)
|
|
{
|
|
WithdrawalDescription = args.Text;
|
|
UpdateWithdrawalButtonStatus();
|
|
}
|
|
private void OnDepositDescChanged(LineEdit.LineEditEventArgs args)
|
|
{
|
|
DepositDescription = args.Text;
|
|
UpdateDepositButtonStatus();
|
|
}
|
|
public void SetBalance(int amount)
|
|
{
|
|
BalanceLabel.Text = BankSystemExtensions.ToSpesoString(amount);
|
|
}
|
|
|
|
public void SetDeposit(int amount)
|
|
{
|
|
if (amount >= 0) // Valid
|
|
DepositLabel.Text = BankSystemExtensions.ToSpesoString(amount);
|
|
else
|
|
DepositLabel.Text = Loc.GetString("bank-atm-menu-cash-error");
|
|
DepositAmount = amount;
|
|
UpdateDepositButtonStatus();
|
|
}
|
|
|
|
public void SetEnabled(bool enabled)
|
|
{
|
|
Enabled = enabled;
|
|
UpdateWithdrawalButtonStatus();
|
|
UpdateDepositButtonStatus();
|
|
}
|
|
|
|
private void UpdateWithdrawalButtonStatus()
|
|
{
|
|
WithdrawButton.Disabled = !Enabled || WithdrawalAmount <= 0 || WithdrawalReason == null || string.IsNullOrEmpty(WithdrawalDescription);
|
|
}
|
|
|
|
private void UpdateDepositButtonStatus()
|
|
{
|
|
DepositButton.Disabled = !Enabled || DepositAmount <= 0 || DepositReason == null || string.IsNullOrEmpty(DepositDescription);
|
|
}
|
|
|
|
private void OnWithdrawPressed(BaseButton.ButtonEventArgs obj)
|
|
{
|
|
WithdrawRequest?.Invoke();
|
|
}
|
|
|
|
private void OnDepositPressed(BaseButton.ButtonEventArgs obj)
|
|
{
|
|
DepositRequest?.Invoke();
|
|
}
|
|
|
|
private void OnWithdrawalAmountChanged(LineEdit.LineEditEventArgs args)
|
|
{
|
|
if (int.TryParse(args.Text, out var amount))
|
|
WithdrawalAmount = amount;
|
|
else
|
|
WithdrawalAmount = 0;
|
|
UpdateWithdrawalButtonStatus();
|
|
}
|
|
|
|
public void PopulateReasons()
|
|
{
|
|
_withdrawalReasonStrings.Clear();
|
|
WithdrawalReasons.Clear();
|
|
|
|
var index = 0;
|
|
foreach (var withdrawalReason in WithdrawalReasonArray)
|
|
{
|
|
_withdrawalReasonStrings.Add(withdrawalReason.Item1);
|
|
WithdrawalReasons.AddItem(withdrawalReason.Item2, index);
|
|
index++;
|
|
}
|
|
|
|
index = 0;
|
|
foreach (var depositReason in DepositReasonArray)
|
|
{
|
|
_depositReasonStrings.Add(depositReason.Item1);
|
|
DepositReasons.AddItem(depositReason.Item2, index);
|
|
index++;
|
|
}
|
|
}
|
|
}
|