перенос файлов клиента из папки White в _White
This commit is contained in:
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