@@ -1,12 +1,15 @@
|
|||||||
using Content.Shared.AirlockPainter;
|
using Content.Shared.AirlockPainter;
|
||||||
using Robust.Client.GameObjects;
|
using Robust.Client.GameObjects;
|
||||||
|
using Robust.Client.UserInterface.Controls;
|
||||||
|
|
||||||
namespace Content.Client.AirlockPainter.UI
|
namespace Content.Client.AirlockPainter.UI
|
||||||
{
|
{
|
||||||
public sealed class AirlockPainterBoundUserInterface : BoundUserInterface
|
public sealed class AirlockPainterBoundUserInterface : BoundUserInterface
|
||||||
{
|
{
|
||||||
private AirlockPainterWindow? _window;
|
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)
|
public AirlockPainterBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey)
|
||||||
{
|
{
|
||||||
@@ -17,22 +20,33 @@ namespace Content.Client.AirlockPainter.UI
|
|||||||
base.Open();
|
base.Open();
|
||||||
|
|
||||||
_window = new AirlockPainterWindow();
|
_window = new AirlockPainterWindow();
|
||||||
if (State != null)
|
|
||||||
UpdateState(State);
|
|
||||||
|
|
||||||
// Add styles
|
_painter = _entitySystems.GetEntitySystem<AirlockPainterSystem>();
|
||||||
var painterSystem = EntitySystem.Get<AirlockPainterSystem>();
|
|
||||||
_window.Populate(painterSystem.Entries);
|
|
||||||
|
|
||||||
_window.OpenCentered();
|
_window.OpenCentered();
|
||||||
|
|
||||||
_window.OnClose += Close;
|
_window.OnClose += Close;
|
||||||
_window.OnSpritePicked += OnSpritePicked;
|
_window.OnSpritePicked = OnSpritePicked;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnSpritePicked(int index)
|
protected override void UpdateState(BoundUserInterfaceState state)
|
||||||
{
|
{
|
||||||
SendMessage(new AirlockPainterSpritePickedMessage(index));
|
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(ItemList.ItemListSelectedEventArgs args)
|
||||||
|
{
|
||||||
|
SendMessage(new AirlockPainterSpritePickedMessage(args.ItemIndex));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<DefaultWindow xmlns="https://spacestation14.io"
|
<DefaultWindow xmlns="https://spacestation14.io"
|
||||||
MinSize="300 300"
|
MinSize="300 300"
|
||||||
SetSize="300 300"
|
SetSize="300 500"
|
||||||
Title="{Loc 'airlock-painter-window-title'}">
|
Title="{Loc 'airlock-painter-window-title'}">
|
||||||
<BoxContainer Orientation="Vertical" SeparationOverride="4" MinWidth="150">
|
<BoxContainer Orientation="Vertical" SeparationOverride="4" MinWidth="150">
|
||||||
<Label Name="SelectedSpriteLabel"
|
<Label Name="SelectedSpriteLabel"
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Robust.Client.AutoGenerated;
|
using Robust.Client.AutoGenerated;
|
||||||
|
using Robust.Client.UserInterface.Controls;
|
||||||
using Robust.Client.UserInterface.CustomControls;
|
using Robust.Client.UserInterface.CustomControls;
|
||||||
using Robust.Client.UserInterface.XAML;
|
using Robust.Client.UserInterface.XAML;
|
||||||
|
|
||||||
@@ -7,22 +8,32 @@ namespace Content.Client.AirlockPainter.UI
|
|||||||
[GenerateTypedNameReferences]
|
[GenerateTypedNameReferences]
|
||||||
public sealed partial class AirlockPainterWindow : DefaultWindow
|
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()
|
public AirlockPainterWindow()
|
||||||
{
|
{
|
||||||
RobustXamlLoader.Load(this);
|
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();
|
// Only clear if the entries change. Otherwise the list would "jump" after selecting an item
|
||||||
foreach (var entry in entries)
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace Content.Shared.AirlockPainter
|
|||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
HashSet<string> styles = new();
|
SortedSet<string> styles = new();
|
||||||
foreach (AirlockGroupPrototype grp in _prototypeManager.EnumeratePrototypes<AirlockGroupPrototype>())
|
foreach (AirlockGroupPrototype grp in _prototypeManager.EnumeratePrototypes<AirlockGroupPrototype>())
|
||||||
{
|
{
|
||||||
Groups.Add(grp);
|
Groups.Add(grp);
|
||||||
|
|||||||
Reference in New Issue
Block a user