Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TextLinkTag #32203

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Content.Client/Guidebook/Richtext/KeyBindTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Content.Client.Guidebook.Richtext;

[UsedImplicitly]
public sealed class KeyBindTag : IMarkupTag
public sealed class KeyBindTag : IMarkupTagHandler
{
[Dependency] private readonly IInputManager _inputManager = default!;

Expand Down
2 changes: 1 addition & 1 deletion Content.Client/Guidebook/Richtext/ProtodataTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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!;
Expand Down
21 changes: 7 additions & 14 deletions Content.Client/Guidebook/Richtext/TextLinkTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
namespace Content.Client.Guidebook.RichText;

[UsedImplicitly]
public sealed class TextLinkTag : IMarkupTag
public sealed class TextLinkTag : IMarkupTagHandler
{
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)
Expand All @@ -35,27 +33,22 @@ public bool TryGetControl(MarkupNode node, [NotNullWhen(true)] out Control? cont

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)
return;

var current = Control;
while (current != null)
while (control != null)
{
current = current.Parent;
control = control.Parent;

if (current is not ILinkClickHandler handler)
if (control is not ILinkClickHandler handler)
continue;
handler.HandleClick(link);
return;
Expand Down
Loading