This commit is contained in:
nephacks
2025-06-04 03:22:50 +02:00
parent f234f23848
commit f12416cffd
14243 changed files with 6446499 additions and 26 deletions

View File

@@ -0,0 +1,770 @@
//======= Copyright © 1996-2008, Valve Corporation, All rights reserved. ======
//
// Purpose: A 2D Slider
//
//=============================================================================
// Valve includes
#include <KeyValues.h>
#include <vgui/MouseCode.h>
#include <vgui/IBorder.h>
#include <vgui/IInput.h>
#include <vgui/ISystem.h>
#include <vgui/IScheme.h>
#include <vgui/ISurface.h>
#include <vgui/ILocalize.h>
#include <vgui_controls/Controls.h>
#include <vgui_controls/TextImage.h>
#include <dme_controls/2DSlider.h>
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
using namespace vgui;
//-----------------------------------------------------------------------------
// Statics
//-----------------------------------------------------------------------------
Color C2DSlider::s_TextColor( 208, 143, 40, 192 );
Color C2DSlider::s_NobColor( 0, 63, 98, 255 );
Color C2DSlider::s_TickColor( 0, 79, 182, 255 );
Color C2DSlider::s_TickFillXColor( 0, 63, 0, 255 );
Color C2DSlider::s_TickFillYColor( 0, 0, 98, 255 );
Color C2DSlider::s_TickFillColor( 0, 63, 98, 255 );
Color C2DSlider::s_TrackColor( 31, 31, 31, 255 );
//-----------------------------------------------------------------------------
// Purpose: Create a slider bar with ticks underneath it
//-----------------------------------------------------------------------------
C2DSlider::C2DSlider( Panel *pParent, const char *pName )
: BaseClass( pParent, pName )
{
m_bDrawLabel = true;
m_bIsDragOnRepositionNob = true;
m_bDragging = false;
m_fValue[ kXAxis ] = 0.0f;
m_fValue[ kYAxis ] = 0.0f;
m_fRange[ kXAxis ][ 0 ] = 0.0f;
m_fRange[ kXAxis ][ 1 ] = 1.0f;
m_fRange[ kYAxis ][ 0 ] = 1.0f;
m_fRange[ kYAxis ][ 1 ] = 0.0f;
m_pNobBorder = NULL;
m_pInsetBorder = NULL;
SetNobSize( 7, 7 );
RecomputeNobPosFromValue();
AddActionSignalTarget( this );
SetBlockDragChaining( true );
m_pLabel = new TextImage( pName );
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
C2DSlider::~C2DSlider()
{
delete m_pLabel;
}
//-----------------------------------------------------------------------------
// Purpose: Set the value of the slider
//-----------------------------------------------------------------------------
void C2DSlider::SetValueX( float fValueX, bool bTriggerChangeMessage /* = true */ )
{
SetValue( fValueX, GetValueY(), bTriggerChangeMessage );
}
//-----------------------------------------------------------------------------
// Purpose: Set the value of the slider
//-----------------------------------------------------------------------------
float C2DSlider::GetValueX() const
{
return m_fValue[ kXAxis ];
}
//-----------------------------------------------------------------------------
// Purpose: Set the value of the slider
//-----------------------------------------------------------------------------
void C2DSlider::SetValueY( float fValueY, bool bTriggerChangeMessage /* = true */ )
{
SetValue( GetValueX(), fValueY, bTriggerChangeMessage );
}
//-----------------------------------------------------------------------------
// Purpose: Set the value of the slider to one of the ticks.
//-----------------------------------------------------------------------------
float C2DSlider::GetValueY() const
{
return m_fValue[ kYAxis ];
}
//-----------------------------------------------------------------------------
// Purpose: Set the value of the slider to one of the ticks.
//-----------------------------------------------------------------------------
void C2DSlider::SetValue( float fValueX, float fValueY, bool bTriggerChangeMessage )
{
fValueX = RemapValClamped( fValueX, m_fRange[ kXAxis ][ 0 ], m_fRange[ kXAxis ][ 1 ], m_fRange[ kXAxis ][ 0 ], m_fRange[ kXAxis ][ 1 ] );
fValueY = RemapValClamped( fValueY, m_fRange[ kYAxis ][ 0 ], m_fRange[ kYAxis ][ 1 ], m_fRange[ kYAxis ][ 0 ], m_fRange[ kYAxis ][ 1 ] );
if ( fValueX != m_fValue[ kXAxis ] || fValueY != m_fValue[ kYAxis ] )
{
m_fValue[ kXAxis ] = fValueX;
m_fValue[ kYAxis ] = fValueY;
RecomputeNobPosFromValue();
if ( bTriggerChangeMessage )
{
SendSliderMovedMessage();
}
}
}
//-----------------------------------------------------------------------------
// Purpose: Return the value of the slider
//-----------------------------------------------------------------------------
void C2DSlider::GetValue( float &fValueX, float &fValueY ) const
{
fValueX = GetValueX();
fValueY = GetValueY();
}
//-----------------------------------------------------------------------------
// Purpose: Set the range of the slider.
//-----------------------------------------------------------------------------
void C2DSlider::SetRange( float fMinX, float fMaxX, float fMinY, float fMaxY, bool bTriggerChangeMessage /* = true */ )
{
m_fRange[ kXAxis ][ 0 ] = fMinX;
m_fRange[ kXAxis ][ 1 ] = fMaxX;
m_fRange[ kYAxis ][ 0 ] = fMinY;
m_fRange[ kYAxis ][ 1 ] = fMaxY;
SetValue( m_fValue[ kXAxis ], m_fValue[ kYAxis ], bTriggerChangeMessage );
}
//-----------------------------------------------------------------------------
// Purpose: Get the max and min values of the slider
//-----------------------------------------------------------------------------
void C2DSlider::GetRange( float &fMinX, float &fMaxX, float &fMinY, float &fMaxY ) const
{
fMinX = m_fRange[ kXAxis ][ 0 ];
fMaxX = m_fRange[ kXAxis ][ 1 ];
fMinY = m_fRange[ kYAxis ][ 0 ];
fMaxY = m_fRange[ kYAxis ][ 1 ];
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void C2DSlider::SetLabelText( const char *pText )
{
m_pLabel->SetText( pText );
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void C2DSlider::SetLabelText( const wchar_t *pText )
{
m_pLabel->SetText( pText );
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void C2DSlider::GetLabelText( wchar_t *pBuffer, int nBufferLen ) const
{
m_pLabel->GetText( pBuffer, nBufferLen );
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void C2DSlider::GetLabelUnlocalizedText( char *pBuffer, int nBufferLen ) const
{
m_pLabel->GetUnlocalizedText( pBuffer, nBufferLen );
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void C2DSlider::SetDrawLabel( bool bState )
{
m_bDrawLabel = bState;
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
bool C2DSlider::IsDrawingLabel() const
{
return m_bDrawLabel;
}
//-----------------------------------------------------------------------------
// Purpose: Get the nob's position ( the ends of each side of the nob )
//-----------------------------------------------------------------------------
void C2DSlider::GetNobPos( int &nX, int &nY )
{
nX = m_nNobPos[ kXAxis ];
nY = m_nNobPos[ kYAxis ];
}
//-----------------------------------------------------------------------------
// Purpose: Respond when the cursor is moved in our window if we are clicking
// and dragging.
//-----------------------------------------------------------------------------
void C2DSlider::OnCursorMoved( int nMouseX, int nMouseY )
{
if ( !m_bDragging )
return;
input()->GetCursorPosition( nMouseX, nMouseY );
ScreenToLocal( nMouseX, nMouseY );
int nTrackX, nTrackY, nTrackWide, nTrackTall;
GetTrackRect( nTrackX, nTrackY, nTrackWide, nTrackTall );
m_nNobPos[ kXAxis ] = clamp( m_nNobDragStartPos[ kXAxis ] + nMouseX - m_nDragStartPos[ kXAxis ], nTrackX, nTrackX + nTrackWide - 1 );
m_nNobPos[ kYAxis ] = clamp( m_nNobDragStartPos[ kYAxis ] + nMouseY - m_nDragStartPos[ kYAxis ], nTrackY, nTrackY + nTrackTall - 1 );
RecomputeValueFromNobPos( false );
Repaint();
SendSliderMovedMessage();
}
//-----------------------------------------------------------------------------
// Purpose: Respond to mouse presses. Trigger Record staring positon.
//-----------------------------------------------------------------------------
void C2DSlider::OnMousePressed( MouseCode /* mouseCode */ )
{
if ( !IsEnabled() )
return;
/*
TODO: Do this in Maya
if ( input()->IsKeyDown( KEY_LSHIFT ) || input()->IsKeyDown( KEY_RSHIFT ) )
return;
if ( input()->IsKeyDown( KEY_LCONTROL ) || input()->IsKeyDown( KEY_LCONTROL ) )
return;
*/
int nMouseX;
int nMouseY;
input()->GetCursorPosition( nMouseX, nMouseY );
ScreenToLocal( nMouseX, nMouseY );
RequestFocus();
bool bStartDragging = false;
bool bPostDragStartSignal = false;
if (
nMouseX >= ( m_nNobPos[ kXAxis ] - m_nNobHalfSize[ kXAxis ] ) &&
nMouseX <= ( m_nNobPos[ kXAxis ] + m_nNobHalfSize[ kXAxis ] ) &&
nMouseY >= ( m_nNobPos[ kYAxis ] - m_nNobHalfSize[ kYAxis ] ) &&
nMouseY <= ( m_nNobPos[ kYAxis ] + m_nNobHalfSize[ kYAxis ] ) )
{
bStartDragging = true;
bPostDragStartSignal = true;
}
else
{
// we clicked elsewhere on the slider; move the nob to that position
int nTrackX, nTrackY, nTrackWide, nTrackTall;
GetTrackRect( nTrackX, nTrackY, nTrackWide, nTrackTall );
m_nNobPos[ kXAxis ] = clamp( nMouseX, nTrackX, nTrackX + nTrackWide - 1 );
m_nNobPos[ kYAxis ] = clamp( nMouseY, nTrackY, nTrackY + nTrackTall - 1 );
RecomputeValueFromNobPos( false );
Repaint();
SendSliderMovedMessage();
m_nNobDragStartPos[ kXAxis ] = nMouseX;
m_nNobDragStartPos[ kYAxis ] = nMouseY;
m_nDragStartPos[ kXAxis ] = nMouseX;
m_nDragStartPos[ kYAxis ] = nMouseY;
OnCursorMoved( nMouseX, nMouseY );
bStartDragging = IsDragOnRepositionNob();
if ( bStartDragging )
{
SendSliderDragStartMessage();
}
}
if ( bStartDragging )
{
// drag the nob
m_bDragging = true;
input()->SetMouseCapture( GetVPanel() );
m_nNobDragStartPos[ kXAxis ] = m_nNobPos[ kXAxis ];
m_nNobDragStartPos[ kYAxis ] = m_nNobPos[ kYAxis ];
m_nDragStartPos[ kXAxis ] = nMouseX;
m_nDragStartPos[ kYAxis ] = nMouseY;
}
if ( bPostDragStartSignal )
{
SendSliderDragStartMessage();
}
}
//-----------------------------------------------------------------------------
// Purpose: Just handle double presses like mouse presses
//-----------------------------------------------------------------------------
void C2DSlider::OnMouseDoublePressed( MouseCode mouseCode )
{
OnMousePressed( mouseCode );
}
//-----------------------------------------------------------------------------
// Purpose: Stop dragging when the mouse is released.
//-----------------------------------------------------------------------------
void C2DSlider::OnMouseReleased( MouseCode /* mouseCode */ )
{
if ( m_bDragging )
{
m_bDragging = false;
input()->SetMouseCapture( 0 );
SendSliderDragEndMessage();
}
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void C2DSlider::SetNobWidth( int nWidth )
{
m_nNobHalfSize[ kXAxis ] = ( ( nWidth | 1 ) - 1 ) / 2;
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
int C2DSlider::GetNobWidth() const
{
return m_nNobHalfSize[ kXAxis ] * 2 + 1;
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void C2DSlider::SetNobTall( int nTall )
{
m_nNobHalfSize[ kYAxis ] = ( ( nTall | 1 ) - 1 ) / 2;
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
int C2DSlider::GetNobTall() const
{
return m_nNobHalfSize[ kYAxis ] * 2 + 1;
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void C2DSlider::SetNobSize( int nWidth, int nTall )
{
SetNobWidth( nWidth );
SetNobTall( nTall );
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void C2DSlider::GetNobSize( int &nHalfWidth, int &nHalfTall ) const
{
nHalfWidth = GetNobWidth();
nHalfTall = GetNobTall();
}
//-----------------------------------------------------------------------------
// Purpose: If you click on the slider outside of the nob, the nob jumps
// to the click position, and if this setting is enabled, the nob
// is then draggable from the new position until the mouse is released
// Input : state -
//-----------------------------------------------------------------------------
void C2DSlider::SetDragOnRepositionNob( bool bState )
{
m_bIsDragOnRepositionNob = bState;
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
bool C2DSlider::IsDragOnRepositionNob() const
{
return m_bIsDragOnRepositionNob;
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
bool C2DSlider::IsDragged() const
{
return m_bDragging;
}
//-----------------------------------------------------------------------------
// Purpose: Set the size of the slider bar.
// Warning less than 30 pixels tall and everything probably won't fit.
//-----------------------------------------------------------------------------
void C2DSlider::OnSizeChanged( int nWide, int nTall )
{
BaseClass::OnSizeChanged( nWide, nTall );
RecomputeNobPosFromValue();
}
//-----------------------------------------------------------------------------
// Purpose: Draw everything on screen
//-----------------------------------------------------------------------------
void C2DSlider::Paint()
{
DrawNob();
}
//-----------------------------------------------------------------------------
// Purpose: Draw the slider track
//-----------------------------------------------------------------------------
void C2DSlider::PaintBackground()
{
BaseClass::PaintBackground();
int x, y;
int wide,tall;
GetTrackRect( x, y, wide, tall );
surface()->DrawSetColor( s_TrackColor );
surface()->DrawFilledRect( x, y, x + wide + 1, y + tall + 1 );
if ( m_pInsetBorder )
{
m_pInsetBorder->Paint( x, y, x + wide, y + tall );
}
}
//-----------------------------------------------------------------------------
// Purpose: Layout the slider before drawing it on screen.
//-----------------------------------------------------------------------------
void C2DSlider::PerformLayout()
{
BaseClass::PerformLayout();
RecomputeNobPosFromValue();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C2DSlider::ApplySchemeSettings( IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
s_TextColor = pScheme->GetColor( "2DSlider.TextColor", s_TextColor );
s_NobColor = pScheme->GetColor( "2DSlider.NobColor", s_NobColor );
s_TickColor = pScheme->GetColor( "2DSlider.TickColor", s_TickColor );
s_TickFillXColor = pScheme->GetColor( "2DSlider.TickFillXColor", s_TickFillXColor );
s_TickFillYColor = pScheme->GetColor( "2DSlider.TickFillYColor", s_TickFillYColor );
s_TickFillColor = pScheme->GetColor( "2DSlider.TickFillColor", s_TickFillColor );
s_TrackColor = pScheme->GetColor( "2DSlider.TrackColor", s_TrackColor );
m_pLabel->SetColor( s_TextColor );
m_pLabel->SetFont( pScheme->GetFont( "Default" ) );
m_pLabel->ResizeImageToContent();
SetFgColor( s_NobColor );
m_pNobBorder = pScheme->GetBorder( "ButtonBorder" );
m_pInsetBorder = pScheme->GetBorder( "ButtonDepressedBorder" );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C2DSlider::ApplySettings( KeyValues *inResourceData )
{
BaseClass::ApplySettings( inResourceData );
SetNobWidth( inResourceData->GetInt( "nobWidth", GetNobWidth() ) );
SetNobTall( inResourceData->GetInt( "nobTall", GetNobTall() ) );
SetDrawLabel( inResourceData->GetBool( "drawLabel", IsDrawingLabel() ) );
wchar_t buf[ BUFSIZ ];
m_pLabel->GetText( buf, ARRAYSIZE( buf ) );
SetLabelText( inResourceData->GetWString( "labelText", buf ) );
SetDragOnRepositionNob( inResourceData->GetBool( "dragOnRepositionNob", IsDragOnRepositionNob() ) );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C2DSlider::GetSettings( KeyValues *outResourceData )
{
BaseClass::GetSettings( outResourceData );
outResourceData->SetInt( "nobWidth", GetNobWidth() );
outResourceData->SetInt( "nobTall", GetNobTall() );
outResourceData->SetBool( "drawLabel", IsDrawingLabel() );
wchar_t buf[ BUFSIZ ];
m_pLabel->GetText( buf, ARRAYSIZE( buf ) );
outResourceData->SetWString( "labelText", buf );
outResourceData->SetBool( "dragOnRepositionNob", IsDragOnRepositionNob() );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
const char *C2DSlider::GetDescription()
{
static char buf[ 1024 ];
Q_snprintf( buf, sizeof( buf ), "%s, int nobWidth, int nobTall, bool dragOnRepositionNob", BaseClass::GetDescription() );
return buf;
}
//-----------------------------------------------------------------------------
// Purpose: Handle key presses
//-----------------------------------------------------------------------------
void C2DSlider::OnKeyCodeTyped( KeyCode nKeyCode )
{
switch ( nKeyCode )
{
// for now left and right arrows just open or close submenus if they are there.
case KEY_LEFT:
MoveNobRelative( -1, 0 );
break;
case KEY_RIGHT:
MoveNobRelative( 1, 0 );
break;
case KEY_DOWN:
MoveNobRelative( 0, 1 );
break;
case KEY_UP:
MoveNobRelative( 0, -1 );
break;
case KEY_HOME:
SetValueX( m_fRange[ kXAxis ][ 0 ] );
break;
case KEY_END:
SetValueX( m_fRange[ kXAxis ][ 1 ] );
break;
case KEY_PAGEUP:
SetValueY( m_fRange[ kYAxis ][ 0 ] );
break;
case KEY_PAGEDOWN:
SetValueY( m_fRange[ kYAxis ][ 1 ] );
break;
default:
BaseClass::OnKeyCodeTyped( nKeyCode );
break;
}
}
//-----------------------------------------------------------------------------
// Purpose: Draw the nob part of the slider.
//-----------------------------------------------------------------------------
void C2DSlider::DrawNob()
{
// horizontal nob
int x, y;
int wide,tall;
GetTrackRect( x, y, wide, tall );
surface()->DrawSetColor( s_TickFillXColor );
surface()->DrawFilledRect( x, y, x + m_nNobPos[ kXAxis ], y + m_nNobPos[ kYAxis ] );
surface()->DrawSetColor( s_TickFillYColor );
surface()->DrawFilledRect( x + m_nNobPos[ kXAxis ] + 1, y + m_nNobPos[ kYAxis ] + 1, x + wide + 1, y + tall + 1 );
surface()->DrawSetColor( s_TickFillColor );
surface()->DrawFilledRect( x, y + m_nNobPos[ kYAxis ] + 1, x + m_nNobPos[ kXAxis ], y + tall + 1 );
surface()->DrawSetColor( s_TickFillColor );
surface()->DrawFilledRect( x, y + tall, m_nNobPos[ kXAxis ] + 1, m_nNobPos[ kYAxis ] );
surface()->DrawSetColor( s_TickColor );
surface()->DrawFilledRect( x, m_nNobPos[ kYAxis ], x + wide - 1, m_nNobPos[ kYAxis ] + 1 );
surface()->DrawFilledRect( m_nNobPos[ kXAxis ], y, m_nNobPos[ kXAxis ] + 1, y + tall - 1 );
// Redraw the inset border
if ( m_pInsetBorder )
{
m_pInsetBorder->Paint( x, y, x + wide, y + tall );
}
surface()->DrawSetColor( s_NobColor );
surface()->DrawFilledRect(
m_nNobPos[ kXAxis ] - m_nNobHalfSize[ kXAxis ], m_nNobPos[ kYAxis ] - m_nNobHalfSize[ kYAxis ],
m_nNobPos[ kXAxis ] + m_nNobHalfSize[ kXAxis ] + 1, m_nNobPos[ kYAxis ] + m_nNobHalfSize[ kYAxis ] + 1 );
// border
if ( m_pNobBorder )
{
m_pNobBorder->Paint(
m_nNobPos[ kXAxis ] - m_nNobHalfSize[ kXAxis ], m_nNobPos[ kYAxis ] - m_nNobHalfSize[ kYAxis ],
m_nNobPos[ kXAxis ] + m_nNobHalfSize[ kXAxis ] + 1, m_nNobPos[ kYAxis ] + m_nNobHalfSize[ kYAxis ] + 1 );
}
char buf[ BUFSIZ ];
Q_snprintf( buf, ARRAYSIZE( buf ), "n %02d %02d v %3.1f %3.1f", m_nNobPos[ kXAxis ], m_nNobPos[ kYAxis ], m_fValue[ kXAxis ], m_fValue[ kYAxis ] );
int nLabelWidth, nLabelTall;
m_pLabel->GetContentSize( nLabelWidth, nLabelTall );
// m_pLabel->SetPos( 10, y + MAX( tall, tall - ( tall - nLabelTall ) / 2 ) );
m_pLabel->SetPos( 10, y + ( MAX( 0, tall - nLabelTall ) ) / 2 );
m_pLabel->Paint();
}
//-----------------------------------------------------------------------------
// Purpose: Get the rectangle to draw the slider track in.
//-----------------------------------------------------------------------------
void C2DSlider::GetTrackRect( int &x, int &y, int &w, int &t )
{
x = 0;
y = 0;
GetPaintSize( w, t );
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void C2DSlider::MoveNobRelative( int nX, int nY )
{
int x, y, wide, tall;
GetTrackRect( x, y, wide, tall );
m_nNobPos[ kXAxis ] = clamp( m_nNobPos[ kXAxis ] + nX, x, x + wide - 1 );
m_nNobPos[ kYAxis ] = clamp( m_nNobPos[ kYAxis ] + nY, y, y + tall - 1 );
RecomputeValueFromNobPos( true );
}
//-----------------------------------------------------------------------------
// Purpose: Move the nob on the slider in response to changing its value.
//-----------------------------------------------------------------------------
void C2DSlider::RecomputeNobPosFromValue()
{
int x, y, wide, tall;
GetTrackRect( x, y, wide, tall );
m_nNobPos[ kXAxis ] = static_cast< int >( RemapValClamped( m_fValue[ kXAxis ], m_fRange[ kXAxis ][ 0 ], m_fRange[ kXAxis ][ 1 ], x, x + wide - 1 ) );
m_nNobPos[ kYAxis ] = static_cast< int >( RemapValClamped( m_fValue[ kYAxis ], m_fRange[ kYAxis ][ 0 ], m_fRange[ kYAxis ][ 1 ], y, y + tall - 1 ) );
Repaint();
}
//-----------------------------------------------------------------------------
// Purpose: Sync the slider's value up with the nob's position.
//-----------------------------------------------------------------------------
void C2DSlider::RecomputeValueFromNobPos( bool bTriggerChangeMessage /* = true */ )
{
int x, y, wide, tall;
GetTrackRect( x, y, wide, tall );
const float fValueX = RemapValClamped( m_nNobPos[ kXAxis ], x, x + wide - 1, m_fRange[ kXAxis ][ 0 ], m_fRange[ kXAxis ][ 1 ] );
const float fValueY = RemapValClamped( m_nNobPos[ kYAxis ], y, y + tall - 1, m_fRange[ kYAxis ][ 0 ], m_fRange[ kYAxis ][ 1 ] );
SetValue( fValueX, fValueY, bTriggerChangeMessage );
}
//-----------------------------------------------------------------------------
// Purpose: Send a message to interested parties when the slider moves
//-----------------------------------------------------------------------------
void C2DSlider::SendSliderMovedMessage()
{
KeyValues *p2DSliderMoved = new KeyValues( "2DSliderMoved" );
p2DSliderMoved->SetFloat( "valueX", m_fValue[ kXAxis ] );
p2DSliderMoved->SetFloat( "valueY", m_fValue[ kYAxis ] );
PostActionSignal( p2DSliderMoved );
}
//-----------------------------------------------------------------------------
// Purpose: Send a message to interested parties when the user begins dragging the slider
//-----------------------------------------------------------------------------
void C2DSlider::SendSliderDragStartMessage()
{
KeyValues *p2DSliderDragStart = new KeyValues( "2DSliderDragStart" );
p2DSliderDragStart->SetFloat( "valueX", m_fValue[ kXAxis ] );
p2DSliderDragStart->SetFloat( "valueY", m_fValue[ kYAxis ] );
PostActionSignal( p2DSliderDragStart );
}
//-----------------------------------------------------------------------------
// Purpose: Send a message to interested parties when the user ends dragging the slider
//-----------------------------------------------------------------------------
void C2DSlider::SendSliderDragEndMessage()
{
KeyValues *p2DSliderDragEnd = new KeyValues( "2DSliderDragEnd" );
p2DSliderDragEnd->SetFloat( "valueX", m_fValue[ kXAxis ] );
p2DSliderDragEnd->SetFloat( "valueY", m_fValue[ kYAxis ] );
PostActionSignal( p2DSliderDragEnd );
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,67 @@
//====== Copyright © 1996-2005, 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" );
// m_pOpen->SetImage( vgui::scheme()->GetImage( "tools/ifm/icon_properties_linkarrow" , false), 0 );
// m_pOpen->SetPaintBorderEnabled( false );
// m_pOpen->SetContentAlignment( vgui::Label::a_center );
}
void CAttributeBasePickerPanel::OnCommand( char const *cmd )
{
if ( !Q_stricmp( cmd, "open" ) )
{
ShowPickerDialog();
}
else
{
BaseClass::OnCommand( cmd );
}
}
void CAttributeBasePickerPanel::PerformLayout()
{
BaseClass::PerformLayout();
int viewWidth, viewHeight;
GetSize( viewWidth, viewHeight );
IImage *arrowImage = vgui::scheme()->GetImage( "tools/ifm/icon_properties_linkarrow" , false);
if( arrowImage )
{
m_pOpen->SetImage( arrowImage , 0 );
m_pOpen->SetPaintBorderEnabled( false );
m_pOpen->SetContentAlignment( vgui::Label::a_center );
m_pOpen->SetBounds( (FirstColumnWidth - ColumnBorderWidth - 16) * 0.5 , ( viewHeight - 16 )* 0.5 , 16, 16 );
}
else
{
m_pOpen->SetBounds( 0, 0, 50, 20 );
}
}

View File

@@ -0,0 +1,162 @@
//====== Copyright © 1996-2005, 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 );
CUtlSymbolLarge symbol = g_pDataModel->GetSymbol( pChoiceString );
m_Choices[0]->SetValue<CUtlSymbolLarge>( "string", symbol );
}
void CDmeEditorBoolChoicesInfo::SetTrueChoice( const char *pChoiceString )
{
CUtlSymbolLarge symbol = g_pDataModel->GetSymbol( pChoiceString );
m_Choices[0]->SetValue<CUtlSymbolLarge>( "string", symbol );
}
//-----------------------------------------------------------------------------
// 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 ) );
}

View File

@@ -0,0 +1,163 @@
//====== Copyright © 1996-2005, 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>();
clr.SetColor( clr.r(), clr.g(), clr.b(), 255 );
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 pickerX, pickerY, pickerW, pickerH;
GetPickerBounds( &pickerX, &pickerY, &pickerW, &pickerH );
m_pOpen->SetBounds( pickerX, pickerY, pickerW, pickerH );
}

View File

@@ -0,0 +1,116 @@
//====== Copyright © 1996-2005, 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;
m_bShowUniqueID = info.m_bShowUniqueID;
}
void CAttributeElementPanel::SetFont( HFont font )
{
BaseClass::SetFont( font );
m_pData->SetFont( font );
m_pType->SetFont( font );
}
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 ] = "";
if( m_bShowUniqueID )
{
UniqueIdToString( element->GetId(), idstr, sizeof( idstr ) );
}
if ( m_bShowMemoryUsage )
{
Q_snprintf( elemText, sizeof( elemText ), "%s %s (%.3fMB total / %.3fKB self)", element->GetTypeString(),
idstr, element->EstimateMemoryUsage( TD_DEEP ) / float( 1 << 20 ), element->EstimateMemoryUsage( TD_NONE ) / float( 1 << 10 ) );
}
else
{
Q_snprintf( elemText, sizeof( elemText ), "%s %s", element->GetTypeString(), idstr );
}
}
m_pData->SetText( elemText );
m_pData->SetEnabled(false);
}
void CAttributeElementPanel::PostConstructor()
{
Refresh();
}
// ----------------------------------------------------------------------------

View File

@@ -0,0 +1,182 @@
//====== Copyright © 1996-2005, 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;
m_bShowUniqueID = 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 ] = "";
if( m_bShowUniqueID )
{
UniqueIdToString( element->GetId(), idstr, sizeof( idstr ) );
}
if ( m_bShowMemoryUsage )
{
Q_snprintf( elemText, sizeof( elemText ), "%s %s (%.3fMB total / %.3fKB self)", element->GetTypeString(),
idstr, element->EstimateMemoryUsage( TD_DEEP ) / float( 1 << 20 ), element->EstimateMemoryUsage( TD_NONE ) / float( 1 << 10 ) );
}
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 );
}
}
//-----------------------------------------------------------------------------
// Layout the panel
//-----------------------------------------------------------------------------
void CAttributeElementPickerPanel::PerformLayout()
{
BaseClass::PerformLayout();
int viewWidth, viewHeight;
GetSize( viewWidth, viewHeight );
IImage *arrowImage = vgui::scheme()->GetImage( "tools/ifm/icon_properties_linkarrow" , false);
if( arrowImage )
{
m_hEdit->SetImage( arrowImage , 0 );
m_hEdit->SetPaintBorderEnabled( false );
m_hEdit->SetContentAlignment( vgui::Label::a_center );
m_hEdit->SetBounds( (FirstColumnWidth - ColumnBorderWidth - 16) * 0.5 , ( viewHeight - 16 )* 0.5 , 16, 16 );
}
else
{
m_hEdit->SetBounds( 0, 0, 100, 20 );
}
}

View File

@@ -0,0 +1,71 @@
//====== Copyright © 1996-2005, 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( CAttributeDmeFilePickerPanel, "Choose DMX file", "DMX", "dmx" );
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->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();
}
}

View File

@@ -0,0 +1,170 @@
//====== Copyright © 1996-2005, 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" );
}

View File

@@ -0,0 +1,91 @@
//====== Copyright © 1996-2005, 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 ) );
}

View File

@@ -0,0 +1,66 @@
//====== Copyright © 1996-2005, 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 );
char pszModelName[ 1024 ];
m_pData->GetText( pszModelName, sizeof( pszModelName ) );
pMDLPickerDialog->SetInitialSelection( pszModelName );
pMDLPickerDialog->DoModal( );
}
//-----------------------------------------------------------------------------
// Called when it's time to show the MDL picker
//-----------------------------------------------------------------------------
void CAttributeMDLPickerPanel::OnMDLSelected( KeyValues *pKeyValues )
{
const char *pMDLName = pKeyValues->GetString( "asset", NULL );
if ( !pMDLName || !pMDLName[ 0 ] )
return;
// Apply to text panel
m_pData->SetText( pMDLName );
SetDirty(true);
if ( IsAutoApply() )
{
Apply();
}
}

View File

@@ -0,0 +1,109 @@
//====== Copyright © 1996-2005, 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();
}
}

View File

@@ -0,0 +1,86 @@
//====== Copyright © 1996-2005, 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;
}
}
CUtlSymbolLarge symbol = GetAttributeValue<CUtlSymbolLarge>();
const char *pCurrentSound = symbol.String();
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();
}
}

