Local Material Silo (#36492)
* Material Silo * fix board, fix copyright * a bit of review.... for the vibe.... * a tiny bit of review * 4 spaced * sloths no good very tiny nitpick * fix ui flickers * oops * slightly lower range * Sloth Review --------- Co-authored-by: ScarKy0 <scarky0@onet.eu>
This commit is contained in:
64
Content.Client/Materials/UI/OreSiloMenu.xaml.cs
Normal file
64
Content.Client/Materials/UI/OreSiloMenu.xaml.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System.Linq;
|
||||
using Content.Client.UserInterface.Controls;
|
||||
using Content.Shared.Materials.OreSilo;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
|
||||
namespace Content.Client.Materials.UI;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class OreSiloMenu : FancyWindow
|
||||
{
|
||||
public event Action<NetEntity>? OnClientEntryPressed;
|
||||
|
||||
public OreSiloMenu()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
ClientList.OnItemSelected += args =>
|
||||
{
|
||||
var item = ClientList[args.ItemIndex];
|
||||
// a little bit of null suppression makes me feel great! :-)
|
||||
OnClientEntryPressed?.Invoke((NetEntity) item.Metadata!);
|
||||
};
|
||||
}
|
||||
|
||||
public void SetEntity(EntityUid uid)
|
||||
{
|
||||
Materials.SetOwner(uid);
|
||||
}
|
||||
|
||||
public void Update(OreSiloBuiState state)
|
||||
{
|
||||
var items = new List<ItemList.Item>();
|
||||
var orderedClients = state.Clients.OrderBy(t => t.Item3).ThenBy(t => t.Item1.Id);
|
||||
foreach (var (ent, _, _) in orderedClients)
|
||||
{
|
||||
items.Add(new ItemList.Item(ClientList)
|
||||
{
|
||||
Metadata = ent
|
||||
});
|
||||
}
|
||||
|
||||
ClientList.SetItems(items,
|
||||
(item1, item2) =>
|
||||
{
|
||||
var ent1 = (NetEntity) item1.Metadata!;
|
||||
var ent2 = (NetEntity) item2.Metadata!;
|
||||
return ent1.CompareTo(ent2);
|
||||
});
|
||||
|
||||
var entTextDict = state.Clients.Select(t => (t.Item1, t.Item2)).ToDictionary();
|
||||
using var enumerator = ClientList.GetEnumerator();
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
if (enumerator.Current.Metadata is not NetEntity ent)
|
||||
continue;
|
||||
|
||||
if (entTextDict.TryGetValue(ent, out var text))
|
||||
enumerator.Current.Text = text;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user