Skip to content

Commit

Permalink
Economy port
Browse files Browse the repository at this point in the history
  • Loading branch information
murlodev committed Mar 8, 2025
1 parent 629e1f6 commit 322433e
Show file tree
Hide file tree
Showing 77 changed files with 5,821 additions and 65 deletions.
59 changes: 59 additions & 0 deletions Content.Client/AWS/Economy/UI/EconomyBankATMBoundUserInteface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Content.Shared.AWS.Economy;
using Content.Client.AWS.Economy.UI;

namespace Content.Client.AWS.Economy.UI;

public sealed class EconomyBankATMBoundUserInteface : BoundUserInterface
{
[ViewVariables]
private EconomyBankATMMenu? _menu;
private EconomyBankATMAccountInfo? _bankAccount;

public EconomyBankATMBoundUserInteface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}

public void OnWithdrawPressed(ulong amount)
{
if (_bankAccount is null)
return;
SendMessage(new EconomyBankATMWithdrawMessage(amount));
}

public void OnTransferPressed(ulong amount, string recipientId)
{
if (_bankAccount is null)
return;
SendMessage(new EconomyBankATMTransferMessage(amount, recipientId));
}

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

_menu = new EconomyBankATMMenu(this);
_menu.OnClose += Close;

_menu.OpenCentered();
}

protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
if (state is not EconomyBankATMUserInterfaceState atmState)
return;

_bankAccount = atmState.BankAccount;

_menu?.SetBankAcount(atmState.BankAccount);
_menu?.SetError(atmState.Error);
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;
_menu?.Dispose();
}
}
28 changes: 28 additions & 0 deletions Content.Client/AWS/Economy/UI/EconomyBankATMMenu.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<controls:FancyWindow xmlns="https://spacestation14.io"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
Title="{Loc 'economy-bank-atm-menu-title'}"
MinSize="550 320">
<BoxContainer Orientation="Vertical" HorizontalExpand="True" VerticalExpand="True" Margin="5">
<GridContainer Columns="2" HorizontalExpand="True" Margin="0 0 0 10">
<Label Text="{Loc 'economy-bank-atm-menu-account-id'}" HorizontalExpand="True" />
<Label Name="AccountIdLabel" HorizontalExpand="True" />
<Label Text="{Loc 'economy-bank-atm-menu-account-owner'}" HorizontalExpand="True" />
<Label Name="AccountOwnerLabel" HorizontalExpand="True" />
<Label Text="{Loc 'economy-bank-atm-menu-account-balance'}" HorizontalExpand="True" />
<Label Name="AccountBalanceLabel" HorizontalExpand="True" />
</GridContainer>
<PanelContainer StyleClasses="LowDivider" />
<Label Text="{Loc 'economy-bank-atm-menu-withdraw-label'}" />
<SpinBox Name="WithdrawAmountBox" HorizontalExpand="True" Value="0" />
<Button Name="WithdrawButton" Text="{Loc 'economy-bank-atm-menu-withdraw-button'}" HorizontalAlignment="Right" />
<PanelContainer StyleClasses="LowDivider" />
<Label Text="{Loc 'economy-bank-atm-menu-transfer-label'}" />
<BoxContainer Orientation="Horizontal" HorizontalExpand="True">
<Label Text="{Loc 'economy-bank-atm-menu-transfer-recipient-label'}" HorizontalExpand="True" />
<LineEdit Name="TransferRecipientField" HorizontalExpand="True" />
</BoxContainer>
<SpinBox Name="TransferAmountBox" HorizontalExpand="True" Value="0" />
<Button Name="TransferButton" Text="{Loc 'economy-bank-atm-menu-transfer-button'}" HorizontalAlignment="Right" />
<Label Name="ErrorLabel" />
</BoxContainer>
</controls:FancyWindow>
96 changes: 96 additions & 0 deletions Content.Client/AWS/Economy/UI/EconomyBankATMMenu.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using Content.Client.UserInterface.Controls;
using Content.Shared.AWS.Economy;
using Content.Client.AWS.Economy.UI;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML;
using Robust.Client.UserInterface.Controls;

namespace Content.Client.AWS.Economy.UI;

