Files
wwdpublic/Content.Client/_DV/SmartFridge/SmartFridgeMenu.xaml.cs
Will-Oliver-Br c00f942bb1 Port SmartFridge Functionality (#2479)
# Description

Port smartfridge functionality from
[Delta-V](https://github.com/DeltaV-Station/Delta-v) and commits from
[Frontier](https://github.com/new-frontiers-14/frontier-station-14)
Pr and commits:
https://github.com/DeltaV-Station/Delta-v/pull/3207

70a9032085

2d4abf62b7

---

<details><summary><h1>Media</h1></summary>
<p>


https://github.com/user-attachments/assets/a67f78ca-327c-4e08-8e34-8be6a1a59eac

</p>
</details>

---

# Changelog

🆑 sowelipililimute, Whatstone and Will-Oliver-Br
- tweak: SmartFridge now really has functionality

---------

Co-authored-by: pathetic meowmeow <uhhadd@gmail.com>
Co-authored-by: Whatstone <whatston3@gmail.com>
2025-07-12 12:42:31 +10:00

76 lines
2.5 KiB
C#

using System.Numerics;
using Robust.Client.Graphics;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML;
using Robust.Client.UserInterface;
using Content.Client.UserInterface.Controls;
using Content.Shared._DV.SmartFridge;
namespace Content.Client._DV.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[0]);
listData.Add(new SmartFridgeListData(representative, item, items.Count));
}
}
VendingContents.PopulateList(listData);
}
}