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

View File

@@ -4,6 +4,7 @@ using Content.Shared.Doors.Components;
using JetBrains.Annotations;
using Robust.Client.Animations;
using Robust.Client.GameObjects;
using Robust.Client.ResourceManagement;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Serialization;
@@ -17,6 +18,7 @@ namespace Content.Client.Doors
{
[Dependency] private readonly IEntityManager _entMan = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IResourceCache _resourceCache = default!;
private const string AnimationKey = "airlock_animation";
@@ -65,7 +67,7 @@ namespace Content.Client.Doors
{
IoCManager.InjectDependencies(this);
CloseAnimation = new Animation {Length = TimeSpan.FromSeconds(_delay)};
CloseAnimation = new Animation { Length = TimeSpan.FromSeconds(_delay) };
{
var flick = new AnimationTrackSpriteFlick();
CloseAnimation.AnimationTracks.Add(flick);
@@ -89,7 +91,7 @@ namespace Content.Client.Doors
}
}
OpenAnimation = new Animation {Length = TimeSpan.FromSeconds(_delay)};
OpenAnimation = new Animation { Length = TimeSpan.FromSeconds(_delay) };
{
var flick = new AnimationTrackSpriteFlick();
OpenAnimation.AnimationTracks.Add(flick);
@@ -112,7 +114,7 @@ namespace Content.Client.Doors
}
}
}
EmaggingAnimation = new Animation {Length = TimeSpan.FromSeconds(_delay)};
EmaggingAnimation = new Animation { Length = TimeSpan.FromSeconds(_delay) };
{
var flickUnlit = new AnimationTrackSpriteFlick();
EmaggingAnimation.AnimationTracks.Add(flickUnlit);
@@ -122,7 +124,7 @@ namespace Content.Client.Doors
if (!_simpleVisuals)
{
DenyAnimation = new Animation {Length = TimeSpan.FromSeconds(_denyDelay)};
DenyAnimation = new Animation { Length = TimeSpan.FromSeconds(_denyDelay) };
{
var flick = new AnimationTrackSpriteFlick();
DenyAnimation.AnimationTracks.Add(flick);
@@ -161,6 +163,18 @@ namespace Content.Client.Doors
var weldedVisible = false;
var emergencyLightsVisible = false;
if (component.TryGetData(DoorVisuals.BaseRSI, out string baseRsi))
{
if (!_resourceCache.TryGetResource<RSIResource>(SharedSpriteComponent.TextureRoot / baseRsi, out var res))
{
Logger.Error("Unable to load RSI '{0}'. Trace:\n{1}", baseRsi, Environment.StackTrace);
}
foreach (ISpriteLayer layer in sprite.AllLayers)
{
layer.Rsi = res?.RSI;
}
}
if (animPlayer.HasRunningAnimation(AnimationKey))
{
animPlayer.Stop(AnimationKey);

View File

@@ -5,6 +5,7 @@ namespace Content.Client.Entry
{
public static string[] List => new[]
{
"AirlockPainter",
"AmmoBox",
"Pickaxe",
"IngestionBlocker",