перенос файлов клиента из папки White в _White
This commit is contained in:
8
Content.Client/_White/Economy/ATMVisualLayers.cs
Normal file
8
Content.Client/_White/Economy/ATMVisualLayers.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Content.Client._White.Economy;
|
||||
|
||||
public enum ATMVisualLayers : byte
|
||||
{
|
||||
Base,
|
||||
BaseUnshaded
|
||||
}
|
||||
|
||||
42
Content.Client/_White/Economy/Ui/ATMBui.cs
Normal file
42
Content.Client/_White/Economy/Ui/ATMBui.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace Content.Client._White.Economy.Ui;
|
||||
|
||||
|
||||
[UsedImplicitly]
|
||||
public sealed class ATMBui : BoundUserInterface
|
||||
{
|
||||
private AtmWindow _window;
|
||||
|
||||
public ATMBui(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
||||
{
|
||||
_window = new AtmWindow();
|
||||
}
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
_window.OnClose += Close;
|
||||
_window.OnWithdrawAttempt += SendMessage;
|
||||
|
||||
if (State != null)
|
||||
{
|
||||
UpdateState(State);
|
||||
}
|
||||
|
||||
_window.OpenCentered();
|
||||
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
base.UpdateState(state);
|
||||
_window?.UpdateState(state);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
_window?.Close();
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
20
Content.Client/_White/Economy/Ui/AtmWindow.xaml
Normal file
20
Content.Client/_White/Economy/Ui/AtmWindow.xaml
Normal file
@@ -0,0 +1,20 @@
|
||||
<DefaultWindow xmlns="https://spacestation14.io"
|
||||
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
|
||||
Title="ATM"
|
||||
SetSize="400 220"
|
||||
Resizable="False">
|
||||
|
||||
<BoxContainer Name="AuthorizationPage" HorizontalExpand="True" VerticalExpand="True">
|
||||
<BoxContainer HorizontalAlignment="Center" HorizontalExpand="True" VerticalAlignment="Center" Orientation="Vertical" MinSize="325 160">
|
||||
<Label Text="NANOTRASEN ATM"/>
|
||||
<Label Name="BalanceLabel" Visible="False"/>
|
||||
<controls:HighDivider Name="Divider" Visible="False"/>
|
||||
<Label Name="StatusLabel"/>
|
||||
<SliderIntInput Name="WithdrawSlider"/>
|
||||
<BoxContainer HorizontalExpand="True" VerticalExpand="True" VerticalAlignment="Bottom" Orientation="Horizontal">
|
||||
<LineEdit Name="PinLineEdit" HorizontalExpand="True" Text="{Loc 'atm-ui-enter-pin'}"/>
|
||||
<Button Name="WithdrawButton" Text="{Loc 'store-ui-default-withdraw-text'}"/>
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
</DefaultWindow>
|
||||
92
Content.Client/_White/Economy/Ui/AtmWindow.xaml.cs
Normal file
92
Content.Client/_White/Economy/Ui/AtmWindow.xaml.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using Content.Shared.White.Economy;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Client._White.Economy.Ui;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class AtmWindow : DefaultWindow
|
||||
{
|
||||
public Action<ATMRequestWithdrawMessage>? OnWithdrawAttempt;
|
||||
|
||||
private readonly string _pinPattern = "[^0-9]";
|
||||
public AtmWindow()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
|
||||
WithdrawButton.OnButtonDown += args =>
|
||||
{
|
||||
if(PinLineEdit.Text.Length != 4) return;
|
||||
OnWithdrawAttempt?.Invoke(new ATMRequestWithdrawMessage(WithdrawSlider.Value, int.Parse((string) PinLineEdit.Text)));
|
||||
};
|
||||
|
||||
PinLineEdit.OnTextChanged += _ =>
|
||||
{
|
||||
ValidatePin();
|
||||
};
|
||||
}
|
||||
|
||||
public void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
if(state is not ATMBuiState cast) return;
|
||||
|
||||
if (!cast.HasCard)
|
||||
{
|
||||
StatusLabel.Text = cast.InfoMessage;
|
||||
BalanceLabel.Visible = false;
|
||||
Divider.Visible = false;
|
||||
StatusLabel.Visible = true;
|
||||
WithdrawSlider.Visible = false;
|
||||
PinLineEdit.Visible = false;
|
||||
WithdrawButton.Visible = false;
|
||||
return;
|
||||
}
|
||||
|
||||
StatusLabel.Text = cast.InfoMessage;
|
||||
|
||||
BalanceLabel.Text = Loc.GetString("atm-ui-balance", ("balance", cast.AccountBalance));
|
||||
BalanceLabel.Visible = true;
|
||||
|
||||
if (cast.AccountBalance > 0)
|
||||
{
|
||||
Divider.Visible = true;
|
||||
StatusLabel.Visible = true;
|
||||
WithdrawSlider.Visible = true;
|
||||
PinLineEdit.Visible = true;
|
||||
WithdrawButton.Visible = true;
|
||||
|
||||
WithdrawSlider.MaxValue = cast.AccountBalance;
|
||||
WithdrawSlider.Value = Math.Min((int) WithdrawSlider.Value, cast.AccountBalance);
|
||||
return;
|
||||
}
|
||||
|
||||
Divider.Visible = false;
|
||||
StatusLabel.Visible = false;
|
||||
WithdrawSlider.Visible = false;
|
||||
PinLineEdit.Visible = false;
|
||||
WithdrawButton.Visible = false;
|
||||
}
|
||||
|
||||
protected override void FrameUpdate(FrameEventArgs args)
|
||||
{
|
||||
base.FrameUpdate(args);
|
||||
WithdrawButton.Disabled = PinLineEdit.Text.Length != 4;
|
||||
}
|
||||
|
||||
private void ValidatePin()
|
||||
{
|
||||
var pinText = Regex.Replace(PinLineEdit.Text, _pinPattern, string.Empty);
|
||||
|
||||
if (pinText.Length > 4)
|
||||
{
|
||||
pinText = pinText[..4];
|
||||
}
|
||||
|
||||
PinLineEdit.Text = pinText;
|
||||
}
|
||||
}
|
||||
33
Content.Client/_White/Economy/Ui/BankUi.cs
Normal file
33
Content.Client/_White/Economy/Ui/BankUi.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Content.Client.UserInterface.Fragments;
|
||||
using Content.Shared.CartridgeLoader;
|
||||
using Content.Shared.White.Economy;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.UserInterface;
|
||||
|
||||
namespace Content.Client._White.Economy.Ui;
|
||||
|
||||
[UsedImplicitly]
|
||||
public sealed partial class BankUi : UIFragment
|
||||
{
|
||||
private BankUiFragment? _fragment;
|
||||
|
||||
public override Control GetUIFragmentRoot()
|
||||
{
|
||||
return _fragment!;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (state is not BankCartridgeUiState bankState)
|
||||
return;
|
||||
|
||||
_fragment?.UpdateState(bankState);
|
||||
}
|
||||
}
|
||||
30
Content.Client/_White/Economy/Ui/BankUiFragment.xaml
Normal file
30
Content.Client/_White/Economy/Ui/BankUiFragment.xaml
Normal file
@@ -0,0 +1,30 @@
|
||||
<ui1:BankUiFragment xmlns="https://spacestation14.io"
|
||||
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
|
||||
xmlns:ui1="clr-namespace:Content.Client._White.Economy.Ui">
|
||||
|
||||
<PanelContainer StyleClasses="BackgroundDark"></PanelContainer>
|
||||
<BoxContainer Orientation="Vertical" HorizontalExpand="True" VerticalExpand="True" Margin="8">
|
||||
<BoxContainer Name="LinkedAccount" Orientation="Vertical" Visible="False">
|
||||
<RichTextLabel Name="LinkedAccountNumberLabel" />
|
||||
<RichTextLabel Name="LinkedAccountNameLabel" />
|
||||
<RichTextLabel Name="LinkedAccountBalanceLabel" />
|
||||
</BoxContainer>
|
||||
<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>
|
||||
</ui1:BankUiFragment>
|
||||
108
Content.Client/_White/Economy/Ui/BankUiFragment.xaml.cs
Normal file
108
Content.Client/_White/Economy/Ui/BankUiFragment.xaml.cs
Normal file
@@ -0,0 +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((string) AccountLineEdit.Text);
|
||||
var pin = int.Parse((string) PinLineEdit.Text);
|
||||
AccountLinkResultLabel.Visible = true;
|
||||
_accountLinkActive = false;
|
||||
OnLinkAttempt?.Invoke(new BankAccountLinkMessage(accountId, pin));
|
||||
};
|
||||
}
|
||||
|
||||
public void UpdateState(BankCartridgeUiState state)
|
||||
{
|
||||
var accountLinked = state.AccountId != null;
|
||||
|
||||
RichTextLabelExt.SetMarkup(AccountLinkMessageLabel, state.AccountLinkMessage);
|
||||
RichTextLabelExt.SetMarkup(AccountLinkResultLabel, state.AccountLinkResult);
|
||||
|
||||
LinkedAccount.Visible = accountLinked;
|
||||
NoLinkedAccountLabel.Visible = !accountLinked;
|
||||
|
||||
if (accountLinked)
|
||||
{
|
||||
RichTextLabelExt.SetMarkup(LinkedAccountNumberLabel, Loc.GetString("bank-program-ui-account-number-text",
|
||||
("account", state.AccountId!.Value)));
|
||||
RichTextLabelExt.SetMarkup(LinkedAccountNameLabel, Loc.GetString("bank-program-ui-account-owner-text",
|
||||
("owner", state.OwnerName)));
|
||||
RichTextLabelExt.SetMarkup(LinkedAccountBalanceLabel, Loc.GetString("atm-ui-balance", ("balance", state.Balance)));
|
||||
UpdateAccountLinkUi();
|
||||
return;
|
||||
}
|
||||
|
||||
RichTextLabelExt.SetMarkup(NoLinkedAccountLabel, 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;
|
||||
}
|
||||
}
|
||||
40
Content.Client/_White/Economy/Ui/EftposBui.cs
Normal file
40
Content.Client/_White/Economy/Ui/EftposBui.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace Content.Client._White.Economy.Ui;
|
||||
|
||||
[UsedImplicitly]
|
||||
public sealed class EftposBui : BoundUserInterface
|
||||
{
|
||||
private readonly EftposWindow _window;
|
||||
|
||||
public EftposBui(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
||||
{
|
||||
_window = new EftposWindow();
|
||||
}
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
_window.OnClose += Close;
|
||||
_window.OnCardButtonPressed += SendMessage;
|
||||
|
||||
if (State != null)
|
||||
{
|
||||
UpdateState(State);
|
||||
}
|
||||
|
||||
_window.OpenCentered();
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
base.UpdateState(state);
|
||||
_window.UpdateState(state);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
_window.Close();
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
26
Content.Client/_White/Economy/Ui/EftposWindow.xaml
Normal file
26
Content.Client/_White/Economy/Ui/EftposWindow.xaml
Normal file
@@ -0,0 +1,26 @@
|
||||
<DefaultWindow xmlns="https://spacestation14.io"
|
||||
Title="{Loc 'eftpos-ui-title'}"
|
||||
Resizable="False"
|
||||
SetSize="380 120">
|
||||
|
||||
<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'}" />
|
||||
</BoxContainer>
|
||||
<Label Name="AccountLabel"
|
||||
VerticalExpand="True"
|
||||
VerticalAlignment="Bottom"
|
||||
Access="Public" />
|
||||
</BoxContainer>
|
||||
</DefaultWindow>
|
||||
58
Content.Client/_White/Economy/Ui/EftposWindow.xaml.cs
Normal file
58
Content.Client/_White/Economy/Ui/EftposWindow.xaml.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using Content.Shared.White.Economy;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
|
||||
namespace Content.Client._White.Economy.Ui;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class EftposWindow : DefaultWindow
|
||||
{
|
||||
public Action<EftposLockMessage>? OnCardButtonPressed;
|
||||
|
||||
public EftposWindow()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
AmountLineEdit.OnTextChanged += _ =>
|
||||
{
|
||||
if (!int.TryParse((string?) AmountLineEdit.Text, out var result) || result <= 0)
|
||||
AmountLineEdit.Text = string.Empty;
|
||||
|
||||
AmountLineEdit.Text = result.ToString();
|
||||
};
|
||||
|
||||
CardButton.OnPressed += _ =>
|
||||
{
|
||||
if (!int.TryParse((string?) AmountLineEdit.Text, out var result) || result < 0)
|
||||
result = 0;
|
||||
|
||||
OnCardButtonPressed?.Invoke(new EftposLockMessage(result));
|
||||
};
|
||||
}
|
||||
|
||||
public void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
if (state is not EftposBuiState eftState)
|
||||
return;
|
||||
|
||||
AmountLineEdit.Text = eftState.Amount == 0 ? string.Empty : eftState.Amount.ToString();
|
||||
if (eftState.Locked)
|
||||
{
|
||||
CardButton.Text = Loc.GetString("eftpos-ui-card-unlock-text");
|
||||
CardButton.ToolTip = Loc.GetString("eftpos-ui-card-unlock-desc");
|
||||
AmountLineEdit.Editable = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
CardButton.Text = Loc.GetString("eftpos-ui-card-lock-text");
|
||||
CardButton.ToolTip = Loc.GetString("eftpos-ui-card-lock-desc");
|
||||
AmountLineEdit.Editable = true;
|
||||
}
|
||||
|
||||
AccountLabel.Text = eftState.Owner == string.Empty
|
||||
? string.Empty
|
||||
: Loc.GetString("eftpos-ui-account-text", ("owner", eftState.Owner));
|
||||
}
|
||||
}
|
||||
13
Content.Client/_White/Economy/Ui/VendingItem.xaml
Normal file
13
Content.Client/_White/Economy/Ui/VendingItem.xaml
Normal file
@@ -0,0 +1,13 @@
|
||||
<Control xmlns="https://spacestation14.io">
|
||||
<BoxContainer Orientation="Horizontal">
|
||||
<TextureRect
|
||||
Name="VendingItemTexture"
|
||||
Stretch="KeepAspectCentered" />
|
||||
<Label Name="VendingItemName" HorizontalExpand="True" />
|
||||
<Button
|
||||
Name="VendingItemBuyButton"
|
||||
MinWidth="80"
|
||||
HorizontalAlignment="Right"
|
||||
Access="Public" />
|
||||
</BoxContainer>
|
||||
</Control>
|
||||
22
Content.Client/_White/Economy/Ui/VendingItem.xaml.cs
Normal file
22
Content.Client/_White/Economy/Ui/VendingItem.xaml.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
|
||||
namespace Content.Client._White.Economy.Ui;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class VendingItem : Control
|
||||
{
|
||||
public VendingItem(string itemName, string price, Texture? texture = null)
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
VendingItemName.Text = itemName;
|
||||
|
||||
VendingItemBuyButton.Text = price;
|
||||
// VendingItemBuyButton.Disabled = !canBuy;
|
||||
|
||||
VendingItemTexture.Texture = texture;
|
||||
}
|
||||
}
|
||||
26
Content.Client/_White/Economy/Ui/VendingMenu.xaml
Normal file
26
Content.Client/_White/Economy/Ui/VendingMenu.xaml
Normal file
@@ -0,0 +1,26 @@
|
||||
<DefaultWindow xmlns="https://spacestation14.io">
|
||||
<BoxContainer Orientation="Vertical">
|
||||
<BoxContainer Orientation="Horizontal">
|
||||
<Label Name="CreditsLabel" HorizontalExpand="True"/>
|
||||
<Button
|
||||
Name="WithdrawButton"
|
||||
Text="{Loc 'store-ui-default-withdraw-text'}"
|
||||
HorizontalAlignment="Right"/>
|
||||
</BoxContainer>
|
||||
<PanelContainer StyleClasses="HighDivider" />
|
||||
<Label
|
||||
Name="OutOfStockLabel"
|
||||
Visible="False"
|
||||
Text="{Loc 'vending-machine-component-try-eject-out-of-stock'}"/>
|
||||
<ScrollContainer
|
||||
HScrollEnabled="False"
|
||||
HorizontalExpand="True"
|
||||
VerticalExpand="True">
|
||||
<BoxContainer
|
||||
Name="VendingContents"
|
||||
Orientation="Vertical"
|
||||
VerticalExpand="True">
|
||||
</BoxContainer>
|
||||
</ScrollContainer>
|
||||
</BoxContainer>
|
||||
</DefaultWindow>
|
||||
88
Content.Client/_White/Economy/Ui/VendingMenu.xaml.cs
Normal file
88
Content.Client/_White/Economy/Ui/VendingMenu.xaml.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using System.Numerics;
|
||||
using Content.Shared.VendingMachines;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Client._White.Economy.Ui;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class VendingMenu : DefaultWindow
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
|
||||
public event Action<int>? OnItemSelected;
|
||||
public Action<VendingMachineWithdrawMessage>? OnWithdraw;
|
||||
|
||||
public VendingMenu()
|
||||
{
|
||||
MinSize = SetSize = new Vector2(250, 150);
|
||||
RobustXamlLoader.Load(this);
|
||||
IoCManager.InjectDependencies(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Populates the list of available items on the vending machine interface
|
||||
/// and sets icons based on their prototypes
|
||||
/// </summary>
|
||||
public void Populate(List<VendingMachineInventoryEntry> inventory, double priceMultiplier, int credits)
|
||||
{
|
||||
CreditsLabel.Text = Loc.GetString("vending-ui-credits-amount", ("credits", credits));
|
||||
WithdrawButton.Disabled = credits == 0;
|
||||
WithdrawButton.OnPressed += _ =>
|
||||
{
|
||||
if (credits == 0)
|
||||
return;
|
||||
OnWithdraw?.Invoke(new VendingMachineWithdrawMessage());
|
||||
};
|
||||
VendingContents.RemoveAllChildren();
|
||||
if (inventory.Count == 0)
|
||||
{
|
||||
OutOfStockLabel.Visible = true;
|
||||
SetSizeAfterUpdate(OutOfStockLabel.Text?.Length ?? 0);
|
||||
return;
|
||||
}
|
||||
OutOfStockLabel.Visible = false;
|
||||
|
||||
var longestEntry = string.Empty;
|
||||
var spriteSystem = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<SpriteSystem>();
|
||||
|
||||
for (var i = 0; i < inventory.Count; i++)
|
||||
{
|
||||
var entry = inventory[i];
|
||||
|
||||
var itemName = entry.ID;
|
||||
Texture? icon = null;
|
||||
if (_prototypeManager.TryIndex<EntityPrototype>(entry.ID, out var prototype))
|
||||
{
|
||||
itemName = prototype.Name;
|
||||
icon = spriteSystem.GetPrototypeIcon(prototype).Default;
|
||||
}
|
||||
|
||||
if (itemName.Length > longestEntry.Length)
|
||||
longestEntry = itemName;
|
||||
|
||||
var price = (int) (entry.Price * priceMultiplier);
|
||||
var vendingItem = new VendingItem($"{itemName} [{entry.Amount}]", $"{price} ¢", icon);
|
||||
|
||||
var j = i;
|
||||
vendingItem.VendingItemBuyButton.OnPressed += _ =>
|
||||
{
|
||||
OnItemSelected?.Invoke(j);
|
||||
};
|
||||
|
||||
VendingContents.AddChild(vendingItem);
|
||||
}
|
||||
|
||||
SetSizeAfterUpdate(longestEntry.Length);
|
||||
}
|
||||
|
||||
private void SetSizeAfterUpdate(int longestEntryLength)
|
||||
{
|
||||
SetSize = new Vector2(Math.Clamp((longestEntryLength + 10) * 12, 250, 700),
|
||||
Math.Clamp(VendingContents.ChildCount * 50, 150, 400));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user