View File

@@ -0,0 +1,174 @@
//====== Copyright © 1996-2005, 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( "value", pChoiceString );
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;
CUtlSymbolLarge symbol = pChoice->GetValue< CUtlSymbolLarge >( "value" );
if ( symbol == UTL_INVAL_SYMBOL_LARGE )
return NULL;
return symbol.String();
}
//-----------------------------------------------------------------------------
// 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 )
{
CUtlSymbolLarge oldSymbol = GetAttributeValue<CUtlSymbolLarge>();
const char *pOldString = oldSymbol.String();
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;
CUtlSymbolLarge symbol = GetAttributeValue<CUtlSymbolLarge>();
const char *pValue = symbol.String();
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" );
}

View File

@@ -0,0 +1,504 @@
//====== Copyright © 1996-2005, 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();
StoreInitialValue( true );
}
}
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();
if ( !IsEnabled() )
return; // don't bother writing data if this attribute is read-only or being driven by a channel
WriteValueToAttribute();
StoreInitialValue();
}
void CAttributeTextEntry::OnMouseWheeled( int delta )
{
// Must have *keyboard* focus for it to work, and alse be writeable and not driven by a channel
if ( !HasFocus() || !IsEnabled() )
{
// 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();
}
// ----------------------------------------------------------------------------

View File

@@ -0,0 +1,133 @@
//====== Copyright © 1996-2005, 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 "movieobjects/dmechannel.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 ) && FindChannelTargetingAttribute( GetAttribute() ) == NULL );
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 %s (%.3fMB)", count, (count == 1) ? "item" : "items", pAttr->EstimateMemoryUsage( TD_DEEP ) / float( 1 << 20 ) );
}
else
{
Q_snprintf( buf, sizeof( buf ), "%d %s", count, (count == 1) ? "item" : "items" );
}
m_pData->SetText( buf );
m_pData->SetEnabled(false);
}
else if ( GetAttributeType() == AT_ELEMENT )
{
m_pData->SetText( "" );
}
else
{
GetAttributeValueAsString( buf, sizeof( buf ) );
// This is a hack because VMatrix has \n characters in the text and the TextEntry field doesn't show them.
if ( GetAttributeType() == AT_VMATRIX )
{
// Replace \n with ' '
char *p = buf;
while ( *p )
{
if ( *p == '\n' )
*p = ' ';
++p;
}
}
m_pData->SetText( buf );
m_pData->SetEnabled( !HasFlag( READONLY ) && FindChannelTargetingAttribute( GetAttribute() ) == NULL );
}
}
void CAttributeTextPanel::PostConstructor()
{
Refresh();
}

View File

@@ -0,0 +1,380 @@
//====== Copyright © 1996-2005, 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/AttributeBooleanPanel.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"
#include "dme_controls/attributesheetsequencepickerpanel.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: boolean entry
static CAttributeWidgetFactory<CAttributeBooleanPanel> g_AttributeBooleanWidgetFactory( "boolean" );
// 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<CAttributeTgaPickerPanel> 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" );
// An Attribute Widget Factory for: selecting sheet sequences
static CAttributeWidgetFactory<CAttributeSheetSequencePickerPanel> g_AttributeSheetSequencePickerWidgetFactory( "sheetsequencepicker" );
// Special-case for the second sequence in a double-sequence material
static CAttributeWidgetFactory<CAttributeSheetSequencePickerPanel> g_AttributeSheetSequencePickerWidgetFactorySecond( "sheetsequencepicker_second" );
//-----------------------------------------------------------------------------
// 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_AttributeBooleanWidgetFactory },
{ AT_STRING, &g_AttributeTextWidgetFactory },
{ AT_VOID, &g_AttributeTextWidgetFactory },
{ AT_TIME, &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_TIME_ARRAY, &g_AttributeTextWidgetFactory },
{ AT_COLOR_ARRAY, &g_AttributeTextWidgetFactory },
{ 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 );
}
}

View File

