1
1
const UMG = require ( 'UMG' )
2
2
const _ = require ( 'lodash' )
3
+ const request = require ( 'request' )
3
4
const fontSize = 12
4
5
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
+ } )
7
13
}
8
14
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 )
22
17
}
23
18
24
- tick()
25
- `
19
+ function editor ( ) {
20
+ let source = ''
26
21
let actors = GWorld . GetAllActorsOfClass ( Actor ) . OutActors
27
22
let elem
28
23
function fire ( ) {
32
27
33
28
class MyEditor extends JavascriptWidget {
34
29
AddChild ( x ) {
35
- console . log ( 'add child' )
36
30
this . SetRootWidget ( x )
37
31
return { }
38
32
}
@@ -49,10 +43,40 @@ tick()
49
43
}
50
44
51
45
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' )
52
61
53
62
return UMG ( MyEditor_C , { 'slot.size.size-rule' : 'Fill' } ,
54
63
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
+ ) ,
56
80
UMG ( MultiLineEditableTextBox , {
57
81
'slot.size.size-rule' : 'Fill' ,
58
82
WidgetStyle : { 'font.size' : fontSize } ,
@@ -67,37 +91,16 @@ tick()
67
91
)
68
92
}
69
93
70
- function logWindow ( ) {
71
- let onMessage = null
72
- let myOutput
73
94
95
+ function logWindow ( ) {
74
96
return UMG ( JavascriptMultiLineEditableTextBox , {
75
97
'slot.size.size-rule' : 'Fill' ,
76
98
AlwaysShowScrollbars : true ,
77
99
IsReadOnly : true ,
78
100
$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
-
88
101
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 } )
101
104
elem . SetTextDelegate = ( text , _layout ) => {
102
105
layout = _layout
103
106
}
@@ -107,7 +110,7 @@ function logWindow() {
107
110
userScrolled = ( offset < 1 - 1e-5 )
108
111
}
109
112
let lines = 0
110
- onMessage = ( msg , v , category ) => {
113
+ let onMessage = ( msg , v , category ) => {
111
114
let str = [ category , msg ] . join ( ':' )
112
115
let model = new JavascriptTextModel ( )
113
116
model . SetString ( str )
@@ -123,11 +126,19 @@ function logWindow() {
123
126
elem . ScrollTo ( lines - 1 )
124
127
}
125
128
}
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
126
138
} ,
127
- $unlink : _ => {
128
- myOutput . Kill ( )
129
- myOutput = null
130
- onMessage = null
139
+ $unlink : elem => {
140
+ elem . myOutput . Kill ( )
141
+ elem . myOutput = null
131
142
}
132
143
} )
133
144
}
@@ -177,4 +188,4 @@ try {
177
188
}
178
189
catch ( e ) {
179
190
require ( 'bootstrap' ) ( 'helloSnippet' )
180
- }
191
+ }
0 commit comments