Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Nov 20, 2019
2 parents e5615f8 + 3c9002d commit 8dab3b7
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 25 deletions.
8 changes: 8 additions & 0 deletions js/AquaRadioButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ define( require => {
const InstanceRegistry = require( 'PHET_CORE/documentation/InstanceRegistry' );
const merge = require( 'PHET_CORE/merge' );
const Node = require( 'SCENERY/nodes/Node' );
const radioButtonSoundPlayerFactory = require( 'TAMBO/radioButtonSoundPlayerFactory' );
const Rectangle = require( 'SCENERY/nodes/Rectangle' );
const sun = require( 'SUN/sun' );
const SunConstants = require( 'SUN/SunConstants' );
Expand Down Expand Up @@ -47,6 +48,9 @@ define( require => {
tandem: Tandem.required,
phetioLinkProperty: true,

// {Playable|null} - sound generator, if set to null default will be used, set to Playable.NO_SOUND to disable
soundPlayer: null,

// a11y
tagName: 'input',
inputType: 'radio',
Expand Down Expand Up @@ -113,9 +117,13 @@ define( require => {
};
property.link( syncWithModel );

// sound generation
const soundPlayer = options.soundPlayer || radioButtonSoundPlayerFactory.getRadioButtonSoundPlayer( 0 );

// set property value on fire
const fire = function() {
property.set( value );
soundPlayer.play();
};
const inputListener = new FireListener( {
fire: fire,
Expand Down
2 changes: 2 additions & 0 deletions js/VerticalAquaRadioButtonGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ define( require => {
const HStrut = require( 'SCENERY/nodes/HStrut' );
const merge = require( 'PHET_CORE/merge' );
const Node = require( 'SCENERY/nodes/Node' );
const radioButtonSoundPlayerFactory = require( 'TAMBO/radioButtonSoundPlayerFactory' );
const sun = require( 'SUN/sun' );
const Tandem = require( 'TANDEM/Tandem' );
const VBox = require( 'SCENERY/nodes/VBox' );
Expand Down Expand Up @@ -82,6 +83,7 @@ define( require => {
merge( {}, options.radioButtonOptions, {
tandem: item.tandemName ? options.tandem.createTandem( item.tandemName ) : Tandem.required,
labelContent: item.labelContent || null,
soundPlayer: radioButtonSoundPlayerFactory.getRadioButtonSoundPlayer( i ),
a11yNameAttribute: CLASS_NAME + instanceCount
} ) );

Expand Down
4 changes: 3 additions & 1 deletion js/buttons/RadioButtonGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ define( require => {
const Property = require( 'AXON/Property' );
const RadioButtonGroupAppearance = require( 'SUN/buttons/RadioButtonGroupAppearance' );
const RadioButtonGroupMember = require( 'SUN/buttons/RadioButtonGroupMember' );
const radioButtonSoundPlayerFactory = require( 'TAMBO/radioButtonSoundPlayerFactory' );
const Rectangle = require( 'SCENERY/nodes/Rectangle' );
const Shape = require( 'KITE/Shape' );
const sun = require( 'SUN/sun' );
Expand Down Expand Up @@ -199,7 +200,8 @@ define( require => {
yAlign: options.buttonContentYAlign,
minWidth: widestContentWidth + 2 * options.buttonContentXMargin,
minHeight: tallestContentHeight + 2 * options.buttonContentYMargin,
phetioDocumentation: currentContent.phetioDocumentation || ''
phetioDocumentation: currentContent.phetioDocumentation || '',
soundPlayer: radioButtonSoundPlayerFactory.getRadioButtonSoundPlayer( i )
}, buttonOptions );

// Pass through the tandem given the tandemName, but also support uninstrumented simulations
Expand Down
11 changes: 11 additions & 0 deletions js/buttons/RadioButtonGroupMember.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ define( require => {
const inherit = require( 'PHET_CORE/inherit' );
const merge = require( 'PHET_CORE/merge' );
const PhetioObject = require( 'TANDEM/PhetioObject' );
const pushButtonSoundPlayer = require( 'TAMBO/shared-sound-players/pushButtonSoundPlayer' );
const RadioButtonGroupAppearance = require( 'SUN/buttons/RadioButtonGroupAppearance' );
const RadioButtonInteractionStateProperty = require( 'SUN/buttons/RadioButtonInteractionStateProperty' );
const RectangularButtonView = require( 'SUN/buttons/RectangularButtonView' );
Expand Down Expand Up @@ -64,6 +65,9 @@ define( require => {
buttonAppearanceStrategy: RadioButtonGroupAppearance.defaultRadioButtonsAppearance,
contentAppearanceStrategy: RadioButtonGroupAppearance.contentAppearanceStrategy,

// {Playable|null} - sound generator, if set to null the default will be used, set to Playable.NO_SOUND to disable
soundPlayer: null,

// a11y
tagName: 'input',
inputType: 'radio',
Expand Down Expand Up @@ -127,10 +131,16 @@ define( require => {
property.set( value );
} );

// sound generation
const soundPlayer = options.soundPlayer || pushButtonSoundPlayer;
const playSound = () => { soundPlayer.play(); };
this.buttonModel.produceSoundEmitter.addListener( playSound );

// @private
this.disposeRadioButtonGroupMember = function() {
property.unlink( accessibleCheckedListener );
this.firedEmitter.dispose();
this.buttonModel.produceSoundEmitter.removeListener( playSound );
this.buttonModel.dispose();
this.interactionStateProperty.dispose();
};
Expand All @@ -146,6 +156,7 @@ define( require => {
fire: function() {
if ( this.buttonModel.enabledProperty.get() ) {
this.firedEmitter.emit();
this.buttonModel.produceSoundEmitter.emit();
}
},

Expand Down
17 changes: 5 additions & 12 deletions js/buttons/RectangularPushButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ define( require => {

options = merge( {

// {Playable|null} - sound generators, if set to null defaults will be used, set to Playable.NO_SOUND to disable
// {Playable|null} - sound generator, if set to null default will be used, set to Playable.NO_SOUND to disable
soundPlayer: null,

// tandem support
Expand All @@ -54,20 +54,13 @@ define( require => {
// Call the parent type
RectangularButtonView.call( this, this.buttonModel, new PushButtonInteractionStateProperty( this.buttonModel ), options );

// get default sound generator if needed
// sound generation
const soundPlayer = options.soundPlayer || pushButtonSoundPlayer;

// If sound production is enabled, hook it up.
let playSound;
if ( soundPlayer ) {
playSound = () => { soundPlayer.play(); };
this.buttonModel.produceSoundEmitter.addListener( playSound );
}
const playSound = () => { soundPlayer.play(); };
this.buttonModel.produceSoundEmitter.addListener( playSound );

this.disposeRectangularPushButton = function() {
if ( playSound ) {
this.buttonModel.produceSoundEmitter.removeListener( playSound );
}
this.buttonModel.produceSoundEmitter.removeListener( playSound );
this.buttonModel.dispose(); //TODO this fails when assertions are enabled, see sun#212
};

Expand Down
18 changes: 6 additions & 12 deletions js/buttons/RoundPushButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ define( require => {

options = merge( {

// {Playable|null} - sound generators, if set to null defaults will be used, set to Playable.NO_SOUND to disable
// {Playable|null} - sound generator, if set to null defaults will be used, set to Playable.NO_SOUND to disable
soundPlayer: null,

// tandem support
Expand All @@ -56,20 +56,14 @@ define( require => {
// add the listener that was potentially saved above
listener && this.addListener( listener );

// get default sound generator if needed
// sound generation
const soundPlayer = options.soundPlayer || pushButtonSoundPlayer;
const playSound = () => { soundPlayer.play(); };
this.buttonModel.produceSoundEmitter.addListener( playSound );

// If sound production is enabled, hook it up.
let playSound;
if ( soundPlayer ) {
playSound = () => { soundPlayer.play(); };
this.buttonModel.produceSoundEmitter.addListener( playSound );
}

// dispose function
this.disposeRoundPushButton = function() {
if ( playSound ) {
this.buttonModel.produceSoundEmitter.removeListener( playSound );
}
this.buttonModel.produceSoundEmitter.removeListener( playSound );
self.buttonModel.dispose();
};

Expand Down
23 changes: 23 additions & 0 deletions js/buttons/RoundToggleButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ define( require => {
// modules
const inherit = require( 'PHET_CORE/inherit' );
const merge = require( 'PHET_CORE/merge' );
const toggleOffSoundPlayer = require( 'TAMBO/shared-sound-players/toggleOffSoundPlayer' );
const toggleOnSoundPlayer = require( 'TAMBO/shared-sound-players/toggleOnSoundPlayer' );
const RoundButtonView = require( 'SUN/buttons/RoundButtonView' );
const sun = require( 'SUN/sun' );
const Tandem = require( 'TANDEM/Tandem' );
Expand All @@ -30,8 +32,15 @@ define( require => {

// Tandem support
options = merge( {

// {Playable|null} - sounds to be played on toggle transitions, use Playable.NO_SOUND to disable
valueOffSoundPlayer: null,
valueOnSoundPlayer: null,

// phet-io support
tandem: Tandem.required,
phetioType: ToggleButtonIO

}, options );

// @private (read-only)
Expand All @@ -45,9 +54,23 @@ define( require => {
tandem: options.tandem.createTandem( 'property' )
} );

// sound generation
const valueOffSoundPlayer = options.valueOffSoundPlayer || toggleOffSoundPlayer;
const valueOnSoundPlayer = options.valueOnSoundPlayer || toggleOnSoundPlayer;
const playSounds = () => {
if ( property.value === valueOff ) {
valueOffSoundPlayer.play();
}
else if ( property.value === valueOn ) {
valueOnSoundPlayer.play();
}
};
this.buttonModel.produceSoundEmitter.addListener( playSounds );

// @private
this.disposeRoundToggleButton = function() {
this.toggleButtonModel.dispose();
this.buttonModel.produceSoundEmitter.removeListener( playSounds );
toggleButtonInteractionStateProperty.dispose();
};
}
Expand Down
1 change: 1 addition & 0 deletions js/buttons/ToggleButtonModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ define( require => {
// @public
toggle: function() {
this.toggledEmitter.emit();
this.produceSoundEmitter.emit();
}
} );
} );

0 comments on commit 8dab3b7

Please sign in to comment.