using Content.Client.UserInterface.Controls; using Robust.Client.AutoGenerated; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.XAML; namespace Content.Client.SprayPainter.UI; /// /// Used to display a group of paintable styles in the spray painter menu. /// (e.g. each type of paintable locker or plastic crate) /// [GenerateTypedNameReferences] public sealed partial class SprayPainterGroup : BoxContainer { public event Action? OnButtonPressed; public SprayPainterGroup() { RobustXamlLoader.Load(this); StyleList.GenerateItem = GenerateItems; } public void PopulateList(List spriteList) { StyleList.PopulateList(spriteList); } public void SelectItemByStyle(string key) { foreach (var elem in StyleList.Data) { if (elem is not SpriteListData spriteElem) continue; if (spriteElem.Style == key) { StyleList.Select(spriteElem); break; } } } private void GenerateItems(ListData data, ListContainerButton button) { if (data is not SpriteListData spriteListData) return; var box = new BoxContainer() { Orientation = LayoutOrientation.Horizontal }; var protoView = new EntityPrototypeView(); protoView.SetPrototype(spriteListData.Prototype); var label = new Label() { Text = Loc.GetString($"spray-painter-style-{spriteListData.Group.ToLower()}-{spriteListData.Style.ToLower()}") }; box.AddChild(protoView); box.AddChild(label); button.AddChild(box); button.AddStyleClass(ListContainer.StyleClassListContainerButton); button.OnPressed += _ => OnButtonPressed?.Invoke(spriteListData); if (spriteListData.SelectedIndex == button.Index) button.Pressed = true; } }