From 8fc9cc86d3af22cc90059d47751570b77bfe2b7b Mon Sep 17 00:00:00 2001 From: Kirus59 <145689588+Kirus59@users.noreply.github.com> Date: Fri, 21 Feb 2025 22:23:01 +0300 Subject: [PATCH 1/5] Add browser link tag --- .../Guidebook/Richtext/TextLinkTag.cs | 2 +- .../Guidebook/Richtext/BrowserLinkTag.cs | 68 +++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 Content.Client/SS220/Guidebook/Richtext/BrowserLinkTag.cs diff --git a/Content.Client/Guidebook/Richtext/TextLinkTag.cs b/Content.Client/Guidebook/Richtext/TextLinkTag.cs index b1e8460bb89a..193a8529fc12 100644 --- a/Content.Client/Guidebook/Richtext/TextLinkTag.cs +++ b/Content.Client/Guidebook/Richtext/TextLinkTag.cs @@ -1,4 +1,4 @@ -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; using JetBrains.Annotations; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; diff --git a/Content.Client/SS220/Guidebook/Richtext/BrowserLinkTag.cs b/Content.Client/SS220/Guidebook/Richtext/BrowserLinkTag.cs new file mode 100644 index 000000000000..7af10256f0e1 --- /dev/null +++ b/Content.Client/SS220/Guidebook/Richtext/BrowserLinkTag.cs @@ -0,0 +1,68 @@ +using Content.Client.SS220.WristWatch; +using JetBrains.Annotations; +using Robust.Client.Graphics; +using Robust.Client.UserInterface; +using Robust.Client.UserInterface.Controls; +using Robust.Client.UserInterface.RichText; +using Robust.Shared.Input; +using Robust.Shared.Utility; +using System.Diagnostics.CodeAnalysis; +using TerraFX.Interop.Xlib; + +namespace Content.Client.SS220.Guidebook.Richtext; + +[UsedImplicitly] +public sealed class BrowserLinkTag : IMarkupTag +{ + [Dependency] private readonly IUriOpener _uriOpener = default!; + [Dependency] private readonly ILogManager _logMan = default!; + + public string Name => "browserlink"; + + private ISawmill Log => _log ??= _logMan.GetSawmill("protodata_tag"); + private ISawmill? _log; + + public bool TryGetControl(MarkupNode node, [NotNullWhen(true)] out Control? control) + { + if (!node.Attributes.TryGetValue("link", out var linkParametr) || + !linkParametr.TryGetString(out var link)) + { + control = null; + return false; + } + + node.Value.TryGetString(out var text); + + var label = new Label(); + if (text != null) + label.Text = text; + else + label.Text = link; + + label.MouseFilter = Control.MouseFilterMode.Stop; + label.FontColorOverride = Color.CornflowerBlue; + label.DefaultCursorShape = Control.CursorShape.Hand; + + label.OnMouseEntered += _ => label.FontColorOverride = Color.LightSkyBlue; + label.OnMouseExited += _ => label.FontColorOverride = Color.CornflowerBlue; + label.OnKeyBindDown += args => OnKeybindDown(args, link); + + control = label; + return true; + } + + private void OnKeybindDown(GUIBoundKeyEventArgs args, string link) + { + if (args.Function != EngineKeyFunctions.UIClick) + return; + + try + { + _uriOpener.OpenUri(link); + } + catch (Exception e) + { + Log.Error(e.Message); + } + } +} From 8f6e6b3bc11b10353807ed4878f63fb0bfff4364 Mon Sep 17 00:00:00 2001 From: Kirus59 <145689588+Kirus59@users.noreply.github.com> Date: Fri, 21 Feb 2025 22:28:51 +0300 Subject: [PATCH 2/5] fix textlink --- Content.Client/Guidebook/Richtext/TextLinkTag.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content.Client/Guidebook/Richtext/TextLinkTag.cs b/Content.Client/Guidebook/Richtext/TextLinkTag.cs index 193a8529fc12..b1e8460bb89a 100644 --- a/Content.Client/Guidebook/Richtext/TextLinkTag.cs +++ b/Content.Client/Guidebook/Richtext/TextLinkTag.cs @@ -1,4 +1,4 @@ -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; using JetBrains.Annotations; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; From af13617ad50d722e68ff92e67b4eac48e3f3ddc4 Mon Sep 17 00:00:00 2001 From: Kirus59 <145689588+Kirus59@users.noreply.github.com> Date: Fri, 21 Feb 2025 22:31:21 +0300 Subject: [PATCH 3/5] delete needless usings --- Content.Client/SS220/Guidebook/Richtext/BrowserLinkTag.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Content.Client/SS220/Guidebook/Richtext/BrowserLinkTag.cs b/Content.Client/SS220/Guidebook/Richtext/BrowserLinkTag.cs index 7af10256f0e1..3b3cb5b64d25 100644 --- a/Content.Client/SS220/Guidebook/Richtext/BrowserLinkTag.cs +++ b/Content.Client/SS220/Guidebook/Richtext/BrowserLinkTag.cs @@ -1,13 +1,11 @@ -using Content.Client.SS220.WristWatch; +// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt using JetBrains.Annotations; -using Robust.Client.Graphics; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.RichText; using Robust.Shared.Input; using Robust.Shared.Utility; using System.Diagnostics.CodeAnalysis; -using TerraFX.Interop.Xlib; namespace Content.Client.SS220.Guidebook.Richtext; From 69d1c9cda770258c60dbc0db14a65de4cddaba47 Mon Sep 17 00:00:00 2001 From: Kirus59 <145689588+Kirus59@users.noreply.github.com> Date: Sat, 22 Feb 2025 17:46:43 +0300 Subject: [PATCH 4/5] fix fix --- .../Guidebook/Richtext/BrowserLinkTag.cs | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/Content.Client/SS220/Guidebook/Richtext/BrowserLinkTag.cs b/Content.Client/SS220/Guidebook/Richtext/BrowserLinkTag.cs index 3b3cb5b64d25..a4d24ce43c47 100644 --- a/Content.Client/SS220/Guidebook/Richtext/BrowserLinkTag.cs +++ b/Content.Client/SS220/Guidebook/Richtext/BrowserLinkTag.cs @@ -22,41 +22,44 @@ public sealed class BrowserLinkTag : IMarkupTag public bool TryGetControl(MarkupNode node, [NotNullWhen(true)] out Control? control) { + var label = new Label(); + node.Value.TryGetString(out var text); + label.Text = text; + if (!node.Attributes.TryGetValue("link", out var linkParametr) || !linkParametr.TryGetString(out var link)) { - control = null; - return false; + control = label; + return true; } - node.Value.TryGetString(out var text); - - var label = new Label(); - if (text != null) - label.Text = text; - else + if (string.IsNullOrEmpty(label.Text)) label.Text = link; - label.MouseFilter = Control.MouseFilterMode.Stop; - label.FontColorOverride = Color.CornflowerBlue; - label.DefaultCursorShape = Control.CursorShape.Hand; + var uri = new Uri(link); + if (uri.Scheme == Uri.UriSchemeHttps || uri.Scheme == Uri.UriSchemeHttp) + { + label.MouseFilter = Control.MouseFilterMode.Stop; + label.FontColorOverride = Color.CornflowerBlue; + label.DefaultCursorShape = Control.CursorShape.Hand; - label.OnMouseEntered += _ => label.FontColorOverride = Color.LightSkyBlue; - label.OnMouseExited += _ => label.FontColorOverride = Color.CornflowerBlue; - label.OnKeyBindDown += args => OnKeybindDown(args, link); + label.OnMouseEntered += _ => label.FontColorOverride = Color.LightSkyBlue; + label.OnMouseExited += _ => label.FontColorOverride = Color.CornflowerBlue; + label.OnKeyBindDown += args => OnKeybindDown(args, uri); + } control = label; return true; } - private void OnKeybindDown(GUIBoundKeyEventArgs args, string link) + private void OnKeybindDown(GUIBoundKeyEventArgs args, Uri uri) { if (args.Function != EngineKeyFunctions.UIClick) return; try { - _uriOpener.OpenUri(link); + _uriOpener.OpenUri(uri); } catch (Exception e) { From 8efd77c3145e3aaa3cb644c42c3511c2751de9e0 Mon Sep 17 00:00:00 2001 From: Kirus59 <145689588+Kirus59@users.noreply.github.com> Date: Sun, 23 Feb 2025 16:03:10 +0300 Subject: [PATCH 5/5] Catch exception --- .../Guidebook/Richtext/BrowserLinkTag.cs | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/Content.Client/SS220/Guidebook/Richtext/BrowserLinkTag.cs b/Content.Client/SS220/Guidebook/Richtext/BrowserLinkTag.cs index a4d24ce43c47..b9079b98eb23 100644 --- a/Content.Client/SS220/Guidebook/Richtext/BrowserLinkTag.cs +++ b/Content.Client/SS220/Guidebook/Richtext/BrowserLinkTag.cs @@ -36,16 +36,23 @@ public bool TryGetControl(MarkupNode node, [NotNullWhen(true)] out Control? cont if (string.IsNullOrEmpty(label.Text)) label.Text = link; - var uri = new Uri(link); - if (uri.Scheme == Uri.UriSchemeHttps || uri.Scheme == Uri.UriSchemeHttp) + try { - label.MouseFilter = Control.MouseFilterMode.Stop; - label.FontColorOverride = Color.CornflowerBlue; - label.DefaultCursorShape = Control.CursorShape.Hand; + var uri = new Uri(link); + if (uri.Scheme == Uri.UriSchemeHttps || uri.Scheme == Uri.UriSchemeHttp) + { + label.MouseFilter = Control.MouseFilterMode.Stop; + label.FontColorOverride = Color.CornflowerBlue; + label.DefaultCursorShape = Control.CursorShape.Hand; - label.OnMouseEntered += _ => label.FontColorOverride = Color.LightSkyBlue; - label.OnMouseExited += _ => label.FontColorOverride = Color.CornflowerBlue; - label.OnKeyBindDown += args => OnKeybindDown(args, uri); + label.OnMouseEntered += _ => label.FontColorOverride = Color.LightSkyBlue; + label.OnMouseExited += _ => label.FontColorOverride = Color.CornflowerBlue; + label.OnKeyBindDown += args => OnKeybindDown(args, uri); + } + } + catch (Exception e) + { + Log.Error(e.Message); } control = label;