93 lines
2.7 KiB
C#
93 lines
2.7 KiB
C#
using Content.Shared._NF.Bank;
|
|
using Content.Shared._NF.Bank.BUI;
|
|
using Content.Shared._NF.Bank.Components;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Client.UserInterface.XAML;
|
|
|
|
namespace Content.Client._NF.CartridgeLoader.Cartridges;
|
|
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class LedgerTab : Control
|
|
{
|
|
public SectorBankAccount Account = SectorBankAccount.Invalid;
|
|
private int _totalIncome = 0;
|
|
private int _totalExpenses = 0;
|
|
private bool _hasIncome = false;
|
|
private bool _hasExpenses = false;
|
|
|
|
private static readonly Color IncomeColor = Color.FromHex("#80FF80");
|
|
private static readonly Color ExpenseColor = Color.FromHex("#FF8080");
|
|
|
|
public LedgerTab()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
}
|
|
|
|
public LedgerTab(SectorBankAccount account)
|
|
{
|
|
Account = account;
|
|
RobustXamlLoader.Load(this);
|
|
}
|
|
|
|
public void ClearLedgerEntries()
|
|
{
|
|
IncomeList.Children.Clear();
|
|
ExpenseList.Children.Clear();
|
|
_hasIncome = false;
|
|
_hasExpenses = false;
|
|
_totalIncome = 0;
|
|
_totalExpenses = 0;
|
|
InvalidateMeasure();
|
|
}
|
|
|
|
public void AddLedgerEntry(LedgerEntryType type, int amount)
|
|
{
|
|
if (amount <= 0)
|
|
return;
|
|
|
|
var isExpense = type >= LedgerEntryType.FirstExpense;
|
|
var list = isExpense ? ExpenseList : IncomeList;
|
|
if (isExpense)
|
|
{
|
|
_totalExpenses += amount;
|
|
_hasExpenses = true;
|
|
}
|
|
else
|
|
{
|
|
_totalIncome += amount;
|
|
_hasIncome = true;
|
|
}
|
|
|
|
var ledgerEntry = new LedgerEntry();
|
|
ledgerEntry.Description.Text = Loc.GetString($"ledger-entry-type-{type}");
|
|
ledgerEntry.Value.Text = BankSystemExtensions.ToSpesoString(amount);
|
|
ledgerEntry.Value.FontColorOverride = isExpense ? ExpenseColor : IncomeColor;
|
|
|
|
list.AddChild(ledgerEntry);
|
|
list.InvalidateMeasure();
|
|
}
|
|
|
|
public void UpdateTotals()
|
|
{
|
|
if (_hasIncome)
|
|
IncomeValue.Text = BankSystemExtensions.ToSpesoString(_totalIncome);
|
|
else
|
|
IncomeValue.Text = Loc.GetString("ledger-no-income");
|
|
|
|
if (_hasExpenses)
|
|
ExpensesValue.Text = BankSystemExtensions.ToSpesoString(_totalExpenses);
|
|
else
|
|
ExpensesValue.Text = Loc.GetString("ledger-no-expenses");
|
|
|
|
if (_hasIncome || _hasExpenses)
|
|
{
|
|
int totalBalance = _totalIncome - _totalExpenses;
|
|
BalanceValue.Text = BankSystemExtensions.ToSpesoString(totalBalance);
|
|
BalanceValue.FontColorOverride = totalBalance < 0 ? ExpenseColor : IncomeColor;
|
|
}
|
|
else
|
|
BalanceValue.Text = Loc.GetString("ledger-no-balance");
|
|
}
|
|
}
|