@@ -0,0 +1,595 @@
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======
//
// Purpose:
//
//=============================================================================
#include "dme_controls/BaseAnimSetAttributeSliderPanel.h"
#include "movieobjects/dmechannel.h"
#include "movieobjects/dmeanimationset.h"
#include "vgui_controls/TextImage.h"
#include "vgui_controls/Button.h"
#include "vgui_controls/Slider.h"
#include "vgui_controls/PanelListPanel.h"
#include "dme_controls/BaseAnimSetPresetFaderPanel.h"
#include "dme_controls/BaseAnimationSetEditor.h"
#include "dme_controls/attributeslider.h"
#include "dme_controls/dmecontrols_utils.h"
#include "vgui/ISurface.h"
#include "vgui/ISystem.h"
#include "vgui/IInput.h"
#include "vgui/IVgui.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
#define ANIMATION_SET_EDITOR_ATTRIBUTESLIDERS_BUTTONTRAY_HEIGHT 32
const int FREE_SLIDER_LIST = 1500;
//-----------------------------------------------------------------------------
//
// CPresetSideFilterSlider class begins
//
//-----------------------------------------------------------------------------
class CPresetSideFilterSlider : public Slider
{
DECLARE_CLASS_SIMPLE( CPresetSideFilterSlider, Slider );
public:
CPresetSideFilterSlider( CBaseAnimSetAttributeSliderPanel *pParent, const char *panelName );
virtual ~CPresetSideFilterSlider();
float GetPos();
void SetPos( float frac );
protected:
virtual void Paint();
virtual void PaintBackground();
virtual void ApplySchemeSettings( IScheme *scheme );
virtual void GetTrackRect( int &x, int &y, int &w, int &h );
virtual void OnMousePressed(MouseCode code);
virtual void OnMouseDoublePressed(MouseCode code);
private:
CBaseAnimSetAttributeSliderPanel *m_pParent;
Color m_ZeroColor;
Color m_TextColor;
Color m_TextColorFocus;
TextImage *m_pName;
};
//-----------------------------------------------------------------------------
// Constructor, destructor
//-----------------------------------------------------------------------------
CPresetSideFilterSlider::CPresetSideFilterSlider( CBaseAnimSetAttributeSliderPanel *parent, const char *panelName ) :
BaseClass( (Panel *)parent, panelName ), m_pParent( parent )
{
SetRange( 0, 1000 );
SetDragOnRepositionNob( true );
SetPos( 0.5f );
SetPaintBackgroundEnabled( true );
m_pName = new TextImage( "Preset Side Filter" );
SetBgColor( Color( 128, 128, 128, 128 ) );
m_ZeroColor = Color( 33, 33, 33, 255 );
m_TextColor = Color( 200, 200, 200, 255 );
m_TextColorFocus = Color( 208, 143, 40, 255 );
}
CPresetSideFilterSlider::~CPresetSideFilterSlider()
{
delete m_pName;
}
void CPresetSideFilterSlider::OnMousePressed(MouseCode code)
{
if ( code == MOUSE_RIGHT )
{
SetPos( 0.5f );
return;
}
BaseClass::OnMousePressed( code );
}
void CPresetSideFilterSlider::OnMouseDoublePressed(MouseCode code)
{
if ( code == MOUSE_LEFT )
{
SetPos( 0.5f );
return;
}
BaseClass::OnMouseDoublePressed( code );
}
float CPresetSideFilterSlider::GetPos()
{
return GetValue() * 0.001f;
}
void CPresetSideFilterSlider::SetPos( float frac )
{
SetValue( (int)( frac * 1000.0f + 0.5f ), false );
}
void CPresetSideFilterSlider::ApplySchemeSettings( IScheme *scheme )
{
BaseClass::ApplySchemeSettings( scheme );
m_pName->SetFont( scheme->GetFont( "DefaultBold" ) );
m_pName->SetColor( m_TextColor );
m_pName->ResizeImageToContent();
SetFgColor( Color( 194, 120, 0, 255 ) );
SetThumbWidth( 3 );
}
void CPresetSideFilterSlider::GetTrackRect( int &x, int &y, int &w, int &h )
{
GetSize( w, h );
x = 0;
y = 2;
h -= 4;
}
void CPresetSideFilterSlider::Paint()
{
// horizontal nob
int x, y;
int wide,tall;
GetTrackRect( x, y, wide, tall );
Color col = GetFgColor();
surface()->DrawSetColor( col );
surface()->DrawFilledRect( _nobPos[0], 1, _nobPos[1], GetTall() - 1 );
surface()->DrawSetColor( m_ZeroColor );
surface()->DrawFilledRect( _nobPos[0] - 1, y + 1, _nobPos[0], y + tall - 1 );
}
void CPresetSideFilterSlider::PaintBackground()
{
int w, h;
GetSize( w, h );
int tx, ty, tw, th;
GetTrackRect( tx, ty, tw, th );
surface()->DrawSetColor( m_ZeroColor );
surface()->DrawFilledRect( tx, ty, tx + tw, ty + th );
int cw, ch;
m_pName->SetColor( _dragging ? m_TextColorFocus : m_TextColor );
m_pName->GetContentSize( cw, ch );
m_pName->SetPos( ( w - cw ) * 0.5f, ( h - ch ) * 0.5f );
m_pName->Paint();
}
//-----------------------------------------------------------------------------
//
// CBaseAnimSetAttributeSliderPanel begins
//
//-----------------------------------------------------------------------------
CBaseAnimSetAttributeSliderPanel::CBaseAnimSetAttributeSliderPanel( vgui::Panel *parent, const char *className, CBaseAnimationSetEditor *editor ) :
BaseClass( parent, className ),
m_pController( NULL )
{
m_hEditor = editor;
m_pLeftRightBoth[ 0 ] = new Button( this, "AttributeSliderLeftOnly", "", this, "OnLeftOnly" );
m_pLeftRightBoth[ 1 ] = new Button( this, "AttributeSliderRightOnly", "", this, "OnRightOnly" );
m_pPresetSideFilter = new CPresetSideFilterSlider( this, "PresetSideFilter" );
m_Sliders = new PanelListPanel( this, "AttributeSliders" );
m_Sliders->SetFirstColumnWidth( 0 );
m_Sliders->SetAutoResize
(
Panel::PIN_TOPLEFT,
Panel::AUTORESIZE_DOWNANDRIGHT,
0, ANIMATION_SET_EDITOR_ATTRIBUTESLIDERS_BUTTONTRAY_HEIGHT,
0, 0
);
m_Sliders->SetVerticalBufferPixels( 0 );
m_pController = editor->GetController();
m_pController->AddControlSelectionChangedListener( this );
ivgui()->AddTickSignal( GetVPanel(), 0 );
InitFreeSliderList( FREE_SLIDER_LIST );
}
void CBaseAnimSetAttributeSliderPanel::OnCommand( const char *pCommand )
{
if ( !Q_stricmp( pCommand, "OnLeftOnly" ) )
{
m_pPresetSideFilter->SetPos( 0.0f );
return;
}
if ( !Q_stricmp( pCommand, "OnRightOnly" ) )
{
m_pPresetSideFilter->SetPos( 1.0f );
return;
}
BaseClass::OnCommand( pCommand );
}
void CBaseAnimSetAttributeSliderPanel::ApplySchemeSettings( IScheme *scheme )
{
BaseClass::ApplySchemeSettings( scheme );
m_Sliders->SetBgColor( Color( 42, 42, 42, 255 ) );
}
void CBaseAnimSetAttributeSliderPanel::PerformLayout()
{
BaseClass::PerformLayout();
int w, h;
GetSize( w, h );
int availH = ANIMATION_SET_EDITOR_ATTRIBUTESLIDERS_BUTTONTRAY_HEIGHT;
int btnSize = 9;
m_pLeftRightBoth[ 0 ]->SetBounds( 15, ( availH - btnSize ) / 2, btnSize, btnSize );
m_pLeftRightBoth[ 1 ]->SetBounds( w - 15, ( availH - btnSize ) / 2, btnSize, btnSize );
m_pPresetSideFilter->SetBounds( 23 + btnSize, 4, w - 38 - 2 * btnSize, availH - 8 );
}
void CBaseAnimSetAttributeSliderPanel::OnTick()
{
BaseClass::OnTick();
bool bVisible = IsVisible();
if ( bVisible )
{
// chain up and see if any parent panel is hiding us
VPANEL p = GetVParent();
while ( p )
{
if ( !ipanel()->IsVisible(p) )
{
bVisible = false;
break;
}
p = ipanel()->GetParent(p);
}
}
if ( !bVisible )
{
OnThink();
}
}
//-----------------------------------------------------------------------------
// Purpose: Determines:
// a) are we holding the ctrl key still, if so
// figures out the crossfade amount of each preset slider with non-zero influence
// b) not holding control, then just see if we are previewing whichever preset the mouse is over
// Input : -
//-----------------------------------------------------------------------------
void CBaseAnimSetAttributeSliderPanel::OnThink()
{
BaseClass::OnThink();
m_pController->UpdatePreviewSliderValues();
m_pController->UpdatePreviewSliderTimes();
ApplySliderValues( false );
UpdateSliderDependencyFlags();
}
void CBaseAnimSetAttributeSliderPanel::ChangeAnimationSetClip( CDmeFilmClip *pFilmClip )
{
RebuildSliderLists();
}
void CBaseAnimSetAttributeSliderPanel::RebuildSliderLists()
{
int c = m_SliderList.Count();
for ( int i = 0 ; i < c; ++i )
{
FreeSlider( m_SliderList[ i ] );
}
m_SliderList.RemoveAll();
m_Sliders->RemoveAll();
CUtlVector< CDmElement * > controlList;
CAnimSetGroupAnimSetTraversal traversal( m_pController->GetAnimationSetClip() );
while ( CDmeAnimationSet *pAnimSet = traversal.Next() )
{
const CDmaElementArray< CDmElement > &controls = pAnimSet->GetControls();
// Now create sliders for all known controls, nothing visible by default
int controlCount = controls.Count();
for ( int ci = 0 ; ci < controlCount; ++ci )
{
CDmElement *control = controls[ ci ];
if ( !control )
continue;
controlList.AddToTail( control );
}
}
for ( int i = 0; i < controlList.Count(); ++i )
{
CDmElement *control = controlList[ i ];
CAttributeSlider *slider = AllocateSlider();
slider->Init( control, false );
slider->SetVisible( false );
m_SliderList.AddToTail( slider );
// Transform controls get two separate sliders, one for position and one for rotation.
// This is something of an artifact of having separate controls for position and rotation,
// but it is useful for value type in to have a separate slider for each.
CDmeTransformControl *pTransformControl = CastElement< CDmeTransformControl >( control );
if ( pTransformControl )
{
CAttributeSlider *pOrientationSlider = AllocateSlider();
pOrientationSlider->Init( control, true );
pOrientationSlider->SetVisible( false );
m_SliderList.AddToTail( pOrientationSlider );
}
}
}
void CBaseAnimSetAttributeSliderPanel::OnControlsAddedOrRemoved()
{
bool changed = false;
int nSliderIndex = 0;
CAnimSetGroupAnimSetTraversal traversal( m_pController->GetAnimationSetClip() );
while ( CDmeAnimationSet *pAnimSet = traversal.Next() )
{
// See if every slider is the same as before
const CDmaElementArray< CDmElement > &controls = pAnimSet->GetControls();
int controlCount = controls.Count();
for ( int i = 0 ; i < controlCount; ++i )
{
CDmElement *control = controls[ i ];
if ( !control )
continue;
if ( nSliderIndex >= m_SliderList.Count() )
{
changed = true;
break;
}
CAttributeSlider *pSlider = m_SliderList[ nSliderIndex++ ];
if ( pSlider->GetControl() != control )
{
changed = true;
break;
}
if ( IsTransformControl( control ) )
{
// Transform controls add two sliders so make sure the
// next slider refers to the transform control as well.
pSlider = m_SliderList[ nSliderIndex++ ];
if ( pSlider->GetControl() != control )
{
changed = true;
break;
}
continue;
}
if ( pSlider->IsStereo() != IsStereoControl( control ) )
{
changed = true;
break;
}
}
}
changed = changed || nSliderIndex != m_SliderList.Count();
if ( !changed )
return;
RebuildSliderLists();
}
void CBaseAnimSetAttributeSliderPanel::OnControlSelectionChanged()
{
bool visibleSlidersChanged = false;
// Walk through all sliders and show only those in the symbol table
int c = m_SliderList.Count();
for ( int i = 0; i < c; ++i )
{
CAttributeSlider *pSlider = m_SliderList[ i ];
CDmElement* pSliderControl = pSlider->GetControl();
TransformComponent_t nComponentFlags = m_pController->GetSelectionComponentFlags( pSliderControl );
// If the slider is transform control slider determine if it is the
// slider for the position or rotation and mask the flags accordingly.
LogComponents_t nLogComponentFlags = SelectionInfo_t::ConvertTransformFlagsToLogFlags( nComponentFlags, pSlider->IsOrientation() );
bool bShowSlider = nComponentFlags != 0;
if ( pSlider->IsVisible() != bShowSlider )
{
pSlider->SetVisible( bShowSlider );
visibleSlidersChanged = true;
}
if ( pSlider->VisibleComponents() != nLogComponentFlags )
{
pSlider->SetVisibleComponents( nLogComponentFlags );
}
}
// If nothing changed then nothing else needs to be done
if ( !visibleSlidersChanged )
return;
// If the visibility of entire sliders changed then
// the slider visibility list must be updated.
m_Sliders->RemoveAll();
for ( int i = 0; i < c; ++i )
{
CAttributeSlider *slider = m_SliderList[ i ];
if ( slider->IsVisible() )
{
m_Sliders->AddItem( NULL, slider );
}
}
}
void CBaseAnimSetAttributeSliderPanel::GetTypeInValueForControl( CDmElement *pControl, bool bOrientation, AttributeValue_t &controlValue, const AttributeValue_t &sliderValue )
{
CDmeTransformControl *pTransformControl = CastElement< CDmeTransformControl >( pControl );
if ( pTransformControl && bOrientation )
{
const Quaternion &q = sliderValue.m_Quaternion;
QAngle ang;
QuaternionAngles( q, ang );
controlValue.m_Vector.x = ang.x;
controlValue.m_Vector.y = ang.y;
controlValue.m_Vector.z = ang.z;
}
else
{
controlValue = sliderValue;
}
}
void CBaseAnimSetAttributeSliderPanel::UpdatePreview( char const *pchFormat, ... )
{
}
bool CBaseAnimSetAttributeSliderPanel::ApplySliderValues( bool bForce )
{
bool bValuesChanged = m_pController->ApplySliderValues( bForce );
if ( bValuesChanged )
{
UpdatePreview( "ApplySliderValues\n" );
}
return bValuesChanged;
}
//-----------------------------------------------------------------------------
// Purpose: Update the slider flags specifying if a slider is dependency of the
// currently active slider.
//-----------------------------------------------------------------------------
void CBaseAnimSetAttributeSliderPanel::UpdateSliderDependencyFlags() const
{
bool ctrlDown = input()->IsKeyDown( KEY_LCONTROL ) || input()->IsKeyDown( KEY_RCONTROL );
CAttributeSlider *pPrimarySlider = ctrlDown ? m_pController->GetActiveAttributeSlider() : NULL;
int nSliders = m_SliderList.Count();
for ( int iSlider = 0; iSlider < nSliders; ++iSlider )
{
CAttributeSlider *pSlider = m_SliderList[ iSlider ];
if ( !pSlider )
continue;
pSlider->SetDependent( pPrimarySlider ? pPrimarySlider->IsDependent( pSlider ) : false );
}
}
void CBaseAnimSetAttributeSliderPanel::SetupForPreset( FaderPreview_t &fader )
{
// Nothing special here
}
float CBaseAnimSetAttributeSliderPanel::GetBalanceSliderValue()
{
return m_pPresetSideFilter->GetPos();
}
int CBaseAnimSetAttributeSliderPanel::FindSliderIndexForControl( const CDmElement *control )
{
int c = m_SliderList.Count();
for ( int i = 0; i < c; ++i )
{
if ( m_SliderList[ i ]->GetControl() == control )
return i;
}
return -1;
}
CAttributeSlider *CBaseAnimSetAttributeSliderPanel::FindSliderForControl( const CDmElement *control )
{
int i = FindSliderIndexForControl( control );
if ( i < 0 )
return NULL;
return m_SliderList[ i ];
}
bool CBaseAnimSetAttributeSliderPanel::GetSliderValues( AttributeValue_t *pValue, int nIndex )
{
Assert( pValue );
Assert( nIndex >= 0 && nIndex < m_SliderList.Count() );
CAttributeSlider *pSlider = m_SliderList[ nIndex ];
CAttributeSlider *pAttrSlider = m_pController->GetActiveAttributeSlider();
bool shiftDown = input()->IsKeyDown( KEY_LSHIFT ) || input()->IsKeyDown( KEY_RSHIFT );
bool bPreviewingAttrSlider = pAttrSlider == pSlider && shiftDown;
bool bGetPreview = bPreviewingAttrSlider || m_pController->WasPreviouslyHoldingPresetPreviewKey() || m_pController->IsPresetFaderBeingDragged();
*pValue = bGetPreview ? pSlider->GetPreview() : pSlider->GetValue();
return pSlider->IsVisible();
}
void CBaseAnimSetAttributeSliderPanel::DispatchCurve( int nCurveType )
{
// Nothing, handled by SFM
}
void CBaseAnimSetAttributeSliderPanel::InitFreeSliderList( int nCount )
{
for ( int i = 0; i < nCount; ++i )
{
CAttributeSlider *slider = new CAttributeSlider( this );
slider->SetVisible( false );
m_FreeSliderList.AddToTail( slider );
}
}
CAttributeSlider *CBaseAnimSetAttributeSliderPanel::AllocateSlider()
{
int c = m_FreeSliderList.Count();
if ( c > 0 )
{
CAttributeSlider *slider = m_FreeSliderList[ c - 1 ];
m_FreeSliderList.Remove( c - 1 );
slider->SetVisible( true );
return slider;
}
// Add a new one
CAttributeSlider *slider = new CAttributeSlider( this );
slider->SetVisible( true );
return slider;
}
void CBaseAnimSetAttributeSliderPanel::FreeSlider( CAttributeSlider *slider )
{
slider->SetVisible( false );
m_FreeSliderList.AddToTail( slider );
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,295 @@
//====== Copyright © 1996-2006, Valve Corporation, All rights reserved. =======
//
// Purpose:
//
//=============================================================================
#include "dme_controls/BaseAnimationSetEditor.h"
#include "tier1/KeyValues.h"
#include "vgui_controls/Splitter.h"
#include "vgui_controls/Menu.h"
#include "studio.h"
#include "dme_controls/BaseAnimSetAttributeSliderPanel.h"
#include "dme_controls/BaseAnimSetPresetFaderPanel.h"
#include "dme_controls/BaseAnimSetControlGroupPanel.h"
#include "dme_controls/dmecontrols_utils.h"
#include "movieobjects/dmechannel.h"
#include "movieobjects/dmeanimationset.h"
#include "movieobjects/dmegamemodel.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
#define ANIMATION_SET_EDITOR_BUTTONTRAY_HEIGHT 38
#define ANIMATION_SET_BUTTON_INSET 0
CBaseAnimationSetEditor::CBaseAnimationSetEditor( vgui::Panel *parent, const char *className, CBaseAnimationSetControl *pAnimationSetController ) :
BaseClass( parent, className ),
m_Layout( LAYOUT_SPLIT ),
m_pController( pAnimationSetController )
{
// SETUP_PANEL( this );
//#pragma warning( disable: 4355 )
m_pController->SetAnimationSetEditorPanel( this );
//#pragma warning( default: 4355 )
PostMessage( GetVPanel(), new KeyValues( "OnChangeLayout", "value", m_Layout ) );
}
CBaseAnimationSetEditor::~CBaseAnimationSetEditor()
{
}
CBaseAnimationSetControl *CBaseAnimationSetEditor::GetController()
{
return m_pController;
}
void CBaseAnimationSetEditor::CreateToolsSubPanels()
{
m_hControlGroup = new CBaseAnimSetControlGroupPanel( (Panel *)NULL, "AnimSetControlGroup", this, false );
m_hPresetFader = new CBaseAnimSetPresetFaderPanel( (Panel *)NULL, "AnimSetPresetFader", this );
m_hAttributeSlider = new CBaseAnimSetAttributeSliderPanel( (Panel *)NULL, "AnimSetAttributeSliderPanel", this );
}
void CBaseAnimationSetEditor::ChangeLayout( EAnimSetLayout_t newLayout )
{
m_Layout = newLayout;
// Make sure these don't get blown away...
m_hControlGroup->SetParent( (Panel *)NULL );
m_hPresetFader->SetParent( (Panel *)NULL );
m_hAttributeSlider->SetParent( (Panel *)NULL );
delete m_Splitter.Get();
m_Splitter = NULL;
CUtlVector< Panel * > list;
list.AddToTail( m_hControlGroup.Get() );
list.AddToTail( m_hPresetFader.Get() );
list.AddToTail( m_hAttributeSlider.Get() );
Splitter *sub = NULL;
switch ( m_Layout )
{
default:
case LAYOUT_SPLIT:
{
m_Splitter = new Splitter( this, "AnimSetEditorMainSplitter", SPLITTER_MODE_VERTICAL, 1 );
m_Splitter->SetAutoResize
(
Panel::PIN_TOPLEFT,
Panel::AUTORESIZE_DOWNANDRIGHT,
0, ANIMATION_SET_EDITOR_BUTTONTRAY_HEIGHT,
0, 0
);
m_Splitter->SetBounds( 0, ANIMATION_SET_EDITOR_BUTTONTRAY_HEIGHT, GetWide(), GetTall() - ANIMATION_SET_EDITOR_BUTTONTRAY_HEIGHT );
m_Splitter->SetSplitterColor( Color(32, 32, 32, 255) );
// m_Splitter->EnableBorders( false );
m_hControlGroup->SetParent( m_Splitter->GetChild( 0 ) );
m_hControlGroup->SetAutoResize
(
Panel::PIN_TOPLEFT,
Panel::AUTORESIZE_DOWNANDRIGHT,
0, 0,
0, 0
);
sub = new Splitter( m_Splitter->GetChild( 1 ), "AnimSetEditorSubSplitter", SPLITTER_MODE_HORIZONTAL, 1 );
sub->SetAutoResize
(
Panel::PIN_TOPLEFT,
Panel::AUTORESIZE_DOWNANDRIGHT,
0, 0,
0, 0
);
m_hPresetFader->SetParent( sub->GetChild( 0 ) );
m_hPresetFader->SetAutoResize
(
Panel::PIN_TOPLEFT,
Panel::AUTORESIZE_DOWNANDRIGHT,
0, 0,
0, 0
);
m_hAttributeSlider->SetParent( sub->GetChild( 1 ) );
m_hAttributeSlider->SetAutoResize
(
Panel::PIN_TOPLEFT,
Panel::AUTORESIZE_DOWNANDRIGHT,
0, 0,
0, 0
);
}
break;
case LAYOUT_VERTICAL:
{
m_Splitter = new Splitter( this, "AnimSetEditorMainSplitter", SPLITTER_MODE_VERTICAL, 2 );
m_Splitter->SetSplitterColor( Color(32, 32, 32, 255) );
m_Splitter->SetAutoResize
(
Panel::PIN_TOPLEFT,
Panel::AUTORESIZE_DOWNANDRIGHT,
0, ANIMATION_SET_EDITOR_BUTTONTRAY_HEIGHT,
0, 0
);
m_Splitter->SetBounds( 0, ANIMATION_SET_EDITOR_BUTTONTRAY_HEIGHT, GetWide(), GetTall() - ANIMATION_SET_EDITOR_BUTTONTRAY_HEIGHT );
for ( int i = 0; i < list.Count(); ++i )
{
list[ i ]->SetParent( m_Splitter->GetChild( i ) );
list[ i ]->SetSize( m_Splitter->GetChild( i )->GetWide(), m_Splitter->GetChild( i )->GetTall() );
list[ i ]->SetAutoResize
(
Panel::PIN_TOPLEFT,
Panel::AUTORESIZE_DOWNANDRIGHT,
0, 0,
0, 0
);
}
m_Splitter->EvenlyRespaceSplitters();
}
break;
case LAYOUT_HORIZONTAL:
{
m_Splitter = new Splitter( this, "AnimSetEditorMainSplitter", SPLITTER_MODE_HORIZONTAL, 2 );
m_Splitter->SetSplitterColor( Color(32, 32, 32, 255) );
m_Splitter->SetAutoResize
(
Panel::PIN_TOPLEFT,
Panel::AUTORESIZE_DOWNANDRIGHT,
0, ANIMATION_SET_EDITOR_BUTTONTRAY_HEIGHT,
0, 0
);
m_Splitter->SetBounds( 0, ANIMATION_SET_EDITOR_BUTTONTRAY_HEIGHT, GetWide(), GetTall() - ANIMATION_SET_EDITOR_BUTTONTRAY_HEIGHT );
for ( int i = 0; i < list.Count(); ++i )
{
list[ i ]->SetParent( m_Splitter->GetChild( i ) );
list[ i ]->SetSize( m_Splitter->GetChild( i )->GetWide(), m_Splitter->GetChild( i )->GetTall() );
list[ i ]->SetAutoResize
(
Panel::PIN_TOPLEFT,
Panel::AUTORESIZE_DOWNANDRIGHT,
0, 0,
0, 0
);
}
m_Splitter->EvenlyRespaceSplitters();
}
break;
}
if ( sub )
{
sub->OnSizeChanged( sub->GetWide(), sub->GetTall() );
sub->EvenlyRespaceSplitters();
}
}
void CBaseAnimationSetEditor::OnChangeLayout( int value )
{
ChangeLayout( ( EAnimSetLayout_t )value );
}
void CBaseAnimationSetEditor::OnOpenContextMenu( KeyValues *params )
{
if ( m_hContextMenu.Get() )
{
delete m_hContextMenu.Get();
m_hContextMenu = NULL;
}
m_hContextMenu = new Menu( this, "ActionMenu" );
m_hContextMenu->AddMenuItem( "#BxAnimSetSplitLayout", new KeyValues( "OnChangeLayout", "value", (int)LAYOUT_SPLIT ), this );
m_hContextMenu->AddMenuItem( "#BxAnimSetVerticalLayout", new KeyValues( "OnChangeLayout", "value", (int)LAYOUT_VERTICAL ), this );
m_hContextMenu->AddMenuItem( "#BxAnimSetHorizontalLayout", new KeyValues( "OnChangeLayout", "value", (int)LAYOUT_HORIZONTAL ), this );
Panel *rpanel = reinterpret_cast< Panel * >( params->GetPtr( "contextlabel" ) );
if ( rpanel )
{
// force the menu to compute required width/height
m_hContextMenu->PerformLayout();
m_hContextMenu->PositionRelativeToPanel( rpanel, Menu::DOWN, 0, true );
}
else
{
Menu::PlaceContextMenu( this, m_hContextMenu.Get() );
}
}
void CBaseAnimationSetEditor::OpenTreeViewContextMenu( KeyValues *pItemData )
{
}
void CBaseAnimationSetEditor::ApplySchemeSettings( vgui::IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
// Have to manually apply settings here if they aren't attached in hierarchy
if ( m_hControlGroup->GetParent() != this )
{
m_hControlGroup->ApplySchemeSettings( pScheme );
}
if ( m_hPresetFader->GetParent() != this )
{
m_hPresetFader->ApplySchemeSettings( pScheme );
}
if ( m_hAttributeSlider->GetParent() != this )
{
m_hAttributeSlider->ApplySchemeSettings( pScheme );
}
}
CBaseAnimSetControlGroupPanel *CBaseAnimationSetEditor::GetControlGroup()
{
return m_hControlGroup.Get();
}
CBaseAnimSetPresetFaderPanel *CBaseAnimationSetEditor::GetPresetFader()
{
return m_hPresetFader.Get();
}
CBaseAnimSetAttributeSliderPanel *CBaseAnimationSetEditor::GetAttributeSlider()
{
return m_hAttributeSlider.Get();
}
void CBaseAnimationSetEditor::OnControlsAddedOrRemoved()
{
m_pController->OnControlsAddedOrRemoved();
if ( m_hControlGroup )
{
m_hControlGroup->OnControlsAddedOrRemoved();
}
if ( m_hAttributeSlider )
{
m_hAttributeSlider->OnControlsAddedOrRemoved();
}
}
void CBaseAnimationSetEditor::ChangeAnimationSetClip( CDmeFilmClip *pFilmClip )
{
m_pController->ChangeAnimationSetClip( pFilmClip );
if ( m_hControlGroup )
{
m_hControlGroup->ChangeAnimationSetClip( pFilmClip );
}
if ( m_hAttributeSlider )
{
m_hAttributeSlider->ChangeAnimationSetClip( pFilmClip );
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,91 @@
//====== Copyright © 1996-2005, 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);
}
}

View File

@@ -0,0 +1,127 @@
//====== Copyright © 1996-2005, 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();
}
}

