]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
show multiple recipes in the guidebook (#22463)
authorNemanja <98561806+EmoGarbage404@users.noreply.github.com>
Wed, 13 Dec 2023 22:17:38 +0000 (17:17 -0500)
committerGitHub <noreply@github.com>
Wed, 13 Dec 2023 22:17:38 +0000 (15:17 -0700)
Content.Client/Guidebook/Controls/GuideReagentEmbed.xaml
Content.Client/Guidebook/Controls/GuideReagentEmbed.xaml.cs
Content.Client/Guidebook/Controls/GuideReagentReaction.xaml [new file with mode: 0644]
Content.Client/Guidebook/Controls/GuideReagentReaction.xaml.cs [new file with mode: 0644]
Resources/Locale/en-US/guidebook/chemistry/core.ftl

index f83eb8c2407bd81be96f594c71e88fbddba61b30..7b1beeeb6504224cd78cf78279a28bef72ad0eb3 100644 (file)
                 <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>
index 5c2caf2230f8c1696189a8287fa289e9903a29d7..a292a93ea6d024086ced7c067cf7f1ee84a9c648 100644 (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)
-            {
-                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();
-            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<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;
+    }
 }
diff --git a/Content.Client/Guidebook/Controls/GuideReagentReaction.xaml b/Content.Client/Guidebook/Controls/GuideReagentReaction.xaml
new file mode 100644 (file)
index 0000000..3f10592
--- /dev/null
@@ -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>
diff --git a/Content.Client/Guidebook/Controls/GuideReagentReaction.xaml.cs b/Content.Client/Guidebook/Controls/GuideReagentReaction.xaml.cs
new file mode 100644 (file)
index 0000000..fbc6bf1
--- /dev/null
@@ -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;
+    }
+}
index c9d1db332d7118e4f99aba434ddae37c9cf8bfd4..960a9972c4ced8837d8e60ee551299c5f6305f74 100644 (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]