* skeleton * ok I think I understand this now * xaml more like xam L * good enough individual law control * Works * Final checks * Final_Final.exe.docx * removed unecessary usings * locstrings * doc comments * requested changeds except var * visual stuff * I could write a manifesto about how much I dislike var * color tweak + other thing * request changed minus the inheritance * sans Boxcontainer * :/ * cache find * requested changed * removed usings * Moved margin and removed unecessary BoxContainer
97 lines
2.9 KiB
C#
97 lines
2.9 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
using Content.Client.Guidebook.Richtext;
|
|
using Content.Client.Message;
|
|
using Content.Client.UserInterface.ControlExtensions;
|
|
using JetBrains.Annotations;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
using Content.Shared.Silicons.Laws;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Client.Guidebook.Controls;
|
|
|
|
/// <summary>
|
|
/// Control for embedding an AI Lawset in a guidebook
|
|
/// </summary>
|
|
[UsedImplicitly, GenerateTypedNameReferences]
|
|
public sealed partial class GuideLawsetEmbed : Control, IDocumentTag, ISearchableControl, IPrototypeRepresentationControl
|
|
{
|
|
[Dependency] private readonly IPrototypeManager _prototype = default!;
|
|
|
|
private ISawmill _logging = default!;
|
|
|
|
public IPrototype? RepresentedPrototype { get; private set; }
|
|
|
|
public GuideLawsetEmbed()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
IoCManager.InjectDependencies(this);
|
|
MouseFilter = MouseFilterMode.Stop;
|
|
}
|
|
|
|
public GuideLawsetEmbed(SiliconLawsetPrototype lawset) : this()
|
|
{
|
|
GenerateControl(lawset);
|
|
}
|
|
|
|
private void GenerateControl(SiliconLawsetPrototype lawset)
|
|
{
|
|
RepresentedPrototype = lawset;
|
|
|
|
var lawsetNameString = lawset.Name == null ? lawset.ID : Loc.GetString(lawset.Name);
|
|
LawsetName.SetMarkup($"[bold]{FormattedMessage.EscapeText(lawsetNameString)}[/bold]");
|
|
|
|
var i = 1;
|
|
foreach (var lawID in lawset.Laws)
|
|
{
|
|
var lawPrototype = _prototype.Index<SiliconLawPrototype>(lawID);
|
|
var locLawString = Loc.GetString(lawPrototype.LawString);
|
|
|
|
RichTextLabel lawN = new()
|
|
{
|
|
Margin = new(0, 5, 0, 1)
|
|
};
|
|
var locLawStatement = Loc.GetString("laws-number-wrapper", ("lawnumber", i), ("lawstring", locLawString));
|
|
lawN.SetMarkup(locLawStatement);
|
|
LawsetContainer.AddChild(lawN);
|
|
|
|
i++;
|
|
}
|
|
}
|
|
|
|
public bool TryParseTag(Dictionary<string, string> args, [NotNullWhen(true)] out Control? control)
|
|
{
|
|
control = null;
|
|
if (!args.TryGetValue("Lawset", out var id))
|
|
{
|
|
_logging.Error("Lawset embed tag is missing lawset prototype argument");
|
|
return false;
|
|
}
|
|
|
|
if (!_prototype.TryIndex<SiliconLawsetPrototype>(id, out var lawset))
|
|
{
|
|
_logging.Error($"Specified SiliconLawsetPrototype \"{id}\" is not a valid Lawset prototype");
|
|
return false;
|
|
}
|
|
|
|
GenerateControl(lawset);
|
|
|
|
control = this;
|
|
return true;
|
|
}
|
|
|
|
public bool CheckMatchesSearch(string query)
|
|
{
|
|
return this.ChildrenContainText(query);
|
|
}
|
|
|
|
public void SetHiddenState(bool state, string query)
|
|
{
|
|
Visible = CheckMatchesSearch(query) ? state : !state;
|
|
}
|
|
}
|