View File

@@ -0,0 +1,363 @@
//====== Copyright © 1996-2005, 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 );
}
//-----------------------------------------------------------------------------
// 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 );
}
}
bool CBaseAttributePanel::GetAttributeValueAsString( char *pBuf, int nLength )
{
CDmElement *pElement = m_hObject.Get();
if ( !pElement )
{
*pBuf = '\0';
return false;
}
if ( m_nArrayIndex < 0 )
{
pElement->GetValueAsString( m_szAttributeName, pBuf, nLength );
}
else
{
CDmrGenericArray array( pElement, m_szAttributeName );
array.GetAsString( m_nArrayIndex, pBuf, nLength );
}
return true;
}
CDmAttribute *CBaseAttributePanel::GetAttribute()
{
CDmElement *pElement = m_hObject.Get();
if ( !pElement )
return NULL;
return pElement->GetAttribute( m_szAttributeName );
}
//-----------------------------------------------------------------------------
// 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;
}
void CBaseAttributePanel::GetPickerBounds( int *x, int *y, int *w, int *h )
{
int viewX, viewY, viewWidth, viewHeight;
GetBounds( viewX, viewY, viewWidth, viewHeight );
*x = ColumnBorderWidth;
*w = PickerWidth;
*y = MAX(0, ceil((viewHeight - PickerHeight) * 0.5)) + 1;
*h = PickerHeight;
}
//-----------------------------------------------------------------------------
// Creates a widget using editor attribute info
//-----------------------------------------------------------------------------
void CBaseAttributePanel::PerformLayout()
{
BaseClass::PerformLayout();
vgui::Panel *valuePanel = GetDataPanel();
if ( valuePanel && HasFlag( HIDEVALUE ) )
{
valuePanel->SetVisible( false );
}
vgui::Panel *typePanel = m_pType;
if ( typePanel && HasFlag( HIDETYPE ) )
{
typePanel->SetVisible( false );
}
int viewWidth, viewHeight;
GetSize( viewWidth, viewHeight );
if( typePanel->IsVisible() && valuePanel->IsVisible() )
{
valuePanel->SetBounds(
FirstColumnWidth,
1,
viewWidth - FirstColumnWidth - ColumnBorderWidth - TypeColumnWidth - ColumnBorderWidth,
viewHeight );
typePanel->SetBounds(
viewWidth - TypeColumnWidth,
1,
TypeColumnWidth,
viewHeight );
}
else if( typePanel->IsVisible() )
{
typePanel->SetBounds( FirstColumnWidth, 1, viewWidth - FirstColumnWidth - ColumnBorderWidth - ColumnBorderWidth, viewHeight);
}
else if( valuePanel->IsVisible() )
{
valuePanel->SetBounds( FirstColumnWidth, 1, viewWidth - FirstColumnWidth - ColumnBorderWidth - ColumnBorderWidth, viewHeight);
}
}
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 );
}
}
}

View File

@@ -0,0 +1,370 @@
//========= Copyright © 1996-2005, 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.999", 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 ];
_snwprintf( pFormat, ARRAYSIZE( pFormat ), L"%%.%df", nDecimalPlaces );
wchar_t wstring[ 32 ];
_snwprintf( wstring, ARRAYSIZE( 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 ];
_snwprintf( pFormat, ARRAYSIZE( pFormat ), L"%%.%df", nDecimalPlaces );
wchar_t wstring[ 32 ];
_snwprintf( wstring, ARRAYSIZE( 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 );
}
surface()->DrawLine( x-1, y, x+1, y );
surface()->DrawLine( x, y-1, x, y+1 );
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 );
}

View File

@@ -0,0 +1,488 @@
//====== Copyright © 1996-2005, 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 );
}

View File

@@ -0,0 +1,143 @@
//====== Copyright © 1996-2005, 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

View File

@@ -0,0 +1,58 @@
//====== Copyright © 1996-2005, 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;
}

View File

@@ -0,0 +1,49 @@
//========= Copyright © 1996-2002, Valve LLC, 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

View File

@@ -0,0 +1,616 @@
//====== Copyright © 1996-2005, 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->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->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() );
}

View File

@@ -0,0 +1,334 @@
// ----------------------------------------- //
// File generated by VPC //
// ----------------------------------------- //
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\2DSlider.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\2DSlider.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\2DSlider.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AssetBuilder.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AssetBuilder.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AssetBuilder.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\attributeassetpickerpanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\attributeassetpickerpanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\attributeassetpickerpanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeBasePickerPanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeBasePickerPanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeBasePickerPanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeBoolChoicePanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeBoolChoicePanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeBoolChoicePanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\attributebooleanpanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\attributebooleanpanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\attributebooleanpanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeColorPickerPanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeColorPickerPanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeColorPickerPanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\attributedetailtypepickerpanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\attributedetailtypepickerpanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\attributedetailtypepickerpanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeElementPanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeElementPanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeElementPanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeElementPickerPanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeElementPickerPanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeElementPickerPanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeFilePickerPanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeFilePickerPanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeFilePickerPanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeIntChoicePanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeIntChoicePanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeIntChoicePanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeInterpolatorChoicePanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeInterpolatorChoicePanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeInterpolatorChoicePanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeMDLPickerPanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeMDLPickerPanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeMDLPickerPanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeSequencePickerPanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeSequencePickerPanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeSequencePickerPanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\attributeshaderpickerpanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\attributeshaderpickerpanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\attributeshaderpickerpanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\attributesheetsequencepickerpanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\attributesheetsequencepickerpanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\attributesheetsequencepickerpanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeSoundPickerPanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeSoundPickerPanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeSoundPickerPanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeStringChoicePanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeStringChoicePanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeStringChoicePanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\attributesurfacepropertypickerpanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\attributesurfacepropertypickerpanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\attributesurfacepropertypickerpanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeTextEntry.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeTextEntry.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeTextEntry.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeTextPanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeTextPanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeTextPanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeWidgetFactory.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeWidgetFactory.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\AttributeWidgetFactory.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\BaseAttributeChoicePanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\BaseAttributeChoicePanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\BaseAttributeChoicePanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\BaseAttributeDoubleChoicePanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\BaseAttributeDoubleChoicePanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\BaseAttributeDoubleChoicePanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\BaseAttributePanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\BaseAttributePanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\BaseAttributePanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\ChannelGraphPanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\ChannelGraphPanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\ChannelGraphPanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\common\debug_lib_check.cpp
Debug output file: F:\csgo_64\cstrike15_src\common\debug_lib_check.cpp
Release output file: F:\csgo_64\cstrike15_src\common\debug_lib_check.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\dmecombinationsystemeditorpanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\dmecombinationsystemeditorpanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\dmecombinationsystemeditorpanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\dmecontrols.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\dmecontrols.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\dmecontrols.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\dmedageditpanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\dmedageditpanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\dmedageditpanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\dmedagrenderpanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\dmedagrenderpanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\dmedagrenderpanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\dmelogeditpanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\dmelogeditpanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\dmelogeditpanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\dmemdlpanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\dmemdlpanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\dmemdlpanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\dmepanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\dmepanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\dmepanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\dmepicker.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\dmepicker.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\dmepicker.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\dmepresetgroupeditorpanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\dmepresetgroupeditorpanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\dmepresetgroupeditorpanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\DmeSourceDCCFilePanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\DmeSourceDCCFilePanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\DmeSourceDCCFilePanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\DmeSourceSkinPanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\DmeSourceSkinPanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\DmeSourceSkinPanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\ElementPropertiesTree.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\ElementPropertiesTree.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\ElementPropertiesTree.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\FileListManager.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\FileListManager.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\FileListManager.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\filtercombobox.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\filtercombobox.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\filtercombobox.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\particlesystempanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\particlesystempanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\particlesystempanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\particlesystempropertiespanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\particlesystempropertiespanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\particlesystempropertiespanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\sheeteditorpanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\sheeteditorpanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\sheeteditorpanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\soundpicker.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\soundpicker.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\soundpicker.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\soundrecordpanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\soundrecordpanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\soundrecordpanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\attributeslider.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\attributeslider.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\attributeslider.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\BaseAnimationSetEditor.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\BaseAnimationSetEditor.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\BaseAnimationSetEditor.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\BaseAnimationSetEditorController.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\BaseAnimationSetEditorController.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\BaseAnimationSetEditorController.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\BaseAnimSetAttributeSliderPanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\BaseAnimSetAttributeSliderPanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\BaseAnimSetAttributeSliderPanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\BaseAnimSetControlGroupPanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\BaseAnimSetControlGroupPanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\BaseAnimSetControlGroupPanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\BaseAnimSetPresetFaderPanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\BaseAnimSetPresetFaderPanel.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\BaseAnimSetPresetFaderPanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\public\phonemeconverter.cpp
Debug output file: F:\csgo_64\cstrike15_src\public\phonemeconverter.cpp
Release output file: F:\csgo_64\cstrike15_src\public\phonemeconverter.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\presetpicker.cpp
Debug output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\presetpicker.cpp
Release output file: F:\csgo_64\cstrike15_src\vgui2\dme_controls\presetpicker.cpp
Containing unity file:
PCH file:

View File

@@ -0,0 +1,101 @@
//====== Copyright © 1996-2005, 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/TGAPicker.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" );
IMPLEMENT_ATTRIBUTE_ASSET_PREVIEW_PICKER( CAttributeTgaPickerPanel, CTGAPickerFrame, "Select .TGA file" );
void CAttributeVmtPickerPanel::OnAssetSelected( KeyValues *kv )
{
BaseClass::OnAssetSelected(kv);
int nSheetSequenceCount = kv->GetInt( "sheet_sequence_count" );
int nSheetSequenceNum = kv->GetInt( "sheet_sequence_number" );
int nSecondSheetSequenceNum = kv->GetInt( "sheet_sequence_secondary_number" );
if ( nSheetSequenceCount > 0 )
{
CUndoScopeGuard guard( 0, NOTIFY_SETDIRTYFLAG, GetNotify(), "Auto-Set Sequence from VMT dialog" );
// selected a VMT that uses sheet information
CDmElement* pElement = GetPanelElement();
CDmAttribute* pSeqNumberAttr = pElement->GetAttribute("sequence_number");
if ( pSeqNumberAttr )
{
pSeqNumberAttr->SetValue(nSheetSequenceNum);
}
CDmAttribute* pSecondSeqNumberAttr = pElement->GetAttribute("sequence_number 1");
if ( pSecondSeqNumberAttr )
{
pSecondSeqNumberAttr->SetValue(nSecondSheetSequenceNum);
}
}
}
//-----------------------------------------------------------------------------
// 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();
}
}

View File

@@ -0,0 +1,73 @@
//============ Copyright (c) Valve Corporation, All rights reserved. ============
#include "dme_controls/attributebooleanpanel.h"
#include "dme_controls/AttributeTextEntry.h"
#include "dme_controls/AttributeWidgetFactory.h"
#include "tier1/KeyValues.h"
#include "datamodel/dmelement.h"
#include "movieobjects/dmeeditortypedictionary.h"
#include "movieobjects/dmechannel.h"
#include "dme_controls/inotifyui.h"
#include "vgui_controls/CheckButton.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
CAttributeBooleanPanel::CAttributeBooleanPanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
BaseClass( parent, info )
{
m_pValueButton = new vgui::CheckButton( this, "", "" );
m_pValueButton->AddActionSignalTarget( this );
}
//-----------------------------------------------------------------------------
void CAttributeBooleanPanel::ApplySchemeSettings(IScheme *pScheme)
{
// Need to override the scheme settings for this button
BaseClass::ApplySchemeSettings( pScheme );
m_pValueButton->SetBorder(NULL);
m_pValueButton->SetPaintBorderEnabled( false );
// Hack to get rid of the checkbox offset of &!^@#% 6
// m_pValueButton->SetImage( vgui::scheme()->GetImage( "tools/ifm/icon_properties_linkarrow" , false), 0);
m_pValueButton->SetImageAtIndex( 0, m_pValueButton->GetImageAtIndex( 0 ), 0 );
}
void CAttributeBooleanPanel::OnCheckButtonChecked( int state )
{
bool attributeValue = GetAttributeValue< bool>();
bool buttonValue = (state == 1);
if( buttonValue != attributeValue )
{
SetAttributeValue( state );
Refresh();
}
}
void CAttributeBooleanPanel::Refresh()
{
BaseClass::Refresh();
bool myValue = GetAttributeValue< bool>();
if( myValue != m_pValueButton->IsSelected() )
{
m_pValueButton->SetSelected( myValue );
}
}
void CAttributeBooleanPanel::PerformLayout()
{
BaseClass::PerformLayout();
int viewWidth, viewHeight;
GetSize( viewWidth, viewHeight );
m_pValueButton->SetBounds( (FirstColumnWidth - ColumnBorderWidth - 16) * 0.5 , ( viewHeight - 16 )* 0.5 , 16, 16 );
}

View File

@@ -0,0 +1,88 @@
//====== Copyright © 1996-2005, 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();
}
}

View File

@@ -0,0 +1,77 @@
//====== Copyright © 1996-2005, 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();
}
}

View File

@@ -0,0 +1,140 @@
//======= Copyright (c) 1996-2009, Valve Corporation, All rights reserved. ======
//
// CAttributeSheetSequencePickerPanel - Panel for editing int attributes that select a sprite sheet sequence
//
//===============================================================================
#include "dme_controls/attributesheetsequencepickerpanel.h"
#include "FileSystem.h"
#include "vgui_controls/MenuButton.h"
#include "vgui_controls/FileOpenDialog.h"
#include "dme_controls/AttributeTextEntry.h"
#include "matsys_controls/sheetsequencepanel.h"
#include "movieobjects/dmeparticlesystemdefinition.h"
#include "tier1/keyvalues.h"
#include "dme_controls/AttributeWidgetFactory.h"
#include "movieobjects/dmeeditortypedictionary.h"
// NOTE: This has to be the last file included!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
//
// CNotifyMenuButton - MenuButton with a notify before the menu is shown
//
//-----------------------------------------------------------------------------
class CNotifyMenuButton: public vgui::MenuButton
{
DECLARE_CLASS_SIMPLE( CNotifyMenuButton, vgui::MenuButton );
public:
CNotifyMenuButton(CAttributeSheetSequencePickerPanel *parent, const char *panelName, const char *text);
virtual void OnShowMenu(Menu *menu);
private:
CAttributeSheetSequencePickerPanel* m_pParent;
};
CNotifyMenuButton::CNotifyMenuButton(CAttributeSheetSequencePickerPanel *parent, const char *panelName, const char *text):
BaseClass(parent,panelName,text)
{
m_pParent = parent;
}
void CNotifyMenuButton::OnShowMenu(Menu *menu)
{
if ( m_pParent )
{
m_pParent->UpdateSheetPanel();
}
BaseClass::OnShowMenu(menu);
}
//-----------------------------------------------------------------------------
//
// CAttributeSheetSequencePickerPanel
//
//-----------------------------------------------------------------------------
CAttributeSheetSequencePickerPanel::CAttributeSheetSequencePickerPanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
BaseClass( parent, info )
{
if ( info.m_pEditorInfo )
{
m_bIsSecondView = !V_stricmp( info.m_pEditorInfo->GetWidgetName(), "sheetsequencepicker_second" );
}
else
{
m_bIsSecondView = false;
}
m_pSheetPanel = new CSheetSequencePanel(this, "sheetsequencepanel");
m_pSheetPanel->AddActionSignalTarget( this );
m_pSequenceSelection = new CNotifyMenuButton( this, "SequenceSelection", "seq" );
m_pSequenceSelection->SetMenu( m_pSheetPanel );
m_pSheetPanel->AddActionSignalTarget( this );
UpdateSheetPanel();
}
void CAttributeSheetSequencePickerPanel::UpdateSheetPanel()
{
CDmElement* pElement = GetPanelElement();
CDmAttribute* pMaterialAttr = pElement->GetAttribute("material");
if ( m_bIsSecondView )
{
m_pSheetPanel->SetSecondSequenceView( true );
m_pSequenceSelection->SetText( "sq2" );
}
if ( pMaterialAttr == NULL )
{
pElement = FindReferringElement< CDmeParticleSystemDefinition >( pElement, "initializers" );
if ( pElement )
{
pMaterialAttr = pElement->GetAttribute("material");
}
}
if ( pMaterialAttr )
{
m_pSheetPanel->SetFromMaterialName( pMaterialAttr->GetValueString() );
}
}
CAttributeSheetSequencePickerPanel::~CAttributeSheetSequencePickerPanel()
{
}
void CAttributeSheetSequencePickerPanel::OnSheetSequenceSelected( int nSequenceNumber )
{
CUndoScopeGuard guard( 0, NOTIFY_SETDIRTYFLAG, GetNotify(), "Select Sheet Sequence" );
SetAttributeValue(nSequenceNumber);
}
// MOC_TODO: factor this somewhere else - shared with other attribute controls
void CAttributeSheetSequencePickerPanel::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_pSequenceSelection->SetBounds( x, y, inset, h );
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,103 @@
//====== Copyright © 1996-2005, 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();
}
}

