Skip to content

Commit f2d7b0a

Browse files
committed
rework RewardDialog so that defaults are appropriate for standard layoutBounds, and options allow customization, #72
Signed-off-by: Chris Malley <[email protected]>
1 parent 0e54941 commit f2d7b0a

File tree

1 file changed

+53
-29
lines changed

1 file changed

+53
-29
lines changed

js/RewardDialog.js

+53-29
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,18 @@ define( function( require ) {
1111
'use strict';
1212

1313
// modules
14-
var inherit = require( 'PHET_CORE/inherit' );
15-
var vegas = require( 'VEGAS/vegas' );
14+
var Dialog = require( 'SUN/Dialog' );
1615
var HBox = require( 'SCENERY/nodes/HBox' );
17-
var VBox = require( 'SCENERY/nodes/VBox' );
1816
var Image = require( 'SCENERY/nodes/Image' );
19-
var RectangularPushButton = require( 'SUN/buttons/RectangularPushButton' );
20-
var VStrut = require( 'SCENERY/nodes/VStrut' );
21-
var Dialog = require( 'SUN/Dialog' );
17+
var inherit = require( 'PHET_CORE/inherit' );
2218
var NumberProperty = require( 'AXON/NumberProperty' );
23-
var ScoreDisplayNumberAndStar = require( 'VEGAS/ScoreDisplayNumberAndStar' );
24-
var Text = require( 'SCENERY/nodes/Text' );
2519
var PhetFont = require( 'SCENERY_PHET/PhetFont' );
2620
var PhetColorScheme = require( 'SCENERY_PHET/PhetColorScheme' );
21+
var RectangularPushButton = require( 'SUN/buttons/RectangularPushButton' );
22+
var ScoreDisplayNumberAndStar = require( 'VEGAS/ScoreDisplayNumberAndStar' );
23+
var Text = require( 'SCENERY/nodes/Text' );
24+
var VBox = require( 'SCENERY/nodes/VBox' );
25+
var vegas = require( 'VEGAS/vegas' );
2726

2827
// images
2928
var phetGirlJugglingStarsImage = require( 'image!VEGAS/phet-girl-juggling-stars.png' );
@@ -33,8 +32,16 @@ define( function( require ) {
3332
var newLevelString = require( 'string!VEGAS/newLevel' );
3433

3534
// constants
36-
var SCORE_FONT = new PhetFont( { size: 40, weight: 'bold' } );
37-
var BUTTON_FONT = new PhetFont( 24 );
35+
var DEFAULT_BUTTONS_FONT = new PhetFont( 16 );
36+
var DEFAULT_SCORE_DISPLAY_OPTIONS = {
37+
font: new PhetFont( { size: 22, weight: 'bold' } ),
38+
spacing: 6,
39+
starNodeOptions: {
40+
outerRadius: 20,
41+
innerRadius: 10,
42+
filledLineWidth: 2
43+
}
44+
};
3845

3946
/**
4047
* @param {number} score
@@ -44,47 +51,64 @@ define( function( require ) {
4451
function RewardDialog( score, options ) {
4552

4653
options = _.extend( {
47-
xMargin: 40,
54+
55+
// RewardDialog options
56+
phetGirlScale: 0.6,
57+
scoreDisplayOptions: null, // {Object|null} options passed to ScoreDisplayNumberAndStar
58+
buttonsFont: DEFAULT_BUTTONS_FONT,
59+
buttonsWidth: 110, // {number} fixed width for both buttons
60+
buttonsYSpacing: 15,
4861
keepGoingButtonListener: function() {}, // called when 'Keep Going' button is pressed
49-
newLevelButtonListener: function() {} // called when 'New Level' button is pressed
62+
newLevelButtonListener: function() {}, // called when 'New Level' button is pressed
63+
64+
// Dialog options
65+
xMargin: 30,
66+
yMargin: 20
5067
}, options );
5168

52-
var phetGirlNode = new Image( phetGirlJugglingStarsImage );
53-
54-
var scoreDisplay = new ScoreDisplayNumberAndStar( new NumberProperty( score ), {
55-
font: SCORE_FONT,
56-
spacing: 6,
57-
starNodeOptions: {
58-
outerRadius: 25,
59-
innerRadius: 12.5,
60-
filledLineWidth: 3,
61-
emptyLineWidth: 3
62-
}
69+
options.scoreDisplayOptions = _.extend( {}, DEFAULT_SCORE_DISPLAY_OPTIONS, options.numeratorOptions );
70+
71+
var phetGirlNode = new Image( phetGirlJugglingStarsImage, {
72+
scale: options.phetGirlScale
6373
} );
6474

75+
var scoreDisplay = new ScoreDisplayNumberAndStar( new NumberProperty( score ), options.scoreDisplayOptions );
76+
6577
var buttonOptions = {
66-
minWidth: 145, // determined empirically
67-
maxWidth: 145
78+
font: options.buttonsFont,
79+
minWidth: options.buttonsWidth,
80+
maxWidth: options.buttonsWidth
6881
};
6982

7083
var keepGoingButton = new RectangularPushButton( _.extend( {}, buttonOptions, {
71-
content: new Text( keepGoingString, { font: BUTTON_FONT } ),
84+
content: new Text( keepGoingString, { font: DEFAULT_BUTTONS_FONT } ),
7285
listener: options.keepGoingButtonListener,
7386
baseColor: 'white'
7487
} ) );
7588

7689
var newLevelButton = new RectangularPushButton( _.extend( {}, buttonOptions, {
77-
content: new Text( newLevelString, { font: BUTTON_FONT } ),
90+
content: new Text( newLevelString, { font: DEFAULT_BUTTONS_FONT } ),
7891
listener: options.newLevelButtonListener,
7992
baseColor: PhetColorScheme.PHET_LOGO_YELLOW
8093
} ) );
8194

95+
var buttons = new VBox( {
96+
children: [ keepGoingButton, newLevelButton ],
97+
spacing: options.buttonsYSpacing
98+
} );
99+
100+
// half the remaining height, so that scoreDisplay will be centered in the negative space above the buttons.
101+
var scoreSpacing = ( phetGirlNode.height - scoreDisplay.height - buttons.height ) / 2;
102+
assert && assert( scoreSpacing > 0, 'phetGirlNode is scaled down too much' );
103+
82104
var rightSideNode = new VBox( {
83-
children: [ scoreDisplay, new VStrut( 20 ), keepGoingButton, newLevelButton ],
84-
spacing: 25
105+
children: [ scoreDisplay, buttons ],
106+
align: 'center',
107+
spacing: scoreSpacing
85108
} );
86109

87110
var content = new HBox( {
111+
align: 'bottom',
88112
children: [ phetGirlNode, rightSideNode ],
89113
spacing: 40
90114
} );

0 commit comments

Comments
 (0)