Seed analyzer (#433)

* hey

* added it to vending machine

* added to vending

* лицензия спрайта

* Update SeedAnalyzerWindow.xaml.cs

* fix my recently added bug

* обосрался знатно, пофиксил

* fix всего кроме null проверки

---------

Co-authored-by: melano <VildanMinnakhmetov>
Co-authored-by: KurokoTurbo <92106367+VildanMinnakhmetov@users.noreply.github.com>
This commit is contained in:
KurokoTurbo
2023-10-01 05:55:21 +03:00
committed by Aviu00
parent bb3d54e753
commit fb8834ac63
14 changed files with 515 additions and 1 deletions

View File

@@ -0,0 +1,51 @@
using Content.Shared.Botany;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
namespace Content.Client.SeedAnalyzer.UI
{
[UsedImplicitly]
public sealed class SeedAnalyzerBoundUserInterface : BoundUserInterface
{
[ViewVariables]
private SeedAnalyzerWindow? _window;
public SeedAnalyzerBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}
protected override void Open()
{
base.Open();
_window = new SeedAnalyzerWindow
{
Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName,
};
_window.OnClose += Close;
_window.OpenCentered();
}
protected override void ReceiveMessage(BoundUserInterfaceMessage message)
{
if (_window == null)
return;
if (message is not SeedAnalyzerScannedUserMessage cast)
return;
_window.Populate(cast);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;
if (_window != null)
_window.OnClose -= Close;
_window?.Dispose();
}
}
}

View File

@@ -0,0 +1,9 @@
<DefaultWindow xmlns="https://spacestation14.io"
MinSize="250 100"
SetSize="250 100">
<BoxContainer Orientation="Vertical">
<Label
Name="Diagnostics"
Text="{Loc seed-analyzer-window-no-plant-data-text}"/>
</BoxContainer>
</DefaultWindow>

View File

@@ -0,0 +1,102 @@
using System.Numerics;
using System.Text;
using Content.Shared.FixedPoint;
using Content.Shared.Botany;
using Robust.Client.AutoGenerated; //probably useless
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
using Content.Shared.Chemistry.Reagent;
namespace Content.Client.SeedAnalyzer.UI
{
[GenerateTypedNameReferences]
public sealed partial class SeedAnalyzerWindow : DefaultWindow
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
public SeedAnalyzerWindow()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
}
public void Populate(SeedAnalyzerScannedUserMessage msg)
{
var text = new StringBuilder();
var entities = IoCManager.Resolve<IEntityManager>(); // maybe bad
if (msg.TargetEntity != null) // this may be bad, maybe && entities.TryGetComponent<SeedComponent>(msg.TargetEntity, out var seed)
{
string entityName = "Unknown"; // без этой строки все ломается и я не знаю почему
if (msg.Viable == false)
{
text.Append($"{Loc.GetString("seed-analyzer-window-entity-viable-text")}\n");
}
if (msg.TurnIntoKudzu == true)
{
text.Append($"\n{Loc.GetString("seed-analyzer-window-entity-turnintokudzu-text")}\n");
}
text.Append($"{Loc.GetString("seed-analyzer-window-entity-endurance-text", ("endurance", msg.Endurance!))}");
text.Append($"\n{Loc.GetString("seed-analyzer-window-entity-yield-text", ("yield", msg.Yield!))}"); //maybe msg.Yield.HasValue ? "N/A" : $"{msg.Yield}"
text.Append($"\n{Loc.GetString("seed-analyzer-window-entity-maturation-text", ("maturation", msg.Maturation!))}");
text.Append($"\n{Loc.GetString("seed-analyzer-window-entity-production-text", ("production", msg.Production!))}");
text.Append($"\n{Loc.GetString("seed-analyzer-window-entity-lifespan-text", ("lifespan", msg.Lifespan!))}");
text.Append($"\n{Loc.GetString("seed-analyzer-window-entity-potency-text", ("potency", msg.Potency!))}");
int zero = 0;
var zero2 = FixedPoint2.New(zero);
Dictionary<string, FixedPoint2> nodic = new Dictionary<string, FixedPoint2>();
nodic.Add("\nNo chemicals", zero2);
if (msg.Chemicals != nodic && msg.Chemicals != null)
{
//text.Append($"\n{Loc.GetString("seed-analyzer-window-entity-chemicals-text")}");
foreach (var (chemical, amount) in msg.Chemicals!)
{
var localizedName = _prototypeManager.TryIndex(chemical, out ReagentPrototype? p) ? p.LocalizedName : Loc.GetString("seed-analyzer-window-reagent-name-not-found-text"); //maybe Loc.GetString("seed-analyzer-window-reagent-name-not-found-text")
text.Append($"\n{Loc.GetString("seed-analyzer-window-entity-chemical-text", ("localizedName", localizedName))}");
text.Append($" {Loc.GetString("seed-analyzer-window-entity-amount-text", ("amount", amount))}");
}
}
if (msg.Ligneous == true)
{
text.Append($"\n{Loc.GetString("seed-analyzer-window-entity-ligneous-text")}");
}
if (msg.CanScream == true)
{
text.Append($"\n{Loc.GetString("seed-analyzer-window-entity-canscream-text")}");
}
if (msg.Slip == true)
{
text.Append($"\n{Loc.GetString("seed-analyzer-window-entity-slip-text")}");
}
if (msg.Bioluminescent == true)
{
text.Append($"\n{Loc.GetString("seed-analyzer-window-entity-bioluminescent-text")}");
}
if (msg.Sentient == true)
{
text.Append($"\n{Loc.GetString("seed-analyzer-window-entity-sentient-text")}");
}
if (msg.Seedless == true)
{
text.Append($"\n{Loc.GetString("seed-analyzer-window-entity-seedless-text")}");
}
Diagnostics.Text = text.ToString();
SetSize = new Vector2(250, 600);
}
else
{
Diagnostics.Text = Loc.GetString("seed-analyzer-window-no-plant-data-text");
SetSize = new Vector2(250, 100);
}
}
}
}