6
2025-11-05 11:11:22 +03:00

97 lines
3.8 KiB
C#

using System.Linq;
using Content.Client.Chemistry.EntitySystems;
using Content.Client.Guidebook.Controls;
using Content.Client.UserInterface.ControlExtensions;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Content.Shared.Kitchen;
using JetBrains.Annotations;
using Robust.Client.AutoGenerated;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Content.Client._NF.Guidebook.Controls;
[UsedImplicitly, GenerateTypedNameReferences]
public sealed partial class GuideMedicalSource : BoxContainer, ISearchableControl
{
private readonly IPrototypeManager _protoMan;
private readonly SpriteSystem _sprites = default!;
public GuideMedicalSource(IPrototypeManager protoMan)
{
RobustXamlLoader.Load(this);
_protoMan = protoMan;
_sprites = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<SpriteSystem>();
}
public GuideMedicalSource(EntityPrototype result, MedicalRecipeData entry, IPrototypeManager protoMan) : this(protoMan)
{
GenerateControl(entry);
GenerateOutputs(result, entry);
}
private void GenerateControl(MedicalRecipeData entry)
{
if (!_protoMan.TryIndex(entry.Recipe, out var recipe))
{
SourceLabel.Text = Loc.GetString("guidebook-food-unknown-proto", ("id", entry.Result)); // Frontier: SetMessage<Text
return;
}
var combinedSolids = recipe.IngredientsSolids
.Select(it => _protoMan.TryIndex<EntityPrototype>(it.Key, out var proto) ? FormatIngredient(proto, it.Value) : "")
.Where(it => it.Length > 0);
var combinedLiquids = recipe.IngredientsReagents
.Select(it => _protoMan.TryIndex<ReagentPrototype>(it.Key, out var proto) ? FormatIngredient(proto, it.Value) : "")
.Where(it => it.Length > 0);
var combinedIngredients = string.Join("\n", combinedLiquids.Union(combinedSolids));
SourceLabel.Text = Loc.GetString("guidebook-food-processing-recipe", ("ingredients", combinedIngredients)); // Frontier: SetMessage<Text
var recipeType = (MicrowaveRecipeType)recipe.RecipeType;
TextureRect processingTexture;
processingTexture = new TextureRect();
processingTexture.Texture = GetRsiTexture("/Textures/_NF/Structures/Machines/medical_assembler.rsi", "mediwave-base");
ProcessingTextures.AddChild(processingTexture);
ProcessingLabel.Text = Loc.GetString("guidebook-food-processing-cooking", ("processingTypes", Loc.GetString("guidebook-food-processing-type-medical-assembler")), ("time", recipe.CookTime));
}
private Texture GetRsiTexture(string path, string state)
{
return _sprites.Frame0(new SpriteSpecifier.Rsi(new ResPath(path), state));
}
private void GenerateOutputs(EntityPrototype result, MedicalRecipeData entry)
{
OutputsLabel.Text = Loc.GetString("guidebook-food-output", ("name", result.Name), ("number", entry.OutputCount));
OutputsTexture.Texture = _sprites.Frame0(result);
}
private string FormatIngredient(EntityPrototype proto, FixedPoint2 amount)
{
return Loc.GetString("guidebook-food-ingredient-solid", ("name", proto.Name), ("amount", amount));
}
private string FormatIngredient(ReagentPrototype proto, FixedPoint2 amount)
{
return Loc.GetString("guidebook-food-ingredient-liquid", ("name", proto.LocalizedName), ("amount", amount));
}
public bool CheckMatchesSearch(string query)
{
return this.ChildrenContainText(query);
}
public void SetHiddenState(bool state, string query)
{
Visible = CheckMatchesSearch(query) ? state : !state;
}
}