using System.Numerics; using Content.Client.Stylesheets; 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; using static Robust.Client.UserInterface.Controls.BoxContainer; namespace Content.Client._RMC14.Attachable.Ui; [GenerateTypedNameReferences] public sealed partial class AttachableHolderStripMenu : FancyWindow { private readonly AttachmentStripBui _boundUI; private readonly Dictionary _attachableSlotControls; public AttachableHolderStripMenu(AttachmentStripBui boundUI) { RobustXamlLoader.Load(this); _boundUI = boundUI; _attachableSlotControls = new Dictionary(); OnClose += boundUI.Close; } public void UpdateMenu(Dictionary attachableSlots) { foreach (var slotId in attachableSlots.Keys) { if (!_attachableSlotControls.ContainsKey(slotId)) AddSlotControl(slotId); _attachableSlotControls[slotId].Update(attachableSlots[slotId].attachableName, attachableSlots[slotId].locked); } } private void AddSlotControl(string slotId, string? attachableName = null) { var slotControl = new AttachableSlotControl(_boundUI, slotId); AttachablesContainer.AddChild(slotControl); _attachableSlotControls.Add(slotId, slotControl); } private sealed class AttachableSlotControl : Control { private readonly Button AttachableButton; public AttachableSlotControl(AttachmentStripBui boundUI, string slotId) { var slotLabel = new Label { Text = Loc.GetString(slotId) + ':', HorizontalAlignment = HAlignment.Left }; AttachableButton = new Button { Text = Loc.GetString("rmc-attachable-holder-strip-ui-empty-slot"), HorizontalExpand = true, HorizontalAlignment = HAlignment.Right, StyleClasses = { StyleBase.ButtonOpenRight } }; var hBox = new BoxContainer { Orientation = LayoutOrientation.Horizontal, Children = { new Control { MinSize = new Vector2(5, 0) }, slotLabel, new Control { MinSize = new Vector2(5, 0) }, AttachableButton, }, }; AttachableButton.OnPressed += _ => boundUI.SendMessage(new AttachableHolderDetachMessage(slotId)); AddChild(hBox); } public void Update(string? attachableName, bool slotLocked) { if (attachableName == null) { AttachableButton.Text = Loc.GetString("rmc-attachable-holder-strip-ui-empty-slot"); AttachableButton.Disabled = true; return; } AttachableButton.Text = attachableName; AttachableButton.Disabled = slotLocked; } } }