From af3630370860666b0cc34b684f687d60f7442a6c Mon Sep 17 00:00:00 2001 From: matthew-blackman Date: Sun, 19 Nov 2023 17:07:27 -0500 Subject: [PATCH] Add launcher to screen view - see https://github.com/phetsims/projectile-data-lab/issues/7 --- js/common/view/PDLScreenView.ts | 39 +++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/js/common/view/PDLScreenView.ts b/js/common/view/PDLScreenView.ts index 58e17bac..2e53694a 100644 --- a/js/common/view/PDLScreenView.ts +++ b/js/common/view/PDLScreenView.ts @@ -19,6 +19,7 @@ import GradientBackgroundNode from '../../../../scenery-phet/js/GradientBackgrou import FieldNode from './FieldNode.js'; import ProjectileDataLabModel from '../model/ProjectileDataLabModel.js'; import FieldOverlayNode from './FieldOverlayNode.js'; +import LauncherNode from './LauncherNode.js'; type SelfOptions = EmptySelfOptions; type PDLScreenViewOptions = SelfOptions & ScreenViewOptions; @@ -26,13 +27,21 @@ type PDLScreenViewOptions = SelfOptions & ScreenViewOptions; export class PDLScreenView extends ScreenView { protected readonly resetAllButton: ResetAllButton; private readonly field: FieldNode; + private readonly launcher: LauncherNode; public constructor( model: ProjectileDataLabModel, options: PDLScreenViewOptions ) { super( options ); - const backgroundNode = new GradientBackgroundNode( 0, 0, 1, 1, - ProjectileDataLabColors.screenBackgroundTopColorProperty, ProjectileDataLabColors.screenBackgroundBottomColorProperty, - 0, 1 ); + const backgroundNode = new GradientBackgroundNode( + 0, + 0, + 1, + 1, + ProjectileDataLabColors.screenBackgroundTopColorProperty, + ProjectileDataLabColors.screenBackgroundBottomColorProperty, + 0, + 1 + ); // This instance lives for the lifetime of the simulation, so we don't need to remove this listener this.visibleBoundsProperty.link( visibleBounds => { @@ -66,15 +75,31 @@ export class PDLScreenView extends ScreenView { this.field = new FieldNode( fieldX, fieldY, model.binWidthProperty, {} ); const fieldOverlayNode = new FieldOverlayNode( fieldX, fieldY, {} ); + // Create the launcher + const originX = fieldX - 0.5 * ProjectileDataLabConstants.FIELD_WIDTH; + this.launcher = new LauncherNode( + originX, + fieldY, + model.launcherAngleProperty, + model.launcherHeightProperty, + model.launcherTypeProperty, + {} + ); + this.addChild( this.field ); + this.addChild( this.launcher ); this.addChild( fieldOverlayNode ); // layout - ManualConstraint.create( this, [ noAirResistanceText, this.resetAllButton ], + ManualConstraint.create( + this, + [ noAirResistanceText, this.resetAllButton ], ( noAirResistanceTextProxy, resetAllButtonProxy ) => { - noAirResistanceTextProxy.right = resetAllButtonProxy.left - ProjectileDataLabConstants.SCREEN_VIEW_X_MARGIN; + noAirResistanceTextProxy.right = + resetAllButtonProxy.left - ProjectileDataLabConstants.SCREEN_VIEW_X_MARGIN; noAirResistanceTextProxy.bottom = resetAllButtonProxy.bottom; - } ); + } + ); } /** @@ -94,4 +119,4 @@ export class PDLScreenView extends ScreenView { } } -projectileDataLab.register( 'PDLScreenView', PDLScreenView ); \ No newline at end of file +projectileDataLab.register( 'PDLScreenView', PDLScreenView );