@@ -3,7 +3,7 @@ import {subGoal, stepInfo, allStages, steps, stepSubgoalMap, vfg, textContent,
3
3
getAllStages , getSteps , getStepInfo , getSubGoal , getStepSubgoalMap } from './dataUtils' ;
4
4
import Button from '@material-ui/core/Button' ;
5
5
import styles from './index.less' ;
6
- import ViScreen , { ControlPanel , StepScreen } from "./screenComponents" ;
6
+ import Screen , { ControlPanel , StepScreen , GoalScreen } from "./screenComponents" ;
7
7
8
8
9
9
class PageFour extends React . Component {
@@ -39,6 +39,8 @@ class PageFour extends React.Component {
39
39
this . receiveMessageFromPlugin = this . receiveMessageFromPlugin . bind ( this ) ;
40
40
}
41
41
42
+
43
+
42
44
updateWindowDimensions ( ) {
43
45
if ( this . refDom ) {
44
46
const { clientWidth, clientHeight} = this . refDom ;
@@ -47,13 +49,17 @@ class PageFour extends React.Component {
47
49
console . log ( 'client.inner' , clientWidth , clientHeight ) ;
48
50
} ) ;
49
51
}
50
- }
52
+ }
53
+
54
+
51
55
52
56
handleOnClick ( ) {
53
57
this . props . history . push ( '/' )
54
58
}
55
59
56
- handleSubItemClick ( key ) {
60
+
61
+
62
+ handleSubItemClick = ( key ) => {
57
63
// this.state.stageIndex = index;
58
64
if ( this . state . showKey !== key ) {
59
65
this . setState ( {
@@ -66,12 +72,16 @@ class PageFour extends React.Component {
66
72
}
67
73
}
68
74
75
+
76
+
69
77
componentDidMount ( ) {
70
78
this . updateWindowDimensions ( ) ;
71
79
this . refDom . addEventListener ( 'resize' , this . updateWindowDimensions ) ;
72
80
73
81
}
74
82
83
+
84
+
75
85
receiveMessageFromPlugin ( event ) {
76
86
if ( event . origin !== "http://localhost:3000" ) {
77
87
console . log ( 'iframe is working:' , event . origin ) ;
@@ -112,8 +122,9 @@ class PageFour extends React.Component {
112
122
return map ;
113
123
}
114
124
125
+
115
126
/**
116
- * Calculate interpolation values between two stages
127
+ * Calculate and diplays interpolation animation between two stages
117
128
* @param {Integer } index
118
129
*/
119
130
animation ( index ) {
@@ -186,7 +197,9 @@ class PageFour extends React.Component {
186
197
this . handler = handler ;
187
198
} ;
188
199
189
- handleStepsClick ( index ) {
200
+
201
+
202
+ handleStepsClick = ( index ) => {
190
203
// Get Stage[index] sprites, and display
191
204
if ( this . handlerPlay ) {
192
205
clearInterval ( this . handlerPlay ) ;
@@ -204,7 +217,9 @@ class PageFour extends React.Component {
204
217
this . animation ( index )
205
218
}
206
219
207
- handleSubgoalStepItemClick ( value ) {
220
+
221
+
222
+ handleSubgoalStepItemClick = ( value ) => {
208
223
if ( this . handlerPlay ) {
209
224
clearInterval ( this . handlerPlay ) ;
210
225
}
@@ -224,7 +239,9 @@ class PageFour extends React.Component {
224
239
this . stepItem [ index ] . current . scrollIntoView ( ) ;
225
240
}
226
241
227
- handlePreviousClick ( value ) {
242
+
243
+
244
+ handlePreviousClick = ( value ) => {
228
245
const previousIndex = Number ( value ) - 1 ;
229
246
if ( previousIndex < 0 ) {
230
247
alert ( "It's already the initial state!" )
@@ -242,7 +259,9 @@ class PageFour extends React.Component {
242
259
}
243
260
}
244
261
245
- handleNextClick ( value ) {
262
+
263
+
264
+ handleNextClick = ( value ) => {
246
265
const nextIndex = Number ( value ) + 1
247
266
if ( nextIndex >= steps . length ) {
248
267
alert ( "It's already the final state!" )
@@ -260,7 +279,9 @@ class PageFour extends React.Component {
260
279
}
261
280
}
262
281
263
- handleStartClick ( value ) {
282
+
283
+
284
+ handleStartClick = ( value ) => {
264
285
let nextIndex = Number ( value ) + 1
265
286
if ( nextIndex === steps . length ) {
266
287
alert ( "It's already the final state!" )
@@ -315,7 +336,9 @@ class PageFour extends React.Component {
315
336
}
316
337
}
317
338
318
- handlePauseClick ( ) {
339
+
340
+
341
+ handlePauseClick = ( ) => {
319
342
if ( this . handlerPlay ) {
320
343
this . setState ( {
321
344
playButtonColor : 'primary' ,
@@ -325,7 +348,9 @@ class PageFour extends React.Component {
325
348
}
326
349
}
327
350
328
- handleResetClick ( ) {
351
+
352
+
353
+ handleResetClick = ( ) => {
329
354
if ( this . handlerPlay ) {
330
355
clearInterval ( this . handlerPlay ) ;
331
356
}
@@ -341,7 +366,9 @@ class PageFour extends React.Component {
341
366
this . stepItem [ 0 ] . current . scrollIntoView ( ) ;
342
367
}
343
368
344
- handleShowFinalGoalClick ( ) {
369
+
370
+
371
+ handleShowFinalGoalClick = ( ) => {
345
372
if ( this . handlerPlay ) {
346
373
clearInterval ( this . handlerPlay ) ;
347
374
}
@@ -358,7 +385,9 @@ class PageFour extends React.Component {
358
385
this . stepItem [ index ] . current . scrollIntoView ( ) ;
359
386
}
360
387
361
- handleExportClick ( ) {
388
+
389
+
390
+ handleExportClick = ( ) => {
362
391
const data = textContent
363
392
let blob = new Blob ( [ data ] ) ;
364
393
let filename = "download.vfg" ;
@@ -382,13 +411,18 @@ class PageFour extends React.Component {
382
411
}
383
412
}
384
413
385
- handleSpeedControllor ( value ) {
414
+
415
+
416
+ handleSpeedControllor = ( value ) => {
386
417
this . setState ( {
387
418
playSpeed : value
388
419
} )
389
420
}
421
+
390
422
391
- // prevent crash when jumping to other pages during the animation playing
423
+ /**
424
+ * prevent crash when jumping to other pages during the animation playing
425
+ * */
392
426
componentWillUnmount ( ) {
393
427
if ( this . handlerPlay ) {
394
428
clearInterval ( this . handlerPlay ) ;
@@ -397,6 +431,8 @@ class PageFour extends React.Component {
397
431
398
432
}
399
433
434
+
435
+
400
436
render ( ) {
401
437
// Get all sprites
402
438
let sprites = this . state . drawSprites ;
@@ -406,13 +442,22 @@ class PageFour extends React.Component {
406
442
return (
407
443
< div className = { styles . container } ref = { ( ref ) => this . refDom = ref } >
408
444
< div className = { styles . left } >
409
- < StepScreen stepInfoIndex = { this . state . stepInfoIndex } stepItem = { this . stepItem } stepInfo = { stepInfo } />
445
+ < StepScreen stepInfoIndex = { this . state . stepInfoIndex } stepItem = { this . stepItem } stepInfo = { stepInfo } onStepClick = { this . handleStepsClick } />
410
446
</ div >
411
447
< div className = { styles . middle } >
412
- < ViScreen canvasWidth = { this . state . canvasWidth } canvasHeight = { this . state . canvasHeight } sprites = { this . state . drawSprites } vfg = { vfg } />
448
+ < Screen canvasWidth = { this . state . canvasWidth } canvasHeight = { this . state . canvasHeight } sprites = { this . state . drawSprites } vfg = { vfg } />
413
449
< div className = { styles . btn_box } >
414
450
< div >
415
- < ControlPanel playButtonColor = { this . state . playButtonColor } pauseButtonColor = { this . state . pauseButtonColor } stepInfoIndex = { this . state . stepInfoIndex } > </ ControlPanel >
451
+ < ControlPanel
452
+ playButtonColor = { this . state . playButtonColor }
453
+ pauseButtonColor = { this . state . pauseButtonColor }
454
+ stepInfoIndex = { this . state . stepInfoIndex }
455
+ onPreviousClick = { this . handlePreviousClick }
456
+ onStartClick = { this . handleStartClick }
457
+ onPauseClick = { this . handlePauseClick }
458
+ onNextClick = { this . handleNextClick }
459
+ onResetClick = { this . handleResetClick }
460
+ onSpeedControllor = { this . handleSpeedControllor } > </ ControlPanel >
416
461
</ div >
417
462
</ div >
418
463
</ div >
@@ -427,29 +472,8 @@ class PageFour extends React.Component {
427
472
Export
428
473
</ Button >
429
474
</ div >
430
- < div className = { styles . sub_title } style = { { position : 'relative' } } >
431
- < span className = { styles . sub_title_key } > Subgoal</ span >
432
- < span className = { styles . sub_title_selected } > { Object . keys ( this . state . selectedSubGoals || { } ) . length } /{ subGoal . size } </ span >
433
- </ div >
434
- < div className = { styles . sub_list } >
435
- { sprites &&
436
- [ ...subGoal . keys ( ) ] . map ( key => {
437
- return < div className = { styles . sub_item + ' ' + ( this . state . selectedSubGoals [ key ] ? styles . highlight_item : ' ' ) }
438
- key = { key } onClick = { ( ) => { this . handleSubItemClick ( key ) } } >
439
- { key }
440
- < div className = { styles . sub_item_menu }
441
- style = { { display : this . state . showKey === key ? 'block' : 'none' } } >
442
- { subGoal . get ( key ) . map ( value => {
443
- return < div className = { styles . sub_item_menu_item }
444
- onClick = { ( ) => this . handleSubgoalStepItemClick ( value ) }
445
- key = { key + value }
446
- > Step { value } </ div >
447
- } ) }
448
- </ div >
449
- </ div > ;
450
- } )
451
- }
452
- </ div >
475
+ < GoalScreen sprites = { sprites } subGoal = { subGoal } selectedSubGoals = { this . state . selectedSubGoals }
476
+ showKey = { this . state . showKey } onSubItemClick = { this . handleSubItemClick } onSubgoalStepItemClick = { this . handleSubgoalStepItemClick } />
453
477
</ div >
454
478
</ div >
455
479
) ;
0 commit comments