⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flexpanel.cpp

📁 hl2 source code. Do not use it illegal.
💻 CPP
📖 第 1 页 / 共 2 页
字号:

	float *settings = exp->GetSettings();
	float *weights = exp->GetWeights();
	Assert( settings );	
	Assert( weights );	

	for (int i = 0; i < hdr->numflexcontrollers; i++)
	{
		int j = hdr->pFlexcontroller( i )->link;
		if ( j == -1 )
			continue;

		SetSlider( j, settings[j] );
		SetInfluence( j, weights[j] );
		models->GetActiveStudioModel()->SetFlexController( i, settings[j] * weights[j] );
	}
}

void FlexPanel::DeleteExpression( int index )
{
	studiohdr_t *hdr = models->GetActiveStudioModel()->getStudioHeader ();
	if ( !hdr )
		return;
	CExpClass *active = expressions->GetActiveClass();
	if ( !active )
		return;

	CExpression *exp = active->GetExpression( index );
	if ( !exp )
		return;

	active->DeleteExpression( exp->name );
}

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : index - 
//-----------------------------------------------------------------------------
void FlexPanel::RevertExpression( int index )
{
	studiohdr_t *hdr = models->GetActiveStudioModel()->getStudioHeader ();
	if ( !hdr )
		return;

	CExpClass *active = expressions->GetActiveClass();
	if ( !active )
		return;

	CExpression *exp = active->GetExpression( index );
	if ( !exp )
		return;

	exp->Revert();
	setExpression( index );
	g_pExpressionTrayTool->redraw();
}

void FlexPanel::SaveExpressionOverride( int index )
{
	studiohdr_t *hdr = models->GetActiveStudioModel()->getStudioHeader ();
	if ( !hdr )
		return;

	CExpClass *active = expressions->GetActiveClass();
	if ( !active )
		return;

	CExpression *exp = active->GetExpression( index );
	if ( !exp )
		return;

	// Found it in the base, now create the override if it doesn't exist
	//
	CExpClass *overrides = expressions->FindOverrideClass( active->GetName() );
	if ( !overrides )
	{
		// create one
		overrides = expressions->AddOverrideClass( active->GetName() );
		if( overrides )
		{
			overrides->SetDirty( true );
			active->SetOverrideClass( overrides );
			overrides->SetIsOverrideClass( true );
		}
	}

	if ( !overrides )
		return;

	CExpression *oe = overrides->FindExpression( exp->name );
	if ( !oe )
	{
		oe = overrides->AddExpression( exp->name, exp->description, exp->GetSettings(), exp->GetWeights(), false );
	}

	if ( !oe )
		return;
	
	float *settings = oe->GetSettings();
	float *weights = oe->GetWeights();
	Assert( settings );	
	Assert( weights );	
	for ( int i = 0; i < hdr->numflexcontrollers; i++ )
	{
		int j = hdr->pFlexcontroller( i )->link;

		settings[ j ] = GetSlider( j );
		weights[ j ] = GetInfluence( j );
	}

	exp->Revert();

	oe->CreateNewBitmap( models->GetActiveModelIndex() );

	oe->ResetUndo();

	oe->SetDirty( false );

	// So overrides save when we save
	active->SetDirty( true );

	active->ApplyOverrides();

	g_pExpressionTrayTool->redraw();
}

void FlexPanel::SaveExpression( int index )
{
	studiohdr_t *hdr = models->GetActiveStudioModel()->getStudioHeader ();
	if ( !hdr )
		return;

	CExpClass *active = expressions->GetActiveClass();
	if ( !active )
		return;

	CExpression *exp = active->GetExpression( index );
	if ( !exp )
		return;

	int retval = mxMessageBox( this, "Overwrite existing expression?", g_appTitle, MX_MB_YESNO | MX_MB_QUESTION );
	if ( retval != 0 )
		return;

	float *settings = exp->GetSettings();
	float *weights = exp->GetWeights();
	Assert( settings );	
	Assert( weights );	
	for ( int i = 0; i < hdr->numflexcontrollers; i++ )
	{
		int j = hdr->pFlexcontroller( i )->link;

		settings[ j ] = GetSlider( j );
		weights[ j ] = GetInfluence( j );
	}

	exp->CreateNewBitmap( models->GetActiveModelIndex() );

	exp->ResetUndo();

	exp->SetDirty( false );

	g_pExpressionTrayTool->redraw();
}

