<commit_before>// Copyright 2002-2013, University of Colorado Boulder

/**
 * Scoreboard for a game.
 *
 * @author <NAME> (PixelZoom, Inc.)
 */
define( function( require ) {
  'use strict';

  // modules
  var Color = require( 'SCENERY/util/Color' );
  var GameTimer = require( 'VEGAS/GameTimer' );
  var inherit = require( 'PHET_CORE/inherit' );
  var Line = require( 'SCENERY/nodes/Line' );
  var Node = require( 'SCENERY/nodes/Node' );
  var Panel = require( 'SUN/Panel' );
  var PhetFont = require( 'SCENERY_PHET/PhetFont' );
  var SimpleClockIcon = require( 'SCENERY_PHET/SimpleClockIcon' );
  var StringUtils = require( 'PHETCOMMON/util/StringUtils' );
  var Text = require( 'SCENERY/nodes/Text' );
  var TextPushButton = require( 'SUN/buttons/TextPushButton' );

  // strings
  var startOverString = require( 'string!VEGAS/startOver' );
  var pattern_0level = require( 'string!VEGAS/label.level' );
  var pattern_0score = require( 'string!VEGAS/label.score' );
  var pattern_0challenge_1max = require( 'string!VEGAS/pattern.0challenge.1max' );

  /**
   * @param {Property.<number>} challengeIndexProperty which challenge is the user current playing? (index starts at 0, displayed starting at 1)
   * @param {Property.<number>} challengesPerGameProperty how many challenges are in the current game
   * @param {Property.<number>} levelProperty
   * @param {Property.<number>} scoreProperty
   * @param {Property.<number>} elapsedTimeProperty elapsed time in seconds
   * @param {Property.<number>} timerEnabledProperty is the timer enabled?
   * @param {function} startOverCallback
   * @param {Object} [options]
   * @constructor
   */
  function ScoreboardPanel( challengeIndexProperty, challengesPerGameProperty, levelProperty, scoreProperty, elapsedTimeProperty, timerEnabledProperty, startOverCallback, options ) {

    var thisNode = this;

    options = _.extend( {
      // things that can be hidden
      levelVisible: true,
      challengeNumberVisible: true,
      // all text
      font: new PhetFont( 20 ),
      // "Start Over" button
      startOverButtonText: startOverString,
      startOverButtonBaseColor: new Color( 229, 243, 255 ),
      startOverButtonXMargin: 10,
      startOverButtonYMargin: 5,
      // Timer
      clockIconRadius: 15,
      // Panel
      minWidth: 0,
      xSpacing: 40,
      xMargin: 20,
      yMargin: 10,
      fill: 'rgb( 180, 205, 255 )',
      stroke: 'black',
      lineWidth: 1,

      // Together.js
      startOverButtonComponentID: null
    }, options );

    // Level
    var levelNode = new Text( '', { font: options.font, pickable: false } );
    levelProperty.link( function( level ) {
      levelNode.text = StringUtils.format( pattern_0level, level + 1 );
    } );

    // Challenge number
    var challengeNumberNode = new Text( '', { font: options.font, pickable: false } );
    challengeIndexProperty.link( function( challengeIndex ) {
      challengeNumberNode.text = StringUtils.format( pattern_0challenge_1max, challengeIndex + 1, challengesPerGameProperty.get() );
    } );

    // Score
    var scoreNode = new Text( '', { font: options.font, pickable: false } );
    scoreProperty.link( function( score ) {
      scoreNode.text = StringUtils.format( pattern_0score, score );
    } );

    // Timer, always takes up space even when hidden.
    var timerNode = new Node( { pickable: false } );
    var clockIcon = new SimpleClockIcon( options.clockIconRadius );
    var timeValue = new Text( '', { font: options.font } );
    timerNode.addChild( clockIcon );
    timerNode.addChild( timeValue );
    timeValue.left = clockIcon.right + 8;
    timeValue.centerY = clockIcon.centerY;
    elapsedTimeProperty.link( function( elapsedTime ) {
      timeValue.text = GameTimer.formatTime( elapsedTime );
    } );
    timerEnabledProperty.link( function( timerEnabled ) {
      timerNode.visible = timerEnabled;
    } );

    // Start Over button
    var startOverButton = new TextPushButton( options.startOverButtonText, {
      listener: startOverCallback,
      font: options.font,
      baseColor: options.startOverButtonBaseColor,
      xMargin: options.startOverButtonXMargin,
      yMargin: options.startOverButtonYMargin,
      componentID: options.startOverButtonComponentID
    } );

    // Content for the panel, one row.
    var subContent = new Node();
    var nodes = [ levelNode, challengeNumberNode, scoreNode, timerNode, startOverButton ];
    if ( !options.levelVisible ) { nodes.splice( nodes.indexOf( levelNode ), 1 ); }
    if ( !options.challengeNumberVisible ) { nodes.splice( nodes.indexOf( challengeNumberNode ), 1 ); }
    for ( var i = 0; i < nodes.length; i++ ) {
      subContent.addChild( nodes[ i ] );
      if ( i > 0 ) {
        nodes[ i ].left = nodes[ i - 1 ].right + options.xSpacing;
        nodes[ i ].centerY = nodes[ i - 1 ].centerY;
      }
    }

    //TODO sun.Panel should support this, instead of having to do it here
    // ensure a minimum width, horizontally center the content.
    var content = subContent;
    if ( subContent.width < options.minWidth ) {
      content = new Node();
      var strut = new Line( 0, 0, options.minWidth, 0, { pickable: false } ); // horizontal strut
      content.addChild( strut );
      content.addChild( subContent );
      subContent.centerX = strut.centerX;
    }

    Panel.call( thisNode, content, options );<commit_msg>#24 ScoreboardPanel: use Panel option.minWidth instead of a strut (no clients of this option yet)<commit_after>// Copyright 2002-2013, University of Colorado Boulder

/**
 * Scoreboard for a game.
 *
 * @author <NAME> (PixelZoom, Inc.)
 */
define( function( require ) {
  'use strict';

  // modules
  var Color = require( 'SCENERY/util/Color' );
  var GameTimer = require( 'VEGAS/GameTimer' );
  var inherit = require( 'PHET_CORE/inherit' );
  var Node = require( 'SCENERY/nodes/Node' );
  var Panel = require( 'SUN/Panel' );
  var PhetFont = require( 'SCENERY_PHET/PhetFont' );
  var SimpleClockIcon = require( 'SCENERY_PHET/SimpleClockIcon' );
  var StringUtils = require( 'PHETCOMMON/util/StringUtils' );
  var Text = require( 'SCENERY/nodes/Text' );
  var TextPushButton = require( 'SUN/buttons/TextPushButton' );

  // strings
  var startOverString = require( 'string!VEGAS/startOver' );
  var pattern_0level = require( 'string!VEGAS/label.level' );
  var pattern_0score = require( 'string!VEGAS/label.score' );
  var pattern_0challenge_1max = require( 'string!VEGAS/pattern.0challenge.1max' );

  /**
   * @param {Property.<number>} challengeIndexProperty which challenge is the user current playing? (index starts at 0, displayed starting at 1)
   * @param {Property.<number>} challengesPerGameProperty how many challenges are in the current game
   * @param {Property.<number>} levelProperty
   * @param {Property.<number>} scoreProperty
   * @param {Property.<number>} elapsedTimeProperty elapsed time in seconds
   * @param {Property.<number>} timerEnabledProperty is the timer enabled?
   * @param {function} startOverCallback
   * @param {Object} [options]
   * @constructor
   */
  function ScoreboardPanel( challengeIndexProperty, challengesPerGameProperty, levelProperty, scoreProperty, elapsedTimeProperty, timerEnabledProperty, startOverCallback, options ) {

    var thisNode = this;

    options = _.extend( {
      // things that can be hidden
      levelVisible: true,
      challengeNumberVisible: true,
      // all text
      font: new PhetFont( 20 ),
      // "Start Over" button
      startOverButtonText: startOverString,
      startOverButtonBaseColor: new Color( 229, 243, 255 ),
      startOverButtonXMargin: 10,
      startOverButtonYMargin: 5,
      // Timer
      clockIconRadius: 15,
      // Panel
      minWidth: 0,
      xSpacing: 40,
      xMargin: 20,
      yMargin: 10,
      fill: 'rgb( 180, 205, 255 )',
      stroke: 'black',
      lineWidth: 1,
      align: 'center',

      // Together.js
      startOverButtonComponentID: null
    }, options );

    // Level
    var levelNode = new Text( '', { font: options.font, pickable: false } );
    levelProperty.link( function( level ) {
      levelNode.text = StringUtils.format( pattern_0level, level + 1 );
    } );

    // Challenge number
    var challengeNumberNode = new Text( '', { font: options.font, pickable: false } );
    challengeIndexProperty.link( function( challengeIndex ) {
      challengeNumberNode.text = StringUtils.format( pattern_0challenge_1max, challengeIndex + 1, challengesPerGameProperty.get() );
    } );

    // Score
    var scoreNode = new Text( '', { font: options.font, pickable: false } );
    scoreProperty.link( function( score ) {
      scoreNode.text = StringUtils.format( pattern_0score, score );
    } );

    // Timer, always takes up space even when hidden.
    var timerNode = new Node( { pickable: false } );
    var clockIcon = new SimpleClockIcon( options.clockIconRadius );
    var timeValue = new Text( '', { font: options.font } );
    timerNode.addChild( clockIcon );
    timerNode.addChild( timeValue );
    timeValue.left = clockIcon.right + 8;
    timeValue.centerY = clockIcon.centerY;
    elapsedTimeProperty.link( function( elapsedTime ) {
      timeValue.text = GameTimer.formatTime( elapsedTime );
    } );
    timerEnabledProperty.link( function( timerEnabled ) {
      timerNode.visible = timerEnabled;
    } );

    // Start Over button
    var startOverButton = new TextPushButton( options.startOverButtonText, {
      listener: startOverCallback,
      font: options.font,
      baseColor: options.startOverButtonBaseColor,
      xMargin: options.startOverButtonXMargin,
      yMargin: options.startOverButtonYMargin,
      componentID: options.startOverButtonComponentID
    } );

    // Content for the panel, one row.
    var content = new Node();
    var nodes = [ levelNode, challengeNumberNode, scoreNode, timerNode, startOverButton ];
    if ( !options.levelVisible ) { nodes.splice( nodes.indexOf( levelNode ), 1 ); }
    if ( !options.challengeNumberVisible ) { nodes.splice( nodes.indexOf( challengeNumberNode ), 1 ); }
    for ( var i = 0; i < nodes.length; i++ ) {
      content.addChild( nodes[ i ] );
      if ( i > 0 ) {
        nodes[ i ].left = nodes[ i - 1 ].right + options.xSpacing;
        nodes[ i ].centerY = nodes[ i - 1 ].centerY;
      }
    }

    Panel.call( thisNode, content, options );
{'fraction_non_alphanumeric': 0.11673753382296095, 'fraction_numerical': 0.01246617703904136, 'mean_word_length': 3.2361850184199756, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '196697', 'n_tokens_mistral': 3190, 'n_tokens_neox': 3029, 'n_words': 831}