mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-12 11:51:11 +03:00
* LatheMenu: cache where possible in PopulateRecipes * Princess Cheeseballs' review + protected HasRecipe Co-authored-by: Princess-Cheeseballs <66055347+Princess-Cheeseballs@users.noreply@github.com> * private HasMaterials with comment --------- Co-authored-by: Princess-Cheeseballs <66055347+Princess-Cheeseballs@users.noreply@github.com>
62 lines
1.8 KiB
C#
62 lines
1.8 KiB
C#
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<string>? OnButtonPressed;
|
|
public Func<string> TooltipTextSupplier;
|
|
|
|
public ProtoId<LatheRecipePrototype> RecipeId { get; private set; }
|
|
private LatheSystem _latheSystem;
|
|
|
|
public RecipeControl(LatheSystem latheSystem, LatheRecipePrototype recipe, Func<string> tooltipTextSupplier, bool canProduce, Control displayControl, string? recipeName = null)
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
|
|
_latheSystem = latheSystem;
|
|
RecipeId = recipe.ID;
|
|
TooltipTextSupplier = tooltipTextSupplier;
|
|
SetRecipe(recipe, recipeName);
|
|
SetCanProduce(canProduce);
|
|
SetDisplayControl(displayControl);
|
|
|
|
Button.OnPressed += (_) =>
|
|
{
|
|
OnButtonPressed?.Invoke(RecipeId);
|
|
};
|
|
Button.TooltipSupplier = SupplyTooltip;
|
|
}
|
|
|
|
public void SetRecipe(LatheRecipePrototype recipe, string? recipeName = null)
|
|
{
|
|
RecipeName.Text = recipeName ?? _latheSystem.GetRecipeName(recipe);
|
|
RecipeId = recipe.ID;
|
|
}
|
|
|
|
public void SetTooltipSupplier(Func<string> 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());
|
|
}
|
|
}
|