show multiple recipes in the guidebook (#22463)
This commit is contained in:
@@ -84,7 +84,11 @@ public sealed partial class GuideReagentEmbed : BoxContainer, IDocumentTag, ISea
|
||||
BackgroundColor = reagent.SubstanceColor
|
||||
};
|
||||
|
||||
var textColor = Color.ToHsl(reagent.SubstanceColor).Z > 0.45
|
||||
var r = reagent.SubstanceColor.R;
|
||||
var g = reagent.SubstanceColor.G;
|
||||
var b = reagent.SubstanceColor.B;
|
||||
|
||||
var textColor = 0.2126f * r + 0.7152f * g + 0.0722f * b > 0.5
|
||||
? Color.Black
|
||||
: Color.White;
|
||||
|
||||
@@ -92,49 +96,19 @@ public sealed partial class GuideReagentEmbed : BoxContainer, IDocumentTag, ISea
|
||||
("color", textColor), ("name", reagent.LocalizedName)));
|
||||
|
||||
#region Recipe
|
||||
// by default, we assume that the reaction has the same ID as the reagent.
|
||||
// if this isn't true, we'll loop through reactions.
|
||||
if (!_prototype.TryIndex<ReactionPrototype>(reagent.ID, out var reactionPrototype))
|
||||
var reactions = _prototype.EnumeratePrototypes<ReactionPrototype>()
|
||||
.Where(p => p.Products.ContainsKey(reagent.ID))
|
||||
.OrderBy(p => p.Priority)
|
||||
.ThenBy(p => p.Products.Count)
|
||||
.ToList();
|
||||
|
||||
if (reactions.Any())
|
||||
{
|
||||
reactionPrototype = _prototype.EnumeratePrototypes<ReactionPrototype>()
|
||||
.FirstOrDefault(p => p.Products.ContainsKey(reagent.ID));
|
||||
}
|
||||
|
||||
if (reactionPrototype != null)
|
||||
{
|
||||
var reactantMsg = new FormattedMessage();
|
||||
var reactantsCount = reactionPrototype.Reactants.Count;
|
||||
var i = 0;
|
||||
foreach (var (product, reactant) in reactionPrototype.Reactants)
|
||||
foreach (var reactionPrototype in reactions)
|
||||
{
|
||||
reactantMsg.AddMarkup(Loc.GetString("guidebook-reagent-recipes-reagent-display",
|
||||
("reagent", _prototype.Index<ReagentPrototype>(product).LocalizedName), ("ratio", reactant.Amount)));
|
||||
i++;
|
||||
if (i < reactantsCount)
|
||||
reactantMsg.PushNewline();
|
||||
var ctrl = GetRecipeGuide(reactionPrototype);
|
||||
RecipesDescriptionContainer.AddChild(ctrl);
|
||||
}
|
||||
reactantMsg.Pop();
|
||||
ReactantsLabel.SetMessage(reactantMsg);
|
||||
|
||||
if (reactionPrototype.MinimumTemperature > 0.0f)
|
||||
{
|
||||
MixLabel.Text = Loc.GetString("guidebook-reagent-recipes-mix-and-heat",
|
||||
("temperature", reactionPrototype.MinimumTemperature));
|
||||
}
|
||||
|
||||
var productMsg = new FormattedMessage();
|
||||
var productCount = reactionPrototype.Products.Count;
|
||||
var u = 0;
|
||||
foreach (var (product, ratio) in reactionPrototype.Products)
|
||||
{
|
||||
productMsg.AddMarkup(Loc.GetString("guidebook-reagent-recipes-reagent-display",
|
||||
("reagent", _prototype.Index<ReagentPrototype>(product).LocalizedName), ("ratio", ratio)));
|
||||
u++;
|
||||
if (u < productCount)
|
||||
productMsg.PushNewline();
|
||||
}
|
||||
productMsg.Pop();
|
||||
ProductsLabel.SetMessage(productMsg);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -186,8 +160,48 @@ public sealed partial class GuideReagentEmbed : BoxContainer, IDocumentTag, ISea
|
||||
FormattedMessage description = new();
|
||||
description.AddText(reagent.LocalizedDescription);
|
||||
description.PushNewline();
|
||||
description.AddText(Loc.GetString("guidebook-reagent-physical-description",
|
||||
description.AddMarkup(Loc.GetString("guidebook-reagent-physical-description",
|
||||
("description", reagent.LocalizedPhysicalDescription)));
|
||||
ReagentDescription.SetMessage(description);
|
||||
}
|
||||
|
||||
private GuideReagentReaction GetRecipeGuide(ReactionPrototype reactionPrototype)
|
||||
{
|
||||
var control = new GuideReagentReaction();
|
||||
|
||||
var reactantMsg = new FormattedMessage();
|
||||
var reactantsCount = reactionPrototype.Reactants.Count;
|
||||
var i = 0;
|
||||
foreach (var (product, reactant) in reactionPrototype.Reactants)
|
||||
{
|
||||
reactantMsg.AddMarkup(Loc.GetString("guidebook-reagent-recipes-reagent-display",
|
||||
("reagent", _prototype.Index<ReagentPrototype>(product).LocalizedName), ("ratio", reactant.Amount)));
|
||||
i++;
|
||||
if (i < reactantsCount)
|
||||
reactantMsg.PushNewline();
|
||||
}
|
||||
reactantMsg.Pop();
|
||||
control.ReactantsLabel.SetMessage(reactantMsg);
|
||||
|
||||
if (reactionPrototype.MinimumTemperature > 0.0f)
|
||||
{
|
||||
control.MixLabel.Text = Loc.GetString("guidebook-reagent-recipes-mix-and-heat",
|
||||
("temperature", reactionPrototype.MinimumTemperature));
|
||||
}
|
||||
|
||||
var productMsg = new FormattedMessage();
|
||||
var productCount = reactionPrototype.Products.Count;
|
||||
var u = 0;
|
||||
foreach (var (product, ratio) in reactionPrototype.Products)
|
||||
{
|
||||
productMsg.AddMarkup(Loc.GetString("guidebook-reagent-recipes-reagent-display",
|
||||
("reagent", _prototype.Index<ReagentPrototype>(product).LocalizedName), ("ratio", ratio)));
|
||||
u++;
|
||||
if (u < productCount)
|
||||
productMsg.PushNewline();
|
||||
}
|
||||
productMsg.Pop();
|
||||
control.ProductsLabel.SetMessage(productMsg);
|
||||
return control;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user