Exemplo n.º 1
0
/* Returns an OPT mask. */
int ScreenOptionsMaster::ExportOption( const OptionRowData &row, const OptionRowHandler &hand, PlayerNumber pn, const vector<bool> &vbSelected )
{
	/* Figure out which selection is the default. */
	switch( hand.type )
	{
	case ROW_LIST:
	case ROW_CHARACTER:
	case ROW_STEP:
		{
			hand.Default.Apply( pn );
			for( unsigned i=0; i<vbSelected.size(); i++ )
				if( vbSelected[i] )
					hand.ListEntries[i].Apply( pn );
		}
		break;

	case ROW_CONFIG:
		{
			int sel = GetOneSelection(vbSelected) - (m_OptionsNavigation==NAV_TOGGLE_THREE_KEY?1:0);

			/* Get the original choice. */
			int Original = hand.opt->Get( row.choices );

			/* Apply. */
			hand.opt->Put( sel, row.choices );

			/* Get the new choice. */
			int New = hand.opt->Get( row.choices );

			/* If it didn't change, don't return any side-effects. */
			if( Original == New )
				return 0;

			return hand.opt->GetEffects();
		}
		break;

	default:
		ASSERT(0);
		break;
	}
	return 0;
}
Exemplo n.º 2
0
void OptionRow::Reload()
{
	switch( GetRowType() )
	{
	case OptionRow::ROW_NORMAL:
		{
			if( m_pHand == NULL )
				return;

			vector<PlayerNumber> vpns;
			FOREACH_HumanPlayer( p )
				vpns.push_back( p );

			// TODO: Nothing uses this yet and it causes skips when changing options.
			//if( m_RowDef.m_bExportOnChange )
			//{
			//	bool bRowHasFocus[NUM_PLAYERS];
			//	ZERO( bRowHasFocus );
			//	ExportOptions( vpns, bRowHasFocus );
			//}

			m_pHand->Reload( m_RowDef );
			ASSERT( !m_RowDef.choices.empty() );

			FOREACH_PlayerNumber( p )
				m_vbSelected[p].resize( m_RowDef.choices.size(), false );

			// TODO: Nothing uses this yet and it causes skips when changing options.
			//ImportOptions( vpns );

			switch( m_RowDef.selectType )
			{
			case SELECT_ONE:
				FOREACH_HumanPlayer( p )
					m_iChoiceInRowWithFocus[p] = GetOneSelection(p);
				break;
			case SELECT_MULTIPLE:
				FOREACH_HumanPlayer( p )
					CLAMP( m_iChoiceInRowWithFocus[p], 0, m_RowDef.choices.size()-1 );
				break;
			default:
				ASSERT(0);
			}

			// TODO: Nothing uses this yet and it causes skips when changing options.
			//if( m_RowDef.m_bExportOnChange )
			//{
			//	bool bRowHasFocus[NUM_PLAYERS];
			//	ZERO( bRowHasFocus );
			//	ExportOptions( vpns, bRowHasFocus );
			//}

			UpdateEnabledDisabled();
			UpdateText();
			FOREACH_HumanPlayer( p )
				PositionUnderlines( p );
		}
		break;
	case OptionRow::ROW_EXIT:
		// nothing to do
		break;
	default:
		ASSERT(0);
	}
}
Exemplo n.º 3
0
int OptionRow::GetOneSharedSelection( bool bAllowFail ) const
{
	return GetOneSelection( (PlayerNumber)0, bAllowFail );
}
Exemplo n.º 4
0
void OptionRow::AfterImportOptions()
{
	// Make all selections the same if bOneChoiceForAllPlayers
	// Hack: we only import active players, so if only player 2 is imported,
	// we need to copy p2 to p1, not p1 to p2.
	if( m_RowDef.bOneChoiceForAllPlayers )
	{
		PlayerNumber pnCopyFrom = GAMESTATE->m_MasterPlayerNumber;
		if( GAMESTATE->m_MasterPlayerNumber == PLAYER_INVALID )
			pnCopyFrom = PLAYER_1;
		FOREACH_PlayerNumber( p )
			m_vbSelected[p] = m_vbSelected[pnCopyFrom];
	}

	FOREACH_PlayerNumber( p )
	{
		switch( m_RowDef.selectType )
		{
		case SELECT_ONE:
			{
				/* Make sure the row actually has a selection. */
				bool bHasASelection = false;
				for( unsigned i=0; i<m_vbSelected[p].size(); i++ )
				{
					if( m_vbSelected[p][i] )
						bHasASelection = true;
				}

				if( !bHasASelection && !m_vbSelected[p].empty() )
					m_vbSelected[p][0] = true;
				
				m_iChoiceInRowWithFocus[p] = GetOneSelection(p, true);	// focus on the selection we just set
			}
			break;
		case SELECT_MULTIPLE:
		case SELECT_NONE:
			m_iChoiceInRowWithFocus[p] = 0;
			break;
		default:
			ASSERT(0);
		}
	}

	// init row icons
	FOREACH_HumanPlayer( p )
	{
		LoadOptionIcon( p, "" );
	}


	// If the items will go off the edge of the screen, then re-init with the "long row" style.
	{
		BitmapText bt;
		bt.LoadFromFont( THEME->GetPathF(m_sType,"item") );
		bt.RunCommands( ITEMS_ON_COMMAND );

		float fX = ITEMS_START_X;
		
		for( unsigned c=0; c<m_RowDef.choices.size(); c++ )
		{
			CString sText = m_RowDef.choices[c];
			PrepareItemText( sText );
			bt.SetText( sText );
			
			fX += bt.GetZoomedWidth();
			
			if( c != m_RowDef.choices.size()-1 )
				fX += ITEMS_GAP_X;

			if( fX > ITEMS_END_X ) 
			{
				m_RowDef.layoutType = LAYOUT_SHOW_ONE_IN_ROW;
				break;
			}
		}
	}

	//
	// load m_textItems
	//
	switch( m_RowDef.layoutType )
	{
	case LAYOUT_SHOW_ONE_IN_ROW:
		// init text
		FOREACH_HumanPlayer( p )
		{
			BitmapText *bt = new BitmapText;
			m_textItems.push_back( bt );

			const int iChoiceInRowWithFocus = m_iChoiceInRowWithFocus[p];

			bt->LoadFromFont( THEME->GetPathF(m_sType,"item") );
			CString sText = (iChoiceInRowWithFocus==-1) ? "" : m_RowDef.choices[iChoiceInRowWithFocus];
			// ugly hack for Speed mods --infamouspat
			PrepareItemText( sText );

			bt->SetText( sText );
			bt->RunCommands( ITEMS_ON_COMMAND );
			bt->SetShadowLength( 0 );

			if( m_RowDef.bOneChoiceForAllPlayers )
			{
				bt->SetX( ITEMS_LONG_ROW_SHARED_X );
				break;	// only initialize one item since it's shared
			}
			else
			{
				bt->SetX( ITEMS_LONG_ROW_X.GetValue(p) );
			}
		}

		// init underlines
		FOREACH_HumanPlayer( p )
		{
			OptionsCursor *ul = new OptionsCursor;
			m_Underline[p].push_back( ul );
			ul->Load( m_sType, OptionsCursor::underline );
			ul->Set( p );
			int iWidth, iX, iY;
			GetWidthXY( p, 0, iWidth, iX, iY );
			ul->SetX( float(iX) );
			ul->SetWidth( float(iWidth) );
		}
		break;

	case LAYOUT_SHOW_ALL_IN_ROW:
		{
			float fX = ITEMS_START_X;
			for( unsigned c=0; c<m_RowDef.choices.size(); c++ )
			{
				// init text
				BitmapText *bt = new BitmapText;
				m_textItems.push_back( bt );
				bt->LoadFromFont( THEME->GetPathF(m_sType,"item") );
				CString sText = m_RowDef.choices[c];
				PrepareItemText( sText );
				bt->SetText( sText );
				bt->RunCommands( ITEMS_ON_COMMAND );
				bt->SetShadowLength( 0 );

				// set the X position of each item in the line
				float fItemWidth = bt->GetZoomedWidth();
				fX += fItemWidth/2;
				bt->SetX( fX );

				// init underlines
				FOREACH_HumanPlayer( p )
				{
					OptionsCursor *ul = new OptionsCursor;
					m_Underline[p].push_back( ul );
					ul->Load( m_sType, OptionsCursor::underline );
					ul->Set( p );
					ul->SetX( fX );
					ul->SetWidth( truncf(fItemWidth) );
				}

				fX += fItemWidth/2 + ITEMS_GAP_X;
			}
		}
		break;

	default:
		ASSERT(0);
	}

	for( unsigned c=0; c<m_textItems.size(); c++ )
		m_Frame.AddChild( m_textItems[c] );
	FOREACH_PlayerNumber( p )
		for( unsigned c=0; c<m_Underline[p].size(); c++ )
			m_Frame.AddChild( m_Underline[p][c] );


	m_textTitle.LoadFromFont( THEME->GetPathF(m_sType,"title") );
	CString sTitle = GetRowTitle();
	m_textTitle.SetText( sTitle );
	m_textTitle.SetX( LABELS_X );
	m_textTitle.RunCommands( LABELS_ON_COMMAND );

	m_sprBullet.Load( THEME->GetPathG(m_sType,"bullet") );
	m_sprBullet.SetX( ARROWS_X );
	
	//
	// HACK: Set focus to one item in the row, which is "go down"
	//
	if( m_bFirstItemGoesDown && m_RowDef.name != "Speed" )
		FOREACH_PlayerNumber( p )
			m_iChoiceInRowWithFocus[p] = 0;	
}