using Content.Shared.Research.Prototypes; using Robust.Client.AutoGenerated; using Robust.Client.UserInterface; using Robust.Client.UserInterface.XAML; using Robust.Shared.Prototypes; namespace Content.Client.Lathe.UI; [GenerateTypedNameReferences] public sealed partial class RecipeControl : Control { public Action? OnButtonPressed; public Func TooltipTextSupplier; private ProtoId _recipeId; private LatheSystem _latheSystem; public RecipeControl(LatheSystem latheSystem, LatheRecipePrototype recipe, Func tooltipTextSupplier, bool canProduce, Control displayControl) { RobustXamlLoader.Load(this); _latheSystem = latheSystem; _recipeId = recipe.ID; TooltipTextSupplier = tooltipTextSupplier; SetRecipe(recipe); SetCanProduce(canProduce); SetDisplayControl(displayControl); Button.OnPressed += (_) => { OnButtonPressed?.Invoke(_recipeId); }; Button.TooltipSupplier = SupplyTooltip; } public void SetRecipe(LatheRecipePrototype recipe) { RecipeName.Text = _latheSystem.GetRecipeName(recipe); _recipeId = recipe.ID; } public void SetTooltipSupplier(Func tooltipTextSupplier) { TooltipTextSupplier = tooltipTextSupplier; } public void SetCanProduce(bool canProduce) { Button.Disabled = !canProduce; } public void SetDisplayControl(Control displayControl) { RecipeDisplayContainer.Children.Clear(); RecipeDisplayContainer.AddChild(displayControl); } private Control? SupplyTooltip(Control sender) { return new RecipeTooltip(TooltipTextSupplier()); } }