40 lines
1.3 KiB
C#
40 lines
1.3 KiB
C#
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.CustomControls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
|
|
namespace Content.Client.AirlockPainter.UI
|
|
{
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class AirlockPainterWindow : DefaultWindow
|
|
{
|
|
public Action<ItemList.ItemListSelectedEventArgs>? OnSpritePicked;
|
|
|
|
private List<AirlockPainterEntry> CurrentEntries = new List<AirlockPainterEntry>();
|
|
|
|
public AirlockPainterWindow()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
}
|
|
|
|
public void Populate(List<AirlockPainterEntry> entries, int selected)
|
|
{
|
|
// Only clear if the entries change. Otherwise the list would "jump" after selecting an item
|
|
if (!CurrentEntries.Equals(entries))
|
|
{
|
|
CurrentEntries = entries;
|
|
SpriteList.Clear();
|
|
foreach (var entry in entries)
|
|
{
|
|
SpriteList.AddItem(entry.Name, entry.Icon);
|
|
}
|
|
}
|
|
|
|
// Disable event so we don't send a new event for pre-selected entry and end up in a loop
|
|
SpriteList.OnItemSelected -= OnSpritePicked;
|
|
SpriteList[selected].Selected = true;
|
|
SpriteList.OnItemSelected += OnSpritePicked;
|
|
}
|
|
}
|
|
}
|