void FlexPanel::CopyControllerSettingsToStructure( CExpression *exp )
{
	Assert( exp );

	studiohdr_t *hdr = models->GetActiveStudioModel()->getStudioHeader ();
	if ( hdr )
	{
		float *settings = exp->GetSettings();
		float *weights = exp->GetWeights();

		for (int i = 0; i < hdr->numflexcontrollers; i++)
		{
			int j = hdr->pFlexcontroller( i )->link;

			settings[ j ] = GetSlider( j );
			weights[ j ] = GetInfluence( j );
		}
	}
}

void FlexPanel::ResetSliders( bool preserveundo )
{
	CExpClass *active = expressions->GetActiveClass();
	if ( !active )
		return;

	bool needredo = false;
	CExpression zeroes;

	CExpression *exp = NULL;
	int index = active->GetSelectedExpression();
	if ( index != -1 )
	{
		exp = active->GetExpression( index );
		if ( exp )
		{
			float *settings = exp->GetSettings();
			Assert( settings );

			if ( memcmp( settings, zeroes.GetSettings(), GLOBAL_STUDIO_FLEX_CONTROL_COUNT * sizeof( float ) ) )
			{
				if ( preserveundo )
				{
					exp->PushUndoInformation();
					needredo = true;
				}

				active->SetDirty( true );

				g_pExpressionTrayTool->redraw();
			}
		}
	}

	studiohdr_t *hdr = models->GetActiveStudioModel()->getStudioHeader ();
	if ( hdr )
	{
		int i;

		if( exp )
		{
			float *settings = exp->GetSettings();
			float *weights = exp->GetWeights();

			Assert( settings && weights );

			for ( i = 0; i < GLOBAL_STUDIO_FLEX_CONTROL_COUNT; i++ )
			{
				settings[ i ] = 0.0f;
				weights[ i ] = 0.0f;
			}
		}

		for ( i = 0; i < hdr->numflexcontrollers; i++ )
		{
			int j = hdr->pFlexcontroller( i )->link;

			if ( j == -1 )
				continue;

			SetSlider( j, 0.0f );
			SetInfluence( j, 0.0f );
			models->GetActiveStudioModel()->SetFlexController( i, 0.0 );
		}
	}

	if ( exp && needredo && preserveundo )
	{
		exp->PushRedoInformation();
	}
}

void FlexPanel::CopyControllerSettings( void )
{
	CExpression *exp = expressions->GetCopyBuffer();
	memset( exp, 0, sizeof( *exp ) );
	CopyControllerSettingsToStructure( exp );
}

void FlexPanel::PasteControllerSettings( void )
{
	CExpClass *active = expressions->GetActiveClass();
	if ( !active )
		return;

	bool needredo = false;
	CExpression *paste = expressions->GetCopyBuffer();
	if ( !paste )
		return;

	CExpression *exp = NULL;
	int index = active->GetSelectedExpression();
	if ( index != -1 )
	{
		exp = active->GetExpression( index );
		if ( exp )
		{
			float *settings = exp->GetSettings();
			Assert( settings );

			// UPDATEME
			if ( memcmp( settings, paste->GetSettings(), GLOBAL_STUDIO_FLEX_CONTROL_COUNT * sizeof( float ) ) )
			{
				exp->PushUndoInformation();
				needredo = true;

				active->SetDirty( true );

				g_pExpressionTrayTool->redraw();
			}
		}
	}

	studiohdr_t *hdr = models->GetActiveStudioModel()->getStudioHeader ();
	if ( hdr )
	{
		float *settings = paste->GetSettings();
		float *weights = paste->GetWeights();
		Assert( settings );
		Assert( weights );

		for (int i = 0; i < hdr->numflexcontrollers; i++)
		{
			int j = hdr->pFlexcontroller( i )->link;

			SetSlider( j, settings[j] );
			SetInfluence( j, weights[j] );
			models->GetActiveStudioModel()->SetFlexController( i, settings[j] * weights[j] );
		}
	}

	if ( exp && needredo )
	{
		exp->PushRedoInformation();
	}

}