View File

@@ -0,0 +1,142 @@
//-----------------------------------------------------------------------------
// 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\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\attributebooleanpanel.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\attributesheetsequencepickerpanel.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\sheeteditorpanel.h"
$File "$SRCDIR\public\dme_controls\soundpicker.h"
$File "$SRCDIR\public\dme_controls\soundrecordpanel.h"
$File "$SRCDIR\public\dme_controls\2DSlider.h"
}
$Folder "Source Files"
{
$File "AssetBuilder.cpp"
$File "attributeassetpickerpanel.cpp"
$File "AttributeBasePickerPanel.cpp"
$File "AttributeBoolChoicePanel.cpp"
$File "attributebooleanpanel.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 "attributesheetsequencepickerpanel.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 "sheeteditorpanel.cpp"
$File "soundpicker.cpp"
$File "soundrecordpanel.cpp"
$File "2DSlider.cpp"
$Folder "Animation Set Editor"
{
$File "$SRCDIR\public\dme_controls\attributeslider.h"
$File "attributeslider.cpp"
$File "BaseAnimationSetEditorController.cpp"
$File "$SRCDIR\public\dme_controls\BaseAnimationSetEditorController.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 "presetpicker.cpp"
$File "$SRCDIR\public\dme_controls\presetpicker.h"
$File "$SRCDIR\public\dme_controls\RecordingState.h"
$File "$SRCDIR\public\phonemeconverter.cpp"
}
}
}

View File

