This commit is contained in:
FluorescentCIAAfricanAmerican
2020-04-22 12:56:21 -04:00
commit 3bf9df6b27
15370 changed files with 5489726 additions and 0 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,59 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "dme_controls/AttributeBasePickerPanel.h"
#include "filesystem.h"
#include "vgui_controls/Button.h"
#include "vgui_controls/FileOpenDialog.h"
#include "dme_controls/AttributeTextEntry.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CAttributeBasePickerPanel::CAttributeBasePickerPanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
BaseClass( parent, info )
{
m_pOpen = new vgui::Button( this, "Open", "...", this, "open" );
}
void CAttributeBasePickerPanel::OnCommand( char const *cmd )
{
if ( !Q_stricmp( cmd, "open" ) )
{
ShowPickerDialog();
}
else
{
BaseClass::OnCommand( cmd );
}
}
void CAttributeBasePickerPanel::PerformLayout()
{
BaseClass::PerformLayout();
int x, y, w, h;
m_pType->GetBounds( x, y, w, h );
int inset = 25;
m_pType->SetWide( w - inset );
x += w;
x -= inset;
h -= 2;
m_pOpen->SetBounds( x, y, inset, h );
}
@@ -0,0 +1,159 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "dme_controls/AttributeBoolChoicePanel.h"
#include "tier1/KeyValues.h"
#include "vgui_controls/ComboBox.h"
#include "datamodel/dmelement.h"
#include "movieobjects/dmeeditortypedictionary.h"
#include "datamodel/dmelementfactoryhelper.h"
#include "dme_controls/inotifyui.h"
#include "dme_controls/dmecontrols.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
// Expose DmeEditorAttributeInfo to the scene database
//-----------------------------------------------------------------------------
IMPLEMENT_ELEMENT_FACTORY( DmeEditorBoolChoicesInfo, CDmeEditorBoolChoicesInfo );
//-----------------------------------------------------------------------------
// Constructor, destructor
//-----------------------------------------------------------------------------
void CDmeEditorBoolChoicesInfo::OnConstruction()
{
// Add a true + false method, default
CreateChoice( "false" );
CreateChoice( "true" );
}
void CDmeEditorBoolChoicesInfo::OnDestruction()
{
}
//-----------------------------------------------------------------------------
// Add a choice
//-----------------------------------------------------------------------------
void CDmeEditorBoolChoicesInfo::SetFalseChoice( const char *pChoiceString )
{
m_Choices[0]->SetValue<CUtlString>( "string", pChoiceString );
}
void CDmeEditorBoolChoicesInfo::SetTrueChoice( const char *pChoiceString )
{
m_Choices[1]->SetValue<CUtlString>( "string", pChoiceString );
}
//-----------------------------------------------------------------------------
// Gets the choices
//-----------------------------------------------------------------------------
const char *CDmeEditorBoolChoicesInfo::GetFalseChoiceString( ) const
{
return GetChoiceString( 0 );
}
const char *CDmeEditorBoolChoicesInfo::GetTrueChoiceString( ) const
{
return GetChoiceString( 1 );
}
//-----------------------------------------------------------------------------
//
// Constructor
//
//-----------------------------------------------------------------------------
CAttributeBoolChoicePanel::CAttributeBoolChoicePanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
BaseClass( parent, info )
{
}
//-----------------------------------------------------------------------------
// Derived classes can re-implement this to fill the combo box however they like
//-----------------------------------------------------------------------------
void CAttributeBoolChoicePanel::PopulateComboBox( vgui::ComboBox *pComboBox )
{
pComboBox->DeleteAllItems();
CDmeEditorBoolChoicesInfo *pInfo = CastElement<CDmeEditorBoolChoicesInfo>( GetEditorInfo() );
if ( !pInfo )
return;
// Fill in the choices
const char *pFalseChoice = pInfo->GetFalseChoiceString( );
const char *pTrueChoice = pInfo->GetTrueChoiceString( );
// Add the dynamic choices next
if ( pInfo->HasChoiceType() )
{
const char *choices[2];
if ( ElementPropertiesChoices()->GetBoolChoiceList( pInfo->GetChoiceType(), GetPanelElement(), GetAttributeName(), IsArrayEntry(), choices ) )
{
pFalseChoice = choices[0];
pTrueChoice = choices[1];
}
}
KeyValues *kv = new KeyValues( "entry" );
kv->SetInt( "value", false );
pComboBox->AddItem( pFalseChoice, kv );
kv = new KeyValues( "entry" );
kv->SetInt( "value", true );
pComboBox->AddItem( pTrueChoice, kv );
}
//-----------------------------------------------------------------------------
// Sets the attribute based on the combo box
//-----------------------------------------------------------------------------
void CAttributeBoolChoicePanel::SetAttributeFromComboBox( vgui::ComboBox *pComboBox, KeyValues *pKeyValues )
{
bool bOldValue = GetAttributeValue<bool>();
bool bValue = pKeyValues->GetInt( "value", 0 ) != 0;
if ( bOldValue == bValue )
return;
CUndoScopeGuard guard( NOTIFY_SOURCE_PROPERTIES_TREE, NOTIFY_SETDIRTYFLAG, "Set Attribute Value", "Set Attribute Value" );
SetAttributeValue( bValue );
}
//-----------------------------------------------------------------------------
// Sets the combo box from the attribute
//-----------------------------------------------------------------------------
void CAttributeBoolChoicePanel::SetComboBoxFromAttribute( vgui::ComboBox *pComboBox )
{
CDmeEditorBoolChoicesInfo *pInfo = CastElement<CDmeEditorBoolChoicesInfo>( GetEditorInfo() );
if ( !pInfo )
return;
bool bValue = GetAttributeValue<bool>();
// Check the dynamic choices next
if ( pInfo->HasChoiceType() )
{
const char *choices[2];
if ( ElementPropertiesChoices()->GetBoolChoiceList( pInfo->GetChoiceType(), GetPanelElement(), GetAttributeName(), IsArrayEntry(), choices ) )
{
pComboBox->SetText( choices[ bValue ] );
return;
}
}
pComboBox->SetText( pInfo->GetChoiceString( bValue ) );
}
@@ -0,0 +1,170 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "dme_controls/AttributeColorPickerPanel.h"
#include "datamodel/dmelement.h"
#include "vgui_controls/Button.h"
#include "dme_controls/AttributeTextEntry.h"
#include "matsys_controls/colorpickerpanel.h"
#include "tier1/KeyValues.h"
#include "dme_controls/inotifyui.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CAttributeColorPickerPanel::CAttributeColorPickerPanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
BaseClass( parent, info )
{
m_pOpen = new vgui::Button( this, "Open", "", this, "open" );
}
void CAttributeColorPickerPanel::OnCommand( char const *cmd )
{
if ( !Q_stricmp( cmd, "open" ) )
{
m_InitialColor = GetAttributeValue<Color>();
CColorPickerFrame *pColorPickerDialog = new CColorPickerFrame( this, "Select Color" );
pColorPickerDialog->AddActionSignalTarget( this );
pColorPickerDialog->DoModal( m_InitialColor );
}
else
{
BaseClass::OnCommand( cmd );
}
}
//-----------------------------------------------------------------------------
// Update button color
//-----------------------------------------------------------------------------
void CAttributeColorPickerPanel::UpdateButtonColor()
{
Color clr = GetAttributeValue<Color>();
m_pOpen->SetDefaultColor( clr, clr );
m_pOpen->SetArmedColor( clr, clr );
m_pOpen->SetDepressedColor( clr, clr );
}
//-----------------------------------------------------------------------------
// Used to set the current color on the picker button
//-----------------------------------------------------------------------------
void CAttributeColorPickerPanel::Refresh()
{
BaseClass::Refresh();
UpdateButtonColor();
}
void CAttributeColorPickerPanel::ApplySchemeSettings(IScheme *pScheme)
{
// Need to override the scheme settings for this button
BaseClass::ApplySchemeSettings( pScheme );
UpdateButtonColor();
}
//-----------------------------------------------------------------------------
// Called when the picker gets a new color but apply hasn't happened yet
//-----------------------------------------------------------------------------
void CAttributeColorPickerPanel::OnPreview( KeyValues *data )
{
{
CDisableUndoScopeGuard guard;
Color c = data->GetColor( "color" );
SetAttributeValue( c );
}
Refresh( );
if ( IsAutoApply() )
{
// NOTE: Don't call Apply since that generates an undo record
CElementTreeNotifyScopeGuard guard( "CAttributeColorPickerPanel::OnPreview", NOTIFY_CHANGE_ATTRIBUTE_VALUE, GetNotify() );
}
else
{
SetDirty( true );
}
}
//-----------------------------------------------------------------------------
// Called when cancel is hit in the picker
//-----------------------------------------------------------------------------
void CAttributeColorPickerPanel::OnCancelled( )
{
// Restore the initial color
CDisableUndoScopeGuard guard;
SetAttributeValue( m_InitialColor );
Refresh( );
CElementTreeNotifyScopeGuard notify( "CAttributeColorPickerPanel::OnCancelled", NOTIFY_CHANGE_ATTRIBUTE_VALUE, GetNotify() );
SetDirty( false );
}
//-----------------------------------------------------------------------------
// Called when the picker gets a new color
//-----------------------------------------------------------------------------
void CAttributeColorPickerPanel::OnPicked( KeyValues *data )
{
Color c = data->GetColor( "color" );
if ( c == m_InitialColor )
{
SetDirty( false );
return;
}
// Kind of an evil hack, but "undo" copies the "old value" off for doing undo, and that value is the new value because
// we haven't been tracking undo while manipulating this. So we'll turn off undo and set the value to the original value.
// In effect, all of the wheeling will drop out and it'll look just like we started at the original value and ended up at the
// final value...
{
CDisableUndoScopeGuard guard;
SetAttributeValue( m_InitialColor );
}
{
CElementTreeUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, GetNotify(), "Set Attribute Value", "Set Attribute Value" );
SetAttributeValue( c );
}
if ( IsAutoApply() )
{
Refresh();
SetDirty( false );
}
}
//-----------------------------------------------------------------------------
// Lays out the button position
//-----------------------------------------------------------------------------
void CAttributeColorPickerPanel::PerformLayout()
{
BaseClass::PerformLayout();
int x, y, w, h;
m_pType->GetBounds( x, y, w, h );
int inset = 25;
m_pType->SetWide( w - inset );
x += w;
x -= inset;
h -= 2;
m_pOpen->SetBounds( x, y, inset, h );
}
@@ -0,0 +1,104 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "dme_controls/AttributeElementPanel.h"
#include "dme_controls/AttributeTextEntry.h"
#include "dme_controls/AttributeWidgetFactory.h"
#include "tier1/KeyValues.h"
#include "datamodel/dmelement.h"
#include "movieobjects/dmeeditortypedictionary.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
// ----------------------------------------------------------------------------
CAttributeElementPanel::CAttributeElementPanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
BaseClass( parent, info ), m_pData( 0 )
{
m_pData = new CAttributeTextEntry( this, "AttributeValue" );
m_pData->SetEnabled( !HasFlag( READONLY ) );
m_pData->AddActionSignalTarget(this);
m_pType->SetText( "element" );
m_bShowMemoryUsage = info.m_bShowMemoryUsage;
}
void CAttributeElementPanel::Apply()
{
// FIXME: Implement when needed
Assert( 0 );
}
vgui::Panel *CAttributeElementPanel::GetDataPanel()
{
return static_cast< vgui::Panel * >( m_pData );
}
void CAttributeElementPanel::OnCreateDragData( KeyValues *msg )
{
if ( GetPanelElement() )
{
char txt[ 256 ];
m_pData->GetText( txt, sizeof( txt ) );
msg->SetString( "text", txt );
CDmElement *element = NULL;
if ( GetPanelElement()->HasAttribute( GetAttributeName() ) )
{
element = GetElement<CDmElement>( GetAttributeValue<DmElementHandle_t>( ) );
msg->SetInt( "dmeelement", element->GetHandle() );
}
}
}
void CAttributeElementPanel::Refresh()
{
char elemText[ 512 ];
elemText[0] = 0;
CDmElement *element = NULL;
if ( !GetEditorInfo() || !GetEditorInfo()->GetValue<bool>( "hideText" ) )
{
if ( HasAttribute( ) )
{
element = GetAttributeValueElement( );
}
else
{
element = GetPanelElement();
}
}
if ( element )
{
char idstr[ 37 ];
UniqueIdToString( element->GetId(), idstr, sizeof( idstr ) );
if ( m_bShowMemoryUsage )
{
Q_snprintf( elemText, sizeof( elemText ), "%s %s %.3fMB", element->GetTypeString(), idstr, element->EstimateMemoryUsage() / float( 1 << 20 ) );
}
else
{
Q_snprintf( elemText, sizeof( elemText ), "%s %s", element->GetTypeString(), idstr );
}
}
m_pData->SetText( elemText );
m_pData->SetEnabled(false);
}
void CAttributeElementPanel::PostConstructor()
{
Refresh();
}
// ----------------------------------------------------------------------------
@@ -0,0 +1,174 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "dme_controls/AttributeElementPickerPanel.h"
#include "dme_controls/AttributeTextEntry.h"
#include "dme_controls/AttributeWidgetFactory.h"
#include "datamodel/dmelement.h"
#include "tier1/KeyValues.h"
#include "vgui_controls/Button.h"
#include "vgui_controls/ComboBox.h"
#include "dme_controls/dmepicker.h"
#include "movieobjects/dmeeditortypedictionary.h"
#include "dme_controls/inotifyui.h"
#include "dme_controls/dmecontrols.h"
#include "dme_controls/dmecontrols_utils.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
// ----------------------------------------------------------------------------
CAttributeElementPickerPanel::CAttributeElementPickerPanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
BaseClass( parent, info )
{
m_hEdit = new vgui::Button( this, "Open", "...", this, "open" );
m_pData = new CAttributeTextEntry( this, "AttributeValue" );
m_pData->SetEnabled( !HasFlag( READONLY ) );
m_pData->AddActionSignalTarget(this);
m_pType->SetText( "element" );
m_bShowMemoryUsage = info.m_bShowMemoryUsage;
}
void CAttributeElementPickerPanel::PostConstructor()
{
Refresh();
}
// ----------------------------------------------------------------------------
vgui::Panel *CAttributeElementPickerPanel::GetDataPanel()
{
return static_cast< vgui::Panel * >( m_pData );
}
void CAttributeElementPickerPanel::Apply()
{
// FIXME: Implement when needed
Assert( 0 );
}
void CAttributeElementPickerPanel::Refresh()
{
char elemText[ 512 ];
elemText[0] = 0;
CDmElement *element = NULL;
if ( !GetEditorInfo() || !GetEditorInfo()->GetValue<bool>( "hideText" ) )
{
if ( HasAttribute( ) )
{
element = GetAttributeValueElement( );
}
else
{
element = GetPanelElement();
}
}
if ( element )
{
char idstr[ 37 ];
UniqueIdToString( element->GetId(), idstr, sizeof( idstr ) );
if ( m_bShowMemoryUsage )
{
Q_snprintf( elemText, sizeof( elemText ), "%s %s %.3fMB", element->GetTypeString(), idstr, element->EstimateMemoryUsage() / float( 1 << 20 ) );
}
else
{
Q_snprintf( elemText, sizeof( elemText ), "%s %s", element->GetTypeString(), idstr );
}
}
m_pData->SetText( elemText );
m_pData->SetEditable( false );
}
//-----------------------------------------------------------------------------
// Called when it's time to show the Dme picker
//-----------------------------------------------------------------------------
void CAttributeElementPickerPanel::ShowPickerDialog()
{
CDmeEditorChoicesInfo *pInfo = CastElement<CDmeEditorChoicesInfo>( GetEditorInfo() );
if ( !pInfo )
return;
// FIXME: Sucky. Should we make GetElementChoiceList return a DmeHandleVec_t?
ElementChoiceList_t choices;
CUtlVector< DmePickerInfo_t > vec;
if ( ElementPropertiesChoices()->GetElementChoiceList( pInfo->GetChoiceType(), GetPanelElement(), GetAttributeName(), IsArrayEntry(), choices ) )
{
int c = choices.Count();
vec.EnsureCapacity( c );
for ( int i = 0; i < c; ++i )
{
int j = vec.AddToTail( );
vec[j].m_hElement = choices[i].m_pValue->GetHandle();
vec[j].m_pChoiceString = choices[i].m_pChoiceString;
}
}
CDmePickerFrame *pDmePickerDialog = new CDmePickerFrame( this, "Select DME Element" );
pDmePickerDialog->AddActionSignalTarget( this );
pDmePickerDialog->DoModal( vec );
}
//-----------------------------------------------------------------------------
// Called by the dme picker dialog if a dme was selected
//-----------------------------------------------------------------------------
void CAttributeElementPickerPanel::OnDmeSelected( KeyValues *pKeyValues )
{
// We're either going to get an activity or sequence name
CDmElement *pElement = GetElementKeyValue< CDmElement >( pKeyValues, "dme" );
SetAttributeValueElement( pElement );
Refresh( );
}
//-----------------------------------------------------------------------------
// Handle commands
//-----------------------------------------------------------------------------
void CAttributeElementPickerPanel::OnCommand( char const *cmd )
{
if ( !Q_stricmp( cmd, "open" ) )
{
ShowPickerDialog();
}
else
{
BaseClass::OnCommand( cmd );
}
}
//-----------------------------------------------------------------------------
// Lay out the panel
//-----------------------------------------------------------------------------
void CAttributeElementPickerPanel::PerformLayout()
{
BaseClass::PerformLayout();
int x, y, w, h;
m_pType->GetBounds( x, y, w, h );
int inset = 25;
m_pType->SetWide( w - inset );
x += w;
x -= inset;
h -= 2;
m_hEdit->SetBounds( x, y, inset, h );
}
@@ -0,0 +1,73 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "dme_controls/AttributeFilePickerPanel.h"
#include "filesystem.h"
#include "vgui_controls/Button.h"
#include "vgui_controls/FileOpenDialog.h"
#include "dme_controls/AttributeTextEntry.h"
#include "vgui/IInput.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
// Various file picker types
//-----------------------------------------------------------------------------
IMPLEMENT_ATTRIBUTE_FILE_PICKER( CAttributeTgaFilePickerPanel, "Choose TGA file", "TGA", "tga" );
IMPLEMENT_ATTRIBUTE_FILE_PICKER( CAttributeDmeFilePickerPanel, "Choose DmE .xml file", "DmE XML", "xml" );
IMPLEMENT_ATTRIBUTE_FILE_PICKER( CAttributeAviFilePickerPanel, "Choose AVI file", "AVI", "avi" );
IMPLEMENT_ATTRIBUTE_FILE_PICKER( CAttributeShtFilePickerPanel, "Choose Sheet file", "SHT", "sht" );
IMPLEMENT_ATTRIBUTE_FILE_PICKER( CAttributeRawFilePickerPanel, "Choose RAW file", "RAW", "raw" );
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CAttributeFilePickerPanel::CAttributeFilePickerPanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
BaseClass( parent, info )
{
}
CAttributeFilePickerPanel::~CAttributeFilePickerPanel()
{
}
//-----------------------------------------------------------------------------
// Shows the picker dialog
//-----------------------------------------------------------------------------
void CAttributeFilePickerPanel::ShowPickerDialog()
{
FileOpenDialog *pFileOpenDialog = new FileOpenDialog( this, "Choose file", true );
SetupFileOpenDialog( pFileOpenDialog );
pFileOpenDialog->AddActionSignalTarget( this );
pFileOpenDialog->SetDeleteSelfOnClose( true );
pFileOpenDialog->DoModal( true );
input()->SetAppModalSurface( pFileOpenDialog->GetVPanel() );
}
void CAttributeFilePickerPanel::OnFileSelected( char const *fullpath )
{
if ( !fullpath || !fullpath[ 0 ] )
return;
char relativepath[ 512 ];
g_pFullFileSystem->FullPathToRelativePath( fullpath, relativepath, sizeof( relativepath ) );
// Apply to text panel
m_pData->SetText( relativepath );
SetDirty(true);
if ( IsAutoApply() )
{
Apply();
}
}
@@ -0,0 +1,170 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "dme_controls/AttributeIntChoicePanel.h"
#include "tier1/KeyValues.h"
#include "vgui_controls/ComboBox.h"
#include "datamodel/dmelement.h"
#include "movieobjects/dmeeditortypedictionary.h"
#include "datamodel/dmelementfactoryhelper.h"
#include "dme_controls/inotifyui.h"
#include "dme_controls/dmecontrols.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
// Expose DmeEditorAttributeInfo to the scene database
//-----------------------------------------------------------------------------
IMPLEMENT_ELEMENT_FACTORY( DmeEditorIntChoicesInfo, CDmeEditorIntChoicesInfo );
//-----------------------------------------------------------------------------
// Constructor, destructor
//-----------------------------------------------------------------------------
void CDmeEditorIntChoicesInfo::OnConstruction()
{
}
void CDmeEditorIntChoicesInfo::OnDestruction()
{
}
//-----------------------------------------------------------------------------
// Add a choice
//-----------------------------------------------------------------------------
void CDmeEditorIntChoicesInfo::AddChoice( int nValue, const char *pChoiceString )
{
CDmElement *pChoice = CreateChoice( pChoiceString );
pChoice->SetValue( "value", nValue );
}
//-----------------------------------------------------------------------------
// Gets the choices
//-----------------------------------------------------------------------------
int CDmeEditorIntChoicesInfo::GetChoiceValue( int nIndex ) const
{
Assert( ( nIndex < GetChoiceCount() ) && ( nIndex >= 0 ) );
CDmElement *pChoice = m_Choices[nIndex];
if ( !pChoice )
return 0;
return pChoice->GetValue<int>( "value" );
}
//-----------------------------------------------------------------------------
//
// Constructor
//
//-----------------------------------------------------------------------------
CAttributeIntChoicePanel::CAttributeIntChoicePanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
BaseClass( parent, info )
{
}
//-----------------------------------------------------------------------------
// Derived classes can re-implement this to fill the combo box however they like
//-----------------------------------------------------------------------------
void CAttributeIntChoicePanel::PopulateComboBox( vgui::ComboBox *pComboBox )
{
pComboBox->DeleteAllItems();
CDmeEditorIntChoicesInfo *pInfo = CastElement<CDmeEditorIntChoicesInfo>( GetEditorInfo() );
if ( !pInfo )
return;
// Fill in the choices
int c = pInfo->GetChoiceCount();
for ( int i = 0; i < c; ++i )
{
KeyValues *kv = new KeyValues( "entry" );
kv->SetInt( "value", pInfo->GetChoiceValue( i ) );
pComboBox->AddItem( pInfo->GetChoiceString( i ) , kv );
}
// Add the dynamic choices next
if ( pInfo->HasChoiceType() )
{
IntChoiceList_t choices;
if ( ElementPropertiesChoices()->GetIntChoiceList( pInfo->GetChoiceType(), GetPanelElement(), GetAttributeName(), IsArrayEntry(), choices ) )
{
c = choices.Count();
for ( int i = 0; i < c; ++i )
{
KeyValues *kv = new KeyValues( "entry" );
kv->SetInt( "value", choices[i].m_nValue );
pComboBox->AddItem( choices[i].m_pChoiceString, kv );
}
}
}
}
//-----------------------------------------------------------------------------
// Sets the attribute based on the combo box
//-----------------------------------------------------------------------------
void CAttributeIntChoicePanel::SetAttributeFromComboBox( vgui::ComboBox *pComboBox, KeyValues *pKeyValues )
{
int nOldValue = GetAttributeValue<int>();
int nValue = pKeyValues->GetInt( "value", 0 );
if ( nOldValue == nValue )
return;
CUndoScopeGuard guard( NOTIFY_SOURCE_PROPERTIES_TREE, NOTIFY_SETDIRTYFLAG, "Set Attribute Value", "Set Attribute Value" );
SetAttributeValue( nValue );
}
//-----------------------------------------------------------------------------
// Sets the combo box from the attribute
//-----------------------------------------------------------------------------
void CAttributeIntChoicePanel::SetComboBoxFromAttribute( vgui::ComboBox *pComboBox )
{
CDmeEditorIntChoicesInfo *pInfo = CastElement<CDmeEditorIntChoicesInfo>( GetEditorInfo() );
if ( !pInfo )
return;
int nValue = GetAttributeValue<int>();
int c = pInfo->GetChoiceCount();
for ( int i = 0; i < c; ++i )
{
if ( nValue == pInfo->GetChoiceValue( i ) )
{
pComboBox->SetText( pInfo->GetChoiceString( i ) );
return;
}
}
// Check the dynamic choices next
if ( pInfo->HasChoiceType() )
{
IntChoiceList_t choices;
if ( ElementPropertiesChoices()->GetIntChoiceList( pInfo->GetChoiceType(), GetPanelElement(), GetAttributeName(), IsArrayEntry(), choices ) )
{
c = choices.Count();
for ( int i = 0; i < c; ++i )
{
if ( nValue == choices[i].m_nValue )
{
pComboBox->SetText( choices[i].m_pChoiceString );
return;
}
}
}
}
pComboBox->SetText( "Unknown value" );
}
@@ -0,0 +1,91 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "dme_controls/AttributeInterpolatorChoicePanel.h"
#include "tier1/KeyValues.h"
#include "vgui_controls/ComboBox.h"
#include "datamodel/dmelement.h"
#include "movieobjects/dmeeditortypedictionary.h"
#include "datamodel/dmelementfactoryhelper.h"
#include "dme_controls/inotifyui.h"
#include "interpolatortypes.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
//
// Constructor
//
//-----------------------------------------------------------------------------
CAttributeInterpolatorChoicePanel::CAttributeInterpolatorChoicePanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
BaseClass( parent, info )
{
}
//-----------------------------------------------------------------------------
// Derived classes can re-implement this to fill the combo box however they like
//-----------------------------------------------------------------------------
void CAttributeInterpolatorChoicePanel::PopulateComboBoxes( vgui::ComboBox *pComboBox[ 2 ] )
{
pComboBox[ 0 ]->DeleteAllItems();
pComboBox[ 1 ]->DeleteAllItems();
// Fill in the choices
int c = NUM_INTERPOLATE_TYPES;
for ( int i = 0; i < c; ++i )
{
KeyValues *kv = new KeyValues( "entry" );
kv->SetInt( "value", i );
pComboBox[ 0 ]->AddItem( Interpolator_NameForInterpolator( i, true ) , kv );
kv = new KeyValues( "entry" );
kv->SetInt( "value", i );
pComboBox[ 1 ]->AddItem( Interpolator_NameForInterpolator( i, true ) , kv );
}
}
//-----------------------------------------------------------------------------
// Sets the attribute based on the combo box
//-----------------------------------------------------------------------------
void CAttributeInterpolatorChoicePanel::SetAttributeFromComboBoxes( vgui::ComboBox *pComboBox[ 2 ], KeyValues *pKeyValues[ 2 ] )
{
int nOldValue = GetAttributeValue<int>();
int nValueLeft = pKeyValues[ 0 ]->GetInt( "value", 0 );
int nValueRight= pKeyValues[ 1 ]->GetInt( "value" , 0 );
int nValue = MAKE_CURVE_TYPE( nValueLeft, nValueRight );
// No change
if ( nOldValue == nValue )
return;
CElementTreeUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, GetNotify(), "Set Attribute Value", "Set Attribute Value" );
SetAttributeValue( nValue );
}
//-----------------------------------------------------------------------------
// Sets the combo box from the attribute
//-----------------------------------------------------------------------------
void CAttributeInterpolatorChoicePanel::SetComboBoxesFromAttribute( vgui::ComboBox *pComboBox[ 2 ] )
{
int nValue = GetAttributeValue<int>();
// Decompose
int leftPart = GET_LEFT_CURVE( nValue );
int rightPart = GET_RIGHT_CURVE( nValue );
pComboBox[ 0 ]->SetText( Interpolator_NameForInterpolator( leftPart, true ) );
pComboBox[ 1 ]->SetText( Interpolator_NameForInterpolator( rightPart, true ) );
}
@@ -0,0 +1,62 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//===========================================================================//
#include "dme_controls/AttributeMDLPickerPanel.h"
#include "filesystem.h"
#include "vgui_controls/Button.h"
#include "vgui_controls/FileOpenDialog.h"
#include "dme_controls/AttributeTextEntry.h"
#include "matsys_controls/MDLPicker.h"
#include "tier1/KeyValues.h"
using namespace vgui;
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CAttributeMDLPickerPanel::CAttributeMDLPickerPanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
BaseClass( parent, info )
{
}
CAttributeMDLPickerPanel::~CAttributeMDLPickerPanel()
{
}
//-----------------------------------------------------------------------------
// Called when it's time to show the MDL picker
//-----------------------------------------------------------------------------
void CAttributeMDLPickerPanel::ShowPickerDialog()
{
// Open file
CMDLPickerFrame *pMDLPickerDialog = new CMDLPickerFrame( this, "Select .MDL File" );
pMDLPickerDialog->AddActionSignalTarget( this );
pMDLPickerDialog->DoModal( );
}
//-----------------------------------------------------------------------------
// Called when it's time to show the MDL picker
//-----------------------------------------------------------------------------
void CAttributeMDLPickerPanel::OnMDLSelected( KeyValues *pKeyValues )
{
const char *pMDLName = pKeyValues->GetString( "mdl", NULL );
if ( !pMDLName || !pMDLName[ 0 ] )
return;
// Apply to text panel
m_pData->SetText( pMDLName );
SetDirty(true);
if ( IsAutoApply() )
{
Apply();
}
}
@@ -0,0 +1,109 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//===========================================================================//
#include "dme_controls/AttributeSequencePickerPanel.h"
#include "filesystem.h"
#include "vgui_controls/Button.h"
#include "vgui_controls/FileOpenDialog.h"
#include "dme_controls/AttributeTextEntry.h"
#include "matsys_controls/MDLPicker.h"
#include "matsys_controls/sequencepicker.h"
#include "tier1/KeyValues.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CAttributeSequencePickerPanel::CAttributeSequencePickerPanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
BaseClass( parent, info )
{
}
CAttributeSequencePickerPanel::~CAttributeSequencePickerPanel()
{
}
//-----------------------------------------------------------------------------
// Called when it's time to show the MDL picker
//-----------------------------------------------------------------------------
void CAttributeSequencePickerPanel::ShowPickerDialog()
{
CMDLPickerFrame *pMDLPickerDialog = new CMDLPickerFrame( this, "Select .MDL File" );
pMDLPickerDialog->AddActionSignalTarget( this );
pMDLPickerDialog->DoModal( );
}
//-----------------------------------------------------------------------------
// Called when it's time to show the MDL picker
//-----------------------------------------------------------------------------
void CAttributeSequencePickerPanel::OnMDLSelected( KeyValues *pKeyValues )
{
const char *pMDLName = pKeyValues->GetString( "asset", NULL );
char pRelativePath[MAX_PATH];
Q_snprintf( pRelativePath, sizeof(pRelativePath), "models\\%s", pMDLName );
ShowSequencePickerDialog( pRelativePath );
}
//-----------------------------------------------------------------------------
// Called when it's time to show the sequence picker
//-----------------------------------------------------------------------------
void CAttributeSequencePickerPanel::ShowSequencePickerDialog( const char *pMDLName )
{
if ( !pMDLName || !pMDLName[ 0 ] )
return;
// Open file
CSequencePicker::PickType_t pickType = CSequencePicker::PICK_ALL;
const char *pTextType = GetTextType();
if ( pTextType )
{
if ( !Q_stricmp( pTextType, "activityName" ) )
{
pickType = CSequencePicker::PICK_ACTIVITIES;
}
else if ( !Q_stricmp( pTextType, "sequenceName" ) )
{
pickType = CSequencePicker::PICK_SEQUENCES;
}
}
CSequencePickerFrame *pSequencePickerDialog = new CSequencePickerFrame( this, pickType );
pSequencePickerDialog->AddActionSignalTarget( this );
pSequencePickerDialog->DoModal( pMDLName );
}
//-----------------------------------------------------------------------------
// Called when it's time to show the MDL picker
//-----------------------------------------------------------------------------
void CAttributeSequencePickerPanel::OnSequenceSelected( KeyValues *pKeyValues )
{
// We're either going to get an activity or sequence name
const char *pActivityName = pKeyValues->GetString( "activity", NULL );
const char *pSequenceName = pKeyValues->GetString( "sequence", pActivityName );
if ( !pSequenceName || !pSequenceName[ 0 ] )
return;
// Apply to text panel
m_pData->SetText( pSequenceName );
SetDirty(true);
if ( IsAutoApply() )
{
Apply();
}
}
@@ -0,0 +1,85 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "dme_controls/AttributeSoundPickerPanel.h"
#include "dme_controls/soundpicker.h"
#include "tier1/KeyValues.h"
#include "dme_controls/AttributeTextEntry.h"
#include "datamodel/dmelement.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CAttributeSoundPickerPanel::CAttributeSoundPickerPanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
BaseClass( parent, info )
{
}
CAttributeSoundPickerPanel::~CAttributeSoundPickerPanel()
{
}
//-----------------------------------------------------------------------------
// Called when it's time to show the sound picker
//-----------------------------------------------------------------------------
void CAttributeSoundPickerPanel::ShowPickerDialog()
{
// Open file
CSoundPicker::PickType_t pickType = CSoundPicker::PICK_ALL;
const char *pTextType = GetTextType();
if ( pTextType )
{
if ( !Q_stricmp( pTextType, "gamesoundName" ) )
{
pickType = CSoundPicker::PICK_GAMESOUNDS;
}
else if ( !Q_stricmp( pTextType, "wavName" ) )
{
pickType = CSoundPicker::PICK_WAVFILES;
}
}
const char *pCurrentSound = GetAttributeValue<CUtlString>().Get();
CSoundPickerFrame *pSoundPickerDialog = new CSoundPickerFrame( this, "Select sound", pickType );
pSoundPickerDialog->AddActionSignalTarget( this );
if ( pickType == CSoundPicker::PICK_ALL )
{
pickType = CSoundPicker::PICK_NONE;
}
pSoundPickerDialog->DoModal( pickType, pCurrentSound );
}
//-----------------------------------------------------------------------------
// Called when the sound picker has picked a sound
//-----------------------------------------------------------------------------
void CAttributeSoundPickerPanel::OnSoundSelected( KeyValues *pKeyValues )
{
// We're either going to get an activity or sequence name
const char *pGameSoundName = pKeyValues->GetString( "gamesound", NULL );
const char *pSoundName = pKeyValues->GetString( "wav", pGameSoundName );
if ( !pSoundName || !pSoundName[ 0 ] )
return;
// Apply to text panel
m_pData->SetText( pSoundName );
SetDirty(true);
if ( IsAutoApply() )
{
Apply();
}
}
@@ -0,0 +1,169 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "dme_controls/AttributeStringChoicePanel.h"
#include "tier1/KeyValues.h"
#include "vgui_controls/ComboBox.h"
#include "datamodel/dmelement.h"
#include "datamodel/dmelementfactoryhelper.h"
#include "dme_controls/inotifyui.h"
#include "dme_controls/dmecontrols.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
// Expose DmeEditorAttributeInfo to the scene database
//-----------------------------------------------------------------------------
IMPLEMENT_ELEMENT_FACTORY( DmeEditorStringChoicesInfo, CDmeEditorStringChoicesInfo );
//-----------------------------------------------------------------------------
// Constructor, destructor
//-----------------------------------------------------------------------------
void CDmeEditorStringChoicesInfo::OnConstruction()
{
}
void CDmeEditorStringChoicesInfo::OnDestruction()
{
}
//-----------------------------------------------------------------------------
// Add a choice
//-----------------------------------------------------------------------------
CDmElement *CDmeEditorStringChoicesInfo::AddChoice( const char *pValueString, const char *pChoiceString )
{
CDmElement *pChoice = CreateChoice( pChoiceString );
pChoice->SetValue<CUtlString>( "value", pValueString );
return pChoice;
}
//-----------------------------------------------------------------------------
// Gets the choices
//-----------------------------------------------------------------------------
const char *CDmeEditorStringChoicesInfo::GetChoiceValue( int nIndex ) const
{
Assert( ( nIndex < GetChoiceCount() ) && ( nIndex >= 0 ) );
CDmElement *pChoice = m_Choices[nIndex];
if ( !pChoice )
return 0;
return pChoice->GetValue<CUtlString>( "value" );
}
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CAttributeStringChoicePanel::CAttributeStringChoicePanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
BaseClass( parent, info )
{
}
//-----------------------------------------------------------------------------
// Derived classes can re-implement this to fill the combo box however they like
//-----------------------------------------------------------------------------
void CAttributeStringChoicePanel::PopulateComboBox( vgui::ComboBox *pComboBox )
{
pComboBox->DeleteAllItems();
CDmeEditorStringChoicesInfo *pInfo = CastElement<CDmeEditorStringChoicesInfo>( GetEditorInfo() );
if ( !pInfo )
return;
// Fill in the standard choices first
int c = pInfo->GetChoiceCount();
for ( int i = 0; i < c; ++i )
{
KeyValues *kv = new KeyValues( "entry" );
kv->SetString( "value", pInfo->GetChoiceValue( i ) );
pComboBox->AddItem( pInfo->GetChoiceString( i ) , kv );
}
// Add the dynamic choices next
if ( pInfo->HasChoiceType() )
{
StringChoiceList_t choices;
if ( ElementPropertiesChoices()->GetStringChoiceList( pInfo->GetChoiceType(), GetPanelElement(), GetAttributeName(), IsArrayEntry(), choices ) )
{
c = choices.Count();
for ( int i = 0; i < c; ++i )
{
KeyValues *kv = new KeyValues( "entry" );
kv->SetString( "value", choices[i].m_pValue );
pComboBox->AddItem( choices[i].m_pChoiceString, kv );
}
}
}
}
//-----------------------------------------------------------------------------
// Sets the attribute based on the combo box
//-----------------------------------------------------------------------------
void CAttributeStringChoicePanel::SetAttributeFromComboBox( vgui::ComboBox *pComboBox, KeyValues *pKeyValues )
{
const char *pOldString = GetAttributeValue<CUtlString>();
const char *pNewString = pKeyValues->GetString( "value", "" );
if ( pOldString == pNewString )
return;
CElementTreeUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, GetNotify(), "Set Attribute Value", "Set Attribute Value" );
SetAttributeValue( pNewString );
}
//-----------------------------------------------------------------------------
// Sets the combo box from the attribute
//-----------------------------------------------------------------------------
void CAttributeStringChoicePanel::SetComboBoxFromAttribute( vgui::ComboBox *pComboBox )
{
CDmeEditorStringChoicesInfo *pInfo = CastElement<CDmeEditorStringChoicesInfo>( GetEditorInfo() );
if ( !pInfo )
return;
const char *pValue = GetAttributeValue<CUtlString>();
int c = pInfo->GetChoiceCount();
for ( int i = 0; i < c; ++i )
{
if ( !Q_stricmp( pValue, pInfo->GetChoiceValue( i ) ) )
{
pComboBox->SetText( pInfo->GetChoiceString( i ) );
return;
}
}
// Check the dynamic choices next
if ( pInfo->HasChoiceType() )
{
StringChoiceList_t choices;
if ( ElementPropertiesChoices()->GetStringChoiceList( pInfo->GetChoiceType(), GetPanelElement(), GetAttributeName(), IsArrayEntry(), choices ) )
{
c = choices.Count();
for ( int i = 0; i < c; ++i )
{
if ( !Q_stricmp( pValue, choices[i].m_pValue ) )
{
pComboBox->SetText( choices[i].m_pChoiceString );
return;
}
}
}
}
pComboBox->SetText( "Unknown value" );
}
+500
View File
@@ -0,0 +1,500 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "dme_controls/AttributeTextEntry.h"
#include "tier1/KeyValues.h"
#include "vgui_controls/Menu.h"
#include "datamodel/dmelement.h"
#include "dme_controls/AttributeTextPanel.h"
#include "vgui/MouseCode.h"
#include "vgui/KeyCode.h"
#include "vgui/IInput.h"
#include "movieobjects/dmeeditortypedictionary.h"
#include "dme_controls/inotifyui.h"
using namespace vgui;
// ----------------------------------------------------------------------------
// CAttributeTextEntry
CAttributeTextEntry::CAttributeTextEntry( Panel *parent, const char *panelName ) :
BaseClass( parent, panelName ),
m_bValueStored( false ),
m_flOriginalValue( 0.0f )
{
SetDragEnabled( true );
SetDropEnabled( true, 0.5f );
m_szOriginalText[ 0 ] = 0;
AddActionSignalTarget( this );
}
void CAttributeTextEntry::ApplySchemeSettings( IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
SetBorder(NULL);
//HFont font = pScheme->GetFont( "DmePropertyVerySmall", IsProportional() );
//SetFont(font);
}
//-----------------------------------------------------------------------------
// Returns the parent panel
//-----------------------------------------------------------------------------
inline CAttributeTextPanel *CAttributeTextEntry::GetParentAttributePanel()
{
return static_cast< CAttributeTextPanel * >( GetParent() );
}
//-----------------------------------------------------------------------------
// Drag + drop
//-----------------------------------------------------------------------------
bool CAttributeTextEntry::GetDropContextMenu( Menu *menu, CUtlVector< KeyValues * >& msglist )
{
menu->AddMenuItem( "Drop as Text", "#BxDropText", "droptext", this );
return true;
}
bool CAttributeTextEntry::IsDroppable( CUtlVector< KeyValues * >& msglist )
{
if ( !IsEnabled() )
return false;
if ( msglist.Count() != 1 )
return false;
KeyValues *msg = msglist[ 0 ];
Panel *draggedPanel = ( Panel * )msg->GetPtr( "panel", NULL );
if ( draggedPanel == GetParent() )
return false;
CAttributeTextPanel *pPanel = GetParentAttributePanel();
if ( !pPanel )
return false;
// If a specific text type is specified, then filter if it doesn't match
const char *pTextType = pPanel->GetTextType();
if ( pTextType[0] )
{
const char *pMsgTextType = msg->GetString( "texttype" );
if ( Q_stricmp( pTextType, pMsgTextType ) )
return false;
}
DmAttributeType_t t = pPanel->GetAttributeType();
switch ( t )
{
default:
break;
case AT_ELEMENT:
{
CDmElement *ptr = reinterpret_cast< CDmElement * >( g_pDataModel->GetElement( DmElementHandle_t( msg->GetInt( "root" ) ) ) );
if ( ptr )
{
return true;
}
return false;
}
break;
case AT_ELEMENT_ARRAY:
return false;
}
return true;
}
void CAttributeTextEntry::OnPanelDropped( CUtlVector< KeyValues * >& msglist )
{
if ( msglist.Count() != 1 )
return;
KeyValues *data = msglist[ 0 ];
Panel *draggedPanel = ( Panel * )data->GetPtr( "panel", NULL );
if ( draggedPanel == GetParent() )
return;
CAttributeTextPanel *pPanel = GetParentAttributePanel();
if ( !pPanel )
return;
// If a specific text type is specified, then filter if it doesn't match
const char *pTextType = pPanel->GetTextType();
if ( pTextType[0] )
{
const char *pMsgTextType = data->GetString( "texttype" );
if ( Q_stricmp( pTextType, pMsgTextType ) )
return;
}
const char *cmd = data->GetString( "command" );
if ( !Q_stricmp( cmd, "droptext" ) || !Q_stricmp( cmd, "default" ) )
{
DmAttributeType_t t = pPanel->GetAttributeType();
switch ( t )
{
default:
{
pPanel->SetDirty( true );
SetText( data->GetString( "text" ) );
if ( pPanel->IsAutoApply() )
{
pPanel->Apply();
}
}
break;
case AT_ELEMENT:
{
CDmElement *ptr = reinterpret_cast< CDmElement * >( g_pDataModel->GetElement( DmElementHandle_t( data->GetInt( "root" ) ) ) );
if ( !ptr )
{
break;
}
pPanel->SetDirty( true );
SetText( data->GetString( "text" ) );
if ( pPanel->IsAutoApply() )
{
pPanel->Apply();
}
}
break;
case AT_ELEMENT_ARRAY:
Assert( 0 );
break;
}
}
StoreInitialValue( true );
}
//-----------------------------------------------------------------------------
// Enter causes changes to be applied
//-----------------------------------------------------------------------------
void CAttributeTextEntry::OnKeyCodeTyped(KeyCode code)
{
bool bCtrl = (input()->IsKeyDown(KEY_LCONTROL) || input()->IsKeyDown(KEY_RCONTROL));
switch ( code )
{
case KEY_ENTER:
{
CAttributeTextPanel *pPanel = GetParentAttributePanel();
if ( !pPanel->IsAutoApply() )
{
pPanel->Apply();
StoreInitialValue( true );
}
else
{
WriteValueToAttribute();
}
}
break;
// Override the base class undo feature, it behaves poorly when typing in data
case KEY_Z:
if ( bCtrl )
{
WriteInitialValueToAttribute( );
break;
}
// NOTE: Fall through to default if it's not Ctrl-Z
default:
BaseClass::OnKeyCodeTyped(code);
break;
}
}
void CAttributeTextEntry::OnTextChanged( KeyValues *data )
{
m_bValueStored = true;
}
//-----------------------------------------------------------------------------
// We'll only create an "undo" record if the values differ upon focus change
//-----------------------------------------------------------------------------
void CAttributeTextEntry::StoreInitialValue( bool bForce )
{
// Already storing value???
if ( m_bValueStored && !bForce )
return;
m_bValueStored = true;
CAttributeTextPanel *pPanel = GetParentAttributePanel();
Assert( pPanel );
switch ( pPanel->GetAttributeType() )
{
case AT_FLOAT:
m_flOriginalValue = pPanel->GetAttributeValue<float>( );
break;
case AT_INT:
m_nOriginalValue = pPanel->GetAttributeValue<int>( );
break;
case AT_BOOL:
m_bOriginalValue = pPanel->GetAttributeValue<bool>( );
break;
default:
GetText( m_szOriginalText, sizeof( m_szOriginalText ) );
break;
}
}
//-----------------------------------------------------------------------------
// Performs undo
//-----------------------------------------------------------------------------
void CAttributeTextEntry::WriteInitialValueToAttribute( )
{
// Already storing value???
if ( !m_bValueStored )
return;
CDisableUndoScopeGuard guard;
CAttributeTextPanel *pPanel = GetParentAttributePanel();
Assert( pPanel );
switch ( pPanel->GetAttributeType() )
{
case AT_FLOAT:
pPanel->SetAttributeValue( m_flOriginalValue );
break;
case AT_INT:
pPanel->SetAttributeValue( m_nOriginalValue );
break;
case AT_BOOL:
pPanel->SetAttributeValue<bool>( m_bOriginalValue );
break;
default:
pPanel->SetAttributeValueFromString( m_szOriginalText );
break;
}
pPanel->SetDirty( false );
pPanel->Refresh();
}
//-----------------------------------------------------------------------------
// We'll only create an "undo" record if the values differ upon focus change
//-----------------------------------------------------------------------------
void CAttributeTextEntry::OnSetFocus()
{
BaseClass::OnSetFocus();
StoreInitialValue();
}
//-----------------------------------------------------------------------------
// Called when focus is lost
//-----------------------------------------------------------------------------
template<class T>
void CAttributeTextEntry::ApplyMouseWheel( T newValue, T originalValue )
{
CAttributeTextPanel *pPanel = GetParentAttributePanel();
// Kind of an evil hack, but "undo" copies the "old value" off for doing undo, and that value is the new value because
// we haven't been tracking undo while manipulating this. So we'll turn off undo and set the value to the original value.
// In effect, all of the wheeling will drop out and it'll look just like we started at the original value and ended up at the
// final value...
{
CDisableUndoScopeGuard guard;
pPanel->SetAttributeValue( originalValue );
}
if ( pPanel->IsAutoApply() )
{
pPanel->Apply();
}
else
{
CElementTreeUndoScopeGuard guard( 0, pPanel->GetNotify(), "Set Attribute Value", "Set Attribute Value" );
pPanel->SetAttributeValue( newValue );
}
}
void CAttributeTextEntry::WriteValueToAttribute()
{
if ( !m_bValueStored )
return;
m_bValueStored = false;
char newText[ MAX_TEXT_LENGTH ];
GetText( newText, sizeof( newText ) );
CAttributeTextPanel *pPanel = GetParentAttributePanel();
Assert( pPanel );
switch (pPanel->GetAttributeType() )
{
case AT_FLOAT:
ApplyMouseWheel( (float)atof(newText), m_flOriginalValue );
break;
case AT_INT:
ApplyMouseWheel( atoi(newText), m_nOriginalValue );
break;
case AT_BOOL:
ApplyMouseWheel( atoi(newText) != 0, m_bOriginalValue );
break;
default:
if ( Q_strcmp( newText, m_szOriginalText ) )
{
pPanel->SetDirty( true );
if ( pPanel->IsAutoApply() )
{
pPanel->Apply();
StoreInitialValue( true );
}
}
else
{
pPanel->SetDirty( false );
}
break;
}
}
//-----------------------------------------------------------------------------
// Called when focus is lost
//-----------------------------------------------------------------------------
void CAttributeTextEntry::OnKillFocus()
{
BaseClass::OnKillFocus();
WriteValueToAttribute();
StoreInitialValue();
}
void CAttributeTextEntry::OnMouseWheeled( int delta )
{
// Must have *keyboard* focus for it to work
if ( !HasFocus() )
{
// Otherwise, let the base class scroll up + down
BaseClass::OnMouseWheeled( delta );
return;
}
CAttributeTextPanel *pPanel = GetParentAttributePanel();
if ( pPanel->GetDirty() )
{
if ( pPanel->IsAutoApply() )
{
pPanel->Apply();
StoreInitialValue( true );
}
else
{
// FIXME: Make this work for non-auto-apply panels
}
}
switch ( pPanel->GetAttributeType() )
{
case AT_FLOAT:
{
float deltaFactor;
if ( input()->IsKeyDown(KEY_LSHIFT) )
{
deltaFactor = ((float)delta) * 10.0f;
}
else if ( input()->IsKeyDown(KEY_LCONTROL) )
{
deltaFactor = ((float)delta) / 100.0;
}
else
{
deltaFactor = ((float)delta) / 10.0;
}
float val = pPanel->GetAttributeValue<float>() + deltaFactor;
if ( input()->IsKeyDown(KEY_LALT) )
{
//val = clamp(val, 0.0, 1.0);
val = (val > 1) ? 1 : ((val < 0) ? 0 : val);
}
{
// Note, these calls to Set won't create Undo Records,
// since we'll check the value in SetFocus/KillFocus so that we
// don't gum up the undo system with hundreds of records...
CDisableUndoScopeGuard guard;
pPanel->SetAttributeValue( val );
}
}
break;
case AT_INT:
{
if ( input()->IsKeyDown(KEY_LSHIFT) )
{
delta *= 10;
}
int val = pPanel->GetAttributeValue<int>() + delta;
{
// Note, these calls to Set won't create Undo Records,
// since we'll check the value in SetFocus/KillFocus so that we
// don't gum up the undo system with hundreds of records...
CDisableUndoScopeGuard guard;
pPanel->SetAttributeValue( val );
}
}
break;
case AT_BOOL:
{
bool val = !pPanel->GetAttributeValue<bool>();
{
// Note, these calls to Set won't create Undo Records,
// since we'll check the value in SetFocus/KillFocus so that we
// don't gum up the undo system with hundreds of records...
CDisableUndoScopeGuard guard;
pPanel->SetAttributeValue( val );
}
}
break;
default:
return;
}
pPanel->Refresh();
if ( pPanel->IsAutoApply() )
{
// NOTE: Don't call Apply since that generates an undo record
CElementTreeNotifyScopeGuard notify( "CAttributeTextEntry::OnMouseWheeled", NOTIFY_CHANGE_ATTRIBUTE_VALUE | NOTIFY_SETDIRTYFLAG, pPanel->GetNotify() );
}
else
{
pPanel->SetDirty( true );
}
//SetDirty(true);
//UpdateTime( m_flLastMouseTime );
//UpdateZoom( -10.0f * delta );
//UpdateTransform();
}
// ----------------------------------------------------------------------------
+119
View File
@@ -0,0 +1,119 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "dme_controls/AttributeTextPanel.h"
#include "dme_controls/AttributeTextEntry.h"
#include "dme_controls/AttributeWidgetFactory.h"
#include "tier1/KeyValues.h"
#include "datamodel/dmelement.h"
#include "movieobjects/dmeeditortypedictionary.h"
#include "dme_controls/inotifyui.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
// CAttributeTextPanel constructor
//-----------------------------------------------------------------------------
CAttributeTextPanel::CAttributeTextPanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
BaseClass( parent, info ), m_pData( 0 ), m_bShowMemoryUsage( info.m_bShowMemoryUsage )
{
m_pData = new CAttributeTextEntry( this, "AttributeValue" );
m_pData->SetEnabled( !HasFlag( READONLY ) );
m_pData->AddActionSignalTarget(this);
SetAllowKeyBindingChainToParent( false );
}
void CAttributeTextPanel::SetFont( HFont font )
{
BaseClass::SetFont( font );
m_pData->SetFont( font );
}
//-----------------------------------------------------------------------------
// Returns the text type
//-----------------------------------------------------------------------------
const char *CAttributeTextPanel::GetTextType()
{
// If a specific text type is specified, then filter if it doesn't match
CDmeEditorAttributeInfo *pInfo = GetEditorInfo();
const char *pTextType = pInfo ? pInfo->GetValueString( "texttype" ) : NULL;
return pTextType ? pTextType : "";
}
void CAttributeTextPanel::Apply()
{
char txt[ 256 ];
m_pData->GetText( txt, sizeof( txt ) );
// Apply means we no longer look blue
SetDirty( false );
if ( GetAttributeType( ) == AT_UNKNOWN )
{
CElementTreeUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, GetNotify(), "Set Attribute Value", "Set Attribute Value" );
SetAttributeValue( "" );
return;
}
char curvalue[ 256 ];
GetAttributeValueAsString( curvalue, sizeof( curvalue ) );
// Only if differnt
if ( Q_strcmp( curvalue, txt ) )
{
CElementTreeUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, GetNotify(), "Set Attribute Value", "Set Attribute Value" );
SetAttributeValueFromString( txt );
}
}
vgui::Panel *CAttributeTextPanel::GetDataPanel()
{
return static_cast< vgui::Panel * >( m_pData );
}
void CAttributeTextPanel::Refresh()
{
char buf[ 512 ];
if ( IsArrayType( GetAttributeType() ) )
{
int count = GetAttributeArrayCount();
if ( m_bShowMemoryUsage )
{
CDmAttribute *pAttr = GetPanelElement()->GetAttribute( GetAttributeName() );
Q_snprintf( buf, sizeof( buf ), "%d items %.3fMB", count, pAttr->EstimateMemoryUsage( TD_DEEP ) / float( 1 << 20 ) );
}
else
{
Q_snprintf( buf, sizeof( buf ), "%d items", count );
}
m_pData->SetText( buf );
m_pData->SetEnabled(false);
}
else if ( GetAttributeType() == AT_ELEMENT )
{
m_pData->SetText( "" );
}
else
{
GetAttributeValueAsString( buf, sizeof( buf ) );
m_pData->SetText( buf );
}
}
void CAttributeTextPanel::PostConstructor()
{
Refresh();
}
@@ -0,0 +1,370 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "dme_controls/AttributeWidgetFactory.h"
#include "tier1/utldict.h"
#include "tier1/KeyValues.h"
#include "movieobjects/dmeeditortypedictionary.h"
#include "dme_controls/AttributeTextEntry.h"
#include "dme_controls/AttributeFilePickerPanel.h"
#include "dme_controls/AttributeBoolChoicePanel.h"
#include "dme_controls/AttributeIntChoicePanel.h"
#include "dme_controls/AttributeStringChoicePanel.h"
#include "dme_controls/AttributeElementPanel.h"
#include "dme_controls/AttributeElementPickerPanel.h"
#include "dme_controls/AttributeMDLPickerPanel.h"
#include "dme_controls/AttributeSequencePickerPanel.h"
#include "dme_controls/AttributeSoundPickerPanel.h"
#include "dme_controls/AttributeAssetPickerPanel.h"
#include "dme_controls/AttributeShaderPickerPanel.h"
#include "dme_controls/AttributeSurfacePropertyPickerPanel.h"
#include "dme_controls/AttributeDetailTypePickerPanel.h"
#include "dme_controls/AttributeColorPickerPanel.h"
#include "dme_controls/AttributeInterpolatorChoicePanel.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
//-----------------------------------------------------------------------------
// Forward declaration
//-----------------------------------------------------------------------------
class CAttributeWidgetFactoryList;
using namespace vgui;
//-----------------------------------------------------------------------------
// CAttributeWidgetFactoryList class definition
//-----------------------------------------------------------------------------
class CAttributeWidgetFactoryList : public IAttributeWidgetFactoryList
{
public:
// Inherited from IAttributeWidgetFactoryList
virtual IAttributeWidgetFactory *GetWidgetFactory( const char *pWidgetName );
virtual IAttributeWidgetFactory *GetWidgetFactory( CDmElement *object, CDmAttribute *pAttribute, CDmeEditorTypeDictionary *pTypeDictionary );
virtual IAttributeWidgetFactory *GetArrayWidgetFactory( CDmElement *object, CDmAttribute *pAttribute, CDmeEditorTypeDictionary *pTypeDictionary );
virtual void ApplyChanges( vgui::Panel *pWidget, vgui::Panel *pSender = NULL );
virtual void Refresh( vgui::Panel *pWidget, vgui::Panel *pSender = NULL );
// Adds a widget to the factory
void AddWidgetFactory( IAttributeWidgetFactory *pFactory, const char *pWidgetName );
// Finds a widget factory by name
IAttributeWidgetFactory *FindWidgetFactory( const char *pWidgetName );
// Creates a widget using editor attribute info
// vgui::Panel *CreateWidget( vgui::Panel *parent, CDmElement *obj, INotifyUI *pNotify, CDmeEditorAttributeInfo *pWidgetInfo, bool bAutoApply );
private:
CUtlDict< IAttributeWidgetFactory*, unsigned short > m_Factories;
};
//-----------------------------------------------------------------------------
// Singleton instance
//-----------------------------------------------------------------------------
static CAttributeWidgetFactoryList *g_pWidgetFactoryFactoryList;
IAttributeWidgetFactoryList *attributewidgetfactorylist;
CAttributeWidgetFactoryList *GetWidgetFactoryManager()
{
if ( !g_pWidgetFactoryFactoryList )
{
g_pWidgetFactoryFactoryList = new CAttributeWidgetFactoryList;
attributewidgetfactorylist = g_pWidgetFactoryFactoryList;
}
return g_pWidgetFactoryFactoryList;
}
//-----------------------------------------------------------------------------
// Standard implementation of a widget factory
//-----------------------------------------------------------------------------
template < class T >
class CAttributeWidgetFactory : public IAttributeWidgetFactory
{
public:
CAttributeWidgetFactory( const char *pWidgetName )
{
GetWidgetFactoryManager()->AddWidgetFactory( this, pWidgetName );
}
// Backward compat
virtual vgui::Panel *Create( vgui::Panel *pParent, const AttributeWidgetInfo_t &info )
{
CBaseAttributePanel *newPanel = new T( pParent, info );
if ( newPanel )
{
newPanel->PostConstructor();
}
return newPanel;
}
};
//-----------------------------------------------------------------------------
// create all the AttributeWidgetFactorys
//-----------------------------------------------------------------------------
// An Attribute Widget Factory for: text entry
static CAttributeWidgetFactory<CAttributeTextPanel> g_AttributeTextWidgetFactory( "text" );
// An Attribute Widget Factory for: picking files
static CAttributeWidgetFactory<CAttributeDmeFilePickerPanel> g_AttributeFilePickerWidgetFactory( "filepicker" );
// An Attribute Widget Factory for: choosing integers
static CAttributeWidgetFactory<CAttributeBoolChoicePanel> g_AttributeBoolChoiceWidgetFactory( "boolchoice" );
// An Attribute Widget Factory for: choosing integers
static CAttributeWidgetFactory<CAttributeIntChoicePanel> g_AttributeIntChoiceWidgetFactory( "intchoice" );
// An Attribute Widget Factory for: choosing strings
static CAttributeWidgetFactory<CAttributeStringChoicePanel> g_AttributeStringChoiceWidgetFactory( "stringchoice" );
// An Attribute Widget Factory for: elements
static CAttributeWidgetFactory<CAttributeElementPanel> g_AttributeElementWidgetFactory( "element" );
// An Attribute Widget Factory for: picking elements
static CAttributeWidgetFactory<CAttributeElementPickerPanel> g_AttributeElementPickerWidgetFactory( "elementchoice" );
// An Attribute Widget Factory for: picking MDLs
static CAttributeWidgetFactory<CAttributeMDLPickerPanel> g_AttributeMDLPickerWidgetFactory( "mdlpicker" );
// An Attribute Widget Factory for: picking sequences
static CAttributeWidgetFactory<CAttributeSequencePickerPanel> g_AttributeSequencePickerWidgetFactory( "sequencepicker" );
// An Attribute Widget Factory for: picking sounds
static CAttributeWidgetFactory<CAttributeSoundPickerPanel> g_AttributeSoundPickerWidgetFactory( "soundpicker" );
// An Attribute Widget Factory for: picking bsps
static CAttributeWidgetFactory<CAttributeBspPickerPanel> g_AttributeBspPickerWidgetFactory( "bsppicker" );
// An Attribute Widget Factory for: picking vmts
static CAttributeWidgetFactory<CAttributeVmtPickerPanel> g_AttributeVmtPickerWidgetFactory( "vmtpicker" );
// An Attribute Widget Factory for: picking vtfs
static CAttributeWidgetFactory<CAttributeVtfPickerPanel> g_AttributeVtfPickerWidgetFactory( "vtfpicker" );
// An Attribute Widget Factory for: picking tgas
static CAttributeWidgetFactory<CAttributeTgaFilePickerPanel> g_AttributeTgaPickerWidgetFactory( "tgapicker" );
// An Attribute Widget Factory for: picking shaders
static CAttributeWidgetFactory<CAttributeShaderPickerPanel> g_AttributeShaderPickerWidgetFactory( "shaderpicker" );
// An Attribute Widget Factory for: picking surface properties
static CAttributeWidgetFactory<CAttributeSurfacePropertyPickerPanel> g_AttributeSurfacePropertyPickerWidgetFactory( "surfacepropertypicker" );
// An Attribute Widget Factory for: picking surface properties
static CAttributeWidgetFactory<CAttributeColorPickerPanel> g_AttributeColorPickerWidgetFactory( "colorpicker" );
// An Attribute Widget Factory for: picking avis
static CAttributeWidgetFactory<CAttributeAviFilePickerPanel> g_AttributeAviPickerWidgetFactory( "avipicker" );
// An Attribute Widget Factory for: picking sht
static CAttributeWidgetFactory<CAttributeShtFilePickerPanel> g_AttributeShtPickerWidgetFactory( "shtpicker" );
// An Attribute Widget Factory for: picking detail types
static CAttributeWidgetFactory<CAttributeDetailTypePickerPanel> g_AttributeDetailTypePickerWidgetFactory( "detailtypepicker" );
// An Attribute Widget Factory for: picking color correction lookup files
static CAttributeWidgetFactory<CAttributeRawFilePickerPanel> g_AttributeRawPickerWidgetFactory( "rawpicker" );
// An Attribute Widget Factory for: choosing interpolator types (left and right)
static CAttributeWidgetFactory<CAttributeInterpolatorChoicePanel> g_AttributeInterpolatorChoiceWidgetFactory( "interpolatorchoice" );
//-----------------------------------------------------------------------------
// Name-based widget factories
//-----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// g_AttributeWidgetFactories
// Purpose: a mapping of all attribute types to AttributeWidgetFactories
struct DefaultAttributeFactoryEntry_t
{
int attributeType;
IAttributeWidgetFactory *factory;
};
static DefaultAttributeFactoryEntry_t g_AttributeWidgetFactories[] =
{
{ AT_UNKNOWN, NULL },
{ AT_ELEMENT, &g_AttributeElementWidgetFactory },
{ AT_INT, &g_AttributeTextWidgetFactory },
{ AT_FLOAT, &g_AttributeTextWidgetFactory },
{ AT_BOOL, &g_AttributeTextWidgetFactory },
{ AT_STRING, &g_AttributeTextWidgetFactory },
{ AT_VOID, &g_AttributeTextWidgetFactory },
{ AT_OBJECTID, &g_AttributeTextWidgetFactory },
{ AT_COLOR, &g_AttributeColorPickerWidgetFactory },
{ AT_VECTOR2, &g_AttributeTextWidgetFactory },
{ AT_VECTOR3, &g_AttributeTextWidgetFactory },
{ AT_VECTOR4, &g_AttributeTextWidgetFactory },
{ AT_QANGLE, &g_AttributeTextWidgetFactory },
{ AT_QUATERNION, &g_AttributeTextWidgetFactory },
{ AT_VMATRIX, &g_AttributeTextWidgetFactory },
{ AT_ELEMENT_ARRAY, &g_AttributeTextWidgetFactory },
{ AT_INT_ARRAY, &g_AttributeTextWidgetFactory },
{ AT_FLOAT_ARRAY, &g_AttributeTextWidgetFactory },
{ AT_BOOL_ARRAY, &g_AttributeTextWidgetFactory },
{ AT_STRING_ARRAY, &g_AttributeTextWidgetFactory },
{ AT_VOID_ARRAY, &g_AttributeTextWidgetFactory },
{ AT_ELEMENT_ARRAY, &g_AttributeTextWidgetFactory },
{ AT_OBJECTID_ARRAY, &g_AttributeTextWidgetFactory },
{ AT_COLOR_ARRAY, &g_AttributeColorPickerWidgetFactory },
{ AT_VECTOR2_ARRAY, &g_AttributeTextWidgetFactory },
{ AT_VECTOR3_ARRAY, &g_AttributeTextWidgetFactory },
{ AT_VECTOR4_ARRAY, &g_AttributeTextWidgetFactory },
{ AT_QANGLE_ARRAY, &g_AttributeTextWidgetFactory },
{ AT_QUATERNION_ARRAY, &g_AttributeTextWidgetFactory },
{ AT_VMATRIX_ARRAY, &g_AttributeTextWidgetFactory },
};
//-----------------------------------------------------------------------------
//
// CAttributeWidgetFactoryList
//
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Adds a widget to the factory
//-----------------------------------------------------------------------------
void CAttributeWidgetFactoryList::AddWidgetFactory( IAttributeWidgetFactory *pFactory, const char *pWidgetName )
{
m_Factories.Insert( pWidgetName, pFactory );
}
//-----------------------------------------------------------------------------
// Finds a widget factory by name
//-----------------------------------------------------------------------------
IAttributeWidgetFactory *CAttributeWidgetFactoryList::FindWidgetFactory( const char *pWidgetName )
{
unsigned short i = m_Factories.Find( pWidgetName );
if ( i != m_Factories.InvalidIndex() )
return m_Factories[i];
return NULL;
}
//-----------------------------------------------------------------------------
// Returns a factory requested by name
//-----------------------------------------------------------------------------
IAttributeWidgetFactory *CAttributeWidgetFactoryList::GetWidgetFactory( const char *pWidgetName )
{
return FindWidgetFactory( pWidgetName );
}
//-----------------------------------------------------------------------------
// Returns a factory used to create widget for the attribute passed in
//-----------------------------------------------------------------------------
IAttributeWidgetFactory *CAttributeWidgetFactoryList::GetWidgetFactory( CDmElement *object,
CDmAttribute *pAttribute, CDmeEditorTypeDictionary *pTypeDictionary )
{
if ( !object )
return NULL;
DmAttributeType_t attributeType = pAttribute->GetType();
IAttributeWidgetFactory *pFactory = g_AttributeWidgetFactories[ attributeType ].factory;
// Override behavior with editor info, if it exists
if ( pTypeDictionary )
{
const char *pAttributeName = pAttribute->GetName();
CDmeEditorAttributeInfo *pEditorInfo = pTypeDictionary->GetAttributeInfo( object, pAttributeName );
if ( pEditorInfo )
{
if ( !pEditorInfo->m_bIsVisible )
return NULL;
if ( pEditorInfo->GetWidgetName() )
{
IAttributeWidgetFactory *pOverriddenFactory = g_pWidgetFactoryFactoryList->FindWidgetFactory( pEditorInfo->GetWidgetName() );
if ( pOverriddenFactory )
{
pFactory = pOverriddenFactory;
}
}
}
}
return pFactory;
}
//-----------------------------------------------------------------------------
// Returns a factory used to create widgets for entries in an attribute array
//-----------------------------------------------------------------------------
IAttributeWidgetFactory *CAttributeWidgetFactoryList::GetArrayWidgetFactory( CDmElement *object,
CDmAttribute *pAttribute, CDmeEditorTypeDictionary *pTypeDictionary )
{
if ( !object )
return NULL;
DmAttributeType_t attributeType = ArrayTypeToValueType( pAttribute->GetType() );
IAttributeWidgetFactory *pFactory = g_AttributeWidgetFactories[ attributeType ].factory;
// Override behavior with editor info, if it exists
if ( pTypeDictionary )
{
CDmeEditorAttributeInfo *pEditorInfo = pTypeDictionary->GetAttributeArrayInfo( object, pAttribute->GetName() );
if ( pEditorInfo )
{
if ( !pEditorInfo->m_bIsVisible )
return NULL;
if ( pEditorInfo->GetWidgetName() )
{
IAttributeWidgetFactory *pOverriddenFactory = g_pWidgetFactoryFactoryList->FindWidgetFactory( pEditorInfo->GetWidgetName() );
if ( pOverriddenFactory )
{
pFactory = pOverriddenFactory;
}
}
}
}
return pFactory;
}
//-----------------------------------------------------------------------------
// Applies changes to a widget
//-----------------------------------------------------------------------------
void CAttributeWidgetFactoryList::ApplyChanges( vgui::Panel *pWidget, vgui::Panel *pSender )
{
CBaseAttributePanel *pPanel = dynamic_cast< CBaseAttributePanel *>( pWidget );
if ( pPanel && pPanel->GetDirty() )
{
Assert( !pPanel->IsAutoApply() );
vgui::ipanel()->SendMessage( pWidget->GetVPanel(), new KeyValues( "ApplyChanges" ), pSender ? pSender->GetVPanel() : NULL );
}
}
//-----------------------------------------------------------------------------
// Refreshes a widget when attributes change
//-----------------------------------------------------------------------------
void CAttributeWidgetFactoryList::Refresh( vgui::Panel *pWidget, vgui::Panel *pSender )
{
if ( pWidget )
{
vgui::ipanel()->SendMessage( pWidget->GetVPanel(), new KeyValues( "Refresh" ), pSender ? pWidget->GetVPanel() : NULL );
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,523 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================
#include "dme_controls/BaseAnimSetControlGroupPanel.h"
#include "vgui_controls/TreeView.h"
#include "vgui_controls/Menu.h"
#include "tier1/KeyValues.h"
#include "movieobjects/dmeanimationset.h"
#include "dme_controls/BaseAnimSetAttributeSliderPanel.h"
#include "dme_controls/BaseAnimationSetEditor.h"
#include "dme_controls/dmecontrols_utils.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
// Shows the tree view of the animation groups
//-----------------------------------------------------------------------------
class CAnimGroupTree : public TreeView
{
DECLARE_CLASS_SIMPLE( CAnimGroupTree, TreeView );
public:
CAnimGroupTree( Panel *parent, const char *panelName, CBaseAnimSetControlGroupPanel *groupPanel );
virtual ~CAnimGroupTree();
virtual bool IsItemDroppable( int itemIndex, CUtlVector< KeyValues * >& msglist );
virtual void OnItemDropped( int itemIndex, CUtlVector< KeyValues * >& msglist );
virtual void GenerateContextMenu( int itemIndex, int x, int y );
private:
MESSAGE_FUNC( OnImportAnimation, "ImportAnimation" );
void CleanupContextMenu();
vgui::DHANDLE< vgui::Menu > m_hContextMenu;
CBaseAnimSetControlGroupPanel *m_pGroupPanel;
};
CAnimGroupTree::CAnimGroupTree( Panel *parent, const char *panelName, CBaseAnimSetControlGroupPanel *groupPanel ) :
BaseClass( parent, panelName ),
m_pGroupPanel( groupPanel )
{
}
CAnimGroupTree::~CAnimGroupTree()
{
CleanupContextMenu();
}
void CAnimGroupTree::CleanupContextMenu()
{
if ( m_hContextMenu.Get() )
{
delete m_hContextMenu.Get();
m_hContextMenu = NULL;
}
}
bool CAnimGroupTree::IsItemDroppable( int itemIndex, CUtlVector< KeyValues * >& msglist )
{
if ( msglist.Count() != 1 )
return false;
KeyValues *data = msglist[ 0 ];
if ( !data )
return false;
if ( !data->FindKey( "color" ) )
return false;
KeyValues *itemData = GetItemData( itemIndex );
if ( !itemData->FindKey( "handle" ) )
return false;
DmElementHandle_t handle = (DmElementHandle_t)itemData->GetInt( "handle" );
if ( handle == DMELEMENT_HANDLE_INVALID )
return false;
return true;
}
void CAnimGroupTree::OnItemDropped( int itemIndex, CUtlVector< KeyValues * >& msglist )
{
if ( !IsItemDroppable( itemIndex, msglist ) )
return;
KeyValues *data = msglist[ 0 ];
if ( !data )
return;
KeyValues *itemData = GetItemData( itemIndex );
CDmElement *group = GetElementKeyValue< CDmElement >( itemData, "handle" );
Assert( m_pGroupPanel );
Color clr = data->GetColor( "color" );
SetItemFgColor( itemIndex, clr );
SetItemSelectionTextColor( itemIndex, clr );
if ( group )
{
CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, "Change Group Color" );
group->SetValue< Color >( "treeColor", clr );
}
}
void CAnimGroupTree::OnImportAnimation()
{
PostMessage( m_pGroupPanel->m_hEditor, new KeyValues( "ImportAnimation", "visibleOnly", "1" ), 0.0f );
}
// override to open a custom context menu on a node being selected and right-clicked
void CAnimGroupTree::GenerateContextMenu( int itemIndex, int x, int y )
{
CleanupContextMenu();
m_hContextMenu = new Menu( this, "ActionMenu" );
m_hContextMenu->AddMenuItem( "#ImportAnimation", new KeyValues( "ImportAnimation" ), this );
Menu::PlaceContextMenu( this, m_hContextMenu.Get() );
}
CBaseAnimSetControlGroupPanel::CBaseAnimSetControlGroupPanel( vgui::Panel *parent, const char *className, CBaseAnimationSetEditor *editor ) :
BaseClass( parent, className ),
m_bStartItemWasSelected( false ),
m_SliderNames( 0, 0, true )
{
m_hEditor = editor;
m_hGroups = new CAnimGroupTree( this, "AnimSetGroups", this );
m_hGroups->SetMultipleItemDragEnabled( true );
m_hGroups->SetAutoResize
(
Panel::PIN_TOPLEFT,
Panel::AUTORESIZE_DOWNANDRIGHT,
0, 0,
0, 0
);
m_hGroups->SetAllowMultipleSelections( true );
}
CBaseAnimSetControlGroupPanel::~CBaseAnimSetControlGroupPanel()
{
}
static int AddItemToTree( TreeView *tv, const char *label, int parentIndex, const Color& fg, int groupNumber, int handle )
{
Color bgColor( 128, 128, 128, 128 );
KeyValues *kv = new KeyValues( "item", "text", label );
kv->SetInt( "groupNumber", groupNumber );
kv->SetInt( "droppable", 1 );
kv->SetInt( "handle", handle );
int idx = tv->AddItem( kv, parentIndex );
tv->SetItemFgColor( idx, fg );
tv->SetItemSelectionTextColor( idx, fg );
tv->SetItemSelectionBgColor( idx, bgColor );
tv->SetItemSelectionUnfocusedBgColor( idx, bgColor );
tv->RemoveSelectedItem( idx );
tv->ExpandItem( idx, false );
kv->deleteThis();
return idx;
}
void CBaseAnimSetControlGroupPanel::ApplySchemeSettings( IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
m_hGroups->SetFont( pScheme->GetFont( "DefaultBold", IsProportional() ) );
}
void CBaseAnimSetControlGroupPanel::OnTreeViewItemSelectionCleared()
{
// We check the entire group manually
OnTreeViewItemSelected( -1 );
}
void CBaseAnimSetControlGroupPanel::OnTreeViewItemDeselected( int itemIndex )
{
OnTreeViewItemSelected( -1 );
}
void CBaseAnimSetControlGroupPanel::OnTreeViewItemSelected( int itemIndex )
{
if ( !m_AnimSet.Get() )
return;
// Build the list of selected groups, and notify the attribute slider panel
CUtlVector< int > selection;
m_hGroups->GetSelectedItems( selection );
const CDmaElementArray<> &groups = m_AnimSet->GetSelectionGroups();
int groupCount = groups.Count();
int i;
int rootIndex = m_hGroups->GetRootItemIndex();
bool selectionHasRoot = false;
for ( i = 0 ; i < selection.Count(); ++i )
{
if ( selection[ i ] == rootIndex )
{
selectionHasRoot = true;
break;
}
}
m_SliderNames.RemoveAll();
if ( selectionHasRoot )
{
for ( i = 0; i < groups.Count(); ++i )
{
CDmElement *element = groups[ i ];
if ( !element )
continue;
const CDmrStringArray array( element, "selectedControls" );
if ( array.IsValid() )
{
for ( int j = 0 ; j < array.Count(); ++j )
{
const char *sliderName = array[ j ];
if ( sliderName && *sliderName )
{
m_SliderNames.AddString( sliderName );
}
}
}
}
}
else
{
for ( i = 0 ; i < selection.Count(); ++i )
{
if ( selection[ i ] == rootIndex )
continue;
KeyValues *kv = m_hGroups->GetItemData( selection[ i ] );
if ( !kv )
continue;
int groupNumber = kv->GetInt( "groupNumber" );
if ( groupNumber < 0 || groupNumber >= groupCount )
{
const char *sliderName = kv->GetString( "text" );
if ( sliderName && *sliderName )
{
m_SliderNames.AddString( sliderName );
}
continue;
}
CDmElement *element = groups[ groupNumber ];
if ( !element )
continue;
const CDmrStringArray array( element, "selectedControls" );
if ( array.IsValid() )
{
for ( int j = 0 ; j < array.Count(); ++j )
{
const char *sliderName = array[ j ];
if ( sliderName && *sliderName )
{
m_SliderNames.AddString( sliderName );
}
}
}
}
}
// now notify the attribute slider panel
CBaseAnimSetAttributeSliderPanel *attSliders = m_hEditor->GetAttributeSlider();
if ( attSliders )
{
attSliders->SetVisibleControlsForSelectionGroup( m_SliderNames );
}
}
void CBaseAnimSetControlGroupPanel::ChangeAnimationSet( CDmeAnimationSet *newAnimSet )
{
bool changed = m_AnimSet.Get() != newAnimSet ? true : false;
m_AnimSet = newAnimSet;
if ( !m_AnimSet.Get() )
{
m_hGroups->RemoveAll();
m_hSelectableIndices.RemoveAll();
m_GroupList.RemoveAll();
return;
}
// Compare groups
bool bRebuildGroups = false;
const CDmaElementArray< CDmElement > &groups = m_AnimSet->GetSelectionGroups();
int c = groups.Count();
if ( c != m_GroupList.Count() )
{
bRebuildGroups = true;
}
else
{
for ( int i = 0; i < c; ++i )
{
CDmElement *group = groups[ i ];
if ( group == m_GroupList[ i ].Get() )
{
continue;
}
bRebuildGroups = true;
break;
}
}
if ( bRebuildGroups )
{
m_hGroups->SetFont( scheme()->GetIScheme( GetScheme() )->GetFont( "DefaultBold", IsProportional() ) );
// Build a tree of every open item in the tree view
OpenItemTree_t openItems;
int nRootIndex = m_hGroups->GetRootItemIndex();
if ( nRootIndex != -1 )
{
BuildOpenItemList( openItems, openItems.InvalidIndex(), nRootIndex );
}
m_hGroups->RemoveAll();
m_hSelectableIndices.RemoveAll();
m_GroupList.RemoveAll();
// Create root
int rootIndex = AddItemToTree( m_hGroups, "root", -1, Color( 128, 128, 128, 255 ), -1, (int)DMELEMENT_HANDLE_INVALID );
Color defaultColor( 0, 128, 255, 255 );
CAppUndoScopeGuard *guard = NULL;
for ( int i = 0; i < c; ++i )
{
CDmElement *group = groups[ i ];
if ( !group->HasAttribute( "treeColor" ) )
{
if ( !guard )
{
guard = new CAppUndoScopeGuard( NOTIFY_SETDIRTYFLAG, "Set Default Colors" );
}
group->SetValue< Color >( "treeColor", defaultColor );
}
int groupIndex = AddItemToTree( m_hGroups, group->GetName(), rootIndex, group->GetValue< Color >( "treeColor" ), i, (int)group->GetHandle() );
const CDmrStringArray array( group, "selectedControls" );
if ( array.IsValid() )
{
for ( int j = 0 ; j < array.Count(); ++j )
{
AddItemToTree( m_hGroups, array[ j ], groupIndex, Color( 200, 200, 200, 255 ), -1, (int)DMELEMENT_HANDLE_INVALID );
}
}
m_hSelectableIndices.AddToTail( groupIndex );
m_GroupList.AddToTail( group->GetHandle() );
}
if ( ( nRootIndex >= 0 ) && ( rootIndex >= 0 ) && !changed )
{
// Iterate through all previously open items and expand them if they exist
if ( openItems.Root() != openItems.InvalidIndex() )
{
ExpandOpenItems( openItems, openItems.Root(), rootIndex, true );
}
}
else
{
m_hGroups->ExpandItem( rootIndex, true );
}
if ( guard )
{
delete guard;
}
}
if ( changed )
{
for ( int i = 0; i < m_hSelectableIndices.Count(); ++i )
{
m_hGroups->AddSelectedItem( m_hSelectableIndices[ i ],
false, // don't clear selection
true, // put focus on tree
false ); // don't expand tree to make all of these visible...
}
}
}
//-----------------------------------------------------------------------------
// Expands all items in the open item tree if they exist
//-----------------------------------------------------------------------------
void CBaseAnimSetControlGroupPanel::ExpandOpenItems( OpenItemTree_t &tree, int nOpenTreeIndex, int nItemIndex, bool makeVisible )
{
int i = tree.FirstChild( nOpenTreeIndex );
if ( nOpenTreeIndex != tree.InvalidIndex() )
{
TreeInfo_t& info = tree[ nOpenTreeIndex ];
if ( info.m_nFlags & EP_EXPANDED )
{
// Expand the item
m_hGroups->ExpandItem( nItemIndex , true );
}
if ( info.m_nFlags & EP_SELECTED )
{
m_hGroups->AddSelectedItem( nItemIndex, false, false );
if ( makeVisible )
{
m_hGroups->MakeItemVisible( nItemIndex );
}
}
}
while ( i != tree.InvalidIndex() )
{
TreeInfo_t& info = tree[ i ];
// Look for a match
int nChildIndex = FindTreeItem( nItemIndex, info.m_Item );
if ( nChildIndex != -1 )
{
ExpandOpenItems( tree, i, nChildIndex, makeVisible );
}
else
{
if ( info.m_nFlags & EP_SELECTED )
{
// Look for preserved item
nChildIndex = FindTreeItem( nItemIndex, info.m_Item );
if ( nChildIndex != -1 )
{
m_hGroups->AddSelectedItem( nChildIndex, false, false );
if ( makeVisible )
{
m_hGroups->MakeItemVisible( nChildIndex );
}
}
}
}
i = tree.NextSibling( i );
}
}
void CBaseAnimSetControlGroupPanel::FillInDataForItem( TreeItem_t &item, int nItemIndex )
{
KeyValues *data = m_hGroups->GetItemData( nItemIndex );
if ( !data )
return;
item.m_pAttributeName = data->GetString( "text" );
}
//-----------------------------------------------------------------------------
// Builds a list of open items
//-----------------------------------------------------------------------------
void CBaseAnimSetControlGroupPanel::BuildOpenItemList( OpenItemTree_t &tree, int nParent, int nItemIndex )
{
KeyValues *data = m_hGroups->GetItemData( nItemIndex );
if ( !data )
return;
bool expanded = m_hGroups->IsItemExpanded( nItemIndex );
bool selected = m_hGroups->IsItemSelected( nItemIndex );
int flags = 0;
if ( expanded )
{
flags |= EP_EXPANDED;
}
if ( selected )
{
flags |= EP_SELECTED;
}
int nChild = tree.InsertChildAfter( nParent, tree.InvalidIndex() );
TreeInfo_t &info = tree[nChild];
FillInDataForItem( info.m_Item, nItemIndex );
info.m_nFlags = flags;
// Deal with children
int nCount = m_hGroups->GetNumChildren( nItemIndex );
for ( int i = 0; i < nCount; ++i )
{
int nChildIndex = m_hGroups->GetChild( nItemIndex, i );
BuildOpenItemList( tree, nChild, nChildIndex );
}
}
//-----------------------------------------------------------------------------
// Finds the tree index of a child matching the particular element + attribute
//-----------------------------------------------------------------------------
int CBaseAnimSetControlGroupPanel::FindTreeItem( int nParentIndex, const TreeItem_t &info )
{
// Look for a match
int nCount = m_hGroups->GetNumChildren( nParentIndex );
for ( int i = nCount; --i >= 0; )
{
int nChildIndex = m_hGroups->GetChild( nParentIndex, i );
KeyValues *data = m_hGroups->GetItemData( nChildIndex );
Assert( data );
const char *pAttributeName = data->GetString( "text" );
if ( !Q_stricmp( pAttributeName, info.m_pAttributeName ) )
{
return nChildIndex;
}
}
return -1;
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,91 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "dme_controls/BaseAttributeChoicePanel.h"
#include "tier1/KeyValues.h"
#include "vgui_controls/ComboBox.h"
#include "datamodel/dmelement.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CBaseAttributeChoicePanel::CBaseAttributeChoicePanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
BaseClass( parent, info ), m_pData( 0 )
{
SetDropEnabled( false );
m_pData = new vgui::ComboBox( this, "AttributeValue", 10, false );
m_pData->SetEnabled( !HasFlag( FATTRIB_READONLY ) );
m_pData->AddActionSignalTarget( this );
}
//-----------------------------------------------------------------------------
// Called after the constructor is finished
//-----------------------------------------------------------------------------
void CBaseAttributeChoicePanel::PostConstructor()
{
BaseClass::PostConstructor();
PopulateComboBox( m_pData );
Refresh();
}
void CBaseAttributeChoicePanel::ApplySchemeSettings( IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
HFont font = pScheme->GetFont( "DmePropertyVerySmall", IsProportional() );
m_pData->SetFont(font);
}
vgui::Panel *CBaseAttributeChoicePanel::GetDataPanel()
{
return static_cast< vgui::Panel * >( m_pData );
}
//-----------------------------------------------------------------------------
// Called when it is time to set the attribute from the combo box state
//-----------------------------------------------------------------------------
void CBaseAttributeChoicePanel::Apply( )
{
KeyValues *kv = m_pData->GetActiveItemUserData();
SetAttributeFromComboBox( m_pData, kv );
}
//-----------------------------------------------------------------------------
// Called when it is time to set the combo box from the attribute
//-----------------------------------------------------------------------------
void CBaseAttributeChoicePanel::Refresh()
{
SetComboBoxFromAttribute( m_pData );
}
//-----------------------------------------------------------------------------
// Called when the text in the panel changes
//-----------------------------------------------------------------------------
void CBaseAttributeChoicePanel::OnTextChanged( Panel *panel )
{
if ( IsAutoApply() )
{
Apply();
}
else
{
SetDirty(true);
}
}
@@ -0,0 +1,127 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "dme_controls/BaseAttributeDoubleChoicePanel.h"
#include "tier1/KeyValues.h"
#include "vgui_controls/ComboBox.h"
#include "datamodel/dmelement.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
CDoubleComboBoxContainerPanel::CDoubleComboBoxContainerPanel( vgui::Panel *parent, char const *name ) :
BaseClass( parent, name )
{
m_pBoxes[ 0 ] = m_pBoxes[ 1 ] = NULL;
}
void CDoubleComboBoxContainerPanel::AddComboBox( int slot, vgui::ComboBox *box )
{
m_pBoxes[ slot ] = box;
}
void CDoubleComboBoxContainerPanel::PerformLayout()
{
BaseClass::PerformLayout();
int w, h;
GetSize( w, h );
if ( m_pBoxes[ 0 ] )
{
m_pBoxes[ 0 ]->SetBounds( 0, 0, w/2, h );
}
if ( m_pBoxes[ 1 ] )
{
m_pBoxes[ 1 ]->SetBounds( w/2, 0, w/2, h );
}
}
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CBaseAttributeDoubleChoicePanel::CBaseAttributeDoubleChoicePanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
BaseClass( parent, info )
{
SetDropEnabled( false );
m_pContainerPanel = new CDoubleComboBoxContainerPanel( this, "Container" );
m_pData[0] = new vgui::ComboBox( m_pContainerPanel, "AttributeValue", 10, false );
m_pData[0]->SetEnabled( !HasFlag( FATTRIB_READONLY ) );
m_pData[0]->AddActionSignalTarget( this );
m_pContainerPanel->AddComboBox( 0, m_pData[ 0 ] );
m_pData[1] = new vgui::ComboBox( m_pContainerPanel, "AttributeValue", 10, false );
m_pData[1]->SetEnabled( !HasFlag( FATTRIB_READONLY ) );
m_pData[1]->AddActionSignalTarget( this );
m_pContainerPanel->AddComboBox( 1, m_pData[ 1 ] );
}
//-----------------------------------------------------------------------------
// Called after the constructor is finished
//-----------------------------------------------------------------------------
void CBaseAttributeDoubleChoicePanel::PostConstructor()
{
BaseClass::PostConstructor();
PopulateComboBoxes( m_pData );
Refresh();
}
void CBaseAttributeDoubleChoicePanel::ApplySchemeSettings( IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
HFont font = pScheme->GetFont( "DmePropertyVerySmall", IsProportional() );
m_pData[0]->SetFont(font);
m_pData[1]->SetFont(font);
}
vgui::Panel *CBaseAttributeDoubleChoicePanel::GetDataPanel()
{
return static_cast< vgui::Panel * >( m_pContainerPanel );
}
//-----------------------------------------------------------------------------
// Called when it is time to set the attribute from the combo box state
//-----------------------------------------------------------------------------
void CBaseAttributeDoubleChoicePanel::Apply( )
{
Assert( m_pData[ 0 ] && m_pData[ 1 ] );
KeyValues *kv[ 2 ];
kv[ 0 ] = m_pData[ 0 ]->GetActiveItemUserData();
kv[ 1 ] = m_pData[ 1 ]->GetActiveItemUserData();
SetAttributeFromComboBoxes( m_pData, kv );
}
//-----------------------------------------------------------------------------
// Called when it is time to set the combo box from the attribute
//-----------------------------------------------------------------------------
void CBaseAttributeDoubleChoicePanel::Refresh()
{
SetComboBoxesFromAttribute( m_pData );
}
//-----------------------------------------------------------------------------
// Called when the text in the panel changes
//-----------------------------------------------------------------------------
void CBaseAttributeDoubleChoicePanel::OnTextChanged( Panel *panel )
{
SetDirty(true);
if ( IsAutoApply() )
{
Apply();
}
}
+365
View File
@@ -0,0 +1,365 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: base class for all element attribute panels
// An attribute panel is a one line widget that can be used by a list
// or tree control.
//
// $NoKeywords: $
//
//=============================================================================//
#include "dme_controls/BaseAttributePanel.h"
#include "dme_controls/attributewidgetfactory.h"
#include "tier1/KeyValues.h"
#include "vgui_controls/Label.h"
#include "movieobjects/dmeeditortypedictionary.h"
#include "dme_controls/inotifyui.h"
using namespace vgui;
//-----------------------------------------------------------------------------
// Lessfunc for columns.
//-----------------------------------------------------------------------------
bool CBaseAttributePanel::ColInfoLessFunc( const CBaseAttributePanel::colinfo_t& lhs, const CBaseAttributePanel::colinfo_t& rhs )
{
return lhs.panel < rhs.panel;
}
//-----------------------------------------------------------------------------
// CBaseAttributePanel constructor
//-----------------------------------------------------------------------------
CBaseAttributePanel::CBaseAttributePanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
BaseClass( parent, info.m_pAttributeName ),
m_pType( 0 ),
m_hObject( info.m_pElement ),
m_hEditorInfo( info.m_pEditorInfo ),
m_hEditorTypeDict( info.m_pEditorTypeDictionary ),
m_pNotify( info.m_pNotify ),
m_nArrayIndex( info.m_nArrayIndex ),
m_ColumnSize( 0, 0, ColInfoLessFunc )
{
Assert( info.m_pElement );
InitializeFlags( info );
Assert( info.m_pAttributeName );
Q_strncpy( m_szAttributeName, info.m_pAttributeName, sizeof( m_szAttributeName ) );
m_pType = new Label( this, "AttributeType", "" );
SetColumnSize( m_pType, 100 );
CDmAttribute *pAttribute = info.m_pElement->GetAttribute( info.m_pAttributeName );
m_AttributeType = pAttribute ? pAttribute->GetType() : AT_UNKNOWN;
if ( m_nArrayIndex >= 0 )
{
m_AttributeType = ArrayTypeToValueType( m_AttributeType );
}
m_pType->SetText( g_pDataModel->GetAttributeNameForType( m_AttributeType ) );
m_hFont = NULL;
// These are draggable
SetDragEnabled( true );
}
//-----------------------------------------------------------------------------
// This only exists so every class always can chain PostConstructors
//-----------------------------------------------------------------------------
void CBaseAttributePanel::PostConstructor()
{
}
//-----------------------------------------------------------------------------
// Initializes flags from the attribute editor info
//-----------------------------------------------------------------------------
void CBaseAttributePanel::InitializeFlags( const AttributeWidgetInfo_t &info )
{
m_nFlags = 0;
if ( info.m_pEditorInfo )
{
if ( info.m_pEditorInfo->m_bHideType )
{
m_nFlags |= HIDETYPE;
}
if ( info.m_pEditorInfo->m_bHideValue )
{
m_nFlags |= HIDEVALUE;
}
if ( info.m_pEditorInfo->m_bIsReadOnly )
{
m_nFlags |= READONLY;
}
}
CDmAttribute *pAttribute = info.m_pElement->GetAttribute( info.m_pAttributeName );
if ( pAttribute && pAttribute->IsFlagSet( FATTRIB_READONLY ) )
{
m_nFlags |= READONLY;
}
if ( info.m_bAutoApply )
{
m_nFlags |= AUTOAPPLY;
}
}
//-----------------------------------------------------------------------------
// Returns the editor info
//-----------------------------------------------------------------------------
CDmeEditorTypeDictionary *CBaseAttributePanel::GetEditorTypeDictionary()
{
return m_hEditorTypeDict;
}
CDmeEditorAttributeInfo *CBaseAttributePanel::GetEditorInfo()
{
return m_hEditorInfo;
}
//-----------------------------------------------------------------------------
// Does the element have the attribute we're attempting to reference?
//-----------------------------------------------------------------------------
bool CBaseAttributePanel::HasAttribute() const
{
return GetPanelElement()->HasAttribute( m_szAttributeName );
}
//-----------------------------------------------------------------------------
// Returns the attribute array count
//-----------------------------------------------------------------------------
int CBaseAttributePanel::GetAttributeArrayCount() const
{
CDmrGenericArrayConst array( GetPanelElement(), m_szAttributeName );
return array.IsValid() ? array.Count() : -1;
}
//-----------------------------------------------------------------------------
// Sets the font
//-----------------------------------------------------------------------------
void CBaseAttributePanel::SetFont( HFont font )
{
m_hFont = font;
m_pType->SetFont(font);
}
//-----------------------------------------------------------------------------
// Applies scheme settings
//-----------------------------------------------------------------------------
void CBaseAttributePanel::ApplySchemeSettings( IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
// set the color of the "type" column
m_pType->SetFgColor( Color ( 160, 160, 160, 255 ) );
if ( GetDirty() )
{
SetBgColor( pScheme->GetColor( "AttributeWidget.DirtyBgColor", Color( 100, 100, 200, 63 ) ) );
}
else
{
SetBgColor( pScheme->GetColor( "Panel.BgColor", Color( 0, 0, 0, 0 ) ) );
}
HFont font = pScheme->GetFont( "DmePropertyVerySmall", IsProportional() );
// m_pType->SetFont(font);
if ( !m_hFont )
{
m_hFont = font;
}
SetFont( m_hFont );
}
//-----------------------------------------------------------------------------
// Returns the panel element
//-----------------------------------------------------------------------------
CDmElement *CBaseAttributePanel::GetPanelElement()
{
return m_hObject;
}
const CDmElement *CBaseAttributePanel::GetPanelElement() const
{
return m_hObject;
}
//-----------------------------------------------------------------------------
// Gets/Sets the attribute value from a string
//-----------------------------------------------------------------------------
void CBaseAttributePanel::SetAttributeValueFromString( const char *pString )
{
if ( m_nArrayIndex < 0 )
{
GetPanelElement()->SetValueFromString( m_szAttributeName, pString );
}
else
{
CDmrGenericArray array( GetPanelElement(), m_szAttributeName );
array.SetFromString( m_nArrayIndex, pString );
}
}
const char *CBaseAttributePanel::GetAttributeValueAsString( char *pBuf, int nLength )
{
if ( m_nArrayIndex < 0 )
{
GetPanelElement()->GetValueAsString( m_szAttributeName, pBuf, nLength );
}
else
{
CDmrGenericArray array( GetPanelElement(), m_szAttributeName );
array.GetAsString( m_nArrayIndex, pBuf, nLength );
}
return pBuf;
}
//-----------------------------------------------------------------------------
// Helper to get/set the attribute value for elements
//-----------------------------------------------------------------------------
CDmElement *CBaseAttributePanel::GetAttributeValueElement()
{
return GetElement< CDmElement >( GetAttributeValue<DmElementHandle_t>( ) );
}
void CBaseAttributePanel::SetAttributeValueElement( CDmElement *pElement )
{
return SetAttributeValue( pElement->GetHandle() );
}
void CBaseAttributePanel::SetDirty( bool dirty )
{
SetFlag( DIRTY, dirty );
InvalidateLayout( false, true );
}
void CBaseAttributePanel::SetColumnSize( Panel *panel, int width )
{
colinfo_t search;
search.panel = panel;
int idx = m_ColumnSize.Find( search );
if ( idx == m_ColumnSize.InvalidIndex() )
{
idx = m_ColumnSize.Insert( search );
}
m_ColumnSize[ idx ].width = width;
}
int CBaseAttributePanel::GetSizeForColumn( Panel *panel )
{
colinfo_t search;
search.panel = panel;
int idx = m_ColumnSize.Find( search );
if ( idx == m_ColumnSize.InvalidIndex() )
{
return 100;
}
return m_ColumnSize[ idx ].width;
}
//-----------------------------------------------------------------------------
// Creates a widget using editor attribute info
//-----------------------------------------------------------------------------
void CBaseAttributePanel::PerformLayout()
{
BaseClass::PerformLayout();
CUtlVector< Panel * > vispanels;
if ( HasFlag( HIDETYPE ) )
{
m_pType->SetVisible( false );
}
else
{
vispanels.AddToTail( m_pType );
}
vgui::Panel *dataPanel = GetDataPanel();
if ( dataPanel )
{
if ( HasFlag( HIDEVALUE ) )
{
dataPanel->SetVisible( false );
}
else
{
vispanels.AddToTail( dataPanel );
}
}
int c = vispanels.Count();
Assert( c >= 0 );
if ( c == 0 )
{
return;
}
int w, h;
GetSize( w, h );
int x = 1;
int y = 0;
w-= 2;
for ( int i = 0; i < c; ++i )
{
Panel *panel = vispanels[ i ];
int width = GetSizeForColumn( panel );
if ( i == c - 1 )
{
width = w - x;
}
panel->SetBounds( x, y, width, h );
x += width;
}
}
void CBaseAttributePanel::OnApplyChanges()
{
Assert( !IsAutoApply() );
Apply();
SetDirty(false);
}
void CBaseAttributePanel::OnRefresh()
{
Refresh();
}
void CBaseAttributePanel::OnCreateDragData( KeyValues *msg )
{
if ( GetPanelElement() )
{
msg->SetInt( "root", GetPanelElement() ? GetPanelElement()->GetHandle() : DMELEMENT_HANDLE_INVALID );
msg->SetString( "type", g_pDataModel->GetAttributeNameForType( m_AttributeType ) );
msg->SetString( "attributename", m_szAttributeName );
if ( m_nArrayIndex >= 0 )
{
msg->SetInt( "arrayIndex", m_nArrayIndex );
}
if ( m_AttributeType != AT_ELEMENT && m_AttributeType != AT_ELEMENT_ARRAY )
{
char pTemp[512];
GetAttributeValueAsString( pTemp, sizeof( pTemp ) );
msg->SetString( "text", pTemp );
}
}
}
+368
View File
@@ -0,0 +1,368 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#include <math.h>
#include <dme_controls/ChannelGraphPanel.h>
#include <vgui/IScheme.h>
#include <vgui/ISurface.h>
#include <vgui/IVGui.h>
#include "vgui/IInput.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
using namespace vgui;
DECLARE_BUILD_FACTORY( CChannelGraphPanel );
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CChannelGraphPanel::CChannelGraphPanel( Panel *parent, const char *name )
: BaseClass( parent, name ), m_font( 0 ),
m_graphMinTime( 0 ), m_graphMaxTime( 0 ),
m_graphMinValue( 0.0f ), m_graphMaxValue( 0.0f ),
m_nMouseStartX( -1 ), m_nMouseStartY( -1 ),
m_nMouseLastX( -1 ), m_nMouseLastY( -1 ),
m_nTextBorder( 2 ), m_nGraphOriginX( 40 ), m_nGraphOriginY( 10 )
{
}
void CChannelGraphPanel::SetChannel( CDmeChannel *pChannel )
{
m_hChannel = pChannel;
CDmeLog *pLog = m_hChannel->GetLog();
m_graphMinTime = pLog->GetBeginTime();
m_graphMaxTime = pLog->GetEndTime();
m_graphMinValue = FLT_MAX;
m_graphMaxValue = -FLT_MAX;
int nComponents = NumComponents( pLog->GetDataType() );
int nKeys = pLog->GetKeyCount();
for ( int k = 0; k < nKeys; ++k )
{
DmeTime_t t = pLog->GetKeyTime( k );
for ( int i = 0; i < nComponents; ++i )
{
float f = pLog->GetComponent( t, i );
m_graphMinValue = min( m_graphMinValue, f );
m_graphMaxValue = max( m_graphMaxValue, f );
}
}
}
//-----------------------------------------------------------------------------
// input methods
//-----------------------------------------------------------------------------
void CChannelGraphPanel::OnSizeChanged( int newWide, int newTall ) // called after the size of a panel has been changed
{
int wide = newWide - m_nGraphOriginX;
int tall = newTall - m_nGraphOriginY;
m_flTimeToPixel = wide / ( m_graphMaxTime - m_graphMinTime ).GetSeconds();
m_flValueToPixel = tall / ( m_graphMaxValue - m_graphMinValue );
}
void CChannelGraphPanel::OnMousePressed( MouseCode code )
{
BaseClass::OnMousePressed( code );
if ( code != MOUSE_LEFT )
return;
vgui::input()->GetCursorPos( m_nMouseStartX, m_nMouseStartY );
ScreenToLocal( m_nMouseStartX, m_nMouseStartY );
m_nMouseLastX = m_nMouseStartX;
m_nMouseLastY = m_nMouseStartY;
input()->SetMouseCapture( GetVPanel() );
}
void CChannelGraphPanel::OnMouseReleased( MouseCode code )
{
BaseClass::OnMouseReleased( code );
if ( code != MOUSE_LEFT )
return;
m_nMouseStartX = m_nMouseStartY = -1;
m_nMouseLastX = m_nMouseLastY = -1;
input()->SetMouseCapture( NULL );
}
void CChannelGraphPanel::OnCursorMoved( int mx, int my )
{
BaseClass::OnCursorMoved( mx, my );
if ( !vgui::input()->IsMouseDown( MOUSE_LEFT ) )
return;
bool bInValueLegend = m_nMouseStartX < m_nGraphOriginX;
bool bInTimeLegend = m_nMouseStartY > GetTall() - m_nGraphOriginY - 1;
if ( bInTimeLegend && bInValueLegend )
{
bInTimeLegend = bInValueLegend = false;
}
int dx = mx - m_nMouseLastX;
int dy = my - m_nMouseLastY;
if ( bInTimeLegend )
{
if ( abs( dy ) > abs( dx ) )
{
m_graphMinTime -= DmeTime_t( dy / m_flTimeToPixel );
m_graphMaxTime += DmeTime_t( dy / m_flTimeToPixel );
m_flTimeToPixel = ( GetWide() - m_nGraphOriginX ) / ( m_graphMaxTime - m_graphMinTime ).GetSeconds();
int x = mx = m_nMouseLastX;
int y = my = m_nMouseLastY;
LocalToScreen( x, y );
vgui::input()->SetCursorPos( x, y );
}
else
{
m_graphMinTime -= DmeTime_t( dx / m_flTimeToPixel );
m_graphMaxTime -= DmeTime_t( dx / m_flTimeToPixel );
}
}
else if ( bInValueLegend )
{
if ( abs( dx ) > abs( dy ) )
{
m_graphMinValue += dx / m_flValueToPixel;
m_graphMaxValue -= dx / m_flValueToPixel;
m_flValueToPixel = ( GetTall() - m_nGraphOriginY ) / ( m_graphMaxValue - m_graphMinValue );
int x = mx = m_nMouseLastX;
int y = my = m_nMouseLastY;
LocalToScreen( x, y );
vgui::input()->SetCursorPos( x, y );
}
else
{
m_graphMinValue += dy / m_flValueToPixel;
m_graphMaxValue += dy / m_flValueToPixel;
}
}
m_nMouseLastX = mx;
m_nMouseLastY = my;
}
void CChannelGraphPanel::OnMouseWheeled( int delta )
{
// TODO - zoom in around current time?
}
//-----------------------------------------------------------------------------
// Purpose: lays out the graph
//-----------------------------------------------------------------------------
void CChannelGraphPanel::PerformLayout()
{
BaseClass::PerformLayout();
}
float GetDisplayIncrement( int windowpixels, int fontpixels, float valuerange, int *pDecimalPlaces = NULL )
{
float ratio = valuerange * fontpixels / ( windowpixels );
int nPower = ( int )ceil( log10( ratio ) );
if ( pDecimalPlaces )
{
*pDecimalPlaces = max( 0, -nPower );
}
return pow( 10.0f, nPower );
}
int CChannelGraphPanel::TimeToPixel( DmeTime_t time )
{
return m_nGraphOriginX + ( int )floor( m_flTimeToPixel * ( time - m_graphMinTime ).GetSeconds() + 0.5f );
}
int CChannelGraphPanel::ValueToPixel( float flValue )
{
return m_nGraphOriginY + ( int )floor( m_flValueToPixel * ( flValue - m_graphMinValue ) + 0.5f );
}
//-----------------------------------------------------------------------------
// Purpose: draws the graph
//-----------------------------------------------------------------------------
void CChannelGraphPanel::Paint()
{
// estimate the size of the graph marker text
int wide = GetWide() - m_nGraphOriginX;
int tall = GetTall() - m_nGraphOriginY;
int textwidth = 40, textheight = 10;
surface()->GetTextSize( m_font, L"999.9", textwidth, textheight );
// draw current time marker
DmeTime_t curtime = m_hChannel->GetCurrentTime();
if ( curtime >= m_graphMinTime && curtime <= m_graphMaxTime )
{
Color cyan( 0, 255, 255, 255 );
surface()->DrawSetColor( cyan );
int x = TimeToPixel( curtime );
surface()->DrawLine( x, 0, x, GetTall() - m_nGraphOriginY - 1 );
}
// draw left/bottom graph border
Color black( 0, 0, 0, 255 );
surface()->DrawSetColor( black );
surface()->DrawLine( m_nGraphOriginX, GetTall() - m_nGraphOriginY - 1, GetWide(), GetTall() - m_nGraphOriginY - 1 );
surface()->DrawLine( m_nGraphOriginX, GetTall() - m_nGraphOriginY - 1, m_nGraphOriginX, 0 );
surface()->DrawSetTextColor( black );
surface()->DrawSetTextFont( m_font );
// draw graph tickmarks and values along the left border
int nDecimalPlaces = 0;
float flValueIncrement = GetDisplayIncrement( tall, ( int )( 1.5f * textheight ), m_graphMaxValue - m_graphMinValue, &nDecimalPlaces );
int nMinValueIndex = ( int )ceil ( m_graphMinValue / flValueIncrement );
int nMaxValueIndex = ( int )floor( m_graphMaxValue / flValueIncrement );
float flValue = nMinValueIndex * flValueIncrement;
for ( int i = nMinValueIndex; i <= nMaxValueIndex; ++i, flValue += flValueIncrement )
{
wchar_t pFormat[ 32 ];
V_swprintf_safe( pFormat, L"%%.%df", nDecimalPlaces );
wchar_t wstring[ 32 ];
V_swprintf_safe( wstring, pFormat, flValue );
int tw = 0, th = 0;
surface()->GetTextSize( m_font, wstring, tw, th );
int y = GetTall() - ValueToPixel( flValue ) - 1;
surface()->DrawSetTextPos( m_nGraphOriginX - m_nTextBorder - tw, y - textheight / 2 );
surface()->DrawPrintText( wstring, wcslen( wstring ) );
surface()->DrawLine( m_nGraphOriginX - m_nTextBorder, y, m_nGraphOriginX, y );
}
// draw graph tickmarks and times along the bottom border
float flTimeIncrement = GetDisplayIncrement( wide, textwidth, ( m_graphMaxTime - m_graphMinTime ).GetSeconds(), &nDecimalPlaces );
int nMinTimeIndex = ( int )ceil ( m_graphMinTime.GetSeconds() / flTimeIncrement );
int nMaxTimeIndex = ( int )floor( m_graphMaxTime.GetSeconds() / flTimeIncrement );
float flTime = nMinTimeIndex * flTimeIncrement;
for ( int i = nMinTimeIndex; i <= nMaxTimeIndex; ++i, flTime += flTimeIncrement )
{
wchar_t pFormat[ 32 ];
V_swprintf_safe( pFormat, L"%%.%df", nDecimalPlaces );
wchar_t wstring[ 32 ];
V_swprintf_safe( wstring, pFormat, flTime );
int tw = 0, th = 0;
surface()->GetTextSize( m_font, wstring, tw, th );
int x = TimeToPixel( DmeTime_t( flTime ) );
surface()->DrawSetTextPos( x - tw / 2, GetTall() - m_nGraphOriginY + m_nTextBorder - 1 );
surface()->DrawPrintText( wstring, wcslen( wstring ) );
surface()->DrawLine( x, GetTall() - m_nGraphOriginY + m_nTextBorder - 1, x, GetTall() - m_nGraphOriginY - 1 );
}
static Color s_componentColors[] =
{
Color( 255, 0, 0, 255 ),
Color( 0, 255, 0, 255 ),
Color( 0, 0, 255, 255 ),
Color( 0, 0, 0, 255 ),
};
CDmeLog *pLog = m_hChannel->GetLog();
int nComponents = NumComponents( pLog->GetDataType() );
int nKeys = pLog->GetKeyCount();
// draw plotted graph
for ( int i = 0; i < nComponents; ++i )
{
Color &color = s_componentColors[ i % ARRAYSIZE( s_componentColors ) ];
surface()->DrawSetColor( color );
int lastx = -1;
int lasty = -1;
for ( int k = 0; k < nKeys; ++k )
{
DmeTime_t t = pLog->GetKeyTime( k );
float f = pLog->GetComponent( t, i );
int x = TimeToPixel( t );
int y = GetTall() - ValueToPixel( f ) - 1;
if ( k )
{
surface()->DrawLine( lastx, lasty, x, y );
}
lastx = x;
lasty = y;
}
}
}
//-----------------------------------------------------------------------------
// Purpose: sets up colors
//-----------------------------------------------------------------------------
void CChannelGraphPanel::ApplySchemeSettings(IScheme *pScheme)
{
BaseClass::ApplySchemeSettings(pScheme);
m_font = pScheme->GetFont( "DefaultVerySmall" );
surface()->GetTextSize( m_font, L"999.9", m_nGraphOriginX, m_nGraphOriginY );
m_nGraphOriginX += 2 * m_nTextBorder;
m_nGraphOriginY += 2 * m_nTextBorder;
SetFgColor(GetSchemeColor("CChannelGraphPanel.FgColor", pScheme));
SetBgColor(GetSchemeColor("CChannelGraphPanel.BgColor", pScheme));
SetBorder(pScheme->GetBorder("ButtonDepressedBorder"));
}
//-----------------------------------------------------------------------------
//
// CChannelGraphFrame methods
//
//-----------------------------------------------------------------------------
CChannelGraphFrame::CChannelGraphFrame( Panel *parent, const char *pTitle )
: BaseClass( parent, "CChannelGraphFrame" )
{
SetTitle( pTitle, true );
SetSizeable( true );
SetCloseButtonVisible( true );
SetMinimumSize( 200, 100 );
SetVisible( true );
SetSize( 400, 200 );
SetPos( 100, 100 );
m_pChannelGraph = new CChannelGraphPanel( this, "ChannelGraph" );
SetScheme( vgui::scheme()->LoadSchemeFromFile( "Resource/BoxRocket.res", "BoxRocket" ) );
}
void CChannelGraphFrame::SetChannel( CDmeChannel *pChannel )
{
m_pChannelGraph->SetChannel( pChannel );
}
void CChannelGraphFrame::OnCommand( const char *cmd )
{
BaseClass::OnCommand( cmd );
m_pChannelGraph->OnCommand( cmd );
}
void CChannelGraphFrame::PerformLayout()
{
BaseClass::PerformLayout();
int border = 5;
int iWidth, iHeight;
GetSize( iWidth, iHeight );
m_pChannelGraph->SetPos( border, GetCaptionHeight() + border );
m_pChannelGraph->SetSize( iWidth - 2 * border, iHeight - GetCaptionHeight() - 2 * border );
}
@@ -0,0 +1,488 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================
#include "dme_controls/DmeSourceDCCFilePanel.h"
#include "dme_controls/DmePanel.h"
#include "movieobjects/dmedccmakefile.h"
#include "vgui_controls/TextEntry.h"
#include "vgui_controls/ListPanel.h"
#include "vgui_controls/Button.h"
#include "vgui_controls/InputDialog.h"
#include "vgui_controls/MessageBox.h"
#include "vgui/keycode.h"
#include "tier1/KeyValues.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
//
// Hook into the dme panel editor system
//
//-----------------------------------------------------------------------------
IMPLEMENT_DMEPANEL_FACTORY( CDmeSourceDCCFilePanel, DmeSourceDCCFile, "DmeSourceDCCFileDefault", "Maya/XSI Source File Editor", true );
//-----------------------------------------------------------------------------
// Sort by MDL name
//-----------------------------------------------------------------------------
static int __cdecl DccObjectSortFunc( vgui::ListPanel *pPanel, const ListPanelItem &item1, const ListPanelItem &item2 )
{
const char *string1 = item1.kv->GetString( "dccobject" );
const char *string2 = item2.kv->GetString( "dccobject" );
return Q_stricmp( string1, string2 );
}
//-----------------------------------------------------------------------------
// Purpose: Constructor, destructor
//-----------------------------------------------------------------------------
CDmeSourceDCCFilePanel::CDmeSourceDCCFilePanel( vgui::Panel *pParent, const char *pPanelName ) :
BaseClass( pParent, pPanelName )
{
m_pRootDCCObjects = new vgui::ListPanel( this, "DCCObjectList" );
m_pRootDCCObjects->AddColumnHeader( 0, "dccobject", "Maya/XSI Object Name", 100, 0 );
m_pRootDCCObjects->AddActionSignalTarget( this );
m_pRootDCCObjects->SetSortFunc( 0, DccObjectSortFunc );
m_pRootDCCObjects->SetSortColumn( 0 );
// m_pRootDCCObjects->SetSelectIndividualCells( true );
m_pRootDCCObjects->SetEmptyListText("No sources");
// m_pRootDCCObjects->SetDragEnabled( true );
m_pDCCObjectBrowser = new vgui::Button( this, "DCCObjectBrowser", "...", this, "OnBrowseDCCObject" );
m_pDCCObjectName = new vgui::TextEntry( this, "DCCObjectName" );
m_pDCCObjectName->SendNewLine( true );
m_pDCCObjectName->AddActionSignalTarget( this );
m_pAddDCCObject = new vgui::Button( this, "AddDCCObjectButton", "Add", this, "OnAddDCCObject" );
m_pRemoveDCCObject = new vgui::Button( this, "RemoveDCCObjectButton", "Remove", this, "OnRemoveDCCObject" );
m_pApplyChanges = new vgui::Button( this, "ApplyChangesButton", "Apply", this, "OnApplyChanges" );
// Load layout settings; has to happen before pinning occurs in code
LoadControlSettings( "resource/DmeSourceDCCFilePanel.res" );
}
CDmeSourceDCCFilePanel::~CDmeSourceDCCFilePanel()
{
}
//-----------------------------------------------------------------------------
// Marks the file as dirty (or not)
//-----------------------------------------------------------------------------
void CDmeSourceDCCFilePanel::SetDirty()
{
PostActionSignal( new KeyValues( "DmeElementChanged" ) );
}
//-----------------------------------------------------------------------------
// Refresh the source list
//-----------------------------------------------------------------------------
void CDmeSourceDCCFilePanel::RefreshDCCObjectList( )
{
m_pRootDCCObjects->RemoveAll();
if ( !m_hSourceDCCFile.Get() )
return;
int nCount = m_hSourceDCCFile->m_RootDCCObjects.Count();
for ( int i = 0; i < nCount; ++i )
{
KeyValues *pItemKeys = new KeyValues( "node", "dccobject", m_hSourceDCCFile->m_RootDCCObjects.Get(i) );
pItemKeys->SetInt( "dccObjectIndex", i );
m_pRootDCCObjects->AddItem( pItemKeys, 0, false, false );
}
m_pRootDCCObjects->SortList();
}
//-----------------------------------------------------------------------------
// Resets the state
//-----------------------------------------------------------------------------
void CDmeSourceDCCFilePanel::SetDmeElement( CDmeSourceDCCFile *pSourceDCCFile )
{
m_hSourceDCCFile = pSourceDCCFile;
bool bEnabled = ( pSourceDCCFile != NULL );
m_pDCCObjectBrowser->SetEnabled( bEnabled );
m_pAddDCCObject->SetEnabled( bEnabled );
m_pRemoveDCCObject->SetEnabled( bEnabled );
m_pApplyChanges->SetEnabled( bEnabled );
if ( !bEnabled )
{
m_pRootDCCObjects->RemoveAll();
m_pDCCObjectName->SetText( "" );
return;
}
RefreshDCCObjectList();
}
//-----------------------------------------------------------------------------
// Called when a list panel's selection changes
//-----------------------------------------------------------------------------
void CDmeSourceDCCFilePanel::OnItemSelectionChanged( )
{
int nCount = m_pRootDCCObjects->GetSelectedItemsCount();
bool bEnabled = ( nCount > 0 );
bool bMultiselect = ( nCount > 1 );
m_pDCCObjectBrowser->SetEnabled( bEnabled && !bMultiselect );
m_pDCCObjectName->SetEnabled( bEnabled && !bMultiselect );
m_pApplyChanges->SetEnabled( bEnabled && !bMultiselect );
m_pRemoveDCCObject->SetEnabled( bEnabled );
if ( !bEnabled || bMultiselect )
{
m_pDCCObjectName->SetText( "" );
return;
}
int nItemID = m_pRootDCCObjects->GetSelectedItem( 0 );
KeyValues *pKeyValues = m_pRootDCCObjects->GetItem( nItemID );
m_pDCCObjectName->SetText( pKeyValues->GetString( "dccobject" ) );
}
//-----------------------------------------------------------------------------
// Called when a list panel's selection changes
//-----------------------------------------------------------------------------
void CDmeSourceDCCFilePanel::OnItemSelected( KeyValues *kv )
{
Panel *pPanel = (Panel *)kv->GetPtr( "panel", NULL );
if ( pPanel == m_pRootDCCObjects )
{
OnItemSelectionChanged();
return;
}
}
//-----------------------------------------------------------------------------
// Called when a list panel's selection changes
//-----------------------------------------------------------------------------
void CDmeSourceDCCFilePanel::OnItemDeselected( KeyValues *kv )
{
Panel *pPanel = (Panel *)kv->GetPtr( "panel", NULL );
if ( pPanel == m_pRootDCCObjects )
{
OnItemSelectionChanged();
return;
}
}
//-----------------------------------------------------------------------------
// Called when return is hit in a text entry field
//-----------------------------------------------------------------------------
void CDmeSourceDCCFilePanel::OnTextNewLine( KeyValues *kv )
{
if ( !m_hSourceDCCFile.Get() )
return;
Panel *pPanel = (Panel *)kv->GetPtr( "panel", NULL );
if ( pPanel == m_pDCCObjectName )
{
OnDCCObjectNameChanged();
return;
}
}
//-----------------------------------------------------------------------------
// Selects a particular DCC object
//-----------------------------------------------------------------------------
void CDmeSourceDCCFilePanel::SelectDCCObject( int nDCCObjectIndex )
{
if ( nDCCObjectIndex < 0 )
{
m_pRootDCCObjects->ClearSelectedItems();
return;
}
int nItemID = m_pRootDCCObjects->FirstItem();
for ( ; nItemID != m_pRootDCCObjects->InvalidItemID(); nItemID = m_pRootDCCObjects->NextItem( nItemID ) )
{
KeyValues *kv = m_pRootDCCObjects->GetItem( nItemID );
if ( kv->GetInt( "dccObjectIndex", -1 ) != nDCCObjectIndex )
continue;
m_pRootDCCObjects->SetSingleSelectedItem( nItemID );
break;
}
}
//-----------------------------------------------------------------------------
// Called when we're browsing for a DCC object and one was selected
//-----------------------------------------------------------------------------
void CDmeSourceDCCFilePanel::OnDCCObjectAdded( const char *pDCCObjectName, KeyValues *pContextKeys )
{
if ( !m_hSourceDCCFile.Get() )
return;
if ( CheckForDuplicateNames( pDCCObjectName ) )
return;
int nIndex = -1;
{
CDisableUndoScopeGuard guard;
nIndex = m_hSourceDCCFile->m_RootDCCObjects.AddToTail( pDCCObjectName );
}
SetDirty( );
RefreshDCCObjectList( );
SelectDCCObject( nIndex );
}
//-----------------------------------------------------------------------------
// Called when the file open dialog for browsing source files selects something
//-----------------------------------------------------------------------------
void CDmeSourceDCCFilePanel::OnInputCompleted( KeyValues *kv )
{
const char *pDCCObjectName = kv->GetString( "text", NULL );
if ( !pDCCObjectName )
return;
KeyValues *pDialogKeys = kv->FindKey( "ChangeDCCObject" );
if ( pDialogKeys )
{
m_pDCCObjectName->SetText( pDCCObjectName );
OnDCCObjectNameChanged();
return;
}
pDialogKeys = kv->FindKey( "AddDCCObject" );
if ( pDialogKeys )
{
OnDCCObjectAdded( pDCCObjectName, pDialogKeys );
return;
}
}
//-----------------------------------------------------------------------------
// Shows the DCC object browser (once we have one)
//-----------------------------------------------------------------------------
void CDmeSourceDCCFilePanel::ShowDCCObjectBrowser( const char *pTitle, const char *pPrompt, KeyValues *pDialogKeys )
{
InputDialog *pInput = new InputDialog( this, pTitle, pPrompt );
pInput->SetMultiline( false );
pInput->DoModal( pDialogKeys );
}
//-----------------------------------------------------------------------------
// Called when the button to add a file is clicked
//-----------------------------------------------------------------------------
void CDmeSourceDCCFilePanel::OnAddDCCObject( )
{
if ( m_hSourceDCCFile.Get() )
{
KeyValues *pDialogKeys = new KeyValues( "AddDCCObject" );
ShowDCCObjectBrowser( "Add DCC Object", "Enter DCC object name to add", pDialogKeys );
}
}
//-----------------------------------------------------------------------------
// Called when the button to browse for a source file is clicked
//-----------------------------------------------------------------------------
void CDmeSourceDCCFilePanel::OnBrowseDCCObject( )
{
int nCount = m_pRootDCCObjects->GetSelectedItemsCount();
if ( nCount == 0 || !m_hSourceDCCFile.Get() )
return;
int nItemID = m_pRootDCCObjects->GetSelectedItem( 0 );
KeyValues *pKeyValues = m_pRootDCCObjects->GetItem( nItemID );
int nDCCObjectIndex = pKeyValues->GetInt( "dccObjectIndex", -1 );
KeyValues *pDialogKeys = new KeyValues( "ChangeDCCObject", "dccObjectIndex", nDCCObjectIndex );
ShowDCCObjectBrowser( "Edit Maya/XSI Object", "Enter new name of Maya/XSI object", pDialogKeys );
}
//-----------------------------------------------------------------------------
// Called when the source file name changes
//-----------------------------------------------------------------------------
bool CDmeSourceDCCFilePanel::CheckForDuplicateNames( const char *pDCCObjectName, int nDCCObjectSkipIndex )
{
// Look for the existence of this source already
if ( pDCCObjectName[0] )
{
int nCount = m_hSourceDCCFile->m_RootDCCObjects.Count();
for ( int i = 0; i < nCount; ++i )
{
if ( i == nDCCObjectSkipIndex )
continue;
if ( !Q_stricmp( pDCCObjectName, m_hSourceDCCFile->m_RootDCCObjects[i] ) )
{
vgui::MessageBox *pError = new vgui::MessageBox( "#DmeSourceDCCFile_DuplicateSourceTitle", "#DmeSourceDCCFile_DuplicateSourceText", GetParent() );
pError->DoModal();
return true;
}
}
}
return false;
}
//-----------------------------------------------------------------------------
// Called when the source file name changes
//-----------------------------------------------------------------------------
void CDmeSourceDCCFilePanel::OnDCCObjectNameChanged()
{
int nCount = m_pRootDCCObjects->GetSelectedItemsCount();
if ( nCount == 0 || !m_hSourceDCCFile.Get() )
return;
int nItemID = m_pRootDCCObjects->GetSelectedItem( 0 );
KeyValues *pKeyValues = m_pRootDCCObjects->GetItem( nItemID );
int nDCCObjectIndex = pKeyValues->GetInt( "dccObjectIndex", -1 );
if ( nDCCObjectIndex < 0 )
return;
char pDCCObjectName[MAX_PATH];
m_pDCCObjectName->GetText( pDCCObjectName, sizeof(pDCCObjectName) );
if ( CheckForDuplicateNames( pDCCObjectName, nDCCObjectIndex ) )
return;
{
CDisableUndoScopeGuard guard;
m_hSourceDCCFile->m_RootDCCObjects.Set( nDCCObjectIndex, pDCCObjectName );
}
pKeyValues->SetString( "dccobject", pDCCObjectName );
m_pRootDCCObjects->ApplyItemChanges( nItemID );
m_pRootDCCObjects->SortList();
SetDirty( );
}
//-----------------------------------------------------------------------------
// Used for sorting below
//-----------------------------------------------------------------------------
static int IntCompare( const void *pSrc1, const void *pSrc2 )
{
int i1 = *(int*)pSrc1;
int i2 = *(int*)pSrc2;
return i1 - i2;
}
//-----------------------------------------------------------------------------
// Called when the button to remove a DCC object is clicked
//-----------------------------------------------------------------------------
void CDmeSourceDCCFilePanel::OnRemoveDCCObject( )
{
int nCount = m_pRootDCCObjects->GetSelectedItemsCount();
if ( nCount == 0 || !m_hSourceDCCFile.Get() )
return;
int nSelectedCount = 0;
int *pDCCObjectIndex = (int*)alloca( nCount*sizeof(int) );
for ( int i = 0; i < nCount; ++i )
{
int nItemID = m_pRootDCCObjects->GetSelectedItem( i );
KeyValues *pKeyValues = m_pRootDCCObjects->GetItem( nItemID );
int nDCCObjectIndex = pKeyValues->GetInt( "dccObjectIndex", -1 );
if ( nDCCObjectIndex < 0 )
continue;
pDCCObjectIndex[nSelectedCount++] = nDCCObjectIndex;
}
if ( nSelectedCount == 0 )
return;
// Sort the object indices so we can remove them all
qsort( pDCCObjectIndex, nSelectedCount, sizeof(int), IntCompare );
// Update the selection to be reasonable after deletion
int nItemID = m_pRootDCCObjects->GetSelectedItem( 0 );
int nRow = m_pRootDCCObjects->GetItemCurrentRow( nItemID );
Assert( nRow >= 0 );
{
CDisableUndoScopeGuard guard;
// Because we sorted it above, removes will occur properly
for ( int i = nSelectedCount; --i >= 0; )
{
m_hSourceDCCFile->m_RootDCCObjects.Remove( pDCCObjectIndex[i] );
}
SetDirty( );
}
RefreshDCCObjectList();
int nVisibleRowCount = m_pRootDCCObjects->GetItemCount();
if ( nVisibleRowCount == 0 )
return;
if ( nRow >= nVisibleRowCount )
{
nRow = nVisibleRowCount - 1;
}
int nNewItemID = m_pRootDCCObjects->GetItemIDFromRow( nRow );
m_pRootDCCObjects->SetSingleSelectedItem( nNewItemID );
}
//-----------------------------------------------------------------------------
// Called when a key is typed
//-----------------------------------------------------------------------------
void CDmeSourceDCCFilePanel::OnKeyCodeTyped( vgui::KeyCode code )
{
if ( code == KEY_DELETE )
{
OnRemoveDCCObject();
return;
}
BaseClass::OnKeyCodeTyped( code );
}
//-----------------------------------------------------------------------------
// Command handler
//-----------------------------------------------------------------------------
void CDmeSourceDCCFilePanel::OnCommand( const char *pCommand )
{
if ( !Q_stricmp( pCommand, "OnBrowseDCCObject" ) )
{
OnBrowseDCCObject();
return;
}
if ( !Q_stricmp( pCommand, "OnAddDCCObject" ) )
{
OnAddDCCObject();
return;
}
if ( !Q_stricmp( pCommand, "OnRemoveDCCObject" ) )
{
OnRemoveDCCObject();
return;
}
if ( !Q_stricmp( pCommand, "OnApplyChanges" ) )
{
OnDCCObjectNameChanged();
return;
}
BaseClass::OnCommand( pCommand );
}
+143
View File
@@ -0,0 +1,143 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================
#include "dme_controls/DmeSourceSkinPanel.h"
#include "dme_controls/DmePanel.h"
#include "movieobjects/dmemdlmakefile.h"
#include "vgui_controls/TextEntry.h"
#include "vgui_controls/CheckButton.h"
#include "tier1/KeyValues.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
//
// Hook into the dme panel editor system
//
//-----------------------------------------------------------------------------
IMPLEMENT_DMEPANEL_FACTORY( CDmeSourceSkinPanel, DmeSourceSkin, "DmeSourceSkinDefault", "MDL Skin Editor", true );
//-----------------------------------------------------------------------------
// Purpose: Constructor, destructor
//-----------------------------------------------------------------------------
CDmeSourceSkinPanel::CDmeSourceSkinPanel( vgui::Panel *pParent, const char *pPanelName ) :
BaseClass( pParent, pPanelName )
{
m_pSkinName = new vgui::TextEntry( this, "SkinName" );
m_pSkinName->AddActionSignalTarget( this );
m_pScale = new vgui::TextEntry( this, "Scale" );
m_pScale->AddActionSignalTarget( this );
m_pFlipTriangles = new vgui::CheckButton( this, "FlipTriangles", "" );
m_pFlipTriangles->AddActionSignalTarget( this );
// Load layout settings; has to happen before pinning occurs in code
LoadControlSettings( "resource/DmeSourceSkinPanel.res" );
}
CDmeSourceSkinPanel::~CDmeSourceSkinPanel()
{
}
//-----------------------------------------------------------------------------
// Marks the file as dirty (or not)
//-----------------------------------------------------------------------------
void CDmeSourceSkinPanel::SetDirty()
{
PostActionSignal( new KeyValues( "DmeElementChanged" ) );
}
//-----------------------------------------------------------------------------
// Resets the state
//-----------------------------------------------------------------------------
void CDmeSourceSkinPanel::SetDmeElement( CDmeSourceSkin *pSourceSkin )
{
m_hSourceSkin = pSourceSkin;
bool bEnabled = (pSourceSkin != NULL);
m_pSkinName->SetEnabled( bEnabled );
m_pScale->SetEnabled( bEnabled );
m_pFlipTriangles->SetEnabled( bEnabled );
if ( !bEnabled )
{
m_pSkinName->SetText( "" );
m_pScale->SetText( "" );
m_pFlipTriangles->SetSelected( false );
return;
}
char pBuf[32];
Q_snprintf( pBuf, sizeof(pBuf), "%.3f", pSourceSkin->m_flScale.Get() );
m_pSkinName->SetText( pSourceSkin->m_SkinName );
m_pScale->SetText( pBuf );
m_pFlipTriangles->SetSelected( pSourceSkin->m_bFlipTriangles );
}
//-----------------------------------------------------------------------------
// Command handler
//-----------------------------------------------------------------------------
void CDmeSourceSkinPanel::OnCheckButtonChecked( int nChecked )
{
if ( !m_hSourceSkin.Get() )
return;
bool bFlipTriangles = ( nChecked != 0 );
if ( bFlipTriangles != m_hSourceSkin->m_bFlipTriangles )
{
m_hSourceSkin->m_bFlipTriangles = bFlipTriangles;
SetDirty();
}
}
//-----------------------------------------------------------------------------
// Called when something is typed in a text entry field
//-----------------------------------------------------------------------------
void CDmeSourceSkinPanel::OnTextChanged( KeyValues *kv )
{
if ( !m_hSourceSkin.Get() )
return;
Panel *pPanel = (Panel *)kv->GetPtr( "panel", NULL );
if ( pPanel == m_pSkinName )
{
char pTextBuf[256];
m_pSkinName->GetText( pTextBuf, sizeof( pTextBuf) );
if ( Q_stricmp( pTextBuf, m_hSourceSkin->m_SkinName ) )
{
m_hSourceSkin->m_SkinName = pTextBuf;
SetDirty();
}
return;
}
if ( pPanel == m_pScale )
{
char pTextBuf[256];
m_pScale->GetText( pTextBuf, sizeof( pTextBuf) );
float flScale = atoi( pTextBuf );
if ( flScale != m_hSourceSkin->m_flScale )
{
m_hSourceSkin->m_flScale = flScale;
SetDirty();
}
return;
}
}
File diff suppressed because it is too large Load Diff
+58
View File
@@ -0,0 +1,58 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "KeyValues.h"
#include "dme_controls/ElementPropertiesTree.h"
#include "datamodel/dmelement.h"
#include "vgui_controls/TextEntry.h"
#include "vgui_controls/ComboBox.h"
#include "vgui_controls/Button.h"
#include "vgui_controls/PanelListPanel.h"
#include "FactoryOverloads.h"
void CFactoryOverloads::AddOverload(
char const *attributeName,
IAttributeWidgetFactory *newFactory,
IAttributeElementChoiceList *newChoiceList )
{
Assert( attributeName );
Assert( newFactory || newChoiceList );
if ( !newFactory )
{
return;
}
Entry_t e;
e.factory = newFactory;
e.choices = newChoiceList;
m_Overloads.Insert( attributeName, e );
}
int CFactoryOverloads::Count()
{
return m_Overloads.Count();
}
char const *CFactoryOverloads::Name( int index )
{
return m_Overloads.GetElementName( index );
}
IAttributeWidgetFactory *CFactoryOverloads::Factory( int index )
{
return m_Overloads[ index ].factory;
}
IAttributeElementChoiceList *CFactoryOverloads::ChoiceList( int index )
{
return m_Overloads[ index ].choices;
}
+49
View File
@@ -0,0 +1,49 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
#ifndef FACTORYOVERLOADS_H
#define FACTORYOVERLOADS_H
#ifdef _WIN32
#pragma once
#endif
#include "utldict.h"
class IAttributeWidgetFactory;
class IAttributeElementChoiceList;
class CFactoryOverloads : public IFactoryOverloads
{
public:
virtual void AddOverload
(
char const *attributeName,
IAttributeWidgetFactory *newFactory,
IAttributeElementChoiceList *newChoiceList
);
int Count();
char const *Name( int index );
IAttributeWidgetFactory *Factory( int index );
IAttributeElementChoiceList *ChoiceList( int index );
private:
struct Entry_t
{
Entry_t() :
factory( 0 ),
choices( 0 )
{
}
IAttributeWidgetFactory *factory;
IAttributeElementChoiceList *choices;
};
CUtlDict< Entry_t, int > m_Overloads;
};
#endif // FACTORYOVERLOADS_H
+618
View File
@@ -0,0 +1,618 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "dme_controls/filelistmanager.h"
#include "vgui_controls/FileOpenDialog.h"
#include "vgui_controls/menu.h"
#include "vgui_controls/messagebox.h"
#include "datamodel/idatamodel.h"
#include "datamodel/dmelement.h"
#include "datamodel/dmattribute.h"
#include "datamodel/dmattributevar.h"
#include "vgui/ISurface.h"
#include <vgui/IInput.h>
#include "vgui/mousecode.h"
#include "tier1/strtools.h"
#include "tier1/KeyValues.h"
#include "tier2/tier2.h"
#include "p4lib/ip4.h"
#include "filesystem.h"
#include "dme_controls/INotifyUI.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
template < int C >
int ListPanelStringSortFunc( vgui::ListPanel *pPanel, const vgui::ListPanelItem &item1, const vgui::ListPanelItem &item2 );
struct ColumnInfo_t
{
char const *columnName;
char const *columnText;
int startingWidth;
int flags;
vgui::SortFunc *pfnSort;
vgui::Label::Alignment alignment;
};
enum ColumnIndex_t
{
CI_FILENAME,
CI_PATH,
CI_LOADED,
CI_NUMELEMENTS,
CI_CHANGED,
CI_INPERFORCE,
CI_OPENFOREDIT,
};
const int baseflags = vgui::ListPanel::COLUMN_UNHIDABLE;
const int fixedflags = vgui::ListPanel::COLUMN_UNHIDABLE | vgui::ListPanel::COLUMN_FIXEDSIZE;
static ColumnInfo_t g_ColInfo[] =
{
{ "filename", "#BxFileManager_Filename", 150, baseflags, ListPanelStringSortFunc< CI_FILENAME >, vgui::Label::a_west },
{ "path", "#BxFileManager_Path", 240, baseflags, ListPanelStringSortFunc< CI_PATH >, vgui::Label::a_west },
{ "loaded", "#BxFileManager_Loaded", 40, fixedflags, ListPanelStringSortFunc< CI_LOADED >, vgui::Label::a_center },
{ "numelements", "#BxFileManager_NumElements", 60, fixedflags, ListPanelStringSortFunc< CI_NUMELEMENTS >, vgui::Label::a_east },
{ "changed", "#BxFileManager_Changed", 50, fixedflags, ListPanelStringSortFunc< CI_CHANGED >, vgui::Label::a_center },
{ "in_perforce", "#BxFileManager_P4Exists", 35, fixedflags, ListPanelStringSortFunc< CI_INPERFORCE >, vgui::Label::a_center },
{ "open_for_edit", "#BxFileManager_P4Edit", 40, fixedflags, ListPanelStringSortFunc< CI_OPENFOREDIT >, vgui::Label::a_center },
};
const char *GetKey( ColumnIndex_t ci )
{
return g_ColInfo[ ci ].columnName;
}
template < int C >
int ListPanelStringSortFunc( vgui::ListPanel *pPanel, const vgui::ListPanelItem &item1, const vgui::ListPanelItem &item2 )
{
NOTE_UNUSED( pPanel );
const char *pKey = GetKey( ( ColumnIndex_t )C );
const char *string1 = item1.kv->GetString( pKey );
const char *string2 = item2.kv->GetString( pKey );
return Q_stricmp( string1, string2 );
}
void AddColumn( CFileListManager *pFileManager, ColumnIndex_t ci )
{
pFileManager->AddColumnHeader( ci, g_ColInfo[ ci ].columnName, g_ColInfo[ ci ].columnText, g_ColInfo[ ci ].startingWidth, g_ColInfo[ ci ].flags );
pFileManager->SetSortFunc( ci, g_ColInfo[ ci ].pfnSort );
pFileManager->SetColumnTextAlignment( ci, g_ColInfo[ ci ].alignment );
}
CFileListManager::CFileListManager( vgui::Panel *parent ) : BaseClass( parent, "FileListManager" )
{
SetMultiselectEnabled( true );
SetVisible( true );
m_bRefreshRequired = false;
SetSize( 800, 200 );
SetPos( 100, 100 );
AddColumn( this, CI_FILENAME );
AddColumn( this, CI_PATH );
AddColumn( this, CI_LOADED );
AddColumn( this, CI_NUMELEMENTS );
AddColumn( this, CI_CHANGED );
AddColumn( this, CI_INPERFORCE );
AddColumn( this, CI_OPENFOREDIT );
SetSortColumn( 0 );
Refresh();
SetScheme( vgui::scheme()->LoadSchemeFromFile( "Resource/BoxRocket.res", "BoxRocket" ) );
// LoadControlSettings( "resource/BxFileListManager.res" );
}
int CFileListManager::AddItem( DmFileId_t fileid, const char *pFilename, const char *pPath, bool bLoaded, int nElements, bool bChanged, bool bInPerforce, bool bOpenForEdit )
{
KeyValues *kv = new KeyValues( "", GetKey( CI_FILENAME ), pFilename, GetKey( CI_PATH ), pPath );
kv->SetInt ( GetKey( CI_NUMELEMENTS ), nElements );
kv->SetString( GetKey( CI_LOADED ), bLoaded ? "Y" : "N" );
kv->SetString( GetKey( CI_CHANGED ), bChanged ? "Y" : "N" );
kv->SetString( GetKey( CI_INPERFORCE ), bInPerforce ? "Y" : "N" );
kv->SetString( GetKey( CI_OPENFOREDIT ), bOpenForEdit ? "Y" : "N" );
int itemID = BaseClass::AddItem( kv, fileid, false, false );
kv->deleteThis();
return itemID;
}
void CFileListManager::SetLoaded( DmFileId_t fileid, bool bLoaded )
{
CNotifyScopeGuard notify( "CFileListManager::SetLoaded", NOTIFY_SOURCE_FILE_LIST_MANAGER, NOTIFY_SETDIRTYFLAG );
if ( bLoaded )
{
const char *pFilename = g_pDataModel->GetFileName( fileid );
Assert( pFilename );
if ( !pFilename )
return;
CDisableUndoScopeGuard guard;
CDmElement *pRoot = NULL;
g_pDataModel->RestoreFromFile( pFilename, NULL, NULL, &pRoot, CR_DELETE_NEW );
}
else
{
CDisableUndoScopeGuard guard;
g_pDataModel->UnloadFile( fileid );
}
}
void CFileListManager::OnMousePressed( vgui::MouseCode code )
{
// determine where we were pressed
int x, y, row, column;
vgui::input()->GetCursorPos( x, y );
GetCellAtPos( x, y, row, column );
if ( code == MOUSE_LEFT )
{
bool bIsFakeToggleButton = column == CI_LOADED;
if ( bIsFakeToggleButton && row >= 0 && row < GetItemCount() )
{
int itemID = GetItemIDFromRow( row );
KeyValues *kv = GetItem( itemID );
const char *pStr = kv->GetString( GetKey( ( ColumnIndex_t )column ), "" );
Assert( *pStr == 'Y' || *pStr == 'N' );
bool bSet = *pStr == 'N'; // bSet is the NEW state, not the old one
kv->SetString( GetKey( ( ColumnIndex_t )column ), bSet ? "Y" : "N" );
SetLoaded( ( DmFileId_t )GetItemUserData( itemID ), bSet );
// get the key focus
RequestFocus();
return;
}
}
else if ( code == MOUSE_RIGHT )
{
int itemID = -1;
if ( row >= 0 && row < GetItemCount() )
{
itemID = GetItemIDFromRow( row );
if ( !IsItemSelected( itemID ) )
{
SetSingleSelectedItem( itemID );
}
}
KeyValues *kv = new KeyValues( "OpenContextMenu", "itemID", itemID );
OnOpenContextMenu( kv );
kv->deleteThis();
return;
}
BaseClass::OnMousePressed( code );
}
int AddMenuItemHelper( vgui::Menu *pMenu, const char *pItemName, const char *pKVName, vgui::Panel *pTarget, bool bEnabled )
{
int id = pMenu->AddMenuItem( pItemName, new KeyValues( pKVName ), pTarget );
pMenu->SetItemEnabled( id, bEnabled );
return id;
}
void CFileListManager::OnOpenContextMenu( KeyValues *pParams )
{
if ( m_hContextMenu.Get() )
{
delete m_hContextMenu.Get();
m_hContextMenu = NULL;
}
m_hContextMenu = new vgui::Menu( this, "ContextMenu" );
int itemID = pParams->GetInt( "itemID", -1 );
if ( itemID < 0 )
{
AddMenuItemHelper( m_hContextMenu, "Open File...", "open", this, true ); // Is this how we should load other files???
}
else
{
bool bP4Connected = p4->IsConnectedToServer();
int nSelected = GetSelectedItemsCount();
int nLoaded = 0;
int nChanged = 0;
int nOnDisk = 0;
int nInPerforce = 0;
int nOpenForEdit = 0;
for ( int i = 0; i < nSelected; ++i )
{
int itemId = GetSelectedItem( i );
DmFileId_t fileid = ( DmFileId_t )GetItemUserData( itemId );
if ( g_pDataModel->IsFileLoaded( fileid ) )
{
++nLoaded;
++nChanged; // TODO - find out for real
}
const char *pFilename = g_pDataModel->GetFileName( fileid );
if ( g_pFullFileSystem->FileExists( pFilename ) )
{
++nOnDisk;
}
if ( bP4Connected )
{
if ( p4->IsFileInPerforce( pFilename ) )
{
++nInPerforce;
if ( p4->GetFileState( pFilename ) != P4FILE_UNOPENED )
{
++nOpenForEdit;
}
}
}
}
AddMenuItemHelper( m_hContextMenu, "Load", "load", this, nLoaded < nSelected && nOnDisk > 0 );
AddMenuItemHelper( m_hContextMenu, "Unload", "unload", this, nLoaded > 0 );
AddMenuItemHelper( m_hContextMenu, "Save", "save", this, nChanged > 0 && nOnDisk == nSelected );
AddMenuItemHelper( m_hContextMenu, "Save As...", "saveas", this, nLoaded == 1 && nSelected == 1 );
AddMenuItemHelper( m_hContextMenu, "Add To Perforce", "p4add", this, nInPerforce < nSelected && nOnDisk > 0 );
AddMenuItemHelper( m_hContextMenu, "Open For Edit", "p4edit", this, nOpenForEdit < nSelected && nOnDisk > 0 );
}
vgui::Menu::PlaceContextMenu( this, m_hContextMenu.Get() );
}
void CFileListManager::OnLoadFiles( KeyValues *pParams )
{
CNotifyScopeGuard notify( "CFileListManager::OnLoadFiles", NOTIFY_SOURCE_FILE_LIST_MANAGER, NOTIFY_SETDIRTYFLAG );
int nSelected = GetSelectedItemsCount();
for ( int i = 0; i < nSelected; ++i )
{
int itemId = GetSelectedItem( i );
DmFileId_t fileid = ( DmFileId_t )GetItemUserData( itemId );
if ( !g_pDataModel->IsFileLoaded( fileid ) )
{
SetLoaded( fileid, true );
}
}
Refresh();
}
void CFileListManager::OnUnloadFiles( KeyValues *pParams )
{
CNotifyScopeGuard notify( "CFileListManager::OnUnloadFiles", NOTIFY_SOURCE_FILE_LIST_MANAGER, NOTIFY_SETDIRTYFLAG );
int nSelected = GetSelectedItemsCount();
for ( int i = 0; i < nSelected; ++i )
{
int itemId = GetSelectedItem( i );
DmFileId_t fileid = ( DmFileId_t )GetItemUserData( itemId );
if ( g_pDataModel->IsFileLoaded( fileid ) )
{
SetLoaded( fileid, false );
}
}
Refresh();
}
void CFileListManager::OnSaveFiles( KeyValues *pParams )
{
int nSelected = GetSelectedItemsCount();
for ( int i = 0; i < nSelected; ++i )
{
int itemId = GetSelectedItem( i );
DmFileId_t fileid = ( DmFileId_t )GetItemUserData( itemId );
if ( !g_pDataModel->IsFileLoaded( fileid ) )
continue;
const char *pFilename = g_pDataModel->GetFileName( fileid );
Assert( pFilename );
if ( !pFilename )
continue;
CDmElement *pRoot = GetElement< CDmElement >( g_pDataModel->GetFileRoot( fileid ) );
Assert( pRoot );
if ( !pRoot )
continue;
const char *pFileFormat = g_pDataModel->GetFileFormat( fileid );
const char *pEncoding = g_pDataModel->GetDefaultEncoding( pFileFormat );
g_pDataModel->SaveToFile( pFilename, NULL, pEncoding, pFileFormat, pRoot );
}
Refresh();
}
void CFileListManager::OnOpenFile( KeyValues *pParams )
{
KeyValues *pContextKeyValues = new KeyValues( "OnOpen" );
vgui::FileOpenDialog *pFileOpenDialog = new vgui::FileOpenDialog( this, "Save .dmx File As", false, pContextKeyValues );
pFileOpenDialog->AddFilter( "*.dmx", "DmElements File (*.dmx)", true );
pFileOpenDialog->AddActionSignalTarget( this );
pFileOpenDialog->SetDeleteSelfOnClose( true );
pFileOpenDialog->DoModal( false );
}
void CFileListManager::OnSaveFileAs( KeyValues *pParams )
{
int nSelected = GetSelectedItemsCount();
Assert( nSelected == 1 );
if ( nSelected != 1 )
return;
KeyValues *pContextKeyValues = new KeyValues( "OnSaveAs" );
pContextKeyValues->SetInt( "itemId", GetSelectedItem( 0 ) );
DmFileId_t fileid = ( DmFileId_t )GetItemUserData( GetSelectedItem( 0 ) );
const char *pFileFormat = g_pDataModel->GetFileFormat( fileid );
vgui::FileOpenDialog *pFileOpenDialog = new vgui::FileOpenDialog( this, "Save .dmx File As", false, pContextKeyValues );
// if this control is moved to vgui_controls, change the default format to "dmx", the generic dmx format
pFileOpenDialog->AddFilter( "*.dmx", "Generic MovieObjects File (*.dmx)", false, "movieobjects" );
if ( V_strcmp( pFileFormat, "movieobjects" ) != 0 )
{
char description[ 256 ];
V_snprintf( description, sizeof( description ), "%s (*.dmx)", g_pDataModel->GetFormatDescription( pFileFormat ) );
pFileOpenDialog->AddFilter( "*.dmx", description, true, pFileFormat );
}
pFileOpenDialog->AddActionSignalTarget( this );
pFileOpenDialog->SetDeleteSelfOnClose( true );
pFileOpenDialog->DoModal( false );
}
void CFileListManager::OnFileSelected( KeyValues *pParams )
{
const char *pFullPath = pParams->GetString( "fullpath" );
if ( !pFullPath || !pFullPath[ 0 ] )
return;
KeyValues *pSaveAsKey = pParams->FindKey( "OnSaveAs" );
if ( pSaveAsKey )
{
int itemId = pSaveAsKey->GetInt( "itemId", -1 );
Assert( itemId != -1 );
if ( itemId == -1 )
return;
DmFileId_t fileid = ( DmFileId_t )GetItemUserData( itemId );
Assert( fileid != DMFILEID_INVALID );
if ( fileid == DMFILEID_INVALID )
return;
CDmElement *pRoot = GetElement< CDmElement >( g_pDataModel->GetFileRoot( fileid ) );
Assert( pRoot );
if ( !pRoot )
return;
const char *pFormat = pParams->GetString( "filterinfo" );
Assert( pFormat );
if ( !pFormat )
return;
g_pDataModel->SetFileName( fileid, pFullPath );
g_pDataModel->SaveToFile( pFullPath, NULL, g_pDataModel->GetDefaultEncoding( pFormat ), pFormat, pRoot );
Refresh();
return;
}
KeyValues *pOpenKey = pParams->FindKey( "OnOpen" );
if ( pOpenKey )
{
CDmElement *pRoot = NULL;
g_pDataModel->RestoreFromFile( pFullPath, NULL, NULL, &pRoot );
Refresh();
return;
}
}
void CFileListManager::OnAddToPerforce( KeyValues *pParams )
{
int nFileCount = 0;
int nSelected = GetSelectedItemsCount();
const char **ppFileNames = ( const char** )_alloca( nSelected * sizeof( char* ) );
for ( int i = 0; i < nSelected; ++i )
{
int itemId = GetSelectedItem( i );
DmFileId_t fileid = ( DmFileId_t )GetItemUserData( itemId );
const char *pFilename = g_pDataModel->GetFileName( fileid );
Assert( pFilename );
if ( !pFilename )
continue;
++nFileCount;
ppFileNames[ i ] = pFilename;
}
bool bSuccess = p4->OpenFilesForAdd( nFileCount, ppFileNames );
if ( !bSuccess )
{
vgui::MessageBox *pError = new vgui::MessageBox( "Perforce Error!", p4->GetLastError(), GetParent() );
pError->SetSmallCaption( true );
pError->DoModal();
}
Refresh();
}
void CFileListManager::OnOpenForEdit( KeyValues *pParams )
{
int nFileCount = 0;
int nSelected = GetSelectedItemsCount();
const char **ppFileNames = ( const char** )_alloca( nSelected * sizeof( char* ) );
for ( int i = 0; i < nSelected; ++i )
{
int itemId = GetSelectedItem( i );
DmFileId_t fileid = ( DmFileId_t )GetItemUserData( itemId );
const char *pFilename = g_pDataModel->GetFileName( fileid );
Assert( pFilename );
if ( !pFilename )
continue;
++nFileCount;
ppFileNames[ i ] = pFilename;
}
bool bSuccess = p4->OpenFilesForEdit( nFileCount, ppFileNames );
if ( !bSuccess )
{
vgui::MessageBox *pError = new vgui::MessageBox( "Perforce Error!", p4->GetLastError(), GetParent() );
pError->SetSmallCaption( true );
pError->DoModal();
}
Refresh();
}
void CFileListManager::OnDataChanged( KeyValues *pParams )
{
int nNotifyFlags = pParams->GetInt( "notifyFlags" );
if ( ( nNotifyFlags & NOTIFY_CHANGE_TOPOLOGICAL ) == 0 )
return;
int nNotifySource = pParams->GetInt( "source" );
if ( nNotifySource == NOTIFY_SOURCE_FILE_LIST_MANAGER )
return;
if ( !IsVisible() )
{
m_bRefreshRequired = true;
return;
}
int nCount = GetItemCount();
int nFiles = g_pDataModel->NumFileIds();
bool bPerformFullRefresh = ( nCount != nFiles );
if ( !bPerformFullRefresh )
{
const char *pNameKey = GetKey( CI_FILENAME );
for ( int i = 0; i < nCount; ++i )
{
DmFileId_t fileid = g_pDataModel->GetFileId( i );
const char *pFileName = g_pDataModel->GetFileName( fileid );
if ( !pFileName || !*pFileName )
{
bPerformFullRefresh = true;
break;
}
pFileName = V_UnqualifiedFileName( pFileName );
KeyValues *pKeyValues = GetItem( i );
bPerformFullRefresh = ( fileid != (DmFileId_t)GetItemUserData(i) ) || Q_stricmp( pFileName, pKeyValues->GetString( pNameKey ) );
if ( bPerformFullRefresh )
break;
pKeyValues->SetInt ( GetKey( CI_NUMELEMENTS ), g_pDataModel->NumElementsInFile( fileid ) );
pKeyValues->SetString( GetKey( CI_LOADED ), g_pDataModel->IsFileLoaded( fileid ) ? "Y" : "N" );
pKeyValues->SetString( GetKey( CI_CHANGED ), false ? "Y" : "N" );
ApplyItemChanges( i );
}
}
if ( bPerformFullRefresh )
{
Refresh();
return;
}
}
void CFileListManager::Refresh()
{
m_bRefreshRequired = false;
RemoveAll();
const bool bP4Connected = p4 ? p4->IsConnectedToServer() : false;
int nFiles = g_pDataModel->NumFileIds();
for ( int i = 0; i < nFiles; ++i )
{
DmFileId_t fileid = g_pDataModel->GetFileId( i );
const char *pFileName = g_pDataModel->GetFileName( fileid );
if ( !pFileName || !*pFileName )
continue; // skip DMFILEID_INVALID and the default fileid ""
bool bLoaded = g_pDataModel->IsFileLoaded( fileid );
int nElements = g_pDataModel->NumElementsInFile( fileid );
bool bChanged = false; // TODO - find out for real
bool bInPerforce = bP4Connected && p4->IsFileInPerforce( pFileName );
bool bOpenForEdit = bInPerforce && p4->GetFileState( pFileName ) != P4FILE_UNOPENED;
char path[ 256 ];
V_ExtractFilePath( pFileName, path, sizeof( path ) );
AddItem( fileid, V_UnqualifiedFileName( pFileName ), path, bLoaded, nElements, bChanged, bInPerforce, bOpenForEdit );
}
}
void CFileListManager::OnThink( )
{
BaseClass::OnThink();
if ( m_bRefreshRequired && IsVisible() )
{
Refresh();
}
}
void CFileListManager::OnCommand( const char *cmd )
{
// if ( !Q_stricmp( cmd, "foo" ) ) ...
BaseClass::OnCommand( cmd );
}
//-----------------------------------------------------------------------------
//
// CFileManagerFrame methods
//
//-----------------------------------------------------------------------------
CFileManagerFrame::CFileManagerFrame( vgui::Panel *parent ) : BaseClass( parent, "FileManagerFrame" )
{
SetTitle( "#BxFileManagerFrame", true );
SetSizeable( true );
SetCloseButtonVisible( false );
SetMinimumSize( 200, 200 );
SetVisible( true );
SetSize( 800, 200 );
SetPos( 100, 100 );
m_pFileListManager = new CFileListManager( this );
Refresh();
SetScheme( vgui::scheme()->LoadSchemeFromFile( "Resource/BoxRocket.res", "BoxRocket" ) );
}
void CFileManagerFrame::Refresh()
{
m_pFileListManager->Refresh();
}
void CFileManagerFrame::OnCommand( const char *cmd )
{
BaseClass::OnCommand( cmd );
m_pFileListManager->OnCommand( cmd );
}
void CFileManagerFrame::PerformLayout()
{
BaseClass::PerformLayout();
int iWidth, iHeight;
GetSize( iWidth, iHeight );
m_pFileListManager->SetPos( 0, GetCaptionHeight() );
m_pFileListManager->SetSize( iWidth, iHeight - GetCaptionHeight() );
}
@@ -0,0 +1,69 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "dme_controls/AttributeAssetPickerPanel.h"
#include "dme_controls/AttributeTextEntry.h"
#include "matsys_controls/AssetPicker.h"
#include "matsys_controls/VtfPicker.h"
#include "matsys_controls/VMTPicker.h"
#include "tier1/KeyValues.h"
using namespace vgui;
//-----------------------------------------------------------------------------
// Assets
//-----------------------------------------------------------------------------
IMPLEMENT_ATTRIBUTE_ASSET_PICKER( CAttributeBspPickerPanel, "Select .BSP file", "BSP Files", "bsp", "maps", "bspName" );
IMPLEMENT_ATTRIBUTE_ASSET_PREVIEW_PICKER( CAttributeVmtPickerPanel, CVMTPickerFrame, "Select .VMT file" );
IMPLEMENT_ATTRIBUTE_ASSET_PREVIEW_PICKER( CAttributeVtfPickerPanel, CVTFPickerFrame, "Select .VTF file" );
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CAttributeAssetPickerPanel::CAttributeAssetPickerPanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
BaseClass( parent, info )
{
}
CAttributeAssetPickerPanel::~CAttributeAssetPickerPanel()
{
}
//-----------------------------------------------------------------------------
// Called when it's time to show the BSP picker
//-----------------------------------------------------------------------------
void CAttributeAssetPickerPanel::ShowPickerDialog()
{
CBaseAssetPickerFrame *pAssetPickerDialog = CreateAssetPickerFrame( );
pAssetPickerDialog->AddActionSignalTarget( this );
pAssetPickerDialog->DoModal( );
}
//-----------------------------------------------------------------------------
// Called by the asset picker dialog if a asset was selected
//-----------------------------------------------------------------------------
void CAttributeAssetPickerPanel::OnAssetSelected( KeyValues *pKeyValues )
{
// Get the asset name back
const char *pAssetName = pKeyValues->GetString( "asset", NULL );
if ( !pAssetName || !pAssetName[ 0 ] )
return;
// Apply to text panel
m_pData->SetText( pAssetName );
SetDirty(true);
if ( IsAutoApply() )
{
Apply();
}
}
@@ -0,0 +1,88 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "dme_controls/AttributeDetailTypePickerPanel.h"
#include "dme_controls/AttributeTextEntry.h"
#include "tier1/KeyValues.h"
#include "filesystem.h"
using namespace vgui;
const char *DETAILTYPE_FILE = "detail.vbsp";
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CAttributeDetailTypePickerPanel::CAttributeDetailTypePickerPanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
BaseClass( parent, info )
{
}
CAttributeDetailTypePickerPanel::~CAttributeDetailTypePickerPanel()
{
}
//-----------------------------------------------------------------------------
// Reads the detail types
//-----------------------------------------------------------------------------
void CAttributeDetailTypePickerPanel::AddDetailTypesToList( PickerList_t &list )
{
KeyValues *pDetailTypes = new KeyValues( DETAILTYPE_FILE );
if ( pDetailTypes->LoadFromFile( g_pFullFileSystem, DETAILTYPE_FILE, "GAME" ) )
{
for ( KeyValues *sub = pDetailTypes->GetFirstTrueSubKey(); sub != NULL; sub = sub->GetNextTrueSubKey() )
{
int i = list.AddToTail( );
list[i].m_pChoiceString = sub->GetName();
list[i].m_pChoiceValue = sub->GetName();
}
}
else
{
Warning( "Unable to load detail prop file '%s'\n", DETAILTYPE_FILE );
}
pDetailTypes->deleteThis();
}
//-----------------------------------------------------------------------------
// Called when it's time to show the picker
//-----------------------------------------------------------------------------
void CAttributeDetailTypePickerPanel::ShowPickerDialog()
{
CPickerFrame *pDetailTypePickerDialog = new CPickerFrame( this, "Select Detail Type", "Detail Type", "detailTypeName" );
PickerList_t detailTypeList;
AddDetailTypesToList( detailTypeList );
pDetailTypePickerDialog->AddActionSignalTarget( this );
pDetailTypePickerDialog->DoModal( detailTypeList );
}
//-----------------------------------------------------------------------------
// Called by the picker dialog if a asset was selected
//-----------------------------------------------------------------------------
void CAttributeDetailTypePickerPanel::OnPicked( KeyValues *pKeyValues )
{
// Get the detail type name back
const char *pDetailTypeName = pKeyValues->GetString( "choice", NULL );
if ( !pDetailTypeName || !pDetailTypeName[ 0 ] )
return;
// Apply to text panel
m_pData->SetText( pDetailTypeName );
SetDirty(true);
if ( IsAutoApply() )
{
Apply();
}
}
@@ -0,0 +1,77 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "dme_controls/AttributeShaderPickerPanel.h"
#include "dme_controls/AttributeTextEntry.h"
#include "matsys_controls/Picker.h"
#include "tier1/KeyValues.h"
#include "matsys_controls/matsyscontrols.h"
#include "materialsystem/imaterialsystem.h"
#include "materialsystem/IShader.h"
using namespace vgui;
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CAttributeShaderPickerPanel::CAttributeShaderPickerPanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
BaseClass( parent, info )
{
}
CAttributeShaderPickerPanel::~CAttributeShaderPickerPanel()
{
}
//-----------------------------------------------------------------------------
// Called when it's time to show the picker
//-----------------------------------------------------------------------------
void CAttributeShaderPickerPanel::ShowPickerDialog()
{
CPickerFrame *pShaderPickerDialog = new CPickerFrame( this, "Select Shader", "Shader", "shaderName" );
int nCount = vgui::MaterialSystem()->ShaderCount();
IShader** ppShaderList = (IShader**)_alloca( nCount * sizeof(IShader) );
vgui::MaterialSystem()->GetShaders( 0, nCount, ppShaderList );
PickerList_t shaderList( 0, nCount );
for ( int i = 0; i < nCount; ++i )
{
if ( ( ppShaderList[i]->GetFlags() & SHADER_NOT_EDITABLE ) == 0 )
{
int j = shaderList.AddToTail( );
shaderList[j].m_pChoiceString = ppShaderList[i]->GetName();
shaderList[j].m_pChoiceValue = ppShaderList[i]->GetName();
}
}
pShaderPickerDialog->AddActionSignalTarget( this );
pShaderPickerDialog->DoModal( shaderList );
}
//-----------------------------------------------------------------------------
// Called by the picker dialog if a asset was selected
//-----------------------------------------------------------------------------
void CAttributeShaderPickerPanel::OnPicked( KeyValues *pKeyValues )
{
// Get the asset name back
const char *pShaderName = pKeyValues->GetString( "choice", NULL );
if ( !pShaderName || !pShaderName[ 0 ] )
return;
// Apply to text panel
m_pData->SetText( pShaderName );
SetDirty(true);
if ( IsAutoApply() )
{
Apply();
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,103 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "dme_controls/AttributeSurfacePropertyPickerPanel.h"
#include "dme_controls/AttributeTextEntry.h"
#include "tier1/KeyValues.h"
#include "filesystem.h"
using namespace vgui;
const char *SURFACEPROP_MANIFEST_FILE = "scripts/surfaceproperties_manifest.txt";
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CAttributeSurfacePropertyPickerPanel::CAttributeSurfacePropertyPickerPanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
BaseClass( parent, info )
{
}
CAttributeSurfacePropertyPickerPanel::~CAttributeSurfacePropertyPickerPanel()
{
}
//-----------------------------------------------------------------------------
// Reads the surface properties
//-----------------------------------------------------------------------------
void CAttributeSurfacePropertyPickerPanel::AddSurfacePropertiesToList( PickerList_t &list )
{
KeyValues *manifest = new KeyValues( SURFACEPROP_MANIFEST_FILE );
if ( manifest->LoadFromFile( g_pFullFileSystem, SURFACEPROP_MANIFEST_FILE, "GAME" ) )
{
for ( KeyValues *sub = manifest->GetFirstSubKey(); sub != NULL; sub = sub->GetNextKey() )
{
if ( Q_stricmp( sub->GetName(), "file" ) )
continue;
KeyValues *file = new KeyValues( SURFACEPROP_MANIFEST_FILE );
if ( file->LoadFromFile( g_pFullFileSystem, sub->GetString(), "GAME" ) )
{
for ( KeyValues *pTrav = file; pTrav; pTrav = pTrav->GetNextKey() )
{
int i = list.AddToTail();
list[i].m_pChoiceString = pTrav->GetName();
list[i].m_pChoiceValue = pTrav->GetName();
}
}
else
{
Warning( "Unable to load surface properties file '%s'\n", sub->GetString() );
}
file->deleteThis();
}
}
else
{
Warning( "Unable to load manifest file '%s'\n", SURFACEPROP_MANIFEST_FILE );
}
manifest->deleteThis();
}
//-----------------------------------------------------------------------------
// Called when it's time to show the picker
//-----------------------------------------------------------------------------
void CAttributeSurfacePropertyPickerPanel::ShowPickerDialog()
{
CPickerFrame *pSurfacePropPickerDialog = new CPickerFrame( this, "Select Surface Property", "Surface Property", "surfacePropertyName" );
PickerList_t surfacePropList;
AddSurfacePropertiesToList( surfacePropList );
pSurfacePropPickerDialog->AddActionSignalTarget( this );
pSurfacePropPickerDialog->DoModal( surfacePropList );
}
//-----------------------------------------------------------------------------
// Called by the picker dialog if a asset was selected
//-----------------------------------------------------------------------------
void CAttributeSurfacePropertyPickerPanel::OnPicked( KeyValues *pKeyValues )
{
// Get the asset name back
const char *pSurfacePropertyName = pKeyValues->GetString( "choice", NULL );
if ( !pSurfacePropertyName || !pSurfacePropertyName[ 0 ] )
return;
// Apply to text panel
m_pData->SetText( pSurfacePropertyName );
SetDirty(true);
if ( IsAutoApply() )
{
Apply();
}
}
+133
View File
@@ -0,0 +1,133 @@
//-----------------------------------------------------------------------------
// DME_CONTROLS.VPC
//
// Project Script
//-----------------------------------------------------------------------------
$Macro SRCDIR "..\.."
$Include "$SRCDIR\vpc_scripts\source_lib_base.vpc"
$Configuration
{
$Compiler
{
$PreprocessorDefinitions "$BASE;DMECONTROLS_LIB"
$PrecompiledHeaderFile "Debug/dme_controls.pch"
}
}
$Project "Dme_controls"
{
$Folder "Header Files"
{
$File "$SRCDIR\public\dme_controls\AttributeSlider.h"
$File "$SRCDIR\public\dme_controls\AssetBuilder.h"
$File "$SRCDIR\public\dme_controls\attributeassetpickerpanel.h"
$File "$SRCDIR\public\dme_controls\AttributeBasePickerPanel.h"
$File "$SRCDIR\public\dme_controls\AttributeBoolChoicePanel.h"
$File "$SRCDIR\public\dme_controls\AttributeColorPickerPanel.h"
$File "$SRCDIR\public\dme_controls\attributedetailtypepickerpanel.h"
$File "$SRCDIR\public\dme_controls\AttributeElementPanel.h"
$File "$SRCDIR\public\dme_controls\AttributeElementPickerPanel.h"
$File "$SRCDIR\public\dme_controls\AttributeFilePickerPanel.h"
$File "$SRCDIR\public\dme_controls\AttributeIntChoicePanel.h"
$File "$SRCDIR\public\dme_controls\AttributeInterpolatorChoicePanel.h"
$File "$SRCDIR\public\dme_controls\AttributeMDLPickerPanel.h"
$File "$SRCDIR\public\dme_controls\AttributeSequencePickerPanel.h"
$File "$SRCDIR\public\dme_controls\attributeshaderpickerpanel.h"
$File "$SRCDIR\public\dme_controls\AttributeSoundPickerPanel.h"
$File "$SRCDIR\public\dme_controls\AttributeStringChoicePanel.h"
$File "$SRCDIR\public\dme_controls\attributesurfacepropertypickerpanel.h"
$File "$SRCDIR\public\dme_controls\AttributeTextEntry.h"
$File "$SRCDIR\public\dme_controls\AttributeTextPanel.h"
$File "$SRCDIR\public\dme_controls\AttributeWidgetFactory.h"
$File "$SRCDIR\public\dme_controls\BaseAttributeChoicePanel.h"
$File "$SRCDIR\public\dme_controls\BaseAttributeDoubleChoicePanel.h"
$File "$SRCDIR\public\dme_controls\BaseAttributePanel.h"
$File "$SRCDIR\public\dme_controls\ChannelGraphPanel.h"
$File "$SRCDIR\public\dme_controls\dmecombinationsystemeditorpanel.h"
$File "$SRCDIR\public\dme_controls\dmecontrols.h"
$File "$SRCDIR\public\dme_controls\dmecontrols_utils.h"
$File "$SRCDIR\public\dme_controls\dmedageditpanel.h"
$File "$SRCDIR\public\dme_controls\dmedagrenderpanel.h"
$File "$SRCDIR\public\dme_controls\dmemdlpanel.h"
$File "$SRCDIR\public\dme_controls\dmepanel.h"
$File "$SRCDIR\public\dme_controls\dmepicker.h"
$File "$SRCDIR\public\dme_controls\dmepresetgroupeditorpanel.h"
$File "$SRCDIR\public\dme_controls\DmeSourceDCCFilePanel.h"
$File "$SRCDIR\public\dme_controls\DmeSourceSkinPanel.h"
$File "$SRCDIR\public\dme_controls\ElementPropertiesTree.h"
$File "$SRCDIR\public\dme_controls\FileListManager.h"
$File "$SRCDIR\public\dme_controls\filtercombobox.h"
$File "$SRCDIR\public\dme_controls\inotifyui.h"
$File "$SRCDIR\public\dme_controls\particlesystempanel.h"
$File "$SRCDIR\public\dme_controls\particlesystempropertiespanel.h"
$File "$SRCDIR\public\dme_controls\soundpicker.h"
$File "$SRCDIR\public\dme_controls\soundrecordpanel.h"
}
$Folder "Source Files"
{
$File "AttributeSlider.cpp"
$File "AssetBuilder.cpp"
$File "attributeassetpickerpanel.cpp"
$File "AttributeBasePickerPanel.cpp"
$File "AttributeBoolChoicePanel.cpp"
$File "AttributeColorPickerPanel.cpp"
$File "attributedetailtypepickerpanel.cpp"
$File "AttributeElementPanel.cpp"
$File "AttributeElementPickerPanel.cpp"
$File "AttributeFilePickerPanel.cpp"
$File "AttributeIntChoicePanel.cpp"
$File "AttributeInterpolatorChoicePanel.cpp"
$File "AttributeMDLPickerPanel.cpp"
$File "AttributeSequencePickerPanel.cpp"
$File "attributeshaderpickerpanel.cpp"
$File "AttributeSoundPickerPanel.cpp"
$File "AttributeStringChoicePanel.cpp"
$File "attributesurfacepropertypickerpanel.cpp"
$File "AttributeTextEntry.cpp"
$File "AttributeTextPanel.cpp"
$File "AttributeWidgetFactory.cpp"
$File "BaseAttributeChoicePanel.cpp"
$File "BaseAttributeDoubleChoicePanel.cpp"
$File "BaseAttributePanel.cpp"
$File "ChannelGraphPanel.cpp"
$File "dmecombinationsystemeditorpanel.cpp"
$File "dmecontrols.cpp"
$File "dmedageditpanel.cpp"
$File "dmedagrenderpanel.cpp"
$File "dmelogeditpanel.cpp"
$File "dmemdlpanel.cpp"
$File "dmepanel.cpp"
$File "dmepicker.cpp"
$File "dmepresetgroupeditorpanel.cpp"
$File "DmeSourceDCCFilePanel.cpp"
$File "DmeSourceSkinPanel.cpp"
$File "ElementPropertiesTree.cpp"
$File "FileListManager.cpp"
$File "filtercombobox.cpp"
$File "particlesystempanel.cpp"
$File "particlesystempropertiespanel.cpp"
$File "soundpicker.cpp"
$File "soundrecordpanel.cpp"
$Folder "Animation Set Editor"
{
$File "$SRCDIR\public\dme_controls\AnimSetAttributeValue.h"
$File "BaseAnimationSetEditor.cpp"
$File "$SRCDIR\public\dme_controls\BaseAnimationSetEditor.h"
$File "BaseAnimSetAttributeSliderPanel.cpp"
$File "$SRCDIR\public\dme_controls\BaseAnimSetAttributeSliderPanel.h"
$File "BaseAnimSetControlGroupPanel.cpp"
$File "$SRCDIR\public\dme_controls\BaseAnimSetControlGroupPanel.h"
$File "BaseAnimSetPresetFaderPanel.cpp"
$File "$SRCDIR\public\dme_controls\BaseAnimSetPresetFaderPanel.h"
$File "$SRCDIR\public\dme_controls\LogPreview.h"
$File "presetpicker.cpp"
$File "$SRCDIR\public\dme_controls\presetpicker.h"
$File "$SRCDIR\public\dme_controls\RecordingState.h"
$File "$SRCDIR\public\phonemeconverter.cpp"
}
}
}
File diff suppressed because it is too large Load Diff
+102
View File
@@ -0,0 +1,102 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//===========================================================================//
#include "dme_controls/dmecontrols.h"
#include "soundemittersystem/isoundemittersystembase.h"
#include "matsys_controls/matsyscontrols.h"
#include "toolframework/ienginetool.h"
#include "vphysics_interface.h"
#include "dme_controls/inotifyui.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
namespace vgui
{
ISoundEmitterSystemBase *g_pSoundEmitterSystem = NULL;
ISoundEmitterSystemBase *SoundEmitterSystem()
{
return g_pSoundEmitterSystem;
}
IEngineTool *enginetools = NULL;
IEngineTool *EngineTool()
{
return enginetools;
}
IPhysicsCollision *g_pPhysicsCollision = NULL;
IPhysicsCollision *PhysicsCollision()
{
return g_pPhysicsCollision;
}
class CDefaultElementPropertiesChoices : public CBaseElementPropertiesChoices
{
public:
};
static CDefaultElementPropertiesChoices s_DefaultChoices;
IElementPropertiesChoices *g_pElementPropertiesChoices = &s_DefaultChoices;
IElementPropertiesChoices *ElementPropertiesChoices()
{
return g_pElementPropertiesChoices;
}
void SetElementPropertiesChoices( IElementPropertiesChoices *pElementPropertiesChoices )
{
g_pElementPropertiesChoices = pElementPropertiesChoices ? pElementPropertiesChoices : &s_DefaultChoices;
}
//-----------------------------------------------------------------------------
// Purpose: finds a particular interface in the factory set
//-----------------------------------------------------------------------------
static void *InitializeInterface( char const *interfaceName, CreateInterfaceFn *factoryList, int numFactories )
{
void *retval;
for ( int i = 0; i < numFactories; i++ )
{
CreateInterfaceFn factory = factoryList[ i ];
if ( !factory )
continue;
retval = factory( interfaceName, NULL );
if ( retval )
return retval;
}
// No provider for requested interface!!!
// Assert( !"No provider for requested interface!!!" );
return NULL;
}
//-----------------------------------------------------------------------------
// Purpose: Initializes the controls
//-----------------------------------------------------------------------------
bool VGui_InitDmeInterfacesList( const char *moduleName, CreateInterfaceFn *factoryList, int numFactories )
{
if ( !vgui::VGui_InitMatSysInterfacesList( moduleName, factoryList, numFactories ) )
return false;
g_pSoundEmitterSystem = (ISoundEmitterSystemBase*)InitializeInterface( SOUNDEMITTERSYSTEM_INTERFACE_VERSION, factoryList, numFactories );
enginetools = (IEngineTool*)InitializeInterface( VENGINETOOL_INTERFACE_VERSION, factoryList, numFactories );
g_pPhysicsCollision = (IPhysicsCollision*)InitializeInterface( VPHYSICS_COLLISION_INTERFACE_VERSION, factoryList, numFactories );
// Can function without either of these
return true;
}
} // namespace vgui
File diff suppressed because it is too large Load Diff
+739
View File
@@ -0,0 +1,739 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
#include "dme_controls/dmedagrenderpanel.h"
#include "movieobjects/dmedag.h"
#include "movieobjects/dmemodel.h"
#include "movieobjects/timeutils.h"
#include "movieobjects/dmeanimationlist.h"
#include "movieobjects/dmeclip.h"
#include "movieobjects/dmechannel.h"
#include "movieobjects/dmemdlmakefile.h"
#include "movieobjects/dmedccmakefile.h"
#include "movieobjects/dmemesh.h"
#include "movieobjects/dmedrawsettings.h"
#include "dme_controls/dmepanel.h"
#include "tier1/KeyValues.h"
#include "VGuiMatSurface/IMatSystemSurface.h"
#include "tier3/tier3.h"
#include "materialsystem/imaterialsystemhardwareconfig.h"
#include "materialsystem/imesh.h"
#include "vgui_controls/Menu.h"
#include "vgui_controls/MenuBar.h"
#include "vgui_controls/MenuButton.h"
#include "vgui/IVGui.h"
//-----------------------------------------------------------------------------
//
// Hook into the dme panel editor system
//
//-----------------------------------------------------------------------------
IMPLEMENT_DMEPANEL_FACTORY( CDmeDagRenderPanel, DmeDag, "DmeDagRenderer", "DmeDag Preview Renderer", false );
IMPLEMENT_DMEPANEL_FACTORY( CDmeDagRenderPanel, DmeSourceSkin, "DmeSourceSkinPreview", "MDL Skin Previewer", false );
IMPLEMENT_DMEPANEL_FACTORY( CDmeDagRenderPanel, DmeSourceAnimation, "DmeSourceAnimationPreview", "MDL Animation Previewer", false );
IMPLEMENT_DMEPANEL_FACTORY( CDmeDagRenderPanel, DmeDCCMakefile, "DmeMakeFileOutputPreview", "DCC MakeFile Output Preview", false );
//-----------------------------------------------------------------------------
// Constructor, destructor
//-----------------------------------------------------------------------------
CDmeDagRenderPanel::CDmeDagRenderPanel( vgui::Panel *pParent, const char *pName ) : BaseClass( pParent, pName )
{
// Used to poll input
vgui::ivgui()->AddTickSignal( GetVPanel() );
m_bDrawJointNames = false;
m_bDrawJoints = false;
m_bDrawGrid = true;
// Deal with the default cubemap
ITexture *pCubemapTexture = g_pMaterialSystem->FindTexture( "editor/cubemap", NULL, true );
m_DefaultEnvCubemap.Init( pCubemapTexture );
pCubemapTexture = g_pMaterialSystem->FindTexture( "editor/cubemap.hdr", NULL, true );
m_DefaultHDREnvCubemap.Init( pCubemapTexture );
m_pDrawSettings = CreateElement< CDmeDrawSettings >( "drawSettings", g_pDataModel->FindOrCreateFileId( "DagRenderPanelDrawSettings" ) );
m_hDrawSettings = m_pDrawSettings;
m_pMenuBar = new vgui::MenuBar( this, "Dag Render Panel Menu Bar" );
m_pShadingMenu = new vgui::Menu( NULL, "Shading Menu" );
m_nMenuSmoothShade = m_pShadingMenu->AddCheckableMenuItem( "&Smooth Shade", new KeyValues( "SmoothShade" ), this );
m_nMenuFlatShade = m_pShadingMenu->AddCheckableMenuItem( "&Flat Shade", new KeyValues( "FlatShade" ), this );
m_nMenuWireframe = m_pShadingMenu->AddCheckableMenuItem( "&Wireframe", new KeyValues( "Wireframe" ), this );
m_pShadingMenu->AddSeparator();
m_nMenuBoundingBox = m_pShadingMenu->AddCheckableMenuItem( "&Bounding Box", new KeyValues( "BoundingBox" ), this );
m_pShadingMenu->AddSeparator(); // Bug is visibility
m_nMenuNormals = m_pShadingMenu->AddCheckableMenuItem( "&Normals", new KeyValues( "Normals" ), this );
m_nMenuWireframeOnShaded = m_pShadingMenu->AddCheckableMenuItem( "WireFrame &On Shaded", new KeyValues( "WireframeOnShaded" ), this );
m_nMenuBackfaceCulling = m_pShadingMenu->AddCheckableMenuItem( "&Backface Culling", new KeyValues( "BackfaceCulling" ), this );
m_nMenuXRay = m_pShadingMenu->AddCheckableMenuItem( "&X-Ray", new KeyValues( "XRay" ), this );
m_nMenuGrayShade = m_pShadingMenu->AddCheckableMenuItem( "&Gray Shade", new KeyValues( "GrayShade" ), this );
// For now...
m_pShadingMenu->SetItemVisible( m_nMenuFlatShade, false );
m_pShadingMenu->SetItemEnabled( m_nMenuFlatShade, false );
m_pShadingMenu->SetItemVisible( m_nMenuBoundingBox, false );
m_pShadingMenu->SetItemEnabled( m_nMenuBoundingBox, false );
m_pShadingMenu->SetItemVisible( m_nMenuBackfaceCulling, false );
m_pShadingMenu->SetItemEnabled( m_nMenuBackfaceCulling, false );
m_pShadingMenu->SetItemVisible( m_nMenuXRay, false );
m_pShadingMenu->SetItemEnabled( m_nMenuXRay, false );
m_pMenuBar->AddMenu( "&Shading", m_pShadingMenu );
UpdateMenu();
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
CDmeDagRenderPanel::~CDmeDagRenderPanel()
{
}
//-----------------------------------------------------------------------------
// Scheme settings
//-----------------------------------------------------------------------------
void CDmeDagRenderPanel::ApplySchemeSettings( vgui::IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
SetBorder( pScheme->GetBorder( "MenuBorder") );
m_hFont = pScheme->GetFont( "DmePropertyVerySmall", IsProportional() );
}
//-----------------------------------------------------------------------------
// Set the scene
//-----------------------------------------------------------------------------
void CDmeDagRenderPanel::SetDmeElement( CDmeDag *pScene )
{
m_hDag = pScene;
ComputeDefaultTangentData( m_hDag, false );
}
//-----------------------------------------------------------------------------
// Other methods which hook into DmePanel
//-----------------------------------------------------------------------------
void CDmeDagRenderPanel::SetDmeElement( CDmeSourceSkin *pSkin )
{
// First, try to grab the dependent makefile
CDmeMakefile *pSourceMakefile = pSkin->GetDependentMakefile();
if ( !pSourceMakefile )
{
m_hDag = NULL;
return;
}
// Next, try to grab the output of that makefile
CDmElement *pOutput = pSourceMakefile->GetOutputElement( true );
if ( !pOutput )
{
m_hDag = NULL;
return;
}
// Finally, grab the 'skin' attribute of that makefile
m_hDag = pOutput->GetValueElement< CDmeDag >( "model" );
ComputeDefaultTangentData( m_hDag, false );
DrawJoints( false );
DrawJointNames( false );
}
void CDmeDagRenderPanel::SetDmeElement( CDmeSourceAnimation *pAnimation )
{
// First, try to grab the dependent makefile
CDmeMakefile *pSourceMakefile = pAnimation->GetDependentMakefile();
if ( !pSourceMakefile )
{
m_hDag = NULL;
return;
}
// Next, try to grab the output of that makefile
CDmElement *pOutput = pSourceMakefile->GetOutputElement( true );
if ( !pOutput )
{
m_hDag = NULL;
return;
}
// Finally, grab the 'model' or 'skeleton' attribute of that makefile
CDmeDag *pDag = pOutput->GetValueElement< CDmeDag >( "model" );
if ( !pDag )
{
pDag = pOutput->GetValueElement< CDmeDag >( "skeleton" );
}
if ( !pDag )
return;
CDmeAnimationList *pAnimationList = pOutput->GetValueElement< CDmeAnimationList >( "animationList" );
if ( !pAnimationList )
return;
if ( pAnimationList->FindAnimation( pAnimation->m_SourceAnimationName ) < 0 )
return;
m_hDag = pDag;
ComputeDefaultTangentData( m_hDag, false );
m_hAnimationList = pAnimationList;
SelectAnimation( pAnimation->m_SourceAnimationName );
DrawJoints( true );
DrawJointNames( true );
}
void CDmeDagRenderPanel::SetDmeElement( CDmeDCCMakefile *pDCCMakefile )
{
// First, try to grab the dependent makefile
CDmElement *pOutputElement = pDCCMakefile->GetOutputElement( true );
if ( !pOutputElement )
{
m_hDag = NULL;
return;
}
// Finally, grab the 'model' or 'skeleton' attribute of that makefile
CDmeDag *pDag = pOutputElement->GetValueElement< CDmeDag >( "model" );
if ( !pDag )
{
pDag = pOutputElement->GetValueElement< CDmeDag >( "skeleton" );
}
if ( !pDag )
return;
CDmeAnimationList *pAnimationList = pOutputElement->GetValueElement< CDmeAnimationList >( "animationList" );
m_hDag = pDag;
ComputeDefaultTangentData( m_hDag, false );
m_hAnimationList = pAnimationList;
SelectAnimation( 0 );
DrawJoints( pAnimationList != NULL );
DrawJointNames( pAnimationList != NULL );
}
CDmeDag *CDmeDagRenderPanel::GetDmeElement()
{
return m_hDag;
}
//-----------------------------------------------------------------------------
// Draw joint names
//-----------------------------------------------------------------------------
void CDmeDagRenderPanel::DrawJointNames( CDmeDag *pRoot, CDmeDag *pDag, const matrix3x4_t& parentToWorld )
{
CDmeTransform *pJointTransform = pDag->GetTransform();
int nJointIndex = -1;
CDmeModel *pRootModel = CastElement<CDmeModel>( pRoot );
if ( pRootModel )
{
nJointIndex = pRootModel->GetJointTransformIndex( pJointTransform );
if ( nJointIndex < 0 && pRootModel != pDag )
return;
}
matrix3x4_t jointToParent, jointToWorld;
pJointTransform->GetTransform( jointToParent );
ConcatTransforms( parentToWorld, jointToParent, jointToWorld );
CDmeJoint *pJoint = CastElement< CDmeJoint >( pDag );
if ( pJoint )
{
Vector vecJointOrigin;
MatrixGetColumn( jointToWorld, 3, &vecJointOrigin );
Vector2D vecPanelPos;
ComputePanelPosition( vecJointOrigin, &vecPanelPos );
char pJointName[512];
if ( nJointIndex >= 0 )
{
Q_snprintf( pJointName, sizeof(pJointName), "%d : %s", nJointIndex, pJoint->GetName() );
}
else
{
Q_snprintf( pJointName, sizeof(pJointName), "%s", pJoint->GetName() );
}
g_pMatSystemSurface->DrawColoredText( m_hFont, vecPanelPos.x + 5, vecPanelPos.y, 255, 255, 255, 255, pJointName );
}
int nCount = pDag->GetChildCount();
for ( int i = 0; i < nCount; ++i )
{
CDmeDag *pChild = pDag->GetChild(i);
if ( !pChild )
continue;
DrawJointNames( pRoot, pChild, jointToWorld );
}
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void CDmeDagRenderPanel::OnSmoothShade()
{
if ( m_pShadingMenu->IsChecked( m_nMenuSmoothShade ) )
{
m_pDrawSettings->SetDrawType( CDmeDrawSettings::DRAW_SMOOTH );
}
UpdateMenu();
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void CDmeDagRenderPanel::OnFlatShade()
{
if ( m_pShadingMenu->IsChecked( m_nMenuFlatShade ) )
{
m_pDrawSettings->SetDrawType( CDmeDrawSettings::DRAW_FLAT );
}
UpdateMenu();
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void CDmeDagRenderPanel::OnWireframe()
{
if ( m_pShadingMenu->IsChecked( m_nMenuWireframe ) )
{
m_pDrawSettings->SetDrawType( CDmeDrawSettings::DRAW_WIREFRAME );
}
UpdateMenu();
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void CDmeDagRenderPanel::OnBoundingBox()
{
if ( m_pShadingMenu->IsChecked( m_nMenuBoundingBox ) )
{
m_pDrawSettings->SetDrawType( CDmeDrawSettings::DRAW_BOUNDINGBOX );
}
UpdateMenu();
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void CDmeDagRenderPanel::OnNormals()
{
m_pDrawSettings->SetNormals( m_pShadingMenu->IsChecked( m_nMenuNormals ) );
UpdateMenu();
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void CDmeDagRenderPanel::OnWireframeOnShaded()
{
m_pDrawSettings->SetWireframeOnShaded( m_pShadingMenu->IsChecked( m_nMenuWireframeOnShaded ) );
UpdateMenu();
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void CDmeDagRenderPanel::OnBackfaceCulling()
{
m_pDrawSettings->SetBackfaceCulling( m_pShadingMenu->IsChecked( m_nMenuBackfaceCulling ) );
UpdateMenu();
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void CDmeDagRenderPanel::OnXRay()
{
m_pDrawSettings->SetXRay( m_pShadingMenu->IsChecked( m_nMenuXRay ) );
UpdateMenu();
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void CDmeDagRenderPanel::OnGrayShade()
{
m_pDrawSettings->SetGrayShade( m_pShadingMenu->IsChecked( m_nMenuGrayShade ) );
UpdateMenu();
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void CDmeDagRenderPanel::OnFrame()
{
if ( !m_hDag )
return;
float flRadius;
Vector vecCenter, vecWorldCenter;
m_hDag->GetBoundingSphere( vecCenter, flRadius );
matrix3x4_t dmeToEngine;
CDmeDag::DmeToEngineMatrix( dmeToEngine );
VectorTransform( vecCenter, dmeToEngine, vecWorldCenter );
LookAt( vecWorldCenter, flRadius );
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void CDmeDagRenderPanel::PerformLayout()
{
BaseClass::PerformLayout();
if ( m_pMenuBar->IsVisible() )
{
int iWidth;
int iHeight;
GetSize( iWidth, iHeight );
int iMenuWidth; // Unused
int iMenuHeight;
m_pMenuBar->GetSize( iMenuWidth, iMenuHeight );
m_pMenuBar->SetSize( iWidth, iMenuHeight );
}
}
//-----------------------------------------------------------------------------
// paint it!
//-----------------------------------------------------------------------------
void CDmeDagRenderPanel::Paint()
{
if ( m_hCurrentAnimation.Get() )
{
DmeTime_t currentTime( Plat_FloatTime() - m_flStartTime );
if ( m_hCurrentAnimation->GetDuration() != DMETIME_ZERO )
{
currentTime = currentTime % m_hCurrentAnimation->GetDuration();
}
else
{
currentTime = DMETIME_ZERO;
}
currentTime += m_hCurrentAnimation->GetStartTime();
DmeTime_t mediaTime = m_hCurrentAnimation->ToChildMediaTime( currentTime, true );
int nChannelCount = m_hCurrentAnimation->m_Channels.Count();
for ( int i = 0; i < nChannelCount; ++i )
{
m_hCurrentAnimation->m_Channels[i]->SetCurrentTime( mediaTime );
}
}
if ( m_hCurrentVertexAnimation.Get() )
{
DmeTime_t currentTime( Plat_FloatTime() - m_flStartTime );
currentTime = currentTime % m_hCurrentVertexAnimation->GetDuration();
currentTime += m_hCurrentVertexAnimation->GetStartTime();
DmeTime_t mediaTime = m_hCurrentVertexAnimation->ToChildMediaTime( currentTime, true );
int nChannelCount = m_hCurrentVertexAnimation->m_Channels.Count();
for ( int i = 0; i < nChannelCount; ++i )
{
m_hCurrentVertexAnimation->m_Channels[i]->SetCurrentTime( mediaTime );
}
}
// FIXME: Shouldn't this happen at the application level?
// run the machinery - apply, resolve, dependencies, operate, resolve
{
CDisableUndoScopeGuard guard;
g_pDmElementFramework->SetOperators( m_operators );
g_pDmElementFramework->Operate( true );
}
// allow elements and attributes to be edited again
g_pDmElementFramework->BeginEdit();
BaseClass::Paint();
// Overlay the joint names
if ( m_bDrawJointNames && m_hDag )
{
matrix3x4_t modelToWorld;
CDmeDag::DmeToEngineMatrix( modelToWorld );
DrawJointNames( m_hDag, m_hDag, modelToWorld );
}
}
//-----------------------------------------------------------------------------
// Indicate we should draw joint names
//-----------------------------------------------------------------------------
void CDmeDagRenderPanel::DrawJointNames( bool bDrawJointNames )
{
m_bDrawJointNames = bDrawJointNames;
}
//-----------------------------------------------------------------------------
// Indicate we should draw joints
//-----------------------------------------------------------------------------
void CDmeDagRenderPanel::DrawJoints( bool bDrawJoint )
{
m_bDrawJoints = bDrawJoint;
}
//-----------------------------------------------------------------------------
// Indicate we should draw the grid
//-----------------------------------------------------------------------------
void CDmeDagRenderPanel::DrawGrid( bool bDrawGrid )
{
m_bDrawGrid = bDrawGrid;
}
//-----------------------------------------------------------------------------
// paint it!
//-----------------------------------------------------------------------------
void CDmeDagRenderPanel::OnPaint3D()
{
CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
ITexture *pLocalCube = pRenderContext->GetLocalCubemap();
if ( g_pMaterialSystemHardwareConfig->GetHDRType() == HDR_TYPE_NONE )
{
pRenderContext->BindLocalCubemap( m_DefaultEnvCubemap );
}
else
{
pRenderContext->BindLocalCubemap( m_DefaultHDREnvCubemap );
}
if ( m_bDrawGrid )
{
BaseClass::DrawGrid();
}
if ( m_bDrawJoints )
{
CDmeJoint::DrawJointHierarchy( true );
}
pRenderContext->CullMode( MATERIAL_CULLMODE_CW );
CDmeDag::DrawUsingEngineCoordinates( true );
m_pDrawSettings->DrawDag( m_hDag );
CDmeDag::DrawUsingEngineCoordinates( false );
pRenderContext->Flush();
pRenderContext->BindLocalCubemap( pLocalCube );
}
//-----------------------------------------------------------------------------
// input
//-----------------------------------------------------------------------------
void CDmeDagRenderPanel::OnMouseDoublePressed( vgui::MouseCode code )
{
OnFrame();
BaseClass::OnMouseDoublePressed( code );
}
//-----------------------------------------------------------------------------
// TODO: Have a whole groovy keybinding thingy like SFM
//-----------------------------------------------------------------------------
void CDmeDagRenderPanel::OnKeyCodePressed( vgui::KeyCode code )
{
BaseClass::OnKeyCodePressed( code );
if ( code == KEY_F )
{
OnFrame();
}
}
//-----------------------------------------------------------------------------
// Rebuilds the list of operators
//-----------------------------------------------------------------------------
void CDmeDagRenderPanel::RebuildOperatorList( )
{
m_operators.RemoveAll();
if ( m_hCurrentAnimation.Get() )
{
int nChannelCount = m_hCurrentAnimation->m_Channels.Count();
for ( int i = 0; i < nChannelCount; ++i )
{
m_hCurrentAnimation->m_Channels[i]->SetMode( CM_PLAY );
m_operators.AddToTail( m_hCurrentAnimation->m_Channels[i] );
}
}
if ( m_hCurrentVertexAnimation.Get() )
{
int nChannelCount = m_hCurrentVertexAnimation->m_Channels.Count();
for ( int i = 0; i < nChannelCount; ++i )
{
m_hCurrentVertexAnimation->m_Channels[i]->SetMode( CM_PLAY );
m_operators.AddToTail( m_hCurrentVertexAnimation->m_Channels[i] );
}
}
m_flStartTime = Plat_FloatTime();
}
//-----------------------------------------------------------------------------
// Select animation by index
//-----------------------------------------------------------------------------
void CDmeDagRenderPanel::SelectAnimation( int nIndex )
{
m_hCurrentAnimation = NULL;
if ( m_hAnimationList.Get() && ( nIndex >= 0 ) )
{
// FIXME: How is this actually going to work?
m_hCurrentAnimation = m_hAnimationList->GetAnimation( nIndex );
}
RebuildOperatorList();
}
void CDmeDagRenderPanel::SelectVertexAnimation( int nIndex )
{
m_hCurrentVertexAnimation = NULL;
if ( m_hVertexAnimationList.Get() && ( nIndex >= 0 ) )
{
// FIXME: How is this actually going to work?
m_hCurrentVertexAnimation = m_hVertexAnimationList->GetAnimation( nIndex );
}
RebuildOperatorList();
}
//-----------------------------------------------------------------------------
// Select animation by name
//-----------------------------------------------------------------------------
void CDmeDagRenderPanel::SelectAnimation( const char *pAnimName )
{
if ( !pAnimName[0] )
{
SelectAnimation( -1 );
return;
}
if ( m_hAnimationList )
{
int nIndex = m_hAnimationList->FindAnimation( pAnimName );
if ( nIndex >= 0 )
{
SelectAnimation( nIndex );
}
}
}
void CDmeDagRenderPanel::SelectVertexAnimation( const char *pAnimName )
{
if ( !pAnimName[0] )
{
SelectVertexAnimation( -1 );
return;
}
if ( m_hVertexAnimationList )
{
int nIndex = m_hVertexAnimationList->FindAnimation( pAnimName );
if ( nIndex >= 0 )
{
SelectVertexAnimation( nIndex );
}
}
}
//-----------------------------------------------------------------------------
// Sets animation
//-----------------------------------------------------------------------------
void CDmeDagRenderPanel::SetAnimationList( CDmeAnimationList *pAnimationList )
{
m_hAnimationList = pAnimationList;
int nCount = pAnimationList ? pAnimationList->GetAnimationCount() : 0;
if ( nCount == 0 )
{
m_hCurrentAnimation = NULL;
return;
}
SelectAnimation( 0 );
}
void CDmeDagRenderPanel::SetVertexAnimationList( CDmeAnimationList *pAnimationList )
{
m_hVertexAnimationList = pAnimationList;
int nCount = pAnimationList ? pAnimationList->GetAnimationCount() : 0;
if ( nCount == 0 )
{
m_hCurrentVertexAnimation = NULL;
return;
}
SelectVertexAnimation( 0 );
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void CDmeDagRenderPanel::UpdateMenu()
{
switch ( m_pDrawSettings->GetDrawType() )
{
case CDmeDrawSettings::DRAW_FLAT:
m_pShadingMenu->SetMenuItemChecked( m_nMenuSmoothShade, false );
m_pShadingMenu->SetMenuItemChecked( m_nMenuFlatShade, true );
m_pShadingMenu->SetMenuItemChecked( m_nMenuWireframe, false );
m_pShadingMenu->SetMenuItemChecked( m_nMenuBoundingBox, false );
break;
case CDmeDrawSettings::DRAW_WIREFRAME:
m_pShadingMenu->SetMenuItemChecked( m_nMenuSmoothShade, false );
m_pShadingMenu->SetMenuItemChecked( m_nMenuFlatShade, false );
m_pShadingMenu->SetMenuItemChecked( m_nMenuWireframe, true );
m_pShadingMenu->SetMenuItemChecked( m_nMenuBoundingBox, false );
break;
case CDmeDrawSettings::DRAW_BOUNDINGBOX:
m_pShadingMenu->SetMenuItemChecked( m_nMenuSmoothShade, false );
m_pShadingMenu->SetMenuItemChecked( m_nMenuFlatShade, false );
m_pShadingMenu->SetMenuItemChecked( m_nMenuWireframe, false );
m_pShadingMenu->SetMenuItemChecked( m_nMenuBoundingBox, true );
break;
default:
m_pShadingMenu->SetMenuItemChecked( m_nMenuSmoothShade, true );
m_pShadingMenu->SetMenuItemChecked( m_nMenuFlatShade, false );
m_pShadingMenu->SetMenuItemChecked( m_nMenuWireframe, false );
m_pShadingMenu->SetMenuItemChecked( m_nMenuBoundingBox, false );
break;
}
m_pShadingMenu->SetMenuItemChecked( m_nMenuNormals, m_pDrawSettings->GetNormals() );
m_pShadingMenu->SetMenuItemChecked( m_nMenuWireframeOnShaded, m_pDrawSettings->GetWireframeOnShaded() );
m_pShadingMenu->SetMenuItemChecked( m_nMenuBackfaceCulling, m_pDrawSettings->GetBackfaceCulling() );
m_pShadingMenu->SetMenuItemChecked( m_nMenuXRay, m_pDrawSettings->GetXRay() );
m_pShadingMenu->SetMenuItemChecked( m_nMenuGrayShade, m_pDrawSettings->GetGrayShade() );
}
+542
View File
@@ -0,0 +1,542 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//===========================================================================//
#include "dme_controls/dmelogeditpanel.h"
#include "movieobjects/dmelog.h"
#include "vgui_controls/button.h"
#include "vgui_controls/combobox.h"
#include "tier1/KeyValues.h"
using namespace vgui;
//-----------------------------------------------------------------------------
// constructor, destructor
//-----------------------------------------------------------------------------
CDmeLogEditPanel::CDmeLogEditPanel( vgui::Panel *pParent, const char *pName ) : BaseClass( pParent, pName )
{
SetVisible( false );
m_flMinVertical = 0;
m_flMaxVertical = 256;
}
CDmeLogEditPanel::~CDmeLogEditPanel()
{
}
//-----------------------------------------------------------------------------
// Converts normalized values to int time
//-----------------------------------------------------------------------------
DmeTime_t CDmeLogEditPanel::NormalizedToTime( float flIn )
{
return m_minTime + NormalizedToDuration( flIn );
}
DmeTime_t CDmeLogEditPanel::NormalizedToDuration( float flDuration )
{
flDuration = clamp( flDuration, 0.0f, 1.0f );
return flDuration * ( m_maxTime - m_minTime );
}
float CDmeLogEditPanel::TimeToNormalized( DmeTime_t time )
{
if ( m_maxTime == m_minTime )
return 0.0f;
return GetFractionOfTimeBetween( time, m_minTime, m_maxTime, true );
}
float CDmeLogEditPanel::NormalizedToValue( float flValue )
{
return Lerp( flValue, m_flMinVertical, m_flMaxVertical );
}
float CDmeLogEditPanel::ValueToNormalized( float flNormalized )
{
if ( m_flMaxVertical == m_flMinVertical )
return 0.0f;
return (flNormalized - m_flMinVertical) / ( m_flMaxVertical - m_flMinVertical );
}
//-----------------------------------------------------------------------------
// Control points + values...
//-----------------------------------------------------------------------------
int CDmeLogEditPanel::FindOrAddControlPoint( float flIn, float flTolerance, float flOut )
{
Assert( m_hLog.Get() );
DmeTime_t time = NormalizedToTime( flIn );
DmeTime_t tolerance = ( flTolerance >= 0 ) ? NormalizedToDuration( flTolerance ) : DmeTime_t( 0 );
float flValue = NormalizedToValue( flOut );
int nKeyIndex = -1;
Assert( m_hLog.Get() );
switch( m_hLog->GetDataType() )
{
case AT_BOOL:
nKeyIndex = CastElement<CDmeBoolLog >( m_hLog )->FindOrAddKey( time, tolerance, (bool)(flValue >= 0.5f) );
break;
case AT_INT:
nKeyIndex = CastElement<CDmeIntLog >( m_hLog )->FindOrAddKey( time, tolerance, (int)(flValue + 0.5f) );
break;
case AT_FLOAT:
nKeyIndex = CastElement<CDmeFloatLog >( m_hLog )->FindOrAddKey( time, tolerance, flValue );
break;
case AT_COLOR:
{
Color c = CastElement<CDmeColorLog >( m_hLog )->GetValue( time );
int nComp = (int)( flValue + 0.5f );
nComp = clamp( nComp, 0, 255 );
for ( int i = 0; i < 4; ++i )
{
if ( m_LogFieldMask & (1 << i) )
{
c[i] = (unsigned char)nComp;
}
}
nKeyIndex = CastElement<CDmeColorLog >( m_hLog )->FindOrAddKey( time, tolerance, c );
}
break;
case AT_VECTOR2:
nKeyIndex = FindOrAddKey< Vector2D >( time, tolerance, 2, flValue );
break;
case AT_VECTOR3:
nKeyIndex = FindOrAddKey< Vector >( time, tolerance, 3, flValue );
break;
case AT_VECTOR4:
nKeyIndex = FindOrAddKey< Vector4D >( time, tolerance, 4, flValue );
break;
case AT_QANGLE:
nKeyIndex = FindOrAddKey< QAngle >( time, tolerance, 3, flValue );
break;
case AT_QUATERNION:
nKeyIndex = FindOrAddKey< Quaternion >( time, tolerance, 4, flValue );
break;
}
return nKeyIndex;
}
//-----------------------------------------------------------------------------
// Finds a control point within tolerance
//-----------------------------------------------------------------------------
int CDmeLogEditPanel::FindControlPoint( float flIn, float flTolerance )
{
Assert( m_hLog.Get() );
DmeTime_t time = NormalizedToTime( flIn );
DmeTime_t tolerance = NormalizedToDuration( flTolerance );
return m_hLog->FindKeyWithinTolerance( time, tolerance );
}
//-----------------------------------------------------------------------------
// Modifies an existing control point
//-----------------------------------------------------------------------------
int CDmeLogEditPanel::ModifyControlPoint( int nPoint, float flIn, float flOut )
{
Assert( m_hLog.Get() );
DmeTime_t time = NormalizedToTime( flIn );
DmeTime_t initialTime = m_hLog->GetKeyTime( nPoint );
float flValue = NormalizedToValue( flOut );
int nKeyIndex = -1;
Assert( m_hLog.Get() );
switch( m_hLog->GetDataType() )
{
case AT_BOOL:
RemoveControlPoint( nPoint );
nKeyIndex = CastElement<CDmeBoolLog >( m_hLog )->FindOrAddKey( time, DmeTime_t( 0 ), (bool)(flValue >= 0.5f) );
break;
case AT_INT:
RemoveControlPoint( nPoint );
nKeyIndex = CastElement<CDmeIntLog >( m_hLog )->FindOrAddKey( time, DmeTime_t( 0 ), (int)(flValue + 0.5f) );
break;
case AT_FLOAT:
RemoveControlPoint( nPoint );
nKeyIndex = CastElement<CDmeFloatLog >( m_hLog )->FindOrAddKey( time, DmeTime_t( 0 ), flValue );
break;
case AT_COLOR:
{
Color c = CastElement<CDmeColorLog >( m_hLog )->GetValue( initialTime );
int nComp = (int)( flValue + 0.5f );
nComp = clamp( nComp, 0, 255 );
for ( int i = 0; i < 4; ++i )
{
if ( m_LogFieldMask & (1 << i) )
{
c[i] = (unsigned char)nComp;
}
}
RemoveControlPoint( nPoint );
nKeyIndex = CastElement<CDmeColorLog >( m_hLog )->FindOrAddKey( time, DmeTime_t( 0 ), c );
}
break;
case AT_VECTOR2:
nKeyIndex = ModifyKey< Vector2D >( nPoint, initialTime, time, 2, flValue );
break;
case AT_VECTOR3:
nKeyIndex = ModifyKey< Vector >( nPoint, initialTime, time, 3, flValue );
break;
case AT_VECTOR4:
nKeyIndex = ModifyKey< Vector4D >( nPoint, initialTime, time, 4, flValue );
break;
case AT_QANGLE:
nKeyIndex = ModifyKey< QAngle >( nPoint, initialTime, time, 3, flValue );
break;
case AT_QUATERNION:
nKeyIndex = ModifyKey< Quaternion >( nPoint, initialTime, time, 4, flValue );
break;
}
return nKeyIndex;
}
//-----------------------------------------------------------------------------
// Removes a single control point
//-----------------------------------------------------------------------------
void CDmeLogEditPanel::RemoveControlPoint( int nPoint )
{
Assert( m_hLog.Get() );
m_hLog->RemoveKey( nPoint );
}
//-----------------------------------------------------------------------------
// Gets the interpolated value of the log based on normalized time
//-----------------------------------------------------------------------------
float CDmeLogEditPanel::GetValue( float flIn )
{
DmeTime_t time = NormalizedToTime( flIn );
float flValue = 0.0f;
Assert( m_hLog.Get() );
switch( m_hLog->GetDataType() )
{
case AT_BOOL:
flValue = CastElement<CDmeBoolLog >( m_hLog )->GetValue( time );
break;
case AT_INT:
flValue = CastElement<CDmeIntLog >( m_hLog )->GetValue( time );
break;
case AT_FLOAT:
flValue = CastElement<CDmeFloatLog >( m_hLog )->GetValue( time );
break;
case AT_COLOR:
{
Color c = CastElement<CDmeColorLog >( m_hLog )->GetValue( time );
flValue = c[m_nFieldIndex];
}
break;
case AT_VECTOR2:
flValue = CastElement<CDmeVector2Log >( m_hLog )->GetValue( time )[m_nFieldIndex];
break;
case AT_VECTOR3:
flValue = CastElement<CDmeVector3Log >( m_hLog )->GetValue( time )[m_nFieldIndex];
break;
case AT_VECTOR4:
flValue = CastElement<CDmeVector2Log >( m_hLog )->GetValue( time )[m_nFieldIndex];
break;
case AT_QANGLE:
flValue = CastElement<CDmeQAngleLog >( m_hLog )->GetValue( time )[m_nFieldIndex];
break;
case AT_QUATERNION:
flValue = CastElement<CDmeQuaternionLog >( m_hLog )->GetValue( time )[m_nFieldIndex];
break;
}
return ValueToNormalized( flValue );
}
int CDmeLogEditPanel::ControlPointCount()
{
Assert( m_hLog.Get() );
return m_hLog->GetKeyCount( );
}
//-----------------------------------------------------------------------------
// Gets a particular control point's value
//-----------------------------------------------------------------------------
void CDmeLogEditPanel::GetControlPoint( int nPoint, float *pIn, float *pOut )
{
Assert( m_hLog.Get() );
DmeTime_t time = m_hLog->GetKeyTime( nPoint );
*pIn = TimeToNormalized( time );
float flValue = 0.0f;
Assert( m_hLog.Get() );
switch( m_hLog->GetDataType() )
{
case AT_BOOL:
flValue = CastElement<CDmeBoolLog >( m_hLog )->GetKeyValue( nPoint );
break;
case AT_INT:
flValue = CastElement<CDmeIntLog >( m_hLog )->GetKeyValue( nPoint );
break;
case AT_FLOAT:
flValue = CastElement<CDmeFloatLog >( m_hLog )->GetKeyValue( nPoint );
break;
case AT_COLOR:
{
Color c = CastElement<CDmeColorLog >( m_hLog )->GetKeyValue( nPoint );
flValue = c[m_nFieldIndex];
}
break;
case AT_VECTOR2:
flValue = CastElement<CDmeVector2Log >( m_hLog )->GetKeyValue( nPoint )[m_nFieldIndex];
break;
case AT_VECTOR3:
flValue = CastElement<CDmeVector3Log >( m_hLog )->GetKeyValue( nPoint )[m_nFieldIndex];
break;
case AT_VECTOR4:
flValue = CastElement<CDmeVector2Log >( m_hLog )->GetKeyValue( nPoint )[m_nFieldIndex];
break;
case AT_QANGLE:
flValue = CastElement<CDmeQAngleLog >( m_hLog )->GetKeyValue( nPoint )[m_nFieldIndex];
break;
case AT_QUATERNION:
flValue = CastElement<CDmeQuaternionLog >( m_hLog )->GetKeyValue( nPoint )[m_nFieldIndex];
break;
}
*pOut = ValueToNormalized( flValue );
}
//-----------------------------------------------------------------------------
// Sets the log to edit
//-----------------------------------------------------------------------------
void CDmeLogEditPanel::SetDmeLog( CDmeLog *pLog )
{
bool bValid = pLog && ( pLog->GetDataType() == AT_INT || pLog->GetDataType() == AT_FLOAT || pLog->GetDataType() == AT_COLOR );
if ( bValid )
{
m_hLog = pLog;
}
else
{
m_minTime.SetSeconds( 0.0f );
m_maxTime.SetSeconds( 0.0f );
}
SetVisible( bValid );
}
void CDmeLogEditPanel::SetMask( int nMask )
{
m_LogFieldMask = nMask;
m_nFieldIndex = 0;
for ( int i = 0; i < 4; ++i )
{
if ( m_LogFieldMask & (1 << i) )
{
m_nFieldIndex = i;
break;
}
}
}
//-----------------------------------------------------------------------------
// Sets the time range on the view in ms
//-----------------------------------------------------------------------------
void CDmeLogEditPanel::SetTimeRange( DmeTime_t startTime, DmeTime_t endTime )
{
m_minTime = startTime;
m_maxTime = endTime;
}
//-----------------------------------------------------------------------------
// Sets the vertical range on the view
//-----------------------------------------------------------------------------
void CDmeLogEditPanel::SetVerticalRange( float flMin, float flMax )
{
m_flMinVertical = flMin;
m_flMaxVertical = flMax;
}
//-----------------------------------------------------------------------------
//
// Purpose: Modal picker frame
//
//-----------------------------------------------------------------------------
CDmeLogEditFrame::CDmeLogEditFrame( vgui::Panel *pParent, const char *pTitle ) :
BaseClass( pParent, "DmeLogEditFrame" )
{
m_pContextKeyValues = NULL;
SetDeleteSelfOnClose( true );
m_pCurveEditor = new CDmeLogEditPanel( this, "DmeLogEditPanel" );
m_pOkButton = new Button( this, "OkButton", "#GameUI_OK", this, "Ok" );
m_pCancelButton = new Button( this, "CancelButton", "#GameUI_Cancel", this, "Cancel" );
m_pFilter = new ComboBox( this, "LogFilter", 5, false );
SetBlockDragChaining( true );
LoadControlSettingsAndUserConfig( "resource/dmelogeditframe.res" );
SetTitle( pTitle, false );
}
CDmeLogEditFrame::~CDmeLogEditFrame()
{
CleanUpMessage();
}
//-----------------------------------------------------------------------------
// Deletes the message
//-----------------------------------------------------------------------------
void CDmeLogEditFrame::CleanUpMessage()
{
if ( m_pContextKeyValues )
{
m_pContextKeyValues->deleteThis();
m_pContextKeyValues = NULL;
}
}
//-----------------------------------------------------------------------------
// Purpose: Called when the combo box changes
//-----------------------------------------------------------------------------
void CDmeLogEditFrame::OnTextChanged( )
{
KeyValues *pKeyValues = m_pFilter->GetActiveItemUserData();
int nMask = pKeyValues->GetInt( "Value", CDmeLogEditPanel::FIELD_ALL );
m_pCurveEditor->SetMask( nMask );
}
//-----------------------------------------------------------------------------
// Purpose: Activate the dialog
//-----------------------------------------------------------------------------
void CDmeLogEditFrame::DoModal( CDmeLog *pLog, DmeTime_t startTime, DmeTime_t endTime, KeyValues *pKeyValues )
{
CleanUpMessage();
m_pContextKeyValues = pKeyValues;
m_pCurveEditor->SetDmeLog( pLog );
m_pCurveEditor->SetTimeRange( startTime, endTime );
m_pFilter->SetVisible( true );
m_pFilter->RemoveAll();
switch( pLog->GetDataType() )
{
case AT_BOOL:
case AT_INT:
case AT_FLOAT:
m_pFilter->SetVisible( false );
break;
case AT_COLOR:
m_pFilter->AddItem( "RGB Channel", new KeyValues( "Mask", "Value", CDmeLogEditPanel::FIELD_R | CDmeLogEditPanel::FIELD_G | CDmeLogEditPanel::FIELD_B ) );
m_pFilter->AddItem( "Red Channel", new KeyValues( "Mask", "Value", CDmeLogEditPanel::FIELD_R ) );
m_pFilter->AddItem( "Green Channel", new KeyValues( "Mask", "Value", CDmeLogEditPanel::FIELD_G ) );
m_pFilter->AddItem( "Blue Channel", new KeyValues( "Mask", "Value", CDmeLogEditPanel::FIELD_B ) );
m_pFilter->AddItem( "Alpha Channel", new KeyValues( "Mask", "Value", CDmeLogEditPanel::FIELD_A ) );
break;
case AT_VECTOR2:
m_pFilter->AddItem( "X Channel", new KeyValues( "Mask", "Value", CDmeLogEditPanel::FIELD_X ) );
m_pFilter->AddItem( "Y Channel", new KeyValues( "Mask", "Value", CDmeLogEditPanel::FIELD_Y ) );
break;
case AT_VECTOR3:
case AT_QANGLE:
m_pFilter->AddItem( "X Channel", new KeyValues( "Mask", "Value", CDmeLogEditPanel::FIELD_X ) );
m_pFilter->AddItem( "Y Channel", new KeyValues( "Mask", "Value", CDmeLogEditPanel::FIELD_Y ) );
m_pFilter->AddItem( "Z Channel", new KeyValues( "Mask", "Value", CDmeLogEditPanel::FIELD_Z ) );
break;
case AT_VECTOR4:
case AT_QUATERNION:
m_pFilter->AddItem( "X Channel", new KeyValues( "Mask", "Value", CDmeLogEditPanel::FIELD_X ) );
m_pFilter->AddItem( "Y Channel", new KeyValues( "Mask", "Value", CDmeLogEditPanel::FIELD_Y ) );
m_pFilter->AddItem( "Z Channel", new KeyValues( "Mask", "Value", CDmeLogEditPanel::FIELD_Z ) );
m_pFilter->AddItem( "W Channel", new KeyValues( "Mask", "Value", CDmeLogEditPanel::FIELD_W ) );
break;
}
if ( m_pFilter->IsVisible() )
{
// Will cause the mask to be set
m_pFilter->ActivateItemByRow( 0 );
}
else
{
m_pCurveEditor->SetMask( CDmeLogEditPanel::FIELD_ALL );
}
BaseClass::DoModal();
}
//-----------------------------------------------------------------------------
// On command
//-----------------------------------------------------------------------------
void CDmeLogEditFrame::OnCommand( const char *pCommand )
{
if ( !Q_stricmp( pCommand, "Ok" ) )
{
KeyValues *pActionKeys = new KeyValues( "LogEdited" );
if ( m_pContextKeyValues )
{
pActionKeys->AddSubKey( m_pContextKeyValues );
// This prevents them from being deleted later
m_pContextKeyValues = NULL;
}
PostActionSignal( pActionKeys );
CloseModal();
return;
}
if ( !Q_stricmp( pCommand, "Cancel" ) )
{
CloseModal();
return;
}
BaseClass::OnCommand( pCommand );
}
+47
View File
@@ -0,0 +1,47 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================
#include "dme_controls/dmemdlpanel.h"
#include "dme_controls/dmecontrols.h"
#include "dme_controls/dmepanel.h"
#include "movieobjects/dmemdl.h"
#include "movieobjects/dmemdlmakefile.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
IMPLEMENT_DMEPANEL_FACTORY( CDmeMDLPanel, DmeMDLMakefile, "DmeMakeFileOutputPreview", "MDL MakeFile Output Preview", false );
//-----------------------------------------------------------------------------
// Constructor, destructor
//-----------------------------------------------------------------------------
CDmeMDLPanel::CDmeMDLPanel( vgui::Panel *pParent, const char *pName ) : BaseClass( pParent, pName )
{
}
CDmeMDLPanel::~CDmeMDLPanel()
{
}
//-----------------------------------------------------------------------------
// DMEPanel..
//-----------------------------------------------------------------------------
void CDmeMDLPanel::SetDmeElement( CDmeMDLMakefile *pMDLMakefile )
{
if ( pMDLMakefile != NULL )
{
CDmeMDL *pMDL = CastElement< CDmeMDL >( pMDLMakefile->GetOutputElement( true ) );
if ( pMDL )
{
SetMDL( pMDL->GetMDL() );
}
}
}
+656
View File
@@ -0,0 +1,656 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================
#include "dme_controls/dmepanel.h"
#include "tier1/KeyValues.h"
#include "dme_controls/dmecontrols.h"
#include "vgui_controls/combobox.h"
#include "datamodel/dmelement.h"
#include "dme_controls/dmecontrols_utils.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
// All DmePanels used by the system must be listed here to link them in
//-----------------------------------------------------------------------------
USING_DMEPANEL_FACTORY( CDmeElementPanel, DmElement );
USING_DMEPANEL_FACTORY( CDmeSourceSkinPanel, DmeSourceSkin );
USING_DMEPANEL_FACTORY( CAssetBuilder, DmeMakefile );
USING_DMEPANEL_FACTORY( CDmeSourceDCCFilePanel, DmeSourceDCCFile );
USING_DMEPANEL_FACTORY( CDmeDagRenderPanel, DmeDag );
USING_DMEPANEL_FACTORY( CDmeDagRenderPanel, DmeSourceAnimation );
USING_DMEPANEL_FACTORY( CDmeDagRenderPanel, DmeSourceSkin );
USING_DMEPANEL_FACTORY( CDmeDagRenderPanel, DmeDCCMakefile );
USING_DMEPANEL_FACTORY( CDmeDagEditPanel, DmeDag );
USING_DMEPANEL_FACTORY( CDmeDagEditPanel, DmeSourceAnimation );
USING_DMEPANEL_FACTORY( CDmeDagEditPanel, DmeSourceSkin );
USING_DMEPANEL_FACTORY( CDmeDagEditPanel, DmeDCCMakefile );
USING_DMEPANEL_FACTORY( CDmeMDLPanel, DmeMDLMakefile );
//-----------------------------------------------------------------------------
// constructor, destructor
//-----------------------------------------------------------------------------
CDmePanel::CDmePanel( vgui::Panel *pParent, const char *pPanelName, bool bComboBoxVisible ) :
BaseClass( pParent, pPanelName )
{
m_pEditorNames = new vgui::ComboBox( this, "EditorDisplayNames", 6, false );
if ( bComboBoxVisible )
{
m_pEditorNames->AddActionSignalTarget( this );
}
else
{
m_pEditorNames->SetVisible( false );
}
m_pDmeEditorPanel = NULL;
m_hElement = NULL;
SetDropEnabled( true );
}
CDmePanel::~CDmePanel()
{
DeleteCachedPanels();
}
//-----------------------------------------------------------------------------
// Scheme
//-----------------------------------------------------------------------------
void CDmePanel::ApplySchemeSettings( vgui::IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
m_pEditorNames->SetFont( pScheme->GetFont( "DefaultVerySmall" ) );
}
//-----------------------------------------------------------------------------
// Layout
//-----------------------------------------------------------------------------
void CDmePanel::PerformLayout()
{
BaseClass::PerformLayout();
int w, h;
GetSize( w, h );
if ( m_pEditorNames->IsVisible() )
{
m_pEditorNames->SetBounds( 1, 1, w-2, 20 );
if ( m_pDmeEditorPanel )
{
m_pDmeEditorPanel->SetBounds( 0, 24, w, h-24 );
}
}
else
{
if ( m_pDmeEditorPanel )
{
m_pDmeEditorPanel->SetBounds( 0, 0, w, h );
}
}
}
//-----------------------------------------------------------------------------
// Drag/drop
//-----------------------------------------------------------------------------
bool CDmePanel::IsDroppable( CUtlVector< KeyValues * >& msglist )
{
if ( msglist.Count() != 1 )
return false;
KeyValues *data = msglist[ 0 ];
CDmElement *ptr = GetElementKeyValue<CDmElement>( data, "dmeelement" );
if ( !ptr )
return false;
if ( ptr == m_hElement.Get() )
return false;
return true;
}
void CDmePanel::OnPanelDropped( CUtlVector< KeyValues * >& msglist )
{
if ( msglist.Count() != 1 )
return;
KeyValues *data = msglist[ 0 ];
CDmElement *ptr = GetElementKeyValue<CDmElement>( data, "dmeelement" );
if ( !ptr )
return;
// Already browsing
if ( ptr == m_hElement.Get() )
return;
SetDmeElement( ptr );
}
//-----------------------------------------------------------------------------
// Sets the default editor type
//-----------------------------------------------------------------------------
void CDmePanel::SetDefaultEditorType( const char *pEditorType )
{
m_DefaultEditorType = pEditorType;
}
//-----------------------------------------------------------------------------
// Populate editor name combo box
//-----------------------------------------------------------------------------
void CDmePanel::PopulateEditorNames( const char *pPanelName )
{
m_pEditorNames->RemoveAll();
m_pEditorNames->SetText( "" );
if ( !m_pEditorNames->IsVisible() )
{
SetEditor( pPanelName );
return;
}
if ( !m_hElement.Get() )
{
OnTextChanged();
return;
}
const char *pPreferredEditor = NULL;
if ( m_LastUsedEditorType.Defined( m_hElement->GetTypeString() ) )
{
pPreferredEditor = m_LastUsedEditorType[ m_hElement->GetTypeString() ].Get();
}
else
{
pPreferredEditor = m_DefaultEditorType;
}
int nBestInheritanceDepth = -1;
int nActiveItemID = -1;
bool bFoundPanelName = false;
DmeFactoryHandle_t h = DmePanelFirstFactory( m_hElement.Get() );
for ( ; h != DMEFACTORY_HANDLE_INVALID; h = DmePanelNextFactory( h, m_hElement.Get() ) )
{
const char *pDisplayName = DmePanelFactoryDisplayName( h );
const char *pEditorName = DmePanelFactoryName( h );
KeyValues *pKeyValues = new KeyValues( "entry", "editorName", pEditorName );
int nItemID = m_pEditorNames->AddItem( pDisplayName, pKeyValues );
if ( pPanelName && !Q_stricmp( pPanelName, pEditorName ) )
{
nBestInheritanceDepth = 0;
nActiveItemID = nItemID;
bFoundPanelName = true;
continue;
}
if ( pPreferredEditor && !bFoundPanelName && !Q_stricmp( pPreferredEditor, pEditorName ) )
{
nBestInheritanceDepth = 0;
nActiveItemID = nItemID;
continue;
}
// Don't select this as the default if it's not a default factory
if ( !DmePanelFactoryIsDefault(h) )
continue;
// Choose this factory if it's more derived than the previous best
const char *pElementType = DmePanelFactoryElementType( h );
int nInheritanceDepth = m_hElement->GetInheritanceDepth( pElementType );
Assert( nInheritanceDepth >= 0 );
if ( nBestInheritanceDepth >= 0 && ( nInheritanceDepth >= nBestInheritanceDepth ) )
continue;
nBestInheritanceDepth = nInheritanceDepth;
nActiveItemID = nItemID;
}
if ( m_pEditorNames->GetItemCount() == 0 )
{
// ItemCount == 0;
m_pEditorNames->SetText( "" );
m_CurrentEditorName = NULL;
OnTextChanged();
return;
}
if ( nActiveItemID >= 0 )
{
m_pEditorNames->ActivateItem( nActiveItemID );
}
else
{
m_pEditorNames->ActivateItemByRow( 0 );
}
}
//-----------------------------------------------------------------------------
// Called when the dme element was changed
//-----------------------------------------------------------------------------
void CDmePanel::OnDmeElementChanged()
{
PostActionSignal( new KeyValues( "DmeElementChanged" ) );
}
//-----------------------------------------------------------------------------
// Context menu support
//-----------------------------------------------------------------------------
void CDmePanel::OnOpenContextMenu( KeyValues *params )
{
// Forward the context menu message to the DME panel
KeyValues *pMsg = params->MakeCopy();
if ( m_pDmeEditorPanel )
{
PostMessage( m_pDmeEditorPanel->GetVPanel(), pMsg );
}
}
//-----------------------------------------------------------------------------
// Copy/paste support
//-----------------------------------------------------------------------------
void CDmePanel::PostMessageToDmePanel( const char *pMessage )
{
if ( m_pDmeEditorPanel )
{
PostMessage( m_pDmeEditorPanel->GetVPanel(), new KeyValues( pMessage ) );
}
}
void CDmePanel::OnCut()
{
PostMessageToDmePanel( "OnCut" );
}
void CDmePanel::OnCopy()
{
PostMessageToDmePanel( "OnCopy" );
}
void CDmePanel::OnPaste()
{
PostMessageToDmePanel( "OnPaste" );
}
void CDmePanel::OnPasteInsert()
{
PostMessageToDmePanel( "OnPasteInsert" );
}
void CDmePanel::OnPasteReference()
{
PostMessageToDmePanel( "OnPasteReference" );
}
void CDmePanel::OnEditDelete()
{
PostMessageToDmePanel( "OnEditDelete" );
}
//-----------------------------------------------------------------------------
// Called when a child of the dme panel switches the thing it's looking at
//-----------------------------------------------------------------------------
void CDmePanel::OnViewedElementChanged( KeyValues *kv )
{
// This is kind of tricky. It's called by the element properties tree
// when doing the back/forward searching. Just calling the normal SetDmeElement
// doesn't work because it reorders the history. What we want is to
// populate the combo box without causing the OnTextChanged message to get sent.
// FIXME: Perhaps it would be better to extract the back/forward/search
// out of the element properties tree and put it into the dme panel?
CDmElement *pElement = GetElementKeyValue<CDmElement>( kv, "dmeelement" );
if ( pElement == m_hElement )
return;
// If the current editor isn't supported by this new element, then just reset. Too bad.
bool bFound = false;
if ( m_CurrentEditorName.Length() && pElement )
{
DmeFactoryHandle_t h = DmePanelFirstFactory( pElement );
for ( ; h != DMEFACTORY_HANDLE_INVALID; h = DmePanelNextFactory( h, pElement ) )
{
const char *pEditorName = DmePanelFactoryName( h );
if ( !Q_stricmp( m_CurrentEditorName, pEditorName ) )
{
bFound = true;
break;
}
}
}
if ( !bFound )
{
SetDmeElement( pElement );
return;
}
// Remove obsolete items
int nCount = m_pEditorNames->GetItemCount();
while ( --nCount >= 0 )
{
int nItemID = m_pEditorNames->GetItemIDFromRow( nCount );
KeyValues *kv = m_pEditorNames->GetItemUserData( nItemID );
if ( Q_stricmp( m_CurrentEditorName, kv->GetString( "editorName" ) ) )
{
m_pEditorNames->DeleteItem( nItemID );
}
}
// Just want to populate the combo box with new items
DmeFactoryHandle_t h = DmePanelFirstFactory( pElement );
for ( ; h != DMEFACTORY_HANDLE_INVALID; h = DmePanelNextFactory( h, pElement ) )
{
const char *pEditorName = DmePanelFactoryName( h );
if ( Q_stricmp( pEditorName, m_CurrentEditorName ) )
{
const char *pDisplayName = DmePanelFactoryDisplayName( h );
KeyValues *pKeyValues = new KeyValues( "entry", "editorName", pEditorName );
m_pEditorNames->AddItem( pDisplayName, pKeyValues );
}
}
m_hElement = pElement;
}
//-----------------------------------------------------------------------------
// Delete cached panels
//-----------------------------------------------------------------------------
void CDmePanel::DeleteCachedPanels()
{
int nCount = m_EditorPanelCache.GetNumStrings();
for ( int i = 0; i < nCount; ++i )
{
int nEditorCount = m_EditorPanelCache[ i ].Count();
for ( int j = 0; j < nEditorCount; ++j )
{
m_EditorPanelCache[ i ][ j ].m_pEditorPanel->MarkForDeletion();
}
}
m_EditorPanelCache.Clear();
}
//-----------------------------------------------------------------------------
// Refreshes the current panel owing to external change
// Values only means no topological change
//-----------------------------------------------------------------------------
void CDmePanel::Refresh( bool bValuesOnly )
{
if ( m_pDmeEditorPanel )
{
KeyValues *pKeyValues = new KeyValues( "ElementChangedExternally", "valuesOnly", bValuesOnly );
PostMessage( m_pDmeEditorPanel, pKeyValues );
}
}
//-----------------------------------------------------------------------------
// Deactivates the current editor
//-----------------------------------------------------------------------------
void CDmePanel::DeactivateCurrentEditor()
{
if ( m_pDmeEditorPanel )
{
m_pDmeEditorPanel->SetParent( (vgui::Panel*)NULL );
m_pDmeEditorPanel = NULL;
m_CurrentEditorName = NULL;
}
}
//-----------------------------------------------------------------------------
// Switch to a new editor
//-----------------------------------------------------------------------------
void CDmePanel::SetEditor( const char *pEditorName )
{
if ( pEditorName && !Q_stricmp( m_CurrentEditorName, pEditorName ) )
return;
DeactivateCurrentEditor();
if ( !m_hElement.Get() || !pEditorName )
return;
if ( m_EditorPanelCache.Defined( pEditorName ) )
{
CUtlVector< EditorPanelMap_t > &entries = m_EditorPanelCache[ pEditorName ];
int nCount = entries.Count();
for ( int i = 0; i < nCount; ++i )
{
EditorPanelMap_t &entry = entries[i];
if ( !m_hElement->IsA( entry.m_pFactory->m_pElementType ) )
continue;
m_pDmeEditorPanel = entry.m_pEditorPanel;
m_pDmeEditorPanel->SetParent( this );
entry.m_pFactory->SetDmeElement( m_pDmeEditorPanel, m_hElement );
break;
}
}
if ( !m_pDmeEditorPanel )
{
EditorPanelMap_t entry;
if ( CreateDmePanel( this, "DmePanelEditor", m_hElement, pEditorName, &entry ) )
{
m_EditorPanelCache[ pEditorName ].AddToTail( entry );
m_pDmeEditorPanel = entry.m_pEditorPanel;
}
}
if ( m_pDmeEditorPanel )
{
// Store the last selected type of editor
m_LastUsedEditorType[ m_hElement->GetTypeString() ] = pEditorName;
m_CurrentEditorName = pEditorName;
m_pDmeEditorPanel->AddActionSignalTarget( this );
}
InvalidateLayout();
}
//-----------------------------------------------------------------------------
// Called when a new element in the combo box has been selected
//-----------------------------------------------------------------------------
void CDmePanel::OnTextChanged()
{
KeyValues *kv = m_pEditorNames->GetActiveItemUserData();
const char *pEditorName = kv ? kv->GetString( "editorName", NULL ) : NULL;
SetEditor( pEditorName );
}
//-----------------------------------------------------------------------------
// Setting a new element
//-----------------------------------------------------------------------------
void CDmePanel::SetDmeElement( CDmElement *pDmeElement, bool bForce, const char *pPanelName )
{
if ( ( m_hElement == pDmeElement ) && !bForce )
{
if ( !pPanelName || !Q_stricmp( pPanelName, m_CurrentEditorName.Get() ) )
return;
}
m_hElement = pDmeElement;
m_CurrentEditorName = NULL;
// Populate the editor type list
PopulateEditorNames( pPanelName );
}
//-----------------------------------------------------------------------------
// Statics for the panel factory
//-----------------------------------------------------------------------------
CBaseDmePanelFactory* CBaseDmePanelFactory::s_pFirstDmePanelFactory;
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CBaseDmePanelFactory::CBaseDmePanelFactory( const char *pElementType, const char *pEditorName,
const char *pEditorDisplayName, bool bIsDefault, bool bIsOverride )
{
// Prior to linking this in, look to see if this has been overridden
CBaseDmePanelFactory *pPrevFactory = NULL;
for( CBaseDmePanelFactory* pFactory = s_pFirstDmePanelFactory; pFactory;
pPrevFactory = pFactory, pFactory = pFactory->m_pNext )
{
if ( !Q_stricmp( pFactory->m_pElementType, pElementType ) &&
!Q_stricmp( pFactory->m_pEditorDisplayName, pEditorDisplayName ) )
{
// Collision found! If this is not an override, then we've been overridden
if ( !bIsOverride )
{
AssertMsg( pFactory->m_bIsOverride, ( "Two DmePanel factories have the same name (\"%s\") + type (\"%s\")!\n", pElementType, pEditorName ) );
return;
}
// If this *is* an override, replace the previous version
AssertMsg( !pFactory->m_bIsOverride, ( "Two DmePanel factories have the same name (\"%s\") + type (\"%s\")!\n", pElementType, pEditorName ) );
if ( pPrevFactory )
{
pPrevFactory->m_pNext = pFactory->m_pNext;
}
else
{
s_pFirstDmePanelFactory = pFactory->m_pNext;
}
break;
}
}
m_pNext = s_pFirstDmePanelFactory;
s_pFirstDmePanelFactory = this;
m_pElementType = pElementType;
m_pEditorName = pEditorName;
m_pEditorDisplayName = pEditorDisplayName;
m_bIsDefault = bIsDefault;
m_bIsOverride = bIsOverride;
}
//-----------------------------------------------------------------------------
// Dme Panel factory iteration methods
//-----------------------------------------------------------------------------
DmeFactoryHandle_t DmePanelFirstFactory( CDmElement *pElement )
{
CBaseDmePanelFactory *pFactory = CBaseDmePanelFactory::s_pFirstDmePanelFactory;
for ( ; pFactory; pFactory = pFactory->m_pNext )
{
if ( !pElement || pElement->IsA( pFactory->m_pElementType ) )
return (DmeFactoryHandle_t)pFactory;
}
return DMEFACTORY_HANDLE_INVALID;
}
DmeFactoryHandle_t DmePanelNextFactory( DmeFactoryHandle_t h, CDmElement *pElement )
{
CBaseDmePanelFactory *pFactory = (CBaseDmePanelFactory*)h;
if ( !pFactory )
return DMEFACTORY_HANDLE_INVALID;
for ( pFactory = pFactory->m_pNext; pFactory; pFactory = pFactory->m_pNext )
{
if ( !pElement || pElement->IsA( pFactory->m_pElementType ) )
return (DmeFactoryHandle_t)pFactory;
}
return DMEFACTORY_HANDLE_INVALID;
}
//-----------------------------------------------------------------------------
// Dme Panel factory info methods
//-----------------------------------------------------------------------------
const char *DmePanelFactoryName( DmeFactoryHandle_t h )
{
CBaseDmePanelFactory *pFactory = (CBaseDmePanelFactory*)h;
return pFactory ? pFactory->m_pEditorName : NULL;
}
const char *DmePanelFactoryDisplayName( DmeFactoryHandle_t h )
{
CBaseDmePanelFactory *pFactory = (CBaseDmePanelFactory*)h;
return pFactory ? pFactory->m_pEditorDisplayName : NULL;
}
const char *DmePanelFactoryElementType( DmeFactoryHandle_t h )
{
CBaseDmePanelFactory *pFactory = (CBaseDmePanelFactory*)h;
return pFactory ? pFactory->m_pElementType : NULL;
}
bool DmePanelFactoryIsDefault( DmeFactoryHandle_t h )
{
CBaseDmePanelFactory *pFactory = (CBaseDmePanelFactory*)h;
return pFactory ? pFactory->m_bIsDefault : false;
}
//-----------------------------------------------------------------------------
// Dme Panel factory methods
//-----------------------------------------------------------------------------
bool CDmePanel::CreateDmePanel( vgui::Panel *pParent, const char *pPanelName, CDmElement *pElement, const char *pEditorName, EditorPanelMap_t *pMap )
{
int nBestInheritanceDepth = -1;
CBaseDmePanelFactory *pBestFactory = NULL;
CBaseDmePanelFactory *pFactory = CBaseDmePanelFactory::s_pFirstDmePanelFactory;
for ( ; pFactory; pFactory = pFactory->m_pNext )
{
if ( !pElement->IsA( pFactory->m_pElementType ) )
continue;
if ( pEditorName )
{
if ( !Q_stricmp( pEditorName, pFactory->m_pEditorName ) )
{
pBestFactory = pFactory;
break;
}
continue;
}
// No editor name specified? Only use default factories
if ( !pFactory->m_bIsDefault )
continue;
// Choose this factory if it's more derived than the previous best
int nInheritanceDepth = pElement->GetInheritanceDepth( pFactory->m_pElementType );
Assert( nInheritanceDepth >= 0 );
if ( nBestInheritanceDepth >= 0 && ( nInheritanceDepth > nBestInheritanceDepth ) )
continue;
nBestInheritanceDepth = nInheritanceDepth;
pBestFactory = pFactory;
}
if ( pBestFactory )
{
pMap->m_pFactory = pBestFactory;
pMap->m_pEditorPanel = pBestFactory->CreateDmePanel( pParent, pPanelName, pElement );
return true;
}
return false;
}
+280
View File
@@ -0,0 +1,280 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================
#include "dme_controls/DmePicker.h"
#include "tier1/KeyValues.h"
#include "vgui_controls/TextEntry.h"
#include "vgui_controls/ListPanel.h"
#include "vgui_controls/Button.h"
#include "datamodel/dmelement.h"
#include "vgui/ISurface.h"
#include "vgui/iinput.h"
#include "dme_controls/dmecontrols_utils.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
//
// Dme Picker
//
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Sort by MDL name
//-----------------------------------------------------------------------------
static int __cdecl DmeBrowserSortFunc( vgui::ListPanel *pPanel, const ListPanelItem &item1, const ListPanelItem &item2 )
{
const char *string1 = item1.kv->GetString("dme");
const char *string2 = item2.kv->GetString("dme");
return stricmp( string1, string2 );
}
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CDmePicker::CDmePicker( vgui::Panel *pParent ) : BaseClass( pParent, "DmePicker" )
{
// FIXME: Make this an image browser
m_pDmeBrowser = new vgui::ListPanel( this, "DmeBrowser" );
m_pDmeBrowser->AddColumnHeader( 0, "dme", "Dme Elements", 52, 0 );
m_pDmeBrowser->SetSelectIndividualCells( true );
m_pDmeBrowser->SetEmptyListText( "No Dme Elements" );
m_pDmeBrowser->SetDragEnabled( true );
m_pDmeBrowser->AddActionSignalTarget( this );
m_pDmeBrowser->SetSortFunc( 0, DmeBrowserSortFunc );
m_pDmeBrowser->SetSortColumn( 0 );
// filter selection
m_pFilterList = new TextEntry( this, "FilterList" );
m_pFilterList->AddActionSignalTarget( this );
m_pFilterList->RequestFocus();
LoadControlSettingsAndUserConfig( "resource/dmepicker.res" );
}
//-----------------------------------------------------------------------------
// Purpose: Destructor
//-----------------------------------------------------------------------------
CDmePicker::~CDmePicker()
{
}
//-----------------------------------------------------------------------------
// Purpose: called to open
//-----------------------------------------------------------------------------
void CDmePicker::Activate( const CUtlVector< DmePickerInfo_t >&vec )
{
m_pDmeBrowser->RemoveAll();
int nCount = vec.Count();
for ( int i = 0; i < nCount; ++i )
{
CDmElement *pElement = GetElement<CDmElement>( vec[i].m_hElement );
const char *pElementName = pElement ? pElement->GetName() : "<null element>";
const char *pItemName = vec[i].m_pChoiceString ? vec[i].m_pChoiceString : pElementName;
KeyValues *kv = new KeyValues( "node", "dme", pItemName );
kv->SetInt( "dmeHandle", vec[i].m_hElement );
int nItemID = m_pDmeBrowser->AddItem( kv, 0, false, false );
KeyValues *pDrag = new KeyValues( "drag", "text", pElementName );
pDrag->SetString( "texttype", "dmeName" );
pDrag->SetInt( "dmeelement", vec[i].m_hElement );
m_pDmeBrowser->SetItemDragData( nItemID, pDrag );
}
RefreshDmeList();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CDmePicker::OnKeyCodePressed( KeyCode code )
{
if (( code == KEY_UP ) || ( code == KEY_DOWN ) || ( code == KEY_PAGEUP ) || ( code == KEY_PAGEDOWN ))
{
KeyValues *pMsg = new KeyValues("KeyCodePressed", "code", code);
vgui::ipanel()->SendMessage( m_pDmeBrowser->GetVPanel(), pMsg, GetVPanel());
pMsg->deleteThis();
}
else
{
BaseClass::OnKeyCodePressed( code );
}
}
//-----------------------------------------------------------------------------
// Purpose: refreshes the file list
//-----------------------------------------------------------------------------
void CDmePicker::RefreshDmeList()
{
// Check the filter matches
int nMatchingElements = 0;
int nTotalCount = 0;
for ( int nItemID = m_pDmeBrowser->FirstItem(); nItemID != m_pDmeBrowser->InvalidItemID(); nItemID = m_pDmeBrowser->NextItem( nItemID ) )
{
KeyValues *kv = m_pDmeBrowser->GetItem( nItemID );
const char *pElementName = kv->GetString( "dme" );
bool bIsVisible = !m_Filter.Length() || Q_stristr( pElementName, m_Filter.Get() );
m_pDmeBrowser->SetItemVisible( nItemID, bIsVisible );
if ( bIsVisible )
{
++nMatchingElements;
}
++nTotalCount;
}
m_pDmeBrowser->SortList();
char pColumnTitle[512];
Q_snprintf( pColumnTitle, sizeof(pColumnTitle), "%s (%d/%d)",
"Dme Elements", nMatchingElements, nTotalCount );
m_pDmeBrowser->SetColumnHeaderText( 0, pColumnTitle );
if ( ( m_pDmeBrowser->GetItemCount() > 0 ) && ( m_pDmeBrowser->GetSelectedItemsCount() == 0 ) )
{
int nItemID = m_pDmeBrowser->GetItemIDFromRow( 0 );
m_pDmeBrowser->SetSelectedCell( nItemID, 0 );
}
}
//-----------------------------------------------------------------------------
// Purpose: refreshes dialog on text changing
//-----------------------------------------------------------------------------
void CDmePicker::OnTextChanged( )
{
int nLength = m_pFilterList->GetTextLength();
m_Filter.SetLength( nLength );
if ( nLength > 0 )
{
m_pFilterList->GetText( m_Filter.GetForModify(), nLength+1 );
}
RefreshDmeList();
}
//-----------------------------------------------------------------------------
// Returns the selceted model name
//-----------------------------------------------------------------------------
CDmElement *CDmePicker::GetSelectedDme( )
{
if ( m_pDmeBrowser->GetSelectedItemsCount() == 0 )
return NULL;
int nIndex = m_pDmeBrowser->GetSelectedItem( 0 );
KeyValues *pItemKeyValues = m_pDmeBrowser->GetItem( nIndex );
return GetElementKeyValue< CDmElement >( pItemKeyValues, "dmeHandle" );
}
//-----------------------------------------------------------------------------
//
// Purpose: Modal picker frame
//
//-----------------------------------------------------------------------------
CDmePickerFrame::CDmePickerFrame( vgui::Panel *pParent, const char *pTitle ) :
BaseClass( pParent, "DmePickerFrame" )
{
m_pContextKeyValues = NULL;
SetDeleteSelfOnClose( true );
m_pPicker = new CDmePicker( this );
m_pPicker->AddActionSignalTarget( this );
m_pOpenButton = new Button( this, "OpenButton", "#FileOpenDialog_Open", this, "Open" );
m_pCancelButton = new Button( this, "CancelButton", "#FileOpenDialog_Cancel", this, "Cancel" );
SetBlockDragChaining( true );
LoadControlSettingsAndUserConfig( "resource/dmepickerframe.res" );
SetTitle( pTitle, false );
}
CDmePickerFrame::~CDmePickerFrame()
{
CleanUpMessage();
}
//-----------------------------------------------------------------------------
// Deletes the message
//-----------------------------------------------------------------------------
void CDmePickerFrame::CleanUpMessage()
{
if ( m_pContextKeyValues )
{
m_pContextKeyValues->deleteThis();
m_pContextKeyValues = NULL;
}
}
//-----------------------------------------------------------------------------
// Purpose: Activate the dialog
//-----------------------------------------------------------------------------
void CDmePickerFrame::DoModal( const CUtlVector< DmePickerInfo_t >& vec, KeyValues *pKeyValues )
{
CleanUpMessage();
m_pContextKeyValues = pKeyValues;
m_pPicker->Activate( vec );
m_pOpenButton->SetEnabled( vec.Count() != 0 );
BaseClass::DoModal();
}
//-----------------------------------------------------------------------------
// On command
//-----------------------------------------------------------------------------
void CDmePickerFrame::OnCommand( const char *pCommand )
{
if ( !Q_stricmp( pCommand, "Open" ) )
{
CDmElement *pElement = m_pPicker->GetSelectedDme( );
KeyValues *pActionKeys = new KeyValues( "DmeSelected" );
SetElementKeyValue( pActionKeys, "dme", pElement );
if ( m_pContextKeyValues )
{
pActionKeys->AddSubKey( m_pContextKeyValues );
// This prevents them from being deleted later
m_pContextKeyValues = NULL;
}
PostActionSignal( pActionKeys );
CloseModal();
return;
}
if ( !Q_stricmp( pCommand, "Cancel" ) )
{
KeyValues *pActionKeys = new KeyValues( "DmeSelectionCancelled" );
if ( m_pContextKeyValues )
{
pActionKeys->AddSubKey( m_pContextKeyValues );
// This prevents them from being deleted later
m_pContextKeyValues = NULL;
}
PostActionSignal( pActionKeys );
CloseModal();
return;
}
BaseClass::OnCommand( pCommand );
}
File diff suppressed because it is too large Load Diff
+53
View File
@@ -0,0 +1,53 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================
#include "dme_controls/filtercombobox.h"
using namespace vgui;
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CFilterComboBox::CFilterComboBox( Panel *parent, const char *panelName, int numLines, bool allowEdit ) :
BaseClass( parent, panelName, numLines, allowEdit )
{
}
//-----------------------------------------------------------------------------
// Purpose: panel lost focus message
//-----------------------------------------------------------------------------
void CFilterComboBox::OnKillFocus()
{
int nLength = GetTextLength();
char *pFilterText = (char*)_alloca( (nLength+1) * sizeof(char) );
GetText( pFilterText, nLength+1 );
// Remove the existing version in the list
char pItemText[512];
int nItemCount = GetItemCount();
int i;
for ( i = 0; i < nItemCount; ++i )
{
GetItemText( i, pItemText, sizeof(pItemText) );
if ( !Q_stricmp( pFilterText, pItemText ) )
break;
}
if ( i != nItemCount )
{
// Remove the existing copy
DeleteItem( i );
}
AddItem( pFilterText, NULL );
BaseClass::OnKillFocus( );
}
+676
View File
@@ -0,0 +1,676 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//===========================================================================//
#include "dme_controls/particlesystempanel.h"
#include "dme_controls/dmepanel.h"
#include "movieobjects/dmeparticlesystemdefinition.h"
#include "materialsystem/imesh.h"
#include "materialsystem/imaterial.h"
#include "VGuiMatSurface/IMatSystemSurface.h"
#include "matsys_controls/matsyscontrols.h"
#include "vgui/IVGui.h"
#include "vgui_controls/propertypage.h"
#include "vgui_controls/propertysheet.h"
#include "vgui_controls/textentry.h"
#include "vgui_controls/splitter.h"
#include "vgui_controls/checkbutton.h"
#include "matsys_controls/colorpickerpanel.h"
#include "particles/particles.h"
#include "tier1/KeyValues.h"
#include "tier1/utlbuffer.h"
#include "tier2/renderutils.h"
using namespace vgui;
//-----------------------------------------------------------------------------
// Enums
//-----------------------------------------------------------------------------
enum
{
SCROLLBAR_SIZE=18, // the width of a scrollbar
WINDOW_BORDER_WIDTH=2 // the width of the window's border
};
#define SPHERE_RADIUS 10.0f
//-----------------------------------------------------------------------------
// Constructor, destructor
//-----------------------------------------------------------------------------
CParticleSystemPanel::CParticleSystemPanel( vgui::Panel *pParent, const char *pName ) : BaseClass( pParent, pName )
{
m_pParticleSystem = NULL;
m_flLastTime = FLT_MAX;
m_bRenderBounds = false;
m_bRenderCullBounds = false;
m_bRenderHelpers = false;
m_bPerformNameBasedLookup = true;
m_ParticleSystemName = NULL;
InvalidateUniqueId( &m_ParticleSystemId );
InvalidateUniqueId( &m_RenderHelperId );
LookAt( SPHERE_RADIUS );
m_pLightmapTexture.Init( "//platform/materials/debug/defaultlightmap", "editor" );
m_DefaultEnvCubemap.Init( "editor/cubemap", "editor", true );
for ( int i = 0; i < MAX_PARTICLE_CONTROL_POINTS; ++i )
{
SetControlPointValue( i, Vector( 0, 0, 10.0f * i ) );
}
}
CParticleSystemPanel::~CParticleSystemPanel()
{
m_pLightmapTexture.Shutdown();
m_DefaultEnvCubemap.Shutdown();
}
//-----------------------------------------------------------------------------
// Scheme
//-----------------------------------------------------------------------------
void CParticleSystemPanel::ApplySchemeSettings( vgui::IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
SetBorder( pScheme->GetBorder( "MenuBorder") );
}
//-----------------------------------------------------------------------------
// Indicates that bounds should be drawn
//-----------------------------------------------------------------------------
void CParticleSystemPanel::RenderBounds( bool bEnable )
{
m_bRenderBounds = bEnable;
}
//-----------------------------------------------------------------------------
// Indicates that cull sphere should be drawn
//-----------------------------------------------------------------------------
void CParticleSystemPanel::RenderCullBounds( bool bEnable )
{
m_bRenderCullBounds = bEnable;
}
//-----------------------------------------------------------------------------
// Indicates that bounds should be drawn
//-----------------------------------------------------------------------------
void CParticleSystemPanel::RenderHelpers( bool bEnable )
{
m_bRenderHelpers = bEnable;
}
//-----------------------------------------------------------------------------
// Indicates which helper to draw
//-----------------------------------------------------------------------------
void CParticleSystemPanel::SetRenderedHelper( CDmeParticleFunction *pOp )
{
if ( !pOp )
{
InvalidateUniqueId( &m_RenderHelperId );
}
else
{
CopyUniqueId( pOp->GetId(), &m_RenderHelperId );
}
}
static bool IsValidHierarchy( CParticleCollection *pCollection )
{
if ( !pCollection->IsValid() )
return false;
for( CParticleCollection *pChild = pCollection->m_Children.m_pHead; pChild; pChild = pChild->m_pNext )
{
if ( !IsValidHierarchy( pChild ) )
return false;
}
return true;
}
//-----------------------------------------------------------------------------
// Simulate the particle system
//-----------------------------------------------------------------------------
void CParticleSystemPanel::OnTick()
{
BaseClass::OnTick();
if ( !m_pParticleSystem )
return;
float flTime = Plat_FloatTime();
if ( m_flLastTime == FLT_MAX )
{
m_flLastTime = flTime;
}
float flDt = flTime - m_flLastTime;
m_flLastTime = flTime;
for ( int i = 0; i < MAX_PARTICLE_CONTROL_POINTS; ++i )
{
if ( !m_pParticleSystem->ReadsControlPoint( i ) )
continue;
m_pParticleSystem->SetControlPoint( i, m_pControlPointValue[i] );
m_pParticleSystem->SetControlPointOrientation( i, Vector( 1, 0, 0 ), Vector( 0, -1, 0 ), Vector( 0, 0, 1 ) );
m_pParticleSystem->SetControlPointParent( i, i );
}
// Restart the particle system if it's finished
bool bIsInvalid = !IsValidHierarchy( m_pParticleSystem );
if ( !bIsInvalid )
{
m_pParticleSystem->Simulate( flDt, false );
}
if ( m_pParticleSystem->IsFinished() || bIsInvalid )
{
delete m_pParticleSystem;
m_pParticleSystem = NULL;
if ( m_bPerformNameBasedLookup )
{
if ( m_ParticleSystemName.Length() )
{
CParticleCollection *pNewParticleSystem = g_pParticleSystemMgr->CreateParticleCollection( m_ParticleSystemName );
m_pParticleSystem = pNewParticleSystem;
}
}
else
{
if ( IsUniqueIdValid( m_ParticleSystemId ) )
{
CParticleCollection *pNewParticleSystem = g_pParticleSystemMgr->CreateParticleCollection( m_ParticleSystemId );
m_pParticleSystem = pNewParticleSystem;
}
}
if ( bIsInvalid )
{
PostActionSignal( new KeyValues( "ParticleSystemReconstructed" ) );
}
m_flLastTime = FLT_MAX;
}
}
//-----------------------------------------------------------------------------
// Startup, shutdown particle collection
//-----------------------------------------------------------------------------
void CParticleSystemPanel::StartupParticleCollection()
{
if ( m_pParticleSystem )
{
vgui::ivgui()->AddTickSignal( GetVPanel(), 0 );
}
m_flLastTime = FLT_MAX;
}
void CParticleSystemPanel::ShutdownParticleCollection()
{
if ( m_pParticleSystem )
{
vgui::ivgui()->RemoveTickSignal( GetVPanel() );
delete m_pParticleSystem;
m_pParticleSystem = NULL;
}
}
//-----------------------------------------------------------------------------
// Set the particle system to draw
//-----------------------------------------------------------------------------
void CParticleSystemPanel::SetParticleSystem( CDmeParticleSystemDefinition *pDef )
{
ShutdownParticleCollection();
if ( pDef )
{
m_bPerformNameBasedLookup = pDef->UseNameBasedLookup();
if ( m_bPerformNameBasedLookup )
{
m_ParticleSystemName = pDef->GetName();
Assert( g_pParticleSystemMgr->IsParticleSystemDefined( m_ParticleSystemName ) );
m_pParticleSystem = g_pParticleSystemMgr->CreateParticleCollection( m_ParticleSystemName );
}
else
{
CopyUniqueId( pDef->GetId(), &m_ParticleSystemId );
Assert( g_pParticleSystemMgr->IsParticleSystemDefined( m_ParticleSystemId ) );
m_pParticleSystem = g_pParticleSystemMgr->CreateParticleCollection( m_ParticleSystemId );
}
PostActionSignal( new KeyValues( "ParticleSystemReconstructed" ) );
}
StartupParticleCollection();
}
void CParticleSystemPanel::SetDmeElement( CDmeParticleSystemDefinition *pDef )
{
SetParticleSystem( pDef );
}
CParticleCollection *CParticleSystemPanel::GetParticleSystem()
{
return m_pParticleSystem;
}
//-----------------------------------------------------------------------------
// Draw bounds
//-----------------------------------------------------------------------------
void CParticleSystemPanel::DrawBounds()
{
Vector vecMins, vecMaxs;
m_pParticleSystem->GetBounds( &vecMins, &vecMaxs );
RenderWireframeBox( vec3_origin, vec3_angle, vecMins, vecMaxs, Color( 0, 255, 255, 255 ), true );
}
//-----------------------------------------------------------------------------
// Draw cull bounds
//-----------------------------------------------------------------------------
void CParticleSystemPanel::DrawCullBounds()
{
Vector vecCenter;
m_pParticleSystem->GetControlPointAtTime( m_pParticleSystem->m_pDef->GetCullControlPoint(), m_pParticleSystem->m_flCurTime, &vecCenter );
RenderWireframeSphere( vecCenter, m_pParticleSystem->m_pDef->GetCullRadius(), 32, 16, Color( 0, 255, 255, 255 ), true );
}
//-----------------------------------------------------------------------------
// paint it!
//-----------------------------------------------------------------------------
#define AXIS_SIZE 5.0f
void CParticleSystemPanel::OnPaint3D()
{
if ( !m_pParticleSystem )
return;
// This needs calling to reset various counters.
g_pParticleSystemMgr->SetLastSimulationTime( m_pParticleSystem->m_flCurTime );
CMatRenderContextPtr pRenderContext( MaterialSystem() );
pRenderContext->BindLightmapTexture( m_pLightmapTexture );
pRenderContext->BindLocalCubemap( m_DefaultEnvCubemap );
// Draw axes
pRenderContext->MatrixMode( MATERIAL_MODEL );
pRenderContext->PushMatrix();
pRenderContext->LoadIdentity( );
if ( m_bRenderBounds )
{
DrawBounds();
Vector vP1;
Vector vP2;
m_pParticleSystem->GetControlPointAtTime( 0, m_pParticleSystem->m_flCurTime, &vP1 );
m_pParticleSystem->GetControlPointAtTime( 1, m_pParticleSystem->m_flCurTime, &vP2 );
RenderLine( vP1, vP2, Color( 0, 255, 255, 255 ), true );
}
if ( m_bRenderCullBounds )
{
DrawCullBounds();
}
if ( m_bRenderHelpers && IsUniqueIdValid( m_RenderHelperId ) )
{
m_pParticleSystem->VisualizeOperator( &m_RenderHelperId );
}
m_pParticleSystem->Render( pRenderContext );
m_pParticleSystem->VisualizeOperator( );
RenderAxes( vec3_origin, AXIS_SIZE, true );
pRenderContext->MatrixMode( MATERIAL_MODEL );
pRenderContext->PopMatrix();
}
//-----------------------------------------------------------------------------
//
// Control point page
//
//-----------------------------------------------------------------------------
class CControlPointPage : public vgui::PropertyPage
{
DECLARE_CLASS_SIMPLE( CControlPointPage, vgui::PropertyPage );
public:
// constructor, destructor
CControlPointPage( vgui::Panel *pParent, const char *pName, CParticleSystemPanel *pParticleSystemPanel );
virtual void PerformLayout();
void CreateControlPointControls( );
private:
MESSAGE_FUNC_PARAMS( OnTextChanged, "TextChanged", params );
MESSAGE_FUNC_PARAMS( OnNewLine, "TextNewLine", params );
void LayoutControlPointControls();
void CleanUpControlPointControls();
vgui::Label *m_pControlPointName[MAX_PARTICLE_CONTROL_POINTS];
vgui::TextEntry *m_pControlPointValue[MAX_PARTICLE_CONTROL_POINTS];
CParticleSystemPanel *m_pParticleSystemPanel;
};
//-----------------------------------------------------------------------------
// Contstructor
//-----------------------------------------------------------------------------
CControlPointPage::CControlPointPage( vgui::Panel *pParent, const char *pName, CParticleSystemPanel *pParticleSystemPanel ) :
BaseClass( pParent, pName )
{
for ( int i = 0; i < MAX_PARTICLE_CONTROL_POINTS; ++i )
{
m_pControlPointName[i] = NULL;
m_pControlPointValue[i] = NULL;
}
m_pParticleSystemPanel = pParticleSystemPanel;
}
//-----------------------------------------------------------------------------
// Called when the text entry for a control point is changed
//-----------------------------------------------------------------------------
void CControlPointPage::OnTextChanged( KeyValues *pParams )
{
vgui::Panel *pPanel = (vgui::Panel *)pParams->GetPtr( "panel" );
for ( int i = 0; i < MAX_PARTICLE_CONTROL_POINTS; ++i )
{
if ( pPanel != m_pControlPointValue[i] )
continue;
char pBuf[512];
m_pControlPointValue[i]->GetText( pBuf, sizeof(pBuf) );
Vector vecValue( 0, 0, 0 );
sscanf( pBuf, "%f %f %f", &vecValue.x, &vecValue.y, &vecValue.z );
m_pParticleSystemPanel->SetControlPointValue( i, vecValue );
break;
}
}
//-----------------------------------------------------------------------------
// Called when the text entry for a control point is changed
//-----------------------------------------------------------------------------
void CControlPointPage::OnNewLine( KeyValues *pParams )
{
vgui::Panel *pPanel = (vgui::Panel *)pParams->GetPtr( "panel" );
for ( int i = 0; i < MAX_PARTICLE_CONTROL_POINTS; ++i )
{
if ( pPanel != m_pControlPointValue[i] )
continue;
char pBuf[512];
m_pControlPointValue[i]->GetText( pBuf, sizeof(pBuf) );
Vector vecValue( 0, 0, 0 );
sscanf( pBuf, "%f %f %f", &vecValue.x, &vecValue.y, &vecValue.z );
m_pParticleSystemPanel->SetControlPointValue( i, vecValue );
vecValue = m_pParticleSystemPanel->GetControlPointValue( i );
Q_snprintf( pBuf, sizeof(pBuf), "%.3f %.3f %.3f", vecValue.x, vecValue.y, vecValue.z );
m_pControlPointValue[i]->SetText( pBuf );
break;
}
}
//-----------------------------------------------------------------------------
// Called when the particle system changes
//-----------------------------------------------------------------------------
void CControlPointPage::PerformLayout()
{
BaseClass::PerformLayout();
LayoutControlPointControls();
}
//-----------------------------------------------------------------------------
// Creates controls used to modify control point values
//-----------------------------------------------------------------------------
void CControlPointPage::CreateControlPointControls()
{
CleanUpControlPointControls();
CParticleCollection* pParticleSystem = m_pParticleSystemPanel->GetParticleSystem();
if ( !pParticleSystem )
return;
for ( int i = 0; i < MAX_PARTICLE_CONTROL_POINTS; ++i )
{
if ( !pParticleSystem->ReadsControlPoint( i ) )
continue;
char pName[512];
Q_snprintf( pName, sizeof(pName), "Pt #%d:", i );
m_pControlPointName[i] = new Label( this, pName, pName );
Q_snprintf( pName, sizeof(pName), "Entry #%d:", i );
m_pControlPointValue[i] = new TextEntry( this, pName );
m_pControlPointValue[i]->AddActionSignalTarget( this );
m_pControlPointValue[i]->SendNewLine( true );
m_pControlPointValue[i]->SetMultiline( false );
const Vector &vecValue = m_pParticleSystemPanel->GetControlPointValue( i );
Q_snprintf( pName, sizeof(pName), "%.3f %.3f %.3f", vecValue.x, vecValue.y, vecValue.z );
m_pControlPointValue[i]->SetText( pName );
}
LayoutControlPointControls();
}
//-----------------------------------------------------------------------------
// Lays out the controls
//-----------------------------------------------------------------------------
void CControlPointPage::LayoutControlPointControls()
{
int nFoundControlCount = 0;
for ( int i = 0; i < MAX_PARTICLE_CONTROL_POINTS; ++i )
{
if ( !m_pControlPointName[i] )
continue;
int yVal = 8 + nFoundControlCount * 28;
m_pControlPointName[i]->SetBounds( 8, yVal, 48, 24 );
m_pControlPointValue[i]->SetBounds( 64, yVal, 160, 24 );
++nFoundControlCount;
}
}
//-----------------------------------------------------------------------------
// Cleans up controls used to modify control point values
//-----------------------------------------------------------------------------
void CControlPointPage::CleanUpControlPointControls( )
{
for ( int i = 0; i < MAX_PARTICLE_CONTROL_POINTS; ++i )
{
if ( m_pControlPointName[i] )
{
delete m_pControlPointName[i];
m_pControlPointName[i] = NULL;
}
if ( m_pControlPointValue[i] )
{
delete m_pControlPointValue[i];
m_pControlPointValue[i] = NULL;
}
}
}
//-----------------------------------------------------------------------------
//
// CParticleSystemPreviewPanel
//
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Dme panel connection
//-----------------------------------------------------------------------------
IMPLEMENT_DMEPANEL_FACTORY( CParticleSystemPreviewPanel, DmeParticleSystemDefinition, "DmeParticleSystemDefinitionViewer", "Particle System Viewer", false );
//-----------------------------------------------------------------------------
// constructor, destructor
//-----------------------------------------------------------------------------
CParticleSystemPreviewPanel::CParticleSystemPreviewPanel( vgui::Panel *pParent, const char *pName ) :
BaseClass( pParent, pName )
{
m_Splitter = new vgui::Splitter( this, "Splitter", SPLITTER_MODE_VERTICAL, 1 );
vgui::Panel *pSplitterLeftSide = m_Splitter->GetChild( 0 );
vgui::Panel *pSplitterRightSide = m_Splitter->GetChild( 1 );
m_pParticleSystemPanel = new CParticleSystemPanel( pSplitterRightSide, "ParticlePreview" );
m_pParticleSystemPanel->AddActionSignalTarget( this );
m_pParticleSystemPanel->SetBackgroundColor( 0, 0, 0 );
m_pParticleCount = new vgui::Label( pSplitterRightSide, "ParticleCountLabel", "" );
m_pParticleCount->SetZPos( 1 );
m_pControlSheet = new vgui::PropertySheet( pSplitterLeftSide, "ControlSheet" );
m_pRenderPage = new vgui::PropertyPage( m_pControlSheet, "RenderPage" );
m_pRenderBounds = new vgui::CheckButton( m_pRenderPage, "RenderBounds", "Render Bounding Box" );
m_pRenderBounds->AddActionSignalTarget( this );
m_pRenderCullBounds = new vgui::CheckButton( m_pRenderPage, "RenderCullBounds", "Render Culling Bounds" );
m_pRenderCullBounds->AddActionSignalTarget( this );
m_pRenderHelpers = new vgui::CheckButton( m_pRenderPage, "RenderHelpers", "Render Helpers" );
m_pRenderHelpers->AddActionSignalTarget( this );
m_pBackgroundColor = new CColorPickerButton( m_pRenderPage, "BackgroundColor", this );
m_pBackgroundColor->SetColor( m_pParticleSystemPanel->GetBackgroundColor() );
m_pRenderPage->LoadControlSettingsAndUserConfig( "resource/particlesystempreviewpanel_renderpage.res" );
m_pControlPointPage = new CControlPointPage( m_pControlSheet, "ControlPointPage", m_pParticleSystemPanel );
// Load layout settings; has to happen before pinning occurs in code
LoadControlSettingsAndUserConfig( "resource/particlesystempreviewpanel.res" );
// NOTE: Page adding happens *after* LoadControlSettingsAndUserConfig
// because the layout of the sheet is correct at this point.
m_pControlSheet->AddPage( m_pRenderPage, "Render" );
m_pControlSheet->AddPage( m_pControlPointPage, "Ctrl Pts" );
}
CParticleSystemPreviewPanel::~CParticleSystemPreviewPanel()
{
}
//-----------------------------------------------------------------------------
// Set the particle system to draw
//-----------------------------------------------------------------------------
void CParticleSystemPreviewPanel::OnThink()
{
BaseClass::OnThink();
CParticleCollection* pParticleSystem = m_pParticleSystemPanel->GetParticleSystem();
if ( !pParticleSystem )
{
m_pParticleCount->SetText( "" );
}
else
{
char buf[256];
Q_snprintf( buf, sizeof(buf), "Particle Count: %5d/%5d",
pParticleSystem->m_nActiveParticles, pParticleSystem->m_nAllocatedParticles );
m_pParticleCount->SetText( buf );
}
}
//-----------------------------------------------------------------------------
// Called when the particle system changes
//-----------------------------------------------------------------------------
void CParticleSystemPreviewPanel::OnParticleSystemReconstructed()
{
m_pControlPointPage->CreateControlPointControls();
}
//-----------------------------------------------------------------------------
// Set the particle system to draw
//-----------------------------------------------------------------------------
void CParticleSystemPreviewPanel::SetParticleSystem( CDmeParticleSystemDefinition *pDef )
{
m_pParticleSystemPanel->SetParticleSystem( pDef );
}
void CParticleSystemPreviewPanel::SetDmeElement( CDmeParticleSystemDefinition *pDef )
{
m_pParticleSystemPanel->SetDmeElement( pDef );
}
//-----------------------------------------------------------------------------
// Indicates which helper to draw
//-----------------------------------------------------------------------------
void CParticleSystemPreviewPanel::SetParticleFunction( CDmeParticleFunction *pFunction )
{
m_pParticleSystemPanel->SetRenderedHelper( pFunction );
}
//-----------------------------------------------------------------------------
// Called when the check button is checked
//-----------------------------------------------------------------------------
void CParticleSystemPreviewPanel::OnCheckButtonChecked( KeyValues *pParams )
{
int state = pParams->GetInt( "state", 0 );
vgui::Panel *pPanel = (vgui::Panel*)pParams->GetPtr( "panel" );
if ( pPanel == m_pRenderBounds )
{
m_pParticleSystemPanel->RenderBounds( state );
return;
}
if ( pPanel == m_pRenderCullBounds )
{
m_pParticleSystemPanel->RenderCullBounds( state );
return;
}
if ( pPanel == m_pRenderHelpers )
{
m_pParticleSystemPanel->RenderHelpers( state );
return;
}
}
//-----------------------------------------------------------------------------
// Called when a new background color is picked
//-----------------------------------------------------------------------------
void CParticleSystemPreviewPanel::OnBackgroundColorChanged( KeyValues *pParams )
{
m_pParticleSystemPanel->SetBackgroundColor( pParams->GetColor( "color" ) );
}
void CParticleSystemPreviewPanel::OnBackgroundColorPreview( KeyValues *pParams )
{
m_pParticleSystemPanel->SetBackgroundColor( pParams->GetColor( "color" ) );
}
void CParticleSystemPreviewPanel::OnBackgroundColorCancel( KeyValues *pParams )
{
m_pParticleSystemPanel->SetBackgroundColor( pParams->GetColor( "startingColor" ) );
}
File diff suppressed because it is too large Load Diff
+194
View File
@@ -0,0 +1,194 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Dialog allowing users to select presets from within a preset group
//
//===========================================================================//
#include "dme_controls/presetpicker.h"
#include "tier1/KeyValues.h"
#include "tier1/utlbuffer.h"
#include "vgui/IVGui.h"
#include "vgui_controls/button.h"
#include "vgui_controls/listpanel.h"
#include "vgui_controls/splitter.h"
#include "vgui_controls/messagebox.h"
#include "movieobjects/dmeanimationset.h"
#include "datamodel/dmelement.h"
#include "matsys_controls/picker.h"
#include "dme_controls/dmecontrols_utils.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
using namespace vgui;
static int __cdecl PresetNameSortFunc( vgui::ListPanel *pPanel, const vgui::ListPanelItem &item1, const vgui::ListPanelItem &item2 )
{
const char *string1 = item1.kv->GetString( "name" );
const char *string2 = item2.kv->GetString( "name" );
return Q_stricmp( string1, string2 );
}
CPresetPickerFrame::CPresetPickerFrame( vgui::Panel *pParent, const char *pTitle, bool bAllowMultiSelect ) :
BaseClass( pParent, "PresetPickerFrame" )
{
SetDeleteSelfOnClose( true );
m_pContextKeyValues = NULL;
m_pPresetList = new vgui::ListPanel( this, "PresetList" );
m_pPresetList->AddColumnHeader( 0, "name", "Preset Name", 52, 0 );
m_pPresetList->SetSelectIndividualCells( false );
m_pPresetList->SetMultiselectEnabled( bAllowMultiSelect );
m_pPresetList->SetEmptyListText( "No presets" );
m_pPresetList->AddActionSignalTarget( this );
m_pPresetList->SetSortFunc( 0, PresetNameSortFunc );
m_pPresetList->SetSortColumn( 0 );
m_pOpenButton = new vgui::Button( this, "OkButton", "#MessageBox_OK", this, "Ok" );
m_pCancelButton = new vgui::Button( this, "CancelButton", "#MessageBox_Cancel", this, "Cancel" );
SetBlockDragChaining( true );
LoadControlSettingsAndUserConfig( "resource/presetpicker.res" );
SetTitle( pTitle, false );
}
CPresetPickerFrame::~CPresetPickerFrame()
{
CleanUpMessage();
}
//-----------------------------------------------------------------------------
// Refreshes the list of presets
//-----------------------------------------------------------------------------
void CPresetPickerFrame::RefreshPresetList( CDmElement *pPresetGroup, bool bSelectAll )
{
m_pPresetList->RemoveAll();
const CDmrElementArray< CDmePreset > presets( pPresetGroup, "presets" );
if ( !presets.IsValid() )
return;
int nCount = presets.Count();
if ( nCount == 0 )
return;
for ( int i = 0; i < nCount; ++i )
{
CDmePreset *pPreset = presets[i];
const char *pName = pPreset->GetName();
if ( !pName || !pName[0] )
{
pName = "<no name>";
}
KeyValues *kv = new KeyValues( "node" );
kv->SetString( "name", pName );
SetElementKeyValue( kv, "preset", pPreset );
int nItemID = m_pPresetList->AddItem( kv, 0, false, false );
if ( bSelectAll )
{
m_pPresetList->AddSelectedItem( nItemID );
}
}
m_pPresetList->SortList();
}
//-----------------------------------------------------------------------------
// Deletes the message
//-----------------------------------------------------------------------------
void CPresetPickerFrame::CleanUpMessage()
{
if ( m_pContextKeyValues )
{
m_pContextKeyValues->deleteThis();
m_pContextKeyValues = NULL;
}
}
//-----------------------------------------------------------------------------
// Sets the current scene + animation list
//-----------------------------------------------------------------------------
void CPresetPickerFrame::DoModal( CDmElement *pPresetGroup, bool bSelectAll, KeyValues *pContextKeyValues )
{
CleanUpMessage();
RefreshPresetList( pPresetGroup, bSelectAll );
m_pContextKeyValues = pContextKeyValues;
BaseClass::DoModal();
}
//-----------------------------------------------------------------------------
// On command
//-----------------------------------------------------------------------------
void CPresetPickerFrame::OnCommand( const char *pCommand )
{
if ( !Q_stricmp( pCommand, "Ok" ) )
{
int nSelectedItemCount = m_pPresetList->GetSelectedItemsCount();
if ( nSelectedItemCount == 0 )
return;
KeyValues *pActionKeys = new KeyValues( "PresetPicked" );
if ( m_pPresetList->IsMultiselectEnabled() )
{
pActionKeys->SetInt( "count", nSelectedItemCount );
// Adds them in selection order
for ( int i = 0; i < nSelectedItemCount; ++i )
{
char pBuf[32];
Q_snprintf( pBuf, sizeof(pBuf), "%d", i );
int nItemID = m_pPresetList->GetSelectedItem( i );
KeyValues *pKeyValues = m_pPresetList->GetItem( nItemID );
CDmePreset *pPreset = GetElementKeyValue<CDmePreset>( pKeyValues, "preset" );
SetElementKeyValue( pActionKeys, pBuf, pPreset );
}
}
else
{
int nItemID = m_pPresetList->GetSelectedItem( 0 );
KeyValues *pKeyValues = m_pPresetList->GetItem( nItemID );
CDmePreset *pPreset = GetElementKeyValue<CDmePreset>( pKeyValues, "preset" );
SetElementKeyValue( pActionKeys, "preset", pPreset );
}
if ( m_pContextKeyValues )
{
pActionKeys->AddSubKey( m_pContextKeyValues );
// This prevents them from being deleted later
m_pContextKeyValues = NULL;
}
PostActionSignal( pActionKeys );
CloseModal();
return;
}
if ( !Q_stricmp( pCommand, "Cancel" ) )
{
KeyValues *pActionKeys = new KeyValues( "PresetPickCancelled" );
if ( m_pContextKeyValues )
{
pActionKeys->AddSubKey( m_pContextKeyValues );
// This prevents them from being deleted later
m_pContextKeyValues = NULL;
}
PostActionSignal( pActionKeys );
CloseModal();
return;
}
BaseClass::OnCommand( pCommand );
}
+602
View File
@@ -0,0 +1,602 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================
#include <windows.h>
#undef PropertySheet
#include "filesystem.h"
#include "dme_controls/soundpicker.h"
#include "tier1/KeyValues.h"
#include "vgui_controls/ListPanel.h"
#include "vgui_controls/Button.h"
#include "vgui_controls/PropertySheet.h"
#include "vgui_controls/PropertyPage.h"
#include "dme_controls/filtercombobox.h"
#include "vgui/ISurface.h"
#include "vgui/iinput.h"
#include "dme_controls/dmecontrols.h"
#include "soundemittersystem/isoundemittersystembase.h"
#include "mathlib/mathlib.h"
// FIXME: Move sound code out of the engine + into a library!
#include "toolframework/ienginetool.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
//
// Sound Picker
//
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Sort by sound name
//-----------------------------------------------------------------------------
static int __cdecl GameSoundSortFunc( vgui::ListPanel *pPanel, const ListPanelItem &item1, const ListPanelItem &item2 )
{
bool bRoot1 = item1.kv->GetInt("root") != 0;
bool bRoot2 = item2.kv->GetInt("root") != 0;
if ( bRoot1 != bRoot2 )
return bRoot1 ? -1 : 1;
const char *string1 = item1.kv->GetString("gamesound");
const char *string2 = item2.kv->GetString("gamesound");
return Q_stricmp( string1, string2 );
}
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CSoundPicker::CSoundPicker( vgui::Panel *pParent, int nFlags ) :
BaseClass( pParent, "Sound Files", "wav", "sound", "wavName" )
{
m_nSoundSuppressionCount = 0;
m_nPlayingSound = 0;
// Connection problem if this failed
Assert( SoundEmitterSystem() );
m_pViewsSheet = new vgui::PropertySheet( this, "ViewsSheet" );
m_pViewsSheet->AddActionSignalTarget( this );
// game sounds
m_pGameSoundPage = NULL;
m_pGameSoundList = NULL;
if ( nFlags & PICK_GAMESOUNDS )
{
m_pGameSoundPage = new PropertyPage( m_pViewsSheet, "GameSoundPage" );
m_pGameSoundList = new ListPanel( m_pGameSoundPage, "GameSoundsList" );
m_pGameSoundList->AddColumnHeader( 0, "GameSound", "Game Sound", 52, 0 );
m_pGameSoundList->AddActionSignalTarget( this );
m_pGameSoundList->SetSelectIndividualCells( true );
m_pGameSoundList->SetEmptyListText("No game sounds");
m_pGameSoundList->SetDragEnabled( true );
m_pGameSoundList->SetAutoResize( Panel::PIN_TOPLEFT, Panel::AUTORESIZE_DOWNANDRIGHT, 0, 0, 0, 0 );
m_pGameSoundList->SetSortFunc( 0, GameSoundSortFunc );
m_pGameSoundList->SetSortColumn( 0 );
m_pGameSoundList->SetMultiselectEnabled( ( nFlags & ALLOW_MULTISELECT ) != 0 );
// filter selection
m_pGameSoundFilter = new TextEntry( m_pGameSoundPage, "GameSoundFilter" );
m_pGameSoundFilter->AddActionSignalTarget( this );
m_pGameSoundPage->LoadControlSettings( "resource/soundpickergamesoundpage.res" );
m_pViewsSheet->AddPage( m_pGameSoundPage, "Game Sounds" );
}
// wav files
m_pWavPage = NULL;
if ( nFlags & PICK_WAVFILES )
{
m_pWavPage = new PropertyPage( m_pViewsSheet, "WavPage" );
bool bAllowMultiselect = ( nFlags & ALLOW_MULTISELECT ) != 0;
CreateStandardControls( m_pWavPage, bAllowMultiselect );
AddExtension( "mp3" );
m_pWavPage->LoadControlSettings( "resource/soundpickerwavpage.res" );
m_pViewsSheet->AddPage( m_pWavPage, "WAVs" );
}
LoadControlSettings( "resource/soundpicker.res" );
}
//-----------------------------------------------------------------------------
// Purpose: Destructor
//-----------------------------------------------------------------------------
CSoundPicker::~CSoundPicker()
{
StopSoundPreview();
}
//-----------------------------------------------------------------------------
// Purpose: called to open
//-----------------------------------------------------------------------------
void CSoundPicker::Activate()
{
BaseClass::Activate();
if ( m_pGameSoundPage )
{
BuildGameSoundList();
}
}
//-----------------------------------------------------------------------------
// Sets the current sound choice
//-----------------------------------------------------------------------------
void CSoundPicker::SetSelectedSound( PickType_t type, const char *pSoundName )
{
if ( type == PICK_NONE || !pSoundName )
return;
if ( m_pGameSoundPage && ( type == PICK_GAMESOUNDS ) )
{
m_pViewsSheet->SetActivePage( m_pGameSoundPage );
m_pGameSoundFilter->SetText( pSoundName );
}
if ( m_pWavPage && ( type == PICK_WAVFILES ) )
{
m_pViewsSheet->SetActivePage( m_pWavPage );
SetInitialSelection( pSoundName );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CSoundPicker::OnKeyCodePressed( KeyCode code )
{
if ( m_pGameSoundPage && ( m_pViewsSheet->GetActivePage() == m_pGameSoundPage ) )
{
if (( code == KEY_UP ) || ( code == KEY_DOWN ) || ( code == KEY_PAGEUP ) || ( code == KEY_PAGEDOWN ))
{
KeyValues *pMsg = new KeyValues( "KeyCodePressed", "code", code );
vgui::ipanel()->SendMessage( m_pGameSoundList->GetVPanel(), pMsg, GetVPanel() );
pMsg->deleteThis();
return;
}
}
BaseClass::OnKeyCodePressed( code );
}
//-----------------------------------------------------------------------------
// Purpose: builds the gamesound list
//-----------------------------------------------------------------------------
bool CSoundPicker::IsGameSoundVisible( int hGameSound )
{
const char *pSoundName = SoundEmitterSystem()->GetSoundName( hGameSound );
return ( !m_GameSoundFilter.Length() || Q_stristr( pSoundName, m_GameSoundFilter.Get() ) );
}
//-----------------------------------------------------------------------------
// Updates the column header in the chooser
//-----------------------------------------------------------------------------
void CSoundPicker::UpdateGameSoundColumnHeader( int nMatchCount, int nTotalCount )
{
char pColumnTitle[512];
Q_snprintf( pColumnTitle, sizeof(pColumnTitle), "%s (%d/%d)",
"Game Sound", nMatchCount, nTotalCount );
m_pGameSoundList->SetColumnHeaderText( 0, pColumnTitle );
}
//-----------------------------------------------------------------------------
// Purpose: builds the gamesound list
//-----------------------------------------------------------------------------
void CSoundPicker::BuildGameSoundList()
{
if ( !m_pGameSoundList )
return;
m_pGameSoundList->RemoveAll();
int nTotalCount = 0;
int i = SoundEmitterSystem()->First();
while ( i != SoundEmitterSystem()->InvalidIndex() )
{
const char *pSoundName = SoundEmitterSystem()->GetSoundName( i );
bool bInRoot = !strchr( pSoundName, '\\' ) && !strchr( pSoundName, '/' );
KeyValues *kv = new KeyValues( "node", "gamesound", pSoundName );
kv->SetInt( "gameSoundHandle", i );
kv->SetInt( "root", bInRoot );
int nItemID = m_pGameSoundList->AddItem( kv, 0, false, false );
m_pGameSoundList->SetItemVisible( nItemID, IsGameSoundVisible( i ) );
KeyValues *pDrag = new KeyValues( "drag", "text", pSoundName );
pDrag->SetString( "texttype", "gamesoundName" );
m_pGameSoundList->SetItemDragData( nItemID, pDrag );
++nTotalCount;
i = SoundEmitterSystem()->Next( i );
}
m_pGameSoundList->SortList();
if ( m_pGameSoundList->GetItemCount() > 0 )
{
int nItemID = m_pGameSoundList->GetItemIDFromRow( 0 );
// This prevents the refreshing of the sound list from playing the sound
++m_nSoundSuppressionCount;
m_pGameSoundList->SetSelectedCell( nItemID, 0 );
}
UpdateGameSoundColumnHeader( nTotalCount, nTotalCount );
}
//-----------------------------------------------------------------------------
// Purpose: refreshes the gamesound list
//-----------------------------------------------------------------------------
void CSoundPicker::RefreshGameSoundList()
{
if ( !m_pGameSoundList )
return;
// Check the filter matches
int nMatchingGameSounds = 0;
int nTotalCount = 0;
for ( int nItemID = m_pGameSoundList->FirstItem(); nItemID != m_pGameSoundList->InvalidItemID(); nItemID = m_pGameSoundList->NextItem( nItemID ) )
{
KeyValues *kv = m_pGameSoundList->GetItem( nItemID );
int hGameSound = kv->GetInt( "gameSoundHandle", SoundEmitterSystem()->InvalidIndex() );
if ( hGameSound == SoundEmitterSystem()->InvalidIndex() )
continue;
bool bIsVisible = IsGameSoundVisible( hGameSound );
m_pGameSoundList->SetItemVisible( nItemID, bIsVisible );
if ( bIsVisible )
{
++nMatchingGameSounds;
}
++nTotalCount;
}
UpdateGameSoundColumnHeader( nMatchingGameSounds, nTotalCount );
if ( ( m_pGameSoundList->GetSelectedItemsCount() == 0 ) && ( m_pGameSoundList->GetItemCount() > 0 ) )
{
int nItemID = m_pGameSoundList->GetItemIDFromRow( 0 );
// This prevents the refreshing of the sound list from playing the sound
++m_nSoundSuppressionCount;
m_pGameSoundList->SetSelectedCell( nItemID, 0 );
}
}
//-----------------------------------------------------------------------------
// Purpose: Update filter when text changes
//-----------------------------------------------------------------------------
void CSoundPicker::OnGameSoundFilterTextChanged( )
{
int nLength = m_pGameSoundFilter->GetTextLength();
m_GameSoundFilter.SetLength( nLength );
if ( nLength > 0 )
{
m_pGameSoundFilter->GetText( m_GameSoundFilter.GetForModify(), nLength+1 );
}
RefreshGameSoundList();
}
//-----------------------------------------------------------------------------
// Purpose: refreshes dialog on filter changing
//-----------------------------------------------------------------------------
void CSoundPicker::OnTextChanged( KeyValues *pKeyValues )
{
vgui::Panel *pSource = (vgui::Panel*)pKeyValues->GetPtr( "panel" );
if ( pSource == m_pGameSoundFilter )
{
OnGameSoundFilterTextChanged();
return;
}
BaseClass::OnTextChanged( pKeyValues );
}
//-----------------------------------------------------------------------------
// Purpose: Called when a page is shown
//-----------------------------------------------------------------------------
void CSoundPicker::RequestGameSoundFilterFocus( )
{
m_pGameSoundFilter->SelectAllOnFirstFocus( true );
m_pGameSoundFilter->RequestFocus();
}
//-----------------------------------------------------------------------------
// Purpose: Called when a page is shown
//-----------------------------------------------------------------------------
void CSoundPicker::OnPageChanged( )
{
StopSoundPreview();
if ( m_pGameSoundPage && ( m_pViewsSheet->GetActivePage() == m_pGameSoundPage ) )
{
RequestGameSoundFilterFocus();
}
if ( m_pWavPage && ( m_pViewsSheet->GetActivePage() == m_pWavPage ) )
{
RequestFilterFocus();
}
}
//-----------------------------------------------------------------------------
// Stop sound preview
//-----------------------------------------------------------------------------
void CSoundPicker::StopSoundPreview( )
{
if ( m_nPlayingSound != 0 )
{
EngineTool()->StopSoundByGuid( m_nPlayingSound );
m_nPlayingSound = 0;
}
}
//-----------------------------------------------------------------------------
// Plays a gamesound
//-----------------------------------------------------------------------------
void CSoundPicker::PlayGameSound( const char *pSoundName )
{
StopSoundPreview();
CSoundParameters params;
if ( SoundEmitterSystem()->GetParametersForSound( pSoundName, params, GENDER_NONE ) )
{
m_nPlayingSound = EngineTool()->StartSound( 0, true, -1, CHAN_STATIC, params.soundname,
params.volume, params.soundlevel, vec3_origin, vec3_origin, 0,
params.pitch, false, params.delay_msec / 1000.0f );
}
}
//-----------------------------------------------------------------------------
// Plays a wav file
//-----------------------------------------------------------------------------
void CSoundPicker::PlayWavSound( const char *pSoundName )
{
StopSoundPreview();
m_nPlayingSound = EngineTool()->StartSound( 0, true, -1, CHAN_STATIC, pSoundName,
VOL_NORM, SNDLVL_NONE, vec3_origin, vec3_origin, 0, PITCH_NORM, false, 0 );
}
//-----------------------------------------------------------------------------
// Don't play a sound when the next selection is a default selection
//-----------------------------------------------------------------------------
void CSoundPicker::OnNextSelectionIsDefault()
{
++m_nSoundSuppressionCount;
}
//-----------------------------------------------------------------------------
// Derived classes have this called when the previewed asset changes
//-----------------------------------------------------------------------------
void CSoundPicker::OnSelectedAssetPicked( const char *pAssetName )
{
bool bPlaySounds = true;
if ( m_nSoundSuppressionCount > 0 )
{
--m_nSoundSuppressionCount;
bPlaySounds = false;
}
if ( pAssetName && bPlaySounds )
{
PlayWavSound( pAssetName );
}
}
//-----------------------------------------------------------------------------
// Purpose: refreshes dialog on text changing
//-----------------------------------------------------------------------------
void CSoundPicker::OnItemSelected( KeyValues *kv )
{
Panel *pPanel = (Panel *)kv->GetPtr( "panel", NULL );
if ( m_pGameSoundList && (pPanel == m_pGameSoundList ) )
{
bool bPlaySounds = true;
if ( m_nSoundSuppressionCount > 0 )
{
--m_nSoundSuppressionCount;
bPlaySounds = false;
}
const char *pGameSoundName = GetSelectedSoundName();
if ( pGameSoundName && bPlaySounds )
{
int len = V_strlen( pGameSoundName );
char *soundname = ( char* )stackalloc( len + 2 );
soundname[ 0 ] = '#'; // mark sound to bypass the dsp
V_strncpy( soundname + 1, pGameSoundName, len + 1 );
PlayGameSound( soundname );
}
return;
}
BaseClass::OnItemSelected( kv );
}
//-----------------------------------------------------------------------------
// Gets the selected sound type
//-----------------------------------------------------------------------------
CSoundPicker::PickType_t CSoundPicker::GetSelectedSoundType( )
{
if ( m_pGameSoundPage && ( m_pViewsSheet->GetActivePage() == m_pGameSoundPage ) )
return PICK_GAMESOUNDS;
if ( m_pWavPage && ( m_pViewsSheet->GetActivePage() == m_pWavPage ) )
return PICK_WAVFILES;
return PICK_NONE;
}
//-----------------------------------------------------------------------------
// Returns the selected sound count
//-----------------------------------------------------------------------------
int CSoundPicker::GetSelectedSoundCount()
{
if ( m_pGameSoundPage && ( m_pViewsSheet->GetActivePage() == m_pGameSoundPage ) )
return m_pGameSoundList->GetSelectedItemsCount();
if ( m_pWavPage && ( m_pViewsSheet->GetActivePage() == m_pWavPage ) )
return GetSelectedAssetCount();
return 0;
}
//-----------------------------------------------------------------------------
// Returns the selected sound
//-----------------------------------------------------------------------------
const char *CSoundPicker::GetSelectedSoundName( int nSelectionIndex )
{
if ( m_pGameSoundPage && ( m_pViewsSheet->GetActivePage() == m_pGameSoundPage ) )
{
int nCount = m_pGameSoundList->GetSelectedItemsCount();
if ( nCount == 0 )
return NULL;
if ( nSelectionIndex < 0 )
{
nSelectionIndex = nCount - 1;
}
int nIndex = m_pGameSoundList->GetSelectedItem( nSelectionIndex );
if ( nIndex >= 0 )
{
KeyValues *pkv = m_pGameSoundList->GetItem( nIndex );
return pkv->GetString( "gamesound", NULL );
}
return NULL;
}
if ( m_pWavPage && ( m_pViewsSheet->GetActivePage() == m_pWavPage ) )
return GetSelectedAsset( nSelectionIndex );
return NULL;
}
//-----------------------------------------------------------------------------
//
// Purpose: Modal picker frame
//
//-----------------------------------------------------------------------------
CSoundPickerFrame::CSoundPickerFrame( vgui::Panel *pParent, const char *pTitle, int nFlags ) :
BaseClass( pParent )
{
SetAssetPicker( new CSoundPicker( this, nFlags ) );
LoadControlSettingsAndUserConfig( "resource/soundpickerframe.res" );
SetTitle( pTitle, false );
}
CSoundPickerFrame::~CSoundPickerFrame()
{
}
//-----------------------------------------------------------------------------
// Purpose: Activate the dialog
//-----------------------------------------------------------------------------
void CSoundPickerFrame::DoModal( CSoundPicker::PickType_t initialType, const char *pInitialValue, KeyValues *pContextKeyValues )
{
vgui::surface()->SetCursor( dc_hourglass );
CSoundPicker *pPicker = static_cast <CSoundPicker*>( GetAssetPicker() );
if ( initialType != CSoundPicker::PICK_NONE && pInitialValue )
{
pPicker->SetSelectedSound( initialType, pInitialValue );
}
BaseClass::DoModal( pContextKeyValues );
}
//-----------------------------------------------------------------------------
// On command
//-----------------------------------------------------------------------------
void CSoundPickerFrame::OnCommand( const char *pCommand )
{
CSoundPicker *pPicker = static_cast <CSoundPicker*>( GetAssetPicker() );
if ( !Q_stricmp( pCommand, "Open" ) )
{
CSoundPicker::PickType_t type = pPicker->GetSelectedSoundType( );
if (( type == CSoundPicker::PICK_GAMESOUNDS ) || ( type == CSoundPicker::PICK_WAVFILES ))
{
const char *pSoundName = pPicker->GetSelectedSoundName();
int len = V_strlen( pSoundName );
char *soundname = ( char* )stackalloc( len + 2 );
soundname[ 0 ] = '#'; // mark sound to bypass the dsp
V_strncpy( soundname + 1, pSoundName, len + 1 );
int nSoundCount = pPicker->GetSelectedSoundCount();
KeyValues *pActionKeys = new KeyValues( "SoundSelected" );
pActionKeys->SetInt( "count", nSoundCount );
KeyValues *pSoundList = NULL;
if ( type == CSoundPicker::PICK_GAMESOUNDS )
{
pActionKeys->SetString( "gamesound", soundname );
if ( pPicker->IsMultiselectEnabled() )
{
pSoundList = pActionKeys->FindKey( "gamesounds", true );
}
}
else
{
pActionKeys->SetString( "wav", soundname );
if ( pPicker->IsMultiselectEnabled() )
{
pSoundList = pActionKeys->FindKey( "wavs", true );
}
}
if ( pSoundList )
{
// Adds them in selection order
for ( int i = 0; i < nSoundCount; ++i )
{
char pBuf[32];
Q_snprintf( pBuf, sizeof(pBuf), "%d", i );
pSoundName = pPicker->GetSelectedSoundName( i );
len = V_strlen( pSoundName );
soundname = ( char* )malloc( len + 2 );
soundname[ 0 ] = '#'; // mark sound to bypass the dsp
V_strncpy( soundname + 1, pSoundName, len + 1 );
pSoundList->SetString( pBuf, soundname );
free( soundname );
}
}
PostMessageAndClose( pActionKeys );
CloseModal();
}
return;
}
BaseClass::OnCommand( pCommand );
}
+212
View File
@@ -0,0 +1,212 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================
#include "dme_controls/soundrecordpanel.h"
#include "filesystem.h"
#include "tier1/KeyValues.h"
#include "vgui_controls/Button.h"
#include "vgui_controls/TextEntry.h"
#include "dme_controls/dmecontrols.h"
#include "vgui_controls/messagebox.h"
#include "soundemittersystem/isoundemittersystembase.h"
#include "vgui/IVGui.h"
#include "mathlib/mathlib.h"
// FIXME: Move sound code out of the engine + into a library!
#include "toolframework/ienginetool.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
//
// Sound Record Dialog
//
//-----------------------------------------------------------------------------
CSoundRecordPanel::CSoundRecordPanel( vgui::Panel *pParent, const char *pTitle ) :
BaseClass( pParent, "SoundRecordPanel" )
{
m_bIsRecording = false;
m_nPlayingSound = 0;
SetDeleteSelfOnClose( true );
m_pOkButton = new Button( this, "OkButton", "#FileOpenDialog_Open", this, "Ok" );
m_pCancelButton = new Button( this, "CancelButton", "#FileOpenDialog_Cancel", this, "Cancel" );
m_pPlayButton = new Button( this, "PlayButton", "Play", this, "Play" );
m_pRecordButton = new Button( this, "Record", "Record", this, "ToggleRecord" );
m_pRecordTime = new TextEntry( this, "RecordTime" );
m_pFileName = new TextEntry( this, "FileName" );
LoadControlSettingsAndUserConfig( "resource/soundrecordpanel.res" );
SetTitle( pTitle, false );
}
CSoundRecordPanel::~CSoundRecordPanel()
{
StopSoundPreview();
}
//-----------------------------------------------------------------------------
// Purpose: Activate the dialog
//-----------------------------------------------------------------------------
void CSoundRecordPanel::DoModal( const char *pFileName )
{
Assert( EngineTool() );
char pRelativeWAVPath[MAX_PATH];
g_pFullFileSystem->FullPathToRelativePath( pFileName, pRelativeWAVPath, sizeof(pRelativeWAVPath) );
// Check to see if this file is not hidden owing to search paths
bool bBadDirectory = false;
char pRelativeDir[MAX_PATH];
Q_strncpy( pRelativeDir, pRelativeWAVPath, sizeof( pRelativeDir ) );
Q_StripFilename( pRelativeDir );
char pFoundFullPath[MAX_PATH];
g_pFullFileSystem->RelativePathToFullPath( pRelativeDir, "MOD", pFoundFullPath, sizeof( pFoundFullPath ) );
if ( StringHasPrefix( pFileName, pFoundFullPath ) )
{
// Strip 'sound/' prefix
m_FileName = pRelativeWAVPath;
const char *pSoundName = StringAfterPrefix( pRelativeWAVPath, "sound\\" );
if ( !pSoundName )
{
pSoundName = pRelativeWAVPath;
bBadDirectory = true;
}
m_EngineFileName = pSoundName;
}
else
{
bBadDirectory = true;
}
if ( bBadDirectory )
{
char pBuf[1024];
Q_snprintf( pBuf, sizeof(pBuf), "File %s is in a bad directory!\nAudio must be recorded into your mod's sound/ directory.\n", pFileName );
vgui::MessageBox *pMessageBox = new vgui::MessageBox( "Bad Save Directory!\n", pBuf, GetParent() );
pMessageBox->DoModal( );
return;
}
m_pFileName->SetText( pFileName );
m_pOkButton->SetEnabled( false );
m_pPlayButton->SetEnabled( false );
BaseClass::DoModal();
}
//-----------------------------------------------------------------------------
// Stop sound preview
//-----------------------------------------------------------------------------
void CSoundRecordPanel::StopSoundPreview( )
{
if ( m_nPlayingSound != 0 )
{
EngineTool()->StopSoundByGuid( m_nPlayingSound );
m_nPlayingSound = 0;
}
}
//-----------------------------------------------------------------------------
// Plays a wav file
//-----------------------------------------------------------------------------
void CSoundRecordPanel::PlaySoundPreview( )
{
StopSoundPreview();
m_nPlayingSound = EngineTool()->StartSound( 0, true, -1, CHAN_STATIC, m_EngineFileName,
VOL_NORM, SNDLVL_NONE, vec3_origin, vec3_origin, 0, PITCH_NORM, false, 0 );
}
//-----------------------------------------------------------------------------
// Updates sound record time during recording
//-----------------------------------------------------------------------------
void CSoundRecordPanel::UpdateTimeRecorded()
{
float flTime = Plat_FloatTime() - m_flRecordStartTime;
char pTimeBuf[64];
Q_snprintf( pTimeBuf, sizeof(pTimeBuf), "%.3f", flTime );
m_pRecordTime->SetText( pTimeBuf );
}
//-----------------------------------------------------------------------------
// Updates sound record time during recording
//-----------------------------------------------------------------------------
void CSoundRecordPanel::OnTick()
{
BaseClass::OnTick();
// Update the amount of time recorded
UpdateTimeRecorded();
}
//-----------------------------------------------------------------------------
// On command
//-----------------------------------------------------------------------------
void CSoundRecordPanel::OnCommand( const char *pCommand )
{
if ( !Q_stricmp( pCommand, "ToggleRecord" ) )
{
if ( !m_bIsRecording )
{
StopSoundPreview();
g_pFullFileSystem->RemoveFile( m_FileName, "MOD" );
EngineTool()->StartRecordingVoiceToFile( m_FileName, "MOD" );
m_pRecordButton->SetText( "Stop Recording" );
m_pPlayButton->SetEnabled( false );
m_pOkButton->SetEnabled( false );
m_pCancelButton->SetEnabled( true );
m_flRecordStartTime = Plat_FloatTime();
vgui::ivgui()->AddTickSignal( GetVPanel(), 0 );
}
else
{
EngineTool()->StopRecordingVoiceToFile();
EngineTool()->ReloadSound( m_EngineFileName );
ivgui()->RemoveTickSignal( GetVPanel() );
UpdateTimeRecorded();
m_pOkButton->SetEnabled( true );
m_pCancelButton->SetEnabled( true );
m_pPlayButton->SetEnabled( true );
m_pRecordButton->SetText( "Record" );
}
m_bIsRecording = !m_bIsRecording;
return;
}
if ( !Q_stricmp( pCommand, "Play" ) )
{
PlaySoundPreview();
return;
}
if ( !Q_stricmp( pCommand, "Ok" ) )
{
PostActionSignal( new KeyValues( "SoundRecorded", "relativepath", m_EngineFileName.Get() ) );
CloseModal();
return;
}
if ( !Q_stricmp( pCommand, "Cancel" ) )
{
g_pFullFileSystem->RemoveFile( m_FileName, "MOD" );
CloseModal();
return;
}
BaseClass::OnCommand( pCommand );
}