@@ -14,8 +14,8 @@ import Slider from '@material-ui/core/Slider';
14
14
import styles from './index.less' ;
15
15
import * as PIXI from 'pixi.js'
16
16
17
- const canvasWidth = 800
18
- const canvasHeight = 470
17
+ // const canvasWidth = 800
18
+ // const canvasHeight = 470
19
19
20
20
function valuetext ( value ) {
21
21
return `${ value } ` ;
@@ -31,6 +31,7 @@ class PageFour extends React.Component {
31
31
this . stepItem [ i ] = React . createRef ( ) ;
32
32
} )
33
33
34
+
34
35
this . state = {
35
36
// data that will be used/changed in render function
36
37
stageIndex : 0 ,
@@ -41,14 +42,27 @@ class PageFour extends React.Component {
41
42
drawSprites : allStages [ 0 ] ,
42
43
playSpeed : 3 ,
43
44
playButtonColor : 'primary' ,
44
- pauseButtonColor : 'default'
45
+ pauseButtonColor : 'default' ,
46
+ canvasWidth : 720 ,
47
+ canvasHeight : 470 ,
45
48
}
46
49
47
50
// Every function that interfaces with UI and data used
48
51
// in this class needs to bind like this:
49
52
this . handleOnClick = this . handleOnClick . bind ( this ) ;
53
+ this . updateWindowDimensions = this . updateWindowDimensions . bind ( this ) ;
50
54
}
51
55
56
+ updateWindowDimensions ( ) {
57
+ if ( this . refDom ) {
58
+ const { clientWidth, clientHeight} = this . refDom ;
59
+ const tmp_width = Math . max ( clientWidth - 550 , 720 )
60
+ this . setState ( { canvasWidth : tmp_width , canvasHeight : Math . min ( tmp_width / 2 , clientHeight - 120 ) } , ( val ) => {
61
+ console . log ( 'client.inner' , clientWidth , clientHeight ) ;
62
+ } ) ;
63
+ }
64
+ }
65
+
52
66
handleOnClick ( ) {
53
67
this . props . history . push ( '/' )
54
68
}
@@ -66,6 +80,10 @@ class PageFour extends React.Component {
66
80
}
67
81
}
68
82
83
+ componentDidMount ( ) {
84
+ this . updateWindowDimensions ( ) ;
85
+ window . addEventListener ( 'resize' , this . updateWindowDimensions ) ;
86
+ }
69
87
70
88
highlight ( index ) {
71
89
const highlightSubGoals = stepSubgoalMap . get ( index ) || [ ] ;
@@ -361,17 +379,18 @@ class PageFour extends React.Component {
361
379
if ( this . handlerPlay ) {
362
380
clearInterval ( this . handlerPlay ) ;
363
381
}
382
+ this . refDom . removeEventListener ( 'resize' , this . updateWindowDimensions ) ;
364
383
}
365
384
366
385
render ( ) {
367
386
// Get all sprites
368
387
// var sprites = vfg.visualStages[this.state.stepInfoIndex].visualSprites;
369
388
var sprites = this . state . drawSprites ;
370
389
// Sort sprites by their depth
371
- sprites . sort ( ( itemA , itemB ) => itemA . depth - itemB . depth )
390
+ sprites && sprites . sort ( ( itemA , itemB ) => itemA . depth - itemB . depth )
372
391
373
392
return (
374
- < div className = { styles . container } >
393
+ < div className = { styles . container } ref = { ( ref ) => this . refDom = ref } >
375
394
< div className = { styles . left } >
376
395
< div className = { styles . sub_title } > Steps </ div >
377
396
< div className = { styles . left_upper } >
@@ -387,21 +406,27 @@ class PageFour extends React.Component {
387
406
} )
388
407
}
389
408
</ div >
390
- < div >
409
+ < div className = { styles . sub_title } > Step Info </ div >
410
+ < div className = { styles . step_info } >
411
+ {
412
+ stepInfo [ this . state . stepInfoIndex ]
413
+ }
414
+ </ div >
415
+ { /* <div>
391
416
<div className={styles.sub_title}> Step Info </div>
392
417
<div className={styles.step_info}>
393
418
{
394
419
stepInfo[this.state.stepInfoIndex]
395
420
}
396
421
</div>
397
- </ div >
422
+ </div> */ }
398
423
</ div >
399
424
< div className = { styles . middle } >
400
- < Stage width = { canvasWidth } height = { canvasHeight }
425
+ < Stage width = { this . state . canvasWidth } height = { this . state . canvasHeight }
401
426
options = { { backgroundColor : 0xffffff } } key = { 'main-graph' } >
402
427
{
403
428
404
- sprites . map ( ( sprite , i ) => {
429
+ sprites && sprites . map ( ( sprite , i ) => {
405
430
// Get the texture name
406
431
var textureName = sprite . prefabimage
407
432
// Get the color of the sprite
@@ -412,17 +437,17 @@ class PageFour extends React.Component {
412
437
// Initialize the rotation of the sprite
413
438
var rotation = 0
414
439
// Initialize the x-axis coordinate position of the sprite
415
- var x = sprite . minX * canvasHeight
440
+ var x = sprite . minX * this . state . canvasHeight
416
441
// Initialize the y-axis coordinate position of the sprite
417
- var y = canvasHeight - sprite . maxY * canvasHeight
442
+ var y = this . state . canvasHeight - sprite . maxY * this . state . canvasHeight
418
443
// Initialize the anchor (i.e. the origin point) of the sprite
419
444
var anchor = ( 0 , 0 )
420
445
// Update the anchor, rotation, (x,y) location if the sprite need to be rotated
421
446
if ( 'rotate' in sprite ) {
422
447
anchor = ( 0.5 , 0.5 )
423
448
rotation = sprite . rotate * Math . PI / 180 ;
424
- x = sprite . minX * canvasHeight + ( sprite . maxX - sprite . minX ) * canvasHeight / 2
425
- y = canvasHeight - sprite . minY * canvasHeight
449
+ x = sprite . minX * this . state . canvasHeight + ( sprite . maxX - sprite . minX ) * this . state . canvasHeight / 2
450
+ y = this . state . canvasHeight - sprite . minY * this . state . canvasHeight
426
451
}
427
452
// Draw the sprite with a text
428
453
if ( sprite . showname ) {
@@ -436,17 +461,17 @@ class PageFour extends React.Component {
436
461
rotation = { rotation }
437
462
x = { x }
438
463
y = { y }
439
- width = { ( sprite . maxX - sprite . minX ) * canvasHeight }
440
- height = { ( sprite . maxY - sprite . minY ) * canvasHeight }
464
+ width = { ( sprite . maxX - sprite . minX ) * this . state . canvasHeight }
465
+ height = { ( sprite . maxY - sprite . minY ) * this . state . canvasHeight }
441
466
tint = { color }
442
467
/>
443
468
< Text
444
469
// text on the sprite
445
470
text = { sprite . name }
446
471
style = { { fontFamily : 'Arial' , fontSize : 16 , fill : 0x000000 } }
447
472
anchor = { ( 0.5 , 0.5 ) }
448
- x = { x + ( sprite . maxX - sprite . minX ) * canvasHeight / 2 }
449
- y = { y + ( sprite . maxY - sprite . minY ) * canvasHeight / 2 }
473
+ x = { x + ( sprite . maxX - sprite . minX ) * this . state . canvasHeight / 2 }
474
+ y = { y + ( sprite . maxY - sprite . minY ) * this . state . canvasHeight / 2 }
450
475
/>
451
476
</ >
452
477
)
@@ -462,8 +487,8 @@ class PageFour extends React.Component {
462
487
rotation = { rotation }
463
488
x = { x }
464
489
y = { y }
465
- width = { ( sprite . maxX - sprite . minX ) * canvasHeight }
466
- height = { ( sprite . maxY - sprite . minY ) * canvasHeight }
490
+ width = { ( sprite . maxX - sprite . minX ) * this . state . canvasHeight }
491
+ height = { ( sprite . maxY - sprite . minY ) * this . state . canvasHeight }
467
492
tint = { color }
468
493
/>
469
494
</ >
@@ -472,7 +497,8 @@ class PageFour extends React.Component {
472
497
} )
473
498
}
474
499
</ Stage >
475
- < div style = { { height :'50px' } } >
500
+ < div className = { styles . btn_box } >
501
+ < div >
476
502
< IconButton color = "primary" style = { { float :'left' , marginLeft :'6%' , marginRight :'5%' } } onClick = { ( ) => { this . handlePreviousClick ( this . state . stepInfoIndex ) ; } } >
477
503
< SkipPreviousIcon fontSize = "large" />
478
504
</ IconButton >
@@ -502,10 +528,11 @@ class PageFour extends React.Component {
502
528
// onChangeCommitted={this.handleSpeedControllor()}
503
529
/>
504
530
</ div >
531
+ </ div >
505
532
</ div >
506
533
507
534
< div className = { styles . right } >
508
- < div style = { { marginTop :'5px' , marginBottom :'5px' } } >
535
+ < div style = { { marginTop :'5px' , marginBottom :'5px' , width : '220px' } } >
509
536
< Button variant = "contained" color = "primary" size = "small" onClick = { ( ) => { this . handleShowFinalGoalClick ( ) } } >
510
537
Show the Goal
511
538
</ Button >
@@ -514,12 +541,12 @@ class PageFour extends React.Component {
514
541
Export
515
542
</ Button >
516
543
</ div >
517
- < div className = { styles . sub_title } >
518
- < div className = { styles . sub_title_key } > Subgoal</ div >
519
- < div className = { styles . sub_title_selected } > { Object . keys ( this . state . selectedSubGoals || { } ) . length } /{ subGoal . size } </ div >
544
+ < div className = { styles . sub_title } style = { { position : 'relative' } } >
545
+ < span className = { styles . sub_title_key } > Subgoal</ span >
546
+ < span className = { styles . sub_title_selected } > { Object . keys ( this . state . selectedSubGoals || { } ) . length } /{ subGoal . size } </ span >
520
547
</ div >
521
548
< div className = { styles . sub_list } >
522
- {
549
+ { sprites &&
523
550
[ ...subGoal . keys ( ) ] . map ( key => {
524
551
return < div className = { styles . sub_item + ' ' + ( this . state . selectedSubGoals [ key ] ? styles . highlight_item : ' ' ) }
525
552
key = { key } onClick = { ( ) => { this . handleSubItemClick ( key ) } } >
0 commit comments