Skip to content

Commit

Permalink
Merge pull request #1 from Vel-San/html-render
Browse files Browse the repository at this point in the history
Html render
  • Loading branch information
Vel-San authored May 12, 2020
2 parents f25fa22 + 52d3fd2 commit 52bf743
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 97 deletions.
54 changes: 26 additions & 28 deletions GUIHTMLTextBox.uc
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,17 @@ function InitComponent(GUIController MyController, GUIComponent MyOwner)
Super.InitComponent(MyController, MyOwner);
MyScrollBar.bTabStop = false;
MyScrollBar.Refocus(Self);
///////////////////////
// VEL-SAN'S SECTION
// lb_MOTD.MyScrollText.bClickText=true;
// lb_MOTD.MyScrollText.OnDblClick=LaunchURLPage;
///////////////////////
}

final function int AddText( string Input, color TextColor, byte TextAlign, byte FontSize, out byte NumSkips )
{
local int i;

i = Lines.Length;
Lines.Length = i+1;
Lines[i].Text = Input;
Expand Down Expand Up @@ -137,12 +142,12 @@ final function AddImage( string Input )
Y = int(GetOption(Input, "HSPACE="));
XS = int(GetOption(Input, "WIDTH="));
YS = int(GetOption(Input, "HEIGHT="));

if( XS==0 )
XS = M.MaterialUSize();
if( YS==0 )
YS = M.MaterialVSize();

i = Images.Length;
Images.Length = i+1;
Images[i].Img = M;
Expand Down Expand Up @@ -172,20 +177,22 @@ final function SetContents( string Input )
TitleString = "";
bHasSplitLines = false;
bNeedsInit = true;

// First remove new liners
Input = Repl(Input, Chr(13)$Chr(10), "");
Input = Repl(Input, Chr(13), "");
Input = Repl(Input, Chr(10), "");
Input = Repl(Input, Chr(9), " ");
Input = Repl(Input, "\\n", "<BR>");

Input = Repl(Input, "<hr>", "<br>____________________________________________________________________________________<br>", false);


TextColor = Class'HUD'.Default.WhiteColor;
OrgTextColor = Class'HUD'.Default.WhiteColor;
LinkColor = Class'HUD'.Default.BlueColor;
ALinkColor = Class'HUD'.Default.RedColor;
FontScaler = 3;
DefaultFontSize = 3;
FontScaler = 5;
DefaultFontSize = 4;
Index = -1;

while (Input != "")
Expand Down Expand Up @@ -234,14 +241,14 @@ final function SetContents( string Input )
TextColor = ParseColor(Temp);
OrgTextColor = TextColor;
}

Temp = GetOption(HTML, "SIZE=");
if (Temp != "")
{
FontScaler = int(Temp);
DefaultFontSize = FontScaler;
}

Temp = GetOption(Input, "IMG=");
if (Temp != "")
{
Expand Down Expand Up @@ -548,7 +555,7 @@ final function Color ParseColor(string S)
final function byte GetHexDigit(string D)
{
local byte i;

i = Asc(D);
if( i>=48 && i<=57 ) // i>='0' && i<='9'
return (i-48); // i-'0'
Expand Down Expand Up @@ -606,7 +613,7 @@ final protected function InitHTMLArea( Canvas C )
}
}
}

// Setup background image scaling
if( BgImage.Img!=None )
{
Expand Down Expand Up @@ -640,7 +647,7 @@ final protected function InitHTMLArea( Canvas C )
break;
}
}

FontSize = -2;
if ( C.SizeY < 480 )
FontSize++;
Expand Down Expand Up @@ -726,7 +733,7 @@ final protected function InitHTMLArea( Canvas C )
}
Lines[i].XS = XS;
X+=XS;

