fish-station/Content.Client/_Sunrise/Synth/SynthMonitorMenu.xaml.cs
Vigers Ray 5775d4cdef
Merge sunrise build (#2)
* commit
2024-05-31 02:16:18 +03:00

84 lines
2.4 KiB
C#

using System.Numerics;
using Content.Client.Stylesheets;
using Content.Shared.Humanoid.Markings;
using Robust.Client.AutoGenerated;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
namespace Content.Client._Sunrise.Synth;
[GenerateTypedNameReferences]
public sealed partial class SynthMonitorMenu : DefaultWindow
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
private readonly SpriteSystem _sprite;
public event Action<string>? OnIdSelected;
private List<string> _possibleScreens = [];
public SynthMonitorMenu()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
_sprite = _entityManager.System<SpriteSystem>();
}
public void UpdateState(List<string> chemList)
{
_possibleScreens = chemList;
UpdateGrid();
}
private void UpdateGrid()
{
ClearGrid();
if (!_prototypeManager.TryIndex("MobSynth", out EntityPrototype? synthProto))
return;
foreach (var screen in _possibleScreens)
{
if (!_prototypeManager.TryIndex(screen, out MarkingPrototype? screenProto))
continue;
var button = new Button
{
MinSize = new Vector2(128, 128),
HorizontalExpand = true,
ToggleMode = false,
StyleClasses = {StyleBase.ButtonSquare},
};
button.OnPressed += _ => OnIdSelected?.Invoke(screen);
Grid.AddChild(button);
var icon = new AnimatedTextureRect
{
DisplayRect =
{
TextureScale = new Vector2(1, 1),
Stretch = TextureRect.StretchMode.KeepAspectCentered,
},
};
icon.SetFromSpriteSpecifier(screenProto.Sprites[0]);
var synth = new TextureRect()
{
Texture = _sprite.GetPrototypeIcon(synthProto).Default,
Stretch = TextureRect.StretchMode.KeepAspectCentered,
};
button.AddChild(synth);
button.AddChild(icon);
}
}
private void ClearGrid()
{
Grid.RemoveAllChildren();
}
}