Skip to content

Commit

Permalink
Switching to optionsNode for global options. see #154
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanolson committed Oct 8, 2014
1 parent 5b9874f commit 3dbc031
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 34 deletions.
37 changes: 6 additions & 31 deletions js/OptionsDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,26 @@
/**
* Shows an Options dialog that consists of sim-global options.
*
* Options are provided as 'globalOptions' inside a sim's options.
*
* @author Jonathan Olson <[email protected]>
*/
define( function( require ) {
'use strict';

// modules
var VBox = require( 'SCENERY/nodes/VBox' );
var Text = require( 'SCENERY/nodes/Text' );
var inherit = require( 'PHET_CORE/inherit' );
var PhetFont = require( 'SCENERY_PHET/PhetFont' );
var CheckBox = require( 'SUN/CheckBox' );
var Dialog = require( 'JOIST/Dialog' );

// strings
var optionsTitleString = require( 'string!JOIST/options.title' );

/**
* The options should be an array of item objects, which all have item.type. The following types are available:
*
* { // 'boolean' will show up as a labeled CheckBox
* type: 'boolean',
* label: 'Some Option',
* property: someBooleanProperty
* }
*
* @param {Array} options
* @param {Node} optionsNode
* @constructor
*/
function OptionsDialog( options ) {

var children = [];
for ( var i = 0; i < options.length; i++ ) {
var option = options[i];

switch( option.type ) {
case 'boolean':
children.push( new CheckBox( new Text( option.label, { font: new PhetFont( 15 ) } ), option.property, {} ) );
break;
default:
throw new Error( 'unknown option type: ' + option.type );
}
}

var content = new VBox( { align: 'left', spacing: 10, children: children } );

Dialog.call( this, content, {
function OptionsDialog( optionsNode ) {
Dialog.call( this, optionsNode, {
title: new Text( optionsTitleString, { font: new PhetFont( 30 ) } ),
titleAlign: 'center',
modal: true,
Expand All @@ -60,5 +32,8 @@ define( function( require ) {

inherit( Dialog, OptionsDialog );

OptionsDialog.DEFAULT_FONT = new PhetFont( 15 );
OptionsDialog.DEFAULT_SPACING = 10;

return OptionsDialog;
} );
4 changes: 2 additions & 2 deletions js/PhetMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ define( function( require ) {
var itemDescriptors = [
{
text: optionsString,
present: !!sim.options.globalOptions,
present: !!sim.options.optionsNode,
callback: function() {
new OptionsDialog( sim.options.globalOptions ).show();
new OptionsDialog( sim.options.optionsNode ).show();
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion js/Sim.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ define( function( require ) {
standalone: false, // whether to run the screen indicated by screenIndex as a standalone sim
credits: {}, // credits, see AboutDialog for format

globalOptions: null, // replace with globalOptions described in OptionsDialog
optionsNode: null, // a node placed into the Options dialog (if available)

// if true, prints screen initialization time (total, model, view) to the console and displays
// profiling information on the screen
Expand Down

0 comments on commit 3dbc031

Please sign in to comment.