for( j=0; j<Lines[i].ImgList.Length; ++j )
{
z = Lines[i].ImgList[j];
Expand Down Expand Up @@ -801,7 +808,7 @@ function bool RenderHTMLText( canvas C )
{
C.SetPos(0,0);
C.DrawColor = BGColor;

if( BgImage.Img!=None )
{
if( BgImage.Align==1 ) // not locked on screen.
Expand Down Expand Up @@ -876,7 +883,7 @@ function bool RenderHTMLText( canvas C )
continue;
if( C.CurY>C.ClipY )
break;

// Check if mouse hovers over URL
if( bMouseOnClient && Lines[i].bHasURL && MX>=Lines[i].X && MX<=(Lines[i].X+Lines[i].XS)
&& MY>=Lines[i].Y && MY<=(Lines[i].Y+Lines[i].YS) )
Expand Down Expand Up @@ -913,31 +920,22 @@ function bool RenderHTMLText( canvas C )
C.OrgY = 0;
C.ClipX = CX;
C.ClipY = CY;

return false;
}

function bool LaunchURL(GUIComponent Sender)
{
if( HoverOverLinkLine>=0 )
{
if( Left(Lines[HoverOverLinkLine].URL,8)~="kfurl://" )
LaunchKFURL(Mid(Lines[HoverOverLinkLine].URL,8));
else if( Left(Lines[HoverOverLinkLine].URL,5)~="kf://" )
ChangeGameURL(Mid(Lines[HoverOverLinkLine].URL,5));
else LaunchURLPage(Lines[HoverOverLinkLine].URL);
LaunchURLPage(Lines[HoverOverLinkLine].URL);
}
return true;
}

delegate LaunchKFURL( string URL );
delegate ChangeGameURL( string URL )
{
Class'SRLevelCleanup'.Static.AddSafeCleanup(PlayerOwner(),URL);
}
delegate LaunchURLPage( string URL )
{
PlayerOwner().Player.Console.DelayedConsoleCommand("START "$URL);
Controller.LaunchURL(URL);
}

defaultproperties
Expand All @@ -962,5 +960,5 @@ defaultproperties
ToolTip=GUIToolTip'KFGui.GUIHTMLTextBox.GUIListBoxBaseToolTip'

OnDraw=GUIHTMLTextBox.RenderHTMLText
OnClick=GUIHTMLTextBox.LaunchURL
OnDblClick=GUIHTMLTextBox.LaunchURL
}
7 changes: 7 additions & 0 deletions KFMOTD.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[KFGui.KFMOTD]
# This is where the HTML News page is hosted at. To create your own page, you need to go here
# https://pastebin.com/YZar5TAb And follow the exact format. No JS Scripts or others, just use HTML structure like that
# Then page ID (from your address bar) in place of only 'YZar5TAb'
getRequest="GET /raw/YZar5TAb HTTP/1.1"
# This will show at the top of the panel like this 'News Source: TRIPWIRE INTERACTIVE'
newsSource="TRIPWIRE INTERACTIVE"
50 changes: 29 additions & 21 deletions KFMOTD.uc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ var String myMOTD;
// Values from Vel-San
var String mutByMsg;
var() globalconfig String getRequest;
var() globalconfig String newsSource;
var automated GUIHTMLTextBox HTMLText;
///////////////////////


Expand All @@ -25,7 +27,8 @@ function InitComponent(GUIController MyController, GUIComponent MyOwner)
super.InitComponent(MyController, MyOwner);

GetNewNews();
lb_MOTD.MyScrollText.SetContent(myMOTD);
HTMLText.SetContents(myMOTD);
PanelCaption="News source: "$newsSource;
}

event Opened(GUIComponent Sender)
Expand Down Expand Up @@ -111,7 +114,7 @@ event Timer()
if(pageWait)
{
myMOTD = myMOTD$".";
lb_MOTD.MyScrollText.SetContent(myMOTD);
HTMLText.SetContents(myMOTD);
}
}
}
Expand All @@ -120,7 +123,7 @@ event Timer()
if(sendGet)
{
myMOTD = myMOTD$"|| Could not connect to news server";
lb_MOTD.MyScrollText.SetContent(myMOTD);
HTMLText.SetContents(myMOTD);
}
}
}
Expand All @@ -130,7 +133,7 @@ event Timer()
{
myMOTD = myMOTD$"|| Retries Failed";
KillTimer();
lb_MOTD.MyScrollText.SetContent(myMOTD);
HTMLText.SetContents(myMOTD);
}
}

