6
StarHorizon_Public/Content.Client/_RMC14/Attachable/Ui/AttachableHolderChooseSlotMenu.xaml.cs
2026-01-24 12:49:55 +03:00

59 lines
1.8 KiB
C#

using Content.Client.UserInterface.Controls;
using Content.Shared._RMC14.Attachable;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
namespace Content.Client._RMC14.Attachable.Ui;
[GenerateTypedNameReferences]
public sealed partial class AttachableHolderChooseSlotMenu : FancyWindow
{
private readonly AttachmentChooseSlotBui _boundUI;
private readonly Dictionary<string, AttachableSlotControl> _attachableSlotControls;
public AttachableHolderChooseSlotMenu(AttachmentChooseSlotBui boundUI)
{
RobustXamlLoader.Load(this);
_boundUI = boundUI;
_attachableSlotControls = new Dictionary<string, AttachableSlotControl>();
OnClose += boundUI.Close;
}
public void UpdateMenu(List<string> attachableSlots)
{
foreach (var slotId in attachableSlots)
{
if (!_attachableSlotControls.ContainsKey(slotId))
AddSlotControl(slotId);
}
}
private void AddSlotControl(string slotId)
{
var slotControl = new AttachableSlotControl(this, _boundUI, slotId);
SlotsContainer.AddChild(slotControl);
_attachableSlotControls.Add(slotId, slotControl);
}
private sealed class AttachableSlotControl : Control
{
public AttachableSlotControl(AttachableHolderChooseSlotMenu slotMenu,
AttachmentChooseSlotBui boundUI,
string slotId)
{
var button = new Button { Text = Loc.GetString(slotId) };
button.OnPressed += _ =>
{
boundUI.SendMessage(new AttachableHolderAttachToSlotMessage(slotId));
slotMenu.Close();
};
AddChild(button);
}
}
}