void FlexPanel::EditExpression( void )
{
	studiohdr_t *hdr = models->GetActiveStudioModel()->getStudioHeader ();
	if ( !hdr )
	{
		Con_ColorPrintf( ERROR_R, ERROR_G, ERROR_B, "Can't edit face pose, must load a model first!\n" );
		return;
	}
	
	CExpClass *active = expressions->GetActiveClass();
	if ( !active )
		return;

	int index = active->GetSelectedExpression();
	if ( index == -1 )
	{
		Con_ColorPrintf( ERROR_R, ERROR_G, ERROR_B, "Can't edit face pose, must select a face from list first!\n" );
		return;
	}

	CExpression *exp = active->GetExpression( index );
	if ( !exp )
	{
		return;
	}

	bool namechanged = false;
	CExpressionParams params;
	memset( &params, 0, sizeof( params ) );

	strcpy( params.m_szDialogTitle, "Edit Expression" );
	strcpy( params.m_szName, exp->name );
	strcpy( params.m_szDescription, exp->description );

	if ( !ExpressionProperties( &params ) )
		return;

	namechanged = stricmp( exp->name, params.m_szName ) ? true : false;

	if ( ( strlen( params.m_szName ) <= 0 ) ||
		!stricmp( params.m_szName, "unnamed" ) )
	{
		Con_ColorPrintf( ERROR_R, ERROR_G, ERROR_B, "You must type in a valid name\n" );
		return;
	}

	if ( ( strlen( params.m_szDescription ) <= 0 ) ||
   	   !stricmp( params.m_szDescription, "description" ) )
	{
		Con_ColorPrintf( ERROR_R, ERROR_G, ERROR_B, "You must type in a valid description\n" );
		return;
	}

	if ( namechanged )
	{
		Con_Printf( "Deleting old bitmap %s\n", exp->GetBitmapFilename( models->GetActiveModelIndex() ) );

		// Remove old bitmap
		_unlink( exp->GetBitmapFilename( models->GetActiveModelIndex() ) );
	}

	strcpy( exp->name, params.m_szName );
	strcpy( exp->description, params.m_szDescription );

	if ( namechanged )
	{
		exp->CreateNewBitmap( models->GetActiveModelIndex() );
	}

	active->SetDirty( true );

	g_pExpressionTrayTool->redraw();
}

void FlexPanel::NewExpression( void )
{
	studiohdr_t *hdr = models->GetActiveStudioModel()->getStudioHeader ();
	if ( !hdr )
	{
		Con_ColorPrintf( ERROR_R, ERROR_G, ERROR_B, "Can't create new face pose, must load a model first!\n" );
		return;
	}

	CExpClass *active = expressions->GetActiveClass();
	if ( !active )
		return;

	g_pExpressionTrayTool->Deselect();

	CExpressionParams params;
	memset( &params, 0, sizeof( params ) );

	strcpy( params.m_szDialogTitle, "Add Expression" );
	strcpy( params.m_szName, "" );
	strcpy( params.m_szDescription, "" );

	if ( !ExpressionProperties( &params ) )
		return;

	if ( ( strlen( params.m_szName ) <= 0 ) ||
		!stricmp( params.m_szName, "unnamed" ) )
	{
		Con_ColorPrintf( ERROR_R, ERROR_G, ERROR_B, "You must type in a valid name\n" );
		return;
	}

	if ( ( strlen( params.m_szDescription ) <= 0 ) ||
   	   !stricmp( params.m_szDescription, "description" ) )
	{
		Con_ColorPrintf( ERROR_R, ERROR_G, ERROR_B, "You must type in a valid description\n" );
		return;
	}

	float settings[ GLOBAL_STUDIO_FLEX_CONTROL_COUNT ];
	float weights[ GLOBAL_STUDIO_FLEX_CONTROL_COUNT ];
	memset( settings, 0, sizeof( settings ) );
	memset( weights, 0, sizeof( settings ) );
	for ( int i = 0; i < hdr->numflexcontrollers; i++ )
	{
		int j = hdr->pFlexcontroller( i )->link;

		settings[ j ] = GetSlider( j );
		weights[ j ] = GetInfluence( j );
	}	

	active->AddExpression( params.m_szName, params.m_szDescription, settings, weights, true );
}

//-----------------------------------------------------------------------------
// Purpose: 
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool FlexPanel::PaintBackground( void )
{
	redraw();
	return false;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -