From: Nemanja <98561806+EmoGarbage404@users.noreply.github.com>
Date: Wed, 13 Dec 2023 22:17:38 +0000 (-0500)
Subject: show multiple recipes in the guidebook (#22463)
X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=500675ba8a1506f49b4b9b93c3148818fc6f822d;p=space-station-14.git
show multiple recipes in the guidebook (#22463)
---
diff --git a/Content.Client/Guidebook/Controls/GuideReagentEmbed.xaml b/Content.Client/Guidebook/Controls/GuideReagentEmbed.xaml
index f83eb8c240..7b1beeeb65 100644
--- a/Content.Client/Guidebook/Controls/GuideReagentEmbed.xaml
+++ b/Content.Client/Guidebook/Controls/GuideReagentEmbed.xaml
@@ -14,29 +14,12 @@
-
-
-
-
-
-
-
-
-
-
-
-
+ HorizontalExpand="True"/>
diff --git a/Content.Client/Guidebook/Controls/GuideReagentEmbed.xaml.cs b/Content.Client/Guidebook/Controls/GuideReagentEmbed.xaml.cs
index 5c2caf2230..a292a93ea6 100644
--- a/Content.Client/Guidebook/Controls/GuideReagentEmbed.xaml.cs
+++ b/Content.Client/Guidebook/Controls/GuideReagentEmbed.xaml.cs
@@ -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(reagent.ID, out var reactionPrototype))
- {
- reactionPrototype = _prototype.EnumeratePrototypes()
- .FirstOrDefault(p => p.Products.ContainsKey(reagent.ID));
- }
+ var reactions = _prototype.EnumeratePrototypes()
+ .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)
- {
- reactantMsg.AddMarkup(Loc.GetString("guidebook-reagent-recipes-reagent-display",
- ("reagent", _prototype.Index(product).LocalizedName), ("ratio", reactant.Amount)));
- i++;
- if (i < reactantsCount)
- reactantMsg.PushNewline();
- }
- reactantMsg.Pop();
- ReactantsLabel.SetMessage(reactantMsg);
-
- if (reactionPrototype.MinimumTemperature > 0.0f)
+ foreach (var reactionPrototype in reactions)
{
- MixLabel.Text = Loc.GetString("guidebook-reagent-recipes-mix-and-heat",
- ("temperature", reactionPrototype.MinimumTemperature));
+ var ctrl = GetRecipeGuide(reactionPrototype);
+ RecipesDescriptionContainer.AddChild(ctrl);
}
-
- 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(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(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(product).LocalizedName), ("ratio", ratio)));
+ u++;
+ if (u < productCount)
+ productMsg.PushNewline();
+ }
+ productMsg.Pop();
+ control.ProductsLabel.SetMessage(productMsg);
+ return control;
+ }
}
diff --git a/Content.Client/Guidebook/Controls/GuideReagentReaction.xaml b/Content.Client/Guidebook/Controls/GuideReagentReaction.xaml
new file mode 100644
index 0000000000..3f10592519
--- /dev/null
+++ b/Content.Client/Guidebook/Controls/GuideReagentReaction.xaml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Content.Client/Guidebook/Controls/GuideReagentReaction.xaml.cs b/Content.Client/Guidebook/Controls/GuideReagentReaction.xaml.cs
new file mode 100644
index 0000000000..fbc6bf13fc
--- /dev/null
+++ b/Content.Client/Guidebook/Controls/GuideReagentReaction.xaml.cs
@@ -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;
+ }
+}
diff --git a/Resources/Locale/en-US/guidebook/chemistry/core.ftl b/Resources/Locale/en-US/guidebook/chemistry/core.ftl
index c9d1db332d..960a9972c4 100644
--- a/Resources/Locale/en-US/guidebook/chemistry/core.ftl
+++ b/Resources/Locale/en-US/guidebook/chemistry/core.ftl
@@ -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]