Players often share URLs via game chat. We can open a hyperlink by clicking on its area in the console. Unfortunately, URLs that begin with https:// are not clickable (in contrast to http://). I think, there is no reason to keep this limitation.
You could also notice that characters < and > are replaced with ( and ) when drawed in console. I found such a behavior odd and unnecessary. To prevent parsing < and > as parts of HTML tags, it's enough to replace such characters with < and >
Suggested resolution:
- in UWindow/UWindowConsoleTextAreaControl.uc define function AddText as follows:
function UWindowDynamicTextRow AddText(string NewLine, optional color TxtCol )
{
local int i, j;
local UWindowHTMLTextRow L;
local HTMLStyle CurrentStyle;
local string Prefix, LowNewLine;
CurrentStyle.BulletLevel = 0;
CurrentStyle.LinkDestination = "";
if( TxtCol.R==0 && TxtCol.G==0 && TxtCol.B==0 )
CurrentStyle.TextColor = TextColor;
else CurrentStyle.TextColor = TxtCol;
// Replace <>
NewLine = ReplaceStr(NewLine, "<", "<");
NewLine = ReplaceStr(NewLine, ">", ">");
// Add links
while (Len(NewLine) > 0)
{
LowNewLine = Locs(NewLine);
i = InStr(LowNewLine, "http");
j = InStr(LowNewLine, "www.");
if (i >= 0 && (j < 0 || i < j)) // parse "http"
{
if (Mid(LowNewLine, i, 7) == "http://" || Mid(LowNewLine, i, 8) == "https://")
{
if (i > 0 || Len(Prefix) > 0)
{
L = UWindowHTMLTextRow(Super(UWindowDynamicTextArea).AddText(Prefix $ Left(NewLine, i)));
L.StartStyle = CurrentStyle;
L.StartStyle.bNoBR = true;
}
NewLine = Mid(NewLine, i);
Prefix = "";
i = InStr(NewLine, " ");
if (i >= 0)
{
L = UWindowHTMLTextRow(Super(UWindowDynamicTextArea).AddText(Left(NewLine, i)));
L.StartStyle = CurrentStyle;
L.StartStyle.LinkDestination = L.Text;
NewLine = Mid(NewLine, i + 1);
}
else
{
L = UWindowHTMLTextRow(Super(UWindowDynamicTextArea).AddText(NewLine));
L.StartStyle = CurrentStyle;
L.StartStyle.LinkDestination = NewLine;
NewLine = "";
}
}
else
{
// skip "http"
Prefix $= Left(NewLine, i + 3);
NewLine = Mid(NewLine, i + 3);
continue;
}
}
else if (j >= 0) // parse "www."
{
if (j > 0 && Mid(NewLine, j - 1, 1) != " ")
{
Prefix $= Left(NewLine, j + 3);
NewLine = Mid(NewLine, j + 3);
continue;
}
if (j > 0 || Len(Prefix) > 0)
{
L = UWindowHTMLTextRow(Super(UWindowDynamicTextArea).AddText(Prefix $ Left(NewLine, j)));
L.StartStyle = CurrentStyle;
L.StartStyle.bNoBR = true;
}
NewLine = Mid(NewLine, j);
Prefix = "";
i = InStr(NewLine, " ");
if (i >= 0)
{
L = UWindowHTMLTextRow(Super(UWindowDynamicTextArea).AddText("http://" $ Left(NewLine, i)));
L.StartStyle = CurrentStyle;
L.StartStyle.LinkDestination = L.Text;
NewLine = Mid(NewLine, i + 1);
}
else
{
L = UWindowHTMLTextRow(Super(UWindowDynamicTextArea).AddText("http://" $ NewLine));
L.StartStyle = CurrentStyle;
L.StartStyle.LinkDestination = L.Text;
NewLine = "";
}
}
else
break;
L.StartStyle.bLink = true;
L.StartStyle.bNoBR = true;
}
NewLine = Prefix $ NewLine;
// End line.
if( Len(NewLine)>0 )
{
L = UWindowHTMLTextRow(Super(UWindowDynamicTextArea).AddText(NewLine));
L.StartStyle = CurrentStyle;
}
return L;
}
- in UWindow/UWindowHTMLTextArea.uc modify function ProcessURL as follows:
....
if ( Left(URL, 7) ~= "http://" )
GetPlayerOwner().ConsoleCommand("start "$URL);
if ( Left(URL, 8) ~= "https://" )
GetPlayerOwner().ConsoleCommand("start "$URL);
....
UWindow/UWindowConsoleTextAreaControl.ucUWindow/UWindowHTMLTextArea.ucImplementation note: the suggested modification should guarantee that multiple URLs of any of the following forms are drawed correctly:
http://ref
https://ref
www.ref
The original implementation ignores upper-case forms HTTP:// WWW.
The suggested implementation parses URLs in a case-insensitive manner.
If you see any potential problems with the new parser, please, share your thoughts.