Created
December 1, 2015 02:26
-
-
Save nakosung/447be3145bbf2d8c1f9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let actor = null | |
function write(something) { | |
if (actor == null) { | |
actor = new TextRenderActor(GWorld, { X: 800, Z: 100 }, { Yaw: 180 }) | |
actor.TextRender.SetHorizontalAlignment('EHTA_Center') | |
} | |
actor.TextRender.K2_SetText(something) | |
} | |
function load(url) { | |
write("loading " + url) | |
return new Promise((resolve, reject) => { | |
var req = new JavascriptHttpRequest() | |
req.SetVerb("GET") | |
req.SetURL(url) | |
req.OnComplete.Add(function (success) { | |
if (success) { | |
let result = eval(req.GetContentAsString()) | |
write("loading " + url + ":done") | |
try { | |
resolve(result) | |
write("done!!!") | |
} catch (e) { | |
write(String(e)) | |
} | |
} else { | |
write("loading " + url + ":fail") | |
reject() | |
} | |
}) | |
req.ProcessRequest() | |
}) | |
} | |
load("https://gist.githubusercontent.com/nakosung/d8a00066ee52af1959da/raw").then(function () { | |
write("invoking main") | |
// set cursor type | |
GetPC().DefaultMouseCursor = Symbol('Default') | |
let str = [] | |
// declare our own HUD class | |
class MyHUD extends HUD { | |
ctor() { | |
this.count = 0 | |
} | |
// override ReceiveDrawHUD | |
ReceiveDrawHUD() { | |
// don't forget to its super function | |
super.ReceiveDrawHUD() | |
// have fun with Canvas | |
let text = str.join("\n") | |
if (this.count-- < 0) { | |
this.count = 100 | |
str.pop() | |
} | |
this.Canvas.K2_DrawText( | |
GEngine.LargeFont, | |
text, | |
{ X: this.Canvas.SizeX / 2, Y: this.Canvas.SizeY / 2 }, | |
{ R: 1, G: 1, B: 1, A: 1 }, | |
0, | |
{ R: 0, G: 0, B: 0, A: 1 }, | |
{ X: 1, Y: 1 }, | |
true, true, true, | |
{ R: 0, G: 0, B: 0, A: 1 } | |
) | |
} | |
} | |
// register new HUD class | |
let MyHUD_C = require('uclass')()(global, MyHUD); | |
// and instantiate it | |
GetPC().ClientSetHUD(MyHUD_C) | |
function testUI() { | |
let cleanup = null | |
let PC = GetPC() | |
let widget = null | |
// create a widget | |
widget = GWorld.CreateWidget(JavascriptWidget, PC) | |
widget.JavascriptContext = Context | |
widget.bSupportsKeyboardFocus = true | |
let UMG = require('UMG') | |
// low-level json which describes UMG structure to set up. | |
let design = UMG.span({}, | |
UMG(Button, { id: 'button' }, UMG.text({}, "RELOAD!")) | |
) | |
let instantiator = require('instantiator') | |
let page = instantiator(design) | |
let bye = null | |
page.find('button').OnClicked.Add(() => { | |
//cleanup() | |
write("loading client!") | |
if (bye) { | |
bye() | |
} | |
load(THE_URL+"?random=" + Math.random()).then((result) => { | |
write("client loaded!") | |
bye = result | |
}) | |
//load("https://gist.githubusercontent.com/nakosung/756aed5399da66ed40d7/raw?random=" + Math.random()) | |
}) | |
page.Visibility = 'Visible' | |
widget.SetRootWidget(page) | |
widget.AddToViewport() | |
// Switch PC to UI only mode. | |
PC.bShowMouseCursor = true | |
PC.SetInputMode_UIOnly(page) | |
cleanup = () => { | |
widget.RemoveFromViewport() | |
if (bye) { | |
bye() | |
} | |
} | |
} | |
try { | |
testUI() | |
} catch (e) { | |
str += String(e) | |
str += String(e.stack) | |
} | |
}).catch((error) => { | |
write(error) | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment