using Content.Client.Stylesheets.Palette; using Content.Client.UserInterface.Controls; using Content.Shared.Changeling.Components; using Content.Shared.Changeling.Systems; using JetBrains.Annotations; using Robust.Client.UserInterface; using Robust.Shared.Utility; namespace Content.Client.Changeling.UI; [UsedImplicitly] public sealed partial class ChangelingTransformBoundUserInterface(EntityUid owner, Enum uiKey) : BoundUserInterface(owner, uiKey) { private SimpleRadialMenu? _menu; private static readonly Color SelectedOptionBackground = Palettes.Green.Element.WithAlpha(128); private static readonly Color DisabledOptionBackground = Palettes.Slate.Element.WithAlpha(128); private static readonly Color SelectedOptionHoverBackground = Palettes.Green.HoveredElement.WithAlpha(128); private static readonly Color DisabledOptionHoverBackground = Palettes.Slate.HoveredElement.WithAlpha(128); protected override void Open() { base.Open(); _menu = this.CreateWindow(); Update(); _menu.OpenOverMouseScreenPosition(); } public override void Update() { if (_menu == null) return; if (!EntMan.TryGetComponent(Owner, out var lingIdentity)) return; var manualDrop = true; if (EntMan.TryGetComponent(Owner, out var lingTransform)) manualDrop = lingTransform.ManualDrop; var models = ConvertToButtons(lingIdentity.ConsumedIdentities, lingIdentity.CurrentIdentity, manualDrop); _menu.SetButtons(models); } private IEnumerable ConvertToButtons( IEnumerable identities, EntityUid? currentIdentity, bool canDrop ) { var buttons = new List(); var dropButtons = new List(); foreach (var identity in identities) { if (identity.Identity == null) continue; // Options for selecting identities. var option = new RadialMenuActionOption(SendIdentitySelect, EntMan.GetNetEntity(identity.Identity.Value)) { IconSpecifier = RadialMenuIconSpecifier.With(identity.Identity.Value), ToolTip = Loc.GetString("changeling-transform-bui-select-entity", ("entity", identity.Identity)), BackgroundColor = (currentIdentity == identity.Identity) ? SelectedOptionBackground : null, // mark as selected HoverBackgroundColor = (currentIdentity == identity.Identity) ? SelectedOptionHoverBackground : null, }; buttons.Add(option); if (!canDrop) continue; // Options for dropping identities. var dropOption = new RadialMenuActionOption(SendIdentityDrop, EntMan.GetNetEntity(identity.Identity.Value)) { IconSpecifier = RadialMenuIconSpecifier.With(identity.Identity.Value), ToolTip = (currentIdentity == identity.Identity) ? Loc.GetString("changeling-transform-bui-drop-identity-cannot-drop") : Loc.GetString("changeling-transform-bui-drop-identity-entity", ("entity", identity.Identity)), BackgroundColor = (currentIdentity == identity.Identity) ? DisabledOptionBackground : null, // cannot drop your current identity HoverBackgroundColor = (currentIdentity == identity.Identity) ? DisabledOptionHoverBackground : null, }; dropButtons.Add(dropOption); } if (canDrop) { // Menu category for dropping identities. var dropMenuButton = new RadialMenuNestedLayerOption(dropButtons) { IconSpecifier = RadialMenuIconSpecifier.With(new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/delete.svg.192dpi.png"))), ToolTip = Loc.GetString("changeling-transform-bui-drop-identity-menu"), Order = 0, // Explicit first option. }; buttons.Add(dropMenuButton); } return buttons; } private void SendIdentitySelect(NetEntity identityId) { SendPredictedMessage(new ChangelingTransformIdentitySelectMessage(identityId)); } private void SendIdentityDrop(NetEntity identityId) { SendPredictedMessage(new ChangelingTransformIdentityDropMessage(identityId)); } }