Files
tbd-station-14/Content.Client/AirlockPainter/UI/AirlockPainterWindow.xaml.cs
jicksaw a008024b37 Airlock painter fixes (#13877)
fix undefined
2023-02-05 13:22:36 -07:00

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;
}
}
}