Fix TextLinkTag (#32203)
This commit is contained in:
@@ -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!;
|
||||
|
||||
|
||||
@@ -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!;
|
||||
|
||||
@@ -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.");
|
||||
|
||||
Reference in New Issue
Block a user