Привязка банковского аккаунта (#506)
* Sustenance vend price fix * Account link
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
using Content.Client.UserInterface.Fragments;
|
||||
using Content.Shared.CartridgeLoader;
|
||||
using Content.Shared.White.Economy;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.UserInterface;
|
||||
|
||||
namespace Content.Client.White.Economy.Ui;
|
||||
|
||||
[UsedImplicitly]
|
||||
public sealed partial class BankUi : UIFragment
|
||||
{
|
||||
private BankUiFragment? _fragment;
|
||||
@@ -17,6 +20,8 @@ public sealed partial class BankUi : UIFragment
|
||||
public override void Setup(BoundUserInterface userInterface, EntityUid? fragmentOwner)
|
||||
{
|
||||
_fragment = new BankUiFragment();
|
||||
|
||||
_fragment.OnLinkAttempt += message => userInterface.SendMessage(new CartridgeUiMessage(message));
|
||||
}
|
||||
|
||||
public override void UpdateState(BoundUserInterfaceState state)
|
||||
|
||||
@@ -1,12 +1,30 @@
|
||||
<ui:BankUiFragment xmlns="https://spacestation14.io"
|
||||
xmlns:ui="clr-namespace:Content.Client.White.Economy.Ui">
|
||||
xmlns:ui="clr-namespace:Content.Client.White.Economy.Ui"
|
||||
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls">
|
||||
|
||||
<PanelContainer StyleClasses="BackgroundDark"></PanelContainer>
|
||||
<BoxContainer Orientation="Vertical" HorizontalExpand="True" VerticalExpand="True" Margin="8">
|
||||
<BoxContainer Name="LinkedAccount" Orientation="Vertical" Visible="False">
|
||||
<RichTextLabel Name="LinkedAccountNameLabel"/>
|
||||
<RichTextLabel Name="LinkedAccountBalanceLabel"/>
|
||||
<RichTextLabel Name="LinkedAccountNumberLabel" />
|
||||
<RichTextLabel Name="LinkedAccountNameLabel" />
|
||||
<RichTextLabel Name="LinkedAccountBalanceLabel" />
|
||||
</BoxContainer>
|
||||
<RichTextLabel Name="NoLinkedAccountLabel" Visible="False"/>
|
||||
<RichTextLabel Name="NoLinkedAccountLabel" Visible="False" />
|
||||
<controls:StripeBack>
|
||||
<Button Name="AccountLinkButton" HorizontalExpand="True" HorizontalAlignment="Center"
|
||||
Text="{Loc 'bank-program-ui-link-account'}" />
|
||||
<BoxContainer Name="AccountLink" Orientation="Vertical" Visible="False" HorizontalExpand="True"
|
||||
Margin="0 5 0 5">
|
||||
<RichTextLabel Name="AccountLinkMessageLabel" />
|
||||
<GridContainer HorizontalExpand="True" Columns="2" Rows="2">
|
||||
<LineEdit Name="AccountLineEdit" HorizontalExpand="True"
|
||||
Text="{Loc 'bank-program-ui-account-number'}" />
|
||||
<Button Name="LinkConfirmButton" Text="{Loc 'bank-program-ui-link-confirm'}" />
|
||||
<LineEdit Name="PinLineEdit" HorizontalExpand="True" Text="PIN" />
|
||||
<Button Name="LinkCancelButton" Text="{Loc 'bank-program-ui-link-cancel'}" />
|
||||
</GridContainer>
|
||||
</BoxContainer>
|
||||
</controls:StripeBack>
|
||||
<RichTextLabel Name="AccountLinkResultLabel" Visible="False" />
|
||||
</BoxContainer>
|
||||
</ui:BankUiFragment>
|
||||
|
||||
@@ -1,30 +1,108 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using Content.Client.Message;
|
||||
using Content.Shared.White.Economy;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Client.White.Economy.Ui;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class BankUiFragment : BoxContainer
|
||||
{
|
||||
public Action<BankAccountLinkMessage>? OnLinkAttempt;
|
||||
|
||||
private bool _accountLinkActive;
|
||||
|
||||
private readonly string _lineEditPattern = "[^0-9]";
|
||||
|
||||
public BankUiFragment()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
AccountLinkButton.OnPressed += _ =>
|
||||
{
|
||||
_accountLinkActive = true;
|
||||
AccountLinkResultLabel.Visible = false;
|
||||
UpdateAccountLinkUi();
|
||||
};
|
||||
|
||||
LinkCancelButton.OnPressed += _ =>
|
||||
{
|
||||
_accountLinkActive = false;
|
||||
UpdateAccountLinkUi();
|
||||
};
|
||||
|
||||
PinLineEdit.OnTextChanged += _ =>
|
||||
{
|
||||
ValidateLineEdit(PinLineEdit, 4);
|
||||
};
|
||||
|
||||
AccountLineEdit.OnTextChanged += _ =>
|
||||
{
|
||||
ValidateLineEdit(AccountLineEdit, 6);
|
||||
};
|
||||
|
||||
LinkConfirmButton.OnPressed += _ =>
|
||||
{
|
||||
if (PinLineEdit.Text.Length != 4 || AccountLineEdit.Text.Length != 6)
|
||||
return;
|
||||
|
||||
var accountId = int.Parse(AccountLineEdit.Text);
|
||||
var pin = int.Parse(PinLineEdit.Text);
|
||||
AccountLinkResultLabel.Visible = true;
|
||||
_accountLinkActive = false;
|
||||
OnLinkAttempt?.Invoke(new BankAccountLinkMessage(accountId, pin));
|
||||
};
|
||||
}
|
||||
|
||||
public void UpdateState(BankCartridgeUiState state)
|
||||
{
|
||||
LinkedAccount.Visible = state.AccountLinked;
|
||||
NoLinkedAccountLabel.Visible = !state.AccountLinked;
|
||||
var accountLinked = state.AccountId != null;
|
||||
|
||||
if (state.AccountLinked)
|
||||
AccountLinkMessageLabel.SetMarkup(state.AccountLinkMessage);
|
||||
AccountLinkResultLabel.SetMarkup(state.AccountLinkResult);
|
||||
|
||||
LinkedAccount.Visible = accountLinked;
|
||||
NoLinkedAccountLabel.Visible = !accountLinked;
|
||||
|
||||
if (accountLinked)
|
||||
{
|
||||
LinkedAccountNameLabel.SetMarkup(Loc.GetString("eftpos-ui-account-text", ("owner", state.OwnerName)));
|
||||
LinkedAccountNumberLabel.SetMarkup(Loc.GetString("bank-program-ui-account-number-text",
|
||||
("account", state.AccountId!.Value)));
|
||||
LinkedAccountNameLabel.SetMarkup(Loc.GetString("bank-program-ui-account-owner-text",
|
||||
("owner", state.OwnerName)));
|
||||
LinkedAccountBalanceLabel.SetMarkup(Loc.GetString("atm-ui-balance", ("balance", state.Balance)));
|
||||
UpdateAccountLinkUi();
|
||||
return;
|
||||
}
|
||||
|
||||
NoLinkedAccountLabel.SetMarkup(Loc.GetString("bank-program-ui-no-account"));
|
||||
UpdateAccountLinkUi();
|
||||
}
|
||||
|
||||
private void UpdateAccountLinkUi()
|
||||
{
|
||||
AccountLinkButton.Visible = !_accountLinkActive;
|
||||
AccountLink.Visible = _accountLinkActive;
|
||||
}
|
||||
|
||||
protected override void FrameUpdate(FrameEventArgs args)
|
||||
{
|
||||
base.FrameUpdate(args);
|
||||
LinkConfirmButton.Disabled = PinLineEdit.Text.Length != 4 || AccountLineEdit.Text.Length != 6;
|
||||
}
|
||||
|
||||
private void ValidateLineEdit(LineEdit lineEdit, int length)
|
||||
{
|
||||
var text = Regex.Replace(lineEdit.Text, _lineEditPattern, string.Empty);
|
||||
|
||||
if (text.Length > length)
|
||||
{
|
||||
text = text[..length];
|
||||
}
|
||||
|
||||
lineEdit.Text = text;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,26 +5,22 @@
|
||||
|
||||
<BoxContainer Orientation="Vertical" VerticalExpand="True" HorizontalExpand="True">
|
||||
<BoxContainer Orientation="Horizontal" HorizontalExpand="True">
|
||||
<Label
|
||||
Name="AmountLabel"
|
||||
Text="{Loc 'eftpos-ui-amount-text'}" />
|
||||
<LineEdit
|
||||
Name="AmountLineEdit"
|
||||
PlaceHolder="0"
|
||||
MinWidth="60"
|
||||
Access="Public" />
|
||||
<Button
|
||||
Name="CardButton"
|
||||
Access="Public"
|
||||
HorizontalExpand="True"
|
||||
HorizontalAlignment="Right"
|
||||
ToolTip="{Loc 'eftpos-ui-card-lock-desc'}"
|
||||
Text="{Loc 'eftpos-ui-card-lock-text'}" />
|
||||
<Label Name="AmountLabel"
|
||||
Text="{Loc 'eftpos-ui-amount-text'}" />
|
||||
<LineEdit Name="AmountLineEdit"
|
||||
PlaceHolder="0"
|
||||
MinWidth="60"
|
||||
Access="Public" />
|
||||
<Button Name="CardButton"
|
||||
Access="Public"
|
||||
HorizontalExpand="True"
|
||||
HorizontalAlignment="Right"
|
||||
ToolTip="{Loc 'eftpos-ui-card-lock-desc'}"
|
||||
Text="{Loc 'eftpos-ui-card-lock-text'}" />
|
||||
</BoxContainer>
|
||||
<Label
|
||||
Name="AccountLabel"
|
||||
VerticalExpand="True"
|
||||
VerticalAlignment="Bottom"
|
||||
Access="Public" />
|
||||
<Label Name="AccountLabel"
|
||||
VerticalExpand="True"
|
||||
VerticalAlignment="Bottom"
|
||||
Access="Public" />
|
||||
</BoxContainer>
|
||||
</DefaultWindow>
|
||||
|
||||
@@ -34,7 +34,7 @@ public sealed partial class EftposWindow : DefaultWindow
|
||||
|
||||
public void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
if(state is not EftposBuiState eftState)
|
||||
if (state is not EftposBuiState eftState)
|
||||
return;
|
||||
|
||||
AmountLineEdit.Text = eftState.Amount == 0 ? string.Empty : eftState.Amount.ToString();
|
||||
|
||||
Reference in New Issue
Block a user