mirror of
https://github.com/space-wizards/space-station-14.git
synced 2026-02-15 03:31:30 +01:00
Refactors Vending Menu to XAML-UI (#4614)
* Initial * Some web-edit reviews * Keep VV * Applied Reviews
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
<SS14Window xmlns="https://spacestation14.io">
|
||||
<ItemList Name="VendingContents"
|
||||
SizeFlagsStretchRatio="8"
|
||||
VerticalExpand="True">
|
||||
</ItemList>
|
||||
</SS14Window>
|
||||
@@ -1,65 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Prototypes;
|
||||
using static Content.Shared.VendingMachines.SharedVendingMachineComponent;
|
||||
|
||||
namespace Content.Client.VendingMachines.UI
|
||||
{
|
||||
class VendingMachineMenu : SS14Window
|
||||
[GenerateTypedNameReferences]
|
||||
public partial class VendingMachineMenu : SS14Window
|
||||
{
|
||||
[Dependency] private readonly IResourceCache _resourceCache = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
|
||||
private readonly ItemList _items;
|
||||
private List<VendingMachineInventoryEntry> _cachedInventory = new();
|
||||
private VendingMachineBoundUserInterface Owner { get; }
|
||||
|
||||
public VendingMachineBoundUserInterface Owner { get; }
|
||||
private List<VendingMachineInventoryEntry> _cachedInventory = new();
|
||||
|
||||
public VendingMachineMenu(VendingMachineBoundUserInterface owner)
|
||||
{
|
||||
SetSize = (300, 450);
|
||||
IoCManager.InjectDependencies(this);
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
Owner = owner;
|
||||
|
||||
_items = new ItemList()
|
||||
{
|
||||
SizeFlagsStretchRatio = 8,
|
||||
VerticalExpand = true,
|
||||
};
|
||||
_items.OnItemSelected += ItemSelected;
|
||||
|
||||
Contents.AddChild(_items);
|
||||
VendingContents.OnItemSelected += ItemSelected;
|
||||
}
|
||||
|
||||
public void Populate(List<VendingMachineInventoryEntry> inventory)
|
||||
{
|
||||
_items.Clear();
|
||||
VendingContents.Clear();
|
||||
_cachedInventory = inventory;
|
||||
var longestEntry = "";
|
||||
foreach (VendingMachineInventoryEntry entry in inventory)
|
||||
{
|
||||
var itemName = _prototypeManager.Index<EntityPrototype>(entry.ID).Name;
|
||||
if (itemName.Length > longestEntry.Length)
|
||||
{
|
||||
longestEntry = itemName;
|
||||
}
|
||||
|
||||
Texture? icon = null;
|
||||
if(_prototypeManager.TryIndex(entry.ID, out EntityPrototype? prototype))
|
||||
{
|
||||
icon = SpriteComponent.GetPrototypeIcon(prototype, _resourceCache).Default;
|
||||
}
|
||||
|
||||
_items.AddItem($"{itemName} ({entry.Amount} left)", icon);
|
||||
VendingContents.AddItem($"{itemName} [{entry.Amount}]", icon);
|
||||
}
|
||||
|
||||
SetSize = ((longestEntry.Length + 8) * 12, _items.Count * 40 + 50);
|
||||
SetSize = (Math.Clamp((longestEntry.Length + 2) * 12, 250, 300),
|
||||
Math.Clamp(VendingContents.Count * 30, 150, 350));
|
||||
}
|
||||
|
||||
public void ItemSelected(ItemList.ItemListSelectedEventArgs args)
|
||||
@@ -7,7 +7,7 @@ using static Content.Shared.VendingMachines.SharedVendingMachineComponent;
|
||||
|
||||
namespace Content.Client.VendingMachines
|
||||
{
|
||||
class VendingMachineBoundUserInterface : BoundUserInterface
|
||||
public class VendingMachineBoundUserInterface : BoundUserInterface
|
||||
{
|
||||
[ViewVariables] private VendingMachineMenu? _menu;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user