Expand All @@ -147,9 +150,9 @@ event Timer()

NewsParse(page);

myMOTD = "|"$page;
myMOTD = "<br>"$page;

lb_MOTD.MyScrollText.SetContent(myMOTD);
HTMLText.SetContents(myMOTD);

myLink.DestroyLink();
myLink = none;
Expand All @@ -165,21 +168,25 @@ function NewsParse(out string page)
{
local string junk;
local string joinedMsg;
local string velsanMail;
local string marcoCreds;
local int i;

junk = page;
Caps(junk);

i = InStr(junk, "<body>");
i = InStr(junk, "<html>");

if ( i > -1 )
{
///////////////////////
// Add Mut By
mutByMsg="- Fixed by: Vel-San||";
joinedMsg=mutByMsg$"(DOUBLE CLICK LINKS TO OPEN THEM)<hr>|";
velsanMail="http://steamcommunity.com/id/Vel-San/";
marcoCreds="- Base HTML rendering by Marco, Enhanced by Vel-San";
mutByMsg="<font color=yellow size=2>- Fixed by: <a href="$velsanMail$">Vel-San</a></font><font color=yellow size=2><font color=yellow><br><br>"$marcoCreds$"</font><br><br>";
joinedMsg=mutByMsg$"<font color=red size=3>(DOUBLE-CLICK A LINK TO OPEN IN BROWSER)</font><hr><br><body BGCOLOR=black>";
// Replace page <BODY>
page = Repl(page, "<body>", joinedMsg, false);
page = Repl(page, "<html>", joinedMsg, false);
// remove all header from string
page = Right(page, len(page) - i);
///////////////////////
Expand All @@ -196,22 +203,23 @@ function NewsParse(out string page)
page = Left(page, i);
}

page = Repl(page, "<br>", "|", false);
///////////////////////
// Text Error Prevention and handling
page = Repl(page, "<hr>", "|_____________________________________________________________________________________________________|", false);
// PRE-HTML UI BOX IMPLEMENTATION
// page = Repl(page, "<br>", "|", false);
// page = Repl(page, "<hr>", "|_____________________________________________________________________________________________________|", false);
page = Repl(page, "’", "'", false);
///////////////////////
}

defaultproperties
{
Begin Object Class=GUIScrollTextBox Name=MyMOTDText
bNoTeletype=True
CharDelay=0.050000
EOLDelay=0.100000
bVisibleWhenEmpty=True
OnCreateComponent=MyMOTDText.InternalOnCreateComponent
Begin Object Class=GUIHTMLTextBox Name=MyMOTDText
// bNoTeletype=True
// CharDelay=0.050000
// EOLDelay=0.100000
// bVisibleWhenEmpty=True
// OnCreateComponent=MyMOTDText.InternalOnCreateComponent
WinTop=0.001679
WinHeight=0.833203
WinLeft=0.01
Expand All @@ -220,7 +228,7 @@ defaultproperties
TabOrder=1
bNeverFocus=True
End Object
lb_MOTD=GUIScrollTextBox'KFGui.KFMOTD.MyMOTDText'
HTMLText=GUIHTMLTextBox'KFGui.KFMOTD.MyMOTDText'

Begin Object Class=GUILabel Name=VersionNum
TextAlign=TXTA_Right
Expand All @@ -234,12 +242,12 @@ defaultproperties
l_Version=GUILabel'KFGui.KFMOTD.VersionNum'

VersionString="KF Version"
PanelCaption="News from Tripwire Interactive"
PanelCaption="News source: TRIPWIRE INTERACTIVE"

b_QuickConnect=None

///////////////////////
myMOTD="||Retrieving Latest Updates From The Server"
myMOTD="<br><br>Retrieving Latest Updates From The Server"
// Values from Vel-San -- Host Server & URL
newsIPAddr="pastebin.com"
getRequest="GET /raw/zZAKur74 HTTP/1.1" // Defaults to this if nothing set, official Announcements
Expand Down
48 changes: 0 additions & 48 deletions SRLevelCleanup.uc

This file was deleted.

Loading

0 comments on commit 52bf743

Please sign in to comment.