11import { Scene } from 'phaser' ;
22import {
33 COLORS ,
4- WEBSITE_URL ,
54 MENU_ITEM_CONFIG ,
65 HOVER_TWEEN_CONFIG ,
76 CONTROLS_LIST_ITEMS ,
@@ -14,6 +13,7 @@ import { SoundFXKey } from '../constants/audio.js';
1413export class Controls extends Scene {
1514 injector ;
1615 _audioSystem ;
16+ _backButton ;
1717
1818 constructor ( ) {
1919 super ( SceneKey . CONTROLS ) ;
@@ -24,6 +24,7 @@ export class Controls extends Scene {
2424 }
2525
2626 create ( data ) {
27+ this . data . merge ( data ) ;
2728 this . cameras . main . setBackgroundColor ( 0x00000000 ) ;
2829
2930 const title = this . add
@@ -42,54 +43,42 @@ export class Controls extends Scene {
4243 let lastSectionItem = title ;
4344
4445 for ( let i = 0 ; i < CONTROLS_LIST_ITEMS . length ; i ++ ) {
45- const section = CONTROLS_LIST_ITEMS [ i ] ;
46- lastSectionItem = this . add
46+ const section = CONTROLS_LIST_ITEMS [ i ] ;
47+ lastSectionItem = this . add
4748 . text (
48- 320 ,
49- lastSectionItem . y + lastSectionItem . height + ( i === 0 ? 20 : 16 ) ,
50- section . title ,
51- {
52- fontFamily : 'usuzi' ,
53- fontSize : 18 ,
54- } ,
49+ 320 ,
50+ lastSectionItem . y + lastSectionItem . height + ( i === 0 ? 20 : 16 ) ,
51+ section . title ,
52+ {
53+ fontFamily : 'usuzi' ,
54+ fontSize : 18 ,
55+ } ,
5556 )
5657 . setOrigin ( 0.5 , 0 ) ;
5758
58- let previousListItem = lastSectionItem ;
59- const controls = section . controls ;
60- for ( let j = 0 ; j < controls . length ; j ++ ) {
61- const listItem = controls [ j ] ;
62- previousListItem = this . add
63- . text (
64- 320 ,
65- previousListItem . y + previousListItem . height + ( j === 0 ? 8 : 4 ) ,
66- `${ listItem . input } - ${ listItem . action } ` ,
67- {
68- fontFamily : 'usuzi' ,
69- fontSize : 14 ,
70- } ,
71- )
72- . setOrigin ( 0.5 , 0 ) ;
73-
74- const href = listItem . href ;
75- if ( href ) {
76- previousListItem . setInteractive ( MENU_ITEM_CONFIG ) ;
77- previousListItem . on ( 'pointerover' , onButtonHover ) ;
78- previousListItem . on ( 'pointerover' , onButtonHoverForInstance , this ) ;
79- previousListItem . on ( 'pointerout' , onButtonOut ) ;
80- previousListItem . on ( 'pointerup' , ( ) => {
81- this . _audioSystem . playSFX ( SoundFXKey . ITEM_SELECTION ) ;
82- window . open ( href , '_blank' ) ;
83- } ) ;
84- }
85-
86- if ( j === controls . length - 1 ) {
87- lastSectionItem = previousListItem ;
88- }
59+ let previousListItem = lastSectionItem ;
60+ const controls = section . controls ;
61+ for ( let j = 0 ; j < controls . length ; j ++ ) {
62+ const listItem = controls [ j ] ;
63+ previousListItem = this . add
64+ . text (
65+ 320 ,
66+ previousListItem . y + previousListItem . height + ( j === 0 ? 8 : 4 ) ,
67+ `${ listItem . input } - ${ listItem . action } ` ,
68+ {
69+ fontFamily : 'usuzi' ,
70+ fontSize : 14 ,
71+ } ,
72+ )
73+ . setOrigin ( 0.5 , 0 ) ;
74+
75+ if ( j === controls . length - 1 ) {
76+ lastSectionItem = previousListItem ;
8977 }
78+ }
9079 }
9180
92- const backButton = this . add
81+ this . _backButton = this . add
9382 . text ( 320 , 340 , 'Go back' , {
9483 fontFamily : 'usuzi' ,
9584 fontSize : 16 ,
@@ -98,16 +87,31 @@ export class Controls extends Scene {
9887 . setOrigin ( 0.5 , 1 )
9988 . setInteractive ( MENU_ITEM_CONFIG ) ;
10089
101- backButton . on ( 'pointerover' , onButtonHover ) ;
102- backButton . on ( 'pointerover' , onButtonHoverForInstance , this ) ;
103- backButton . on ( 'pointerout' , onButtonOut ) ;
104- backButton . on ( 'pointerup' , ( ) => {
105- this . _audioSystem . playSFX ( SoundFXKey . ITEM_SELECTION ) ;
106- this . scene . start ( data . returnScene ) ;
107- } ) ;
90+ this . _backButton . on ( 'pointerover' , onButtonHover ) ;
91+ this . _backButton . on ( 'pointerover' , onButtonHoverForInstance , this ) ;
92+ this . _backButton . on ( 'pointerout' , onButtonOut ) ;
93+ this . _backButton . on ( 'pointerup' , onBackButtonPressForInstance , this ) ;
94+
95+ this . events . once (
96+ 'shutdown' ,
97+ ( ) => {
98+ this . _backButton . off ( 'pointerover' , onButtonHover ) ;
99+ this . _backButton . off ( 'pointerover' , onButtonHoverForInstance , this ) ;
100+ this . _backButton . off ( 'pointerout' , onButtonOut ) ;
101+ this . _backButton . off ( 'pointerup' , onBackButtonPressForInstance , this ) ;
102+ } ,
103+ this ,
104+ ) ;
108105 }
109106}
110107
108+ function onBackButtonPressForInstance ( ) {
109+ this . _audioSystem . playSFX ( SoundFXKey . ITEM_SELECTION ) ;
110+ this . scene . start ( this . data . get ( 'returnScene' ) , {
111+ isReturning : true ,
112+ } ) ;
113+ }
114+
111115function onButtonHoverForInstance ( ) {
112116 this . _audioSystem . playSFX ( SoundFXKey . ITEM_HOVER ) ;
113117}
0 commit comments