@@ -0,0 +1,13 @@
"vpc_cache"
{
"CacheVersion" "1"
"win32"
{
"CRCFile" "dme_controls.vcxproj.vpc_crc"
"OutputFiles"
{
"0" "dme_controls.vcxproj"
"1" "dme_controls.vcxproj.filters"
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,103 @@
//===== Copyright © 1996-2005, 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"
#include "tier3/tier3.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

View File

@@ -0,0 +1,984 @@
//========= Copyright © 1996-2001, Valve LLC, All rights reserved. ============
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
#include "vstdlib/random.h"
#include "dme_controls/dmedageditpanel.h"
#include "dme_controls/dmedagrenderpanel.h"
#include "dme_controls/dmepanel.h"
#include "vgui_controls/Button.h"
#include "vgui_controls/Splitter.h"
#include "vgui_controls/PropertySheet.h"
#include "vgui_controls/PropertyPage.h"
#include "vgui_controls/Label.h"
#include "vgui_controls/ScrollBar.h"
#include "vgui_controls/Slider.h"
#include "vgui_controls/ScrollableEditablePanel.h"
#include "vgui_controls/ListPanel.h"
#include "vgui_controls/Image.h"
#include "vgui_controls/TextImage.h"
#include "vgui/isurface.h"
#include "vgui/ischeme.h"
#include "vgui/iinput.h"
#include "vgui/ivgui.h"
#include "vgui/cursor.h"
#include "movieobjects/dmemakefile.h"
#include "movieobjects/dmemdlmakefile.h"
#include "movieobjects/dmedccmakefile.h"
#include "movieobjects/dmedag.h"
#include "movieobjects/dmeclip.h"
#include "movieobjects/dmeanimationlist.h"
#include "movieobjects/dmecombinationoperator.h"
#include "movieobjects/dmeanimationset.h"
#include "movieobjects/dmeflexrules.h"
#include "tier1/keyvalues.h"
#include "materialsystem/imesh.h"
#include "dme_controls/BaseAnimationSetEditor.h"
#include "dme_controls/BaseAnimationSetEditorController.h"
#include "dme_controls/BaseAnimSetAttributeSliderPanel.h"
//-----------------------------------------------------------------------------
//
// Hook into the dme panel editor system
//
//-----------------------------------------------------------------------------
IMPLEMENT_DMEPANEL_FACTORY( CDmeDagEditPanel, DmeDag, "DmeDagPreview2", "DmeDag Previewer 2", false );
IMPLEMENT_DMEPANEL_FACTORY( CDmeDagEditPanel, DmeSourceSkin, "DmeSourceSkinPreview2", "MDL Skin Previewer 2", false );
IMPLEMENT_DMEPANEL_FACTORY( CDmeDagEditPanel, DmeSourceAnimation, "DmeSourceAnimationPreview2", "MDL Animation Previewer 2", false );
IMPLEMENT_DMEPANEL_FACTORY( CDmeDagEditPanel, DmeDCCMakefile, "DmeMakeFileOutputPreview2", "DCC MakeFile Output Previewer 2", false );
//-----------------------------------------------------------------------------
// Slider panel
//-----------------------------------------------------------------------------
class CDmeAnimationListPanel : public vgui::EditablePanel
{
DECLARE_CLASS_SIMPLE( CDmeAnimationListPanel, vgui::EditablePanel );
public:
// constructor, destructor
CDmeAnimationListPanel( vgui::Panel *pParent, const char *pName );
virtual ~CDmeAnimationListPanel();
void SetAnimationList( CDmeAnimationList *pList );
void RefreshAnimationList();
const char *GetSelectedAnimation() const;
private:
// Called when the selection changes moves
MESSAGE_FUNC( OnItemSelected, "ItemSelected" );
MESSAGE_FUNC( OnItemDeselected, "ItemDeselected" );
vgui::ListPanel *m_pAnimationList;
CDmeHandle< CDmeAnimationList > m_hAnimationList;
};
static int __cdecl AnimationNameSortFunc( 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 );
}
//-----------------------------------------------------------------------------
// constructor, destructor
//-----------------------------------------------------------------------------
CDmeAnimationListPanel::CDmeAnimationListPanel( vgui::Panel *pParent, const char *pName ) :
BaseClass( pParent, pName )
{
m_pAnimationList = new vgui::ListPanel( this, "AnimationList" );
m_pAnimationList->AddColumnHeader( 0, "name", "name", 100, 0 );
m_pAnimationList->AddActionSignalTarget( this );
m_pAnimationList->SetSortFunc( 0, AnimationNameSortFunc );
m_pAnimationList->SetSortColumn( 0 );
m_pAnimationList->SetEmptyListText("No animations");
m_pAnimationList->SetMultiselectEnabled( false );
LoadControlSettingsAndUserConfig( "resource/dmeanimationlistpanel.res" );
}
CDmeAnimationListPanel::~CDmeAnimationListPanel()
{
}
//-----------------------------------------------------------------------------
// Sets the combination operator
//-----------------------------------------------------------------------------
void CDmeAnimationListPanel::SetAnimationList( CDmeAnimationList *pList )
{
if ( pList != m_hAnimationList.Get() )
{
m_hAnimationList = pList;
RefreshAnimationList();
}
}
//-----------------------------------------------------------------------------
// Builds the list of animations
//-----------------------------------------------------------------------------
void CDmeAnimationListPanel::RefreshAnimationList()
{
m_pAnimationList->RemoveAll();
if ( !m_hAnimationList.Get() )
return;
int nCount = m_hAnimationList->GetAnimationCount();
for ( int i = 0; i < nCount; ++i )
{
CDmeChannelsClip *pAnimation = m_hAnimationList->GetAnimation( i );
KeyValues *pItemKeys = new KeyValues( "node", "name", pAnimation->GetName() );
m_pAnimationList->AddItem( pItemKeys, 0, false, false );
}
m_pAnimationList->SortList();
}
//-----------------------------------------------------------------------------
// Returns the selected animation
//-----------------------------------------------------------------------------
const char *CDmeAnimationListPanel::GetSelectedAnimation() const
{
if ( m_pAnimationList->GetSelectedItemsCount() == 0 )
return "";
int nIndex = m_pAnimationList->GetSelectedItem( 0 );
KeyValues *pItemKeyValues = m_pAnimationList->GetItem( nIndex );
return pItemKeyValues->GetString( "name" );
}
//-----------------------------------------------------------------------------
// Called when an animation is selected or deselected
//-----------------------------------------------------------------------------
void CDmeAnimationListPanel::OnItemSelected( )
{
const char *pAnimationName = GetSelectedAnimation();
PostActionSignal( new KeyValues( "AnimationSelected", "animationName", pAnimationName ) );
}
void CDmeAnimationListPanel::OnItemDeselected( )
{
PostActionSignal( new KeyValues( "AnimationDeselected" ) );
}
class CCombinationOperatorControl : public CBaseAnimationSetControl
{
public:
CCombinationOperatorControl() {}
virtual void ChangeAnimationSetClip( CDmeFilmClip *pFilmClip )
{
RebuildControlList( m_FullControlList, pFilmClip );
CBaseAnimationSetControl::ChangeAnimationSetClip( pFilmClip );
}
virtual void OnControlsAddedOrRemoved()
{
RemoveNullControls( m_FullControlList );
AddMissingControls( m_FullControlList, m_hFilmClip );
CBaseAnimationSetControl::OnControlsAddedOrRemoved();
}
protected:
virtual SelectionInfo_t *FindSelectionInfoForControl( const CDmElement *pControl )
{
return ::FindSelectionInfoForControl( m_FullControlList, pControl );
}
CUtlVector< SelectionInfo_t* > m_FullControlList;
};
class CDmeCombinationOperatorPanel : public CBaseAnimationSetEditor
{
DECLARE_CLASS_SIMPLE( CDmeCombinationOperatorPanel, CBaseAnimationSetEditor );
public:
CDmeCombinationOperatorPanel( vgui::Panel *parent, const char *panelName, CBaseAnimationSetControl *pAnimationSetController );
virtual ~CDmeCombinationOperatorPanel();
virtual void OnTick();
void SetCombinationOperator( CDmeCombinationOperator *pOp );
void RefreshCombinationOperator();
private:
void CreateFakeAnimationSet( );
void DestroyFakeAnimationSet( );
// Adds new controls to the animation set
void AddNewAnimationSetControls();
// Removes a controls from all presets
void RemoveAnimationControlFromPresets( const char *pControlName );
// Removes controls from the animation set that aren't used
void RemoveUnusedAnimationSetControls();
// Modify controls in the presets which have had stereo settings changed
void ModifyExistingAnimationSetControls();
// Modify controls in the presets which have had stereo settings changed
void ModifyExistingAnimationSetPresets( CDmElement *pControlElement );
// Modify controls which have had stereo settings changed
void ModifyExistingAnimationSetControl( CDmElement *pControlElement );
void RefreshAnimationSet();
// Sort control names to match the combination controls
void SortAnimationSetControls();
CDmeHandle< CDmeCombinationOperator > m_hCombinationOperator;
CUtlVector< IDmeOperator * > m_operatorList;
};
//-----------------------------------------------------------------------------
// Constructor/destructor
//-----------------------------------------------------------------------------
CDmeCombinationOperatorPanel::CDmeCombinationOperatorPanel( vgui::Panel *parent, const char *panelName, CBaseAnimationSetControl *pAnimationSetController ) :
BaseClass( parent, panelName, pAnimationSetController )
{
CreateFakeAnimationSet();
vgui::ivgui()->AddTickSignal( GetVPanel(), 0 );
}
CDmeCombinationOperatorPanel::~CDmeCombinationOperatorPanel()
{
DestroyFakeAnimationSet();
}
//-----------------------------------------------------------------------------
// Create, destroy fake animation sets
//-----------------------------------------------------------------------------
void CDmeCombinationOperatorPanel::CreateFakeAnimationSet()
{
CDmeFilmClip *pFilmClip = CreateElement< CDmeFilmClip >( "fakeFilmClip", DMFILEID_INVALID );
CDmeAnimationSet *pAnimSet = CreateElement< CDmeAnimationSet >( "fakeAnimSet", DMFILEID_INVALID );
pAnimSet->SetValue( "gameModel", DMELEMENT_HANDLE_INVALID );
pFilmClip->GetAnimationSets().AddToTail( pAnimSet );
g_pDataModel->DontAutoDelete( pFilmClip->GetHandle() );
ChangeAnimationSetClip( pFilmClip );
}
void CDmeCombinationOperatorPanel::DestroyFakeAnimationSet( )
{
DestroyElement( m_pController->GetAnimationSetClip(), TD_DEEP );
}
//-----------------------------------------------------------------------------
// Sets combination ops + animation sets
//-----------------------------------------------------------------------------
void CDmeCombinationOperatorPanel::SetCombinationOperator( CDmeCombinationOperator *pOp )
{
// The Animation Set Editor Doesn't Handle Passing The Same Animation Set With
// Different Data In It Very Well
DestroyFakeAnimationSet();
CreateFakeAnimationSet();
m_operatorList.RemoveAll();
if ( pOp != m_hCombinationOperator.Get() )
{
m_hCombinationOperator = pOp;
m_operatorList.AddToTail( m_hCombinationOperator );
for ( int i = 0; i < pOp->GetOperationTargetCount(); ++i )
{
CDmeFlexRules *pDmeFlexRules = CastElement< CDmeFlexRules >( pOp->GetOperationTarget( i ) );
if ( !pDmeFlexRules )
continue;
m_operatorList.AddToTail( pDmeFlexRules );
for ( int j = 0; j < pDmeFlexRules->GetRuleCount(); ++j )
{
CDmeFlexRuleBase *pDmeFlexRule = pDmeFlexRules->GetRule( j );
if ( !pDmeFlexRule )
continue;
m_operatorList.AddToTail( pDmeFlexRule );
}
}
RefreshCombinationOperator();
}
}
//-----------------------------------------------------------------------------
// Removes a controls from all presets
//-----------------------------------------------------------------------------
void CDmeCombinationOperatorPanel::RemoveAnimationControlFromPresets( const char *pControlName )
{
// TODO - we should be storing which animationset an item is associated with
CAnimSetGroupAnimSetTraversal traversal( m_pController->GetAnimationSetClip() );
CDmeAnimationSet *pAnimationSet = traversal.Next();
Assert( !traversal.IsValid() );
CDmrElementArray< CDmePresetGroup > presetGroupList = pAnimationSet->GetPresetGroups();
int nPresetGroupCount = presetGroupList.Count();
for ( int i = 0; i < nPresetGroupCount; ++i )
{
CDmePresetGroup *pPresetGroup = presetGroupList[ i ];
CDmrElementArray< CDmePreset > presetList = pPresetGroup->GetPresets();
int nPresetCount = presetList.Count();
for ( int j = 0; j < nPresetCount; ++j )
{
CDmePreset *pPreset = presetList[ j ];
CDmrElementArray<> controlValues = pPreset->GetControlValues();
int nControlCount = controlValues.Count();
for ( int k = 0; k < nControlCount; ++k )
{
CDmElement *v = controlValues[ k ];
if ( !Q_stricmp( v->GetName(), pControlName ) )
{
controlValues.FastRemove( k );
break;
}
}
}
}
}
//-----------------------------------------------------------------------------
// Removes controls from the animation set that aren't used
//-----------------------------------------------------------------------------
void CDmeCombinationOperatorPanel::RemoveUnusedAnimationSetControls()
{
// TODO - we should be storing which animationset an item is associated with
CAnimSetGroupAnimSetTraversal traversal( m_pController->GetAnimationSetClip() );
CDmeAnimationSet *pAnimationSet = traversal.Next();
Assert( !traversal.IsValid() );
CDmrElementArray< > controls = pAnimationSet->GetControls();
// Remove all controls in the animation set and in presets that don't exist in the combination system
int nAnimSetCount = controls.Count();
for ( int i = nAnimSetCount; --i >= 0; )
{
CDmElement *pControlElement = controls[i];
if ( !pControlElement )
continue;
// Don't do any of this work for transforms
if ( IsTransformControl( pControlElement ) )
continue;
const char *pControlName = pControlElement->GetName();
// Look for a match
if ( FindComboOpControlIndexForAnimSetControl( m_hCombinationOperator, pControlName ) >= 0 )
continue;
// No match, blow the control away.
RemoveAnimationControlFromPresets( pControlName );
pAnimationSet->RemoveControlFromGroups( pControlName );
controls.FastRemove( i );
}
}
//-----------------------------------------------------------------------------
// Modify controls in the presets which have had stereo settings changed
//-----------------------------------------------------------------------------
void CDmeCombinationOperatorPanel::ModifyExistingAnimationSetControl( CDmElement *pControlElement )
{
const char *pControlName = pControlElement->GetName();
// Look for a match
bool bIsMultiControl;
ControlIndex_t nControlIndex = FindComboOpControlIndexForAnimSetControl( m_hCombinationOperator, pControlName, &bIsMultiControl );
Assert( nControlIndex >= 0 );
float flDefaultValue = m_hCombinationOperator->GetControlDefaultValue( nControlIndex );
if ( bIsMultiControl )
{
// multi control can't (currently) be stereo, and so it either exists or it doesn't...
pControlElement->SetValue< float >( "value", m_hCombinationOperator->GetMultiControlLevel( nControlIndex ) );
pControlElement->SetValue( "defaultValue", 0.5f );
}
else
{
bool bIsStereoControl = m_hCombinationOperator->IsStereoControl( nControlIndex );
bool bIsAnimControlStereo = IsStereoControl( pControlElement );
if ( bIsAnimControlStereo != bIsStereoControl )
{
if ( !bIsStereoControl )
{
float flValue = m_hCombinationOperator->GetControlValue( nControlIndex );
pControlElement->SetValue< float >( "value", flValue );
pControlElement->RemoveAttribute( "leftValue" );
pControlElement->RemoveAttribute( "rightValue" );
}
else
{
const Vector2D &value = m_hCombinationOperator->GetStereoControlValue( nControlIndex );
pControlElement->SetValue< float >( "leftValue", value.x );
pControlElement->SetValue< float >( "rightValue", value.y );
pControlElement->RemoveAttribute( "value" );
}
}
pControlElement->SetValue( "defaultValue", flDefaultValue );
}
}
//-----------------------------------------------------------------------------
// Modify controls in the presets which have had stereo settings changed
//-----------------------------------------------------------------------------
void CDmeCombinationOperatorPanel::ModifyExistingAnimationSetPresets( CDmElement *pControlElement )
{
const char *pControlName = pControlElement->GetName();
// TODO - we should be storing which animationset an item is associated with
CAnimSetGroupAnimSetTraversal traversal( m_pController->GetAnimationSetClip() );
CDmeAnimationSet *pAnimationSet = traversal.Next();
Assert( !traversal.IsValid() );
const CDmrElementArray< CDmePresetGroup > &presetGroupList = pAnimationSet->GetPresetGroups();
int nPresetGroupCount = presetGroupList.Count();
for ( int g = 0; g < nPresetGroupCount; ++g )
{
CDmePresetGroup *pPresetGroup = presetGroupList[ g ];
const CDmrElementArray< CDmePreset > &presetList = pPresetGroup->GetPresets();
int nPresetCount = presetList.Count();
for ( int i = 0; i < nPresetCount; ++i )
{
CDmePreset *pPreset = presetList[ i ];
Assert( !pPreset->IsAnimated() ); // deal with this after GDC
if ( pPreset->IsAnimated() )
continue;
const CDmrElementArray< CDmElement > &controlValues = pPreset->GetControlValues( );
int nControlCount = controlValues.Count();
for ( int j = 0; j < nControlCount; ++j )
{
CDmElement *v = controlValues[ j ];
if ( Q_stricmp( v->GetName(), pControlName ) )
continue;
bool bIsAnimControlStereo = IsStereoControl( pControlElement );
if ( bIsAnimControlStereo )
{
float flValue = v->GetValue< float >( "value" );
v->RemoveAttribute( "value" );
v->InitValue( "leftValue", flValue );
v->InitValue( "rightValue", flValue );
}
else
{
float flLeftValue = v->GetValue< float >( "leftValue" );
float flRightValue = v->GetValue< float >( "rightValue" );
v->RemoveAttribute( "leftValue" );
v->RemoveAttribute( "rightValue" );
v->InitValue( "value", MAX( flLeftValue, flRightValue ) ); // TODO - should this be max or average?
}
}
}
}
}
//-----------------------------------------------------------------------------
// Modify controls which have had stereo settings changed
//-----------------------------------------------------------------------------
void CDmeCombinationOperatorPanel::ModifyExistingAnimationSetControls()
{
// TODO - we should be storing which animationset an item is associated with
CAnimSetGroupAnimSetTraversal traversal( m_pController->GetAnimationSetClip() );
CDmeAnimationSet *pAnimationSet = traversal.Next();
Assert( !traversal.IsValid() );
const CDmrElementArray< CDmElement > &controls = pAnimationSet->GetControls();
// Update the main controls; update defaults and add or remove combo + multi data
int nAnimSetCount = controls.Count();
for ( int i = nAnimSetCount; --i >= 0; )
{
CDmElement *pControlElement = controls[i];
if ( !pControlElement )
continue;
// Don't do any of this work for transforms
if ( IsTransformControl( pControlElement ) )
continue;
ModifyExistingAnimationSetControl( pControlElement );
ModifyExistingAnimationSetPresets( pControlElement );
}
}
//-----------------------------------------------------------------------------
// Adds new controls to the animation set
//-----------------------------------------------------------------------------
void CDmeCombinationOperatorPanel::AddNewAnimationSetControls()
{
if ( !m_hCombinationOperator.Get() )
return;
// TODO - we should be storing which animationset an item is associated with
CAnimSetGroupAnimSetTraversal traversal( m_pController->GetAnimationSetClip() );
CDmeAnimationSet *pAnimationSet = traversal.Next();
Assert( !traversal.IsValid() );
CDmaElementArray< > &controls = pAnimationSet->GetControls();
// Remove all controls in the animation set and in presets that don't exist in the combination system
int nFirstControl = controls.Count();
int nCombinationControlCount = m_hCombinationOperator->GetControlCount();
int iCurrentAnimSetControl = 0;
for ( int i = 0; i < nCombinationControlCount; ++i, ++iCurrentAnimSetControl )
{
const char *pControlName = m_hCombinationOperator->GetControlName( i );
if ( !pAnimationSet->FindControl( pControlName ) )
{
bool bIsStereoControl = m_hCombinationOperator->IsStereoControl( i );
float flDefaultValue = m_hCombinationOperator->GetControlDefaultValue( i );
// Add the control to the controls group
CDmElement *pControl = CreateElement< CDmElement >( pControlName, pAnimationSet->GetFileId() );
Assert( pControl );
controls.InsertBefore( iCurrentAnimSetControl, pControl );
if ( bIsStereoControl )
{
const Vector2D &value = m_hCombinationOperator->GetStereoControlValue(i);
pControl->SetValue( "leftValue", value.x );
pControl->SetValue( "rightValue", value.y );
}
else
{
pControl->SetValue( "value", m_hCombinationOperator->GetControlValue(i) );
}
pControl->SetValue( "defaultValue", flDefaultValue );
}
bool bIsMultiControl = m_hCombinationOperator->IsMultiControl( i );
if ( bIsMultiControl )
{
++iCurrentAnimSetControl;
char pMultiControlName[ 256 ];
V_snprintf( pMultiControlName, sizeof( pMultiControlName ), MULTI_CONTROL_FORMAT_STRING, pControlName );
if ( !pAnimationSet->FindControl( pMultiControlName ) )
{
CDmElement *pMultiControl = CreateElement< CDmElement >( pMultiControlName, pAnimationSet->GetFileId() );
Assert( pMultiControl );
controls.InsertBefore( iCurrentAnimSetControl, pMultiControl );
pMultiControl->SetValue( "value", m_hCombinationOperator->GetMultiControlLevel( i ) );
pMultiControl->SetValue( "defaultValue", 0.5f );
}
}
}
int nLastControl = controls.Count();
if ( nLastControl == nFirstControl )
return;
// Add new controls to the root group
CDmElement *pGroup = pAnimationSet->FindOrAddControlGroup( NULL, "Root" );
// Fill in members
CDmrElementArray<> groups( pGroup, "controls" );
for ( int i = nFirstControl; i < nLastControl; ++i )
{
groups.AddToTail( controls[ i ] );
}
}
//-----------------------------------------------------------------------------
// Sort control names to match the combination controls
//-----------------------------------------------------------------------------
void CDmeCombinationOperatorPanel::SortAnimationSetControls()
{
// TODO - we should be storing which animationset an item is associated with
CAnimSetGroupAnimSetTraversal traversal( m_pController->GetAnimationSetClip() );
CDmeAnimationSet *pAnimSet = traversal.Next();
Assert( !traversal.IsValid() );
// TODO: Figure out why this isn't called on load
pAnimSet->OnElementUnserialized();
CDmaElementArray<> &controls = pAnimSet->GetControls();
int nControlCount = controls.Count();
if ( nControlCount == 0 )
return;
int nCombinationControlCount = m_hCombinationOperator->GetControlCount();
DmElementHandle_t *pElements = (DmElementHandle_t*)_alloca( nControlCount * sizeof(DmElementHandle_t) );
int iCurrentControlIndex = 0;
for ( int i = 0; i < nCombinationControlCount; ++i )
{
const char *pControlName = m_hCombinationOperator->GetControlName( i );
CDmElement *pControl = pAnimSet->FindControl( pControlName );
pElements[iCurrentControlIndex++] = pControl->GetHandle();
if ( m_hCombinationOperator->IsMultiControl( i ) )
{
char pMultiControlName[ 256 ];
V_snprintf( pMultiControlName, sizeof( pMultiControlName ), MULTI_CONTROL_FORMAT_STRING, pControlName );
CDmElement *pMultiControl = pAnimSet->FindControl( pMultiControlName );
pElements[iCurrentControlIndex++] = pMultiControl->GetHandle();
}
}
Assert( nControlCount == iCurrentControlIndex );
controls.SetMultiple( 0, nControlCount, pElements );
}
//-----------------------------------------------------------------------------
// Called when the animation set has to be made to match the combination operator
//-----------------------------------------------------------------------------
void CDmeCombinationOperatorPanel::RefreshAnimationSet()
{
if ( !m_pController->GetAnimationSetClip() )
return;
CDisableUndoScopeGuard sg;
// Remove all controls in the animation set and in presets that don't exist in the combination system
RemoveUnusedAnimationSetControls();
// Modify controls in the presets which have had stereo settings changed
ModifyExistingAnimationSetControls();
// Add all controls not in the animation set but which do exist in the combination system
AddNewAnimationSetControls();
// Sort control names to match the combination controls
SortAnimationSetControls();
}
void CDmeCombinationOperatorPanel::RefreshCombinationOperator()
{
RefreshAnimationSet();
ChangeAnimationSetClip( m_pController->GetAnimationSetClip() );
}
//-----------------------------------------------------------------------------
// Simulate
//-----------------------------------------------------------------------------
void CDmeCombinationOperatorPanel::OnTick()
{
BaseClass::OnTick();
if ( m_hCombinationOperator )
{
{
CDisableUndoScopeGuard sg;
int nCombinationControlCount = m_hCombinationOperator->GetControlCount();
int iCurrentControlIndex = 0;
for ( int i = 0; i < nCombinationControlCount; ++i )
{
AttributeValue_t value;
if ( GetAttributeSlider()->GetSliderValues( &value, iCurrentControlIndex++ ) )
{
if ( m_hCombinationOperator->IsStereoControl( i ) )
{
m_hCombinationOperator->SetControlValue( i, value.m_pValue[ANIM_CONTROL_VALUE_LEFT], value.m_pValue[ANIM_CONTROL_VALUE_RIGHT] );
}
else
{
m_hCombinationOperator->SetControlValue( i, value.m_pValue[ANIM_CONTROL_VALUE] );
}
}
if ( m_hCombinationOperator->IsMultiControl( i ) )
{
AttributeValue_t multiValue;
if ( GetAttributeSlider()->GetSliderValues( &multiValue, iCurrentControlIndex++ ) )
{
m_hCombinationOperator->SetMultiControlLevel( i, multiValue.m_pValue[ANIM_CONTROL_VALUE] );
}
}
}
}
if ( m_operatorList.Count() )
{
CDisableUndoScopeGuard guard;
g_pDmElementFramework->SetOperators( m_operatorList );
g_pDmElementFramework->Operate( true );
}
else
{
// FIXME: Shouldn't this happen at the application level?
// run the machinery - apply, resolve, dependencies, operate, resolve
CUtlVector< IDmeOperator* > operators;
operators.AddToTail( m_hCombinationOperator );
CDisableUndoScopeGuard guard;
g_pDmElementFramework->SetOperators( operators );
g_pDmElementFramework->Operate( true );
}
}
// allow elements and attributes to be edited again
g_pDmElementFramework->BeginEdit();
}
//-----------------------------------------------------------------------------
// Constructor, destructor
//-----------------------------------------------------------------------------
CDmeDagEditPanel::CDmeDagEditPanel( vgui::Panel *pParent, const char *pName ) : BaseClass( pParent, pName )
{
m_pPropertiesSplitter = new vgui::Splitter( this, "PropertiesSplitter", vgui::SPLITTER_MODE_VERTICAL, 1 );
vgui::Panel *pSplitterLeftSide = m_pPropertiesSplitter->GetChild( 0 );
vgui::Panel *pSplitterRightSide = m_pPropertiesSplitter->GetChild( 1 );
m_pDagRenderPanel = new CDmeDagRenderPanel( pSplitterRightSide, "DagRenderPanel" );
m_pEditorSheet = new vgui::PropertySheet( pSplitterLeftSide, "EditorSheet" );
m_pEditorSheet->AddActionSignalTarget( this );
m_pAnimationPage = new vgui::PropertyPage( m_pEditorSheet, "AnimationPage" );
m_pCombinationPage = new vgui::PropertyPage( m_pEditorSheet, "AnimationSetEditor" );
m_pVertexAnimationPage = new vgui::PropertyPage( m_pEditorSheet, "VertexAnimationPage" );
CCombinationOperatorControl *pAnimationSetController = new CCombinationOperatorControl();
m_pCombinationPanel = new CDmeCombinationOperatorPanel( m_pCombinationPage, "AnimationSetEditorPanel", pAnimationSetController );
m_pCombinationPanel->CreateToolsSubPanels();
m_pAnimationListPanel = new CDmeAnimationListPanel( m_pAnimationPage, "AnimationListPanel" );
m_pAnimationListPanel->AddActionSignalTarget( this );
m_pVertexAnimationListPanel = new CDmeAnimationListPanel( m_pVertexAnimationPage, "VertexAnimationListPanel" );
m_pVertexAnimationListPanel->AddActionSignalTarget( this );
m_pCombinationPage->LoadControlSettingsAndUserConfig( "resource/dmedageditpanel_animationseteditorpage.res" );
m_pAnimationPage->LoadControlSettingsAndUserConfig( "resource/dmedageditpanel_animationpage.res" );
m_pVertexAnimationPage->LoadControlSettingsAndUserConfig( "resource/dmedageditpanel_vertexanimationpage.res" );
// Load layout settings; has to happen before pinning occurs in code
LoadControlSettingsAndUserConfig( "resource/dmedageditpanel.res" );
// NOTE: Page adding happens *after* LoadControlSettingsAndUserConfig
// because the layout of the sheet is correct at this point.
m_pEditorSheet->AddPage( m_pAnimationPage, "Animation" );
m_pEditorSheet->AddPage( m_pCombinationPage, "Combination" );
m_pEditorSheet->AddPage( m_pVertexAnimationPage, "Vertex Animation" );
m_pEditorSheet->SetActivePage( m_pCombinationPage );
}
CDmeDagEditPanel::~CDmeDagEditPanel()
{
}
//-----------------------------------------------------------------------------
// Set the scene
//-----------------------------------------------------------------------------
void CDmeDagEditPanel::SetDmeElement( CDmeDag *pScene )
{
m_pDagRenderPanel->SetDmeElement( pScene );
}
//-----------------------------------------------------------------------------
// Sets up the various panels in the dag editor
//-----------------------------------------------------------------------------
void CDmeDagEditPanel::SetMakefileRootElement( CDmElement *pRoot )
{
CDmeAnimationList *pAnimationList = pRoot->GetValueElement< CDmeAnimationList >( "animationList" );
SetAnimationList( pAnimationList );
CDmeAnimationList *pVertexAnimationList = pRoot->GetValueElement< CDmeAnimationList >( "vertexAnimationList" );
SetVertexAnimationList( pVertexAnimationList );
CDmeCombinationOperator *pComboOp = pRoot->GetValueElement< CDmeCombinationOperator >( "combinationOperator" );
SetCombinationOperator( pComboOp );
}
//-----------------------------------------------------------------------------
// Other methods which hook into DmePanel
//-----------------------------------------------------------------------------
void CDmeDagEditPanel::SetDmeElement( CDmeSourceSkin *pSkin )
{
m_pDagRenderPanel->SetDmeElement( pSkin );
// First, try to grab the dependent makefile
CDmeMakefile *pSourceMakefile = pSkin->GetDependentMakefile();
if ( !pSourceMakefile )
return;
// Next, try to grab the output of that makefile
CDmElement *pOutput = pSourceMakefile->GetOutputElement( true );
if ( !pOutput )
return;
SetMakefileRootElement( pOutput );
}
void CDmeDagEditPanel::SetDmeElement( CDmeSourceAnimation *pAnimation )
{
m_pDagRenderPanel->SetDmeElement( pAnimation );
// First, try to grab the dependent makefile
CDmeMakefile *pSourceMakefile = pAnimation->GetDependentMakefile();
if ( !pSourceMakefile )
return;
// Next, try to grab the output of that makefile
CDmElement *pOutput = pSourceMakefile->GetOutputElement( true );
if ( !pOutput )
return;
SetMakefileRootElement( pOutput );
// if ( pAnimationList->FindAnimation( pAnimation->m_SourceAnimationName ) < 0 )
// return;
}
void CDmeDagEditPanel::SetDmeElement( CDmeDCCMakefile *pDCCMakefile )
{
m_pDagRenderPanel->SetDmeElement( pDCCMakefile );
// First, try to grab the dependent makefile
CDmElement *pOutput = pDCCMakefile->GetOutputElement( true );
if ( !pOutput )
return;
SetMakefileRootElement( pOutput );
}
CDmeDag *CDmeDagEditPanel::GetDmeElement()
{
return m_pDagRenderPanel->GetDmeElement();
}
//-----------------------------------------------------------------------------
// paint it!
//-----------------------------------------------------------------------------
void CDmeDagEditPanel::Paint()
{
BaseClass::Paint();
}
//-----------------------------------------------------------------------------
// Sets animation
//-----------------------------------------------------------------------------
void CDmeDagEditPanel::SetAnimationList( CDmeAnimationList *pAnimationList )
{
m_pDagRenderPanel->SetAnimationList( pAnimationList );
m_pDagRenderPanel->SelectAnimation( "" );
m_pAnimationListPanel->SetAnimationList( pAnimationList );
}
void CDmeDagEditPanel::SetVertexAnimationList( CDmeAnimationList *pAnimationList )
{
m_pDagRenderPanel->SetVertexAnimationList( pAnimationList );
m_pDagRenderPanel->SelectVertexAnimation( "" );
m_pVertexAnimationListPanel->SetAnimationList( pAnimationList );
}
void CDmeDagEditPanel::SetCombinationOperator( CDmeCombinationOperator *pComboOp )
{
m_pCombinationPanel->SetCombinationOperator( pComboOp );
}
void CDmeDagEditPanel::RefreshCombinationOperator()
{
m_pCombinationPanel->RefreshCombinationOperator();
}
//-----------------------------------------------------------------------------
// Called when the page changes
//-----------------------------------------------------------------------------
void CDmeDagEditPanel::OnPageChanged( )
{
if ( m_pEditorSheet->GetActivePage() == m_pCombinationPage )
{
m_pDagRenderPanel->SelectAnimation( "" );
m_pDagRenderPanel->SelectVertexAnimation( "" );
return;
}
if ( m_pEditorSheet->GetActivePage() == m_pAnimationPage )
{
m_pDagRenderPanel->SelectAnimation( m_pAnimationListPanel->GetSelectedAnimation() );
m_pDagRenderPanel->SelectVertexAnimation( "" );
return;
}
if ( m_pEditorSheet->GetActivePage() == m_pVertexAnimationPage )
{
m_pDagRenderPanel->SelectAnimation( "" );
m_pDagRenderPanel->SelectVertexAnimation( m_pVertexAnimationListPanel->GetSelectedAnimation() );
return;
}
}
//-----------------------------------------------------------------------------
// Called when new animations are selected
//-----------------------------------------------------------------------------
void CDmeDagEditPanel::OnAnimationSelected( KeyValues *pKeyValues )
{
vgui::Panel *pPanel = (vgui::Panel *)pKeyValues->GetPtr( "panel", NULL );
const char *pAnimationName = pKeyValues->GetString( "animationName", "" );
if ( pPanel == m_pAnimationListPanel )
{
m_pDagRenderPanel->SelectAnimation( pAnimationName );
return;
}
if ( pPanel == m_pVertexAnimationListPanel )
{
m_pDagRenderPanel->SelectVertexAnimation( pAnimationName );
return;
}
}
void CDmeDagEditPanel::OnAnimationDeselected( KeyValues *pKeyValues )
{
vgui::Panel *pPanel = (vgui::Panel *)pKeyValues->GetPtr( "panel", NULL );
if ( pPanel == m_pAnimationListPanel )
{
m_pDagRenderPanel->SelectAnimation( "" );
return;
}
if ( pPanel == m_pVertexAnimationListPanel )
{
m_pDagRenderPanel->SelectVertexAnimation( "" );
return;
}
}

View File

@@ -0,0 +1,919 @@
//========= Copyright © 1996-2001, Valve LLC, All rights reserved. ============
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
#include "dme_controls/dmedagrenderpanel.h"
#include "movieobjects/dmedag.h"
#include "movieobjects/dmemodel.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"
//-----------------------------------------------------------------------------
//
// 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 )
{
CDisableUndoScopeGuard sg;
m_bDrawJointNames = false;
m_bDrawJoints = false;
m_bDrawGrid = true;
m_bDrawAxis = true;
m_bModelInEngineCoordinates = false;
m_bModelZUp = false;
// 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 );
if ( g_pMaterialSystem )
{
KeyValues *pVMTKeyValues = new KeyValues( "wireframe" );
pVMTKeyValues->SetInt( "$vertexcolor", 1 );
pVMTKeyValues->SetInt( "$ignorez", 1 );
m_axisMaterial.Init( "__DmeDagRenderPanelAxis", pVMTKeyValues );
}
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()
{
if ( g_pMaterialSystem )
{
m_axisMaterial.Shutdown();
}
}
//-----------------------------------------------------------------------------
// 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 );
CDmeModel *pDmeModel = CastElement< CDmeModel >( m_hDag );
if ( pDmeModel )
{
ModelZUp( pDmeModel->IsZUp() );
}
}
//-----------------------------------------------------------------------------
// 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 );
CDmeModel *pDmeModel = CastElement< CDmeModel >( m_hDag );
if ( pDmeModel )
{
ModelZUp( pDmeModel->IsZUp() );
}
else
{
pDmeModel = CastElement< CDmeModel >( pOutput );
if ( pDmeModel )
{
ModelZUp( pDmeModel->IsZUp() );
}
}
}
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 );
CDmeModel *pDmeModel = CastElement< CDmeModel >( m_hDag );
if ( pDmeModel )
{
ModelZUp( pDmeModel->IsZUp() );
}
else
{
pDmeModel = CastElement< CDmeModel >( pOutput );
if ( pDmeModel )
{
ModelZUp( pDmeModel->IsZUp() );
}
}
}
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 );
CDmeModel *pDmeModel = CastElement< CDmeModel >( m_hDag );
if ( pDmeModel )
{
ModelZUp( pDmeModel->IsZUp() );
}
else
{
pDmeModel = CastElement< CDmeModel >( pOutputElement );
if ( pDmeModel )
{
ModelZUp( pDmeModel->IsZUp() );
}
}
}
CDmeDag *CDmeDagRenderPanel::GetDmeElement()
{
return m_hDag;
}
//-----------------------------------------------------------------------------
// Draw joint names
//-----------------------------------------------------------------------------
void CDmeDagRenderPanel::DrawJointNames( CDmeDag *pRoot, CDmeDag *pDag, const matrix3x4_t& parentToWorld )
{
int nJointIndex = -1;
CDmeModel *pRootModel = CastElement<CDmeModel>( pRoot );
if ( pRootModel )
{
nJointIndex = pRootModel->GetJointIndex( pDag );
if ( nJointIndex < 0 && pRootModel != pDag )
return;
}
matrix3x4_t jointToParent, jointToWorld;
pDag->GetTransform()->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 );
}
}
//-----------------------------------------------------------------------------
// Draw highlight points
//-----------------------------------------------------------------------------
void CDmeDagRenderPanel::DrawHighlightPoints()
{
if ( !m_pDrawSettings )
return;
const float flPointRadius = m_pDrawSettings->m_flHighlightSize;
Vector2D vecPanelPos;
g_pMatSystemSurface->DrawSetColor( m_pDrawSettings->m_cHighlightColor );
const CUtlVector< Vector > &highLightPoints = m_pDrawSettings->GetHighlightPoints();
const int nPointCount = highLightPoints.Count();
for ( int i = 0; i < nPointCount; ++i )
{
ComputePanelPosition( highLightPoints[i], &vecPanelPos );
g_pMatSystemSurface->DrawFilledRect( vecPanelPos.x - flPointRadius, vecPanelPos.y - flPointRadius, vecPanelPos.x + flPointRadius, vecPanelPos.y + flPointRadius );
}
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
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;
if ( !m_bModelInEngineCoordinates )
{
CDmeDag::DmeToEngineMatrix( dmeToEngine, m_bModelZUp );
}
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;
if ( !m_bModelInEngineCoordinates )
{
CDmeDag::DmeToEngineMatrix( modelToWorld, m_bModelZUp );
}
DrawJointNames( m_hDag, m_hDag, modelToWorld );
}
DrawHighlightPoints();
}
//-----------------------------------------------------------------------------
// 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;
}
//-----------------------------------------------------------------------------
// Indicate we should draw the coordinate axis
//-----------------------------------------------------------------------------
void CDmeDagRenderPanel::DrawAxis( bool bDrawAxis )
{
m_bDrawAxis = bDrawAxis;
}
//-----------------------------------------------------------------------------
// Indicate whether the model is in engine coordinates already
//-----------------------------------------------------------------------------
void CDmeDagRenderPanel::ModelInEngineCoordinates( bool bDrawInEngineCoordinates )
{
m_bModelInEngineCoordinates = bDrawInEngineCoordinates;
}
//-----------------------------------------------------------------------------
// Indicate whether the model is Z Up
//-----------------------------------------------------------------------------
void CDmeDagRenderPanel::ModelZUp( bool bDrawZUp )
{
m_bModelZUp = bDrawZUp;
}
//-----------------------------------------------------------------------------
// 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( !m_bModelInEngineCoordinates );
CDmeDag::DrawZUp( m_bModelZUp );
m_pDrawSettings->DrawDag( m_hDag );
CDmeDag::DrawUsingEngineCoordinates( false );
CDmeDag::DrawZUp( false );
if ( m_bDrawAxis )
{
DrawAxis();
}
pRenderContext->Flush();
pRenderContext->BindLocalCubemap( pLocalCube );
}
//-----------------------------------------------------------------------------
// For rendering joints
//-----------------------------------------------------------------------------
#define AXIS_SIZE 10.0f
void CDmeDagRenderPanel::DrawAxis( )
{
if ( !g_pMaterialSystem )
return;
CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
pRenderContext->MatrixMode( MATERIAL_MODEL );
pRenderContext->Bind( m_axisMaterial );
IMesh *pMesh = pRenderContext->GetDynamicMesh( );
CMeshBuilder meshBuilder;
meshBuilder.Begin( pMesh, MATERIAL_LINES, 3 );
meshBuilder.Position3f( 0.0f, 0.0f, 0.0f );
meshBuilder.Color4ub( 255, 0, 0, 255 );
meshBuilder.AdvanceVertexF< VTX_HAVEPOS | VTX_HAVECOLOR, 0 >();
meshBuilder.Position3f( AXIS_SIZE, 0.0f, 0.0f );
meshBuilder.Color4ub( 255, 0, 0, 255 );
meshBuilder.AdvanceVertexF< VTX_HAVEPOS | VTX_HAVECOLOR, 0 >();
meshBuilder.Position3f( 0.0f, 0.0f, 0.0f );
meshBuilder.Color4ub( 0, 255, 0, 255 );
meshBuilder.AdvanceVertexF< VTX_HAVEPOS | VTX_HAVECOLOR, 0 >();
meshBuilder.Position3f( 0.0f, AXIS_SIZE, 0.0f );
meshBuilder.Color4ub( 0, 255, 0, 255 );
meshBuilder.AdvanceVertexF< VTX_HAVEPOS | VTX_HAVECOLOR, 0 >();
meshBuilder.Position3f( 0.0f, 0.0f, 0.0f );
meshBuilder.Color4ub( 0, 0, 255, 255 );
meshBuilder.AdvanceVertexF< VTX_HAVEPOS | VTX_HAVECOLOR, 0 >();
meshBuilder.Position3f( 0.0f, 0.0f, AXIS_SIZE );
meshBuilder.Color4ub( 0, 0, 255, 255 );
meshBuilder.AdvanceVertexF< VTX_HAVEPOS | VTX_HAVECOLOR, 0 >();
meshBuilder.End();
pMesh->Draw();
pRenderContext->MatrixMode( MATERIAL_MODEL );
pRenderContext->LoadIdentity();
}
//-----------------------------------------------------------------------------
// 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() );
}

