Skip to content

Commit

Permalink
ui (#7)
Browse files Browse the repository at this point in the history
* ui

* uifix

* uiLog

* uiLogFix
  • Loading branch information
ZoNeSRuS authored Sep 18, 2024
1 parent 11a96af commit 1168f9e
Show file tree
Hide file tree
Showing 13 changed files with 380 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Content.Shared.AWS.Economy;
using Content.Client.AWS.Economy.UI;

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="800 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 Content.Client.AWS.Economy.UI;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML;
using Robust.Client.UserInterface.Controls;
using System.Linq;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using YamlDotNet.Core.Tokens;

namespace Content.Client.AWS.Economy.UI;

[GenerateTypedNameReferences]
public sealed partial class EconomyLogConsoleMenu : FancyWindow
{
[Dependency] private readonly IEntitySystemManager _entitySystem = default!;
private EconomyLogConsoleBoundUserInterface Owner { get; set; }
private Dictionary<string, EconomyBankAccountComponent> _accounts;
public EconomyLogConsoleMenu(EconomyLogConsoleBoundUserInterface owner)
{
IoCManager.InjectDependencies(this);
RobustXamlLoader.Load(this);
var economyBankAccount = _entitySystem.GetEntitySystem<EconomyBankAccountSystemShared>();

LogDetails.SelectMode = ItemList.ItemListSelectMode.None;

Owner = owner;
_accounts = economyBankAccount.GetAccounts();

FillList();

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

}

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

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

if (accountComponent.Logs.Count == 0)
{
LogDetails.AddItem("No logs detected");
return;
}
for (int i = accountComponent.Logs.Count - 1; i != -1; i--)
{
var item = accountComponent.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 accountComponent = (accountId.Metadata! as EconomyBankAccountComponent)!;

for (int i = accountComponent.Logs.Count - 1; i != -1; i--)
{
var item = accountComponent.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 comp)
{
return comp.AccountId + "" + comp.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();
}
}
13 changes: 13 additions & 0 deletions Content.Client/AWS/Economy/UI/EconomyTerminalMenu.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<controls:FancyWindow xmlns="https://spacestation14.io"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
Title="Payment Terminal"
MinSize="300 105"
Resizable="False">
<BoxContainer Orientation="Vertical" HorizontalExpand="True" VerticalExpand="True">
<Label Text="{Loc 'economy-Terminal-Reason'}" Margin="0 5 0 0"/>
<LineEdit Name="ReasonField" HorizontalExpand="True" />
<Label Text="{Loc 'economy-Terminal-Amount'}" Margin="0 5 0 0"/>
<SpinBox Name="AmountBox" HorizontalExpand="True" Value="0" />
<Button Name="SetButton" Text="{Loc 'economy-Terminal-SetButton-button'}" HorizontalExpand="True"/>
</BoxContainer>
</controls:FancyWindow>
24 changes: 24 additions & 0 deletions Content.Client/AWS/Economy/UI/EconomyTerminalMenu.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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 EconomyTerminalMenu : FancyWindow
{
private EconomyTerminalBoundUserInterface Owner { get; set; }

public EconomyTerminalMenu(EconomyTerminalBoundUserInterface owner)
{
IoCManager.InjectDependencies(this);
RobustXamlLoader.Load(this);

Owner = owner;

SetButton.OnPressed += _ => Owner.OnPayPressed((ulong) AmountBox.Value, ReasonField.Text);
}
}
9 changes: 9 additions & 0 deletions Content.Shared/AWS/Economy/EconomyLogConsoleMenuState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Robust.Shared.Serialization;

namespace Content.Shared.AWS.Economy;

[Serializable, NetSerializable]
public enum EconomyLogConsoleMenuUiKey
{
Key
}
15 changes: 15 additions & 0 deletions Content.Shared/AWS/Economy/EconomyTerminalUserInterfaceState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Robust.Shared.Serialization;

namespace Content.Shared.AWS.Economy;

[Serializable, NetSerializable]
public sealed class EconomyTerminalMessage(ulong amount, string reason) : BoundUserInterfaceMessage
{
public readonly ulong Amount = amount;
public readonly string Reason = reason;
}
[Serializable, NetSerializable]
public enum EconomyTerminalUiKey
{
Key
}
2 changes: 1 addition & 1 deletion Resources/Locale/ru-RU/aws/economy/atm.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ economy-bank-atm-menu-withdraw-label = Снять со счёта
economy-bank-atm-menu-withdraw-button = Снять
economy-bank-atm-menu-transfer-label = Перевод на счёт
economy-bank-atm-menu-transfer-recipient-label = Номер счёта-получателя
economy-bank-atm-menu-transfer-button = Перевести
economy-bank-atm-menu-transfer-button = Перевести
4 changes: 3 additions & 1 deletion Resources/Locale/ru-RU/aws/economy/logs.ftl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
economybanksystem-log-withdraw = Снятие {$amount} {$currencyName}
economybanksystem-log-send-to = Перевод {$amount} {$currencyName} на {$accountId}
economybanksystem-log-send-from = Пополнение на {$amount} {$currencyName} с {$accountId}
economybanksystem-log-vending-buying = Покупка {$itemName}
economybanksystem-log-vending-buying = Покупка {$itemName}
economybanksystem-console-accounts-title = Список счетов
economybanksystem-console-logs-title = Список операций
3 changes: 3 additions & 0 deletions Resources/Locale/ru-RU/aws/economy/terminal.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ ent-MedicalTerminal = терминал медицинского отдела
ent-CargoTerminal = терминал отдела снабжения
ent-CCTerminal = терминал центрального командования
ent-EngineeringTerminal = терминал инженерного отдела
economy-Terminal-SetButton-button = Установить
economy-Terminal-Reason = Причина
economy-Terminal-Amount = Сумма
88 changes: 88 additions & 0 deletions Resources/Prototypes/AWS/Economy/console.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
- type: entity
id: ConsoleLog
parent: BaseMachinePowered
name: LogComp
components:
- type: Sprite
sprite: AWS/economy/ATM.rsi
layers:
- map: ["computerLayerBody"]
state: ATM
- map: ["enum.PowerDeviceVisualLayers.Powered"]
state: ATM-on
shader: unshaded
- map: ["enum.WiresVisualLayers.MaintenancePanel"]
state: panel
visible: false
- type: GenericVisualizer
visuals:
enum.PowerDeviceVisuals.Powered:
enum.PowerDeviceVisualLayers.Powered:
True: { visible: true }
False: { visible: false }
- type: Icon
sprite: AWS/economy/ATM.rsi
state: icon
- type: Physics
bodyType: Static
- type: Transform
noRot: true
- type: Fixtures
fixtures:
fix1:
shape:
!type:PhysShapeAabb
bounds: "-0.25,-0.45,0.25,0.45"
mask:
- MachineMask
layer:
- MachineLayer
density: 200
- type: Destructible
thresholds:
- trigger:
!type:DamageTrigger
damage: 100
behaviors:
- !type:DoActsBehavior
acts: ["Breakage"]
- !type:EjectVendorItems
- trigger:
!type:DamageTrigger
damage: 200
behaviors:
- !type:SpawnEntitiesBehavior
spawn:
SheetSteel1:
min: 1
max: 1
- !type:DoActsBehavior
acts: [ "Destruction" ]
- !type:PlaySoundBehavior
sound:
collection: MetalGlassBreak
- type: Repairable
doAfterDelay: 8
- type: ActivatableUI
key: enum.EconomyLogConsoleMenuUiKey.Key
- type: ActivatableUIRequiresPower
- type: UserInterface
interfaces:
enum.EconomyLogConsoleMenuUiKey.Key:
type: EconomyLogConsoleBoundUserInterface
- type: WiresPanel
- type: WiresVisuals
- type: Anchorable
- type: DoAfter
- type: Electrified
enabled: false
usesApcPower: true
- type: PointLight
enabled: false
castShadows: false
radius: 1.5
- type: LitOnPowered
- type: ApcPowerReceiver
powerLoad: 200
- type: Actions
- type: Appearance
Loading

0 comments on commit 1168f9e

Please sign in to comment.