Airlock visuals (#7261)

This commit is contained in:
Joosep Jääger
2022-04-16 05:31:12 +00:00
committed by GitHub
parent 636dc9c26a
commit 0cdb34741e
23 changed files with 528 additions and 6 deletions

View File

@@ -0,0 +1,54 @@
using Content.Shared.AirlockPainter;
using Robust.Client.Graphics;
using Robust.Client.ResourceManagement;
using Robust.Shared.Utility;
using System.Linq;
using static Robust.Shared.GameObjects.SharedSpriteComponent;
namespace Content.Client.AirlockPainter
{
public sealed class AirlockPainterSystem : SharedAirlockPainterSystem
{
[Dependency] private readonly IResourceCache _resourceCache = default!;
public List<AirlockPainterEntry> Entries { get; private set; } = new();
public override void Initialize()
{
base.Initialize();
foreach (string style in Styles)
{
string? iconPath = Groups
.FindAll(x => x.StylePaths.ContainsKey(style))?
.MaxBy(x => x.IconPriority)?.StylePaths[style];
if (iconPath == null)
{
Entries.Add(new AirlockPainterEntry(style, null));
continue;
}
RSIResource doorRsi = _resourceCache.GetResource<RSIResource>(TextureRoot / new ResourcePath(iconPath));
if (!doorRsi.RSI.TryGetState("closed", out var icon))
{
Entries.Add(new AirlockPainterEntry(style, null));
continue;
}
Entries.Add(new AirlockPainterEntry(style, icon.Frame0));
}
}
}
public sealed class AirlockPainterEntry
{
public string Name;
public Texture? Icon;
public AirlockPainterEntry(string name, Texture? icon)
{
Name = name;
Icon = icon;
}
}
}

View File

@@ -0,0 +1,38 @@
using Content.Shared.AirlockPainter;
using Robust.Client.GameObjects;
namespace Content.Client.AirlockPainter.UI
{
public sealed class AirlockPainterBoundUserInterface : BoundUserInterface
{
private AirlockPainterWindow? _window;
public List<string> Styles = new();
public AirlockPainterBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
{
}
protected override void Open()
{
base.Open();
_window = new AirlockPainterWindow();
if (State != null)
UpdateState(State);
// Add styles
var painterSystem = EntitySystem.Get<AirlockPainterSystem>();
_window.Populate(painterSystem.Entries);
_window.OpenCentered();
_window.OnClose += Close;
_window.OnSpritePicked += OnSpritePicked;
}
private void OnSpritePicked(int index)
{
SendMessage(new AirlockPainterSpritePickedMessage(index));
}
}
}

View File

@@ -0,0 +1,14 @@
<DefaultWindow xmlns="https://spacestation14.io"
MinSize="300 300"
SetSize="300 300"
Title="{Loc 'airlock-painter-window-title'}">
<BoxContainer Orientation="Vertical" SeparationOverride="4" MinWidth="150">
<Label Name="SelectedSpriteLabel"
Text="{Loc 'airlock-painter-selected-style'}">
</Label>
<ItemList Name="SpriteList"
SizeFlagsStretchRatio="8"
VerticalExpand="True">
</ItemList>
</BoxContainer>
</DefaultWindow>

View File

@@ -0,0 +1,28 @@
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
namespace Content.Client.AirlockPainter.UI
{
[GenerateTypedNameReferences]
public sealed partial class AirlockPainterWindow : DefaultWindow
{
public event Action<int>? OnSpritePicked;
public AirlockPainterWindow()
{
RobustXamlLoader.Load(this);
SpriteList.OnItemSelected += e => OnSpritePicked?.Invoke(e.ItemIndex);
}
public void Populate(List<AirlockPainterEntry> entries)
{
SpriteList.Clear();
foreach (var entry in entries)
{
SpriteList.AddItem(entry.Name, entry.Icon);
}
}
}
}