Skip to content

Commit

Permalink
Add a second gate for visibility for the reverse battery button, see #…
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Feb 7, 2023
1 parent 0f7e071 commit e6c663f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
13 changes: 0 additions & 13 deletions js/view/BatteryReverseButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import circuitConstructionKitCommon from '../circuitConstructionKitCommon.js';
import Battery from '../model/Battery.js';
import CCKCRoundPushButton from './CCKCRoundPushButton.js';
import Circuit from '../model/Circuit.js';
import CircuitElement from '../model/CircuitElement.js';
import Vertex from '../model/Vertex.js';
import { RoundPushButtonOptions } from '../../../sun/js/buttons/RoundPushButton.js';
import optionize, { EmptySelfOptions } from '../../../phet-core/js/optionize.js';

Expand Down Expand Up @@ -78,17 +76,6 @@ export default class BatteryReverseButton extends CCKCRoundPushButton {
}
}, providedOptions );
super( options );

const isReversibleListener = ( isReversible: boolean ) => {
this.visible = isReversible;
};

// This is reused across all batteries. The button itself can be hidden by PhET-iO customization, but the parent
// node is another gate for the visibility.
circuit.selectionProperty.link( ( newCircuitElement: CircuitElement | Vertex | null, oldCircuitElement: CircuitElement | Vertex | null ) => {
oldCircuitElement instanceof Battery && oldCircuitElement.isReversibleProperty.unlink( isReversibleListener );
newCircuitElement instanceof Battery && newCircuitElement.isReversibleProperty.link( isReversibleListener );
} );
}

public override dispose(): void {
Expand Down
20 changes: 16 additions & 4 deletions js/view/CircuitElementEditContainerNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ export default class CircuitElementEditContainerNode extends Node {
children: [ fuseRepairButton ]
} );

const isRepairableListener = ( isRepairable: boolean ) => {
fuseRepairButtonContainer.visible = isRepairable;
};
const isRepairableListener = ( isRepairable: boolean ) => fuseRepairButtonContainer.setVisible( isRepairable );

// This is reused across all instances. The button itself can be hidden by PhET-iO customization, but the parent
// node is another gate for the visibility.
Expand All @@ -166,6 +164,20 @@ export default class CircuitElementEditContainerNode extends Node {
maxHeight: trashButton.height
} );

// This is reused across all batteries. The button itself can be hidden by PhET-iO customization, but the parent
// node is another gate for the visibility.
const batteryReverseContainerNode = new Node( {
excludeInvisibleChildrenFromBounds: true,
children: [ batteryReverseButton ]
} );

const isReversibleListener = ( isReversible: boolean ) => batteryReverseContainerNode.setVisible( isReversible );

circuit.selectionProperty.link( ( newCircuitElement: CircuitElement | Vertex | null, oldCircuitElement: CircuitElement | Vertex | null ) => {
oldCircuitElement instanceof Battery && oldCircuitElement.isReversibleProperty.unlink( isReversibleListener );
newCircuitElement instanceof Battery && newCircuitElement.isReversibleProperty.link( isReversibleListener );
} );

const switchReadoutNode = new SwitchReadoutNode( circuit, tandem.createTandem( 'switchReadoutNode' ) );

const listener = ( isDisposable: boolean ) => trashButtonContainer.setVisible( isDisposable );
Expand Down Expand Up @@ -392,7 +404,7 @@ export default class CircuitElementEditContainerNode extends Node {

// Batteries can be reversed, nest in a Node so the layout will reflow correctly
new Node( {
children: [ batteryReverseButton ],
children: [ batteryReverseContainerNode ],
excludeInvisibleChildrenFromBounds: true
} ),
selectedCircuitElement.batteryType === 'high-voltage' ? extremeBatteryVoltageNumberControl : voltageNumberControl,
Expand Down

0 comments on commit e6c663f

Please sign in to comment.