using Content.Shared.AirlockPainter;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface.Controls;
namespace Content.Client.AirlockPainter.UI
{
public sealed class AirlockPainterBoundUserInterface : BoundUserInterface
{
private AirlockPainterWindow? _window;
- public List<string> Styles = new();
+ private AirlockPainterSystem? _painter;
+
+ [Dependency] private readonly IEntitySystemManager _entitySystems = default!;
public AirlockPainterBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey)
{
base.Open();
_window = new AirlockPainterWindow();
- if (State != null)
- UpdateState(State);
- // Add styles
- var painterSystem = EntitySystem.Get<AirlockPainterSystem>();
- _window.Populate(painterSystem.Entries);
+ _painter = _entitySystems.GetEntitySystem<AirlockPainterSystem>();
_window.OpenCentered();
-
_window.OnClose += Close;
- _window.OnSpritePicked += OnSpritePicked;
+ _window.OnSpritePicked = OnSpritePicked;
+ }
+
+ protected override void UpdateState(BoundUserInterfaceState state)
+ {
+ base.UpdateState(state);
+
+ if (_window == null)
+ return;
+
+ if (_painter == null)
+ return;
+
+ if (state is not AirlockPainterBoundUserInterfaceState stateCast)
+ return;
+
+ _window.Populate(_painter.Entries, stateCast.SelectedStyle);
}
- private void OnSpritePicked(int index)
+ private void OnSpritePicked(ItemList.ItemListSelectedEventArgs args)
{
- SendMessage(new AirlockPainterSpritePickedMessage(index));
+ SendMessage(new AirlockPainterSpritePickedMessage(args.ItemIndex));
}
}
}
<DefaultWindow xmlns="https://spacestation14.io"
MinSize="300 300"
- SetSize="300 300"
+ SetSize="300 500"
Title="{Loc 'airlock-painter-window-title'}">
<BoxContainer Orientation="Vertical" SeparationOverride="4" MinWidth="150">
<Label Name="SelectedSpriteLabel"
using Robust.Client.AutoGenerated;
+using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
[GenerateTypedNameReferences]
public sealed partial class AirlockPainterWindow : DefaultWindow
{
- public event Action<int>? OnSpritePicked;
+ public Action<ItemList.ItemListSelectedEventArgs>? OnSpritePicked;
+
+ private List<AirlockPainterEntry> CurrentEntries = new List<AirlockPainterEntry>();
public AirlockPainterWindow()
{
RobustXamlLoader.Load(this);
-
- SpriteList.OnItemSelected += e => OnSpritePicked?.Invoke(e.ItemIndex);
}
- public void Populate(List<AirlockPainterEntry> entries)
+ public void Populate(List<AirlockPainterEntry> entries, int selected)
{
- SpriteList.Clear();
- foreach (var entry in entries)
+ // Only clear if the entries change. Otherwise the list would "jump" after selecting an item
+ if (!CurrentEntries.Equals(entries))
{
- SpriteList.AddItem(entry.Name, entry.Icon);
+ 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;
}
}
}
{
base.Initialize();
- HashSet<string> styles = new();
+ SortedSet<string> styles = new();
foreach (AirlockGroupPrototype grp in _prototypeManager.EnumeratePrototypes<AirlockGroupPrototype>())
{
Groups.Add(grp);