Skip to content

Commit

Permalink
restore default z-order on reset all and reset balloons, see #535
Browse files Browse the repository at this point in the history
(cherry picked from commit de7524a)
  • Loading branch information
jbphet committed Sep 13, 2021
1 parent dfba97f commit 37845dc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
35 changes: 25 additions & 10 deletions js/balloons-and-static-electricity/view/BASEView.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class BASEView extends ScreenView {
{ fill: 'black', tandem: tandem.createTandem( 'spaceToLeftOfWall' ) }
) );

const controlPanel = new ControlPanel( model, this.layoutBounds, tandem.createTandem( 'controlPanel' ) );
const controlPanel = new ControlPanel( model, this, tandem.createTandem( 'controlPanel' ) );

// @private - sound generator for the deflection of the charges in the wall, never disposed
this.chargeDeflectionSoundGenerator = new ChargeDeflectionSoundGenerator(
Expand Down Expand Up @@ -154,11 +154,13 @@ class BASEView extends ScreenView {
const screenSummaryNode = new BASESummaryNode( model, this.yellowBalloonNode, this.greenBalloonNode, this.wallNode, tandem.createTandem( 'screenSummaryNode' ) );
this.setScreenSummaryContent( screenSummaryNode );

// combine the balloon content into single nodes so that they are easily layerable
const greenBalloonLayerNode = new Node( { children: [ this.greenBalloonTetherNode, this.greenBalloonNode ] } );
const yellowBalloonLayerNode = new Node( { children: [ this.yellowBalloonTetherNode, this.yellowBalloonNode ] } );
this.addChild( yellowBalloonLayerNode );
this.addChild( greenBalloonLayerNode );
// @private {Node} - layer on which the green balloon resides.
this.greenBalloonLayerNode = new Node( { children: [ this.greenBalloonTetherNode, this.greenBalloonNode ] } );
this.addChild( this.greenBalloonLayerNode );

// @private {Node} - layer on which the yellow balloon resides.
this.yellowBalloonLayerNode = new Node( { children: [ this.yellowBalloonTetherNode, this.yellowBalloonNode ] } );
this.addChild( this.yellowBalloonLayerNode );

// Only show the selected balloon(s)
model.greenBalloon.isVisibleProperty.link( isVisible => {
Expand All @@ -168,18 +170,23 @@ class BASEView extends ScreenView {

this.addChild( controlPanel );

// when one of the balloons is picked up, move its content and cue nodes to front
// When one of the balloons is picked up, move its content and cue nodes to the front.
Property.multilink( [ model.yellowBalloon.isDraggedProperty, model.greenBalloon.isDraggedProperty ], ( yellowDragged, greenDragged ) => {
if ( yellowDragged ) {
yellowBalloonLayerNode.moveToFront();
this.yellowBalloonLayerNode.moveToFront();
}
else if ( greenDragged ) {
greenBalloonLayerNode.moveToFront();
this.greenBalloonLayerNode.moveToFront();
}
} );

// pdom - assign components to the appropriate sections and specify order
this.pdomPlayAreaNode.pdomOrder = [ sweaterNode, yellowBalloonLayerNode, greenBalloonLayerNode, this.wallNode ];
this.pdomPlayAreaNode.pdomOrder = [
sweaterNode,
this.yellowBalloonLayerNode,
this.greenBalloonLayerNode,
this.wallNode
];
this.pdomControlAreaNode.pdomOrder = [ controlPanel ];

//--------------------------------------------------------------------------
Expand All @@ -202,6 +209,14 @@ class BASEView extends ScreenView {
this.yellowBalloonNode.step( dt );
}

/**
* Set the default layering of the balloons, generally used to restore initial view state.
* @public
*/
setDefaultBalloonZOrder() {
this.greenBalloonLayerNode.moveToFront();
}

/**
* Custom layout function for this view. It is most natural for this simulation for the view to
* be held on the bottom of the navigation bar so that the balloon's tether and wall are always cut
Expand Down
14 changes: 11 additions & 3 deletions js/balloons-and-static-electricity/view/ControlPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ class ControlPanel extends Node {

/**
* @param {BASEModel} model
* @param {Bounds2} layoutBounds
* @param {BASEView} view
* @param {Tandem} tandem
*/
constructor( model, layoutBounds, tandem ) {
constructor( model, view, tandem ) {

// super constructor
super();
Expand Down Expand Up @@ -231,6 +231,9 @@ class ControlPanel extends Node {
balloon.reset( true );
} );

// Make sure the balloons are correctly layered in the view.
view.setDefaultBalloonZOrder();

this.forEachUtteranceQueue( utteranceQueue => { utteranceQueue.enabled = true; } );

// alert to assistive technology
Expand Down Expand Up @@ -277,7 +280,10 @@ class ControlPanel extends Node {

//Add the controls at the right, with the reset all button and the wall button
const resetAllButton = new ResetAllButton( {
listener: model.reset.bind( model ),
listener: () => {
model.reset();
view.setDefaultBalloonZOrder();
},
scale: 0.96,
tandem: tandem.createTandem( 'resetAllButton' )
} );
Expand All @@ -288,6 +294,8 @@ class ControlPanel extends Node {
children: [ resetAllButton, this.wallButton ]
} );

const layoutBounds = view.layoutBounds;

// more than other controls so the reset button touch area doesn't overlap the nav bar
controls.bottom = layoutBounds.maxY - BOTTOM_CONTROL_SPACING;
controls.right = layoutBounds.maxX - 4.5;// so "Remove Wall" button looks centered with wall
Expand Down

0 comments on commit 37845dc

Please sign in to comment.