* Add SmartFridge * my nit so pick * my access so expanded and my whitelist so both * list -> hashset
82 lines
2.6 KiB
C#
82 lines
2.6 KiB
C#
using System.Linq;
|
|
using System.Numerics;
|
|
using Content.Client.UserInterface.Controls;
|
|
using Content.Shared.SmartFridge;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Client.UserInterface;
|
|
|
|
namespace Content.Client.SmartFridge;
|
|
|
|
public record SmartFridgeListData(EntityUid Representative, SmartFridgeEntry Entry, int Amount) : ListData;
|
|
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class SmartFridgeMenu : FancyWindow
|
|
{
|
|
[Dependency] private readonly IEntityManager _entityManager = default!;
|
|
|
|
public event Action<GUIBoundKeyEventArgs, ListData>? OnItemSelected;
|
|
|
|
private readonly StyleBoxFlat _styleBox = new() { BackgroundColor = new Color(70, 73, 102) };
|
|
|
|
public SmartFridgeMenu()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
VendingContents.SearchBar = SearchBar;
|
|
VendingContents.DataFilterCondition += DataFilterCondition;
|
|
VendingContents.GenerateItem += GenerateButton;
|
|
VendingContents.ItemKeyBindDown += (args, data) => OnItemSelected?.Invoke(args, data);
|
|
}
|
|
|
|
private bool DataFilterCondition(string filter, ListData data)
|
|
{
|
|
if (data is not SmartFridgeListData entry)
|
|
return false;
|
|
|
|
if (string.IsNullOrEmpty(filter))
|
|
return true;
|
|
|
|
return entry.Entry.Name.Contains(filter, StringComparison.CurrentCultureIgnoreCase);
|
|
}
|
|
|
|
private void GenerateButton(ListData data, ListContainerButton button)
|
|
{
|
|
if (data is not SmartFridgeListData entry)
|
|
return;
|
|
|
|
var label = Loc.GetString("smart-fridge-list-item", ("item", entry.Entry.Name), ("amount", entry.Amount));
|
|
button.AddChild(new SmartFridgeItem(entry.Representative, label));
|
|
|
|
button.ToolTip = label;
|
|
button.StyleBoxOverride = _styleBox;
|
|
}
|
|
|
|
public void Populate(Entity<SmartFridgeComponent> ent)
|
|
{
|
|
var listData = new List<ListData>();
|
|
|
|
foreach (var item in ent.Comp.Entries)
|
|
{
|
|
if (!ent.Comp.ContainedEntries.TryGetValue(item, out var items) || items.Count == 0)
|
|
{
|
|
listData.Add(new SmartFridgeListData(EntityUid.Invalid, item, 0));
|
|
}
|
|
else
|
|
{
|
|
var representative = _entityManager.GetEntity(items.First());
|
|
listData.Add(new SmartFridgeListData(representative, item, items.Count));
|
|
}
|
|
}
|
|
|
|
VendingContents.PopulateList(listData);
|
|
}
|
|
|
|
public void SetFlavorText(string flavor)
|
|
{
|
|
LeftFlavorLabel.Text = flavor;
|
|
}
|
|
}
|