From 70c3609ba83958c52a49f77d6c0c4e3f1196139e Mon Sep 17 00:00:00 2001 From: Kirus59 <145689588+Kirus59@users.noreply.github.com> Date: Sun, 5 Jan 2025 00:46:51 +0300 Subject: [PATCH] add ent sprites into recipe guidebook --- .../UI/Controls/GuideCookingRecipeEmbed.xaml | 14 +-- .../Controls/GuideCookingRecipeEmbed.xaml.cs | 93 ++++++++++++------- .../SupaKitchen/CookingRecipePrototype.cs | 4 +- .../SS220/SupaKitchen/Recipes/oven.yml | 1 + 4 files changed, 67 insertions(+), 45 deletions(-) diff --git a/Content.Client/SS220/SupaKitchen/UI/Controls/GuideCookingRecipeEmbed.xaml b/Content.Client/SS220/SupaKitchen/UI/Controls/GuideCookingRecipeEmbed.xaml index 01f5a463222733..717ab5ec8752a1 100644 --- a/Content.Client/SS220/SupaKitchen/UI/Controls/GuideCookingRecipeEmbed.xaml +++ b/Content.Client/SS220/SupaKitchen/UI/Controls/GuideCookingRecipeEmbed.xaml @@ -5,11 +5,11 @@ Margin="5 5 5 5"> - + - + @@ -19,10 +19,7 @@ Orientation="Horizontal" HorizontalAlignment="Stretch" HorizontalExpand="True"> - - + - - + diff --git a/Content.Client/SS220/SupaKitchen/UI/Controls/GuideCookingRecipeEmbed.xaml.cs b/Content.Client/SS220/SupaKitchen/UI/Controls/GuideCookingRecipeEmbed.xaml.cs index e9e16cd69fa76a..c4d99de289a468 100644 --- a/Content.Client/SS220/SupaKitchen/UI/Controls/GuideCookingRecipeEmbed.xaml.cs +++ b/Content.Client/SS220/SupaKitchen/UI/Controls/GuideCookingRecipeEmbed.xaml.cs @@ -12,6 +12,8 @@ using Content.Client.Message; using Robust.Shared.Utility; using Content.Shared.Chemistry.Reagent; +using Robust.Client.GameObjects; +using Content.Shared.FixedPoint; namespace Content.Client.SS220.SupaKitchen.UI.Controls; @@ -22,6 +24,9 @@ namespace Content.Client.SS220.SupaKitchen.UI.Controls; public sealed partial class GuideCookingRecipeEmbed : BoxContainer, IDocumentTag, ISearchableControl { [Dependency] private readonly IPrototypeManager _prototype = default!; + [Dependency] private readonly IEntitySystemManager _entSysmMan = default!; + + private readonly SpriteSystem _spriteSystem; private HashSet _nameSearchCache; @@ -31,6 +36,7 @@ public GuideCookingRecipeEmbed() { RobustXamlLoader.Load(this); IoCManager.InjectDependencies(this); + _spriteSystem = _entSysmMan.GetEntitySystem(); MouseFilter = MouseFilterMode.Stop; _sawmill = Logger.GetSawmill("KitchenCookbook"); @@ -87,37 +93,18 @@ private void GenerateControl(CookingRecipePrototype recipe) return; _nameSearchCache.Add(product.Name); - ProductsLabelTitle.SetMarkup(product.Name); - // RecipeName.Text = recipe.Name; - - // solid ingredients - var ingredientsMsg = new FormattedMessage(); - var solidIngredientsCount = recipe.IngredientsSolids.Count; - var i = 0; - foreach (var (ingredientId, ingredientAmount) in recipe.IngredientsSolids) - { - if (!_prototype.TryIndex(ingredientId, out var ingredientProto)) - { - solidIngredientsCount--; - continue; - } - - var ingredientName = ingredientProto.Name; - _nameSearchCache.Add(ingredientName); - - ingredientsMsg.AddMarkupOrThrow(Loc.GetString("guidebook-cooking-recipes-ingredient-display", - ("reagent", ingredientName), ("ratio", ingredientAmount))); - - i++; - if (i < solidIngredientsCount) - ingredientsMsg.PushNewline(); - } + RecipeLabelTitle.SetMarkup(product.Name); + //RecipeLabelTitle.SetMarkup(recipe.Name); // reagents + var reagentsMsg = new FormattedMessage(); var reagentIngredientsCount = recipe.IngredientsReagents.Count; - if (reagentIngredientsCount > 0) - ingredientsMsg.PushNewline(); var u = 0; + var reagentsLabel = new RichTextLabel() + { + HorizontalAlignment = HAlignment.Center, + VerticalAlignment = VAlignment.Center + }; foreach (var (ingredientId, ingredientAmount) in recipe.IngredientsReagents) { if (!_prototype.TryIndex(ingredientId, out var ingredientProto)) @@ -129,20 +116,35 @@ private void GenerateControl(CookingRecipePrototype recipe) var ingredientName = ingredientProto.LocalizedName; _nameSearchCache.Add(ingredientName); - ingredientsMsg.AddMarkupOrThrow(Loc.GetString("guidebook-cooking-recipes-ingredient-display", + reagentsMsg.AddMarkupOrThrow(Loc.GetString("guidebook-cooking-recipes-ingredient-display", ("reagent", ingredientName), ("ratio", ingredientAmount))); u++; if (u < reagentIngredientsCount) - ingredientsMsg.PushNewline(); + reagentsMsg.PushNewline(); + } + + if (!reagentsMsg.IsEmpty) + { + reagentsMsg.Pop(); + reagentsLabel.SetMessage(reagentsMsg); + IngredientsContainer.AddChild(reagentsLabel); } - ingredientsMsg.Pop(); - IngredientsLabel.SetMessage(ingredientsMsg); + // solid ingredients + foreach (var (ingredientId, ingredientAmount) in recipe.IngredientsSolids) + { + if (!_prototype.TryIndex(ingredientId, out var ingredientProto)) + continue; + + var ingredientName = ingredientProto.Name; + _nameSearchCache.Add(ingredientName); + + IngredientsContainer.AddChild(GetEntContainer(ingredientProto, ingredientAmount)); + } // output - ProductsLabel.SetMarkup(Loc.GetString("guidebook-cooking-recipes-ingredient-display", - ("reagent", product.Name), ("ratio", 1))); + ProductsContainer.AddChild(GetEntContainer(product, 1)); if (!_prototype.TryIndex(recipe.InstrumentType, out var instrumentProto)) return; @@ -157,4 +159,29 @@ private void GenerateControl(CookingRecipePrototype recipe) if (instrumentProto.IconPath is not null) InstrumentIcon.TexturePath = instrumentProto.IconPath; } + + private BoxContainer GetEntContainer(EntityPrototype prototype, FixedPoint2 amount) + { + var entContainer = new BoxContainer + { + Orientation = LayoutOrientation.Horizontal, + HorizontalExpand = true, + HorizontalAlignment = HAlignment.Center, + }; + + var entView = new EntityPrototypeView(); + entView.SetPrototype(prototype); + entContainer.AddChild(entView); + + var entMsg = new FormattedMessage(); + entMsg.AddMarkupOrThrow(Loc.GetString("guidebook-cooking-recipes-ingredient-display", + ("reagent", prototype.Name), ("ratio", amount))); + entMsg.Pop(); + + var entLabel = new RichTextLabel(); + entLabel.SetMessage(entMsg); + entContainer.AddChild(entLabel); + + return entContainer; + } } diff --git a/Content.Shared/SS220/SupaKitchen/CookingRecipePrototype.cs b/Content.Shared/SS220/SupaKitchen/CookingRecipePrototype.cs index c19e91ad1a57ec..3244d8f78614f7 100644 --- a/Content.Shared/SS220/SupaKitchen/CookingRecipePrototype.cs +++ b/Content.Shared/SS220/SupaKitchen/CookingRecipePrototype.cs @@ -25,8 +25,8 @@ public sealed class CookingRecipePrototype : IPrototype [DataField] public ProtoId Result { get; } = string.Empty; - [DataField] - public ProtoId InstrumentType { get; } = string.Empty; + [DataField(required: true)] + public ProtoId InstrumentType { get; } [DataField("time")] public uint CookTime { get; } = 5; diff --git a/Resources/Prototypes/SS220/SupaKitchen/Recipes/oven.yml b/Resources/Prototypes/SS220/SupaKitchen/Recipes/oven.yml index 50bfa76686d92e..2369c7c41501d1 100644 --- a/Resources/Prototypes/SS220/SupaKitchen/Recipes/oven.yml +++ b/Resources/Prototypes/SS220/SupaKitchen/Recipes/oven.yml @@ -89,6 +89,7 @@ id: RecipeCatBurger name: cat burger recipe result: FoodBurgerCat + instrumentType: oven time: 10 solids: FoodBreadBun: 1