Files
tbd-station-14/Content.Client/VendingMachines/VendingMachineMenu.cs
ZelteHonor b2e2aef78d Rider static analysis (#433)
* Non-accessed local variable

* Merge cast and type checks.

* StringComparison.Ordinal added for better culture support

* Supposed code improvement in launcher. Remove unused code.

* Update ExplosionHelper.cs

Unintentional change.

* Optimized Import

* Add Robust.Shared.Utility import where it was deleted

* Other random suggestion

* Improve my comment
2019-11-13 23:37:46 +01:00

68 lines
2.3 KiB
C#

using System.Collections.Generic;
using Content.Client.GameObjects.Components.VendingMachines;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Interfaces.ResourceManagement;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Prototypes;
using static Content.Shared.GameObjects.Components.VendingMachines.SharedVendingMachineComponent;
namespace Content.Client.VendingMachines
{
class VendingMachineMenu : SS14Window
{
protected override Vector2? CustomSize => (300, 450);
private readonly ItemList _items;
private List<VendingMachineInventoryEntry> _cachedInventory;
#pragma warning disable CS0649
[Dependency]
private IResourceCache _resourceCache;
[Dependency]
private readonly IPrototypeManager _prototypeManager;
#pragma warning restore
public VendingMachineBoundUserInterface Owner { get; set; }
public VendingMachineMenu()
{
IoCManager.InjectDependencies(this);
_items = new ItemList()
{
SizeFlagsStretchRatio = 8,
SizeFlagsVertical = SizeFlags.FillExpand,
};
_items.OnItemSelected += ItemSelected;
Contents.AddChild(_items);
}
public void Populate(List<VendingMachineInventoryEntry> inventory)
{
_items.Clear();
_cachedInventory = inventory;
foreach (VendingMachineInventoryEntry entry in inventory)
{
var itemName = _prototypeManager.Index<EntityPrototype>(entry.ID).Name;
Texture icon = null;
if(_prototypeManager.TryIndex(entry.ID, out EntityPrototype prototype))
{
icon = IconComponent.GetPrototypeIcon(prototype, _resourceCache).TextureFor(Direction.South);
}
_items.AddItem($"{itemName} ({entry.Amount} left)", icon);
}
}
public void ItemSelected(ItemList.ItemListSelectedEventArgs args)
{
Owner.Eject(_cachedInventory[args.ItemIndex].ID);
}
}
}