-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prototype FaucetControlsKeyboardHelpContent, #249
- Loading branch information
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2022, University of Colorado Boulder | ||
|
||
//TODO https://github.com/phetsims/scenery-phet/issues/773 move to scenery-phet | ||
/** | ||
* FaucetControlsKeyboardHelpContent is the keyboard-help section that describes how to interact with FaucetNode. | ||
* | ||
* @author Chris Malley (PixelZoom, Inc.) | ||
*/ | ||
|
||
import StringProperty from '../../../../axon/js/StringProperty.js'; | ||
import optionize from '../../../../phet-core/js/optionize.js'; | ||
import PickOptional from '../../../../phet-core/js/types/PickOptional.js'; | ||
import { FaucetNodeOptions } from '../../../../scenery-phet/js/FaucetNode.js'; | ||
import KeyboardHelpIconFactory from '../../../../scenery-phet/js/keyboard/help/KeyboardHelpIconFactory.js'; | ||
import KeyboardHelpSection, { KeyboardHelpSectionOptions } from '../../../../scenery-phet/js/keyboard/help/KeyboardHelpSection.js'; | ||
import KeyboardHelpSectionRow from '../../../../scenery-phet/js/keyboard/help/KeyboardHelpSectionRow.js'; | ||
import TextKeyNode from '../../../../scenery-phet/js/keyboard/TextKeyNode.js'; | ||
import phScale from '../../phScale.js'; | ||
|
||
//TODO https://github.com/phetsims/scenery-phet/issues/773 i18n, add to scenery-phet-strings_en.json | ||
const faucetControlsStringProperty = new StringProperty( 'Faucet Controls' ); | ||
const openCloseStringProperty = new StringProperty( 'Open/close' ); | ||
const openCloseSlowerStringProperty = new StringProperty( 'Open/close slower' ); | ||
const dispenseASmallAmountStringProperty = new StringProperty( 'Dispense a small amount' ); | ||
|
||
type SelfOptions = PickOptional<FaucetNodeOptions, 'tapToDispenseEnabled'>; | ||
|
||
export type FaucetControlsKeyboardHelpContentOptions = SelfOptions & KeyboardHelpSectionOptions; | ||
|
||
export default class FaucetControlsKeyboardHelpContent extends KeyboardHelpSection { | ||
|
||
public constructor( providedOptions?: FaucetControlsKeyboardHelpContentOptions ) { | ||
|
||
const options = optionize<FaucetControlsKeyboardHelpContentOptions, SelfOptions, KeyboardHelpSectionOptions>()( { | ||
|
||
// SelfOptions | ||
tapToDispenseEnabled: true | ||
}, providedOptions ); | ||
|
||
// arrows or WASD | ||
const normalRow = KeyboardHelpSectionRow.labelWithIcon( openCloseStringProperty, | ||
KeyboardHelpIconFactory.arrowOrWasdKeysRowIcon() ); | ||
|
||
// Shift+arrows or Shift+WASD | ||
const slowerRow = KeyboardHelpSectionRow.labelWithIconList( openCloseSlowerStringProperty, [ | ||
KeyboardHelpIconFactory.shiftPlusIcon( KeyboardHelpIconFactory.arrowKeysRowIcon() ), | ||
KeyboardHelpIconFactory.shiftPlusIcon( KeyboardHelpIconFactory.wasdRowIcon() ) | ||
] ); | ||
|
||
const rows = [ normalRow, slowerRow ]; | ||
|
||
// Space or Enter | ||
if ( options.tapToDispenseEnabled ) { | ||
|
||
const dispenseRow = KeyboardHelpSectionRow.labelWithIcon( | ||
dispenseASmallAmountStringProperty, | ||
KeyboardHelpIconFactory.iconOrIcon( TextKeyNode.space(), TextKeyNode.enter() ) | ||
); | ||
rows.push( dispenseRow ); | ||
} | ||
|
||
super( faucetControlsStringProperty, rows ); | ||
} | ||
} | ||
|
||
phScale.register( 'FaucetControlsKeyboardHelpContent', FaucetControlsKeyboardHelpContent ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters