Skip to content

Commit

Permalink
Move KeypadPlane to KeypadDialog and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonLi8 committed May 22, 2020
1 parent f89a932 commit bd856e8
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 266 deletions.
1 change: 1 addition & 0 deletions js/common/CollisionLabConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const CollisionLabConstants = {
CHECKBOX_FONT: new PhetFont( 16 ),
DISPLAY_FONT: new PhetFont( 16 ),
PANEL_TITLE_FONT: new PhetFont( { size: 15, weight: 600 } ),
KEYPAD_FONT: new PhetFont( 15 ),

//----------------------------------------------------------------------------------------
// panels
Expand Down
17 changes: 9 additions & 8 deletions js/common/view/BallValuesNumberDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import collisionLab from '../../collisionLab.js';
import collisionLabStrings from '../../collisionLabStrings.js';
import CollisionLabConstants from '../CollisionLabConstants.js';
import Ball from '../model/Ball.js';
import KeypadPlane from './KeypadPlane.js';
import KeypadDialog from './KeypadDialog.js';

// constants
const DISPLAY_RANGE = new Range( -10, 10 ); // Display range for the NumberDisplay (used to determine width).
Expand All @@ -47,13 +47,13 @@ class BallValuesNumberDisplay extends NumberDisplay {
/**
* @param {Ball} ball - the Ball model
* @param {BallQuantities} ballQuantity - the Ball Quantity to display
* @param {KeypadPlane} keypadPlane
* @param {KeypadDialog} keypadDialog
* @param {Object} [options]
*/
constructor( ball, ballQuantity, keypadPlane, options ) {
constructor( ball, ballQuantity, keypadDialog, options ) {
assert && assert( ball instanceof Ball, `invalid Ball: ${ball}` );
assert && assert( BallQuantities.includes( ballQuantity ), `invalid ballQuantity: ${ballQuantity}` );
assert && assert( keypadPlane instanceof KeypadPlane, `invalid keypadPlane: ${keypadPlane}` );
assert && assert( keypadDialog instanceof KeypadDialog, `invalid keypadDialog: ${keypadDialog}` );
assert && assert( !options || Object.getPrototypeOf( options ) === Object.prototype, `invalid options: ${options}` );

// Indicates if the Ball Property can be edited.
Expand Down Expand Up @@ -116,13 +116,14 @@ class BallValuesNumberDisplay extends NumberDisplay {
unit = collisionLabStrings.metersPerSecond;
}

// Create a FireListener that listens to presses and to fire the keypadPlane to allow the user to edit the
// Create a FireListener that listens to presses and to fire the keypadDialog to allow the user to edit the
// ballProperty. Null if canEdit is false. Disposed in the dispose() method.
fireListener = new FireListener( {
fire: () => {
keypadPlane.beginEdit( ballProperty, editRange, unit, {
onBeginEdit: () => { this.backgroundFill = PhetColorScheme.BUTTON_YELLOW; },
onEndEdit: () => { this.backgroundFill = options.backgroundFill; }
this.backgroundFill = PhetColorScheme.BUTTON_YELLOW;

keypadDialog.beginEdit( ballProperty, editRange, unit, () => {
this.backgroundFill = options.backgroundFill;
} );
},
fireOnDown: true
Expand Down
26 changes: 13 additions & 13 deletions js/common/view/BallValuesPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ import collisionLabStrings from '../../collisionLabStrings.js';
import CollisionLabConstants from '../CollisionLabConstants.js';
import Ball from '../model/Ball.js';
import BallValuesPanelColumnNode from './BallValuesPanelColumnNode.js';
import KeypadPlane from './KeypadPlane.js';
import KeypadDialog from './KeypadDialog.js';

class BallValuesPanel extends Panel {

/**
* @param {ObservableArray.<Ball>} balls - collections of particles inside the container
* @param {Property.<boolean>} moreDataVisibleProperty - indicates if the "More Data" checkbox is checked.
* @param {KeypadPlane} keypadPlane
* @param {KeypadDialog} keypadDialog
* @param {Object} [options]
*/
constructor( balls, moreDataVisibleProperty, keypadPlane, options ) {
constructor( balls, moreDataVisibleProperty, keypadDialog, options ) {
assert && assert( balls instanceof ObservableArray && balls.count( ball => ball instanceof Ball ) === balls.length, `invalid balls: ${balls}` );
assert && assert( moreDataVisibleProperty instanceof BooleanProperty, `invalid moreDataVisibleProperty: ${moreDataVisibleProperty}` );
assert && assert( keypadPlane instanceof KeypadPlane, `invalid keypadPlane: ${keypadPlane}` );
assert && assert( keypadDialog instanceof KeypadDialog, `invalid keypadDialog: ${keypadDialog}` );
assert && assert( !options || Object.getPrototypeOf( options ) === Object.prototype, `invalid options: ${options}` );

options = merge( {}, CollisionLabConstants.PANEL_OPTIONS, {
Expand All @@ -72,15 +72,15 @@ class BallValuesPanel extends Panel {
const contentAlignGroup = new AlignGroup( { matchHorizontal: false, matchVertical: true } );

// Create each BallValuesPanelColumnNode for each type of BallValuesPanelColumnNode.ColumnTypes
const ballIconsColumnNode = new BallValuesPanelColumnNode( balls, BallValuesPanelColumnNode.ColumnTypes.BALL_ICONS, contentAlignGroup, labelAlignGroup, keypadPlane );
const massColumnNode = new BallValuesPanelColumnNode( balls, BallValuesPanelColumnNode.ColumnTypes.MASS, contentAlignGroup, labelAlignGroup, keypadPlane );
const xPositionColumnNode = new BallValuesPanelColumnNode( balls, BallValuesPanelColumnNode.ColumnTypes.X_POSITION, contentAlignGroup, labelAlignGroup, keypadPlane );
const yPositionColumnNode = new BallValuesPanelColumnNode( balls, BallValuesPanelColumnNode.ColumnTypes.Y_POSITION, contentAlignGroup, labelAlignGroup, keypadPlane );
const xVelocityColumnNode = new BallValuesPanelColumnNode( balls, BallValuesPanelColumnNode.ColumnTypes.X_VELOCITY, contentAlignGroup, labelAlignGroup, keypadPlane );
const yVelocityColumnNode = new BallValuesPanelColumnNode( balls, BallValuesPanelColumnNode.ColumnTypes.Y_VELOCITY, contentAlignGroup, labelAlignGroup, keypadPlane );
const xMomentumColumnNode = new BallValuesPanelColumnNode( balls, BallValuesPanelColumnNode.ColumnTypes.X_MOMENTUM, contentAlignGroup, labelAlignGroup, keypadPlane );
const yMomentumColumnNode = new BallValuesPanelColumnNode( balls, BallValuesPanelColumnNode.ColumnTypes.Y_MOMENTUM, contentAlignGroup, labelAlignGroup, keypadPlane );
const massSlidersColumnNode = new BallValuesPanelColumnNode( balls, BallValuesPanelColumnNode.ColumnTypes.MASS_SLIDERS, contentAlignGroup, labelAlignGroup, keypadPlane );
const ballIconsColumnNode = new BallValuesPanelColumnNode( balls, BallValuesPanelColumnNode.ColumnTypes.BALL_ICONS, contentAlignGroup, labelAlignGroup, keypadDialog );
const massColumnNode = new BallValuesPanelColumnNode( balls, BallValuesPanelColumnNode.ColumnTypes.MASS, contentAlignGroup, labelAlignGroup, keypadDialog );
const xPositionColumnNode = new BallValuesPanelColumnNode( balls, BallValuesPanelColumnNode.ColumnTypes.X_POSITION, contentAlignGroup, labelAlignGroup, keypadDialog );
const yPositionColumnNode = new BallValuesPanelColumnNode( balls, BallValuesPanelColumnNode.ColumnTypes.Y_POSITION, contentAlignGroup, labelAlignGroup, keypadDialog );
const xVelocityColumnNode = new BallValuesPanelColumnNode( balls, BallValuesPanelColumnNode.ColumnTypes.X_VELOCITY, contentAlignGroup, labelAlignGroup, keypadDialog );
const yVelocityColumnNode = new BallValuesPanelColumnNode( balls, BallValuesPanelColumnNode.ColumnTypes.Y_VELOCITY, contentAlignGroup, labelAlignGroup, keypadDialog );
const xMomentumColumnNode = new BallValuesPanelColumnNode( balls, BallValuesPanelColumnNode.ColumnTypes.X_MOMENTUM, contentAlignGroup, labelAlignGroup, keypadDialog );
const yMomentumColumnNode = new BallValuesPanelColumnNode( balls, BallValuesPanelColumnNode.ColumnTypes.Y_MOMENTUM, contentAlignGroup, labelAlignGroup, keypadDialog );
const massSlidersColumnNode = new BallValuesPanelColumnNode( balls, BallValuesPanelColumnNode.ColumnTypes.MASS_SLIDERS, contentAlignGroup, labelAlignGroup, keypadDialog );

// Horizontally group the components of BallValuesPanelColumnNodes into groups.
const positionColumnGroup = new HBox( {
Expand Down
14 changes: 7 additions & 7 deletions js/common/view/BallValuesPanelColumnNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import Ball from '../model/Ball.js';
import BallMassSlider from './BallMassSlider.js';
import BallValuesNumberDisplay from './BallValuesNumberDisplay.js';
import CollisionLabIconFactory from './CollisionLabIconFactory.js';
import KeypadPlane from './KeypadPlane.js';
import KeypadDialog from './KeypadDialog.js';

// Possible BallValuesPanelColumnNode types. See the comment at the top of this file for context.
const ColumnTypes = Enumeration.byKeys( [
Expand All @@ -58,15 +58,15 @@ class BallValuesPanelColumnNode extends VBox {
* @param {ColumnTypes} columnType - the column-type.
* @param {AlignGroup} contentAlignGroup - AlignGroup for the main content of the column.
* @param {AlignGroup} labelAlignGroup - AlignGroup for the label of the column, even if there is no apparent label.
* @param {KeypadPlane} keypadPlane
* @param {KeypadDialog} keypadDialog
* @param {Object} [options]
*/
constructor( balls, columnType, contentAlignGroup, labelAlignGroup, keypadPlane, options ) {
constructor( balls, columnType, contentAlignGroup, labelAlignGroup, keypadDialog, options ) {
assert && assert( balls instanceof ObservableArray && balls.count( ball => ball instanceof Ball ) === balls.length, `invalid balls: ${balls}` );
assert && assert( ColumnTypes.includes( columnType ), `invalid columnType: ${columnType}` );
assert && assert( contentAlignGroup instanceof AlignGroup, `invalid contentAlignGroup: ${contentAlignGroup}` );
assert && assert( labelAlignGroup instanceof AlignGroup, `invalid labelAlignGroup: ${labelAlignGroup}` );
assert && assert( keypadPlane instanceof KeypadPlane, `invalid keypadPlane: ${keypadPlane}` );
assert && assert( keypadDialog instanceof KeypadDialog, `invalid keypadDialog: ${keypadDialog}` );
assert && assert( !options || Object.getPrototypeOf( options ) === Object.prototype, `invalid options: ${options}` );

options = merge( {
Expand Down Expand Up @@ -100,8 +100,8 @@ class BallValuesPanelColumnNode extends VBox {
// @private {AlignGroup}
this.contentAlignGroup = contentAlignGroup;

// @private {KeypadPlane}
this.keypadPlane = keypadPlane;
// @private {KeypadDialog}
this.keypadDialog = keypadDialog;

// @private {ObservableArray.<Ball>}
this.balls = balls;
Expand Down Expand Up @@ -138,7 +138,7 @@ class BallValuesPanelColumnNode extends VBox {
else {
contentNode = new BallValuesNumberDisplay( ball,
BallValuesNumberDisplay.BallQuantities[ this.columnType.name ], // TODO: find a better way to do this
this.keypadPlane
this.keypadDialog
);
}

Expand Down
5 changes: 2 additions & 3 deletions js/common/view/CollisionLabScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import BallValuesPanel from './BallValuesPanel.js';
import CollisionLabTimeControlNode from './CollisionLabTimeControlNode.js';
import CollisionLabViewProperties from './CollisionLabViewProperties.js';
import ControlPanelCheckbox from './ControlPanelCheckbox.js';
import KeypadPlane from './KeypadPlane.js';
import KeypadDialog from './KeypadDialog.js';
import PlayAreaControlPanel from './PlayAreaControlPanel.js';
import PlayAreaNode from './PlayAreaNode.js';
import RestartButton from './RestartButton.js';
Expand Down Expand Up @@ -179,13 +179,12 @@ class CollisionLabScreenView extends ScreenView {
moreDataCheckbox.top = playAreaNode.bottom + 30;


const keypad = new KeypadPlane();
const keypad = new KeypadDialog();

const ballValuesDisplay = new BallValuesPanel( model.playArea.balls, viewProperties.moreDataVisibleProperty, keypad );
this.addChild( ballValuesDisplay );
ballValuesDisplay.top = collisionLabTimeControlNode.bottom + 10;
ballValuesDisplay.left = 40;
this.addChild( keypad );
}

// @public
Expand Down
Loading

1 comment on commit bd856e8

@brandonLi8
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to tag #60, #27.

Please sign in to comment.