Fix TextLinkTag (#32203)

This commit is contained in:
Leon Friedrich
2025-07-04 07:11:21 +12:00
committed by GitHub
parent f6946f1db7
commit 32f0ba340a
3 changed files with 8 additions and 11 deletions

View File

@@ -6,7 +6,7 @@ using Robust.Shared.Utility;
namespace Content.Client.Guidebook.Richtext;
[UsedImplicitly]
public sealed class KeyBindTag : IMarkupTag
public sealed class KeyBindTag : IMarkupTagHandler
{
[Dependency] private readonly IInputManager _inputManager = default!;

View File

@@ -9,7 +9,7 @@ namespace Content.Client.Guidebook.RichText;
/// In order to be accessed by this tag, the desired field/property must
/// be tagged with <see cref="Shared.Guidebook.GuidebookDataAttribute"/>.
/// </summary>
public sealed class ProtodataTag : IMarkupTag
public sealed class ProtodataTag : IMarkupTagHandler
{
[Dependency] private readonly ILogManager _logMan = default!;
[Dependency] private readonly IEntityManager _entMan = default!;

View File

@@ -10,16 +10,14 @@ using Content.Client.UserInterface.ControlExtensions;
namespace Content.Client.Guidebook.RichText;
[UsedImplicitly]
public sealed class TextLinkTag : IMarkupTag
public sealed class TextLinkTag : IMarkupTagHandler
{
public static Color LinkColor => Color.CornflowerBlue;
public string Name => "textlink";
public Control? Control;
/// <inheritdoc/>
public bool TryGetControl(MarkupNode node, [NotNullWhen(true)] out Control? control)
public bool TryCreateControl(MarkupNode node, [NotNullWhen(true)] out Control? control)
{
if (!node.Value.TryGetString(out var text)
|| !node.Attributes.TryGetValue("link", out var linkParameter)
@@ -38,22 +36,21 @@ public sealed class TextLinkTag : IMarkupTag
label.OnMouseEntered += _ => label.FontColorOverride = Color.LightSkyBlue;
label.OnMouseExited += _ => label.FontColorOverride = Color.CornflowerBlue;
label.OnKeyBindDown += args => OnKeybindDown(args, link);
label.OnKeyBindDown += args => OnKeybindDown(args, link, label);
control = label;
Control = label;
return true;
}
private void OnKeybindDown(GUIBoundKeyEventArgs args, string link)
private void OnKeybindDown(GUIBoundKeyEventArgs args, string link, Control? control)
{
if (args.Function != EngineKeyFunctions.UIClick)
return;
if (Control == null)
if (control == null)
return;
if (Control.TryGetParentHandler<ILinkClickHandler>(out var handler))
if (control.TryGetParentHandler<ILinkClickHandler>(out var handler))
handler.HandleClick(link);
else
Logger.Warning("Warning! No valid ILinkClickHandler found.");