View File

@@ -0,0 +1,542 @@
//===== Copyright © 1996-2005, 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 );
}

View File

@@ -0,0 +1,47 @@
//====== Copyright © 1996-2005, 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() );
}
}
}

View File

@@ -0,0 +1,656 @@
//====== Copyright © 1996-2005, 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;
}

View File

@@ -0,0 +1,280 @@
//====== Copyright © 1996-2005, 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::OnKeyCodeTyped( KeyCode code )
{
if (( code == KEY_UP ) || ( code == KEY_DOWN ) || ( code == KEY_PAGEUP ) || ( code == KEY_PAGEDOWN ))
{
KeyValues *pMsg = new KeyValues("KeyCodeTyped", "code", code);
vgui::ipanel()->SendMessage( m_pDmeBrowser->GetVPanel(), pMsg, GetVPanel());
pMsg->deleteThis();
}
else
{
BaseClass::OnKeyCodeTyped( 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.Get(), 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

View File

@@ -0,0 +1,53 @@
//====== Copyright © 1996-2005, 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( );
}

View File

@@ -0,0 +1,495 @@
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======
//
// Purpose:
//
//=============================================================================
#include "dme_controls/mdlpanel.h"
#include "materialsystem/imaterialsystem.h"
#include <materialsystem/IMaterialSystemHardwareConfig.h>
#include "materialsystem/imesh.h"
#include "vgui/ivgui.h"
#include "tier1/keyvalues.h"
#include "movieobjects/dmemdl.h"
#include "movieobjects/dmetransform.h"
#include "movieobjects/dmedag.h"
#include "movieobjects/dmemdlmakefile.h"
#include "vgui_controls/frame.h"
#include "convar.h"
#include "tier0/dbg.h"
#include "istudiorender.h"
#include "matsys_controls/matsyscontrols.h"
#include "vcollide.h"
#include "vcollide_parse.h"
#include "bone_setup.h"
#include "vphysics_interface.h"
#include "dme_controls/dmecontrols.h"
#include "dme_controls/dmepanel.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
IMPLEMENT_DMEPANEL_FACTORY( CMDLPanel, DmeMDLMakefile, "DmeMakeFileOutputPreview", "MDL MakeFile Output Preview", false );
//-----------------------------------------------------------------------------
// Constructor, destructor
//-----------------------------------------------------------------------------
CMDLPanel::CMDLPanel( vgui::Panel *pParent, const char *pName ) : BaseClass( pParent, pName )
{
CDmeMDL *pMDL = CreateElement< CDmeMDL >( "mdl", DMFILEID_INVALID );
m_hMDL = pMDL;
m_hMDL->DrawInEngine( true );
UseEngineCoordinateSystem( true );
m_pDag = CreateElement< CDmeDag >( "dag", DMFILEID_INVALID );
m_pDag->SetShape( pMDL );
SetVisible( true );
// Used to poll input
vgui::ivgui()->AddTickSignal( GetVPanel() );
// Deal with the default cubemap
ITexture *pCubemapTexture = vgui::MaterialSystem()->FindTexture( "editor/cubemap", NULL, true );
m_DefaultEnvCubemap.Init( pCubemapTexture );
pCubemapTexture = vgui::MaterialSystem()->FindTexture( "editor/cubemap.hdr", NULL, true );
m_DefaultHDREnvCubemap.Init( pCubemapTexture );
KeyValues *pMaterialKeys = new KeyValues( "Wireframe", "$model", "1" );
pMaterialKeys->SetString( "$vertexcolor", "1" );
m_Wireframe.Init( "mdlpanelwireframe", pMaterialKeys );
m_bDrawCollisionModel = false;
m_bWireFrame = false;
m_bGroundGrid = false;
m_bLockView = false;
m_bIsExternalMDL = false;
}
CMDLPanel::~CMDLPanel()
{
CDisableUndoScopeGuard guard;
m_pDag->SetShape( NULL );
m_DefaultEnvCubemap.Shutdown( );
m_DefaultHDREnvCubemap.Shutdown();
if ( !m_bIsExternalMDL )
{
DestroyElement( m_hMDL );
m_hMDL = NULL;
}
g_pDataModel->DestroyElement( m_pDag->GetHandle() );
}
//-----------------------------------------------------------------------------
// Scheme settings
//-----------------------------------------------------------------------------
void CMDLPanel::ApplySchemeSettings( vgui::IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
SetBorder( pScheme->GetBorder( "MenuBorder") );
}
//-----------------------------------------------------------------------------
// DMEPanel..
//-----------------------------------------------------------------------------
void CMDLPanel::SetDmeElement( CDmeMDLMakefile *pMDLMakefile )
{
CDisableUndoScopeGuard sg;
if ( !m_bIsExternalMDL )
{
DestroyElement( m_hMDL );
m_hMDL = NULL;
}
CDmeMDL *pMDL = NULL;
if ( pMDLMakefile != NULL )
{
pMDL = CastElement< CDmeMDL >( pMDLMakefile->GetOutputElement( true ) );
m_bIsExternalMDL = ( pMDL != NULL );
}
if ( !pMDL )
{
pMDL = CreateElement< CDmeMDL >( "mdl", DMFILEID_INVALID );
}
m_hMDL = pMDL;
m_hMDL->DrawInEngine( true );
m_pDag->SetShape( pMDL );
}
//-----------------------------------------------------------------------------
// Rendering options
//-----------------------------------------------------------------------------
void CMDLPanel::SetCollsionModel( bool bVisible )
{
m_bDrawCollisionModel = bVisible;
}
void CMDLPanel::SetGroundGrid( bool bVisible )
{
m_bGroundGrid = bVisible;
}
void CMDLPanel::SetWireFrame( bool bVisible )
{
m_bWireFrame = bVisible;
}
void CMDLPanel::SetLockView( bool bLocked )
{
m_bLockView = bLocked;
}
void CMDLPanel::SetLookAtCamera( bool bLookAtCamera )
{
m_bLookAtCamera = bLookAtCamera;
}
//-----------------------------------------------------------------------------
// Stores the clip
//-----------------------------------------------------------------------------
void CMDLPanel::SetMDL( MDLHandle_t handle )
{
CDisableUndoScopeGuard sg;
m_hMDL->SetMDL( handle );
}
//-----------------------------------------------------------------------------
// Sets the camera to look at the model
//-----------------------------------------------------------------------------
void CMDLPanel::LookAtMDL( )
{
if ( m_bLockView )
return;
float flRadius;
Vector vecCenter;
m_hMDL->GetBoundingSphere( vecCenter, flRadius );
LookAt( vecCenter, flRadius );
}
//-----------------------------------------------------------------------------
// FIXME: This should be moved into studiorender
//-----------------------------------------------------------------------------
static ConVar r_showenvcubemap( "r_showenvcubemap", "0", FCVAR_CHEAT );
static ConVar r_eyegloss ( "r_eyegloss", "1", FCVAR_ARCHIVE ); // wet eyes
static ConVar r_eyemove ( "r_eyemove", "1", FCVAR_ARCHIVE ); // look around
static ConVar r_eyeshift_x ( "r_eyeshift_x", "0", FCVAR_ARCHIVE ); // eye X position
static ConVar r_eyeshift_y ( "r_eyeshift_y", "0", FCVAR_ARCHIVE ); // eye Y position
static ConVar r_eyeshift_z ( "r_eyeshift_z", "0", FCVAR_ARCHIVE ); // eye Z position
static ConVar r_eyesize ( "r_eyesize", "0", FCVAR_ARCHIVE ); // adjustment to iris textures
static ConVar mat_softwareskin( "mat_softwareskin", "0" );
static ConVar r_nohw ( "r_nohw", "0", FCVAR_CHEAT );
static ConVar r_nosw ( "r_nosw", "0", FCVAR_CHEAT );
static ConVar r_teeth ( "r_teeth", "1" );
static ConVar r_drawentities ( "r_drawentities", "1", FCVAR_CHEAT );
static ConVar r_flex ( "r_flex", "1" );
static ConVar r_eyes ( "r_eyes", "1" );
static ConVar r_skin ( "r_skin","0" );
static ConVar r_maxmodeldecal ( "r_maxmodeldecal", "50" );
static ConVar r_modelwireframedecal ( "r_modelwireframedecal", "0", FCVAR_CHEAT );
static ConVar mat_normals ( "mat_normals", "0", FCVAR_CHEAT );
static ConVar r_eyeglintlodpixels ( "r_eyeglintlodpixels", "0", FCVAR_CHEAT );
static ConVar r_rootlod ( "r_rootlod", "0", FCVAR_CHEAT );
static StudioRenderConfig_t s_StudioRenderConfig;
void CMDLPanel::UpdateStudioRenderConfig( void )
{
memset( &s_StudioRenderConfig, 0, sizeof(s_StudioRenderConfig) );
s_StudioRenderConfig.bEyeMove = !!r_eyemove.GetInt();
s_StudioRenderConfig.fEyeShiftX = r_eyeshift_x.GetFloat();
s_StudioRenderConfig.fEyeShiftY = r_eyeshift_y.GetFloat();
s_StudioRenderConfig.fEyeShiftZ = r_eyeshift_z.GetFloat();
s_StudioRenderConfig.fEyeSize = r_eyesize.GetFloat();
if( mat_softwareskin.GetInt() || m_bWireFrame )
{
s_StudioRenderConfig.bSoftwareSkin = true;
}
else
{
s_StudioRenderConfig.bSoftwareSkin = false;
}
s_StudioRenderConfig.bNoHardware = !!r_nohw.GetInt();
s_StudioRenderConfig.bNoSoftware = !!r_nosw.GetInt();
s_StudioRenderConfig.bTeeth = !!r_teeth.GetInt();
s_StudioRenderConfig.drawEntities = r_drawentities.GetInt();
s_StudioRenderConfig.bFlex = !!r_flex.GetInt();
s_StudioRenderConfig.bEyes = !!r_eyes.GetInt();
s_StudioRenderConfig.bWireframe = m_bWireFrame;
s_StudioRenderConfig.bDrawNormals = mat_normals.GetBool();
s_StudioRenderConfig.skin = r_skin.GetInt();
s_StudioRenderConfig.maxDecalsPerModel = r_maxmodeldecal.GetInt();
s_StudioRenderConfig.bWireframeDecals = r_modelwireframedecal.GetInt() != 0;
s_StudioRenderConfig.fullbright = false;
s_StudioRenderConfig.bSoftwareLighting = false;
s_StudioRenderConfig.bShowEnvCubemapOnly = r_showenvcubemap.GetBool();
s_StudioRenderConfig.fEyeGlintPixelWidthLODThreshold = r_eyeglintlodpixels.GetFloat();
StudioRender()->UpdateConfig( s_StudioRenderConfig );
}
void CMDLPanel::DrawCollisionModel()
{
vcollide_t *pCollide = MDLCache()->GetVCollide( m_hMDL->GetMDL() );
if ( !pCollide || pCollide->solidCount <= 0 )
return;
static color32 color = {255,0,0,0};
IVPhysicsKeyParser *pParser = g_pPhysicsCollision->VPhysicsKeyParserCreate( pCollide );
CStudioHdr studioHdr( g_pMDLCache->GetStudioHdr( m_hMDL->GetMDL() ), g_pMDLCache );
matrix3x4_t pBoneToWorld[MAXSTUDIOBONES];
matrix3x4_t shapeToWorld;
m_pDag->GetTransform()->GetTransform( shapeToWorld );
m_hMDL->SetUpBones( shapeToWorld, MAXSTUDIOBONES, pBoneToWorld );
// PERFORMANCE: Just parse the script each frame. It's fast enough for tools. If you need
// this to go faster then cache off the bone index mapping in an array like HLMV does
while ( !pParser->Finished() )
{
const char *pBlock = pParser->GetCurrentBlockName();
if ( !stricmp( pBlock, "solid" ) )
{
solid_t solid;
pParser->ParseSolid( &solid, NULL );
int boneIndex = Studio_BoneIndexByName( &studioHdr, solid.name );
Vector *outVerts;
int vertCount = g_pPhysicsCollision->CreateDebugMesh( pCollide->solids[solid.index], &outVerts );
if ( vertCount )
{
CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
pRenderContext->CullMode( MATERIAL_CULLMODE_CCW );
// NOTE: assumes these have been set up already by the model render code
// So this is a little bit of a back door to a cache of the bones
// this code wouldn't work unless you draw the model this frame before calling
// this routine. CMDLPanel always does this, but it's worth noting.
// A better solution would be to move the ragdoll visulization into the CDmeMdl
// and either draw it there or make it queryable and query/draw here.
matrix3x4_t xform;
SetIdentityMatrix( xform );
if ( boneIndex >= 0 )
{
MatrixCopy( pBoneToWorld[ boneIndex ], xform );
}
IMesh *pMesh = pRenderContext->GetDynamicMesh( true, NULL, NULL, m_Wireframe );
CMeshBuilder meshBuilder;
meshBuilder.Begin( pMesh, MATERIAL_TRIANGLES, vertCount/3 );
for ( int j = 0; j < vertCount; j++ )
{
Vector out;
VectorTransform( outVerts[j].Base(), xform, out.Base() );
meshBuilder.Position3fv( out.Base() );
meshBuilder.Color4ub( color.r, color.g, color.b, color.a );
meshBuilder.TexCoord2f( 0, 0, 0 );
meshBuilder.AdvanceVertex();
}
meshBuilder.End();
pMesh->Draw();
}
g_pPhysicsCollision->DestroyDebugMesh( vertCount, outVerts );
}
else
{
pParser->SkipBlock();
}
}
g_pPhysicsCollision->VPhysicsKeyParserDestroy( pParser );
}
//-----------------------------------------------------------------------------
// paint it!
//-----------------------------------------------------------------------------
void CMDLPanel::OnPaint3D()
{
if ( !m_hMDL.Get() )
return;
// FIXME: Move this call into DrawModel in StudioRender
StudioRenderConfig_t oldStudioRenderConfig;
StudioRender()->GetCurrentConfig( oldStudioRenderConfig );
UpdateStudioRenderConfig();
CMatRenderContextPtr pRenderContext( vgui::MaterialSystem() );
ITexture *pLocalCube = pRenderContext->GetLocalCubemap();
if ( vgui::MaterialSystemHardwareConfig()->GetHDRType() == HDR_TYPE_NONE )
{
ITexture *pMyCube = HasLightProbe() ? GetLightProbeCubemap( false ) : m_DefaultEnvCubemap;
pRenderContext->BindLocalCubemap( pMyCube );
}
else
{
ITexture *pMyCube = HasLightProbe() ? GetLightProbeCubemap( true ) : m_DefaultHDREnvCubemap;
pRenderContext->BindLocalCubemap( pMyCube );
}
if ( m_bGroundGrid )
{
DrawGrid();
}
if ( m_bLookAtCamera )
{
CDisableUndoScopeGuard sg;
matrix3x4_t worldToCamera;
ComputeCameraTransform( &worldToCamera );
Vector vecPosition;
MatrixGetColumn( worldToCamera, 3, vecPosition );
m_hMDL->m_bWorldSpaceViewTarget = true;
m_hMDL->m_vecViewTarget = vecPosition;
}
// Draw the MDL
m_pDag->Draw();
if ( m_bDrawCollisionModel )
{
DrawCollisionModel();
}
pRenderContext->Flush();
StudioRender()->UpdateConfig( oldStudioRenderConfig );
pRenderContext->BindLocalCubemap( pLocalCube );
}
//-----------------------------------------------------------------------------
// Sets the current sequence
//-----------------------------------------------------------------------------
void CMDLPanel::SetSequence( int nSequence )
{
CDisableUndoScopeGuard guard;
m_hMDL->m_nSequence = nSequence;
}
void CMDLPanel::SetSkin( int nSkin )
{
CDisableUndoScopeGuard guard;
m_hMDL->m_nSkin = nSkin;
}
//-----------------------------------------------------------------------------
// Purpose: Keeps a global clock to autoplay sequences to run from
// Also deals with speedScale changes
//-----------------------------------------------------------------------------
float GetAutoPlayTime( void )
{
static int g_prevTicks;
static float g_time;
int ticks = Plat_MSTime();
// limit delta so that float time doesn't overflow
if (g_prevTicks == 0)
{
g_prevTicks = ticks;
}
g_time += ( ticks - g_prevTicks ) / 1000.0f;
g_prevTicks = ticks;
return g_time;
}
//-----------------------------------------------------------------------------
// called when we're ticked...
//-----------------------------------------------------------------------------
void CMDLPanel::OnTick()
{
BaseClass::OnTick();
if ( m_hMDL->GetMDL() != MDLHANDLE_INVALID )
{
CDisableUndoScopeGuard guard;
m_hMDL->m_flTime = GetAutoPlayTime();
}
}
//-----------------------------------------------------------------------------
// input
//-----------------------------------------------------------------------------
void CMDLPanel::OnMouseDoublePressed( vgui::MouseCode code )
{
float flRadius;
Vector vecCenter;
m_hMDL->GetBoundingSphere( vecCenter, flRadius );
LookAt( vecCenter, flRadius );
BaseClass::OnMouseDoublePressed( code );
}
//-----------------------------------------------------------------------------
// Draws the grid under the MDL
//-----------------------------------------------------------------------------
void CMDLPanel::DrawGrid()
{
matrix3x4_t transform;
SetIdentityMatrix( transform );
CMatRenderContextPtr pRenderContext( MaterialSystem() );
pRenderContext->MatrixMode( MATERIAL_MODEL );
pRenderContext->LoadMatrix( transform );
pRenderContext->Bind( m_Wireframe );
IMesh *pMesh = pRenderContext->GetDynamicMesh();
int nGridDim = 10;
CMeshBuilder meshBuilder;
meshBuilder.Begin( pMesh, MATERIAL_LINES, 2 * nGridDim + 2 );
float bounds = 100.0f;
float delta = 2 * bounds / nGridDim;
for ( int i = 0; i < nGridDim + 1; ++i )
{
float xy = -bounds + delta * i;
meshBuilder.Position3f( xy, -bounds, 0 );
meshBuilder.Color4ub( 255, 255, 255, 255 );
meshBuilder.AdvanceVertex();
meshBuilder.Position3f( xy, bounds, 0 );
meshBuilder.Color4ub( 255, 255, 255, 255 );
meshBuilder.AdvanceVertex();
meshBuilder.Position3f( -bounds, xy, 0 );
meshBuilder.Color4ub( 255, 255, 255, 255 );
meshBuilder.AdvanceVertex();
meshBuilder.Position3f( bounds, xy, 0 );
meshBuilder.Color4ub( 255, 255, 255, 255 );
meshBuilder.AdvanceVertex();
}
meshBuilder.End();
pMesh->Draw();
}

View File

@@ -0,0 +1,889 @@
//===== Copyright © 1996-2005, 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_bRenderControlPoints = false;
m_bPerformNameBasedLookup = true;
m_bTickMyself = true;
m_bAutoView = false;
m_bSuppressAutoView = false;
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, vec3_invalid );
}
}
CParticleSystemPanel::~CParticleSystemPanel()
{
m_pLightmapTexture.Shutdown();
m_DefaultEnvCubemap.Shutdown();
delete m_pParticleSystem;
m_pParticleSystem = NULL;
}
void CParticleSystemPanel::ResetView()
{
BaseClass::ResetView();
LookAt(SPHERE_RADIUS);
m_BestViewBoundsMin = vec3_origin;
m_BestViewBoundsMax = vec3_origin;
m_bSuppressAutoView = false;
}
//-----------------------------------------------------------------------------
// Scheme
//-----------------------------------------------------------------------------
void CParticleSystemPanel::ApplySchemeSettings( vgui::IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
SetBorder( pScheme->GetBorder( "MenuBorder") );
}
//-----------------------------------------------------------------------------
// Stop System
//-----------------------------------------------------------------------------
void CParticleSystemPanel::StopEffect()
{
if ( !m_pParticleSystem )
return;
m_pParticleSystem->StopEmission(false, false, false, true );
}
//-----------------------------------------------------------------------------
// Indicates that the grid should be drawn
//-----------------------------------------------------------------------------
void CParticleSystemPanel::RenderGrid( bool bEnable )
{
m_bRenderGrid = bEnable;
}
//-----------------------------------------------------------------------------
// Indicates that bounds should be drawn
//-----------------------------------------------------------------------------
void CParticleSystemPanel::RenderBounds( bool bEnable )
{
m_bRenderBounds = bEnable;
}
//-----------------------------------------------------------------------------
// Indicates that control points should be drawn
//-----------------------------------------------------------------------------
void CParticleSystemPanel::RenderControlPoints( bool bEnable )
{
m_bRenderControlPoints = 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 );
}
}
//-----------------------------------------------------------------------------
// Simulate the particle system
//-----------------------------------------------------------------------------
void CParticleSystemPanel::OnTick()
{
BaseClass::OnTick();
if( m_bTickMyself )
{
Simulate();
}
}
void CParticleSystemPanel::Simulate()
{
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 ) || m_pControlPointValue[i] == vec3_invalid )
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 = !m_pParticleSystem->IsFullyValid();
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;
}
else
{
m_pParticleSystem->Simulate( flDt );
}
if( m_bAutoView && !m_bSuppressAutoView )
{
UseAutoView();
}
}
//-----------------------------------------------------------------------------
// Startup, shutdown particle collection
//-----------------------------------------------------------------------------
void CParticleSystemPanel::StartupParticleCollection()
{
if ( m_pParticleSystem && m_bTickMyself )
{
vgui::ivgui()->AddTickSignal( GetVPanel(), 0 );
}
m_flLastTime = FLT_MAX;
}
void CParticleSystemPanel::ShutdownParticleCollection()
{
if ( m_pParticleSystem )
{
if( m_bTickMyself )
{
vgui::ivgui()->RemoveTickSignal( GetVPanel() );
}
delete m_pParticleSystem;
m_pParticleSystem = NULL;
}
}
void CParticleSystemPanel::SetSelfSimulation(bool bSelfSimulate )
{
if( m_pParticleSystem && ( m_bTickMyself != bSelfSimulate ) )
{
if ( !bSelfSimulate )
{
vgui::ivgui()->RemoveTickSignal( GetVPanel() );
}
else
{
vgui::ivgui()->AddTickSignal( GetVPanel(), 0 );
}
}
m_bTickMyself = bSelfSimulate;
}
//-----------------------------------------------------------------------------
// 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::SetParticleSystem( const char* szParticleSystemName )
{
ShutdownParticleCollection();
if ( szParticleSystemName )
{
m_ParticleSystemName = szParticleSystemName;
if ( g_pParticleSystemMgr->IsParticleSystemDefined( m_ParticleSystemName ) )
{
m_pParticleSystem = g_pParticleSystemMgr->CreateParticleCollection( m_ParticleSystemName );
}
else
{
m_pParticleSystem = NULL;
}
PostActionSignal( new KeyValues( "ParticleSystemReconstructed" ) );
}
StartupParticleCollection();
}
void CParticleSystemPanel::SetDmeElement( CDmeParticleSystemDefinition *pDef )
{
SetParticleSystem( pDef );
}
CParticleCollection *CParticleSystemPanel::GetParticleSystem()
{
return m_pParticleSystem;
}
//-----------------------------------------------------------------------------
// Auto-viewing
//-----------------------------------------------------------------------------
void CParticleSystemPanel::EnterManipulationMode( ManipulationMode_t manipMode, bool bMouseCapture, vgui::MouseCode mouseCode )
{
BaseClass::EnterManipulationMode(manipMode,bMouseCapture,mouseCode);
if( manipMode != CAMERA_ROTATE )
{
m_bSuppressAutoView = true;
}
}
void CParticleSystemPanel::EnableAutoViewing( bool bEnable )
{
m_bAutoView = bEnable;
m_BestViewBoundsMin = vec3_origin;
m_BestViewBoundsMax = vec3_origin;
if ( m_bAutoView )
{
m_bSuppressAutoView = false;
}
}
void CParticleSystemPanel::UseAutoView()
{
Vector vecMins, vecMaxs;
m_pParticleSystem->GetBounds( &vecMins, &vecMaxs );
m_BestViewBoundsMin = m_BestViewBoundsMin.Min(vecMins);
m_BestViewBoundsMax = m_BestViewBoundsMax.Max(vecMaxs);
float flBestViewRad = MAX( 5.0f, 0.25f*(m_BestViewBoundsMax-m_BestViewBoundsMin).Length() );
Vector viewCenter = ( m_BestViewBoundsMin + m_BestViewBoundsMax ) * 0.5f;
LookAt( viewCenter, flBestViewRad );
}
//-----------------------------------------------------------------------------
// 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;
CMatRenderContextPtr pRenderContext( MaterialSystem() );
pRenderContext->BindLightmapTexture( m_pLightmapTexture );
pRenderContext->BindLocalCubemap( m_DefaultEnvCubemap );
// Draw axes
pRenderContext->MatrixMode( MATERIAL_MODEL );
pRenderContext->PushMatrix();
pRenderContext->LoadIdentity( );
if ( m_bRenderGrid )
{
DrawGrid();
}
if ( m_bRenderBounds )
{
DrawBounds();
}
if ( m_bRenderCullBounds )
{
DrawCullBounds();
}
if ( m_bRenderHelpers && IsUniqueIdValid( m_RenderHelperId ) )
{
m_pParticleSystem->VisualizeOperator( &m_RenderHelperId );
}
Vector4D vecDiffuseModulation( 1.0f, 1.0f, 1.0f, 1.0f );
m_pParticleSystem->Render( 0, pRenderContext, vecDiffuseModulation );
m_pParticleSystem->VisualizeOperator( );
RenderAxes( vec3_origin, AXIS_SIZE, true );
if ( m_bRenderControlPoints )
{
for ( int i = 0; i < MAX_PARTICLE_CONTROL_POINTS; ++i )
{
if ( m_pParticleSystem->ReadsControlPoint( i ) )
{
Vector vP;
m_pParticleSystem->GetControlPointAtTime( i, m_pParticleSystem->m_flCurTime, &vP );
RenderAxes( vP, 3.0f, 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 );
Vector vecValue = m_pParticleSystemPanel->GetControlPointValue( i );
if ( vecValue == vec3_invalid )
vecValue = vec3_origin;
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_pUnlockSystem = NULL;
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_pRenderControlPoints = new vgui::CheckButton( m_pRenderPage, "RenderControlPoints", "Render Control Points" );
m_pRenderControlPoints->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_pRenderGrid = new vgui::CheckButton( m_pRenderPage, "RenderGrid", "Render Grid" );
m_pRenderGrid->AddActionSignalTarget( this );
m_pBackgroundColor = new CColorPickerButton( m_pRenderPage, "BackgroundColor", this );
m_pBackgroundColor->SetColor( m_pParticleSystemPanel->GetBackgroundColor() );
m_pLockPreview = new vgui::CheckButton( m_pRenderPage, "LockPreview", "Lock Preview System" );
m_pLockPreview->AddActionSignalTarget( this );
m_pStopEffect = new vgui::Button( m_pRenderPage, "StopEffect", "Stop Effect", this, "StopEffect" );
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, bool bOverrideLock )
{
bool bLocked = m_pLockPreview->IsSelected();
if ( bOverrideLock || !bLocked )
{
m_pParticleSystemPanel->SetParticleSystem( pDef );
if ( bOverrideLock && bLocked )
{
m_pLockPreview->SetSelected(false);
m_pUnlockSystem = NULL;
}
else
{
m_pUnlockSystem = pDef;
}
}
else
{
m_pUnlockSystem = pDef;
}
}
void CParticleSystemPreviewPanel::ClearParticleSystemLock()
{
m_pLockPreview->SetSelected(false);
m_pUnlockSystem = NULL;
}
void CParticleSystemPreviewPanel::SetDmeElement( CDmeParticleSystemDefinition *pDef )
{
SetParticleSystem( pDef, false );
}
//-----------------------------------------------------------------------------
// 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 )
{
bool bState = pParams->GetBool( "state", false );
vgui::Panel *pPanel = (vgui::Panel*)pParams->GetPtr( "panel" );
if ( pPanel == m_pRenderGrid )
{
m_pParticleSystemPanel->RenderGrid( bState );
return;
}
if ( pPanel == m_pLockPreview )
{
if ( !m_pLockPreview->IsSelected() )
{
// unchecked the lock - switch to the latest requested selection
m_pParticleSystemPanel->SetParticleSystem( m_pUnlockSystem );
}
return;
}
if ( pPanel == m_pRenderBounds )
{
m_pParticleSystemPanel->RenderBounds( bState );
return;
}
if ( pPanel == m_pRenderCullBounds )
{
m_pParticleSystemPanel->RenderCullBounds( bState );
return;
}
if ( pPanel == m_pRenderHelpers )
{
m_pParticleSystemPanel->RenderHelpers( bState );
return;
}
if ( pPanel == m_pRenderControlPoints )
{
m_pParticleSystemPanel->RenderControlPoints( bState );
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" ) );
}
//-----------------------------------------------------------------------------
// Called when buttons are clicked
//-----------------------------------------------------------------------------
void CParticleSystemPreviewPanel::OnCommand( const char *pCommand )
{
if ( !Q_stricmp( pCommand, "StopEffect" ) )
{
m_pParticleSystemPanel->StopEffect();
return;
}
BaseClass::OnCommand( pCommand );
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,194 @@
//===== Copyright © 1996-2005, 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 );
}

View File

@@ -0,0 +1,89 @@
//======= Copyright (c) 1996-2009, Valve Corporation, All rights reserved. ======
//
// CSheetEditorPanel - Tool panel for editing sprite sheet information
//
//===============================================================================
#include "dme_controls/sheeteditorpanel.h"
#include "dme_controls/dmepanel.h"
#include "movieobjects/dmeparticlesystemdefinition.h"
#include "materialsystem/imesh.h"
#include "materialsystem/imaterial.h"
#include "materialsystem/imaterialvar.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"
#include "bitmap/psheet.h"
#include "matsys_controls/vmtpicker.h"
// NOTE: This has to be the last file included!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
//
// CSheetEditorPanel
//
//-----------------------------------------------------------------------------
//IMPLEMENT_DMEPANEL_FACTORY( CParticleSystemDmePanel, DmeParticleSystemDefinition, "DmeParticleSystemDefinitionEditor", "Particle System Editor", true );
CSheetEditorPanel::CSheetEditorPanel( vgui::Panel *pParent, const char *pName ) :
BaseClass( pParent, pName ),
m_pSheetInfo(NULL)
{
m_pTitleLabel = new vgui::Label( this, "TestLabel", "<Title>" );
m_pTitleLabel->SetPinCorner( Panel::PIN_TOPLEFT, 12, 12 );
m_pTitleLabel->SetWide( 400 );
m_pVMTPicker = new CVMTPicker( this, "SheetPreview" );
m_pVMTPicker->SetAutoResize( Panel::PIN_TOPLEFT, Panel::AUTORESIZE_DOWNANDRIGHT, 200, 42, -12, -12 );
}
void CSheetEditorPanel::ApplySchemeSettings(vgui::IScheme *pScheme)
{
BaseClass::ApplySchemeSettings(pScheme);
m_pTitleLabel->SetBgColor( Color( 200, 200, 200, 255 ) );
m_pTitleLabel->SetFgColor( Color( 0, 0, 0, 255 ) );
SetBgColor( Color( 100, 200, 100, 255 ) );
}
CSheetEditorPanel::~CSheetEditorPanel()
{
}
void CSheetEditorPanel::SetParticleSystem( CDmeParticleSystemDefinition *pParticleSystem )
{
char strBuffer[ 256 ];
const char *pSystemName = "<no system>";
const char *pVMTName = "<no vmt>";
if ( pParticleSystem != NULL )
{
pSystemName = pParticleSystem->GetName();
if ( !pSystemName || !pSystemName[0] )
{
pSystemName = "<no name>";
}
}
if ( pParticleSystem != NULL )
{
pVMTName = pParticleSystem->GetValueString( "material" );
}
Q_snprintf( strBuffer, sizeof(strBuffer), "%s: %s", pSystemName, pVMTName );
m_pTitleLabel->SetText( strBuffer );
}

View File

@@ -0,0 +1,609 @@
//====== Copyright © 1996-2005, 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"
#include "soundchars.h"
#include "tier1/fmtstr.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: 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::OnKeyCodeTyped( 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( "KeyCodeTyped", "code", code );
vgui::ipanel()->SendMessage( m_pGameSoundList->GetVPanel(), pMsg, GetVPanel() );
pMsg->deleteThis();
return;
}
}
BaseClass::OnKeyCodeTyped( 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.Get(), 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();
if ( pSoundName[ 0 ] )
{
EngineTool()->ValidateSoundCache( CFmtStr( "sound\\%s", PSkipSoundChars( pSoundName ) ) );
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()
{
}
void CSoundPickerFrame::OnClose()
{
CSoundPicker *pPicker = static_cast <CSoundPicker*>( GetAssetPicker() );
pPicker->StopSoundPreview();
BaseClass::OnClose();
}
//-----------------------------------------------------------------------------
// 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();
if ( !pSoundName )
{
CloseModal();
return;
}
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 );
const char *pSoundName = pPicker->GetSelectedSoundName( i );
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 );
pSoundList->SetString( pBuf, soundname );
}
}
PostMessageAndClose( pActionKeys );
CloseModal();
}
return;
}
BaseClass::OnCommand( pCommand );
}

View File

@@ -0,0 +1,212 @@
//====== Copyright © 1996-2005, 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 );
}