using Content.Client.UserInterface.Controls; using Content.Shared._DV.Light.Events; using Content.Shared.Light.Components; using JetBrains.Annotations; using Robust.Client.UserInterface; using Robust.Shared.Prototypes; namespace Content.Client._DV.Light.BoundUserInterfaces; [UsedImplicitly] public sealed class LightReplacerMenuBoundUserInterface(EntityUid owner, Enum uiKey) : BoundUserInterface(owner, uiKey) { private EntityQuery _lightBulbQuery; private EntityQuery _metaDataQuery; private SimpleRadialMenu? _menu; protected override void Open() { base.Open(); _lightBulbQuery = EntMan.GetEntityQuery(); _metaDataQuery = EntMan.GetEntityQuery(); if (!EntMan.TryGetComponent(Owner, out var replacer)) return; var lightTypes = CreateButtons(replacer); if (lightTypes == null) return; _menu = this.CreateWindow(); _menu.SetButtons(lightTypes); _menu.OpenCentered(); } private List? CreateButtons(LightReplacerComponent replacer) { var options = new List(); Dictionary tubes = []; Dictionary bulbs = []; var hasActiveTubes = false; var hasActiveBulbs = false; foreach (var light in replacer.InsertedBulbs.ContainedEntities) { if (!_lightBulbQuery.TryComp(light, out var bulb) || !_metaDataQuery.TryComp(light, out var metaData)) continue; if (bulb.Type == LightBulbType.Tube) { if (metaData.EntityName != replacer.ActiveLightTube) tubes.TryAdd(metaData.EntityName, light); else hasActiveTubes = true; } else { if (metaData.EntityName != replacer.ActiveLightBulb) bulbs.TryAdd(metaData.EntityName, light); else hasActiveBulbs = true; } } if (hasActiveTubes) { var toggleLightTubes = new RadialMenuActionOption(EjectLights, replacer.ActiveLightTube) { IconSpecifier = RadialMenuIconSpecifier.With(replacer.EjectTubes), ToolTip = Loc.GetString("comp-light-replacer-eject-specified-lights", ("light-name", replacer.ActiveLightTube)), }; options.Add(toggleLightTubes); } if (hasActiveBulbs) { var toggleLightBulbs = new RadialMenuActionOption(EjectLights, replacer.ActiveLightBulb) { IconSpecifier = RadialMenuIconSpecifier.With(replacer.EjectBulbs), ToolTip = Loc.GetString("comp-light-replacer-eject-specified-lights", ("light-name", replacer.ActiveLightBulb)), }; options.Add(toggleLightBulbs); } // This iterates through every unique light to add them as options. foreach (var light in tubes) { PopulateOptions(light.Key, light.Value, LightBulbType.Tube, ref options); } foreach (var light in bulbs) { PopulateOptions(light.Key, light.Value, LightBulbType.Bulb, ref options); } return options; } private void PopulateOptions(string name, EntityUid light, LightBulbType lightType, ref List options) { var switchLight = new RadialMenuActionOption<(string, LightBulbType)>(SwitchActiveLight, (name, lightType)) { IconSpecifier = RadialMenuIconSpecifier.With(light), ToolTip = Loc.GetString("comp-light-replacer-select-lights", ("light-name", name)), }; options.Add(switchLight); } private void SwitchActiveLight((string, LightBulbType) light) { var message = new SwitchLightTypeMessage(light); SendPredictedMessage(message); } private void EjectLights(string lightName) { var message = new EjectLightTypeMessage(lightName); SendPredictedMessage(message); } }