mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-02-14 23:14:45 +01:00
57 lines
1.7 KiB
C#
57 lines
1.7 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
using Content.Client.Guidebook;
|
|
using Content.Client.Guidebook.Richtext;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
|
|
namespace Content.Client.Corvax.Guidebook.Controls;
|
|
|
|
/// <summary>
|
|
/// Control for embedding text with fluent support into guidebook/document
|
|
/// </summary>
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class FTLTextpart : RichTextLabel, IDocumentTag
|
|
{
|
|
[Dependency] private readonly ILogManager _logManager = default!;
|
|
[Dependency] private readonly ILocalizationManager _loc = default!;
|
|
[Dependency] private readonly DocumentParsingManager _documentParsingManager = default!;
|
|
|
|
private readonly ISawmill _sawmill;
|
|
|
|
public FTLTextpart()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
_sawmill = _logManager.GetSawmill("guidebook.loc");
|
|
MouseFilter = MouseFilterMode.Stop;
|
|
}
|
|
|
|
public bool TryParseTag(Dictionary<string, string> args, [NotNullWhen(true)] out Control? control)
|
|
{
|
|
if (!args.TryGetValue("Key", out var key))
|
|
{
|
|
_sawmill.Error("Fluent tag cannot be found");
|
|
control = null;
|
|
return false;
|
|
}
|
|
|
|
if (_loc.TryGetString(key, out var fluentString))
|
|
{
|
|
var doc = new Document();
|
|
if (_documentParsingManager.TryAddMarkup(doc, fluentString))
|
|
{
|
|
control = doc;
|
|
return true;
|
|
}
|
|
|
|
control = null;
|
|
return false;
|
|
}
|
|
|
|
_sawmill.Error($"Fluent key {key} cannot be found");
|
|
control = null;
|
|
return false;
|
|
}
|
|
}
|