Skip to content

Commit

Permalink
add ent sprites into recipe guidebook
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirus59 committed Jan 4, 2025
1 parent 7401a35 commit 70c3609
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
Margin="5 5 5 5">
<PanelContainer HorizontalExpand="True">
<PanelContainer.PanelOverride>
<gfx:StyleBoxFlat BorderThickness="1" BorderColor="#777777"/>
<gfx:StyleBoxFlat BorderThickness="1.5" BorderColor="#777777"/>
</PanelContainer.PanelOverride>
<BoxContainer Orientation="Vertical">
<PanelContainer Name="NameBackground" HorizontalExpand="True" VerticalExpand="False">
<RichTextLabel Name="ProductsLabelTitle" HorizontalAlignment="Center"/>
<RichTextLabel Name="RecipeLabelTitle" HorizontalAlignment="Center"/>
</PanelContainer>

<BoxContainer Name="RecipeContainer" HorizontalExpand="True" Orientation="Vertical">
Expand All @@ -19,10 +19,7 @@
Orientation="Horizontal"
HorizontalAlignment="Stretch"
HorizontalExpand="True">
<BoxContainer Orientation="Vertical" HorizontalExpand="True" VerticalAlignment="Center">
<RichTextLabel Name="IngredientsLabel"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
<BoxContainer Name="IngredientsContainer" Orientation="Vertical" HorizontalExpand="True" VerticalAlignment="Center">
</BoxContainer>
<BoxContainer Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="10 0">
<TextureRect
Expand All @@ -32,10 +29,7 @@
<RichTextLabel Name="InstrumentName"
HorizontalAlignment="Center"/>
</BoxContainer>
<BoxContainer Orientation="Vertical" HorizontalExpand="True" VerticalAlignment="Center">
<RichTextLabel Name="ProductsLabel"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
<BoxContainer Name="ProductsContainer" Orientation="Vertical" HorizontalExpand="True" VerticalAlignment="Center">
</BoxContainer>
</BoxContainer>
</BoxContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<string> _nameSearchCache;

Expand All @@ -31,6 +36,7 @@ public GuideCookingRecipeEmbed()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
_spriteSystem = _entSysmMan.GetEntitySystem<SpriteSystem>();

MouseFilter = MouseFilterMode.Stop;
_sawmill = Logger.GetSawmill("KitchenCookbook");
Expand Down Expand Up @@ -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<EntityPrototype>(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<ReagentPrototype>(ingredientId, out var ingredientProto))
Expand All @@ -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<EntityPrototype>(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<CookingInstrumentTypePrototype>(recipe.InstrumentType, out var instrumentProto))
return;
Expand All @@ -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;
}
}
4 changes: 2 additions & 2 deletions Content.Shared/SS220/SupaKitchen/CookingRecipePrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public sealed class CookingRecipePrototype : IPrototype
[DataField]
public ProtoId<EntityPrototype> Result { get; } = string.Empty;

[DataField]
public ProtoId<CookingInstrumentTypePrototype> InstrumentType { get; } = string.Empty;
[DataField(required: true)]
public ProtoId<CookingInstrumentTypePrototype> InstrumentType { get; }

[DataField("time")]
public uint CookTime { get; } = 5;
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/SS220/SupaKitchen/Recipes/oven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
id: RecipeCatBurger
name: cat burger recipe
result: FoodBurgerCat
instrumentType: oven
time: 10
solids:
FoodBreadBun: 1
Expand Down

0 comments on commit 70c3609

Please sign in to comment.