show multiple recipes in the guidebook (#22463)

This commit is contained in:
Nemanja
2023-12-13 17:17:38 -05:00
committed by GitHub
parent 9864cb0232
commit 500675ba8a
5 changed files with 106 additions and 64 deletions

View File

@@ -14,29 +14,12 @@
<Collapsible Orientation="Vertical" HorizontalExpand="True">
<CollapsibleHeading Title="{Loc 'guidebook-reagent-recipes-header'}"/>
<CollapsibleBody>
<BoxContainer Name="RecipesDescriptionContainer"
<GridContainer Name="RecipesDescriptionContainer"
Margin="10 0 10 0"
Orientation="Horizontal"
Columns="1"
HSeparationOverride="5"
HorizontalAlignment="Stretch"
HorizontalExpand="True">
<BoxContainer Orientation="Vertical" HorizontalExpand="True" VerticalAlignment="Center">
<RichTextLabel Name="ReactantsLabel"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</BoxContainer>
<BoxContainer Orientation="Vertical" VerticalAlignment="Center">
<TextureRect TexturePath="/Textures/Interface/Misc/beakerlarge.png"
HorizontalAlignment="Center"/>
<Label Name="MixLabel"
Text="{Loc 'guidebook-reagent-recipes-mix'}"
HorizontalAlignment="Center"/>
</BoxContainer>
<BoxContainer Orientation="Vertical" HorizontalExpand="True" VerticalAlignment="Center">
<RichTextLabel Name="ProductsLabel"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</BoxContainer>
</BoxContainer>
HorizontalExpand="True"/>
</CollapsibleBody>
</Collapsible>
</BoxContainer>

View File

@@ -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))
{
reactionPrototype = _prototype.EnumeratePrototypes<ReactionPrototype>()
.FirstOrDefault(p => p.Products.ContainsKey(reagent.ID));
}
var reactions = _prototype.EnumeratePrototypes<ReactionPrototype>()
.Where(p => p.Products.ContainsKey(reagent.ID))
.OrderBy(p => p.Priority)
.ThenBy(p => p.Products.Count)
.ToList();
if (reactionPrototype != null)
if (reactions.Any())
{
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;
}
}

View File

@@ -0,0 +1,25 @@
<BoxContainer xmlns="https://spacestation14.io"
Orientation="Horizontal"
HorizontalAlignment="Stretch"
HorizontalExpand="True">
<BoxContainer Orientation="Vertical" HorizontalExpand="True" VerticalAlignment="Center">
<RichTextLabel Name="ReactantsLabel"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Access="Public"/>
</BoxContainer>
<BoxContainer Orientation="Vertical" VerticalAlignment="Center">
<TextureRect TexturePath="/Textures/Interface/Misc/beakerlarge.png"
HorizontalAlignment="Center"/>
<Label Name="MixLabel"
Text="{Loc 'guidebook-reagent-recipes-mix'}"
HorizontalAlignment="Center"
Access="Public"/>
</BoxContainer>
<BoxContainer Orientation="Vertical" HorizontalExpand="True" VerticalAlignment="Center">
<RichTextLabel Name="ProductsLabel"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Access="Public"/>
</BoxContainer>
</BoxContainer>

View File

@@ -0,0 +1,20 @@
using Content.Client.UserInterface.ControlExtensions;
using JetBrains.Annotations;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
namespace Content.Client.Guidebook.Controls;
[UsedImplicitly, GenerateTypedNameReferences]
public sealed partial class GuideReagentReaction : BoxContainer, ISearchableControl
{
public bool CheckMatchesSearch(string query)
{
return this.ChildrenContainText(query);
}
public void SetHiddenState(bool state, string query)
{
Visible = CheckMatchesSearch(query) ? state : !state;
}
}

View File

@@ -14,4 +14,4 @@ guidebook-reagent-recipes-mix = Mix
guidebook-reagent-recipes-mix-and-heat = Mix at above {$temperature}K
guidebook-reagent-effects-header = Effects
guidebook-reagent-effects-metabolism-group-rate = [bold]{$group}[/bold] [color=gray]({$rate} units per second)[/color]
guidebook-reagent-physical-description = Seems to be {$description}.
guidebook-reagent-physical-description = [italic]Seems to be {$description}.[/italic]