11const UMG = require ( 'UMG' )
22const _ = require ( 'lodash' )
3+ const request = require ( 'request' )
34const fontSize = 12
45
5- function GetPC ( ) {
6- return PlayerController . C ( GWorld . GetAllActorsOfClass ( PlayerController ) . OutActors [ 0 ] )
6+ function textStyle ( color ) {
7+ return TextBlockStyle ( {
8+ Font : { Size : fontSize } ,
9+ ColorAndOpacity : {
10+ SpecifiedColor : color
11+ }
12+ } )
713}
814
9- function editor ( ) {
10- let source = `
11- let actor = new StaticMeshActor(GWorld)
12- actor.StaticMeshComponent.SetMobility('Movable')
13- actor.StaticMeshComponent.SetStaticMesh(StaticMesh.Load('/Engine/BasicShapes/Cube'))
14-
15- function tick() {
16- if (!actor.IsValid()) return
17- let rad = $time
18- let r = 50
19- let p = {Y:Math.cos(rad) * r, Z:Math.sin(rad) * r}
20- actor.SetActorLocation(p)
21- process.nextTick(tick)
15+ function GetPC ( ) {
16+ return World . C ( GWorld ) . GetPlayerController ( 0 )
2217}
2318
24- tick()
25- `
19+ function editor ( ) {
20+ let source = ''
2621 let actors = GWorld . GetAllActorsOfClass ( Actor ) . OutActors
2722 let elem
2823 function fire ( ) {
3227
3328 class MyEditor extends JavascriptWidget {
3429 AddChild ( x ) {
35- console . log ( 'add child' )
3630 this . SetRootWidget ( x )
3731 return { }
3832 }
@@ -49,10 +43,40 @@ tick()
4943 }
5044
5145 let MyEditor_C = require ( 'uclass' ) ( ) ( global , MyEditor )
46+
47+ let gist = ''
48+
49+ function load ( id ) {
50+ gist = id
51+
52+ request ( 'GET' , `https://gist.githubusercontent.com/${ id } /raw` , { res :'string' } ) . then ( str => {
53+ elem . SetText ( str )
54+ fire ( )
55+ } ) . catch ( e => {
56+ console . error ( String ( e ) )
57+ } )
58+ }
59+
60+ load ( 'nakosung/2466994e78e887d19c2b' )
5261
5362 return UMG ( MyEditor_C , { 'slot.size.size-rule' : 'Fill' } ,
5463 UMG . div ( { 'slot.size.size-rule' : 'Fill' } ,
55- UMG ( Button , { OnClicked : _ => fire ( ) } , "RUN (F5)" ) ,
64+ UMG . span ( { } ,
65+ UMG ( EditableTextBox , {
66+ 'slot.size.size-rule' : 'Fill' ,
67+ WidgetStyle :{ 'font.size' :fontSize } ,
68+ Text :gist ,
69+ HintText :'Gist id' ,
70+ OnTextCommitted :text => {
71+ if ( text != gist ) {
72+ load ( text )
73+ }
74+ }
75+ } ) ,
76+ UMG ( Button , { OnClicked : _ => fire ( ) } ,
77+ UMG . text ( { 'font.size' :fontSize * 1.5 } , "RUN (F5)" )
78+ )
79+ ) ,
5680 UMG ( MultiLineEditableTextBox , {
5781 'slot.size.size-rule' : 'Fill' ,
5882 WidgetStyle : { 'font.size' : fontSize } ,
@@ -67,37 +91,16 @@ tick()
6791 )
6892}
6993
70- function logWindow ( ) {
71- let onMessage = null
72- let myOutput
7394
95+ function logWindow ( ) {
7496 return UMG ( JavascriptMultiLineEditableTextBox , {
7597 'slot.size.size-rule' : 'Fill' ,
7698 AlwaysShowScrollbars : true ,
7799 IsReadOnly : true ,
78100 $link : elem => {
79- class MyOutput extends JavascriptOutputDevice {
80- OnMessage ( msg , verbosity , category ) {
81- onMessage && onMessage ( msg , verbosity , category )
82- }
83- }
84-
85- let MyOutput_C = require ( 'uclass' ) ( ) ( global , MyOutput )
86- myOutput = new MyOutput_C
87-
88101 let layout
89- let style = TextBlockStyle ( {
90- Font : { Size : fontSize } ,
91- ColorAndOpacity : {
92- SpecifiedColor : { R : 1 , G : 1 , B : 1 , A : 1 }
93- }
94- } )
95- let style2 = TextBlockStyle ( {
96- Font : { Size : fontSize } ,
97- ColorAndOpacity : {
98- SpecifiedColor : { R : 1 , G : 1 , B : 1 , A : 0.5 }
99- }
100- } )
102+ let style = textStyle ( { R : 1 , G : 1 , B : 1 , A : 1 } )
103+ let style2 = textStyle ( { R : 1 , G : 1 , B : 1 , A : 0.5 } )
101104 elem . SetTextDelegate = ( text , _layout ) => {
102105 layout = _layout
103106 }
@@ -107,7 +110,7 @@ function logWindow() {
107110 userScrolled = ( offset < 1 - 1e-5 )
108111 }
109112 let lines = 0
110- onMessage = ( msg , v , category ) => {
113+ let onMessage = ( msg , v , category ) => {
111114 let str = [ category , msg ] . join ( ':' )
112115 let model = new JavascriptTextModel ( )
113116 model . SetString ( str )
@@ -123,11 +126,19 @@ function logWindow() {
123126 elem . ScrollTo ( lines - 1 )
124127 }
125128 }
129+
130+ class MyOutput extends JavascriptOutputDevice {
131+ OnMessage ( msg , verbosity , category ) {
132+ onMessage && onMessage ( msg , verbosity , category )
133+ }
134+ }
135+
136+ let MyOutput_C = require ( 'uclass' ) ( ) ( global , MyOutput )
137+ elem . myOutput = new MyOutput_C
126138 } ,
127- $unlink : _ => {
128- myOutput . Kill ( )
129- myOutput = null
130- onMessage = null
139+ $unlink : elem => {
140+ elem . myOutput . Kill ( )
141+ elem . myOutput = null
131142 }
132143 } )
133144}
@@ -177,4 +188,4 @@ try {
177188}
178189catch ( e ) {
179190 require ( 'bootstrap' ) ( 'helloSnippet' )
180- }
191+ }
0 commit comments