2021-09-19 10:21:05 -07:00
|
|
|
|
using System;
|
2021-06-04 00:26:08 +00:00
|
|
|
|
using System.Collections.Generic;
|
2021-09-19 10:21:05 -07:00
|
|
|
|
using Robust.Client.AutoGenerated;
|
2019-08-14 10:49:28 +02:00
|
|
|
|
using Robust.Client.GameObjects;
|
|
|
|
|
|
using Robust.Client.Graphics;
|
2021-02-11 01:13:03 -08:00
|
|
|
|
using Robust.Client.ResourceManagement;
|
2019-11-13 17:37:46 -05:00
|
|
|
|
using Robust.Client.UserInterface.Controls;
|
|
|
|
|
|
using Robust.Client.UserInterface.CustomControls;
|
2021-09-19 10:21:05 -07:00
|
|
|
|
using Robust.Client.UserInterface.XAML;
|
2019-11-13 17:37:46 -05:00
|
|
|
|
using Robust.Shared.IoC;
|
2019-08-14 10:49:28 +02:00
|
|
|
|
using Robust.Shared.Prototypes;
|
2021-06-09 22:19:39 +02:00
|
|
|
|
using static Content.Shared.VendingMachines.SharedVendingMachineComponent;
|
2019-08-14 10:49:28 +02:00
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
|
namespace Content.Client.VendingMachines.UI
|
2019-08-14 10:49:28 +02:00
|
|
|
|
{
|
2021-09-19 10:21:05 -07:00
|
|
|
|
[GenerateTypedNameReferences]
|
2022-02-16 00:23:23 -07:00
|
|
|
|
public sealed partial class VendingMachineMenu : DefaultWindow
|
2019-08-14 10:49:28 +02:00
|
|
|
|
{
|
2020-08-24 14:10:28 +02:00
|
|
|
|
[Dependency] private readonly IResourceCache _resourceCache = default!;
|
|
|
|
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
|
|
|
|
|
2021-09-19 10:21:05 -07:00
|
|
|
|
private VendingMachineBoundUserInterface Owner { get; }
|
2019-08-14 10:49:28 +02:00
|
|
|
|
|
2021-09-19 10:21:05 -07:00
|
|
|
|
private List<VendingMachineInventoryEntry> _cachedInventory = new();
|
2019-08-14 10:49:28 +02:00
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
|
public VendingMachineMenu(VendingMachineBoundUserInterface owner)
|
2019-08-14 10:49:28 +02:00
|
|
|
|
{
|
|
|
|
|
|
IoCManager.InjectDependencies(this);
|
2021-09-19 10:21:05 -07:00
|
|
|
|
RobustXamlLoader.Load(this);
|
2019-08-14 10:49:28 +02:00
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
|
Owner = owner;
|
2021-09-19 10:21:05 -07:00
|
|
|
|
VendingContents.OnItemSelected += ItemSelected;
|
2019-08-14 10:49:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Populate(List<VendingMachineInventoryEntry> inventory)
|
|
|
|
|
|
{
|
2021-09-19 10:21:05 -07:00
|
|
|
|
VendingContents.Clear();
|
2019-08-14 10:49:28 +02:00
|
|
|
|
_cachedInventory = inventory;
|
2021-03-15 01:38:08 -07:00
|
|
|
|
var longestEntry = "";
|
2019-08-14 10:49:28 +02:00
|
|
|
|
foreach (VendingMachineInventoryEntry entry in inventory)
|
|
|
|
|
|
{
|
2019-09-20 20:39:54 +02:00
|
|
|
|
var itemName = _prototypeManager.Index<EntityPrototype>(entry.ID).Name;
|
2021-03-15 01:38:08 -07:00
|
|
|
|
if (itemName.Length > longestEntry.Length)
|
|
|
|
|
|
longestEntry = itemName;
|
2019-09-20 20:39:54 +02:00
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
|
Texture? icon = null;
|
|
|
|
|
|
if(_prototypeManager.TryIndex(entry.ID, out EntityPrototype? prototype))
|
|
|
|
|
|
icon = SpriteComponent.GetPrototypeIcon(prototype, _resourceCache).Default;
|
2021-03-15 01:38:08 -07:00
|
|
|
|
|
2021-09-19 10:21:05 -07:00
|
|
|
|
VendingContents.AddItem($"{itemName} [{entry.Amount}]", icon);
|
2019-08-14 10:49:28 +02:00
|
|
|
|
}
|
2021-03-15 01:38:08 -07:00
|
|
|
|
|
2021-09-19 10:21:05 -07:00
|
|
|
|
SetSize = (Math.Clamp((longestEntry.Length + 2) * 12, 250, 300),
|
2022-01-30 22:16:41 -06:00
|
|
|
|
Math.Clamp(VendingContents.Count * 50, 150, 350));
|
2019-08-14 10:49:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void ItemSelected(ItemList.ItemListSelectedEventArgs args)
|
|
|
|
|
|
{
|
|
|
|
|
|
Owner.Eject(_cachedInventory[args.ItemIndex].ID);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|