Add reagent sources to the guidebook (#22627)
* source in my guidebook * finish it! * sir yes sir oorah * network that bitch, baby
This commit is contained in:
@@ -6,10 +6,8 @@ using Content.Client.Message;
|
||||
using Content.Client.UserInterface.ControlExtensions;
|
||||
using Content.Shared.Chemistry.Reaction;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Localizations;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
@@ -99,7 +97,7 @@ public sealed partial class GuideReagentEmbed : BoxContainer, IDocumentTag, ISea
|
||||
|
||||
#region Recipe
|
||||
var reactions = _prototype.EnumeratePrototypes<ReactionPrototype>()
|
||||
.Where(p => p.Products.ContainsKey(reagent.ID))
|
||||
.Where(p => !p.Source && p.Products.ContainsKey(reagent.ID))
|
||||
.OrderBy(p => p.Priority)
|
||||
.ThenBy(p => p.Products.Count)
|
||||
.ToList();
|
||||
@@ -108,8 +106,7 @@ public sealed partial class GuideReagentEmbed : BoxContainer, IDocumentTag, ISea
|
||||
{
|
||||
foreach (var reactionPrototype in reactions)
|
||||
{
|
||||
var ctrl = GetRecipeGuide(reactionPrototype);
|
||||
RecipesDescriptionContainer.AddChild(ctrl);
|
||||
RecipesDescriptionContainer.AddChild(new GuideReagentReaction(reactionPrototype, _prototype, _systemManager));
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -159,6 +156,8 @@ public sealed partial class GuideReagentEmbed : BoxContainer, IDocumentTag, ISea
|
||||
}
|
||||
#endregion
|
||||
|
||||
GenerateSources(reagent);
|
||||
|
||||
FormattedMessage description = new();
|
||||
description.AddText(reagent.LocalizedDescription);
|
||||
description.PushNewline();
|
||||
@@ -167,64 +166,45 @@ public sealed partial class GuideReagentEmbed : BoxContainer, IDocumentTag, ISea
|
||||
ReagentDescription.SetMessage(description);
|
||||
}
|
||||
|
||||
private GuideReagentReaction GetRecipeGuide(ReactionPrototype reactionPrototype)
|
||||
private void GenerateSources(ReagentPrototype reagent)
|
||||
{
|
||||
var control = new GuideReagentReaction();
|
||||
|
||||
var reactantMsg = new FormattedMessage();
|
||||
var reactantsCount = reactionPrototype.Reactants.Count;
|
||||
var i = 0;
|
||||
foreach (var (product, reactant) in reactionPrototype.Reactants)
|
||||
var sources = _chemistryGuideData.GetReagentSources(reagent.ID);
|
||||
if (sources.Count == 0)
|
||||
{
|
||||
reactantMsg.AddMarkup(Loc.GetString("guidebook-reagent-recipes-reagent-display",
|
||||
("reagent", _prototype.Index<ReagentPrototype>(product).LocalizedName), ("ratio", reactant.Amount)));
|
||||
i++;
|
||||
if (i < reactantsCount)
|
||||
reactantMsg.PushNewline();
|
||||
SourcesContainer.Visible = false;
|
||||
return;
|
||||
}
|
||||
reactantMsg.Pop();
|
||||
control.ReactantsLabel.SetMessage(reactantMsg);
|
||||
SourcesContainer.Visible = true;
|
||||
|
||||
var productMsg = new FormattedMessage();
|
||||
var productCount = reactionPrototype.Products.Count;
|
||||
var u = 0;
|
||||
foreach (var (product, ratio) in reactionPrototype.Products)
|
||||
var orderedSources = sources
|
||||
.OrderBy(o => o.OutputCount)
|
||||
.ThenBy(o => o.IdentifierString);
|
||||
foreach (var source in orderedSources)
|
||||
{
|
||||
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);
|
||||
|
||||
var mixingCategories = new List<MixingCategoryPrototype>();
|
||||
if (reactionPrototype.MixingCategories != null)
|
||||
{
|
||||
foreach (var category in reactionPrototype.MixingCategories)
|
||||
if (source is ReagentEntitySourceData entitySourceData)
|
||||
{
|
||||
mixingCategories.Add(_prototype.Index(category));
|
||||
SourcesDescriptionContainer.AddChild(new GuideReagentReaction(
|
||||
entitySourceData.SourceEntProto,
|
||||
entitySourceData.Solution,
|
||||
entitySourceData.MixingType,
|
||||
_prototype,
|
||||
_systemManager));
|
||||
}
|
||||
else if (source is ReagentReactionSourceData reactionSourceData)
|
||||
{
|
||||
SourcesDescriptionContainer.AddChild(new GuideReagentReaction(
|
||||
reactionSourceData.ReactionPrototype,
|
||||
_prototype,
|
||||
_systemManager));
|
||||
}
|
||||
else if (source is ReagentGasSourceData gasSourceData)
|
||||
{
|
||||
SourcesDescriptionContainer.AddChild(new GuideReagentReaction(
|
||||
gasSourceData.GasPrototype,
|
||||
gasSourceData.MixingType,
|
||||
_prototype,
|
||||
_systemManager));
|
||||
}
|
||||
}
|
||||
|
||||
// only use the first one for the icon.
|
||||
if (mixingCategories.FirstOrDefault() is { } primaryCategory)
|
||||
{
|
||||
control.MixTexture.Texture = _systemManager.GetEntitySystem<SpriteSystem>().Frame0(primaryCategory.Icon);
|
||||
}
|
||||
|
||||
var mixingVerb = mixingCategories.Count == 0
|
||||
? Loc.GetString("guidebook-reagent-recipes-mix")
|
||||
: ContentLocalizationManager.FormatList(mixingCategories.Select(p => Loc.GetString(p.VerbText)).ToList());
|
||||
|
||||
var text = Loc.GetString("guidebook-reagent-recipes-mix-info",
|
||||
("verb", mixingVerb),
|
||||
("minTemp", reactionPrototype.MinimumTemperature),
|
||||
("maxTemp", reactionPrototype.MaximumTemperature),
|
||||
("hasMax", !float.IsPositiveInfinity(reactionPrototype.MaximumTemperature)));
|
||||
|
||||
control.MixLabel.SetMarkup(text);
|
||||
return control;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user