From 242dd71b1638193cce6a62b3763891b3002e5ce7 Mon Sep 17 00:00:00 2001 From: Michael Kauzmann Date: Fri, 25 Aug 2023 16:31:53 -0600 Subject: [PATCH] reset a couple more things on the second screen, https://github.com/phetsims/build-a-nucleus/issues/167 --- js/chart-intro/model/ChartIntroModel.ts | 2 + js/chart-intro/model/DecayEquationModel.ts | 6 +++ js/chart-intro/view/ChartIntroScreenView.ts | 41 +++++++++++++-------- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/js/chart-intro/model/ChartIntroModel.ts b/js/chart-intro/model/ChartIntroModel.ts index 190106d..1494797 100644 --- a/js/chart-intro/model/ChartIntroModel.ts +++ b/js/chart-intro/model/ChartIntroModel.ts @@ -98,6 +98,8 @@ class ChartIntroModel extends BANModel { } } ); super.reset(); + this.selectedNuclideChartProperty.reset(); + this.decayEquationModel.reset(); // Put this last to make sure that this.particleAtom can be cleared first (by supertype). this.miniParticleAtom.clear(); diff --git a/js/chart-intro/model/DecayEquationModel.ts b/js/chart-intro/model/DecayEquationModel.ts index 2820bc6..41e7fec 100644 --- a/js/chart-intro/model/DecayEquationModel.ts +++ b/js/chart-intro/model/DecayEquationModel.ts @@ -60,6 +60,12 @@ class DecayEquationModel { private getCurrentCellModel( cellModelArray: NuclideChartCellModel[][], protonNumber: number, massNumber: number ): NuclideChartCellModel | null { return _.find( cellModelArray[ protonNumber ], cellModel => cellModel.neutronNumber === massNumber - protonNumber ) || null; } + + public reset(): void { + this.currentCellModelProperty.reset(); + this.finalProtonNumberProperty.reset(); + this.finalMassNumberProperty.reset(); + } } buildANucleus.register( 'DecayEquationModel', DecayEquationModel ); diff --git a/js/chart-intro/view/ChartIntroScreenView.ts b/js/chart-intro/view/ChartIntroScreenView.ts index 8c2e9b0..ed25946 100644 --- a/js/chart-intro/view/ChartIntroScreenView.ts +++ b/js/chart-intro/view/ChartIntroScreenView.ts @@ -38,6 +38,7 @@ import AlphaParticle from '../../common/model/AlphaParticle.js'; import BANQueryParameters from '../../common/BANQueryParameters.js'; import TinyProperty from '../../../../axon/js/TinyProperty.js'; import NuclearShellModelText from './NuclearShellModelText.js'; +import Property from '../../../../axon/js/Property.js'; // types export type NuclideChartIntroScreenViewOptions = BANScreenViewOptions; @@ -59,6 +60,8 @@ class ChartIntroScreenView extends BANScreenView { // positions and sizes particles in the miniParticleAtom private readonly miniAtomMVT: ModelViewTransform2; + private readonly showMagicNumbersProperty: Property; + private readonly nuclideChartAccordionBox: NuclideChartAccordionBox; public constructor( model: ChartIntroModel, providedOptions?: NuclideChartIntroScreenViewOptions ) { @@ -188,41 +191,41 @@ class ChartIntroScreenView extends BANScreenView { this.addChild( rightDashedLine ); // Whether to show a special highlight for magic-numbered nuclides in the charts - const showMagicNumbersProperty = new BooleanProperty( false ); + this.showMagicNumbersProperty = new BooleanProperty( false ); // create the nuclideChartAccordionBox - const nuclideChartAccordionBox = new NuclideChartAccordionBox( + this.nuclideChartAccordionBox = new NuclideChartAccordionBox( this.model.particleAtom.protonCountProperty, this.model.particleAtom.neutronCountProperty, this.model.selectedNuclideChartProperty, this.model.decayEquationModel, - this.decayAtom.bind( this ), showMagicNumbersProperty, this.model.hasIncomingParticlesProperty, { + this.decayAtom.bind( this ), this.showMagicNumbersProperty, this.model.hasIncomingParticlesProperty, { minWidth: periodicTableAndIsotopeSymbol.width } ); // position and add the nuclideChartAccordionBox - nuclideChartAccordionBox.top = periodicTableAndIsotopeSymbol.bottom + CHART_VERTICAL_MARGINS; - nuclideChartAccordionBox.left = periodicTableAndIsotopeSymbol.left; - this.addChild( nuclideChartAccordionBox ); + this.nuclideChartAccordionBox.top = periodicTableAndIsotopeSymbol.bottom + CHART_VERTICAL_MARGINS; + this.nuclideChartAccordionBox.left = periodicTableAndIsotopeSymbol.left; + this.addChild( this.nuclideChartAccordionBox ); // create and add the radio buttons that select the chart type view in the nuclideChartAccordionBox - const partialChartRadioButton = new RectangularRadioButtonGroup( + const partialChartRadioButtonGroup = new RectangularRadioButtonGroup( this.model.selectedNuclideChartProperty, [ { value: 'partial', createNode: () => new CompleteNuclideChartIconNode() }, { value: 'zoom', createNode: () => new ZoomInNuclideChartIconNode() } ], { - left: nuclideChartAccordionBox.left, - top: nuclideChartAccordionBox.bottom + CHART_VERTICAL_MARGINS, + left: this.nuclideChartAccordionBox.left, + top: this.nuclideChartAccordionBox.bottom + CHART_VERTICAL_MARGINS, orientation: 'horizontal', radioButtonOptions: { baseColor: BANColors.chartRadioButtonsBackgroundColorProperty } } ); - this.addChild( partialChartRadioButton ); + this.addChild( partialChartRadioButtonGroup ); // create and add the checkbox to show special highlight for magic-numbered nuclides in the charts - const showMagicNumbersCheckbox = new Checkbox( showMagicNumbersProperty, + const showMagicNumbersCheckbox = new Checkbox( this.showMagicNumbersProperty, new Text( BuildANucleusStrings.magicNumbersStringProperty, { font: BANConstants.LEGEND_FONT, maxWidth: 145 } ), { boxWidth: 15, touchAreaYDilation: 4 } ); - showMagicNumbersCheckbox.left = partialChartRadioButton.right + CHART_VERTICAL_MARGINS; - showMagicNumbersCheckbox.top = nuclideChartAccordionBox.bottom + CHART_VERTICAL_MARGINS; + showMagicNumbersCheckbox.left = partialChartRadioButtonGroup.right + CHART_VERTICAL_MARGINS; + showMagicNumbersCheckbox.top = this.nuclideChartAccordionBox.bottom + CHART_VERTICAL_MARGINS; this.addChild( showMagicNumbersCheckbox ); // create and add the fullChartDialog and 'Full Chart' button @@ -239,7 +242,7 @@ class ChartIntroScreenView extends BANScreenView { listener: () => fullChartDialog.show() } ); fullChartTextButton.left = showMagicNumbersCheckbox.left; - fullChartTextButton.bottom = partialChartRadioButton.bottom; + fullChartTextButton.bottom = partialChartRadioButtonGroup.bottom; this.addChild( fullChartTextButton ); // add the particleView layer nodes after everything else so particles are in the top layer @@ -247,8 +250,8 @@ class ChartIntroScreenView extends BANScreenView { this.addChild( this.energyLevelLayer ); this.pdomPlayAreaNode.pdomOrder = this.pdomPlayAreaNode.pdomOrder!.concat( [ - nuclideChartAccordionBox, - partialChartRadioButton, + this.nuclideChartAccordionBox, + partialChartRadioButtonGroup, showMagicNumbersCheckbox, fullChartTextButton ] ); @@ -258,6 +261,12 @@ class ChartIntroScreenView extends BANScreenView { } ); } + protected override reset(): void { + this.showMagicNumbersProperty.reset(); + this.nuclideChartAccordionBox.reset(); + super.reset(); + } + /** * Returns whether the nucleon is within a rectangular capture radius defined by the left edge of the proton arrow * buttons, the right edge of the neutron arrow buttons, below the periodic table, and above the arrow buttons.