[GenerateTypedNameReferences]
public sealed partial class EconomyBankATMMenu : FancyWindow
{
private EconomyBankATMBoundUserInteface Owner { get; set; }

private EconomyBankATMAccountInfo? _bankAccount;

public EconomyBankATMMenu(EconomyBankATMBoundUserInteface owner)
{
IoCManager.InjectDependencies(this);
RobustXamlLoader.Load(this);

Owner = owner;

SetupMoneySpinBox(WithdrawAmountBox);
WithdrawAmountBox.ValueChanged += args =>
{
RefreshWithdrawButton();
};
WithdrawButton.OnPressed += _ => Owner.OnWithdrawPressed((ulong) WithdrawAmountBox.Value);

SetupMoneySpinBox(TransferAmountBox);
TransferAmountBox.ValueChanged += args =>
{
RefreshTransferButton();
};
TransferButton.OnPressed += _ => Owner.OnTransferPressed((ulong) TransferAmountBox.Value, TransferRecipientField.Text);

RefreshWithdrawButton();
RefreshTransferButton();
RefreshAccountInfo();
}

public override void Close()
{
base.Close();
}

public void SetBankAcount(EconomyBankATMAccountInfo? bankAccount)
{
_bankAccount = bankAccount;
RefreshWithdrawButton();
RefreshTransferButton();
RefreshAccountInfo();
}

public void SetError(string? error)
{
ErrorLabel.Text = error;
}

private void RefreshWithdrawButton()
{
var isEnabled = _bankAccount is not null &&
!_bankAccount.Blocked &&
_bankAccount.Balance >= (ulong) WithdrawAmountBox.Value;
WithdrawButton.Disabled = !isEnabled;
}

private void RefreshTransferButton()
{
var isEnabled = _bankAccount is not null &&
!_bankAccount.Blocked &&
_bankAccount.Balance >= (ulong) TransferAmountBox.Value;
TransferButton.Disabled = !isEnabled;
}

private void RefreshAccountInfo()
{
AccountIdLabel.Text = _bankAccount?.AccountId ?? "-";
AccountOwnerLabel.Text = _bankAccount?.AccountName ?? "-";
AccountBalanceLabel.Text = _bankAccount?.Balance.ToString("N0") ?? "-";
}

private void SetupMoneySpinBox(SpinBox spinBox)
{
spinBox.AddLeftButton(-1000, "-1000");
spinBox.AddLeftButton(-100, "-100");
spinBox.AddLeftButton(-10, "-10");
spinBox.AddLeftButton(-1, "-1");
spinBox.AddRightButton(1, "+1");
spinBox.AddRightButton(10, "+10");
spinBox.AddRightButton(100, "+100");
spinBox.AddRightButton(1000, "+1000");
spinBox.IsValid = amount => amount >= 0 && _bankAccount is { } && (ulong) amount <= _bankAccount.Balance;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace Content.Client.AWS.Economy.UI;

public sealed class EconomyLogConsoleBoundUserInterface : BoundUserInterface
{
[ViewVariables]
private EconomyLogConsoleMenu? _menu;

public EconomyLogConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}

protected override void Open()
{
base.Open();
_menu = new EconomyLogConsoleMenu(this);
_menu.OnClose += Close;

_menu?.OpenCentered();
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;

_menu?.Dispose();
}
}
25 changes: 25 additions & 0 deletions Content.Client/AWS/Economy/UI/EconomyLogConsoleMenu.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<controls:FancyWindow xmlns="https://spacestation14.io"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
Title="Bank Accounts"
MinSize="1000 400"
Resizable="False">
<BoxContainer Orientation="Horizontal" HorizontalExpand="True" VerticalExpand="True">
<!-- Left: Account List -->
<BoxContainer Orientation="Vertical" Margin="5" MinWidth="300">
<Label Text="{Loc 'economybanksystem-console-accounts-title'}" HorizontalExpand="True" Align="Center"/>
<LineEdit Name="FindAccount" HorizontalExpand="True" />
<ScrollContainer VerticalExpand="True">
<ItemList Name="AccountList" />
</ScrollContainer>
</BoxContainer>

<!-- Right: Account Logs -->
<BoxContainer Orientation="Vertical" Margin="5" VerticalExpand="True" HorizontalExpand="True">
<Label Text="{Loc 'economybanksystem-console-logs-title'}" HorizontalExpand="True" Align="Center"/>
<LineEdit Name="FindLog" HorizontalExpand="True" />
<ScrollContainer VerticalExpand="True">
<ItemList Name="LogDetails" />
</ScrollContainer>
</BoxContainer>
</BoxContainer>
</controls:FancyWindow>
114 changes: 114 additions & 0 deletions Content.Client/AWS/Economy/UI/EconomyLogConsoleMenu.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using Content.Client.UserInterface.Controls;
using Content.Shared.AWS.Economy;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML;
using Robust.Client.UserInterface.Controls;
using System.Linq;

namespace Content.Client.AWS.Economy.UI;

[GenerateTypedNameReferences]
public sealed partial class EconomyLogConsoleMenu : FancyWindow
{
[Dependency] private readonly EntityManager _entityManager = default!;

private EconomyLogConsoleBoundUserInterface Owner { get; set; }
private IReadOnlyList<Entity<EconomyBankAccountComponent>> _accounts = default!;

public EconomyLogConsoleMenu(EconomyLogConsoleBoundUserInterface owner)
{
IoCManager.InjectDependencies(this);
RobustXamlLoader.Load(this);

LogDetails.SelectMode = ItemList.ItemListSelectMode.None;

Owner = owner;

var bankAccountSystem = _entityManager.System<EconomyBankAccountSystemShared>();
_accounts = bankAccountSystem.GetAccounts().Values.ToList();

FillList();

FindAccount.OnTextEntered += OnTextEnteredAccount;
FindLog.OnTextEntered += OnTextEnteredLog;

}

private void OnSelectAccount(ItemList.Item accountId)
{
LogDetails.Clear();

var account = (accountId.Metadata! as EconomyBankAccountComponent)!;

if (account.Logs.Count == 0)
{
LogDetails.AddItem("No logs detected");
return;
}
for (int i = account.Logs.Count - 1; i != -1; i--)
{
var item = account.Logs[i];
LogDetails.AddItem("[" + item.Date.ToString("hh\\:mm\\:ss") + "] — " + item.Text);
}
}

private void OnTextEnteredAccount(LineEdit.LineEditEventArgs eventArgs)
{
AccountList.Clear();
var upText = eventArgs.Text.ToUpper();
foreach (var (key, value) in _accounts)
{
var fieldName = FormFieldName(value);
if (fieldName.Contains(upText))
{
var field = AccountList.AddItem(fieldName);
field.Metadata = value;
field.OnSelected += OnSelectAccount;
}
}
if (AccountList.Count == 0)
{
AccountList.AddItem("No data acquired");
return;
}
AccountList.SortItemsByText();
}
private void OnTextEnteredLog(LineEdit.LineEditEventArgs eventArgs)
{

if (!AccountList.GetSelected().Any())
{
LogDetails.Clear();
LogDetails.AddItem("Error no select Account");
return;
}
var accountId = AccountList.GetSelected().First();
LogDetails.Clear();
var upText = eventArgs.Text.ToUpper();

var account = (accountId.Metadata! as EconomyBankAccountComponent)!;

for (int i = account.Logs.Count - 1; i != -1; i--)
{
var item = account.Logs[i];
if (item.Text.Contains(upText))
LogDetails.AddItem("[" + item.Date.ToString("hh\\:mm\\:ss") + "] — " + item.Text);
}
}

private void FillList()
{
foreach (var (key, value) in _accounts)
{
var field = AccountList.AddItem(FormFieldName(value));
field.Metadata = value;
field.OnSelected += OnSelectAccount;
}
AccountList.SortItemsByText();
}

private string FormFieldName(EconomyBankAccountComponent account)
{
return account.AccountID + " — " + account.AccountName;
}
}
37 changes: 37 additions & 0 deletions Content.Client/AWS/Economy/UI/EconomyTerminalBoundUserInterface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Content.Shared.AWS.Economy;
using Content.Client.AWS.Economy.UI;

namespace Content.Client.AWS.Economy.UI;

public sealed class EconomyTerminalBoundUserInterface : BoundUserInterface
{
[ViewVariables]
private EconomyTerminalMenu? _menu;

public EconomyTerminalBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}

public void OnPayPressed(ulong amount, string reason)
{
SendMessage(new EconomyTerminalMessage(amount, reason));
}

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

_menu = new EconomyTerminalMenu(this);
_menu.OnClose += Close;

_menu.OpenCentered();
}

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

0 comments on commit 322433e

Please sign in to comment.