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
@@ -0,0 +1,64 @@
// ----------------------------------------- //
// File generated by VPC //
// ----------------------------------------- //
Source file: F:\csgo_64\cstrike15_src\tools\commedit\commeditdoc.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\commedit\commeditdoc.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\commedit\commeditdoc.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\tools\commedit\commedittool.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\commedit\commedittool.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\commedit\commedittool.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\tools\commedit\commentarynodebrowserpanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\commedit\commentarynodebrowserpanel.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\commedit\commentarynodebrowserpanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\tools\commedit\commentarypropertiespanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\commedit\commentarypropertiespanel.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\commedit\commentarypropertiespanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\common\debug_dll_check.cpp
Debug output file: F:\csgo_64\cstrike15_src\common\debug_dll_check.cpp
Release output file: F:\csgo_64\cstrike15_src\common\debug_dll_check.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\tools\commedit\dmecommentarynodeentity.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\commedit\dmecommentarynodeentity.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\commedit\dmecommentarynodeentity.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\public\interpolatortypes.cpp
Debug output file: F:\csgo_64\cstrike15_src\public\interpolatortypes.cpp
Release output file: F:\csgo_64\cstrike15_src\public\interpolatortypes.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\public\tier0\memoverride.cpp
Debug output file: F:\csgo_64\cstrike15_src\public\tier0\memoverride.cpp
Release output file: F:\csgo_64\cstrike15_src\public\tier0\memoverride.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\public\registry.cpp
Debug output file: F:\csgo_64\cstrike15_src\public\registry.cpp
Release output file: F:\csgo_64\cstrike15_src\public\registry.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\public\vgui_controls\vgui_controls.cpp
Debug output file: F:\csgo_64\cstrike15_src\public\vgui_controls\vgui_controls.cpp
Release output file: F:\csgo_64\cstrike15_src\public\vgui_controls\vgui_controls.cpp
Containing unity file:
PCH file:
+66
View File
@@ -0,0 +1,66 @@
//-----------------------------------------------------------------------------
// COMMEDIT.VPC
//
// Project Script
//-----------------------------------------------------------------------------
$Macro SRCDIR "..\.."
$Macro OUTBINDIR "$SRCDIR\..\game\bin\tools"
$Include "$SRCDIR\vpc_scripts\source_dll_win32_base.vpc"
$Configuration
{
$Compiler
{
$AdditionalIncludeDirectories "$BASE,.\,..\common,$SRCDIR\game\shared"
$PreprocessorDefinitions "$BASE;COMMEDIT_EXPORTS"
}
$Linker
{
$AdditionalDependencies "$BASE Psapi.lib"
}
}
$Project "Commedit"
{
$Folder "Source Files"
{
$File "commeditdoc.cpp"
$File "commedittool.cpp"
$File "commentarynodebrowserpanel.cpp"
$File "commentarypropertiespanel.cpp"
$File "dmecommentarynodeentity.cpp"
$File "$SRCDIR\public\interpolatortypes.cpp"
$File "$SRCDIR\public\registry.cpp"
$File "$SRCDIR\public\vgui_controls\vgui_controls.cpp"
}
$Folder "Header Files"
{
$File "commeditdoc.h"
$File "commedittool.h"
$File "commentarynodebrowserpanel.h"
$File "commentarypropertiespanel.h"
$File "dmecommentarynodeentity.h"
$File "$SRCDIR\public\mathlib\mathlib.h"
}
$Folder "Link Libraries"
{
$File "$SRCDIR\lib\public\bonesetup.lib"
$File "$SRCDIR\lib\public\datamodel.lib"
$File "$SRCDIR\lib\public\dmxloader.lib"
$File "$SRCDIR\lib\public\dme_controls.lib"
$File "$SRCDIR\lib\public\dmserializers.lib"
$File "$SRCDIR\lib\public\dmxloader.lib"
$File "$SRCDIR\lib\public\mathlib.lib"
$File "$SRCDIR\lib\public\matsys_controls.lib"
$File "$SRCDIR\lib\public\movieobjects.lib"
$File "$SRCDIR\lib\public\tier2.lib"
$File "$SRCDIR\lib\public\tier3.lib"
$File "$SRCDIR\lib\public\toolutils.lib"
$File "$SRCDIR\lib\public\vgui_controls.lib"
}
}
+13
View File
@@ -0,0 +1,13 @@
"vpc_cache"
{
"CacheVersion" "1"
"win32"
{
"CRCFile" "commedit.vcxproj.vpc_crc"
"OutputFiles"
{
"0" "commedit.vcxproj"
"1" "commedit.vcxproj.filters"
}
}
}
+465
View File
@@ -0,0 +1,465 @@
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "commeditdoc.h"
#include "tier1/keyvalues.h"
#include "tier1/utlbuffer.h"
#include "toolutils/enginetools_int.h"
#include "filesystem.h"
#include "commedittool.h"
#include "toolframework/ienginetool.h"
#include "dmecommentarynodeentity.h"
#include "datamodel/idatamodel.h"
#include "toolutils/attributeelementchoicelist.h"
#include "commentarynodebrowserpanel.h"
#include "vgui_controls/messagebox.h"
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CCommEditDoc::CCommEditDoc( ICommEditDocCallback *pCallback ) : m_pCallback( pCallback )
{
m_hRoot = NULL;
m_pTXTFileName[0] = 0;
m_bDirty = false;
g_pDataModel->InstallNotificationCallback( this );
}
CCommEditDoc::~CCommEditDoc()
{
g_pDataModel->RemoveNotificationCallback( this );
}
//-----------------------------------------------------------------------------
// Inherited from INotifyUI
//-----------------------------------------------------------------------------
void CCommEditDoc::NotifyDataChanged( const char *pReason, int nNotifySource, int nNotifyFlags )
{
OnDataChanged( pReason, nNotifySource, nNotifyFlags );
}
//-----------------------------------------------------------------------------
// Gets the file name
//-----------------------------------------------------------------------------
const char *CCommEditDoc::GetTXTFileName()
{
return m_pTXTFileName;
}
void CCommEditDoc::SetTXTFileName( const char *pFileName )
{
Q_strncpy( m_pTXTFileName, pFileName, sizeof( m_pTXTFileName ) );
Q_FixSlashes( m_pTXTFileName );
SetDirty( true );
}
//-----------------------------------------------------------------------------
// Dirty bits
//-----------------------------------------------------------------------------
void CCommEditDoc::SetDirty( bool bDirty )
{
m_bDirty = bDirty;
}
bool CCommEditDoc::IsDirty() const
{
return m_bDirty;
}
//-----------------------------------------------------------------------------
// Saves/loads from file
//-----------------------------------------------------------------------------
bool CCommEditDoc::LoadFromFile( const char *pFileName )
{
Assert( !m_hRoot.Get() );
CAppDisableUndoScopeGuard guard( "CCommEditDoc::LoadFromFile", 0 );
SetDirty( false );
if ( !pFileName[0] )
return false;
char mapname[ 256 ];
// Compute the map name
const char *pMaps = Q_stristr( pFileName, "\\maps\\" );
if ( !pMaps )
return false;
// Build map name
//int nNameLen = (int)( (size_t)pComm - (size_t)pMaps ) - 5;
Q_StripExtension( pFileName, mapname, sizeof(mapname) );
char *pszFileName = (char*)Q_UnqualifiedFileName(mapname);
// Set the txt file name.
// If we loaded an existing commentary file, keep the same filename.
// If we loaded a .bsp, change the name & the extension.
if ( !V_stricmp( Q_GetFileExtension( pFileName ), "bsp" ) )
{
const char *pCommentaryAppend = "_commentary.txt";
Q_StripExtension( pFileName, m_pTXTFileName, sizeof(m_pTXTFileName)- strlen(pCommentaryAppend) - 1 );
Q_strcat( m_pTXTFileName, pCommentaryAppend, sizeof( m_pTXTFileName ) );
if ( g_pFileSystem->FileExists( m_pTXTFileName ) )
{
char pBuf[1024];
Q_snprintf( pBuf, sizeof(pBuf), "File %s already exists!\n", m_pTXTFileName );
m_pTXTFileName[0] = 0;
vgui::MessageBox *pMessageBox = new vgui::MessageBox( "Unable to overwrite file!\n", pBuf, g_pCommEditTool );
pMessageBox->DoModal( );
return false;
}
DmFileId_t fileid = g_pDataModel->FindOrCreateFileId( m_pTXTFileName );
m_hRoot = CreateElement<CDmElement>( "root", fileid );
CDmrElementArray<> subkeys( m_hRoot->AddAttribute( "subkeys", AT_ELEMENT_ARRAY ) );
CDmElement *pRoot2 = CreateElement<CDmElement>( "Entities", fileid );
pRoot2->AddAttribute( "subkeys", AT_ELEMENT_ARRAY );
subkeys.AddToTail( pRoot2 );
g_pDataModel->SetFileRoot( fileid, m_hRoot );
}
else
{
char *pComm = Q_stristr( pszFileName, "_commentary" );
if ( !pComm )
{
char pBuf[1024];
Q_snprintf( pBuf, sizeof(pBuf), "File %s is not a commentary file!\nThe file name must end in _commentary.txt.\n", m_pTXTFileName );
m_pTXTFileName[0] = 0;
vgui::MessageBox *pMessageBox = new vgui::MessageBox( "Bad file name!\n", pBuf, g_pCommEditTool );
pMessageBox->DoModal( );
return false;
}
// Clip off the "_commentary" at the end of the filename
*pComm = '\0';
// This is not undoable
CDisableUndoScopeGuard guard;
CDmElement *pTXT = NULL;
DmFileId_t fileid = g_pDataModel->RestoreFromFile( pFileName, NULL, "commentary", &pTXT );
if ( fileid == DMFILEID_INVALID )
{
m_pTXTFileName[0] = 0;
return false;
}
SetTXTFileName( pFileName );
m_hRoot = pTXT;
}
guard.Release();
SetDirty( false );
char cmd[ 256 ];
Q_snprintf( cmd, sizeof( cmd ), "disconnect; map %s\n", pszFileName );
enginetools->Command( cmd );
enginetools->Execute( );
return true;
}
void CCommEditDoc::SaveToFile( )
{
if ( m_hRoot.Get() && m_pTXTFileName && m_pTXTFileName[0] )
{
g_pDataModel->SaveToFile( m_pTXTFileName, NULL, "keyvalues", "keyvalues", m_hRoot );
}
SetDirty( false );
}
//-----------------------------------------------------------------------------
// Returns the root object
//-----------------------------------------------------------------------------
CDmElement *CCommEditDoc::GetRootObject()
{
return m_hRoot;
}
//-----------------------------------------------------------------------------
// Returns the entity list
//-----------------------------------------------------------------------------
CDmAttribute *CCommEditDoc::GetEntityList()
{
CDmrElementArray<> mainKeys( m_hRoot, "subkeys" );
if ( !mainKeys.IsValid() || mainKeys.Count() == 0 )
return NULL;
CDmeHandle<CDmElement> hEntityList;
hEntityList = mainKeys[ 0 ];
return hEntityList ? hEntityList->GetAttribute( "subkeys", AT_ELEMENT_ARRAY ) : NULL;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCommEditDoc::AddNewInfoRemarkable( const Vector &vecOrigin, const QAngle &angAngles )
{
CDmrCommentaryNodeEntityList entities( GetEntityList() );
if ( !entities.IsValid() )
return;
CDmeCommentaryNodeEntity *pTarget;
{
CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, "Add Info Remarkable", "Add Info Remarkable" );
pTarget = CreateElement<CDmeCommentaryNodeEntity>( "remarkable", entities.GetOwner()->GetFileId() );
pTarget->SetName( "entity" );
pTarget->SetValue( "classname", "info_remarkable" );
pTarget->SetRenderOrigin( vecOrigin );
pTarget->SetRenderAngles( angAngles );
entities.AddToTail( pTarget );
pTarget->MarkDirty();
pTarget->DrawInEngine( true );
}
g_pCommEditTool->GetCommentaryNodeBrowser()->SelectNode( pTarget );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCommEditDoc::AddNewInfoRemarkable( void )
{
Vector vecOrigin;
QAngle angAngles;
float flFov;
clienttools->GetLocalPlayerEyePosition( vecOrigin, angAngles, flFov );
AddNewInfoRemarkable( vecOrigin, vec3_angle );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCommEditDoc::AddNewInfoTarget( const Vector &vecOrigin, const QAngle &angAngles )
{
CDmrCommentaryNodeEntityList entities( GetEntityList() );
if ( !entities.IsValid() )
return;
CDmeCommentaryNodeEntity *pTarget;
{
CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, "Add Info Target", "Add Info Target" );
pTarget = CreateElement<CDmeCommentaryNodeEntity>( "target", entities.GetOwner()->GetFileId() );
pTarget->SetName( "entity" );
pTarget->SetValue( "classname", "info_target" );
pTarget->SetRenderOrigin( vecOrigin );
pTarget->SetRenderAngles( angAngles );
entities.AddToTail( pTarget );
pTarget->MarkDirty();
pTarget->DrawInEngine( true );
}
g_pCommEditTool->GetCommentaryNodeBrowser()->SelectNode( pTarget );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCommEditDoc::AddNewInfoTarget( void )
{
Vector vecOrigin;
QAngle angAngles;
float flFov;
clienttools->GetLocalPlayerEyePosition( vecOrigin, angAngles, flFov );
AddNewInfoTarget( vecOrigin, vec3_angle );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCommEditDoc::AddNewCommentaryNode( const Vector &vecOrigin, const QAngle &angAngles )
{
CDmrCommentaryNodeEntityList entities = GetEntityList();
CDmeCommentaryNodeEntity *pNode;
{
CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, "Add Commentary Node", "Add Commentary Node" );
pNode = CreateElement<CDmeCommentaryNodeEntity>( "node", entities.GetOwner()->GetFileId() );
pNode->SetName( "entity" );
pNode->SetValue( "classname", "point_commentary_node" );
pNode->SetRenderOrigin( vecOrigin );
pNode->SetRenderAngles( angAngles );
pNode->SetValue( "precommands", "" );
pNode->SetValue( "postcommands", "" );
pNode->SetValue( "commentaryfile", "" );
pNode->SetValue( "viewtarget", "" );
pNode->SetValue( "viewposition", "" );
pNode->SetValue<int>( "prevent_movement", 0 );
pNode->SetValue( "speakers", "" );
pNode->SetValue( "synopsis", "" );
entities.AddToTail( pNode );
pNode->MarkDirty();
pNode->DrawInEngine( true );
}
g_pCommEditTool->GetCommentaryNodeBrowser()->SelectNode( pNode );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCommEditDoc::AddNewCommentaryNode( void )
{
Vector vecOrigin;
QAngle angAngles;
float flFov;
clienttools->GetLocalPlayerEyePosition( vecOrigin, angAngles, flFov );
AddNewCommentaryNode( vecOrigin, vec3_angle );
}
//-----------------------------------------------------------------------------
// Deletes a commentary node
//-----------------------------------------------------------------------------
void CCommEditDoc::DeleteCommentaryNode( CDmElement *pRemoveNode )
{
CDmrCommentaryNodeEntityList entities = GetEntityList();
int nCount = entities.Count();
for ( int i = 0; i < nCount; ++i )
{
if ( pRemoveNode == entities[i] )
{
CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, "Delete Commentary Node", "Delete Commentary Node" );
CDmeCommentaryNodeEntity *pNode = entities[ i ];
pNode->DrawInEngine( false );
entities.FastRemove( i );
return;
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : &vecOrigin -
// &angAbsAngles -
// Output : CDmeCommentaryNodeEntity
//-----------------------------------------------------------------------------
CDmeCommentaryNodeEntity *CCommEditDoc::GetCommentaryNodeForLocation( Vector &vecOrigin, QAngle &angAbsAngles )
{
CDmrCommentaryNodeEntityList entities = GetEntityList();
int nCount = entities.Count();
for ( int i = 0; i < nCount; ++i )
{
CDmeCommentaryNodeEntity *pNode = entities[ i ];
if ( !pNode )
continue;
Vector &vecAngles = *(Vector*)(&pNode->GetRenderAngles());
if ( pNode->GetRenderOrigin().DistTo( vecOrigin ) < 1e-3 && vecAngles.DistTo( *(Vector*)&angAbsAngles ) < 1e-1 )
return pNode;
}
return NULL;
}
//-----------------------------------------------------------------------------
// Populate string choice lists
//-----------------------------------------------------------------------------
bool CCommEditDoc::GetStringChoiceList( const char *pChoiceListType, CDmElement *pElement,
const char *pAttributeName, bool bArrayElement, StringChoiceList_t &list )
{
if ( !Q_stricmp( pChoiceListType, "info_targets" ) )
{
CDmrCommentaryNodeEntityList entities = GetEntityList();
StringChoice_t sChoice;
sChoice.m_pValue = "";
sChoice.m_pChoiceString = "";
list.AddToTail( sChoice );
int nCount = entities.Count();
for ( int i = 0; i < nCount; ++i )
{
CDmeCommentaryNodeEntity *pNode = entities[ i ];
if ( !pNode )
continue;
if ( !V_stricmp( pNode->GetClassName(), "info_target" ) )
{
StringChoice_t sChoice;
sChoice.m_pValue = pNode->GetTargetName();
sChoice.m_pChoiceString = pNode->GetTargetName();
list.AddToTail( sChoice );
}
}
return true;
}
return false;
}
//-----------------------------------------------------------------------------
// Populate element choice lists
//-----------------------------------------------------------------------------
bool CCommEditDoc::GetElementChoiceList( const char *pChoiceListType, CDmElement *pElement,
const char *pAttributeName, bool bArrayElement, ElementChoiceList_t &list )
{
if ( !Q_stricmp( pChoiceListType, "allelements" ) )
{
AddElementsRecursively( m_hRoot, list );
return true;
}
if ( !Q_stricmp( pChoiceListType, "info_targets" ) )
{
CDmrCommentaryNodeEntityList entities = GetEntityList();
bool bFound = false;
int nCount = entities.Count();
for ( int i = 0; i < nCount; ++i )
{
CDmeCommentaryNodeEntity *pNode = entities[ i ];
if ( pNode && !V_stricmp( pNode->GetClassName(), "info_target" ) )
{
bFound = true;
ElementChoice_t sChoice;
sChoice.m_pValue = pNode;
sChoice.m_pChoiceString = pNode->GetTargetName();
list.AddToTail( sChoice );
}
}
return bFound;
}
// by default, try to treat the choice list type as a Dme element type
AddElementsRecursively( m_hRoot, list, pChoiceListType );
return list.Count() > 0;
}
//-----------------------------------------------------------------------------
// Called when data changes
//-----------------------------------------------------------------------------
void CCommEditDoc::OnDataChanged( const char *pReason, int nNotifySource, int nNotifyFlags )
{
SetDirty( nNotifyFlags & NOTIFY_SETDIRTYFLAG ? true : false );
m_pCallback->OnDocChanged( pReason, nNotifySource, nNotifyFlags );
}
+96
View File
@@ -0,0 +1,96 @@
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
// $NoKeywords: $
//
//===========================================================================//
#ifndef COMMEDITDOC_H
#define COMMEDITDOC_H
#ifdef _WIN32
#pragma once
#endif
#include "dme_controls/inotifyui.h"
#include "datamodel/dmehandle.h"
#include "datamodel/dmelement.h"
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class ICommEditDocCallback;
class CCommEditDoc;
class CDmeCommentaryNodeEntity;
typedef CDmrElementArray<CDmeCommentaryNodeEntity> CDmrCommentaryNodeEntityList;
//-----------------------------------------------------------------------------
// Contains all editable state
//-----------------------------------------------------------------------------
class CCommEditDoc : public IDmNotify
{
public:
CCommEditDoc( ICommEditDocCallback *pCallback );
~CCommEditDoc();
// Inherited from INotifyUI
virtual void NotifyDataChanged( const char *pReason, int nNotifySource, int nNotifyFlags );
// Sets/Gets the file name
const char *GetTXTFileName();
void SetTXTFileName( const char *pFileName );
// Dirty bits (has it changed since the last time it was saved?)
void SetDirty( bool bDirty );
bool IsDirty() const;
// Saves/loads from file
bool LoadFromFile( const char *pFileName );
void SaveToFile( );
// Returns the root object
CDmElement *GetRootObject();
// Called when data changes (see INotifyUI for flags)
void OnDataChanged( const char *pReason, int nNotifySource, int nNotifyFlags );
// Returns the entity list
CDmAttribute *GetEntityList();
// Adds a new info_target
void AddNewInfoTarget( void );
void AddNewInfoTarget( const Vector &vecOrigin, const QAngle &angAngles );
// Adds a new commentary node
void AddNewCommentaryNode( void );
void AddNewCommentaryNode( const Vector &vecOrigin, const QAngle &angAngles );
// Adds an info remarkable
void AddNewInfoRemarkable( void );
void AddNewInfoRemarkable( const Vector &vecOrigin, const QAngle &angAngles );
// Deletes a commentary node
void DeleteCommentaryNode( CDmElement *pNode );
// Returns the commentary node at the specified location
CDmeCommentaryNodeEntity *GetCommentaryNodeForLocation( Vector &vecOrigin, QAngle &angAbsAngles );
// For element choice lists. Return false if it's an unknown choice list type
virtual bool GetStringChoiceList( const char *pChoiceListType, CDmElement *pElement,
const char *pAttributeName, bool bArrayElement, StringChoiceList_t &list );
virtual bool GetElementChoiceList( const char *pChoiceListType, CDmElement *pElement,
const char *pAttributeName, bool bArrayElement, ElementChoiceList_t &list );
private:
ICommEditDocCallback *m_pCallback;
CDmeHandle< CDmElement > m_hRoot;
char m_pTXTFileName[512];
bool m_bDirty;
};
#endif // COMMEDITDOC_H
File diff suppressed because it is too large Load Diff
+239
View File
@@ -0,0 +1,239 @@
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======
//
// Purpose: CommEdit tool; main UI smarts class
//
//=============================================================================
#ifndef COMMEDITTOOL_H
#define COMMEDITTOOL_H
#ifdef _WIN32
#pragma once
#endif
#include "tier0/platform.h"
#include "toolutils/basetoolsystem.h"
#include "toolutils/recentfilelist.h"
#include "toolutils/toolmenubar.h"
#include "toolutils/toolswitchmenubutton.h"
#include "toolutils/tooleditmenubutton.h"
#include "toolutils/toolfilemenubutton.h"
#include "toolutils/toolmenubutton.h"
#include "datamodel/dmelement.h"
#include "dmecommentarynodeentity.h"
#include "toolframework/ienginetool.h"
#include "toolutils/enginetools_int.h"
#include "toolutils/savewindowpositions.h"
#include "toolutils/toolwindowfactory.h"
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class CDmElement;
class CConsolePage;
class CCommEditDoc;
class CCommentaryPropertiesPanel;
class CCommentaryNodeBrowserPanel;
namespace vgui
{
class Panel;
}
//-----------------------------------------------------------------------------
// Allows the doc to call back into the CommEdit editor tool
//-----------------------------------------------------------------------------
abstract_class ICommEditDocCallback
{
public:
// Called by the doc when the data changes
virtual void OnDocChanged( const char *pReason, int nNotifySource, int nNotifyFlags ) = 0;
};
//-----------------------------------------------------------------------------
// Global methods of the commedit tool
//-----------------------------------------------------------------------------
abstract_class ICommEditTool
{
public:
// Gets at the rool panel (for modal dialogs)
virtual vgui::Panel *GetRootPanel() = 0;
// Gets the registry name (for saving settings)
virtual const char *GetRegistryName() = 0;
// Shows a particular entity in the entity properties dialog
virtual void ShowEntityInEntityProperties( CDmeCommentaryNodeEntity *pEntity ) = 0;
};
//-----------------------------------------------------------------------------
// Implementation of the CommEdit tool
//-----------------------------------------------------------------------------
class CCommEditTool : public CBaseToolSystem, public IFileMenuCallbacks, public ICommEditDocCallback, public ICommEditTool
{
DECLARE_CLASS_SIMPLE( CCommEditTool, CBaseToolSystem );
public:
CCommEditTool();
// Inherited from IToolSystem
virtual const char *GetToolName() { return "Commentary Editor"; }
virtual bool Init( );
virtual void Shutdown();
virtual bool CanQuit( const char *pExitMsg );
virtual void OnToolActivate();
virtual void OnToolDeactivate();
virtual const char* GetEntityData( const char *pActualEntityData );
virtual void DrawCommentaryNodeEntitiesInEngine( bool bDrawInEngine );
virtual void ClientLevelInitPostEntity();
virtual void ClientLevelShutdownPreEntity();
virtual bool TrapKey( ButtonCode_t key, bool down );
virtual void ClientPreRender();
// Inherited from IFileMenuCallbacks
virtual int GetFileMenuItemsEnabled( );
virtual void AddRecentFilesToMenu( vgui::Menu *menu );
virtual bool GetPerforceFileName( char *pFileName, int nMaxLen );
// Inherited from ICommEditDocCallback
virtual void OnDocChanged( const char *pReason, int nNotifySource, int nNotifyFlags );
virtual vgui::Panel *GetRootPanel() { return this; }
virtual void ShowEntityInEntityProperties( CDmeCommentaryNodeEntity *pEntity );
// Inherited from CBaseToolSystem
virtual vgui::HScheme GetToolScheme();
virtual vgui::Menu *CreateActionMenu( vgui::Panel *pParent );
virtual void OnCommand( const char *cmd );
virtual const char *GetRegistryName() { return "CommEditTool"; }
virtual const char *GetBindingsContextFile() { return "cfg/CommEdit.kb"; }
virtual vgui::MenuBar *CreateMenuBar( CBaseToolSystem *pParent );
MESSAGE_FUNC( Save, "OnSave" );
void SaveAndTest();
void CenterView( CDmeCommentaryNodeEntity* pEntity );
// Enter mode where we preview dropping nodes
void EnterNodeDropMode();
void LeaveNodeDropMode();
public:
MESSAGE_FUNC( OnRestartLevel, "RestartLevel" );
MESSAGE_FUNC( OnNew, "OnNew" );
MESSAGE_FUNC( OnOpen, "OnOpen" );
MESSAGE_FUNC( OnSaveAs, "OnSaveAs" );
MESSAGE_FUNC( OnClose, "OnClose" );
MESSAGE_FUNC( OnCloseNoSave, "OnCloseNoSave" );
MESSAGE_FUNC( OnMarkNotDirty, "OnMarkNotDirty" );
MESSAGE_FUNC( OnExit, "OnExit" );
// Commands related to the edit menu
void OnDescribeUndo();
// Methods related to the CommEdit menu
MESSAGE_FUNC( OnAddNewNodes, "AddNewNodes" );
// Methods related to the view menu
MESSAGE_FUNC( OnToggleProperties, "OnToggleProperties" );
MESSAGE_FUNC( OnToggleEntityReport, "OnToggleEntityReport" );
MESSAGE_FUNC( OnToggleConsole, "ToggleConsole" );
MESSAGE_FUNC( OnDefaultLayout, "OnDefaultLayout" );
// Keybindings
KEYBINDING_FUNC( undo, KEY_Z, vgui::MODIFIER_CONTROL, OnUndo, "#undo_help", 0 );
KEYBINDING_FUNC( redo, KEY_Z, vgui::MODIFIER_CONTROL | vgui::MODIFIER_SHIFT, OnRedo, "#redo_help", 0 );
KEYBINDING_FUNC_NODECLARE( CommEditAddNewNodes, KEY_A, vgui::MODIFIER_CONTROL, OnAddNewNodes, "#CommEditAddNewNodesHelp", 0 );
void PerformNew();
void OpenFileFromHistory( int slot );
void OpenSpecificFile( const char *pFileName );
virtual void SetupFileOpenDialog( vgui::FileOpenDialog *pDialog, bool bOpenFile, const char *pFileFormat, KeyValues *pContextKeyValues );
virtual bool OnReadFileFromDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues );
virtual bool OnWriteFileToDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues );
virtual void OnFileOperationCompleted( const char *pFileType, bool bWroteFile, vgui::FileOpenStateMachine::CompletionState_t state, KeyValues *pContextKeyValues );
void AttachAllEngineEntities();
// returns the document
CCommEditDoc *GetDocument();
// Gets at tool windows
CCommentaryPropertiesPanel *GetProperties();
CCommentaryNodeBrowserPanel *GetCommentaryNodeBrowser();
CConsolePage *GetConsole();
CDmeHandle< CDmeCommentaryNodeEntity > GetCurrentEntity( void ) { return m_hCurrentEntity; }
private:
// Loads up a new document
bool LoadDocument( const char *pDocName );
// Updates the menu bar based on the current file
void UpdateMenuBar( );
// Shows element properties
void ShowElementProperties( );
virtual const char *GetLogoTextureName();
// Creates, destroys tools
void CreateTools( CCommEditDoc *doc );
void DestroyTools();
// Initializes the tools
void InitTools();
// Shows, toggles tool windows
void ToggleToolWindow( Panel *tool, char const *toolName );
void ShowToolWindow( Panel *tool, char const *toolName, bool visible );
// Kills all tool windows
void DestroyToolContainers();
// Gets the position of the preview object
void GetPlacementInfo( Vector &vecOrigin, QAngle &angles );
// Brings the console to front
void BringConsoleToFront();
private:
enum DropNodeMode_t
{
DROP_MODE_COMMENTARY = 0,
DROP_MODE_TARGET,
DROP_MODE_REMARKABLE,
DROP_MODE_COUNT,
};
// Document
CCommEditDoc *m_pDoc;
// The menu bar
CToolFileMenuBar *m_pMenuBar;
// Element properties for editing material
vgui::DHANDLE< CCommentaryPropertiesPanel > m_hProperties;
// The entity report
vgui::DHANDLE< CCommentaryNodeBrowserPanel > m_hCommentaryNodeBrowser;
// The console
vgui::DHANDLE< CConsolePage > m_hConsole;
// The currently viewed entity
CDmeHandle< CDmeCommentaryNodeEntity > m_hCurrentEntity;
// Separate undo context for the act busy tool
bool m_bInNodeDropMode;
DropNodeMode_t m_nDropMode;
CDmeHandle< CDmeCommentaryNodeEntity > m_hPreviewEntity[DROP_MODE_COUNT];
CToolWindowFactory< ToolWindow > m_ToolWindowFactory;
};
extern CCommEditTool *g_pCommEditTool;
#endif // COMMEDITTOOL_H
@@ -0,0 +1,283 @@
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose: Singleton dialog that generates and presents the entity report.
//
//===========================================================================//
#include "CommentaryNodeBrowserPanel.h"
#include "tier1/keyvalues.h"
#include "tier1/utlbuffer.h"
#include "iregistry.h"
#include "vgui/ivgui.h"
#include "vgui_controls/listpanel.h"
#include "vgui_controls/textentry.h"
#include "vgui_controls/checkbutton.h"
#include "vgui_controls/combobox.h"
#include "vgui_controls/radiobutton.h"
#include "vgui_controls/messagebox.h"
#include "commeditdoc.h"
#include "commedittool.h"
#include "datamodel/dmelement.h"
#include "vgui/keycode.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
using namespace vgui;
//-----------------------------------------------------------------------------
// Sort by target name
//-----------------------------------------------------------------------------
static int __cdecl TargetNameSortFunc( vgui::ListPanel *pPanel, const ListPanelItem &item1, const ListPanelItem &item2 )
{
const char *string1 = item1.kv->GetString("targetname");
const char *string2 = item2.kv->GetString("targetname");
int nRetVal = Q_stricmp( string1, string2 );
if ( nRetVal != 0 )
return nRetVal;
string1 = item1.kv->GetString("classname");
string2 = item2.kv->GetString("classname");
return Q_stricmp( string1, string2 );
}
//-----------------------------------------------------------------------------
// Sort by class name
//-----------------------------------------------------------------------------
static int __cdecl ClassNameSortFunc( vgui::ListPanel *pPanel, const ListPanelItem &item1, const ListPanelItem &item2 )
{
const char *string1 = item1.kv->GetString("classname");
const char *string2 = item2.kv->GetString("classname");
int nRetVal = Q_stricmp( string1, string2 );
if ( nRetVal != 0 )
return nRetVal;
string1 = item1.kv->GetString("targetname");
string2 = item2.kv->GetString("targetname");
return Q_stricmp( string1, string2 );
}
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CCommentaryNodeBrowserPanel::CCommentaryNodeBrowserPanel( CCommEditDoc *pDoc, vgui::Panel* pParent, const char *pName )
: BaseClass( pParent, pName ), m_pDoc( pDoc )
{
SetPaintBackgroundEnabled( true );
m_pEntities = new vgui::ListPanel( this, "Entities" );
m_pEntities->AddColumnHeader( 0, "targetname", "Name", 52, ListPanel::COLUMN_RESIZEWITHWINDOW );
m_pEntities->AddColumnHeader( 1, "classname", "Class Name", 52, ListPanel::COLUMN_RESIZEWITHWINDOW );
m_pEntities->SetColumnSortable( 0, true );
m_pEntities->SetColumnSortable( 1, true );
m_pEntities->SetEmptyListText( "No Entities" );
// m_pEntities->SetDragEnabled( true );
m_pEntities->AddActionSignalTarget( this );
m_pEntities->SetSortFunc( 0, TargetNameSortFunc );
m_pEntities->SetSortFunc( 1, ClassNameSortFunc );
m_pEntities->SetSortColumn( 0 );
LoadControlSettingsAndUserConfig( "resource/commentarynodebrowserpanel.res" );
UpdateEntityList();
}
CCommentaryNodeBrowserPanel::~CCommentaryNodeBrowserPanel()
{
SaveUserConfig();
}
//-----------------------------------------------------------------------------
// Purpose: Shows the most recent selected object in properties window
//-----------------------------------------------------------------------------
void CCommentaryNodeBrowserPanel::OnProperties( )
{
if ( m_pEntities->GetSelectedItemsCount() == 0 )
{
g_pCommEditTool->ShowEntityInEntityProperties( NULL );
return;
}
int iSel = m_pEntities->GetSelectedItem( 0 );
KeyValues *kv = m_pEntities->GetItem( iSel );
CDmeCommentaryNodeEntity *pEntity = CastElement< CDmeCommentaryNodeEntity >( (CDmElement *)kv->GetPtr( "entity" ) );
g_pCommEditTool->ShowEntityInEntityProperties( pEntity );
}
//-----------------------------------------------------------------------------
// Purpose: Deletes the marked objects.
//-----------------------------------------------------------------------------
void CCommentaryNodeBrowserPanel::OnDeleteEntities(void)
{
int iSel = m_pEntities->GetSelectedItem( 0 );
{
// This is undoable
CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, "Delete Entities", "Delete Entities" );
//
// Build a list of objects to delete.
//
int nCount = m_pEntities->GetSelectedItemsCount();
for (int i = 0; i < nCount; i++)
{
int nItemID = m_pEntities->GetSelectedItem(i);
KeyValues *kv = m_pEntities->GetItem( nItemID );
CDmElement *pEntity = (CDmElement *)kv->GetPtr( "entity" );
if ( pEntity )
{
m_pDoc->DeleteCommentaryNode( pEntity );
}
}
}
// Update the list box selection.
if (iSel >= m_pEntities->GetItemCount())
{
iSel = m_pEntities->GetItemCount() - 1;
}
m_pEntities->SetSingleSelectedItem( iSel );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCommentaryNodeBrowserPanel::OnKeyCodeTyped( vgui::KeyCode code )
{
if ( code == KEY_DELETE )
{
OnDeleteEntities();
}
else
{
BaseClass::OnKeyCodeTyped( code );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCommentaryNodeBrowserPanel::OnItemSelected( void )
{
OnProperties();
}
//-----------------------------------------------------------------------------
// Select a particular node
//-----------------------------------------------------------------------------
void CCommentaryNodeBrowserPanel::SelectNode( CDmeCommentaryNodeEntity *pNode )
{
m_pEntities->ClearSelectedItems();
for ( int nItemID = m_pEntities->FirstItem(); nItemID != m_pEntities->InvalidItemID(); nItemID = m_pEntities->NextItem( nItemID ) )
{
KeyValues *kv = m_pEntities->GetItem( nItemID );
CDmElement *pEntity = (CDmElement *)kv->GetPtr( "entity" );
if ( pEntity == pNode )
{
m_pEntities->AddSelectedItem( nItemID );
break;
}
}
}
//-----------------------------------------------------------------------------
// Called when buttons are clicked
//-----------------------------------------------------------------------------
void CCommentaryNodeBrowserPanel::OnCommand( const char *pCommand )
{
if ( !Q_stricmp( pCommand, "delete" ) )
{
// Confirm we want to do it
MessageBox *pConfirm = new MessageBox( "#CommEditDeleteObjects", "#CommEditDeleteObjectsMsg", g_pCommEditTool->GetRootPanel() );
pConfirm->AddActionSignalTarget( this );
pConfirm->SetOKButtonText( "Yes" );
pConfirm->SetCommand( new KeyValues( "DeleteEntities" ) );
pConfirm->SetCancelButtonVisible( true );
pConfirm->SetCancelButtonText( "No" );
pConfirm->DoModal();
return;
}
if ( !Q_stricmp( pCommand, "Save" ) )
{
g_pCommEditTool->Save();
return;
}
if ( !Q_stricmp( pCommand, "CenterView" ) )
{
if ( m_pEntities->GetSelectedItemsCount() == 1 )
{
int iSel = m_pEntities->GetSelectedItem( 0 );
KeyValues *kv = m_pEntities->GetItem( iSel );
CDmeCommentaryNodeEntity *pEntity = CastElement< CDmeCommentaryNodeEntity >( (CDmElement *)kv->GetPtr( "entity" ) );
g_pCommEditTool->CenterView( pEntity );
}
return;
}
if ( !Q_stricmp( pCommand, "SaveAndTest" ) )
{
g_pCommEditTool->SaveAndTest();
return;
}
if ( !Q_stricmp( pCommand, "DropNodes" ) )
{
g_pCommEditTool->EnterNodeDropMode();
return;
}
BaseClass::OnCommand( pCommand );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCommentaryNodeBrowserPanel::UpdateEntityList(void)
{
m_pEntities->RemoveAll();
CDmrCommentaryNodeEntityList entityList( m_pDoc->GetEntityList() );
if ( !entityList.IsValid() )
return;
int nCount = entityList.Count();
for ( int i = 0; i < nCount; ++i )
{
CDmElement *pEntity = entityList[i];
Assert( pEntity );
if ( !pEntity )
continue;
const char *pClassName = pEntity->GetValueString( "classname" );
if ( !pClassName || !pClassName[0] )
{
pClassName = "<no class>";
}
KeyValues *kv = new KeyValues( "node" );
kv->SetString( "classname", pClassName );
kv->SetPtr( "entity", pEntity );
const char *pTargetname = pEntity->GetValueString( "targetname" );
if ( !pTargetname || !pTargetname[0] )
{
pTargetname = "<no targetname>";
}
kv->SetString( "targetname", pTargetname );
m_pEntities->AddItem( kv, 0, false, false );
}
m_pEntities->SortList();
}
@@ -0,0 +1,67 @@
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
//===========================================================================//
#ifndef COMMENTARYNODEBROWSERPANEL_H
#define COMMENTARYNODEBROWSERPANEL_H
#ifdef _WIN32
#pragma once
#endif
#include "vgui_controls/editablepanel.h"
#include "tier1/utlstring.h"
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class CCommEditDoc;
class CDmeCommentaryNodeEntity;
namespace vgui
{
class ComboBox;
class Button;
class TextEntry;
class ListPanel;
class CheckButton;
class RadioButton;
}
//-----------------------------------------------------------------------------
// Panel that shows all entities in the level
//-----------------------------------------------------------------------------
class CCommentaryNodeBrowserPanel : public vgui::EditablePanel
{
DECLARE_CLASS_SIMPLE( CCommentaryNodeBrowserPanel, vgui::EditablePanel );
public:
CCommentaryNodeBrowserPanel( CCommEditDoc *pDoc, vgui::Panel* pParent, const char *pName ); // standard constructor
virtual ~CCommentaryNodeBrowserPanel();
// Inherited from Panel
virtual void OnCommand( const char *pCommand );
virtual void OnKeyCodeTyped( vgui::KeyCode code );
// Methods related to updating the listpanel
void UpdateEntityList();
// Select a particular node
void SelectNode( CDmeCommentaryNodeEntity *pNode );
private:
// Messages handled
MESSAGE_FUNC( OnDeleteEntities, "DeleteEntities" );
MESSAGE_FUNC( OnItemSelected, "ItemSelected" );
// Shows the most recent selected object in properties window
void OnProperties();
CCommEditDoc *m_pDoc;
vgui::ListPanel *m_pEntities;
};
#endif // COMMENTARYNODEBROWSERPANEL_H
@@ -0,0 +1,530 @@
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose: Singleton dialog that generates and presents the entity report.
//
//===========================================================================//
#include "CommentaryPropertiesPanel.h"
#include "tier1/keyvalues.h"
#include "tier1/utlbuffer.h"
#include "iregistry.h"
#include "vgui/ivgui.h"
#include "vgui_controls/listpanel.h"
#include "vgui_controls/textentry.h"
#include "vgui_controls/checkbutton.h"
#include "vgui_controls/combobox.h"
#include "vgui_controls/radiobutton.h"
#include "vgui_controls/messagebox.h"
#include "vgui_controls/scrollbar.h"
#include "vgui_controls/scrollableeditablepanel.h"
#include "commeditdoc.h"
#include "commedittool.h"
#include "datamodel/dmelement.h"
#include "dmecommentarynodeentity.h"
#include "dme_controls/soundpicker.h"
#include "dme_controls/soundrecordpanel.h"
#include "matsys_controls/picker.h"
#include "vgui_controls/fileopendialog.h"
#include "filesystem.h"
#include "tier2/fileutils.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
using namespace vgui;
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CCommentaryPropertiesPanel::CCommentaryPropertiesPanel( CCommEditDoc *pDoc, vgui::Panel* pParent )
: BaseClass( pParent, "CommentaryPropertiesPanel" ), m_pDoc( pDoc )
{
SetPaintBackgroundEnabled( true );
SetKeyBoardInputEnabled( true );
m_pCommentaryNode = new vgui::EditablePanel( (vgui::Panel*)NULL, "CommentaryNode" );
m_pNodeName = new vgui::TextEntry( m_pCommentaryNode, "CommentaryNodeName" );
m_pNodeName->AddActionSignalTarget( this );
m_pSoundFilePicker = new vgui::Button( m_pCommentaryNode, "AudioFilePickerButton", "", this, "PickSound" );
m_pSoundFileName = new vgui::TextEntry( m_pCommentaryNode, "AudioFileName" );
m_pSoundFileName->AddActionSignalTarget( this );
m_pRecordSound = new vgui::Button( m_pCommentaryNode, "RecordAudioButton", "", this, "Record" );
m_pSpeakerName = new vgui::TextEntry( m_pCommentaryNode, "Speaker" );
m_pSpeakerName->AddActionSignalTarget( this );
m_pSynopsis = new vgui::TextEntry( m_pCommentaryNode, "Synopsis" );
m_pSynopsis->AddActionSignalTarget( this );
m_pViewPositionPicker = new vgui::Button( m_pCommentaryNode, "ViewPositionPickerButton", "", this, "PickViewPosition" );
m_pViewTargetPicker = new vgui::Button( m_pCommentaryNode, "ViewTargetPickerButton", "", this, "PickViewTarget" );
m_pViewPosition = new vgui::TextEntry( m_pCommentaryNode, "ViewPosition" );
m_pViewPosition->AddActionSignalTarget( this );
m_pViewTarget = new vgui::TextEntry( m_pCommentaryNode, "ViewTarget" );
m_pViewTarget->AddActionSignalTarget( this );
m_pPreventMovement = new vgui::CheckButton( m_pCommentaryNode, "PreventMovement", "" );
m_pPreventMovement->SetCommand( "PreventMovementClicked" );
m_pPreventMovement->AddActionSignalTarget( this );
m_pStartCommands = new vgui::TextEntry( m_pCommentaryNode, "StartCommands" );
m_pStartCommands->AddActionSignalTarget( this );
m_pEndCommands = new vgui::TextEntry( m_pCommentaryNode, "EndCommands" );
m_pEndCommands->AddActionSignalTarget( this );
m_pPosition[0] = new vgui::TextEntry( m_pCommentaryNode, "PositionX" );
m_pPosition[0]->AddActionSignalTarget( this );
m_pPosition[1] = new vgui::TextEntry( m_pCommentaryNode, "PositionY" );
m_pPosition[1]->AddActionSignalTarget( this );
m_pPosition[2] = new vgui::TextEntry( m_pCommentaryNode, "PositionZ" );
m_pPosition[2]->AddActionSignalTarget( this );
m_pOrientation[0] = new vgui::TextEntry( m_pCommentaryNode, "Pitch" );
m_pOrientation[0]->AddActionSignalTarget( this );
m_pOrientation[1] = new vgui::TextEntry( m_pCommentaryNode, "Yaw" );
m_pOrientation[1]->AddActionSignalTarget( this );
m_pOrientation[2] = new vgui::TextEntry( m_pCommentaryNode, "Roll" );
m_pOrientation[2]->AddActionSignalTarget( this );
m_pCommentaryNode->LoadControlSettings( "resource/commentarypropertiessubpanel_node.res" );
m_pInfoTarget = new vgui::EditablePanel( (vgui::Panel*)NULL, "InfoTarget" );
m_pTargetName = new vgui::TextEntry( m_pInfoTarget, "TargetName" );
m_pTargetName->AddActionSignalTarget( this );
m_pTargetPosition[0] = new vgui::TextEntry( m_pInfoTarget, "PositionX" );
m_pTargetPosition[0]->AddActionSignalTarget( this );
m_pTargetPosition[1] = new vgui::TextEntry( m_pInfoTarget, "PositionY" );
m_pTargetPosition[1]->AddActionSignalTarget( this );
m_pTargetPosition[2] = new vgui::TextEntry( m_pInfoTarget, "PositionZ" );
m_pTargetPosition[2]->AddActionSignalTarget( this );
m_pTargetOrientation[0] = new vgui::TextEntry( m_pInfoTarget, "Pitch" );
m_pTargetOrientation[0]->AddActionSignalTarget( this );
m_pTargetOrientation[1] = new vgui::TextEntry( m_pInfoTarget, "Yaw" );
m_pTargetOrientation[1]->AddActionSignalTarget( this );
m_pTargetOrientation[2] = new vgui::TextEntry( m_pInfoTarget, "Roll" );
m_pTargetOrientation[2]->AddActionSignalTarget( this );
m_pInfoTarget->LoadControlSettings( "resource/commentarypropertiessubpanel_target.res" );
m_pInfoRemarkable = new vgui::EditablePanel( (vgui::Panel*)NULL, "InfoRemarkable" );
m_pInfoRemarkableName = new vgui::TextEntry( m_pInfoRemarkable, "RemarkableName" );
m_pInfoRemarkableName->AddActionSignalTarget( this );
m_pRemarkablePosition[0] = new vgui::TextEntry( m_pInfoRemarkable, "PositionX" );
m_pRemarkablePosition[0]->AddActionSignalTarget( this );
m_pRemarkablePosition[1] = new vgui::TextEntry( m_pInfoRemarkable, "PositionY" );
m_pRemarkablePosition[1]->AddActionSignalTarget( this );
m_pRemarkablePosition[2] = new vgui::TextEntry( m_pInfoRemarkable, "PositionZ" );
m_pRemarkablePosition[2]->AddActionSignalTarget( this );
m_pInfoRemarkableSubject = new vgui::TextEntry( m_pInfoRemarkable, "RemarkableSubject" );
m_pInfoRemarkableSubject->AddActionSignalTarget( this );
m_pInfoRemarkable->LoadControlSettings( "resource/commentarypropertiessubpanel_remarkable.res" );
m_pCommentaryNodeScroll = new vgui::ScrollableEditablePanel( this, m_pCommentaryNode, "CommentaryNodeScroll" );
m_pInfoTargetScroll = new vgui::ScrollableEditablePanel( this, m_pInfoTarget, "InfoTargetScroll" );
m_pInfoRemarkableScroll = new vgui::ScrollableEditablePanel( this, m_pInfoRemarkable, "InfoRemarkableScroll" );
LoadControlSettings( "resource/commentarypropertiespanel.res" );
m_pCommentaryNodeScroll->SetVisible( false );
m_pInfoTargetScroll->SetVisible( false );
m_pInfoRemarkableScroll->SetVisible( false );
}
//-----------------------------------------------------------------------------
// Text to attribute...
//-----------------------------------------------------------------------------
void CCommentaryPropertiesPanel::TextEntryToAttribute( vgui::TextEntry *pEntry, const char *pAttributeName )
{
int nLen = pEntry->GetTextLength();
char *pBuf = (char*)_alloca( nLen+1 );
pEntry->GetText( pBuf, nLen+1 );
m_hEntity->SetValue( pAttributeName, pBuf );
}
void CCommentaryPropertiesPanel::TextEntriesToVector( vgui::TextEntry *pEntry[3], const char *pAttributeName )
{
CUtlVectorFixedGrowable< char, 256 > buf;
Vector vec;
for ( int i = 0; i < 3; ++i )
{
int nLen = pEntry[i]->GetTextLength();
buf.EnsureCount( nLen + 1 );
pEntry[i]->GetText( buf.Base(), nLen+1 );
vec[i] = atof( buf.Base() );
}
m_hEntity->SetValue( pAttributeName, vec );
clienttools->MarkClientRenderableDirty( m_hEntity );
}
//-----------------------------------------------------------------------------
// Updates entity state when text fields change
//-----------------------------------------------------------------------------
void CCommentaryPropertiesPanel::UpdateCommentaryNode()
{
if ( !m_hEntity.Get() )
return;
CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, "Commentary Node Change", "Commentary Node Change" );
TextEntryToAttribute( m_pNodeName, "targetname" );
TextEntryToAttribute( m_pStartCommands, "precommands" );
TextEntryToAttribute( m_pEndCommands, "postcommands" );
TextEntryToAttribute( m_pViewPosition, "viewposition" );
TextEntryToAttribute( m_pViewTarget, "viewtarget" );
TextEntryToAttribute( m_pSynopsis, "synopsis" );
TextEntryToAttribute( m_pSpeakerName, "speakers" );
TextEntryToAttribute( m_pSoundFileName, "commentaryfile" );
TextEntriesToVector( m_pPosition, "origin" );
TextEntriesToVector( m_pOrientation, "angles" );
m_hEntity->SetValue<int>( "prevent_movement", m_pPreventMovement->IsSelected() ? 1 : 0 );
m_hEntity->MarkDirty();
}
void CCommentaryPropertiesPanel::UpdateInfoTarget()
{
if ( !m_hEntity.Get() )
return;
CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, "Info Target Change", "Info Target Change" );
TextEntryToAttribute( m_pTargetName, "targetname" );
TextEntriesToVector( m_pTargetPosition, "origin" );
TextEntriesToVector( m_pTargetOrientation, "angles" );
m_hEntity->MarkDirty();
}
void CCommentaryPropertiesPanel::UpdateInfoRemarkable()
{
if ( !m_hEntity.Get() )
return;
CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, "Info Remarkable Change", "Info Remarkable Change" );
TextEntryToAttribute( m_pInfoRemarkableName, "targetname" );
TextEntryToAttribute( m_pInfoRemarkableSubject, "contextsubject" );
TextEntriesToVector( m_pRemarkablePosition, "origin" );
m_hEntity->MarkDirty();
}
//-----------------------------------------------------------------------------
// Populates the commentary node fields
//-----------------------------------------------------------------------------
void CCommentaryPropertiesPanel::PopulateCommentaryNodeFields()
{
if ( !m_hEntity.Get() )
return;
m_pNodeName->SetText( m_hEntity->GetTargetName() );
m_pStartCommands->SetText( m_hEntity->GetValueString( "precommands" ) );
m_pEndCommands->SetText( m_hEntity->GetValueString( "postcommands" ) );
m_pViewPosition->SetText( m_hEntity->GetValueString( "viewposition" ) );
m_pViewTarget->SetText( m_hEntity->GetValueString( "viewtarget" ) );
m_pSynopsis->SetText( m_hEntity->GetValueString( "synopsis" ) );
m_pSpeakerName->SetText( m_hEntity->GetValueString( "speakers" ) );
m_pSoundFileName->SetText( m_hEntity->GetValueString( "commentaryfile" ) );
Vector vecPosition = m_hEntity->GetRenderOrigin();
QAngle vecAngles = m_hEntity->GetRenderAngles();
for ( int i = 0; i < 3; ++i )
{
char pTemp[512];
Q_snprintf( pTemp, sizeof(pTemp), "%.2f", vecPosition[i] );
m_pPosition[i]->SetText( pTemp );
Q_snprintf( pTemp, sizeof(pTemp), "%.2f", vecAngles[i] );
m_pOrientation[i]->SetText( pTemp );
}
m_pPreventMovement->SetSelected( m_hEntity->GetValue<int>( "prevent_movement" ) != 0 );
}
//-----------------------------------------------------------------------------
// Populates the info_target fields
//-----------------------------------------------------------------------------
void CCommentaryPropertiesPanel::PopulateInfoTargetFields()
{
if ( !m_hEntity.Get() )
return;
m_pTargetName->SetText( m_hEntity->GetTargetName() );
Vector vecPosition = m_hEntity->GetRenderOrigin();
QAngle vecAngles = m_hEntity->GetRenderAngles();
for ( int i = 0; i < 3; ++i )
{
char pTemp[512];
Q_snprintf( pTemp, sizeof(pTemp), "%.2f", vecPosition[i] );
m_pTargetPosition[i]->SetText( pTemp );
Q_snprintf( pTemp, sizeof(pTemp), "%.2f", vecAngles[i] );
m_pTargetOrientation[i]->SetText( pTemp );
}
}
//-----------------------------------------------------------------------------
// Populates the info_target fields
//-----------------------------------------------------------------------------
void CCommentaryPropertiesPanel::PopulateInfoRemarkableFields()
{
if ( !m_hEntity.Get() )
return;
m_pInfoRemarkableName->SetText( m_hEntity->GetTargetName() );
Vector vecPosition = m_hEntity->GetRenderOrigin();
QAngle vecAngles = m_hEntity->GetRenderAngles();
for ( int i = 0; i < 3; ++i )
{
char pTemp[512];
Q_snprintf( pTemp, sizeof(pTemp), "%.2f", vecPosition[i] );
m_pRemarkablePosition[i]->SetText( pTemp );
}
m_pInfoRemarkableSubject->SetText( m_hEntity->GetValueString( "contextsubject" ) );
}
//-----------------------------------------------------------------------------
// Sets the object to look at
//-----------------------------------------------------------------------------
void CCommentaryPropertiesPanel::SetObject( CDmeCommentaryNodeEntity *pEntity )
{
m_hEntity = pEntity;
m_pCommentaryNodeScroll->SetVisible( false );
m_pInfoTargetScroll->SetVisible( false );
m_pInfoRemarkableScroll->SetVisible( false );
if ( pEntity )
{
if ( !Q_stricmp( pEntity->GetClassName(), "info_target" ) )
{
PopulateInfoTargetFields();
m_pInfoTargetScroll->SetVisible( true );
m_pTargetName->RequestFocus();
return;
}
if ( !Q_stricmp( pEntity->GetClassName(), "info_remarkable" ) )
{
PopulateInfoRemarkableFields();
m_pInfoRemarkableScroll->SetVisible( true );
m_pInfoRemarkableName->RequestFocus();
return;
}
if ( !Q_stricmp( pEntity->GetClassName(), "point_commentary_node" ) )
{
PopulateCommentaryNodeFields();
m_pCommentaryNodeScroll->SetVisible( true );
m_pNodeName->RequestFocus();
return;
}
}
}
//-----------------------------------------------------------------------------
// Called when text is changed
//-----------------------------------------------------------------------------
void CCommentaryPropertiesPanel::OnTextChanged( KeyValues *pParams )
{
vgui::Panel *pPanel = (vgui::Panel*)pParams->GetPtr( "panel" );
if ( pPanel->GetParent() == m_pCommentaryNode )
{
UpdateCommentaryNode();
return;
}
if ( pPanel->GetParent() == m_pInfoTarget )
{
UpdateInfoTarget();
return;
}
if ( pPanel->GetParent() == m_pInfoRemarkable )
{
UpdateInfoRemarkable();
return;
}
}
//-----------------------------------------------------------------------------
// Called when the audio picker has picked something
//-----------------------------------------------------------------------------
void CCommentaryPropertiesPanel::OnSoundSelected( KeyValues *pParams )
{
const char *pAssetName = pParams->GetString( "wav" );
m_pSoundFileName->SetText( pAssetName );
UpdateCommentaryNode();
}
//-----------------------------------------------------------------------------
// Called when the audio picker button is selected
//-----------------------------------------------------------------------------
void CCommentaryPropertiesPanel::PickSound()
{
CSoundPickerFrame *pSoundPickerDialog = new CSoundPickerFrame( g_pCommEditTool->GetRootPanel(), "Select commentary audio file", CSoundPicker::PICK_WAVFILES );
pSoundPickerDialog->AddActionSignalTarget( this );
pSoundPickerDialog->DoModal( CSoundPicker::PICK_NONE, NULL );
}
//-----------------------------------------------------------------------------
// Called when the string picker has picked something
//-----------------------------------------------------------------------------
void CCommentaryPropertiesPanel::OnPicked( KeyValues *pParams )
{
const char *pInfoTargetName = pParams->GetString( "choice" );
KeyValues *pContextKeyValues = pParams->FindKey( "context" );
vgui::TextEntry *pTextEntry = (vgui::TextEntry *)pContextKeyValues->GetPtr( "widget" );
pTextEntry->SetText( pInfoTargetName );
UpdateCommentaryNode();
}
//-----------------------------------------------------------------------------
// Called when the audio picker button is selected
//-----------------------------------------------------------------------------
void CCommentaryPropertiesPanel::PickInfoTarget( vgui::TextEntry *pControl )
{
CDmrCommentaryNodeEntityList entities( m_pDoc->GetEntityList() );
int nCount = entities.Count();
PickerList_t vec( 0, nCount+1 );
int j = vec.AddToTail( );
vec[j].m_pChoiceString = "<no target>";
vec[j].m_pChoiceValue = "";
for ( int i = 0; i < nCount; ++i )
{
CDmeCommentaryNodeEntity *pNode = entities[ i ];
const char *pTargetName = pNode->GetTargetName();
if ( !pTargetName || !pTargetName[0] )
continue;
if ( !Q_stricmp( pNode->GetClassName(), "info_target" ) )
{
j = vec.AddToTail( );
vec[j].m_pChoiceString = pTargetName;
vec[j].m_pChoiceValue = pTargetName;
}
}
CPickerFrame *pInfoTargetPickerDialog = new CPickerFrame( g_pCommEditTool->GetRootPanel(), "Select Target", "InfoTarget", NULL );
KeyValues *pContextKeyValues = new KeyValues( "context" );
pContextKeyValues->SetPtr( "widget", pControl );
pInfoTargetPickerDialog->AddActionSignalTarget( this );
pInfoTargetPickerDialog->DoModal( vec, pContextKeyValues );
}
//-----------------------------------------------------------------------------
// Called when a sound is successfully recorded
//-----------------------------------------------------------------------------
void CCommentaryPropertiesPanel::OnSoundRecorded( KeyValues *pKeyValues )
{
const char *pFileName = pKeyValues->GetString( "relativepath" );
m_pSoundFileName->SetText( pFileName );
UpdateCommentaryNode();
}
//-----------------------------------------------------------------------------
// Used to open a particular file in perforce, and deal with all the lovely dialogs
//-----------------------------------------------------------------------------
void CCommentaryPropertiesPanel::OnFileSelected( KeyValues *pKeyValues )
{
const char *pFileName = pKeyValues->GetString( "fullpath" );
if ( g_pFileSystem->FileExists( pFileName ) )
{
char pBuf[1024];
Q_snprintf( pBuf, sizeof(pBuf), "File %s already exists!\nRecording audio will not overwrite existing files.", pFileName );
vgui::MessageBox *pMessageBox = new vgui::MessageBox( "File already Exists!\n", pBuf, g_pCommEditTool );
pMessageBox->DoModal( );
return;
}
CSoundRecordPanel *pSoundRecordPanel = new CSoundRecordPanel( g_pCommEditTool->GetRootPanel(), "Record Commentary" );
pSoundRecordPanel->AddActionSignalTarget( this );
pSoundRecordPanel->DoModal( pFileName );
}
//-----------------------------------------------------------------------------
// Called when sound recording is requested
//-----------------------------------------------------------------------------
void CCommentaryPropertiesPanel::RecordSound( )
{
char pStartingDir[ MAX_PATH ];
GetModSubdirectory( "sound", pStartingDir, sizeof(pStartingDir) );
vgui::FileOpenDialog *pDialog = new vgui::FileOpenDialog( this, "Save As", false );
pDialog->SetTitle( "Enter New Audio File", true );
pDialog->SetStartDirectoryContext( "commedit_audio_record", pStartingDir );
pDialog->AddFilter( "*.wav", "Audio File (*.wav)", true );
pDialog->AddActionSignalTarget( this );
pDialog->DoModal( true );
}
//-----------------------------------------------------------------------------
// Called when buttons are clicked
//-----------------------------------------------------------------------------
void CCommentaryPropertiesPanel::OnCommand( const char *pCommand )
{
if ( !Q_stricmp( pCommand, "PickSound" ) )
{
PickSound();
return;
}
if ( !Q_stricmp( pCommand, "Record" ) )
{
RecordSound();
return;
}
if ( !Q_stricmp( pCommand, "PickViewPosition" ) )
{
PickInfoTarget( m_pViewPosition );
return;
}
if ( !Q_stricmp( pCommand, "PickViewTarget" ) )
{
PickInfoTarget( m_pViewTarget );
return;
}
if ( !Q_stricmp( pCommand, "PreventMovementClicked" ) )
{
UpdateCommentaryNode();
return;
}
BaseClass::OnCommand( pCommand );
}
+123
View File
@@ -0,0 +1,123 @@
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
//===========================================================================//
#ifndef COMMENTARYPROPERTIESPANEL_H
#define COMMENTARYPROPERTIESPANEL_H
#ifdef _WIN32
#pragma once
#endif
#include "vgui_controls/editablepanel.h"
#include "tier1/utlstring.h"
#include "datamodel/dmehandle.h"
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class CCommEditDoc;
class CDmeCommentaryNodeEntity;
namespace vgui
{
class ComboBox;
class Button;
class TextEntry;
class ListPanel;
class CheckButton;
class RadioButton;
}
//-----------------------------------------------------------------------------
// Panel that shows all entities in the level
//-----------------------------------------------------------------------------
class CCommentaryPropertiesPanel : public vgui::EditablePanel
{
DECLARE_CLASS_SIMPLE( CCommentaryPropertiesPanel, vgui::EditablePanel );
public:
CCommentaryPropertiesPanel( CCommEditDoc *pDoc, vgui::Panel* pParent ); // standard constructor
// Inherited from Panel
virtual void OnCommand( const char *pCommand );
// Sets the object to look at
void SetObject( CDmeCommentaryNodeEntity *pEntity );
private:
// Populates the commentary node fields
void PopulateCommentaryNodeFields();
// Populates the info_target fields
void PopulateInfoTargetFields();
// Populates the info_remarkable fields
void PopulateInfoRemarkableFields();
// Text to attribute...
void TextEntryToAttribute( vgui::TextEntry *pEntry, const char *pAttributeName );
void TextEntriesToVector( vgui::TextEntry *pEntry[3], const char *pAttributeName );
// Updates entity state when text fields change
void UpdateCommentaryNode();
void UpdateInfoTarget();
void UpdateInfoRemarkable();
// Called when the audio picker button is selected
void PickSound();
// Called when sound recording is requested
void RecordSound( );
// Called when the audio picker button is selected
void PickInfoTarget( vgui::TextEntry *pControl );
// Messages handled
MESSAGE_FUNC_PARAMS( OnTextChanged, "TextChanged", kv );
MESSAGE_FUNC_PARAMS( OnSoundSelected, "SoundSelected", kv );
MESSAGE_FUNC_PARAMS( OnPicked, "Picked", kv );
MESSAGE_FUNC_PARAMS( OnFileSelected, "FileSelected", kv );
MESSAGE_FUNC_PARAMS( OnSoundRecorded, "SoundRecorded", kv );
CCommEditDoc *m_pDoc;
vgui::EditablePanel *m_pCommentaryNodeScroll;
vgui::EditablePanel *m_pInfoTargetScroll;
vgui::EditablePanel *m_pInfoRemarkableScroll;
vgui::EditablePanel *m_pCommentaryNode;
vgui::EditablePanel *m_pInfoTarget;
vgui::EditablePanel *m_pInfoRemarkable;
vgui::TextEntry *m_pNodeName;
vgui::Button *m_pSoundFilePicker;
vgui::TextEntry *m_pSoundFileName;
vgui::Button *m_pRecordSound;
vgui::TextEntry *m_pSpeakerName;
vgui::TextEntry *m_pSynopsis;
vgui::TextEntry *m_pViewPosition;
vgui::Button *m_pViewPositionPicker;
vgui::TextEntry *m_pViewTarget;
vgui::Button *m_pViewTargetPicker;
vgui::TextEntry *m_pStartCommands;
vgui::TextEntry *m_pEndCommands;
vgui::CheckButton *m_pPreventMovement;
vgui::TextEntry *m_pPosition[3];
vgui::TextEntry *m_pOrientation[3];
vgui::TextEntry *m_pTargetName;
vgui::TextEntry *m_pTargetPosition[3];
vgui::TextEntry *m_pTargetOrientation[3];
vgui::TextEntry *m_pInfoRemarkableName;
vgui::TextEntry *m_pInfoRemarkableSubject;
vgui::TextEntry *m_pRemarkablePosition[3];
CDmeHandle< CDmeCommentaryNodeEntity > m_hEntity;
};
#endif // COMMENTARYPROPERTIESPANEL_H
+343
View File
@@ -0,0 +1,343 @@
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======
//
// Purpose:
//
//=============================================================================
#include "dmecommentarynodeentity.h"
#include "datamodel/dmelementfactoryhelper.h"
#include "toolframework/itoolentity.h"
#include "materialsystem/imesh.h"
#include "materialsystem/imaterial.h"
#include "materialsystem/imaterialsystem.h"
#include "engine/iclientleafsystem.h"
#include "toolutils/enginetools_int.h"
#include "commedittool.h"
#include "keyvalues.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
#define SPHERE_RADIUS 16
//-----------------------------------------------------------------------------
// Expose this class to the scene database
//-----------------------------------------------------------------------------
IMPLEMENT_ELEMENT_FACTORY( DmeCommentaryNodeEntity, CDmeCommentaryNodeEntity );
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CDmeCommentaryNodeEntity::OnConstruction()
{
m_ClassName.InitAndSet( this, "classname", false, FATTRIB_HAS_CALLBACK );
m_TargetName.Init( this, "targetname" );
m_bIsPlaceholder.InitAndSet( this, "_placeholder", false, FATTRIB_DONTSAVE );
m_vecLocalOrigin.Init( this, "origin" );
m_vecLocalAngles.Init( this, "angles" );
// Used to make sure these aren't saved if they aren't changed
m_TargetName.GetAttribute()->AddFlag( FATTRIB_DONTSAVE | FATTRIB_HAS_CALLBACK );
m_vecLocalAngles.GetAttribute()->AddFlag( FATTRIB_DONTSAVE | FATTRIB_HAS_CALLBACK );
m_bInfoTarget = false;
m_bIsDirty = false;
m_hEngineEntity = HTOOLHANDLE_INVALID;
KeyValues *pVMTKeyValues = new KeyValues( "UnlitGeneric" );
pVMTKeyValues->SetString( "$basetexture", "editor/info_target" );
pVMTKeyValues->SetInt( "$nocull", 1 );
pVMTKeyValues->SetInt( "$vertexcolor", 1 );
pVMTKeyValues->SetInt( "$vertexalpha", 1 );
pVMTKeyValues->SetInt( "$no_fullbright", 1 );
pVMTKeyValues->SetInt( "$translucent", 1 );
m_InfoTargetSprite.Init( "__commentary_info_target", pVMTKeyValues );
pVMTKeyValues = new KeyValues( "UnlitGeneric" );
pVMTKeyValues->SetInt( "$nocull", 1 );
pVMTKeyValues->SetString( "$color", "{255 0 0}" );
pVMTKeyValues->SetInt( "$vertexalpha", 1 );
pVMTKeyValues->SetInt( "$no_fullbright", 1 );
pVMTKeyValues->SetInt( "$additive", 1 );
m_SelectedInfoTarget.Init( "__selected_commentary_info_target", pVMTKeyValues );
}
void CDmeCommentaryNodeEntity::OnDestruction()
{
// Unhook it from the engine
AttachToEngineEntity( HTOOLHANDLE_INVALID );
m_SelectedInfoTarget.Shutdown();
m_InfoTargetSprite.Shutdown();
}
//-----------------------------------------------------------------------------
// Called whem attributes change
//-----------------------------------------------------------------------------
void CDmeCommentaryNodeEntity::OnAttributeChanged( CDmAttribute *pAttribute )
{
BaseClass::OnAttributeChanged( pAttribute );
// Once these have changed, then save them out, and don't bother calling back
if ( pAttribute == m_TargetName.GetAttribute() ||
pAttribute == m_vecLocalAngles.GetAttribute() )
{
pAttribute->RemoveFlag( FATTRIB_DONTSAVE | FATTRIB_HAS_CALLBACK );
return;
}
if ( pAttribute == m_ClassName.GetAttribute() )
{
m_bInfoTarget = !Q_strncmp( m_ClassName, "info_target", 11 ) || !Q_strcmp( m_ClassName, "info_remarkable" );
if ( !Q_stricmp( m_ClassName, "point_commentary_node" ) )
{
SetModelName( "models/extras/info_speech.mdl" );
GetMDL()->m_flPlaybackRate = 0.0f;
}
else
{
SetModelName( NULL );
}
OnTranslucencyTypeChanged();
return;
}
}
//-----------------------------------------------------------------------------
// Returns the entity ID
//-----------------------------------------------------------------------------
int CDmeCommentaryNodeEntity::GetEntityId() const
{
return atoi( GetName() );
}
//-----------------------------------------------------------------------------
// Mark the entity as being dirty
//-----------------------------------------------------------------------------
void CDmeCommentaryNodeEntity::MarkDirty( bool bDirty )
{
m_bIsDirty = bDirty;
OnTranslucencyTypeChanged();
}
//-----------------------------------------------------------------------------
// Is the renderable transparent?
//-----------------------------------------------------------------------------
RenderableTranslucencyType_t CDmeCommentaryNodeEntity::ComputeTranslucencyType( void )
{
if ( m_bIsDirty || m_bInfoTarget )
return RENDERABLE_IS_TRANSLUCENT;
return BaseClass::ComputeTranslucencyType();
}
//-----------------------------------------------------------------------------
// Entity Key iteration
//-----------------------------------------------------------------------------
bool CDmeCommentaryNodeEntity::IsEntityKey( CDmAttribute *pEntityKey )
{
return pEntityKey->IsFlagSet( FATTRIB_USERDEFINED );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CDmAttribute *CDmeCommentaryNodeEntity::FirstEntityKey()
{
for ( CDmAttribute *pAttribute = FirstAttribute(); pAttribute; pAttribute = pAttribute->NextAttribute() )
{
if ( IsEntityKey( pAttribute ) )
return pAttribute;
}
return NULL;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CDmAttribute *CDmeCommentaryNodeEntity::NextEntityKey( CDmAttribute *pEntityKey )
{
if ( !pEntityKey )
return NULL;
for ( CDmAttribute *pAttribute = pEntityKey->NextAttribute(); pAttribute; pAttribute = pAttribute->NextAttribute() )
{
if ( IsEntityKey( pAttribute ) )
return pAttribute;
}
return NULL;
}
//-----------------------------------------------------------------------------
// Attach/detach from an engine entity with the same editor index
//-----------------------------------------------------------------------------
void CDmeCommentaryNodeEntity::AttachToEngineEntity( HTOOLHANDLE hToolHandle )
{
if ( m_hEngineEntity != HTOOLHANDLE_INVALID )
{
clienttools->SetEnabled( m_hEngineEntity, true );
}
m_hEngineEntity = hToolHandle;
if ( m_hEngineEntity != HTOOLHANDLE_INVALID )
{
clienttools->SetEnabled( m_hEngineEntity, false );
}
}
//-----------------------------------------------------------------------------
// Position and bounds for the model
//-----------------------------------------------------------------------------
const Vector &CDmeCommentaryNodeEntity::GetRenderOrigin( void )
{
return m_vecLocalOrigin;
}
const QAngle &CDmeCommentaryNodeEntity::GetRenderAngles( void )
{
return *(QAngle*)(&m_vecLocalAngles.Get());
}
//-----------------------------------------------------------------------------
// Draws the helper for the entity
//-----------------------------------------------------------------------------
void CDmeCommentaryNodeEntity::DrawSprite( IMaterial *pMaterial )
{
float t = 0.5f * sin( Plat_FloatTime() * M_PI / 1.0f ) + 0.5f;
CMatRenderContextPtr pRenderContext( materials );
pRenderContext->Bind( pMaterial );
IMesh* pMesh = pRenderContext->GetDynamicMesh();
CMeshBuilder meshBuilder;
meshBuilder.Begin( pMesh, MATERIAL_TRIANGLE_STRIP, 4, 4 );
unsigned char nBaseR = 255;
unsigned char nBaseG = 255;
unsigned char nBaseB = 255;
unsigned char nAlpha = m_bIsDirty ? (unsigned char)(255 * t) : 255;
meshBuilder.Position3f( -SPHERE_RADIUS, -SPHERE_RADIUS, 0.0f );
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
meshBuilder.TexCoord2f( 0, 0.0f, 1.0f );
meshBuilder.AdvanceVertex();
meshBuilder.Position3f( SPHERE_RADIUS, -SPHERE_RADIUS, 0.0f );
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
meshBuilder.TexCoord2f( 0, 1.0f, 1.0f );
meshBuilder.AdvanceVertex();
meshBuilder.Position3f( SPHERE_RADIUS, SPHERE_RADIUS, 0.0f );
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
meshBuilder.TexCoord2f( 0, 1.0f, 0.0f );
meshBuilder.AdvanceVertex();
meshBuilder.Position3f( -SPHERE_RADIUS, SPHERE_RADIUS, 0.0f );
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
meshBuilder.TexCoord2f( 0, 0.0f, 0.0f );
meshBuilder.AdvanceVertex();
meshBuilder.FastIndex( 0 );
meshBuilder.FastIndex( 1 );
meshBuilder.FastIndex( 3 );
meshBuilder.FastIndex( 2 );
meshBuilder.End();
pMesh->Draw();
}
//-----------------------------------------------------------------------------
// Draws the helper for the entity
//-----------------------------------------------------------------------------
int CDmeCommentaryNodeEntity::DrawModel( int flags, const RenderableInstance_t &instance )
{
bool bSelected = ( g_pCommEditTool->GetCurrentEntity().Get() == this );
if ( !m_bInfoTarget )
{
// If we have a visible engine entity, we don't need to draw it here
// info targets always draw though, because they have no visible model.
CDisableUndoScopeGuard guard;
float t = 0.5f * sin( Plat_FloatTime() * M_PI / 1.0f ) + 0.5f;
unsigned char nAlpha = m_bIsDirty ? (unsigned char)(255 * t) : 255;
if ( bSelected )
{
GetMDL()->m_Color.SetColor( 255, 64, 64, nAlpha );
}
else
{
GetMDL()->m_Color.SetColor( 255, 255, 255, nAlpha );
}
return BaseClass::DrawModel( flags, instance );
}
Assert( IsDrawingInEngine() );
CMatRenderContextPtr pRenderContext( materials );
matrix3x4_t mat;
VMatrix worldToCamera, cameraToWorld;
pRenderContext->GetMatrix( MATERIAL_VIEW, &worldToCamera );
MatrixInverseTR( worldToCamera, cameraToWorld );
MatrixCopy( cameraToWorld.As3x4(), mat );
MatrixSetColumn( m_vecLocalOrigin, 3, mat );
pRenderContext->MatrixMode( MATERIAL_MODEL );
pRenderContext->PushMatrix();
pRenderContext->LoadMatrix( mat );
pRenderContext->FogMode( MATERIAL_FOG_NONE );
pRenderContext->SetNumBoneWeights( 0 );
pRenderContext->CullMode( MATERIAL_CULLMODE_CW );
DrawSprite( m_InfoTargetSprite );
if ( bSelected )
{
DrawSprite( m_SelectedInfoTarget );
}
pRenderContext->CullMode( MATERIAL_CULLMODE_CCW );
pRenderContext->MatrixMode( MATERIAL_MODEL );
pRenderContext->PopMatrix();
return 1;
}
//-----------------------------------------------------------------------------
// Position and bounds for the model
//-----------------------------------------------------------------------------
void CDmeCommentaryNodeEntity::GetRenderBounds( Vector& mins, Vector& maxs )
{
if ( !m_bInfoTarget )
{
BaseClass::GetRenderBounds( mins, maxs );
return;
}
mins.Init( -SPHERE_RADIUS, -SPHERE_RADIUS, -SPHERE_RADIUS );
maxs.Init( SPHERE_RADIUS, SPHERE_RADIUS, SPHERE_RADIUS );
}
//-----------------------------------------------------------------------------
// Update renderable position
//-----------------------------------------------------------------------------
void CDmeCommentaryNodeEntity::SetRenderOrigin( const Vector &vecOrigin )
{
m_vecLocalOrigin = vecOrigin;
clienttools->MarkClientRenderableDirty( this );
}
void CDmeCommentaryNodeEntity::SetRenderAngles( const QAngle &angles )
{
m_vecLocalAngles = *(Vector*)&angles;
clienttools->MarkClientRenderableDirty( this );
}
+100
View File
@@ -0,0 +1,100 @@
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======
//
// Purpose: Represents an entity in a VMF
//
//=============================================================================
#ifndef DMEVMFENTITY_H
#define DMEVMFENTITY_H
#ifdef _WIN32
#pragma once
#endif
#include "toolutils/dmemdlrenderable.h"
#include "datamodel/dmelement.h"
#include "toolframework/itoolentity.h"
#include "materialsystem/materialsystemutil.h"
//-----------------------------------------------------------------------------
// Represents an editable entity; draws its helpers
//-----------------------------------------------------------------------------
class CDmeCommentaryNodeEntity : public CDmeMdlRenderable<CDmElement>
{
DEFINE_ELEMENT( CDmeCommentaryNodeEntity, CDmeMdlRenderable<CDmElement> );
public:
// Inherited from CDmElement
virtual void OnAttributeChanged( CDmAttribute *pAttribute );
public:
// Inherited from DmeRenderable
virtual const Vector &GetRenderOrigin( void );
virtual const QAngle &GetRenderAngles( void );
virtual int DrawModel( int flags, const RenderableInstance_t &instance );
virtual void GetRenderBounds( Vector& mins, Vector& maxs );
virtual RenderableTranslucencyType_t ComputeTranslucencyType( void );
public:
int GetEntityId() const;
const char *GetClassName() const;
const char *GetTargetName() const;
bool IsPlaceholder() const;
// Entity Key iteration
CDmAttribute *FirstEntityKey();
CDmAttribute *NextEntityKey( CDmAttribute *pEntityKey );
// Attach/detach from an engine entity with the same editor index
void AttachToEngineEntity( HTOOLHANDLE hToolHandle );
void SetRenderOrigin( const Vector &vecOrigin );
void SetRenderAngles( const QAngle &angles );
void MarkDirty( bool bDirty = true );
private:
bool IsEntityKey( CDmAttribute *pEntityKey );
// Draws the helper for the entity
void DrawSprite( IMaterial *pMaterial );
CDmaVar<Vector> m_vecLocalOrigin;
CDmaVar<Vector> m_vecLocalAngles;
CDmaString m_ClassName;
CDmaString m_TargetName;
CDmaVar<bool> m_bIsPlaceholder;
bool m_bInfoTarget;
bool m_bIsDirty;
// The entity it's connected to in the engine
HTOOLHANDLE m_hEngineEntity;
CMaterialReference m_SelectedInfoTarget;
CMaterialReference m_InfoTargetSprite;
};
//-----------------------------------------------------------------------------
// Inline methods
//-----------------------------------------------------------------------------
inline const char *CDmeCommentaryNodeEntity::GetClassName() const
{
return m_ClassName;
}
inline const char *CDmeCommentaryNodeEntity::GetTargetName() const
{
return m_TargetName;
}
inline bool CDmeCommentaryNodeEntity::IsPlaceholder() const
{
return m_bIsPlaceholder;
}
#endif // DMEVMFENTITY_H
+581
View File
@@ -0,0 +1,581 @@
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose: Singleton dialog that generates and presents the entity report.
//
//===========================================================================//
#include "EntityReportPanel.h"
#include "tier1/keyvalues.h"
#include "tier1/utlbuffer.h"
#include "iregistry.h"
#include "vgui/ivgui.h"
#include "vgui_controls/listpanel.h"
#include "vgui_controls/textentry.h"
#include "vgui_controls/checkbutton.h"
#include "vgui_controls/combobox.h"
#include "vgui_controls/radiobutton.h"
#include "vgui_controls/messagebox.h"
#include "commeditdoc.h"
#include "commedittool.h"
#include "datamodel/dmelement.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
using namespace vgui;
//-----------------------------------------------------------------------------
// Sort by target name
//-----------------------------------------------------------------------------
static int __cdecl TargetNameSortFunc( vgui::ListPanel *pPanel, const ListPanelItem &item1, const ListPanelItem &item2 )
{
const char *string1 = item1.kv->GetString("targetname");
const char *string2 = item2.kv->GetString("targetname");
int nRetVal = Q_stricmp( string1, string2 );
if ( nRetVal != 0 )
return nRetVal;
string1 = item1.kv->GetString("classname");
string2 = item2.kv->GetString("classname");
return Q_stricmp( string1, string2 );
}
//-----------------------------------------------------------------------------
// Sort by class name
//-----------------------------------------------------------------------------
static int __cdecl ClassNameSortFunc( vgui::ListPanel *pPanel, const ListPanelItem &item1, const ListPanelItem &item2 )
{
const char *string1 = item1.kv->GetString("classname");
const char *string2 = item2.kv->GetString("classname");
int nRetVal = Q_stricmp( string1, string2 );
if ( nRetVal != 0 )
return nRetVal;
string1 = item1.kv->GetString("targetname");
string2 = item2.kv->GetString("targetname");
return Q_stricmp( string1, string2 );
}
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CEntityReportPanel::CEntityReportPanel( CCommEditDoc *pDoc, vgui::Panel* pParent, const char *pName )
: BaseClass( pParent, pName ), m_pDoc( pDoc )
{
m_bSuppressEntityListUpdate = false;
m_iFilterByType = FILTER_SHOW_EVERYTHING;
m_bFilterByKeyvalue = false;
m_bFilterByClass = false;
m_bFilterByHidden = false;
m_bFilterByKeyvalue = false;
m_bExact = false;
m_bFilterTextChanged = false;
SetPaintBackgroundEnabled( true );
m_pEntities = new vgui::ListPanel( this, "Entities" );
m_pEntities->AddColumnHeader( 0, "targetname", "Name", 52, ListPanel::COLUMN_RESIZEWITHWINDOW );
m_pEntities->AddColumnHeader( 1, "classname", "Class Name", 52, ListPanel::COLUMN_RESIZEWITHWINDOW );
m_pEntities->SetColumnSortable( 0, true );
m_pEntities->SetColumnSortable( 1, true );
m_pEntities->SetEmptyListText( "No Entities" );
// m_pEntities->SetDragEnabled( true );
m_pEntities->AddActionSignalTarget( this );
m_pEntities->SetSortFunc( 0, TargetNameSortFunc );
m_pEntities->SetSortFunc( 1, ClassNameSortFunc );
m_pEntities->SetSortColumn( 0 );
// Filtering checkboxes
m_pFilterByClass = new vgui::CheckButton( this, "ClassnameCheck", "" );
m_pFilterByClass->AddActionSignalTarget( this );
m_pFilterByKeyvalue = new vgui::CheckButton( this, "KeyvalueCheck", "" );
m_pFilterByKeyvalue->AddActionSignalTarget( this );
m_pFilterByHidden = new vgui::CheckButton( this, "HiddenCheck", "" );
m_pFilterByHidden->AddActionSignalTarget( this );
m_pExact = new vgui::CheckButton( this, "ExactCheck", "" );
m_pExact->AddActionSignalTarget( this );
// Filtering text entries
m_pFilterKey = new vgui::TextEntry( this, "KeyTextEntry" );
m_pFilterValue = new vgui::TextEntry( this, "ValueTextEntry" );
// Classname combobox
m_pFilterClass = new vgui::ComboBox( this, "ClassNameComboBox", 16, true );
// Filter by type radio buttons
m_pFilterEverything = new vgui::RadioButton( this, "EverythingRadio", "" );
m_pFilterPointEntities = new vgui::RadioButton( this, "PointRadio", "" );
m_pFilterBrushModels = new vgui::RadioButton( this, "BrushRadio", "" );
LoadControlSettings( "resource/entityreportpanel.res" );
ReadSettingsFromRegistry();
// Used for updating filter while changing text
ivgui()->AddTickSignal( GetVPanel(), 300 );
}
//-----------------------------------------------------------------------------
// Reads settings from registry
//-----------------------------------------------------------------------------
void CEntityReportPanel::ReadSettingsFromRegistry()
{
m_bSuppressEntityListUpdate = true;
const char *pKeyBase = g_pCommEditTool->GetRegistryName();
m_pFilterByKeyvalue->SetSelected( registry->ReadInt(pKeyBase, "FilterByKeyvalue", 0) );
m_pFilterByClass->SetSelected( registry->ReadInt(pKeyBase, "FilterByClass", 0) );
m_pFilterByHidden->SetSelected( registry->ReadInt(pKeyBase, "FilterByHidden", 1) );
m_pExact->SetSelected( registry->ReadInt(pKeyBase, "Exact", 0) );
m_iFilterByType = (FilterType_t)registry->ReadInt(pKeyBase, "FilterByType", FILTER_SHOW_EVERYTHING);
m_pFilterEverything->SetSelected( m_iFilterByType == FILTER_SHOW_EVERYTHING );
m_pFilterPointEntities->SetSelected( m_iFilterByType == FILTER_SHOW_POINT_ENTITIES );
m_pFilterBrushModels->SetSelected( m_iFilterByType == FILTER_SHOW_BRUSH_ENTITIES );
// Gotta call change functions manually since SetText doesn't post an action signal
const char *pValue = registry->ReadString( pKeyBase, "FilterClass", "" );
m_pFilterClass->SetText( pValue );
OnChangeFilterclass( pValue );
pValue = registry->ReadString( pKeyBase, "FilterKey", "" );
m_pFilterKey->SetText( pValue );
OnChangeFilterkey( pValue );
pValue = registry->ReadString( pKeyBase, "FilterValue", "" );
m_pFilterValue->SetText( pValue );
OnChangeFiltervalue( pValue );
m_bSuppressEntityListUpdate = false;
UpdateEntityList();
}
//-----------------------------------------------------------------------------
// Writes settings to registry
//-----------------------------------------------------------------------------
void CEntityReportPanel::SaveSettingsToRegistry()
{
const char *pKeyBase = g_pCommEditTool->GetRegistryName();
registry->WriteInt(pKeyBase, "FilterByKeyvalue", m_bFilterByKeyvalue);
registry->WriteInt(pKeyBase, "FilterByClass", m_bFilterByClass);
registry->WriteInt(pKeyBase, "FilterByHidden", m_bFilterByHidden);
registry->WriteInt(pKeyBase, "FilterByType", m_iFilterByType);
registry->WriteInt(pKeyBase, "Exact", m_bExact);
registry->WriteString(pKeyBase, "FilterClass", m_szFilterClass);
registry->WriteString(pKeyBase, "FilterKey", m_szFilterKey);
registry->WriteString(pKeyBase, "FilterValue", m_szFilterValue);
}
//-----------------------------------------------------------------------------
// Purpose: Shows the most recent selected object in properties window
//-----------------------------------------------------------------------------
void CEntityReportPanel::OnProperties(void)
{
int iSel = m_pEntities->GetSelectedItem( 0 );
KeyValues *kv = m_pEntities->GetItem( iSel );
CDmElement *pEntity = (CDmElement *)kv->GetPtr( "entity" );
g_pCommEditTool->ShowEntityInEntityProperties( pEntity );
}
//-----------------------------------------------------------------------------
// Purpose: Deletes the marked objects.
//-----------------------------------------------------------------------------
void CEntityReportPanel::OnDeleteEntities(void)
{
// This is undoable
CUndoScopeGuard guard( g_pDataModel, "Delete Entities", "Delete Entities" );
int iSel = m_pEntities->GetSelectedItem( 0 );
//
// Build a list of objects to delete.
//
int nCount = m_pEntities->GetSelectedItemsCount();
for (int i = 0; i < nCount; i++)
{
int nItemID = m_pEntities->GetSelectedItem(i);
KeyValues *kv = m_pEntities->GetItem( nItemID );
CDmElement *pEntity = (CDmElement *)kv->GetPtr( "entity" );
if ( pEntity )
{
m_pDoc->DeleteCommentaryNode( pEntity );
}
}
UpdateEntityList();
// Update the list box selection.
if (iSel >= m_pEntities->GetItemCount())
{
iSel = m_pEntities->GetItemCount() - 1;
}
m_pEntities->SetSingleSelectedItem( iSel );
}
//-----------------------------------------------------------------------------
// Called when buttons are clicked
//-----------------------------------------------------------------------------
void CEntityReportPanel::OnCommand( const char *pCommand )
{
if ( !Q_stricmp( pCommand, "delete" ) )
{
// Confirm we want to do it
MessageBox *pConfirm = new MessageBox( "#CommEditDeleteObjects", "#CommEditDeleteObjectsMsg", g_pCommEditTool->GetRootPanel() );
pConfirm->AddActionSignalTarget( this );
pConfirm->SetOKButtonText( "Yes" );
pConfirm->SetCommand( new KeyValues( "DeleteEntities" ) );
pConfirm->SetCancelButtonVisible( true );
pConfirm->SetCancelButtonText( "No" );
pConfirm->DoModal();
return;
}
if ( !Q_stricmp( pCommand, "ShowProperties" ) )
{
OnProperties();
return;
}
}
//-----------------------------------------------------------------------------
// Call this when our settings are dirty
//-----------------------------------------------------------------------------
void CEntityReportPanel::MarkDirty( bool bFilterDirty )
{
float flTime = Plat_FloatTime();
m_bRegistrySettingsChanged = true;
m_flRegistryTime = flTime;
if ( bFilterDirty && !m_bFilterTextChanged )
{
m_bFilterTextChanged = true;
m_flFilterTime = flTime;
}
}
//-----------------------------------------------------------------------------
// Methods related to filtering
//-----------------------------------------------------------------------------
void CEntityReportPanel::OnFilterByHidden( bool bState )
{
m_bFilterByHidden = bState;
UpdateEntityList();
MarkDirty( false );
}
void CEntityReportPanel::OnFilterByKeyvalue( bool bState )
{
m_bFilterByKeyvalue = bState;
UpdateEntityList();
MarkDirty( false );
m_pFilterKey->SetEnabled( bState );
m_pFilterValue->SetEnabled( bState );
m_pExact->SetEnabled( bState );
}
void CEntityReportPanel::OnFilterKeyValueExact( bool bState )
{
m_bExact = bState;
UpdateEntityList();
MarkDirty( false );
}
void CEntityReportPanel::OnFilterByType( FilterType_t type )
{
m_iFilterByType = type;
UpdateEntityList();
MarkDirty( false );
}
void CEntityReportPanel::OnFilterByClass( bool bState )
{
m_bFilterByClass = bState;
UpdateEntityList();
MarkDirty( false );
m_pFilterClass->SetEnabled( bState );
}
void CEntityReportPanel::OnChangeFilterkey( const char *pText )
{
m_szFilterKey = pText;
MarkDirty( true );
}
void CEntityReportPanel::OnChangeFiltervalue( const char *pText )
{
m_szFilterValue = pText;
MarkDirty( true );
}
void CEntityReportPanel::OnChangeFilterclass( const char *pText )
{
m_szFilterClass = pText;
MarkDirty( true );
}
//-----------------------------------------------------------------------------
// Deals with all check buttons
//-----------------------------------------------------------------------------
void CEntityReportPanel::OnTextChanged( KeyValues *kv )
{
TextEntry *pPanel = (TextEntry*)kv->GetPtr( "panel", NULL );
int nLength = pPanel->GetTextLength();
char *pBuf = (char*)_alloca( nLength + 1 );
pPanel->GetText( pBuf, nLength+1 );
if ( pPanel == m_pFilterClass )
{
OnChangeFilterclass( pBuf );
return;
}
if ( pPanel == m_pFilterKey )
{
OnChangeFilterkey( pBuf );
return;
}
if ( pPanel == m_pFilterValue )
{
OnChangeFiltervalue( pBuf );
return;
}
}
//-----------------------------------------------------------------------------
// Deals with all check buttons
//-----------------------------------------------------------------------------
void CEntityReportPanel::OnButtonToggled( KeyValues *kv )
{
Panel *pPanel = (Panel*)kv->GetPtr( "panel", NULL );
bool bState = kv->GetInt( "state", 0 ) != 0;
if ( pPanel == m_pFilterByClass )
{
OnFilterByClass( bState );
return;
}
if ( pPanel == m_pFilterByKeyvalue )
{
OnFilterByKeyvalue( bState );
return;
}
if ( pPanel == m_pFilterByHidden )
{
OnFilterByHidden( bState );
return;
}
if ( pPanel == m_pExact )
{
OnFilterKeyValueExact( bState );
return;
}
if ( pPanel == m_pFilterEverything )
{
OnFilterByType( FILTER_SHOW_EVERYTHING );
return;
}
if ( pPanel == m_pFilterPointEntities )
{
OnFilterByType( FILTER_SHOW_POINT_ENTITIES );
return;
}
if ( pPanel == m_pFilterBrushModels )
{
OnFilterByType( FILTER_SHOW_BRUSH_ENTITIES );
return;
}
}
//-----------------------------------------------------------------------------
// FIXME: Necessary because SetSelected doesn't cause a ButtonToggled message to trigger
//-----------------------------------------------------------------------------
void CEntityReportPanel::OnCheckButtonChecked( KeyValues *kv )
{
OnButtonToggled( kv );
}
void CEntityReportPanel::OnRadioButtonChecked( KeyValues *kv )
{
OnButtonToggled( kv );
}
#if 0
//-----------------------------------------------------------------------------
// Purpose: Centers the 2D and 3D views on the selected entities.
//-----------------------------------------------------------------------------
void CEntityReportPanel::OnGoto()
{
MarkSelectedEntities();
m_pDoc->CenterViewsOnSelection();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEntityReportPanel::MarkSelectedEntities()
{
m_pDoc->SelectObject(NULL, CMapDoc::scClear);
for(int i = 0; i < m_cEntities.GetCount(); i++)
{
if(!m_cEntities.GetSel(i))
continue;
CMapEntity *pEntity = (CMapEntity*) m_cEntities.GetItemDataPtr(i);
m_pDoc->SelectObject(pEntity, CMapDoc::scSelect);
}
m_pDoc->SelectObject(NULL, CMapDoc::scUpdateDisplay);
}
#endif
void CEntityReportPanel::OnTick( )
{
BaseClass::OnTick();
// check filters
float flTime = Plat_FloatTime();
if ( m_bFilterTextChanged )
{
if ( (flTime - m_flFilterTime) > 1e-3 )
{
m_bFilterTextChanged = false;
m_flFilterTime = flTime;
UpdateEntityList();
}
}
if ( m_bRegistrySettingsChanged )
{
if ( (flTime - m_flRegistryTime) > 1e-3 )
{
m_bRegistrySettingsChanged = false;
m_flRegistryTime = flTime;
SaveSettingsToRegistry();
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEntityReportPanel::UpdateEntityList(void)
{
if ( m_bSuppressEntityListUpdate )
return;
m_bFilterTextChanged = false;
m_pEntities->RemoveAll();
CDmAttribute *pEntityList = m_pDoc->GetEntityList();
int nCount = pEntityList->Count();
for ( int i = 0; i < nCount; ++i )
{
CDmElement *pEntity = GetElement< CDmElement >( pEntityList->Get(i) );
const char *pClassName = pEntity->GetAttributeValueString( "classname" );
if ( !pClassName || !pClassName[0] )
{
pClassName = "<no class>";
}
KeyValues *kv = new KeyValues( "node" );
kv->SetString( "classname", pClassName );
kv->SetPtr( "entity", pEntity );
m_pEntities->AddItem( kv, 0, false, false );
}
m_pEntities->SortList();
}
#if 0
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEntityReportPanel::GenerateReport()
{
POSITION p = pGD->Classes.GetHeadPosition();
CString str;
while(p)
{
GDclass *pc = pGD->Classes.GetNext(p);
if(!pc->IsBaseClass())
{
str = pc->GetName();
if(str != "worldspawn")
m_cFilterClass.AddString(str);
}
}
SetTimer(1, 500, NULL);
OnFilterbykeyvalue();
OnFilterbytype();
OnFilterbyclass();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEntityReportPanel::OnSelChangeEntityList()
{
MarkSelectedEntities();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEntityReportPanel::OnDblClkEntityList()
{
m_pDoc->CenterViewsOnSelection();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEntityReportPanel::OnOK()
{
DestroyWindow();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEntityReportPanel::OnClose()
{
DestroyWindow();
}
//-----------------------------------------------------------------------------
// Purpose: Called when our window is being destroyed.
//-----------------------------------------------------------------------------
void CEntityReportPanel::OnDestroy()
{
SaveToIni();
s_pDlg = NULL;
delete this;
}
#endif
@@ -0,0 +1,58 @@
// ----------------------------------------- //
// File generated by VPC //
// ----------------------------------------- //
Source file: F:\csgo_64\cstrike15_src\common\debug_dll_check.cpp
Debug output file: F:\csgo_64\cstrike15_src\common\debug_dll_check.cpp
Release output file: F:\csgo_64\cstrike15_src\common\debug_dll_check.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\public\interpolatortypes.cpp
Debug output file: F:\csgo_64\cstrike15_src\public\interpolatortypes.cpp
Release output file: F:\csgo_64\cstrike15_src\public\interpolatortypes.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\public\tier0\memoverride.cpp
Debug output file: F:\csgo_64\cstrike15_src\public\tier0\memoverride.cpp
Release output file: F:\csgo_64\cstrike15_src\public\tier0\memoverride.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\tools\pet\particlesystemdefinitionbrowser.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\pet\particlesystemdefinitionbrowser.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\pet\particlesystemdefinitionbrowser.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\tools\pet\particlesystempropertiescontainer.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\pet\particlesystempropertiescontainer.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\pet\particlesystempropertiescontainer.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\tools\pet\petdoc.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\pet\petdoc.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\pet\petdoc.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\tools\pet\pettool.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\pet\pettool.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\pet\pettool.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\public\registry.cpp
Debug output file: F:\csgo_64\cstrike15_src\public\registry.cpp
Release output file: F:\csgo_64\cstrike15_src\public\registry.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\public\vgui_controls\vgui_controls.cpp
Debug output file: F:\csgo_64\cstrike15_src\public\vgui_controls\vgui_controls.cpp
Release output file: F:\csgo_64\cstrike15_src\public\vgui_controls\vgui_controls.cpp
Containing unity file:
PCH file:
@@ -0,0 +1,513 @@
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose: Singleton dialog that generates and presents the entity report.
//
//===========================================================================//
#include "particlesystemdefinitionbrowser.h"
#include "tier1/keyvalues.h"
#include "tier1/utlbuffer.h"
#include "iregistry.h"
#include "vgui/ivgui.h"
#include "vgui_controls/listpanel.h"
#include "vgui_controls/inputdialog.h"
#include "vgui_controls/messagebox.h"
#include "petdoc.h"
#include "pettool.h"
#include "datamodel/dmelement.h"
#include "vgui/keycode.h"
#include "dme_controls/dmecontrols_utils.h"
#include "dme_controls/particlesystempanel.h"
#include "matsys_controls/particlepicker.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
using namespace vgui;
//-----------------------------------------------------------------------------
// Sort by particle system definition name
//-----------------------------------------------------------------------------
static int __cdecl ParticleSystemNameSortFunc( vgui::ListPanel *pPanel, const ListPanelItem &item1, const ListPanelItem &item2 )
{
const char *string1 = item1.kv->GetString("name");
const char *string2 = item2.kv->GetString("name");
return Q_stricmp( string1, string2 );
}
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CParticleSystemDefinitionBrowser::CParticleSystemDefinitionBrowser( CPetDoc *pDoc, vgui::Panel* pParent, const char *pName )
: BaseClass( pParent, pName ), m_pDoc( pDoc )
{
SetKeyBoardInputEnabled( true );
SetPaintBackgroundEnabled( true );
m_pSystemGrid = new CParticleSnapshotGrid( this, "SnapshotGrid" );
m_pSystemGrid->AddActionSignalTarget(this);
CBoxSizer *pBaseSizer = new CBoxSizer( ESLD_HORIZONTAL );
{
CBoxSizer *pDefinitionSizer = new CBoxSizer( ESLD_VERTICAL );
pDefinitionSizer->AddPanel( new Label( this, "ParticleSystemsLabel", "Particle System Definitions:" ), SizerAddArgs_t() );
pDefinitionSizer->AddPanel( m_pSystemGrid, SizerAddArgs_t().Expand( 1.0f ) );
{
CBoxSizer *pBottomRowSizer = new CBoxSizer( ESLD_HORIZONTAL );
pBottomRowSizer->AddPanel( new Button( this, "SaveButton", "Save", this, "save" ), SizerAddArgs_t() );
pBottomRowSizer->AddPanel( new Button( this, "SaveAndTestButton", "Save and Test", this, "SaveAndTest" ), SizerAddArgs_t() );
pDefinitionSizer->AddSizer( pBottomRowSizer, SizerAddArgs_t() );
}
pBaseSizer->AddSizer( pDefinitionSizer, SizerAddArgs_t().Expand( 1.0f ) );
}
{
CBoxSizer *pButtonColSizer = new CBoxSizer( ESLD_VERTICAL );
m_pCreateButton = new Button( this, "CreateButton", "Create", this, "Create" );
pButtonColSizer->AddPanel( m_pCreateButton, SizerAddArgs_t() );
m_pDeleteButton = new Button( this, "DeleteButton", "Delete", this, "Delete" );
m_pDeleteButton->SetEnabled(false);
pButtonColSizer->AddPanel( m_pDeleteButton, SizerAddArgs_t() );
m_pCopyButton = new Button( this, "CopyButton", "Duplicate", this, "Copy" );
m_pCopyButton->SetEnabled(false);
pButtonColSizer->AddPanel( m_pCopyButton, SizerAddArgs_t() );
pBaseSizer->AddSizer( pButtonColSizer, SizerAddArgs_t() );
}
SetSizer( pBaseSizer );
UpdateParticleSystemList();
}
CParticleSystemDefinitionBrowser::~CParticleSystemDefinitionBrowser()
{
SaveUserConfig();
}
//-----------------------------------------------------------------------------
// Gets the ith selected particle system
//-----------------------------------------------------------------------------
CDmeParticleSystemDefinition* CParticleSystemDefinitionBrowser::GetSelectedParticleSystem( int i )
{
if ( i < 0 || i >= m_pSystemGrid->GetSelectedSystemCount() )
return NULL;
int iSel = m_pSystemGrid->GetSelectedSystemId(i);
return m_pDoc->GetParticleSystem(iSel);
}
//-----------------------------------------------------------------------------
// Purpose: Deletes the marked objects.
//-----------------------------------------------------------------------------
void CParticleSystemDefinitionBrowser::DeleteParticleSystems()
{
{
// This is undoable
CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG|NOTIFY_FLAG_PARTICLESYS_ADDED_OR_REMOVED, "Delete Particle Systems", "Delete Particle Systems" );
//
// Build a list of objects to delete.
//
CUtlVector< CDmeParticleSystemDefinition* > itemsToDelete;
int nCount = m_pSystemGrid->GetSelectedSystemCount();
for (int i = 0; i < nCount; i++)
{
CDmeParticleSystemDefinition *pParticleSystem = GetSelectedParticleSystem( i );
if ( pParticleSystem )
{
itemsToDelete.AddToTail( pParticleSystem );
}
}
m_pSystemGrid->DeselectAll();
nCount = itemsToDelete.Count();
for ( int i = 0; i < nCount; ++i )
{
m_pDoc->DeleteParticleSystemDefinition( itemsToDelete[i] );
}
g_pPetTool->SetCurrentParticleSystem( NULL, true );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CParticleSystemDefinitionBrowser::OnKeyCodeTyped( vgui::KeyCode code )
{
if ( code == KEY_DELETE )
{
DeleteParticleSystems();
}
else
{
BaseClass::OnKeyCodeTyped( code );
}
}
//-----------------------------------------------------------------------------
// Called when the selection changes
//-----------------------------------------------------------------------------
void CParticleSystemDefinitionBrowser::UpdateParticleSystemSelection()
{
if ( m_pSystemGrid->GetSelectedSystemCount() == 1 )
{
g_pPetTool->SetCurrentParticleSystem( m_pDoc->GetParticleSystem( m_pSystemGrid->GetSelectedSystemId(0) ), false );
}
else
{
g_pPetTool->SetCurrentParticleSystem( NULL, false );
}
}
void CParticleSystemDefinitionBrowser::OnParticleSystemSelectionChanged( )
{
UpdateParticleSystemSelection();
bool bAnySelected = ( m_pSystemGrid->GetSelectedSystemCount() > 0 );
m_pDeleteButton->SetEnabled( bAnySelected );
m_pCopyButton->SetEnabled( bAnySelected );
}
//-----------------------------------------------------------------------------
// Select a particular node
//-----------------------------------------------------------------------------
void CParticleSystemDefinitionBrowser::SelectParticleSystem( CDmeParticleSystemDefinition *pFind )
{
for ( int i = 0; i < m_pDoc->GetParticleSystemCount(); ++i )
{
if ( m_pDoc->GetParticleSystem(i) == pFind )
{
m_pSystemGrid->SelectId( i, false, false );
break;
}
}
}
//-----------------------------------------------------------------------------
// Called when buttons are clicked
//-----------------------------------------------------------------------------
void CParticleSystemDefinitionBrowser::OnInputCompleted( KeyValues *pKeyValues )
{
const char *pText = pKeyValues->GetString( "text", NULL );
if ( m_pDoc->IsParticleSystemDefined( pText ) )
{
char pBuf[1024];
Q_snprintf( pBuf, sizeof(pBuf), "Particle System \"%s\" already exists!\n", pText );
vgui::MessageBox *pMessageBox = new vgui::MessageBox( "Duplicate Particle System Name!\n", pBuf, g_pPetTool->GetRootPanel() );
pMessageBox->DoModal( );
return;
}
if ( pKeyValues->FindKey( "create" ) )
{
CDmeParticleSystemDefinition *pParticleSystem = m_pDoc->AddNewParticleSystemDefinition( pText );
g_pPetTool->SetCurrentParticleSystem( pParticleSystem );
}
else if ( pKeyValues->FindKey( "copy_one" ) || pKeyValues->FindKey( "copy_many" ) )
{
int nCount = m_pSystemGrid->GetSelectedSystemCount();
if ( nCount == 1 )
{
CDmeParticleSystemDefinition *pParticleSystem = GetSelectedParticleSystem( 0 );
CDmeParticleSystemDefinition * pNew = NULL;
{
CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG|NOTIFY_FLAG_PARTICLESYS_ADDED_OR_REMOVED, "Duplicate One Particle System", "Duplicate One Particle System" );
pNew = CastElement<CDmeParticleSystemDefinition>( pParticleSystem->Copy( ) );
pNew->SetName( pText );
m_pDoc->AddNewParticleSystemDefinition( pNew, guard );
}
g_pPetTool->SetCurrentParticleSystem( pNew );
}
else if ( nCount > 1 )
{
CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG|NOTIFY_FLAG_PARTICLESYS_ADDED_OR_REMOVED, "Duplicate Multiple Particle Systems", "Duplicate Multiple Particle Systems" );
CUtlVector<CDmeParticleSystemDefinition*> pNewSystems;
for ( int i = 0; i < nCount; ++i )
{
CDmeParticleSystemDefinition *pParticleSystem = GetSelectedParticleSystem( i );
CDmeParticleSystemDefinition *pNew = NULL;
CUtlString newName = pParticleSystem->GetName();
newName += pText;
pNew = CastElement<CDmeParticleSystemDefinition>( pParticleSystem->Copy( ) );
pNew->SetName( newName.Get() );
pNewSystems.AddToTail(pNew);
}
Assert( pNewSystems.Count() == nCount );
for ( int i = 0; i < nCount; ++i )
{
m_pDoc->AddNewParticleSystemDefinition( pNewSystems[i], guard );
}
g_pPetTool->SetCurrentParticleSystem( NULL );
}
}
}
//-----------------------------------------------------------------------------
// Copy to clipboard
//-----------------------------------------------------------------------------
void CParticleSystemDefinitionBrowser::OnCopy( )
{
int nCount = m_pSystemGrid->GetSelectedSystemCount();
CUtlVector< KeyValues * > list;
CUtlRBTree< CDmeParticleSystemDefinition* > defs( 0, 0, DefLessFunc( CDmeParticleSystemDefinition* ) );
for ( int i = 0; i < nCount; ++i )
{
CDmeParticleSystemDefinition *pParticleSystem = GetSelectedParticleSystem( i );
CUtlBuffer buf( 0, 0, CUtlBuffer::TEXT_BUFFER );
if ( g_pDataModel->Serialize( buf, "keyvalues2", "pcf", pParticleSystem->GetHandle() ) )
{
KeyValues *pData = new KeyValues( "Clipboard" );
pData->SetString( PARTICLE_CLIPBOARD_DEFINITION_STR, (char*)buf.Base() );
list.AddToTail( pData );
}
}
if ( list.Count() )
{
g_pDataModel->SetClipboardData( list );
}
}
//-----------------------------------------------------------------------------
// Paste from clipboard
//-----------------------------------------------------------------------------
void CParticleSystemDefinitionBrowser::ReplaceDef_r( CUndoScopeGuard& guard, CDmeParticleSystemDefinition *pDef )
{
if ( !pDef )
return;
m_pDoc->ReplaceParticleSystemDefinition( pDef );
int nChildCount = pDef->GetParticleFunctionCount( FUNCTION_CHILDREN );
for ( int i = 0; i < nChildCount; ++i )
{
CDmeParticleChild *pChildFunction = static_cast< CDmeParticleChild* >( pDef->GetParticleFunction( FUNCTION_CHILDREN, i ) );
CDmeParticleSystemDefinition* pChild = pChildFunction->m_Child;
ReplaceDef_r( guard, pChild );
}
}
void CParticleSystemDefinitionBrowser::PasteOperator( CUndoScopeGuard& guard, CDmeParticleFunction *pFunc )
{
int nCount = m_pSystemGrid->GetSelectedSystemCount();
for ( int i = 0; i < nCount; ++i )
{
CDmeParticleSystemDefinition *pParticleSystem = GetSelectedParticleSystem( i );
pParticleSystem->AddCopyOfOperator( pFunc );
}
}
void CParticleSystemDefinitionBrowser::PasteDefinitionBody( CUndoScopeGuard& guard, CDmeParticleSystemDefinition *pDef )
{
int nCount = m_pSystemGrid->GetSelectedSystemCount();
for ( int i = 0; i < nCount; ++i )
{
CDmeParticleSystemDefinition *pParticleSystem = GetSelectedParticleSystem( i );
pParticleSystem->OverrideAttributesFromOtherDefinition( pDef );
}
}
void CParticleSystemDefinitionBrowser::PasteFromClipboard( )
{
// This is undoable
CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, "Paste From Clipboard", "Paste From Clipboard" );
bool bRefreshAll = false;
CUtlVector< KeyValues * > list;
g_pDataModel->GetClipboardData( list );
int nItems = list.Count();
for ( int i = 0; i < nItems; ++i )
{
CDmeParticleSystemDefinition *pDef = ReadParticleClassFromKV<CDmeParticleSystemDefinition>( list[i], PARTICLE_CLIPBOARD_DEFINITION_STR );
if ( pDef )
{
ReplaceDef_r( guard, pDef );
bRefreshAll = true;
continue;
}
CDmeParticleFunction *pFunc = ReadParticleClassFromKV<CDmeParticleFunction>( list[i], PARTICLE_CLIPBOARD_FUNCTIONS_STR );
if ( pFunc )
{
PasteOperator( guard, pFunc );
bRefreshAll = true;
continue;
}
pDef = ReadParticleClassFromKV<CDmeParticleSystemDefinition>( list[i], PARTICLE_CLIPBOARD_DEF_BODY_STR );
if ( pDef )
{
PasteDefinitionBody( guard, pDef );
bRefreshAll = true;
continue;
}
}
guard.Release();
if ( bRefreshAll )
{
m_pDoc->UpdateAllParticleSystems();
}
}
//-----------------------------------------------------------------------------
// Called when buttons are clicked
//-----------------------------------------------------------------------------
void CParticleSystemDefinitionBrowser::OnCommand( const char *pCommand )
{
if ( !Q_stricmp( pCommand, "create" ) )
{
vgui::InputDialog *pInputDialog = new vgui::InputDialog( g_pPetTool->GetRootPanel(), "Enter Particle System Name", "Name:", "" );
pInputDialog->SetSmallCaption( true );
pInputDialog->SetMultiline( false );
pInputDialog->AddActionSignalTarget( this );
pInputDialog->DoModal( new KeyValues("create") );
return;
}
if ( !Q_stricmp( pCommand, "copy" ) )
{
if ( m_pSystemGrid->GetSelectedSystemCount() == 1 )
{
CUtlString newName = m_pSystemGrid->GetSystemName(m_pSystemGrid->GetSelectedSystemId(0));
newName += "_copy";
vgui::InputDialog *pInputDialog = new vgui::InputDialog( g_pPetTool->GetRootPanel(), "Enter Duplicate System Name", "Name:", newName.Get() );
pInputDialog->SetSmallCaption( true );
pInputDialog->SetMultiline( false );
pInputDialog->AddActionSignalTarget( this );
pInputDialog->DoModal( new KeyValues("copy_one") );
}
else if ( m_pSystemGrid->GetSelectedSystemCount() > 1 )
{
vgui::InputDialog *pInputDialog = new vgui::InputDialog( g_pPetTool->GetRootPanel(), "Enter Suffix for New Systems", "Suffix:", "_copy" );
pInputDialog->SetSmallCaption( true );
pInputDialog->SetMultiline( false );
pInputDialog->AddActionSignalTarget( this );
pInputDialog->DoModal( new KeyValues("copy_many") );
}
return;
}
if ( !Q_stricmp( pCommand, "delete" ) )
{
DeleteParticleSystems();
return;
}
if ( !Q_stricmp( pCommand, "Save" ) )
{
g_pPetTool->Save();
return;
}
if ( !Q_stricmp( pCommand, "SaveAndTest" ) )
{
g_pPetTool->SaveAndTest();
return;
}
BaseClass::OnCommand( pCommand );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CParticleSystemDefinitionBrowser::UpdateParticleSystemList( bool bRetainSelection )
{
/////////////////////////
// build a list of previously selected systems
CUtlVector< CUtlString > selectedItems;
if ( bRetainSelection )
{
int nCount = m_pSystemGrid->GetSelectedSystemCount();
for ( int i = 0; i < nCount; ++i )
{
CDmeParticleSystemDefinition *pParticleSystem = GetSelectedParticleSystem( i );
if ( pParticleSystem )
{
selectedItems.AddToTail( pParticleSystem->GetName() );
}
}
}
/////////////////////////
// now go nuts
const CDmrParticleSystemList particleSystemList = m_pDoc->GetParticleSystemDefinitionList();
if ( !particleSystemList.IsValid() )
{
m_pSystemGrid->SetParticleList( CUtlVector<const char *>() );
return;
}
CUtlVector<const char *> systemNames;
CUtlVector<int> selectionIndicies;
/////////////////////////
// populate the new list
for ( int i = 0; i < particleSystemList.Count(); ++i )
{
CDmeParticleSystemDefinition *pParticleSystem = particleSystemList[i];
if ( !pParticleSystem )
continue;
systemNames.AddToTail( pParticleSystem->GetName() );
// see if the system was previously selected
for ( int s = 0; s < selectedItems.Count(); ++s )
{
if( !V_strcmp(pParticleSystem->GetName(), selectedItems[s]) )
{
selectionIndicies.AddToTail(i);
}
}
}
m_pSystemGrid->SetParticleList( systemNames );
/////////////////////////
// reselect any identified systems
if ( bRetainSelection )
{
for ( int i = 0; i < selectionIndicies.Count(); ++i )
{
m_pSystemGrid->SelectId( selectionIndicies[i], true, false );
}
}
}
@@ -0,0 +1,93 @@
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
//===========================================================================//
#ifndef PARTICLESYSTEMDEFINITIONBROWSER_H
#define PARTICLESYSTEMDEFINITIONBROWSER_H
#ifdef _WIN32
#pragma once
#endif
#include "vgui_controls/editablepanel.h"
#include "tier1/utlstring.h"
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class CPetDoc;
class CPetTool;
class CDmeParticleSystemDefinition;
class CUndoScopeGuard;
class CParticleSnapshotGrid;
namespace vgui
{
class ComboBox;
class Button;
class TextEntry;
class ListPanel;
class CheckButton;
class RadioButton;
}
//-----------------------------------------------------------------------------
// Panel that shows all entities in the level
//-----------------------------------------------------------------------------
class CParticleSystemDefinitionBrowser : public vgui::EditablePanel
{
DECLARE_CLASS_SIMPLE( CParticleSystemDefinitionBrowser, vgui::EditablePanel );
public:
CParticleSystemDefinitionBrowser( CPetDoc *pDoc, vgui::Panel* pParent, const char *pName ); // standard constructor
virtual ~CParticleSystemDefinitionBrowser();
// Inherited from Panel
virtual void OnCommand( const char *pCommand );
virtual void OnKeyCodeTyped( vgui::KeyCode code );
// Methods related to updating the listpanel
void UpdateParticleSystemList( bool bRetainSelection = true );
// Select a particular node
void SelectParticleSystem( CDmeParticleSystemDefinition *pParticleSystem );
// paste.
void PasteFromClipboard();
private:
MESSAGE_FUNC( OnCopy, "OnCopy" );
KEYBINDING_FUNC_NODECLARE( edit_copy, KEY_C, vgui::MODIFIER_CONTROL, OnCopy, "#edit_copy_help", 0 );
MESSAGE_FUNC_PARAMS( OnInputCompleted, "InputCompleted", kv );
MESSAGE_FUNC( OnParticleSystemSelectionChanged, "ParticleSystemSelectionChanged" );
void ReplaceDef_r( CUndoScopeGuard& guard, CDmeParticleSystemDefinition *pDef );
void PasteOperator( CUndoScopeGuard& guard, class CDmeParticleFunction *pDef );
void PasteDefinitionBody( CUndoScopeGuard& guard, CDmeParticleSystemDefinition *pDef );
// Gets the selected particle system
CDmeParticleSystemDefinition* GetSelectedParticleSystem( int nIdx );
// Called when the selection changes
void UpdateParticleSystemSelection();
// Deletes selected particle systems
void DeleteParticleSystems();
// Shows the most recent selected object in properties window
void OnProperties();
CPetDoc *m_pDoc;
CParticleSnapshotGrid *m_pSystemGrid;
vgui::Button *m_pCreateButton;
vgui::Button *m_pDeleteButton;
vgui::Button *m_pCopyButton;
};
#endif // PARTICLESYSTEMDEFINITIONBROWSER_H
@@ -0,0 +1,73 @@
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose: Dialog used to edit properties of a particle system definition
//
//===========================================================================//
#include "ParticleSystemPropertiesContainer.h"
#include "petdoc.h"
#include "pettool.h"
#include "datamodel/dmelement.h"
#include "movieobjects/dmeparticlesystemdefinition.h"
#include "dme_controls/dmecontrols_utils.h"
#include "dme_controls/particlesystempanel.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
using namespace vgui;
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
#pragma warning (disable:4355)
CParticleSystemPropertiesContainer::CParticleSystemPropertiesContainer( CPetDoc *pDoc, vgui::Panel* pParent ) :
BaseClass( this, pParent ), m_pDoc( pDoc )
{
}
#pragma warning (default:4355)
//-----------------------------------------------------------------------------
// Refreshes the list of raw controls
//-----------------------------------------------------------------------------
void CParticleSystemPropertiesContainer::GetKnownParticleDefinitions( CUtlVector< CDmeParticleSystemDefinition* > &definitions )
{
definitions.RemoveAll();
CDmrParticleSystemList particleSystemList = g_pPetTool->GetDocument()->GetParticleSystemDefinitionList();
if ( !particleSystemList.IsValid() )
return;
int nCount = particleSystemList.Count();
definitions.EnsureCapacity( nCount );
for ( int i = 0; i < nCount; ++i )
{
CDmeParticleSystemDefinition *pParticleSystem = particleSystemList[i];
definitions.AddToTail( pParticleSystem );
}
}
//-----------------------------------------------------------------------------
// Called when the base class changes anything at all in the particle system
//-----------------------------------------------------------------------------
void CParticleSystemPropertiesContainer::OnParticleSystemModified()
{
CAppNotifyScopeGuard sg( "CParticleSystemPropertiesContainer::OnParticleSystemModified", NOTIFY_SETDIRTYFLAG );
}
//-----------------------------------------------------------------------------
// Called when the selected particle function changes
//-----------------------------------------------------------------------------
void CParticleSystemPropertiesContainer::OnParticleFunctionSelChanged( KeyValues *pParams )
{
if ( g_pPetTool->GetParticlePreview() )
{
CDmeParticleFunction *pFunction = GetElementKeyValue<CDmeParticleFunction>( pParams, "function" );
g_pPetTool->GetParticlePreview()->SetParticleFunction( pFunction );
}
}
@@ -0,0 +1,45 @@
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose: Dialog used to edit properties of a particle system definition
//
//===========================================================================//
#ifndef PARTICLESYSTEMPROPERTIESCONTAINER_H
#define PARTICLESYSTEMPROPERTIESCONTAINER_H
#ifdef _WIN32
#pragma once
#endif
#include "dme_controls/particlesystempropertiespanel.h"
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class CPetDoc;
//-----------------------------------------------------------------------------
// Panel used to edit a particle system definition
//-----------------------------------------------------------------------------
class CParticleSystemPropertiesContainer : public CParticleSystemPropertiesPanel, public IParticleSystemPropertiesPanelQuery
{
DECLARE_CLASS_SIMPLE( CParticleSystemPropertiesContainer, CParticleSystemPropertiesPanel );
public:
CParticleSystemPropertiesContainer( CPetDoc *pDoc, vgui::Panel* pParent ); // standard constructor
// Inherited from IParticleSystemPropertiesPanelQuery
virtual void GetKnownParticleDefinitions( CUtlVector< CDmeParticleSystemDefinition* > &definitions );
private:
MESSAGE_FUNC_PARAMS( OnParticleFunctionSelChanged, "ParticleFunctionSelChanged", params );
// For inheriting classes to get notified without having to listen to messages
virtual void OnParticleSystemModified();
CPetDoc *m_pDoc;
};
#endif // PARTICLESYSTEMPROPERTIESCONTAINER_H
+64
View File
@@ -0,0 +1,64 @@
//-----------------------------------------------------------------------------
// PET.VPC
//
// Project Script
//-----------------------------------------------------------------------------
$Macro SRCDIR "..\.."
$Macro OUTBINDIR "$SRCDIR\..\game\bin\tools"
$Include "$SRCDIR\vpc_scripts\source_dll_win32_base.vpc"
$Configuration
{
$Compiler
{
$AdditionalIncludeDirectories "$BASE,.\,$SRCDIR\game\shared"
$PreprocessorDefinitions "$BASE;PET_EXPORTS"
}
$Linker
{
$AdditionalDependencies "$BASE Psapi.lib"
}
}
$Project "Pet"
{
$Folder "Source Files"
{
$File "$SRCDIR\public\interpolatortypes.cpp"
$File "particlesystemdefinitionbrowser.cpp"
$File "particlesystempropertiescontainer.cpp"
$File "petdoc.cpp"
$File "pettool.cpp"
$File "$SRCDIR\public\registry.cpp"
$File "$SRCDIR\public\vgui_controls\vgui_controls.cpp"
}
$Folder "Header Files"
{
$File "$SRCDIR\public\mathlib\mathlib.h"
$File "particlesystemdefinitionbrowser.h"
$File "particlesystempropertiescontainer.h"
$File "petdoc.h"
$File "pettool.h"
}
$Folder "Link Libraries"
{
$File "$SRCDIR\lib\public\bonesetup.lib"
$File "$SRCDIR\lib\public\datamodel.lib"
$File "$SRCDIR\lib\public\dme_controls.lib"
$File "$SRCDIR\lib\public\dmserializers.lib"
$File "$SRCDIR\lib\public\dmxloader.lib"
$File "$SRCDIR\lib\public\mathlib.lib"
$File "$SRCDIR\lib\public\matsys_controls.lib"
$File "$SRCDIR\lib\public\movieobjects.lib"
$File "$SRCDIR\lib\public\particles.lib"
$File "$SRCDIR\lib\public\tier2.lib"
$File "$SRCDIR\lib\public\tier3.lib"
$File "$SRCDIR\lib\public\toolutils.lib"
$File "$SRCDIR\lib\public\vgui_controls.lib"
}
}
+13
View File
@@ -0,0 +1,13 @@
"vpc_cache"
{
"CacheVersion" "1"
"win32"
{
"CRCFile" "pet.vcxproj.vpc_crc"
"OutputFiles"
{
"0" "pet.vcxproj"
"1" "pet.vcxproj.filters"
}
}
}
+616
View File
@@ -0,0 +1,616 @@
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "petdoc.h"
#include "tier1/keyvalues.h"
#include "tier1/utlbuffer.h"
#include "toolutils/enginetools_int.h"
#include "filesystem.h"
#include "pettool.h"
#include "toolframework/ienginetool.h"
#include "movieobjects/dmeparticlesystemdefinition.h"
#include "datamodel/idatamodel.h"
#include "toolutils/attributeelementchoicelist.h"
#include "particlesystemdefinitionbrowser.h"
#include "vgui_controls/messagebox.h"
#include "particles/particles.h"
#include "particlesystempropertiescontainer.h"
#include "dme_controls/particlesystempanel.h"
#include "dme_controls/sheeteditorpanel.h"
#include "dme_controls/dmecontrols.h"
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CPetDoc::CPetDoc( IPetDocCallback *pCallback ) : m_pCallback( pCallback )
{
m_hRoot = NULL;
m_pFileName[0] = 0;
m_bDirty = false;
g_pDataModel->InstallNotificationCallback( this );
SetElementPropertiesChoices( this );
}
CPetDoc::~CPetDoc()
{
if ( m_hRoot.Get() )
{
g_pDataModel->RemoveFileId( m_hRoot->GetFileId() );
m_hRoot = NULL;
}
g_pDataModel->RemoveNotificationCallback( this );
SetElementPropertiesChoices( NULL );
}
//-----------------------------------------------------------------------------
// Inherited from INotifyUI
//-----------------------------------------------------------------------------
void CPetDoc::NotifyDataChanged( const char *pReason, int nNotifySource, int nNotifyFlags )
{
OnDataChanged( pReason, nNotifySource, nNotifyFlags );
}
bool CPetDoc::GetIntChoiceList( const char *pChoiceListType, CDmElement *pElement,
const char *pAttributeName, bool bArrayElement, IntChoiceList_t &list )
{
if ( !Q_stricmp( pChoiceListType, "particlefield" ) )
{
for ( int i = 0; i < MAX_PARTICLE_ATTRIBUTES; ++i )
{
const char *pName = g_pParticleSystemMgr->GetParticleFieldName( i );
if ( pName )
{
int j = list.AddToTail();
list[j].m_nValue = i;
list[j].m_pChoiceString = pName;
}
}
return true;
}
if ( !Q_stricmp( pChoiceListType, "particlefield_scalar" ) )
{
for ( int i = 0; i < MAX_PARTICLE_ATTRIBUTES; ++i )
{
if ( ( ATTRIBUTES_WHICH_ARE_VEC3S_MASK & ( 1 << i ) ) != 0 )
continue;
const char *pName = g_pParticleSystemMgr->GetParticleFieldName( i );
if ( pName )
{
int j = list.AddToTail();
list[j].m_nValue = i;
list[j].m_pChoiceString = pName;
}
}
return true;
}
if ( !Q_stricmp( pChoiceListType, "particlefield_vector" ) )
{
for ( int i = 0; i < MAX_PARTICLE_ATTRIBUTES; ++i )
{
if ( ( ATTRIBUTES_WHICH_ARE_VEC3S_MASK & ( 1 << i ) ) == 0 )
continue;
const char *pName = g_pParticleSystemMgr->GetParticleFieldName( i );
if ( pName )
{
int j = list.AddToTail();
list[j].m_nValue = i;
list[j].m_pChoiceString = pName;
}
}
return true;
}
if ( !Q_stricmp( pChoiceListType, "particlefield_rotation" ) )
{
for ( int i = 0; i < MAX_PARTICLE_ATTRIBUTES; ++i )
{
if ( ( ATTRIBUTES_WHICH_ARE_ROTATION & ( 1 << i ) ) == 0 )
continue;
const char *pName = g_pParticleSystemMgr->GetParticleFieldName( i );
if ( pName )
{
int j = list.AddToTail();
list[j].m_nValue = i;
list[j].m_pChoiceString = pName;
}
}
return true;
}
if ( !Q_stricmp( pChoiceListType, "particlefield_activity" ) )
{
for ( int i = 0; i < g_pParticleSystemMgr->Query()->GetActivityCount(); ++i )
{
const char *pName = g_pParticleSystemMgr->Query()->GetActivityNameFromIndex( i );
if ( pName )
{
int j = list.AddToTail();
list[j].m_nValue = i;
list[j].m_pChoiceString = pName;
}
}
return true;
}
return false;
}
//-----------------------------------------------------------------------------
// Gets the file name
//-----------------------------------------------------------------------------
const char *CPetDoc::GetFileName()
{
return m_pFileName;
}
void CPetDoc::SetFileName( const char *pFileName )
{
Q_strncpy( m_pFileName, pFileName, sizeof( m_pFileName ) );
Q_FixSlashes( m_pFileName );
SetDirty( true );
}
//-----------------------------------------------------------------------------
// Dirty bits
//-----------------------------------------------------------------------------
void CPetDoc::SetDirty( bool bDirty )
{
m_bDirty = bDirty;
}
bool CPetDoc::IsDirty() const
{
return m_bDirty;
}
//-----------------------------------------------------------------------------
// Creates the root element
//-----------------------------------------------------------------------------
bool CPetDoc::CreateRootElement()
{
Assert( !m_hRoot.Get() );
DmFileId_t fileid = g_pDataModel->FindOrCreateFileId( GetFileName() );
// Create the main element
m_hRoot = g_pDataModel->CreateElement( "DmElement", GetFileName(), fileid );
if ( m_hRoot == DMELEMENT_HANDLE_INVALID )
return false;
g_pDataModel->SetFileRoot( fileid, m_hRoot );
// We need to create an element array attribute storing particle system definitions
m_hRoot->AddAttribute( "particleSystemDefinitions", AT_ELEMENT_ARRAY );
return true;
}
//-----------------------------------------------------------------------------
// Creates a new document
//-----------------------------------------------------------------------------
void CPetDoc::CreateNew()
{
Assert( !m_hRoot.Get() );
// This is not undoable
CDisableUndoScopeGuard guard;
Q_strncpy( m_pFileName, "untitled", sizeof( m_pFileName ) );
// Create the main element
if ( !CreateRootElement() )
return;
SetDirty( false );
}
//-----------------------------------------------------------------------------
// Saves/loads from file
//-----------------------------------------------------------------------------
bool CPetDoc::LoadFromFile( const char *pFileName )
{
Assert( !m_hRoot.Get() );
CAppDisableUndoScopeGuard guard( "CPetDoc::LoadFromFile", NOTIFY_CHANGE_OTHER );
SetDirty( false );
if ( !pFileName[0] )
return false;
const char *pGame = Q_stristr( pFileName, "\\game\\" );
if ( !pGame )
return false;
Q_strncpy( m_pFileName, pFileName, sizeof( m_pFileName ) );
CDmElement *pRoot = NULL;
DmFileId_t fileid = g_pDataModel->RestoreFromFile( pFileName, NULL, NULL, &pRoot, CR_DELETE_OLD );
if ( fileid == DMFILEID_INVALID )
{
m_pFileName[0] = 0;
return false;
}
m_hRoot = pRoot;
// remove any null functions (eg. if a child has a bad id)
CDmrParticleSystemList defArray( m_hRoot, "particleSystemDefinitions" );
int nSystems = defArray.Count();
for ( int i = 0; i < nSystems; ++i )
{
defArray[i]->RemoveInvalidFunctions();
}
SetDirty( false );
return true;
}
void CPetDoc::SaveToFile( )
{
if ( m_hRoot.Get() && m_pFileName && m_pFileName[0] )
{
CDisableUndoScopeGuard guard;
// make a copy of the definition tree
CDmElement* pRootCopy = m_hRoot->Copy( TD_ALL );
CDmrParticleSystemList defCopyArray( pRootCopy, "particleSystemDefinitions" );
// compact the copied definitions
int nSystems = defCopyArray.Count();
for ( int i = 0; i < nSystems; ++i )
{
defCopyArray[i]->Compact();
}
// save the copy, and kill it
g_pDataModel->SaveToFile( m_pFileName, NULL, "binary", PET_FILE_FORMAT, pRootCopy );
DestroyElement( pRootCopy, TD_ALL );
}
SetDirty( false );
}
//-----------------------------------------------------------------------------
// Returns the root object
//-----------------------------------------------------------------------------
CDmElement *CPetDoc::GetRootObject()
{
return m_hRoot;
}
//-----------------------------------------------------------------------------
// Returns the root object fileid
//-----------------------------------------------------------------------------
DmFileId_t CPetDoc::GetFileId()
{
return m_hRoot.Get() ? m_hRoot->GetFileId() : DMFILEID_INVALID;
}
//-----------------------------------------------------------------------------
// Returns the particle system definition list
//-----------------------------------------------------------------------------
CDmAttribute *CPetDoc::GetParticleSystemDefinitionList()
{
CDmrElementArray<> array( m_hRoot, "particleSystemDefinitions" );
return array.GetAttribute();
}
int CPetDoc::GetParticleSystemCount( )
{
CDmrElementArray<> array( m_hRoot, "particleSystemDefinitions" );
return array.Count();
}
CDmeParticleSystemDefinition *CPetDoc::GetParticleSystem( int nIndex )
{
CDmrParticleSystemList array( m_hRoot, "particleSystemDefinitions" );
if( array.IsValid() && nIndex >= 0 && nIndex < array.Count() )
{
return array[nIndex];
}
else
{
return NULL;
}
}
void CPetDoc::AddNewParticleSystemDefinition( CDmeParticleSystemDefinition *pNew, CUndoScopeGuard &Guard )
{
CDmrParticleSystemList particleSystemList( GetParticleSystemDefinitionList() );
particleSystemList.AddToTail( pNew );
Guard.Release();
UpdateParticleDefinition( pNew );
}
//-----------------------------------------------------------------------------
// Adds a new particle system definition
//-----------------------------------------------------------------------------
CDmeParticleSystemDefinition* CPetDoc::AddNewParticleSystemDefinition( const char *pName )
{
if ( !pName || !pName[0] )
{
pName = "New Particle System";
}
CDmeParticleSystemDefinition *pParticleSystem;
{
CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG|NOTIFY_FLAG_PARTICLESYS_ADDED_OR_REMOVED, "Add Particle System", "Add Particle System" );
pParticleSystem = CreateElement<CDmeParticleSystemDefinition>( pName, GetFileId() );
AddNewParticleSystemDefinition( pParticleSystem, guard );
}
return pParticleSystem;
}
//-----------------------------------------------------------------------------
// Refresh all particle definitions
//-----------------------------------------------------------------------------
void CPetDoc::UpdateAllParticleSystems( )
{
// Force a resolve to get the particle created
g_pDmElementFramework->Operate( true );
g_pDmElementFramework->BeginEdit();
CDmrParticleSystemList particleSystemList( GetParticleSystemDefinitionList() );
int nCount = particleSystemList.Count();
for ( int i = 0; i < nCount; ++i )
{
UpdateParticleDefinition( particleSystemList[i] );
}
}
//-----------------------------------------------------------------------------
// Deletes a particle system definition
//-----------------------------------------------------------------------------
void CPetDoc::DeleteParticleSystemDefinition( CDmeParticleSystemDefinition *pParticleSystem )
{
if ( !pParticleSystem )
return;
CDmrParticleSystemList particleSystemList( GetParticleSystemDefinitionList() );
int nCount = particleSystemList.Count();
for ( int i = 0; i < nCount; ++i )
{
if ( pParticleSystem == particleSystemList[i] )
{
CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG|NOTIFY_FLAG_PARTICLESYS_ADDED_OR_REMOVED, "Delete Particle System", "Delete Particle System" );
particleSystemList.FastRemove( i );
break;
}
}
// Find all CDmeParticleChilds referring to this function
CUtlVector< CDmeParticleChild* > children;
FindAncestorsReferencingElement( pParticleSystem, children );
int nChildCount = children.Count();
for ( int i = 0; i < nChildCount; ++i )
{
CDmeParticleChild *pChildReference = children[i];
CDmeParticleSystemDefinition *pParent = FindReferringElement<CDmeParticleSystemDefinition>( pChildReference, "children" );
if ( !pParent )
continue;
pParent->RemoveFunction( FUNCTION_CHILDREN, pChildReference );
DestroyElement( pChildReference, TD_NONE );
}
DestroyElement( pParticleSystem, TD_DEEP );
}
CDmeParticleSystemDefinition *CPetDoc::FindParticleSystemDefinition( const char *pName )
{
CDmrParticleSystemList particleSystemList( GetParticleSystemDefinitionList() );
int nCount = particleSystemList.Count();
for ( int i = 0; i < nCount; ++i )
{
CDmeParticleSystemDefinition* pParticleSystem = particleSystemList[i];
if ( !Q_stricmp( pName, pParticleSystem->GetName() ) )
return pParticleSystem;
}
return NULL;
}
//-----------------------------------------------------------------------------
// Replaces a particle system definition
//-----------------------------------------------------------------------------
void CPetDoc::ReplaceParticleSystemDefinition( CDmeParticleSystemDefinition *pParticleSystem )
{
if ( !pParticleSystem )
return;
CDmrParticleSystemList particleSystemList( GetParticleSystemDefinitionList() );
int nCount = particleSystemList.Count();
int nFoundIndex = -1;
for ( int i = 0; i < nCount; ++i )
{
if ( !particleSystemList[i] )
continue;
if ( !Q_stricmp( particleSystemList[i]->GetName(), pParticleSystem->GetName() ) )
{
nFoundIndex = i;
break;
}
}
if ( nFoundIndex < 0 )
{
CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, "Replace Particle System", "Replace Particle System" );
CDmrParticleSystemList particleSystemList( GetParticleSystemDefinitionList() );
pParticleSystem->SetFileId( m_hRoot->GetFileId(), TD_ALL );
particleSystemList.AddToTail( pParticleSystem );
return;
}
CDmeParticleSystemDefinition *pOldParticleSystem = particleSystemList[nFoundIndex];
// This can happen if we unserialized w/ replace
if ( pOldParticleSystem == pParticleSystem )
return;
CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, "Replace Particle System", "Replace Particle System" );
particleSystemList.Set( nFoundIndex, pParticleSystem );
pParticleSystem->SetFileId( m_hRoot->GetFileId(), TD_ALL );
// Find all CDmeParticleChilds referring to this function
CUtlVector< CDmeParticleChild* > children;
FindAncestorsReferencingElement( pOldParticleSystem, children );
int nChildCount = children.Count();
for ( int i = 0; i < nChildCount; ++i )
{
CDmeParticleChild *pChildReference = children[i];
pChildReference->m_Child = pParticleSystem;
}
DestroyElement( pOldParticleSystem, TD_SHALLOW );
}
//-----------------------------------------------------------------------------
// Does a particle system exist already?
//-----------------------------------------------------------------------------
bool CPetDoc::IsParticleSystemDefined( const char *pName )
{
return FindParticleSystemDefinition( pName ) != NULL;
}
//-----------------------------------------------------------------------------
// Updates a specific particle defintion
//-----------------------------------------------------------------------------
void CPetDoc::UpdateParticleDefinition( CDmeParticleSystemDefinition *pDef )
{
if ( !pDef )
return;
CUtlBuffer buf;
g_pDataModel->Serialize( buf, "binary", PET_FILE_FORMAT, pDef->GetHandle() );
// Tell the game about the new definitions
if ( clienttools )
{
clienttools->ReloadParticleDefintions( GetFileName(), buf.Base(), buf.TellMaxPut() );
}
if ( servertools )
{
servertools->ReloadParticleDefintions( GetFileName(), buf.Base(), buf.TellMaxPut() );
}
// Let the other tools know
KeyValues *pMessage = new KeyValues( "ParticleSystemUpdated" );
pMessage->SetPtr( "definitionBits", buf.Base() );
pMessage->SetInt( "definitionSize", buf.TellMaxPut() );
g_pPetTool->PostMessageToAllTools( pMessage );
pMessage->deleteThis();
}
//-----------------------------------------------------------------------------
// Populate string choice lists
//-----------------------------------------------------------------------------
bool CPetDoc::GetStringChoiceList( const char *pChoiceListType, CDmElement *pElement,
const char *pAttributeName, bool bArrayElement, StringChoiceList_t &list )
{
if ( !Q_stricmp( pChoiceListType, "particleSystemDefinitions" ) )
{
CDmrParticleSystemList particleSystemList( GetParticleSystemDefinitionList() );
StringChoice_t sChoice;
sChoice.m_pValue = "";
sChoice.m_pChoiceString = "";
list.AddToTail( sChoice );
int nCount = particleSystemList.Count();
for ( int i = 0; i < nCount; ++i )
{
CDmeParticleSystemDefinition *pParticleSystem = particleSystemList[ i ];
StringChoice_t sChoice;
sChoice.m_pValue = pParticleSystem->GetName();
sChoice.m_pChoiceString = pParticleSystem->GetName();
list.AddToTail( sChoice );
}
return true;
}
return false;
}
//-----------------------------------------------------------------------------
// Populate element choice lists
//-----------------------------------------------------------------------------
bool CPetDoc::GetElementChoiceList( const char *pChoiceListType, CDmElement *pElement,
const char *pAttributeName, bool bArrayElement, ElementChoiceList_t &list )
{
if ( !Q_stricmp( pChoiceListType, "allelements" ) )
{
AddElementsRecursively( m_hRoot, list );
return true;
}
if ( !Q_stricmp( pChoiceListType, "particleSystemDefinitions" ) )
{
CDmrParticleSystemList particleSystemList( GetParticleSystemDefinitionList() );
int nCount = particleSystemList.Count();
for ( int i = 0; i < nCount; ++i )
{
CDmeParticleSystemDefinition *pParticleSystem = particleSystemList[ i ];
ElementChoice_t sChoice;
sChoice.m_pValue = pParticleSystem;
sChoice.m_pChoiceString = pParticleSystem->GetName();
list.AddToTail( sChoice );
}
return ( nCount > 0 );
}
// by default, try to treat the choice list type as a Dme element type
AddElementsRecursively( m_hRoot, list, pChoiceListType );
return list.Count() > 0;
}
//-----------------------------------------------------------------------------
// Called when data changes
//-----------------------------------------------------------------------------
void CPetDoc::OnDataChanged( const char *pReason, int nNotifySource, int nNotifyFlags )
{
SetDirty( nNotifyFlags & NOTIFY_SETDIRTYFLAG ? true : false );
m_pCallback->OnDocChanged( pReason, nNotifySource, nNotifyFlags );
}
+124
View File
@@ -0,0 +1,124 @@
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
// $NoKeywords: $
//
//===========================================================================//
#ifndef PETDOC_H
#define PETDOC_H
#ifdef _WIN32
#pragma once
#endif
#include "dme_controls/inotifyui.h"
#include "datamodel/dmehandle.h"
#include "datamodel/dmelement.h"
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class IPetDocCallback;
class CPetDoc;
class CDmeParticleSystemDefinition;
//-----------------------------------------------------------------------------
// The file format for particle system definitions
//-----------------------------------------------------------------------------
#define PET_FILE_FORMAT "pcf"
typedef CDmrElementArray<CDmeParticleSystemDefinition> CDmrParticleSystemList;
//-----------------------------------------------------------------------------
// Contains all editable state
//-----------------------------------------------------------------------------
class CPetDoc : public IDmNotify, CBaseElementPropertiesChoices
{
public:
CPetDoc( IPetDocCallback *pCallback );
~CPetDoc();
// Inherited from INotifyUI
virtual void NotifyDataChanged( const char *pReason, int nNotifySource, int nNotifyFlags );
virtual bool GetIntChoiceList( const char *pChoiceListType, CDmElement *pElement,
const char *pAttributeName, bool bArrayElement, IntChoiceList_t &list );
// Sets/Gets the file name
const char *GetFileName();
void SetFileName( const char *pFileName );
// Dirty bits (has it changed since the last time it was saved?)
void SetDirty( bool bDirty );
bool IsDirty() const;
// Creates a new document
void CreateNew();
// Saves/loads from file
bool LoadFromFile( const char *pFileName );
void SaveToFile( );
// Returns the root object
CDmElement *GetRootObject();
// Returns the root object fileid
DmFileId_t GetFileId();
// Called when data changes (see INotifyUI for flags)
void OnDataChanged( const char *pReason, int nNotifySource, int nNotifyFlags );
// Returns the particle system definition list
CDmAttribute *GetParticleSystemDefinitionList();
int GetParticleSystemCount( );
CDmeParticleSystemDefinition *GetParticleSystem( int nIndex );
// add a new definition we've created
void AddNewParticleSystemDefinition( CDmeParticleSystemDefinition *pNew,
CUndoScopeGuard &Guard );
// Adds a new particle system definition
CDmeParticleSystemDefinition *AddNewParticleSystemDefinition( const char *pName );
// Deletes a particle system definition
void DeleteParticleSystemDefinition( CDmeParticleSystemDefinition *pParticleSystem );
// find particle system def by name
CDmeParticleSystemDefinition *FindParticleSystemDefinition( const char *pName );
// Replace any particle system with the same name as the passed-in definition
// with the passed-in definition
void ReplaceParticleSystemDefinition( CDmeParticleSystemDefinition *pParticleSystem );
// Does a particle system exist already?
bool IsParticleSystemDefined( const char *pName );
// For element choice lists. Return false if it's an unknown choice list type
virtual bool GetStringChoiceList( const char *pChoiceListType, CDmElement *pElement,
const char *pAttributeName, bool bArrayElement, StringChoiceList_t &list );
virtual bool GetElementChoiceList( const char *pChoiceListType, CDmElement *pElement,
const char *pAttributeName, bool bArrayElement, ElementChoiceList_t &list );
// Updates a specific particle defintion
void UpdateParticleDefinition( CDmeParticleSystemDefinition *pDef );
// Update all particle definitions
void UpdateAllParticleSystems( );
private:
// Creates the root element
bool CreateRootElement();
IPetDocCallback *m_pCallback;
CDmeHandle< CDmElement > m_hRoot;
char m_pFileName[MAX_PATH];
bool m_bDirty;
};
#endif // PETDOC_H
File diff suppressed because it is too large Load Diff
+223
View File
@@ -0,0 +1,223 @@
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======
//
// Purpose: P.E.T. (Particle Editing Tool); main UI smarts class
//
//=============================================================================
#ifndef PETTOOL_H
#define PETTOOL_H
#ifdef _WIN32
#pragma once
#endif
#include "tier0/platform.h"
#include "toolutils/basetoolsystem.h"
#include "toolutils/recentfilelist.h"
#include "toolutils/toolmenubar.h"
#include "toolutils/toolswitchmenubutton.h"
#include "toolutils/tooleditmenubutton.h"
#include "toolutils/toolfilemenubutton.h"
#include "toolutils/toolmenubutton.h"
#include "datamodel/dmelement.h"
#include "datamodel/dmehandle.h"
#include "toolframework/ienginetool.h"
#include "toolutils/enginetools_int.h"
#include "toolutils/savewindowpositions.h"
#include "toolutils/toolwindowfactory.h"
#include "movieobjects/dmeparticlesystemdefinition.h"
#include "particles/particles.h"
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class CDmElement;
class CPetDoc;
class CParticleSystemPropertiesContainer;
class CParticleSystemDefinitionBrowser;
class CParticleSystemPreviewPanel;
class CSheetEditorPanel;
class CDmeParticleSystemDefinition;
enum ParticleFunctionType_t;
namespace vgui
{
class Panel;
}
enum
{
NOTIFY_FLAG_PARTICLESYS_ADDED_OR_REMOVED = (1<<NOTIFY_FLAG_FIRST_APPLICATION_BIT)
};
//-----------------------------------------------------------------------------
// Allows the doc to call back into the CommEdit editor tool
//-----------------------------------------------------------------------------
abstract_class IPetDocCallback
{
public:
// Called by the doc when the data changes
virtual void OnDocChanged( const char *pReason, int nNotifySource, int nNotifyFlags ) = 0;
};
//-----------------------------------------------------------------------------
// Global methods of the commedit tool
//-----------------------------------------------------------------------------
abstract_class IPetTool
{
public:
// Gets at the rool panel (for modal dialogs)
virtual vgui::Panel *GetRootPanel() = 0;
// Gets the registry name (for saving settings)
virtual const char *GetRegistryName() = 0;
};
//-----------------------------------------------------------------------------
// Implementation of the CommEdit tool
//-----------------------------------------------------------------------------
class CPetTool : public CBaseToolSystem, public IFileMenuCallbacks, public IPetDocCallback, public IPetTool
{
DECLARE_CLASS_SIMPLE( CPetTool, CBaseToolSystem );
public:
CPetTool();
// Inherited from IToolSystem
virtual const char *GetToolName() { return "Particle Editor"; }
virtual bool Init( );
virtual void Shutdown();
virtual bool CanQuit( const char *pExitMsg );
virtual void OnToolActivate();
virtual void OnToolDeactivate();
virtual void Think( bool finalTick );
// Inherited from IFileMenuCallbacks
virtual int GetFileMenuItemsEnabled( );
virtual void AddRecentFilesToMenu( vgui::Menu *menu );
virtual bool GetPerforceFileName( char *pFileName, int nMaxLen );
// Inherited from IPetDocCallback
virtual void OnDocChanged( const char *pReason, int nNotifySource, int nNotifyFlags );
virtual vgui::Panel *GetRootPanel() { return this; }
// Inherited from CBaseToolSystem
virtual vgui::HScheme GetToolScheme();
virtual vgui::Menu *CreateActionMenu( vgui::Panel *pParent );
virtual void OnCommand( const char *cmd );
virtual const char *GetRegistryName() { return "PetTool"; }
virtual const char *GetBindingsContextFile() { return "cfg/Pet.kb"; }
virtual vgui::MenuBar *CreateMenuBar( CBaseToolSystem *pParent );
MESSAGE_FUNC( Save, "OnSave" );
void SaveAndTest();
void PreOperatorsPaste();
public:
MESSAGE_FUNC( OnRestartLevel, "RestartLevel" );
MESSAGE_FUNC( OnNew, "OnNew" );
MESSAGE_FUNC( OnOpen, "OnOpen" );
MESSAGE_FUNC( OnSaveAs, "OnSaveAs" );
MESSAGE_FUNC( OnClose, "OnClose" );
MESSAGE_FUNC( OnCloseNoSave, "OnCloseNoSave" );
MESSAGE_FUNC( OnMarkNotDirty, "OnMarkNotDirty" );
MESSAGE_FUNC( OnExit, "OnExit" );
MESSAGE_FUNC( OnCopySystems, "OnCopySystems" );
MESSAGE_FUNC( OnCopyFunctions, "OnCopyFunctions" );
MESSAGE_FUNC( OnPaste, "OnPaste" );
MESSAGE_FUNC( OnRequestPaste, "RequestPaste" );
// Commands related to the edit menu
void OnDescribeUndo();
// Methods related to the view menu
MESSAGE_FUNC( OnToggleProperties, "OnToggleProperties" );
MESSAGE_FUNC( OnToggleParticleSystemBrowser, "OnToggleParticleSystemBrowser" );
MESSAGE_FUNC( OnToggleParticlePreview, "OnToggleParticlePreview" );
// MESSAGE_FUNC( OnToggleSheetEditor, "OnToggleSheetEditor" );
MESSAGE_FUNC( OnDefaultLayout, "OnDefaultLayout" );
// Keybindings
KEYBINDING_FUNC( undo, KEY_Z, vgui::MODIFIER_CONTROL, OnUndo, "#undo_help", 0 );
KEYBINDING_FUNC( redo, KEY_Z, vgui::MODIFIER_CONTROL | vgui::MODIFIER_SHIFT, OnRedo, "#redo_help", 0 );
KEYBINDING_FUNC_NODECLARE( edit_paste, KEY_V, vgui::MODIFIER_CONTROL, OnPaste, "#edit_paste_help", 0 );
void PerformNew();
void OpenFileFromHistory( int slot );
void OpenSpecificFile( const char *pFileName );
virtual void SetupFileOpenDialog( vgui::FileOpenDialog *pDialog, bool bOpenFile, const char *pFileFormat, KeyValues *pContextKeyValues );
virtual bool OnReadFileFromDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues );
virtual bool OnWriteFileToDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues );
virtual void OnFileOperationCompleted( const char *pFileType, bool bWroteFile, vgui::FileOpenStateMachine::CompletionState_t state, KeyValues *pContextKeyValues );
// returns the document
CPetDoc *GetDocument();
// Gets at tool windows
CParticleSystemPropertiesContainer *GetProperties();
CParticleSystemDefinitionBrowser *GetParticleSystemDefinitionBrowser();
CParticleSystemPreviewPanel *GetParticlePreview();
// CSheetEditorPanel *GetSheetEditor();
void SetCurrentParticleSystem( CDmeParticleSystemDefinition *pParticleSystem, bool bForceBrowserSelection = true );
CDmeParticleSystemDefinition* GetCurrentParticleSystem( void );
private:
// Creates a new document
void NewDocument( );
// Loads up a new document
bool LoadDocument( const char *pDocName );
// Updates the menu bar based on the current file
void UpdateMenuBar( );
virtual const char *GetLogoTextureName();
// Creates, destroys tools
void CreateTools( CPetDoc *doc );
void DestroyTools();
// Initializes the tools
void InitTools();
// Shows, toggles tool windows
void ToggleToolWindow( Panel *tool, char const *toolName );
void ShowToolWindow( Panel *tool, char const *toolName, bool visible );
// Kills all tool windows
void DestroyToolContainers();
private:
// Document
CPetDoc *m_pDoc;
// The menu bar
CToolFileMenuBar *m_pMenuBar;
// Element properties for editing material
vgui::DHANDLE< CParticleSystemPropertiesContainer > m_hProperties;
// The entity report
vgui::DHANDLE< CParticleSystemDefinitionBrowser > m_hParticleSystemDefinitionBrowser;
// Particle preview window
vgui::DHANDLE< CParticleSystemPreviewPanel > m_hParticlePreview;
// Sheet editor
// vgui::DHANDLE< CSheetEditorPanel > m_hSheetEditorPanel;
// The currently viewed entity
CDmeHandle< CDmeParticleSystemDefinition > m_hCurrentParticleSystem;
// Separate undo context for the act busy tool
CToolWindowFactory< ToolWindow > m_ToolWindowFactory;
};
extern CPetTool *g_pPetTool;
#endif // PETTOOL_H
File diff suppressed because it is too large Load Diff
+45
View File
@@ -0,0 +1,45 @@
//===== Copyright © 1996-2006, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
// $NoKeywords: $
//===========================================================================//
#include "toolutils/ConsolePage.h"
#include "toolutils/enginetools_int.h"
#include "toolframework/ienginetool.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CConsolePage::CConsolePage( Panel *parent, bool bStatusVersion ) : BaseClass( parent, "ToolsConsole", bStatusVersion )
{
AddActionSignalTarget( this );
}
//-----------------------------------------------------------------------------
// Submits a command
//-----------------------------------------------------------------------------
void CConsolePage::OnCommandSubmitted( const char *pCommand )
{
enginetools->Command( pCommand );
}
//-----------------------------------------------------------------------------
// Purpose: sets up colors
//-----------------------------------------------------------------------------
void CConsolePage::ApplySchemeSettings(IScheme *pScheme)
{
BaseClass::ApplySchemeSettings(pScheme);
m_PrintColor = GetSchemeColor("IFMConsole.TextColor", pScheme);
m_DPrintColor = GetSchemeColor("IFMConsole.DevTextColor", pScheme);
}
+336
View File
@@ -0,0 +1,336 @@
//===== Copyright © 1996-2009, Valve Corporation, All rights reserved. ========
//
// Purpose: Implementation of the CScriptEditorPanel class and associated helper
// classes. The ScriptEditorPanel class represents a vgui panel which contains
// a text editing panel which may be used to edit a script and text panel which
// displays output from the script.
//
//=============================================================================
#include "toolutils/scripteditorpanel.h"
#include "vgui/iinput.h"
#include "vgui/ischeme.h"
#include "vgui/ivgui.h"
#include "vgui/isurface.h"
#include "vgui_controls/button.h"
#include "vgui_controls/textentry.h"
#include "vgui_controls/richtext.h"
#include "tier1/utlbuffer.h"
#include "vgui/ilocalize.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CLineNumberPanel::CLineNumberPanel( vgui::Panel *pParent, vgui::TextEntry *pTextEntry, const char *pchName )
: BaseClass( pParent, pchName )
, m_pTextEntry( pTextEntry )
, m_hFont( NULL )
{
}
//-----------------------------------------------------------------------------
// Purpose: Paint the background of the panel, including the line numbers
//-----------------------------------------------------------------------------
void CLineNumberPanel::PaintBackground()
{
BaseClass::PaintBackground();
Panel *pParent = GetParent();
if ( pParent )
{
if ( pParent->IsVisible() == false )
return;
}
int width, height;
GetSize( width, height );
int fontHeight = surface()->GetFontTall( m_hFont );
int yPos = 1;
int line = m_pTextEntry->GetCurrentStartLine() + 1;
surface()->DrawSetTextFont( m_hFont );
surface()->DrawSetTextColor( m_Color );
while ( (yPos + fontHeight) < height )
{
wchar_t sz[ 32 ];
_snwprintf( sz, sizeof( sz ), L"%4i", line );
surface()->DrawSetTextPos( 0, yPos );
surface()->DrawPrintText( sz, wcslen( sz ) );
yPos += fontHeight + 1;
++line;
}
}
//-----------------------------------------------------------------------------
// Purpose: Apply the settings from the provided scheme, and save the font to
// display line numbers.
//-----------------------------------------------------------------------------
void CLineNumberPanel::ApplySchemeSettings(IScheme *pScheme)
{
BaseClass::ApplySchemeSettings(pScheme);
m_hFont = pScheme->GetFont( "ConsoleText", IsProportional() );
m_Color = GetSchemeColor( "Console.TextColor", pScheme );
}
//-----------------------------------------------------------------------------
// Purpose: Constructor, creates all of the controls owned by the panel.
//-----------------------------------------------------------------------------
CScriptEditorPanel::CScriptEditorPanel( vgui::Panel *pParent, const char *pName )
: BaseClass( pParent, pName )
{
SetKeyBoardInputEnabled( true );
SetMinimumSize(300,200);
// Create the output panel
m_pOutput = new RichText(this, "ConsoleHistory");
m_pOutput->SetAllowKeyBindingChainToParent( false );
SETUP_PANEL( m_pOutput );
m_pOutput->SetVerticalScrollbar( true );
m_pOutput->GotoTextEnd();
// Create the submit button
m_pSubmit = new Button(this, "ConsoleSubmit", "#Console_Submit");
m_pSubmit->SetCommand("submit");
m_pSubmit->SetVisible( true );
// Create the script entry panel
m_pScriptEntry = new TextEntry(this, "ScriptEntry" );
m_pScriptEntry->AddActionSignalTarget(this);
m_pScriptEntry->SetMultiline( true );
m_pScriptEntry->SetVerticalScrollbar( true );
m_pScriptEntry->SetCatchEnterKey( true );
m_pScriptEntry->SetCatchTabKey( true );
m_pScriptEntry->SendNewLine( true );
m_pScriptEntry->SetTabPosition(1);
// Create the line number display panel
m_pLineNumberPanel = new CLineNumberPanel( this, m_pScriptEntry, "ScriptLineNumbers" );
// Set the default text colors, these will be overridden by ApplySchemeSettings
m_PrintColor = Color(216, 222, 211, 255);
m_DPrintColor = Color(196, 181, 80, 255);
// Add to global console list so the the console
// output will be displayed in the output panel.
g_pCVar->InstallConsoleDisplayFunc( this );
}
//-----------------------------------------------------------------------------
// Purpose: Destructor, removes the output from the global console list and
// destroys the controls.
//-----------------------------------------------------------------------------
CScriptEditorPanel::~CScriptEditorPanel()
{
// Remove from the global console list
g_pCVar->RemoveConsoleDisplayFunc( this );
// Destroy the controls
delete m_pOutput;
m_pOutput = NULL;
delete m_pSubmit;
m_pSubmit = NULL;
delete m_pScriptEntry;
m_pScriptEntry = NULL;
delete m_pLineNumberPanel;
m_pLineNumberPanel = NULL;
}
//-----------------------------------------------------------------------------
// Purpose: Clears the output console
//-----------------------------------------------------------------------------
void CScriptEditorPanel::Clear()
{
m_pOutput->SetText("");
m_pOutput->GotoTextEnd();
}
//-----------------------------------------------------------------------------
// Purpose: color text print
//-----------------------------------------------------------------------------
void CScriptEditorPanel::ColorPrint( const Color& clr, const char *msg )
{
m_pOutput->InsertColorChange( clr );
m_pOutput->InsertString( msg );
}
//-----------------------------------------------------------------------------
// Purpose: normal text print
//-----------------------------------------------------------------------------
void CScriptEditorPanel::Print(const char *msg)
{
ColorPrint( m_PrintColor, msg );
}
//-----------------------------------------------------------------------------
// Purpose: debug text print
//-----------------------------------------------------------------------------
void CScriptEditorPanel::DPrint( const char *msg )
{
ColorPrint( m_DPrintColor, msg );
}
//-----------------------------------------------------------------------------
// Returns the console text
//-----------------------------------------------------------------------------
void CScriptEditorPanel::GetConsoleText( char *pchText, size_t bufSize ) const
{
wchar_t *temp = new wchar_t[ bufSize ];
m_pScriptEntry->GetText( temp, bufSize * sizeof( wchar_t ) );
g_pVGuiLocalize->ConvertUnicodeToANSI( temp, pchText, bufSize );
delete[] temp;
}
//-----------------------------------------------------------------------------
// Purpose: Called whenever the user types text
//-----------------------------------------------------------------------------
void CScriptEditorPanel::OnTextChanged(Panel *panel)
{
if (panel != m_pScriptEntry)
return;
RequestFocus();
m_pScriptEntry->RequestFocus();
}
//-----------------------------------------------------------------------------
// Purpose: generic vgui command handler
//-----------------------------------------------------------------------------
void CScriptEditorPanel::OnCommand(const char *command)
{
if ( !Q_stricmp( command, "Submit" ) )
{
// always go the end of the buffer when the user has typed something
m_pOutput->GotoTextEnd();
// Get the text from the script entry and store in a single string.
int textLength = m_pScriptEntry->GetTextLength() + 2;
CUtlBuffer scriptBuffer( 0, textLength, CUtlBuffer::TEXT_BUFFER );
m_pScriptEntry->GetText( (char*)scriptBuffer.Base(), scriptBuffer.Size() );
// Run the script
RunScript( scriptBuffer );
}
else
{
BaseClass::OnCommand(command);
}
}
//-----------------------------------------------------------------------------
// Purpose: Run the specified script
//-----------------------------------------------------------------------------
void CScriptEditorPanel::RunScript( const CUtlBuffer& scriptBuffer )
{
// No script execution exists at this level, derived classes should
// override this function to execute scripts.
}
//-----------------------------------------------------------------------------
// Purpose: Determine of the script entry panel has the current focus
//-----------------------------------------------------------------------------
bool CScriptEditorPanel::TextEntryHasFocus() const
{
return ( input()->GetFocus() == m_pScriptEntry->GetVPanel() );
}
//-----------------------------------------------------------------------------
// Purpose: Request that the script entry panel receive the input focus
//-----------------------------------------------------------------------------
void CScriptEditorPanel::TextEntryRequestFocus()
{
m_pScriptEntry->RequestFocus();
}
//-----------------------------------------------------------------------------
// Purpose: Lays out the controls within the panel
//-----------------------------------------------------------------------------
void CScriptEditorPanel::PerformLayout()
{
BaseClass::PerformLayout();
// setup tab ordering
GetFocusNavGroup().SetDefaultButton(m_pSubmit);
IScheme *pScheme = scheme()->GetIScheme( GetScheme() );
m_pScriptEntry->SetBorder(pScheme->GetBorder("DepressedButtonBorder"));
m_pOutput->SetBorder(pScheme->GetBorder("DepressedButtonBorder"));
// layout controls
int wide, tall;
GetSize(wide, tall);
const int lineNumberWidth = 24;
const int inset = 8;
const int topHeight = 4;
const int entryInset = 4;
const int submitWide = 64;
const int submitHeight = 20;
const int submitInset = 7; // x inset to pull the submit button away from the frame grab
const int editHeight = ( tall - ( submitHeight + topHeight + (inset * 4 ) ) ) / 2;
m_pOutput->SetPos(inset, inset + topHeight);
m_pOutput->SetSize(wide - (inset * 2), editHeight );
m_pOutput->InvalidateLayout();
int nSubmitXPos = wide - ( inset + submitWide + submitInset );
m_pSubmit->SetPos( nSubmitXPos, tall - (entryInset * 2 + submitHeight ));
m_pSubmit->SetSize( submitWide, submitHeight );
int nScriptEntryYPos = topHeight + ( inset * 2 ) + editHeight;
m_pScriptEntry->SetPos( ( inset * 2 ) + lineNumberWidth, nScriptEntryYPos );
m_pScriptEntry->SetSize( wide - ( (inset * 3) + lineNumberWidth ), editHeight );
m_pLineNumberPanel->SetPos( inset, nScriptEntryYPos );
m_pLineNumberPanel->SetSize( lineNumberWidth, editHeight );
}
//-----------------------------------------------------------------------------
// Purpose: Apply the color, font, and size settings from the specified scheme
//-----------------------------------------------------------------------------
void CScriptEditorPanel::ApplySchemeSettings( IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
m_PrintColor = GetSchemeColor( "Console.TextColor", pScheme );
m_DPrintColor = GetSchemeColor( "Console.DevTextColor", pScheme );
m_pOutput->SetFont( pScheme->GetFont( "ConsoleText", IsProportional() ) );
m_pScriptEntry->SetFont( pScheme->GetFont( "ConsoleText", IsProportional() ) );
InvalidateLayout();
}
+248
View File
@@ -0,0 +1,248 @@
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======
//
// Standard file menu
//
//=============================================================================
#include "toolutils/toolfilemenubutton.h"
#include "toolutils/toolmenubutton.h"
#include "tier1/keyvalues.h"
#include "tier1/utlstring.h"
#include "vgui_controls/menu.h"
#include "vgui_controls/frame.h"
#include "vgui_controls/button.h"
#include "vgui_controls/listpanel.h"
#include "toolutils/enginetools_int.h"
#include "p4lib/ip4.h"
#include "vgui_controls/perforcefilelistframe.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
//-----------------------------------------------------------------------------
// Global function to create the file menu
//-----------------------------------------------------------------------------
CToolMenuButton* CreateToolFileMenuButton( vgui::Panel *parent, const char *panelName,
const char *text, vgui::Panel *pActionTarget, IFileMenuCallbacks *pCallbacks )
{
return new CToolFileMenuButton( parent, panelName, text, pActionTarget, pCallbacks );
}
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CToolFileMenuButton::CToolFileMenuButton( vgui::Panel *pParent, const char *panelName, const char *text, vgui::Panel *pActionSignalTarget, IFileMenuCallbacks *pFileMenuCallback ) :
BaseClass( pParent, panelName, text, pActionSignalTarget ), m_pFileMenuCallback( pFileMenuCallback )
{
Assert( pFileMenuCallback );
AddMenuItem( "new", "#ToolFileNew", new KeyValues( "OnNew" ), pActionSignalTarget, NULL, "file_new" );
AddMenuItem( "open", "#ToolFileOpen", new KeyValues( "OnOpen" ), pActionSignalTarget, NULL, "file_open" );
AddMenuItem( "save", "#ToolFileSave", new KeyValues( "OnSave" ), pActionSignalTarget, NULL, "file_save" );
AddMenuItem( "saveas", "#ToolFileSaveAs", new KeyValues( "OnSaveAs" ), pActionSignalTarget );
AddMenuItem( "close", "#ToolFileClose", new KeyValues( "OnClose" ), pActionSignalTarget );
AddSeparator();
// Add the Perforce menu options only if there is a valid P4 interface (SDK users won't have this)
if ( p4 )
{
m_pPerforce = new vgui::Menu( this, "Perforce" );
m_pMenu->AddCascadingMenuItem( "#ToolPerforce", this, m_pPerforce );
m_nPerforceAdd = m_pPerforce->AddMenuItem( "perforce_add", "#ToolPerforceAdd", new KeyValues( "OnPerforceAdd" ), this );
m_nPerforceOpen = m_pPerforce->AddMenuItem( "perforce_open", "#ToolPerforceOpen", new KeyValues( "OnPerforceOpen" ), this );
m_nPerforceRevert = m_pPerforce->AddMenuItem( "perforce_revert", "#ToolPerforceRevert", new KeyValues( "OnPerforceRevert" ), this );
m_nPerforceSubmit = m_pPerforce->AddMenuItem( "perforce_submit", "#ToolPerforceSubmit", new KeyValues( "OnPerforceSubmit" ), this );
m_pPerforce->AddSeparator();
m_nPerforceP4Win = m_pPerforce->AddMenuItem( "perforce_p4win", "#ToolPerforceP4Win", new KeyValues( "OnPerforceP4Win" ), this );
m_nPerforceListOpenFiles = m_pPerforce->AddMenuItem( "perforce_listopenfiles", "#ToolPerforceListOpenFiles", new KeyValues( "OnPerforceListOpenFiles" ), this );
}
m_pRecentFiles = new vgui::Menu( this, "RecentFiles" );
m_nRecentFiles = m_pMenu->AddCascadingMenuItem( "#ToolFileRecent", pActionSignalTarget, m_pRecentFiles );
AddSeparator();
AddMenuItem( "exit", "#ToolFileExit", new KeyValues ( "OnExit" ), pActionSignalTarget );
SetMenu( m_pMenu );
}
//-----------------------------------------------------------------------------
// Gets called when the menu is shown
//-----------------------------------------------------------------------------
void CToolFileMenuButton::OnShowMenu( vgui::Menu *menu )
{
BaseClass::OnShowMenu( menu );
// Update the menu
int nEnableMask = m_pFileMenuCallback->GetFileMenuItemsEnabled();
int id = m_Items.Find( "new" );
SetItemEnabled( id, (nEnableMask & IFileMenuCallbacks::FILE_NEW) != 0 );
id = m_Items.Find( "open" );
SetItemEnabled( id, (nEnableMask & IFileMenuCallbacks::FILE_OPEN) != 0 );
id = m_Items.Find( "save" );
SetItemEnabled( id, (nEnableMask & IFileMenuCallbacks::FILE_SAVE) != 0 );
id = m_Items.Find( "saveas" );
SetItemEnabled( id, (nEnableMask & IFileMenuCallbacks::FILE_SAVEAS) != 0 );
id = m_Items.Find( "close" );
SetItemEnabled( id, (nEnableMask & IFileMenuCallbacks::FILE_CLOSE) != 0 );
m_pRecentFiles->DeleteAllItems();
if ( (nEnableMask & IFileMenuCallbacks::FILE_RECENT) == 0 )
{
m_pMenu->SetItemEnabled( m_nRecentFiles, false );
}
else
{
m_pMenu->SetItemEnabled( m_nRecentFiles, true );
m_pFileMenuCallback->AddRecentFilesToMenu( m_pRecentFiles );
}
// We only have the Perforce menu items if we have valid p4 interface
if ( p4 )
{
bool bP4Connected = p4->IsConnectedToServer( false );
char pPerforceFile[MAX_PATH];
if ( bP4Connected && m_pFileMenuCallback->GetPerforceFileName( pPerforceFile, sizeof(pPerforceFile) ) )
{
bool bIsUnnamed = !Q_IsAbsolutePath( pPerforceFile );
bool bOpenedForEdit = p4->GetFileState( pPerforceFile ) != P4FILE_UNOPENED;
bool bFileInPerforce = p4->IsFileInPerforce( pPerforceFile );
m_pPerforce->SetItemEnabled( m_nPerforceAdd, !bIsUnnamed && !bFileInPerforce && !bOpenedForEdit );
m_pPerforce->SetItemEnabled( m_nPerforceOpen, !bIsUnnamed && bFileInPerforce && !bOpenedForEdit );
m_pPerforce->SetItemEnabled( m_nPerforceRevert, !bIsUnnamed && bOpenedForEdit );
m_pPerforce->SetItemEnabled( m_nPerforceSubmit, !bIsUnnamed && bOpenedForEdit );
m_pPerforce->SetItemEnabled( m_nPerforceP4Win, !bIsUnnamed && bFileInPerforce || bOpenedForEdit );
m_pPerforce->SetItemEnabled( m_nPerforceListOpenFiles, true );
}
else
{
m_pPerforce->SetItemEnabled( m_nPerforceAdd, false );
m_pPerforce->SetItemEnabled( m_nPerforceOpen, false );
m_pPerforce->SetItemEnabled( m_nPerforceRevert, false );
m_pPerforce->SetItemEnabled( m_nPerforceSubmit, false );
m_pPerforce->SetItemEnabled( m_nPerforceP4Win, false );
m_pPerforce->SetItemEnabled( m_nPerforceListOpenFiles, bP4Connected );
}
}
}
//-----------------------------------------------------------------------------
// Perforce functions
//-----------------------------------------------------------------------------
void CToolFileMenuButton::OnPerforceAdd( )
{
char pPerforceFile[MAX_PATH];
if ( m_pFileMenuCallback->GetPerforceFileName( pPerforceFile, sizeof(pPerforceFile) ) )
{
CPerforceFileListFrame *pPerforceFrame = new CPerforceFileListFrame( m_pFileMenuCallback->GetRootPanel(), "Add Movie File to Perforce?", "Movie File", PERFORCE_ACTION_FILE_ADD );
pPerforceFrame->AddFile( pPerforceFile );
pPerforceFrame->DoModal( );
}
}
//-----------------------------------------------------------------------------
// Check out a file
//-----------------------------------------------------------------------------
void CToolFileMenuButton::OnPerforceOpen( )
{
char pPerforceFile[MAX_PATH];
if ( m_pFileMenuCallback->GetPerforceFileName( pPerforceFile, sizeof(pPerforceFile) ) )
{
CPerforceFileListFrame *pPerforceFrame = new CPerforceFileListFrame( m_pFileMenuCallback->GetRootPanel(), "Check Out Movie File from Perforce?", "Movie File", PERFORCE_ACTION_FILE_EDIT );
pPerforceFrame->AddFile( pPerforceFile );
pPerforceFrame->DoModal( );
}
}
//-----------------------------------------------------------------------------
// Revert a file
//-----------------------------------------------------------------------------
void CToolFileMenuButton::OnPerforceRevert( )
{
char pPerforceFile[MAX_PATH];
if ( m_pFileMenuCallback->GetPerforceFileName( pPerforceFile, sizeof(pPerforceFile) ) )
{
CPerforceFileListFrame *pPerforceFrame = new CPerforceFileListFrame( m_pFileMenuCallback->GetRootPanel(), "Revert Movie File Changes from Perforce?", "Movie File", PERFORCE_ACTION_FILE_REVERT );
pPerforceFrame->AddFile( pPerforceFile );
pPerforceFrame->DoModal( );
}
}
//-----------------------------------------------------------------------------
// Submit a file
//-----------------------------------------------------------------------------
void CToolFileMenuButton::OnPerforceSubmit( )
{
char pPerforceFile[MAX_PATH];
if ( m_pFileMenuCallback->GetPerforceFileName( pPerforceFile, sizeof(pPerforceFile) ) )
{
CPerforceFileListFrame *pPerforceFrame = new CPerforceFileListFrame( m_pFileMenuCallback->GetRootPanel(), "Submit Movie File Changes to Perforce?", "Movie File", PERFORCE_ACTION_FILE_SUBMIT );
pPerforceFrame->AddFile( pPerforceFile );
pPerforceFrame->DoModal( );
}
}
//-----------------------------------------------------------------------------
// Open a file in p4win
//-----------------------------------------------------------------------------
void CToolFileMenuButton::OnPerforceP4Win( )
{
char pPerforceFile[MAX_PATH];
if ( m_pFileMenuCallback->GetPerforceFileName( pPerforceFile, sizeof(pPerforceFile) ) )
{
if ( p4->IsFileInPerforce( pPerforceFile ) )
{
p4->OpenFileInP4Win( pPerforceFile );
}
}
}
//-----------------------------------------------------------------------------
// Show a file in p4win
//-----------------------------------------------------------------------------
void CToolFileMenuButton::OnPerforceListOpenFiles( )
{
CUtlVector<P4File_t> openedFiles;
p4->GetOpenedFileListInPath( "GAME", openedFiles );
COperationFileListFrame *pOpenedFiles = new COperationFileListFrame( m_pFileMenuCallback->GetRootPanel(), "Opened Files In Perforce", "File Name", false, true );
int nCount = openedFiles.Count();
for ( int i = 0; i < nCount; ++i )
{
const char *pOpenType = NULL;
switch( openedFiles[i].m_eOpenState )
{
case P4FILE_OPENED_FOR_ADD:
pOpenType = "Add";
break;
case P4FILE_OPENED_FOR_EDIT:
pOpenType = "Edit";
break;
case P4FILE_OPENED_FOR_DELETE:
pOpenType = "Delete";
break;
case P4FILE_OPENED_FOR_INTEGRATE:
pOpenType = "Integrate";
break;
}
if ( pOpenType )
{
pOpenedFiles->AddOperation( pOpenType, p4->String( openedFiles[i].m_sLocalFile ) );
}
}
pOpenedFiles->DoModal( );
}
+60
View File
@@ -0,0 +1,60 @@
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======
//
// Purpose: Core Movie Maker UI API
//
//=============================================================================
#include "toolutils/toolswitchmenubutton.h"
#include "vgui_controls/panel.h"
#include "toolutils/toolmenubutton.h"
#include "toolutils/enginetools_int.h"
#include "tier1/keyvalues.h"
#include "vgui_controls/menu.h"
#include "vgui/ILocalize.h"
#include "toolframework/ienginetool.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
//-----------------------------------------------------------------------------
// Menu to switch between tools
//-----------------------------------------------------------------------------
class CToolHelpMenuButton : public CToolMenuButton
{
DECLARE_CLASS_SIMPLE( CToolHelpMenuButton, CToolMenuButton );
public:
CToolHelpMenuButton( char const *toolName, char const *helpBinding, vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionTarget );
};
//-----------------------------------------------------------------------------
// Global function to create the help menu
//-----------------------------------------------------------------------------
CToolMenuButton* CreateToolHelpMenuButton( char const *toolName, char const *helpBinding, vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionTarget )
{
return new CToolHelpMenuButton( toolName, helpBinding, parent, panelName, text, pActionTarget );
}
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CToolHelpMenuButton::CToolHelpMenuButton( char const *toolName, char const *helpBinding, vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionTarget ) :
BaseClass( parent, panelName, text, pActionTarget )
{
wchar_t *fmt = g_pVGuiLocalize->Find( "ToolHelpShowHelp" );
if ( fmt )
{
wchar_t desc[ 256 ];
g_pVGuiLocalize->ConvertANSIToUnicode( toolName, desc, sizeof( desc ) );
wchar_t buf[ 512 ];
g_pVGuiLocalize->ConstructString( buf, sizeof( buf ), fmt, 1, desc );
AddMenuItem( "help", buf, new KeyValues( "OnHelp" ), pActionTarget, NULL, helpBinding );
}
SetMenu(m_pMenu);
}
+190
View File
@@ -0,0 +1,190 @@
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======
//
// Purpose: Core Movie Maker UI API
//
//=============================================================================
#include "toolutils/toolmenubutton.h"
#include "toolutils/toolmenubar.h"
#include "toolutils/basetoolsystem.h"
#include "vgui_controls/menu.h"
#include "vgui_controls/KeyBindingMap.h"
#include "vgui/ILocalize.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CToolMenuButton::CToolMenuButton( Panel *parent, const char *panelName, const char *text, Panel *actionTarget ) :
BaseClass( parent, panelName, text ),
m_pActionTarget( actionTarget )
{
m_pMenu = new Menu( this, "Menu" );
}
void CToolMenuButton::Reset()
{
m_Items.RemoveAll();
m_pMenu->DeleteAllItems();
}
int CToolMenuButton::AddMenuItem( char const *itemName, const char *itemText, KeyValues *message, Panel *target, const KeyValues *userData /*= NULL*/, char const *kbcommandname /*= NULL*/ )
{
int id = m_pMenu->AddMenuItem(itemText, message, target, userData);
MenuItem_t item;
item.m_ItemID = id;
if ( kbcommandname )
{
item.m_KeyBinding = kbcommandname;
}
m_Items.Insert( itemName, item );
return id;
}
int CToolMenuButton::AddCheckableMenuItem( char const *itemName, const char *itemText, KeyValues *message, Panel *target, const KeyValues *userData /*= NULL*/, char const *kbcommandname /*= NULL*/ )
{
int id = m_pMenu->AddCheckableMenuItem(itemText, message, target, userData);
MenuItem_t item;
item.m_ItemID = id;
if ( kbcommandname )
{
item.m_KeyBinding = kbcommandname;
}
m_Items.Insert( itemName, item );
return id;
}
int CToolMenuButton::AddMenuItem( char const *itemName, const wchar_t *itemText, KeyValues *message, Panel *target, const KeyValues *userData /*= NULL*/, char const *kbcommandname /*= NULL*/ )
{
int id = m_pMenu->AddMenuItem(itemName, itemText, message, target, userData);
MenuItem_t item;
item.m_ItemID = id;
if ( kbcommandname )
{
item.m_KeyBinding = kbcommandname;
}
m_Items.Insert( itemName, item );
return id;
}
int CToolMenuButton::AddCheckableMenuItem( char const *itemName, const wchar_t *itemText, KeyValues *message, Panel *target, const KeyValues *userData /*= NULL*/, char const *kbcommandname /*= NULL*/ )
{
int id = m_pMenu->AddCheckableMenuItem(itemName, itemText, message, target, userData);
MenuItem_t item;
item.m_ItemID = id;
if ( kbcommandname )
{
item.m_KeyBinding = kbcommandname;
}
m_Items.Insert( itemName, item );
return id;
}
void CToolMenuButton::AddSeparator()
{
m_pMenu->AddSeparator();
}
void CToolMenuButton::SetItemEnabled( int itemID, bool state )
{
m_pMenu->SetItemEnabled( m_Items[ itemID ].m_ItemID, state );
}
int CToolMenuButton::FindMenuItem( char const *itemName )
{
int id = m_Items.Find( itemName );
if ( id == m_Items.InvalidIndex() )
return -1;
return m_Items[ id ].m_ItemID;
}
MenuItem *CToolMenuButton::GetMenuItem( int itemID )
{
return m_pMenu->GetMenuItem( itemID );
}
void CToolMenuButton::AddSeparatorAfterItem( char const *itemName )
{
int id = FindMenuItem( itemName );
if ( id != -1 )
{
m_pMenu->AddSeparatorAfterItem( id );
}
}
void CToolMenuButton::MoveMenuItem( int itemID, int moveBeforeThisItemID )
{
m_pMenu->MoveMenuItem( itemID, moveBeforeThisItemID );
}
void CToolMenuButton::SetCurrentKeyBindingLabel( char const *itemName, char const *binding )
{
int id = FindMenuItem( itemName );
if ( id != -1 )
{
m_pMenu->SetCurrentKeyBinding( id, binding );
}
}
void CToolMenuButton::UpdateMenuItemKeyBindings()
{
if ( !m_pActionTarget )
return;
int c = m_Items.Count();
for ( int i = 0; i < c; ++i )
{
if ( !m_Items[ i ].m_KeyBinding.IsValid() )
continue;
char const *bindingName = m_Items[ i ].m_KeyBinding.String();
CUtlVector< BoundKey_t * > list;
m_pActionTarget->LookupBoundKeys( bindingName, list );
if ( list.Count() <= 0 )
continue;
BoundKey_t *kb = list[ 0 ];
Assert( kb );
// Found it, now convert to binding string
// First do modifiers
wchar_t sz[ 256 ];
wcsncpy( sz, Panel::KeyCodeModifiersToDisplayString( (KeyCode)kb->keycode, kb->modifiers ), 256 );
sz[ 255 ] = L'\0';
char ansi[ 512 ];
g_pVGuiLocalize->ConvertUnicodeToANSI( sz, ansi, sizeof( ansi ) );
m_pMenu->SetCurrentKeyBinding( m_Items[ i ].m_ItemID, ansi );
}
}
void CToolMenuButton::OnShowMenu( Menu *menu )
{
CToolMenuBar *bar = dynamic_cast< CToolMenuBar * >( GetParent() );
if ( bar )
{
CBaseToolSystem *sys = bar->GetToolSystem();
if ( sys )
{
sys->UpdateMenu( menu );
}
}
UpdateMenuItemKeyBindings();
m_pMenu->ForceCalculateWidth();
}
vgui::Menu *CToolMenuButton::GetMenu()
{
return m_pMenu;
}
+202
View File
@@ -0,0 +1,202 @@
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======
//
// Purpose: Core Movie Maker UI API
//
//=============================================================================
#include "toolutils/toolswitchmenubutton.h"
#include "vgui_controls/panel.h"
#include "toolutils/toolmenubutton.h"
#include "toolutils/enginetools_int.h"
#include "tier1/keyvalues.h"
#include "vgui_controls/menu.h"
#include "toolframework/ienginetool.h"
#include "vgui_controls/Frame.h"
#include "vgui_controls/Button.h"
#include "vgui_controls/ListPanel.h"
#include "filesystem.h"
#include "tier1/fmtstr.h"
#include "toolframework/itoolframework.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
class CLoadToolDialog : public Frame
{
DECLARE_CLASS_SIMPLE( CLoadToolDialog, Frame );
public:
CLoadToolDialog( Panel *panel );
protected:
virtual void OnCommand( const char *pCommand );
ListPanel *m_pModuleList;
Button *m_pLoadButton;
Button *m_pCancelButton;
};
CLoadToolDialog::CLoadToolDialog( Panel *panel ) :
BaseClass( panel, "LoadToolDialog" )
{
m_pModuleList = new ListPanel( this, "ModuleList" );
m_pModuleList->AddActionSignalTarget( this );
m_pModuleList->AddColumnHeader( 0, "text", "Text", 250, ListPanel::COLUMN_RESIZEWITHWINDOW );
m_pModuleList->SetMultiselectEnabled( true );
m_pLoadButton = new Button( this, "OkButton", "#VGui_OK", this, "Ok" );
m_pCancelButton = new Button( this, "Cancel", "#vgui_Cancel", this, "Cancel" );
SetSize( 300, 400 );
SetSizeable( true );
SetMoveable( true );
// Iterate loadable tools
// Search the directory structure.
char searchpath[ MAX_PATH ];
Q_strncpy( searchpath, "tools/*.dll", sizeof(searchpath) );
CUtlVector< CUtlString > toolmodules;
FileFindHandle_t handle;
char const *findfn = g_pFullFileSystem->FindFirstEx( searchpath, "EXECUTABLE_PATH", &handle );
while ( findfn )
{
if ( !g_pFullFileSystem->FindIsDirectory( handle ) )
{
char sz[ MAX_PATH ] = { 0 };
Q_FileBase( findfn, sz, sizeof( sz ) );
toolmodules.AddToTail( CUtlString( sz ) );
}
findfn = g_pFullFileSystem->FindNext( handle );
}
g_pFullFileSystem->FindClose( handle );
for ( int i = 0; i < toolmodules.Count(); ++i )
{
KeyValues *item = new KeyValues( "item" );
item->SetString( "text", toolmodules[ i ].String() );
m_pModuleList->AddItem( item, 0, false, false );
}
LoadControlSettings( "resource/loadtooldialog.res" );
}
void CLoadToolDialog::OnCommand( const char *pCommand )
{
if ( !Q_stricmp( pCommand, "Ok" ) )
{
KeyValues *pActionKeys = new KeyValues( "OnLoadTools" );
int nCount = m_pModuleList->GetSelectedItemsCount();
pActionKeys->SetInt( "count", nCount );
for ( int i = 0; i < nCount; ++i )
{
int itemID = m_pModuleList->GetSelectedItem( i );
KeyValues *item = m_pModuleList->GetItem( itemID );
pActionKeys->SetString( CFmtStr( "%i", i ), item->GetString( "text" ) );
}
CloseModal();
PostActionSignal( pActionKeys );
return;
}
if ( !Q_stricmp( pCommand, "Cancel" ) )
{
CloseModal();
return;
}
BaseClass::OnCommand( pCommand );
}
//-----------------------------------------------------------------------------
// Menu to switch between tools
//-----------------------------------------------------------------------------
class CToolSwitchMenuButton : public CToolMenuButton
{
DECLARE_CLASS_SIMPLE( CToolSwitchMenuButton, CToolMenuButton );
public:
CToolSwitchMenuButton( Panel *parent, const char *panelName, const char *text, Panel *pActionTarget );
virtual void OnShowMenu(Menu *menu);
protected:
MESSAGE_FUNC( OnShowLoadToolDialog, "OnShowLoadToolDialog" );
MESSAGE_FUNC_PARAMS( OnLoadTools, "OnLoadTools", params );
DHANDLE< CLoadToolDialog > m_hLoadToolDialog;
};
//-----------------------------------------------------------------------------
// Global function to create the switch menu
//-----------------------------------------------------------------------------
CToolMenuButton* CreateToolSwitchMenuButton( Panel *parent, const char *panelName, const char *text, Panel *pActionTarget )
{
return new CToolSwitchMenuButton( parent, panelName, text, pActionTarget );
}
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CToolSwitchMenuButton::CToolSwitchMenuButton( Panel *parent, const char *panelName, const char *text, Panel *pActionTarget ) :
BaseClass( parent, panelName, text, pActionTarget )
{
SetMenu(m_pMenu);
}
void CToolSwitchMenuButton::OnShowLoadToolDialog()
{
m_hLoadToolDialog = new CLoadToolDialog( this );
m_hLoadToolDialog->MoveToCenterOfScreen();
m_hLoadToolDialog->AddActionSignalTarget( this );
m_hLoadToolDialog->DoModal();
}
void CToolSwitchMenuButton::OnLoadTools( KeyValues *params )
{
int nCount = params->GetInt( "count", 0 );
for ( int i = 0; i < nCount; ++i )
{
char const *pToolName = params->GetString( CFmtStr( "%i", i ), "" );
if ( pToolName && *pToolName )
{
// Load it
enginetools->LoadToolModule( pToolName, false );
}
}
}
//-----------------------------------------------------------------------------
// Is called when the menu is made visible
//-----------------------------------------------------------------------------
void CToolSwitchMenuButton::OnShowMenu(Menu *menu)
{
BaseClass::OnShowMenu( menu );
Reset();
int c = enginetools->GetToolCount();
for ( int i = 0 ; i < c; ++i )
{
char const *toolname = enginetools->GetToolName( i );
char toolcmd[ 32 ];
Q_snprintf( toolcmd, sizeof( toolcmd ), "OnTool%i", i );
int id = AddCheckableMenuItem( toolname, toolname, new KeyValues ( "Command", "command", toolcmd ), m_pActionTarget );
m_pMenu->SetItemEnabled( id, true );
m_pMenu->SetMenuItemChecked( id, enginetools->IsTopmostTool( enginetools->GetToolSystem( i ) ) );
}
m_pMenu->AddSeparator();
m_pMenu->AddMenuItem( "#ToolShowLoadToolDialog", new KeyValues( "OnShowLoadToolDialog" ), this );
}
+117
View File
@@ -0,0 +1,117 @@
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======
//
// The tool UI has 4 purposes:
// 1) Create the menu bar and client area (lies under the menu bar)
// 2) Forward all mouse messages to the tool workspace so action menus work
// 3) Forward all commands to the tool system so all smarts can reside there
// 4) Control the size of the menu bar + the working area
//=============================================================================
#include "ToolUI.h"
#include "toolutils/toolmenubar.h"
#include "toolutils/basetoolsystem.h"
#include "vgui/cursor.h"
#include "vgui/isurface.h"
#include "tier1/keyvalues.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
#define MENU_HEIGHT 28
// Height of the status bar, if the tool installs one
#define STATUS_HEIGHT 24
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CToolUI::CToolUI( vgui::Panel *pParent, const char *panelName, CBaseToolSystem *pBaseToolSystem ) :
BaseClass( pParent, panelName ), m_pClientArea( 0 ), m_pBaseToolSystem( pBaseToolSystem )
{
SetPaintEnabled(false);
SetPaintBackgroundEnabled(false);
SetPaintBorderEnabled(false);
int w, h;
pParent->GetSize( w, h );
SetBounds( 0, 0, w, h );
m_pMenuBar = m_pBaseToolSystem->CreateMenuBar( m_pBaseToolSystem );
m_pMenuBar->SetParent( this );
m_pMenuBar->SetSize( w, MENU_HEIGHT );
// This can be NULL if no status bar should be included
m_pStatusBar = m_pBaseToolSystem->CreateStatusBar( this );
m_pStatusBar->SetParent( this );
m_pClientArea = new vgui::Panel( this, "ClientArea" );
m_pClientArea->SetMouseInputEnabled( false );
m_pClientArea->SetCursor( vgui::dc_none );
m_pClientArea->SetBounds( 0, MENU_HEIGHT, w, h - MENU_HEIGHT );
}
vgui::Panel *CToolUI::GetClientArea()
{
return m_pClientArea;
}
//-----------------------------------------------------------------------------
// The tool UI panel should always fill the space...
//-----------------------------------------------------------------------------
void CToolUI::PerformLayout()
{
BaseClass::PerformLayout();
// Make the editor panel fill the space
int iWidth, iHeight;
vgui::VPANEL parent = GetParent() ? GetParent()->GetVPanel() : vgui::surface()->GetEmbeddedPanel();
vgui::ipanel()->GetSize( parent, iWidth, iHeight );
SetSize( iWidth, iHeight );
int insettop = MENU_HEIGHT;
int insetbottom = 0;
m_pMenuBar->SetSize( iWidth, insettop );
if ( m_pStatusBar )
{
insetbottom = STATUS_HEIGHT;
m_pStatusBar->SetBounds( 0, iHeight - insetbottom, iWidth, insetbottom );
}
m_pClientArea->SetBounds( 0, insettop, iWidth, iHeight - insettop - insetbottom );
}
//-----------------------------------------------------------------------------
// Returns the menu bar
//-----------------------------------------------------------------------------
vgui::MenuBar *CToolUI::GetMenuBar()
{
return m_pMenuBar;
}
vgui::Panel *CToolUI::GetStatusBar()
{
return m_pStatusBar;
}
//-----------------------------------------------------------------------------
// Forward commands to systems that have more smarts than I do!
//-----------------------------------------------------------------------------
void CToolUI::OnMousePressed( vgui::MouseCode code )
{
// Chain mouse pressed calls to the parent tool workspace
CallParentFunction( new KeyValues( "MousePressed", "code", code ) );
}
void CToolUI::OnCommand( const char *cmd )
{
m_pBaseToolSystem->OnCommand( cmd );
}
void CToolUI::UpdateMenuBarTitle()
{
CToolFileMenuBar *mb = dynamic_cast< CToolFileMenuBar * >( GetMenuBar() );
if ( mb )
{
char title[ 64 ];
m_pBaseToolSystem->ComputeMenuBarTitle( title, sizeof( title ) );
mb->SetInfo( title );
}
}
+66
View File
@@ -0,0 +1,66 @@
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======
//
// The tool UI has 4 purposes:
// 1) Create the menu bar and client area (lies under the menu bar)
// 2) Forward all mouse messages to the tool workspace so action menus work
// 3) Forward all commands to the tool system so all smarts can reside there
// 4) Control the size of the menu bar + the working area
//=============================================================================
#ifndef TOOLUI_H
#define TOOLUI_H
#ifdef _WIN32
#pragma once
#endif
#include "vgui_controls/panel.h"
#include "vgui/mousecode.h"
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class CBaseToolSystem;
namespace vgui
{
class MenuBar;
}
//-----------------------------------------------------------------------------
// The tool UI has 4 purposes:
// 1) Create the menu bar and client area (lies under the menu bar)
// 2) Forward all mouse messages to the tool workspace so action menus work
// 3) Forward all commands to the tool system so all smarts can reside there
// 4) Control the size of the menu bar + the working area
//-----------------------------------------------------------------------------
class CToolUI : public vgui::Panel
{
DECLARE_CLASS_SIMPLE( CToolUI, vgui::Panel );
public:
// Constructor
CToolUI( vgui::Panel *pParent, const char *pPanelName, CBaseToolSystem *pBaseToolSystem );
// Overrides of panel methods
virtual void PerformLayout();
virtual void OnCommand( const char *cmd );
virtual void OnMousePressed( vgui::MouseCode code );
virtual void UpdateMenuBarTitle();
// Other public methods
vgui::MenuBar *GetMenuBar();
vgui::Panel *GetClientArea();
vgui::Panel *GetStatusBar();
private:
vgui::MenuBar *m_pMenuBar;
vgui::Panel *m_pStatusBar;
vgui::Panel *m_pClientArea;
CBaseToolSystem *m_pBaseToolSystem;
};
#endif // TOOLUI_H
@@ -0,0 +1,118 @@
// ----------------------------------------- //
// File generated by VPC //
// ----------------------------------------- //
Source file: F:\csgo_64\cstrike15_src\tools\toolutils\attributeelementchoicelist.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\toolutils\attributeelementchoicelist.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\toolutils\attributeelementchoicelist.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\tools\toolutils\basepropertiescontainer.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\toolutils\basepropertiescontainer.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\toolutils\basepropertiescontainer.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\tools\toolutils\basestatusbar.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\toolutils\basestatusbar.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\toolutils\basestatusbar.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\tools\toolutils\BaseToolSystem.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\toolutils\BaseToolSystem.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\toolutils\BaseToolSystem.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\tools\toolutils\ConsolePage.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\toolutils\ConsolePage.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\toolutils\ConsolePage.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\tools\toolutils\miniviewport.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\toolutils\miniviewport.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\toolutils\miniviewport.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\tools\toolutils\recentfilelist.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\toolutils\recentfilelist.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\toolutils\recentfilelist.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\tools\toolutils\savewindowpositions.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\toolutils\savewindowpositions.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\toolutils\savewindowpositions.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\tools\toolutils\ScriptEditorPanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\toolutils\ScriptEditorPanel.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\toolutils\ScriptEditorPanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\tools\toolutils\tool_main.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\toolutils\tool_main.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\toolutils\tool_main.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\tools\toolutils\tooleditmenubutton.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\toolutils\tooleditmenubutton.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\toolutils\tooleditmenubutton.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\tools\toolutils\ToolFileMenuButton.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\toolutils\ToolFileMenuButton.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\toolutils\ToolFileMenuButton.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\tools\toolutils\ToolHelpMenuButton.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\toolutils\ToolHelpMenuButton.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\toolutils\ToolHelpMenuButton.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\tools\toolutils\toolmenubar.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\toolutils\toolmenubar.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\toolutils\toolmenubar.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\tools\toolutils\ToolMenuButton.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\toolutils\ToolMenuButton.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\toolutils\ToolMenuButton.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\tools\toolutils\ToolSwitchMenuButton.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\toolutils\ToolSwitchMenuButton.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\toolutils\ToolSwitchMenuButton.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\tools\toolutils\ToolUI.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\toolutils\ToolUI.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\toolutils\ToolUI.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\tools\toolutils\vgui_tools.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\toolutils\vgui_tools.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\toolutils\vgui_tools.cpp
Containing unity file:
PCH file:
@@ -0,0 +1,137 @@
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "toolutils/attributeelementchoicelist.h"
#include "datamodel/dmelement.h"
#include "datamodel/dmattributevar.h"
typedef CUtlRBTree< CDmElement *, int > ElementDict_t;
//-----------------------------------------------------------------------------
// returns the choice string that AddElementsRecursively would have returned
//-----------------------------------------------------------------------------
const char *GetChoiceString( CDmElement *pElement )
{
return pElement->GetName();
}
//-----------------------------------------------------------------------------
// Recursively adds all elements referred to this element into the list of elements
//-----------------------------------------------------------------------------
void AddElementsRecursively_R( CDmElement *pElement, ElementChoiceList_t &list, ElementDict_t &dict, const char *pElementType )
{
if ( !pElement )
return;
if ( dict.Find( pElement ) != dict.InvalidIndex() )
return;
dict.Insert( pElement );
if ( pElement->IsA( pElementType ) )
{
int nIndex = list.AddToTail( );
ElementChoice_t &entry = list[nIndex];
entry.m_pValue = pElement;
entry.m_pChoiceString = GetChoiceString( pElement );
}
for ( CDmAttribute *pAttribute = pElement->FirstAttribute(); pAttribute; pAttribute = pAttribute->NextAttribute() )
{
char const *attributeName = pAttribute->GetName( );
DmAttributeType_t attrType = pAttribute->GetType( );
if ( attrType == AT_ELEMENT )
{
CDmElement *pChild = pElement->GetValueElement< CDmElement >( attributeName );
AddElementsRecursively_R( pChild, list, dict, pElementType );
}
else if ( attrType == AT_ELEMENT_ARRAY )
{
const CDmrElementArray<CDmElement> children( pElement, attributeName );
uint n = children.Count();
for ( uint i = 0; i < n; ++i )
{
CDmElement *pChild = children[ i ];
AddElementsRecursively_R( pChild, list, dict, pElementType );
}
}
}
}
//-----------------------------------------------------------------------------
// Recursively adds all elements referred to this element into the list of elements
//-----------------------------------------------------------------------------
void AddElementsRecursively_R( CDmElement *pElement, DmeHandleVec_t &list, ElementDict_t &dict, const char *pElementType )
{
if ( !pElement )
return;
if ( dict.Find( pElement ) != dict.InvalidIndex() )
return;
dict.Insert( pElement );
if ( pElement->IsA( pElementType ) )
{
int nIndex = list.AddToTail( );
list[nIndex] = pElement;
}
for ( CDmAttribute *pAttribute = pElement->FirstAttribute(); pAttribute; pAttribute = pAttribute->NextAttribute() )
{
char const *attributeName = pAttribute->GetName( );
DmAttributeType_t attrType = pAttribute->GetType( );
if ( attrType == AT_ELEMENT )
{
CDmElement *pChild = pElement->GetValueElement< CDmElement >( attributeName );
AddElementsRecursively_R( pChild, list, dict, pElementType );
}
else if ( attrType == AT_ELEMENT_ARRAY )
{
const CDmrElementArray<CDmElement> children( pElement, attributeName );
uint n = children.Count();
for ( uint i = 0; i < n; ++i )
{
CDmElement *pChild = children[ i ];
AddElementsRecursively_R( pChild, list, dict, pElementType );
}
}
}
}
//-----------------------------------------------------------------------------
// Recursively adds all elements referred to this element into the list of elements
//-----------------------------------------------------------------------------
void AddElementsRecursively( CDmElement *obj, ElementChoiceList_t &list, const char *pElementType )
{
if ( !pElementType )
{
pElementType = CDmElement::GetStaticTypeSymbol().String();
}
ElementDict_t dict( 0, 0, DefLessFunc( CDmElement * ) );
AddElementsRecursively_R( obj, list, dict, pElementType );
}
//-----------------------------------------------------------------------------
// Recursively adds all elements of the specified type under pElement into the vector
//-----------------------------------------------------------------------------
void AddElementsRecursively( CDmElement *pElement, DmeHandleVec_t &list, const char *pElementType )
{
if ( !pElementType )
{
pElementType = CDmElement::GetStaticTypeSymbol().String();
}
ElementDict_t dict( 0, 0, DefLessFunc( CDmElement * ) );
AddElementsRecursively_R( pElement, list, dict, pElementType );
}
@@ -0,0 +1,47 @@
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======
//
// Purpose:
//
//=============================================================================
#include "toolutils/basepropertiescontainer.h"
#include "tier1/KeyValues.h"
CBasePropertiesContainer::CBasePropertiesContainer( vgui::Panel *parent, IDmNotify *pNotify, CDmeEditorTypeDictionary *pDict /*=NULL*/ )
: BaseClass( parent, pNotify, NULL, true, pDict )
{
SetDropEnabled( true );
}
bool CBasePropertiesContainer::IsDroppable( CUtlVector< KeyValues * >& msglist )
{
if ( msglist.Count() != 1 )
return false;
KeyValues *data = msglist[ 0 ];
CDmElement *ptr = reinterpret_cast< CDmElement * >( g_pDataModel->GetElement( DmElementHandle_t( data->GetInt( "dmeelement", DMELEMENT_HANDLE_INVALID ) ) ) );
if ( !ptr )
return false;
if ( ptr == GetObject() )
return false;
return true;
}
void CBasePropertiesContainer::OnPanelDropped( CUtlVector< KeyValues * >& msglist )
{
if ( msglist.Count() != 1 )
return;
KeyValues *data = msglist[ 0 ];
CDmElement *ptr = reinterpret_cast< CDmElement * >( g_pDataModel->GetElement( DmElementHandle_t( data->GetInt( "dmeelement", DMELEMENT_HANDLE_INVALID ) ) ) );
if ( !ptr )
return;
// Already browsing
if ( ptr == GetObject() )
return;
SetObject( ptr );
}
+151
View File
@@ -0,0 +1,151 @@
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======
//
// Purpose:
//
//=============================================================================
#include "toolutils/basestatusbar.h"
#include "toolutils/ConsolePage.h"
#include "vgui_controls/Label.h"
#include "movieobjects/dmeclip.h"
#include "tier1/KeyValues.h"
#include "vgui/IVGui.h"
#include "toolutils/enginetools_int.h"
#include "toolframework/ienginetool.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CBaseStatusBar::CBaseStatusBar( vgui::Panel *parent, char const *panelName )
: BaseClass( parent, panelName ),
m_flLastFPSSnapShot( -1.0f )
{
SetVisible( true );
m_pConsole = new CConsolePage( this, true );
m_pLabel = new Label( this, "Console", "#BxConsole" );
m_pMemory = new Label( this, "Memory", "" );
m_pFPS = new Label( this, "FPS", "" );
m_pGameTime = new Label( this, "GameTime", "" );
MakePopup( false );
UpdateMemoryUsage( 9.999 );
}
//-----------------------------------------------------------------------------
// Purpose: Forces console to take up full area except right edge
// Input : -
//-----------------------------------------------------------------------------
void CBaseStatusBar::PerformLayout()
{
BaseClass::PerformLayout();
int w, h;
GetSize( w, h );
int oldw = w;
w *= 0.45f;
int x = 8;
int cw, ch;
m_pLabel->GetContentSize( cw, ch );
m_pLabel->SetBounds( x, 4, cw, h - 8 );
x += cw + 4;
int consoleWide = w - x - 8;
m_pConsole->SetBounds( x, 2, consoleWide, h - 4 );
x += consoleWide + 4;
int infoW = 85;
int rightx = oldw - infoW - 10;
m_pFPS->SetBounds( rightx, 2, infoW - 2 - 10, h - 8 );
rightx -= infoW;
m_pGameTime->SetBounds( rightx, 2, infoW - 2, h - 8 );
rightx -= infoW;
m_pMemory->SetBounds( rightx, 2, infoW - 2, h - 8 );
}
void CBaseStatusBar::UpdateMemoryUsage( float mbUsed )
{
char mem[ 256 ];
Q_snprintf( mem, sizeof( mem ), "[mem: %.2f Mb]", mbUsed );
m_pMemory->SetText( mem );
}
//-----------------------------------------------------------------------------
// Purpose: Message map
//-----------------------------------------------------------------------------
void CBaseStatusBar::ApplySchemeSettings(IScheme *pScheme)
{
BaseClass::ApplySchemeSettings(pScheme);
// get the borders we need
SetBorder(pScheme->GetBorder("ButtonBorder"));
// get the background color
SetBgColor(pScheme->GetColor( "StatusBar.BgColor", GetBgColor() ));
m_pLabel->SetFont( pScheme->GetFont( "DefaultVerySmall" ) );
m_pMemory->SetFont( pScheme->GetFont( "DefaultVerySmall" ) );
m_pFPS->SetFont( pScheme->GetFont( "DefaultVerySmall" ) );
m_pGameTime->SetFont( pScheme->GetFont( "DefaultVerySmall" ) );
}
static float GetMemoryUsage();
void CBaseStatusBar::OnThink()
{
BaseClass::OnThink();
float curtime = enginetools->GetRealTime();
char gt[ 32 ];
Q_snprintf( gt, sizeof( gt ), "[game: %.3f]", enginetools->ServerTime() );
m_pGameTime->SetText( gt );
float elapsed = curtime - m_flLastFPSSnapShot;
if ( elapsed < 0.4f )
return;
m_flLastFPSSnapShot = curtime;
float ft = enginetools->GetRealFrameTime();
if ( ft <= 0.0f )
{
m_pFPS->SetText( "[fps: ??]" );
}
else
{
char fps[ 32 ];
Q_snprintf( fps, sizeof( fps ), "[fps: %.1f]", 1.0f / ft );
m_pFPS->SetText( fps );
}
UpdateMemoryUsage( GetMemoryUsage() );
}
#include <windows.h>
#include <psapi.h>
static float GetMemoryUsage()
{
PROCESS_MEMORY_COUNTERS counters;
counters.cb = sizeof( counters );
if ( GetProcessMemoryInfo( GetCurrentProcess(), &counters, sizeof( counters ) ) )
{
return (float)counters.WorkingSetSize / ( 1024.0f * 1024.0f );
}
return 0;
}
+430
View File
@@ -0,0 +1,430 @@
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======
//
// Purpose:
//
//=============================================================================
#include "toolutils/miniviewport.h"
#include "tier1/utlstring.h"
#include "vgui/ISurface.h"
#include "materialsystem/imaterialsystemhardwareconfig.h"
#include "materialsystem/IMaterialSystem.h"
#include "materialsystem/MaterialSystemUtil.h"
#include "materialsystem/IMesh.h"
#include "materialsystem/IMaterial.h"
#include "materialsystem/itexture.h"
#include "tier1/KeyValues.h"
#include "toolframework/ienginetool.h"
#include "toolutils/enginetools_int.h"
#include "vguimatsurface/imatsystemsurface.h"
#include "view_shared.h"
#include "texture_group_names.h"
#include "vgui_controls/PropertySheet.h"
#include "tier3/tier3.h"
#include <windows.h> // for MultiByteToWideChar
#include "cdll_int.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
class CMiniViewportEngineRenderArea;
using namespace vgui;
#define DEFAULT_PREVIEW_WIDTH 1280
//-----------------------------------------------------------------------------
// Purpose: This is a "frame" which is used to position the engine
//-----------------------------------------------------------------------------
class CMiniViewportPropertyPage : public vgui::EditablePanel
{
DECLARE_CLASS_SIMPLE( CMiniViewportPropertyPage, vgui::EditablePanel );
public:
CMiniViewportPropertyPage( Panel *parent, const char *panelName );
virtual Color GetBgColor();
void GetEngineBounds( int& x, int& y, int& w, int& h );
void RenderFrameBegin();
CMiniViewportEngineRenderArea *GetViewportArea() { return m_pViewportArea; }
private:
virtual void PerformLayout();
Color m_bgColor;
CMiniViewportEngineRenderArea *m_pViewportArea;
};
//-----------------------------------------------------------------------------
//
// the actual renderable area
//
//-----------------------------------------------------------------------------
class CMiniViewportEngineRenderArea : public vgui::EditablePanel
{
DECLARE_CLASS_SIMPLE( CMiniViewportEngineRenderArea, vgui::EditablePanel );
public:
CMiniViewportEngineRenderArea( Panel *parent, const char *panelName );
~CMiniViewportEngineRenderArea();
virtual void PaintBackground();
virtual void GetEngineBounds( int& x, int& y, int& w, int& h );
virtual void ApplySchemeSettings( IScheme *pScheme );
void RenderFrameBegin();
void SetOverlayText( const char *pText );
protected:
void InitSceneMaterials();
void ShutdownSceneMaterials();
// Paints the black borders around the engine window
void PaintEngineBorders( int x, int y, int w, int h );
// Paints the engine window itself
void PaintEngineWindow( int x, int y, int w, int h );
// Paints the overlay text
void PaintOverlayText( );
int m_nEngineOutputTexture;
vgui::HFont m_OverlayTextFont;
CUtlString m_OverlayText;
CTextureReference m_ScreenBuffer;
CMaterialReference m_ScreenMaterial;
};
CMiniViewportEngineRenderArea::CMiniViewportEngineRenderArea( Panel *parent, const char *panelName )
: BaseClass( parent, panelName )
{
SetPaintEnabled( false );
SetPaintBorderEnabled( false );
SetPaintBackgroundEnabled( true );
m_nEngineOutputTexture = vgui::surface()->CreateNewTextureID();
}
CMiniViewportEngineRenderArea::~CMiniViewportEngineRenderArea()
{
ShutdownSceneMaterials();
}
void CMiniViewportEngineRenderArea::RenderFrameBegin()
{
if ( !enginetools->IsInGame() )
return;
InitSceneMaterials();
CViewSetup playerViewSetup;
int x, y, w, h;
GetEngineBounds( x, y, w, h );
enginetools->GetPlayerView( playerViewSetup, 0, 0, w, h );
// NOTE: This is a workaround to a nasty problem. Vgui uses stencil
// to determing if the panels should occlude each other. The engine
// has now started to use stencil for various random effects.
// To prevent these different stencil uses from clashing, we will
// render the engine prior to vgui painting + cache the result off in
//
// Make the engine draw the scene
CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
pRenderContext->PushRenderTargetAndViewport( m_ScreenBuffer, 0, 0, w, h );
// Tell the engine to tell the client to render the view (sans viewmodel)
enginetools->SetMainView( playerViewSetup.origin, playerViewSetup.angles );
enginetools->RenderView( playerViewSetup, VIEW_CLEAR_COLOR | VIEW_CLEAR_DEPTH, RENDERVIEW_DRAWHUD | RENDERVIEW_DRAWVIEWMODEL );
// Pop the target
pRenderContext->PopRenderTargetAndViewport();
}
void CMiniViewportEngineRenderArea::InitSceneMaterials()
{
if ( m_ScreenBuffer )
return;
if ( g_pMaterialSystem->IsTextureLoaded( "_rt_LayoffResult" ) )
{
ITexture *pTexture = g_pMaterialSystem->FindTexture( "_rt_LayoffResult", TEXTURE_GROUP_RENDER_TARGET );
m_ScreenBuffer.Init( pTexture );
}
else
{
// For now, layoff dimensions match aspect of back buffer
int nBackBufferWidth, nBackBufferHeight;
g_pMaterialSystem->GetBackBufferDimensions( nBackBufferWidth, nBackBufferHeight );
float flAspect = nBackBufferWidth / (float)nBackBufferHeight;
int nPreviewWidth = min( DEFAULT_PREVIEW_WIDTH, nBackBufferWidth );
int nPreviewHeight = ( int )( nPreviewWidth / flAspect + 0.5f );
g_pMaterialSystem->BeginRenderTargetAllocation(); // Begin allocating RTs which IFM can scribble into
// LDR final result of either HDR or LDR rendering
m_ScreenBuffer.Init( g_pMaterialSystem->CreateNamedRenderTargetTextureEx2(
"_rt_LayoffResult", nPreviewWidth, nPreviewHeight, RT_SIZE_OFFSCREEN,
g_pMaterialSystem->GetBackBufferFormat(), MATERIAL_RT_DEPTH_SHARED, TEXTUREFLAGS_BORDER ) );
g_pMaterialSystem->EndRenderTargetAllocation(); // End allocating RTs which IFM can scribble into
}
KeyValues *pVMTKeyValues = NULL;
pVMTKeyValues= new KeyValues( "UnlitGeneric" );
pVMTKeyValues->SetString( "$basetexture", m_ScreenBuffer->GetName() );
pVMTKeyValues->SetInt( "$nofog", 1 );
m_ScreenMaterial.Init( "MiniViewportEngineRenderAreaSceneMaterial", pVMTKeyValues );
m_ScreenMaterial->Refresh();
}
//-----------------------------------------------------------------------------
// Apply scheme settings
//-----------------------------------------------------------------------------
void CMiniViewportEngineRenderArea::ApplySchemeSettings( IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
m_OverlayTextFont = pScheme->GetFont( "DefaultLargeOutline" );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CMiniViewportEngineRenderArea::ShutdownSceneMaterials()
{
m_ScreenBuffer.Shutdown();
m_ScreenMaterial.Shutdown();
}
//-----------------------------------------------------------------------------
// Sets text to draw over the window
//-----------------------------------------------------------------------------
void CMiniViewportEngineRenderArea::SetOverlayText( const char *pText )
{
m_OverlayText = pText;
}
//-----------------------------------------------------------------------------
// Paints the black borders around the engine window
//-----------------------------------------------------------------------------
void CMiniViewportEngineRenderArea::PaintEngineBorders( int x, int y, int w, int h )
{
// Draws black borders around the engine window
surface()->DrawSetColor( Color( 0, 0, 0, 255 ) );
if ( x != 0 )
{
surface()->DrawFilledRect( 0, 0, x, h );
surface()->DrawFilledRect( x + w, 0, w + 2 * x, h );
}
else if ( y != 0 )
{
surface()->DrawFilledRect( 0, 0, w, y );
surface()->DrawFilledRect( 0, y + h, w, h + 2 * y );
}
}
//-----------------------------------------------------------------------------
// Paints the overlay text
//-----------------------------------------------------------------------------
void CMiniViewportEngineRenderArea::PaintOverlayText( )
{
if ( !m_OverlayText.Length() )
return;
int cw, ch;
GetSize( cw, ch );
int nTextWidth, nTextHeight;
int nBufLen = m_OverlayText.Length()+1;
wchar_t *pTemp = (wchar_t*)_alloca( nBufLen * sizeof(wchar_t) );
::MultiByteToWideChar( CP_UTF8, 0, m_OverlayText.Get(), -1, pTemp, nBufLen );
g_pMatSystemSurface->GetTextSize( m_OverlayTextFont, pTemp, nTextWidth, nTextHeight );
int lx = (cw - nTextWidth) / 2;
if ( lx < 10 )
{
lx = 10;
}
int ly = ch - 10 - nTextHeight;
g_pMatSystemSurface->DrawColoredTextRect( m_OverlayTextFont,
lx, ly, cw - lx, ch - ly,
255, 255, 255, 255, "%s", m_OverlayText.Get() );
}
//-----------------------------------------------------------------------------
// Paints the engine window itself
//-----------------------------------------------------------------------------
void CMiniViewportEngineRenderArea::PaintEngineWindow( int x, int y, int w, int h )
{
if ( !enginetools->IsInGame() )
{
surface()->DrawSetColor( Color( 127, 127, 200, 63 ) );
surface()->DrawFilledRect( x, y, x + w, y + h );
}
else
{
CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
g_pMatSystemSurface->DrawSetTextureMaterial( m_nEngineOutputTexture, m_ScreenMaterial );
surface()->DrawSetColor( Color( 0, 0, 0, 255 ) );
int nTexWidth = m_ScreenBuffer->GetActualWidth();
int nTexHeight = m_ScreenBuffer->GetActualHeight();
float flOOWidth = 1.0f / nTexWidth;
float flOOHeight = 1.0f / nTexHeight;
float s0, s1, t0, t1;
s0 = ( 0.5f ) * flOOWidth;
t0 = ( 0.5f ) * flOOHeight;
s1 = ( (float)w - 0.5f ) * flOOWidth;
t1 = ( (float)h - 0.5f ) * flOOHeight;
vgui::surface()->DrawTexturedSubRect( x, y, x+w, y+h, s0, t0, s1, t1 );
PaintOverlayText();
}
}
//-----------------------------------------------------------------------------
// Paints the background
//-----------------------------------------------------------------------------
void CMiniViewportEngineRenderArea::PaintBackground()
{
int x, y, w, h;
GetEngineBounds( x, y, w, h );
PaintEngineBorders( x, y, w, h );
PaintEngineWindow( x, y, w, h );
}
void CMiniViewportEngineRenderArea::GetEngineBounds( int& x, int& y, int& w, int& h )
{
x = 0;
y = 0;
GetSize( w, h );
// Check aspect ratio
int sx, sy;
surface()->GetScreenSize( sx, sy );
if ( sy > 0 &&
h > 0 )
{
float screenaspect = (float)sx / (float)sy;
float aspect = (float)w / (float)h;
float ratio = screenaspect / aspect;
// Screen is wider, need bars at top and bottom
if ( ratio > 1.0f )
{
int usetall = (float)w / screenaspect;
y = ( h - usetall ) / 2;
h = usetall;
}
// Screen is narrower, need bars at left/right
else
{
int usewide = (float)h * screenaspect;
x = ( w - usewide ) / 2;
w = usewide;
}
}
}
CMiniViewportPropertyPage::CMiniViewportPropertyPage(Panel *parent, const char *panelName ) :
BaseClass( parent, panelName )
{
m_bgColor = Color( 0, 0, 0, 0 );
m_pViewportArea = new CMiniViewportEngineRenderArea( this, "Engine" );
}
void CMiniViewportPropertyPage::PerformLayout()
{
BaseClass::PerformLayout();
int w, h;
GetSize( w, h );
m_pViewportArea->SetBounds( 0, 0, w, h );
}
Color CMiniViewportPropertyPage::GetBgColor()
{
return m_bgColor;
}
void CMiniViewportPropertyPage::GetEngineBounds( int& x, int& y, int& w, int& h )
{
m_pViewportArea->GetEngineBounds( x, y, w, h );
m_pViewportArea->LocalToScreen( x, y );
}
void CMiniViewportPropertyPage::RenderFrameBegin()
{
m_pViewportArea->RenderFrameBegin();
}
CMiniViewport::CMiniViewport( vgui::Panel *parent, bool contextLabel, vgui::IToolWindowFactory *factory /*= 0*/,
vgui::Panel *page /*= NULL*/, char const *title /*= NULL*/, bool contextMenu /*= false*/ ) :
BaseClass( parent, contextLabel, factory, page, title, contextMenu, false )
{
SetCloseButtonVisible( false );
GetPropertySheet()->SetDraggableTabs( false );
// Add the viewport panel
m_hPage = new CMiniViewportPropertyPage( this, "ViewportPage" );
AddPage( m_hPage.Get(), "#ToolMiniViewport", false );
}
void CMiniViewport::GetViewport( bool& enabled, int& x, int& y, int& w, int& h )
{
enabled = false;
x = y = w = h = 0;
int screenw, screenh;
surface()->GetScreenSize( screenw, screenh );
m_hPage->GetEngineBounds( x, y, w, h );
y = screenh - ( y + h );
}
void CMiniViewport::GetEngineBounds( int& x, int& y, int& w, int& h )
{
m_hPage->GetEngineBounds( x, y, w, h );
}
//-----------------------------------------------------------------------------
// Sets text to draw over the window
//-----------------------------------------------------------------------------
void CMiniViewport::SetOverlayText( const char *pText )
{
if ( m_hPage.Get() )
{
m_hPage->GetViewportArea()->SetOverlayText( pText );
}
}
void CMiniViewport::RenderFrameBegin()
{
if ( m_hPage.Get() )
{
m_hPage->RenderFrameBegin();
}
}
+159
View File
@@ -0,0 +1,159 @@
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======
//
// Purpose: Core Movie Maker UI API
//
//=============================================================================
#include "toolutils/recentfilelist.h"
#include "vgui_controls/menu.h"
#include "iregistry.h"
#include "tier1/keyvalues.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
//-----------------------------------------------------------------------------
// Adds a file to the list of recent files
//-----------------------------------------------------------------------------
void CToolsRecentFileList::Add( const char *pFileName, const char *pFileFormat )
{
RecentFileInfo_t info;
info.m_pFileName = pFileName;
int idx = m_RecentFiles.Find( info );
if ( idx != m_RecentFiles.InvalidIndex() )
{
// Remove from current slot so it gets added to head (most recent) below...
m_RecentFiles.Remove( idx );
}
while ( m_RecentFiles.Count() >= MAX_RECENT_FILES )
{
// Oldest is at last slot
m_RecentFiles.Remove( m_RecentFiles.Count() - 1 );
}
int i = m_RecentFiles.AddToHead( );
m_RecentFiles[i].m_pFileName = pFileName;
m_RecentFiles[i].m_pFileFormat = pFileFormat;
}
//-----------------------------------------------------------------------------
// Removes all files from the list
//-----------------------------------------------------------------------------
void CToolsRecentFileList::Clear()
{
m_RecentFiles.RemoveAll();
}
//-----------------------------------------------------------------------------
// Returns true if there's no files in the file list
//-----------------------------------------------------------------------------
bool CToolsRecentFileList::IsEmpty() const
{
return m_RecentFiles.Count() == 0;
}
//-----------------------------------------------------------------------------
// Gets the file in a particular slot
//-----------------------------------------------------------------------------
const char *CToolsRecentFileList::GetFile( int slot ) const
{
if ( slot < 0 || slot >= m_RecentFiles.Count() )
return NULL;
return m_RecentFiles[slot].m_pFileName;
}
//-----------------------------------------------------------------------------
// Gets the file in a particular slot
//-----------------------------------------------------------------------------
const char *CToolsRecentFileList::GetFileFormat( int slot ) const
{
if ( slot < 0 || slot >= m_RecentFiles.Count() )
return NULL;
return m_RecentFiles[slot].m_pFileFormat;
}
//-----------------------------------------------------------------------------
// Loads the file list from the registry
//-----------------------------------------------------------------------------
void CToolsRecentFileList::LoadFromRegistry( const char *pToolKeyName )
{
Clear();
// Iterate in reverse order so most recent files goes to top
for ( int i = MAX_RECENT_FILES; i >= 0; --i )
{
char sz[ 128 ];
char szType[ 128 ];
Q_snprintf( sz, sizeof( sz ), "%s\\history%02i", pToolKeyName, i );
Q_snprintf( szType, sizeof( szType ), "%s\\history_fileformat%02i", pToolKeyName, i );
// NOTE: Can't call registry->ReadString twice in a row!
char pFileName[MAX_PATH];
Q_strncpy( pFileName, registry->ReadString( sz, "" ), sizeof(pFileName) );
if ( pFileName && pFileName[ 0 ] )
{
const char *valType = registry->ReadString( szType, "" );
const char *pFormat = (valType && valType[0]) ? valType : "dmx";
Add( pFileName, pFormat );
}
}
}
//-----------------------------------------------------------------------------
// Saves file list into the registry
//-----------------------------------------------------------------------------
void CToolsRecentFileList::SaveToRegistry( const char *pToolKeyName ) const
{
char sz[ 128 ];
int i, c;
c = m_RecentFiles.Count();
for ( i = 0 ; i < c; ++i )
{
Q_snprintf( sz, sizeof( sz ), "%s\\history%02i", pToolKeyName, i );
registry->WriteString( sz, m_RecentFiles[i].m_pFileName );
Q_snprintf( sz, sizeof( sz ), "%s\\history_fileformat%02i", pToolKeyName, i );
registry->WriteString( sz, m_RecentFiles[i].m_pFileFormat );
}
// Clear out all other registry settings
for ( ; i < MAX_RECENT_FILES; ++i )
{
Q_snprintf( sz, sizeof( sz ), "%s\\history%02i", pToolKeyName, i );
registry->WriteString( sz, "" );
Q_snprintf( sz, sizeof( sz ), "%s\\history_fileformat%02i", pToolKeyName, i );
registry->WriteString( sz, "" );
}
}
//-----------------------------------------------------------------------------
// Adds the list of files to a particular menu
//-----------------------------------------------------------------------------
void CToolsRecentFileList::AddToMenu( vgui::Menu *menu, vgui::Panel *pActionTarget, const char *pCommandName ) const
{
int i, c;
c = m_RecentFiles.Count();
for ( i = 0 ; i < c; ++i )
{
char sz[ 32 ];
Q_snprintf( sz, sizeof( sz ), "%s%02i", pCommandName, i );
char const *fn = m_RecentFiles[i].m_pFileName;
menu->AddMenuItem( fn, new KeyValues( "Command", "command", sz ), pActionTarget );
}
menu->AddSeparator();
menu->AddMenuItem( "clearrecent", "#ToolFileClearRecent", new KeyValues ( "OnClearRecent" ), pActionTarget );
}
+286
View File
@@ -0,0 +1,286 @@
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======
//
// Purpose:
//
//=============================================================================
#include "toolutils/savewindowpositions.h"
#include "iregistry.h"
#include "vgui_controls/Panel.h"
#include "vgui_controls/PHandle.h"
#include "vgui_controls/ToolWindow.h"
#include "vgui/isurface.h"
#include "vgui_controls/PropertySheet.h"
#include "tier1/UtlSymbol.h"
#include "tier1/UtlBuffer.h"
#include "tier1/KeyValues.h"
#include "filesystem.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
// Purpose: This will save the bounds and the visibility state of UI elements registered during startup
// FIXME: Preserve Z order?
//-----------------------------------------------------------------------------
class CWindowPositionMgr : public IWindowPositionMgr
{
public:
// Inherited from IWindowPositionMgr
virtual void SavePositions( char const *filename, char const *key );
virtual bool LoadPositions( char const *filename, Panel *parent, vgui::IToolWindowFactory *factory, char const *key, bool force = false );
virtual void RegisterPanel( char const *saveName, Panel *panel, bool contextMenu );
virtual void UnregisterPanel( vgui::Panel *panel );
private:
struct LoadInfo_t
{
CUtlSymbol m_Name;
PHandle m_hPanel;
bool m_bLoaded;
bool m_bContextMenu;
};
LoadInfo_t *Find( Panel *panel );
LoadInfo_t *Find( char const *panelName );
CUtlVector< LoadInfo_t > m_Panels;
};
//-----------------------------------------------------------------------------
// Singleton instance
//-----------------------------------------------------------------------------
static CWindowPositionMgr g_WindowPositionMgr;
IWindowPositionMgr *windowposmgr = &g_WindowPositionMgr;
CWindowPositionMgr::LoadInfo_t *CWindowPositionMgr::Find( Panel *panel )
{
if ( !panel )
return NULL;
int c = m_Panels.Count();
for ( int i = 0; i < c; ++i )
{
LoadInfo_t *info = &m_Panels[ i ];
if ( info->m_hPanel.Get() == panel )
return info;
}
return NULL;
}
CWindowPositionMgr::LoadInfo_t *CWindowPositionMgr::Find( char const *panelName )
{
if ( !panelName )
return NULL;
int c = m_Panels.Count();
for ( int i = 0; i < c; ++i )
{
LoadInfo_t *info = &m_Panels[ i ];
if ( !Q_stricmp( info->m_Name.String(), panelName ) )
return info;
}
return NULL;
}
static void BufPrint( CUtlBuffer& buf, int level, char const *fmt, ... )
{
char string[ 2048 ];
va_list argptr;
va_start( argptr, fmt );
_vsnprintf( string, sizeof( string ) - 1, fmt, argptr );
va_end( argptr );
string[ sizeof( string ) - 1 ] = 0;
while ( --level >= 0 )
{
buf.Printf( " " );
}
buf.Printf( "%s", string );
}
void CWindowPositionMgr::SavePositions( char const *filename, char const *key )
{
CUtlBuffer buf( 0, 0, CUtlBuffer::TEXT_BUFFER );
buf.Printf( "%s\n", key );
buf.Printf( "{\n" );
int sw, sh;
vgui::surface()->GetScreenSize( sw, sh );
float flOOW = (sw != 0.0f) ? 1.0f / (float)sw : 1.0f;
float flOOH = (sh != 0.0f) ? 1.0f / (float)sh : 1.0f;
int c = ToolWindow::GetToolWindowCount();
for ( int i = 0 ; i < c; ++i )
{
ToolWindow *tw = ToolWindow::GetToolWindow( i );
Assert( tw );
if ( !tw )
continue;
BufPrint( buf, 1, "toolwindow\n" );
BufPrint( buf, 1, "{\n" );
// Get panel bounds
int x, y, w, h;
tw->GetBounds( x, y, w, h );
float fx = (float)x * flOOW;
float fy = (float)y * flOOH;
float fw = (float)w * flOOW;
float fh = (float)h * flOOH;
BufPrint( buf, 2, "bounds \"%.10f %.10f %.10f %.10f\"\n", fx, fy, fw, fh );
// Now iterate the actual contained panels
PropertySheet *sheet = tw->GetPropertySheet();
Assert( sheet );
if ( sheet )
{
int subCount = sheet->GetNumPages();
Assert( subCount > 0 );
if ( subCount > 0 )
{
BufPrint( buf, 2, "windows\n" );
BufPrint( buf, 2, "{\n" );
for ( int s = 0 ; s < subCount; ++s )
{
Panel *subPanel = sheet->GetPage( s );
if ( !subPanel )
continue;
LoadInfo_t *info = Find( subPanel );
if ( !info )
continue;
BufPrint( buf, 3, "panel \"%s\"\n", info->m_Name.String() );
}
BufPrint( buf, 2, "}\n" );
}
}
BufPrint( buf, 1, "}\n" );
}
buf.Printf( "}\n" );
if ( g_pFullFileSystem->FileExists( filename, "DEFAULT_WRITE_PATH" ) &&
!g_pFullFileSystem->IsFileWritable( filename, "DEFAULT_WRITE_PATH" ) )
{
Warning( "IFM window layout file '%s' is read-only!!!\n", filename );
}
FileHandle_t h = g_pFullFileSystem->Open( filename, "wb", "DEFAULT_WRITE_PATH" );
if ( FILESYSTEM_INVALID_HANDLE != h )
{
g_pFullFileSystem->Write( buf.Base(), buf.TellPut(), h );
g_pFullFileSystem->Close( h );
}
}
bool CWindowPositionMgr::LoadPositions( char const *filename, vgui::Panel *parent, vgui::IToolWindowFactory *factory, char const *key, bool force /*=false*/ )
{
bool success = false;
int sw, sh;
vgui::surface()->GetScreenSize( sw, sh );
KeyValues *kv = new KeyValues( key );
if ( kv->LoadFromFile( g_pFullFileSystem, filename, "GAME" ) )
{
// Walk through tools
for ( KeyValues *tw = kv->GetFirstSubKey(); tw != NULL; tw = tw->GetNextKey() )
{
if ( Q_stricmp( tw->GetName(), "toolwindow" ) )
continue;
// read bounds
float fx, fy, fw, fh;
int x, y, w, h;
char const *bounds = tw->GetString( "bounds", "" );
if ( !bounds || !bounds[ 0 ] )
continue;
if ( 4 != sscanf( bounds, "%f %f %f %f", &fx, &fy, &fw, &fh ) )
continue;
x = (int)( sw * fx + 0.5f );
y = (int)( sh * fy + 0.5f );
w = (int)( sw * fw + 0.5f );
h = (int)( sh * fh + 0.5f );
w = clamp( w, 0, sw );
h = clamp( h, 0, sh );
// Now load pages
KeyValues *pages = tw->FindKey( "windows", false );
if ( !pages )
continue;
ToolWindow *newTool = factory->InstanceToolWindow( parent, true, NULL, NULL, false );
newTool->SetBounds( x, y, w, h );
for ( KeyValues *page = pages->GetFirstSubKey(); page != NULL; page = page->GetNextKey() )
{
if ( Q_stricmp( page->GetName(), "panel" ) )
continue;
char const *pageName = page->GetString();
if ( !pageName || !pageName[ 0 ] )
continue;
LoadInfo_t *info = Find( pageName );
if ( !info )
continue;
newTool->AddPage( info->m_hPanel.Get(), info->m_Name.String(), info->m_bContextMenu );
success = true;
}
// If we didn't successfully create something, delete the tool
if ( !success )
{
delete newTool;
}
}
}
kv->deleteThis();
return success;
}
void CWindowPositionMgr::RegisterPanel( char const *saveName, Panel *panel, bool contextMenu )
{
char const *panelName = panel->GetName();
if ( !panelName || !panelName[ 0 ] )
{
Warning( "CWindowPositionMgr::RegisterPanel: Panel has NULL or blank name!!!\n" );
return;
}
LoadInfo_t info;
info.m_hPanel = panel;
info.m_Name = saveName;
info.m_bLoaded = false;
info.m_bContextMenu = contextMenu;
m_Panels.AddToTail( info );
}
void CWindowPositionMgr::UnregisterPanel( vgui::Panel *panel )
{
int c = m_Panels.Count();
for ( int i = c - 1; i >= 0; --i )
{
if ( m_Panels[ i ].m_hPanel.Get() != panel )
continue;
m_Panels.Remove( i );
break;
}
}
+236
View File
@@ -0,0 +1,236 @@
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======
//
// Purpose:
//
//=============================================================================
#include "tier1/UtlVector.h"
#include "tier1/convar.h"
#include "icvar.h"
#include "toolframework/itoolsystem.h"
#include "toolframework/itooldictionary.h"
#include "toolframework/ienginetool.h"
#include "toolutils/enginetools_int.h"
#include "ienginevgui.h"
#include "icvar.h"
#include "toolutils/vgui_tools.h"
#include "mathlib/mathlib.h"
#include "iregistry.h"
#include "datamodel/idatamodel.h"
#include "filesystem.h"
#include "p4lib/ip4.h"
#include "engine/ivdebugoverlay.h"
#include "tier3/tier3dm.h"
#include "datamodel/dmelementfactoryhelper.h"
#include "dmserializers/idmserializers.h"
#include "engine/ivmodelinfo.h"
//-----------------------------------------------------------------------------
// Singleton interfaces
//-----------------------------------------------------------------------------
IEngineTool *enginetools = NULL;
IEngineVGui *enginevgui = NULL;
IFileSystem *g_pFileSystem = NULL;
IVDebugOverlay *debugoverlay = NULL;
IVModelInfoClient *modelinfoclient = NULL;
//-----------------------------------------------------------------------------
// Assumed to be implemented within the specific tool DLL
//-----------------------------------------------------------------------------
bool ConnectTools( CreateInterfaceFn factory );
void CreateTools( );
void DisconnectTools( );
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void VGUI_CreateToolRootPanel( void )
{
// Just using PANEL_GAMEDLL in HL2 right now
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void VGUI_DestroyToolRootPanel( void )
{
}
//-----------------------------------------------------------------------------
// Global accessors for root tool panels
//-----------------------------------------------------------------------------
vgui::VPANEL VGui_GetToolRootPanel( void )
{
vgui::VPANEL root = enginevgui->GetPanel( PANEL_GAMEDLL );
return root;
}
vgui::VPANEL VGui_GetRootPanel( void )
{
vgui::VPANEL root = enginevgui->GetPanel( PANEL_ROOT );
return root;
}
//-----------------------------------------------------------------------------
// Implementation of IToolDictionary
//-----------------------------------------------------------------------------
class CToolDictionary : public CTier3DmAppSystem< IToolDictionary >
{
typedef CTier3DmAppSystem< IToolDictionary > BaseClass;
public:
CToolDictionary();
// Inherited from IAppSystem
virtual bool Connect( CreateInterfaceFn factory );
virtual void Disconnect();
virtual void *QueryInterface( const char *pInterfaceName );
virtual InitReturnVal_t Init();
virtual void Shutdown();
// Inherited from IToolDictionary
virtual void CreateTools();
virtual int GetToolCount() const;
virtual IToolSystem *GetTool( int index );
public:
void RegisterTool( IToolSystem *tool );
private:
CUtlVector< IToolSystem * > m_Tools;
};
//-----------------------------------------------------------------------------
// Singleton interface for tools
//-----------------------------------------------------------------------------
static CToolDictionary g_ToolDictionary;
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CToolDictionary, IToolDictionary, VTOOLDICTIONARY_INTERFACE_VERSION, g_ToolDictionary );
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CToolDictionary::CToolDictionary()
{
}
//-----------------------------------------------------------------------------
// Inherited from IAppSystem
//-----------------------------------------------------------------------------
bool CToolDictionary::Connect( CreateInterfaceFn factory )
{
if ( !BaseClass::Connect( factory ) )
return false;
// FIXME: This interface pointer is taken care of in tier2 + tier1
g_pFileSystem = g_pFullFileSystem;
enginevgui = ( IEngineVGui * )factory( VENGINE_VGUI_VERSION, NULL );
enginetools = ( IEngineTool * )factory( VENGINETOOL_INTERFACE_VERSION, NULL );
debugoverlay = ( IVDebugOverlay * )factory( VDEBUG_OVERLAY_INTERFACE_VERSION, NULL );
modelinfoclient = ( IVModelInfoClient *)factory( VMODELINFO_CLIENT_INTERFACE_VERSION, NULL );
if ( !enginevgui || !debugoverlay || !g_pCVar || !enginetools || !g_pFileSystem || ( !p4 && !CommandLine()->FindParm( "-nop4" ) ) || !modelinfoclient )
return false;
if ( !VGui_Startup( factory ) )
return false;
return ConnectTools( factory );
}
void CToolDictionary::Disconnect()
{
DisconnectTools();
enginevgui = NULL;
enginetools = NULL;
debugoverlay = NULL;
g_pFileSystem = NULL;
BaseClass::Disconnect( );
}
void *CToolDictionary::QueryInterface( const char *pInterfaceName )
{
if ( !V_strcmp( pInterfaceName, VTOOLDICTIONARY_INTERFACE_VERSION ) )
return (IToolDictionary*)this;
return NULL;
}
InitReturnVal_t CToolDictionary::Init()
{
InitReturnVal_t nRetVal = BaseClass::Init();
if ( nRetVal != INIT_OK )
return nRetVal;
MathLib_Init( 2.2f, 2.2f, 0.0f, 2.0f );
// Init registry
if ( !registry->Init( "Source\\Tools" ) )
{
Warning( "registry->Init failed\n" );
return INIT_FAILED;
}
// Re-enable this and VGui_Shutdown if we create root tool panels
// VGui_PostInit();
return INIT_OK;
}
void CToolDictionary::Shutdown()
{
// Re-enable this and VGui_PostInit if we create root tool panels
VGui_Shutdown();
registry->Shutdown();
BaseClass::Shutdown();
}
//-----------------------------------------------------------------------------
// Implementation of IToolDictionary methods
//-----------------------------------------------------------------------------
void CToolDictionary::CreateTools()
{
::CreateTools( );
}
int CToolDictionary::GetToolCount() const
{
return m_Tools.Count();
}
IToolSystem *CToolDictionary::GetTool( int index )
{
if ( index < 0 || index >= m_Tools.Count() )
{
return NULL;
}
return m_Tools[ index ];
}
void CToolDictionary::RegisterTool( IToolSystem *tool )
{
m_Tools.AddToTail( tool );
}
//-----------------------------------------------------------------------------
// Allows tools to install themselves into the dictionary
//-----------------------------------------------------------------------------
void RegisterTool( IToolSystem *tool )
{
g_ToolDictionary.RegisterTool( tool );
}
+131
View File
@@ -0,0 +1,131 @@
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======
//
// Purpose: Standard edit menu for tools
//
//=============================================================================
#include "toolutils/tooleditmenubutton.h"
#include "toolutils/toolmenubutton.h"
#include "tier1/keyvalues.h"
#include "toolutils/enginetools_int.h"
#include "datamodel/idatamodel.h"
#include "vgui_controls/menu.h"
#include "vgui/ilocalize.h"
#include "tier2/tier2.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
//-----------------------------------------------------------------------------
//
// The Edit menu
//
//-----------------------------------------------------------------------------
class CToolEditMenuButton : public CToolMenuButton
{
DECLARE_CLASS_SIMPLE( CToolEditMenuButton, CToolMenuButton );
public:
CToolEditMenuButton( vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionSignalTarget );
virtual void OnShowMenu( vgui::Menu *menu );
};
//-----------------------------------------------------------------------------
// Global function to create the file menu
//-----------------------------------------------------------------------------
CToolMenuButton* CreateToolEditMenuButton( vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionTarget )
{
return new CToolEditMenuButton( parent, panelName, text, pActionTarget );
}
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CToolEditMenuButton::CToolEditMenuButton( vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionSignalTarget )
: BaseClass( parent, panelName, text, pActionSignalTarget )
{
AddMenuItem( "undo", "#ToolEditUndo", new KeyValues ( "Command", "command", "OnUndo" ), pActionSignalTarget, NULL, "undo" );
AddMenuItem( "redo", "#ToolEditRedo", new KeyValues ( "Command", "command", "OnRedo" ), pActionSignalTarget, NULL, "redo" );
AddSeparator();
AddMenuItem( "describe", "#ToolEditDescribeUndo", new KeyValues ( "Command", "command", "OnDescribeUndo" ), pActionSignalTarget);
AddMenuItem( "wipeundo", "#ToolEditWipeUndo", new KeyValues ( "Command", "command", "OnWipeUndo" ), pActionSignalTarget);
AddSeparator();
AddMenuItem( "editkeybindings", "#BxEditKeyBindings", new KeyValues( "OnEditKeyBindings" ), pActionSignalTarget, NULL, "editkeybindings" );
SetMenu(m_pMenu);
}
void CToolEditMenuButton::OnShowMenu( vgui::Menu *menu )
{
BaseClass::OnShowMenu( menu );
// Update the menu
char sz[ 512 ];
int id;
id = m_Items.Find( "undo" );
if ( g_pDataModel->CanUndo() )
{
m_pMenu->SetItemEnabled( id, true );
wchar_t *fmt = g_pVGuiLocalize->Find( "ToolEditUndoStr" );
if ( fmt )
{
wchar_t desc[ 256 ];
g_pVGuiLocalize->ConvertANSIToUnicode( g_pDataModel->GetUndoDesc(), desc, sizeof( desc ) );
wchar_t buf[ 512 ];
g_pVGuiLocalize->ConstructString( buf, sizeof( buf ), fmt, 1, desc );
m_pMenu->UpdateMenuItem( id, buf, new KeyValues( "Command", "command", "OnUndo" ) );
}
else
{
m_pMenu->UpdateMenuItem( id, "#ToolEditUndo", new KeyValues( "Command", "command", "OnUndo" ) );
}
}
else
{
m_pMenu->SetItemEnabled( id, false );
m_pMenu->UpdateMenuItem( id, "#ToolEditUndo", new KeyValues( "Command", "command", "OnUndo" ) );
}
id = m_Items.Find( "redo" );
if ( g_pDataModel->CanRedo() )
{
m_pMenu->SetItemEnabled( id, true );
wchar_t *fmt = g_pVGuiLocalize->Find( "ToolEditRedoStr" );
if ( fmt )
{
wchar_t desc[ 256 ];
g_pVGuiLocalize->ConvertANSIToUnicode( g_pDataModel->GetRedoDesc(), desc, sizeof( desc ) );
wchar_t buf[ 512 ];
g_pVGuiLocalize->ConstructString( buf, sizeof( buf ), fmt, 1, desc );
m_pMenu->UpdateMenuItem( id, buf, new KeyValues( "Command", "command", "OnRedo" ) );
}
else
{
m_pMenu->UpdateMenuItem( id, sz, new KeyValues( "Command", "command", "OnRedo" ) );
}
}
else
{
m_pMenu->SetItemEnabled( id, false );
m_pMenu->UpdateMenuItem( id, "#ToolEditRedo", new KeyValues( "Command", "command", "OnRedo" ) );
}
id = m_Items.Find( "describe" );
if ( g_pDataModel->CanUndo() )
{
m_pMenu->SetItemEnabled( id, true );
}
else
{
m_pMenu->SetItemEnabled( id, false );
}
}
+132
View File
@@ -0,0 +1,132 @@
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======
//
// Purpose: Core Movie Maker UI API
//
//=============================================================================
#include "toolutils/toolmenubar.h"
#include "vgui_controls/Label.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
//
// Version that only has tool name and info
//
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CToolMenuBar::CToolMenuBar( CBaseToolSystem *pParent, const char *pPanelName ) :
BaseClass( (Panel *)pParent, pPanelName ),
m_pToolSystem( pParent )
{
m_pInfo = new Label( this, "Info", "" );
m_pToolName = new Label( this, "ToolName", "" );
}
CBaseToolSystem *CToolMenuBar::GetToolSystem()
{
return m_pToolSystem;
}
//-----------------------------------------------------------------------------
// Sets the tool bar's name
//-----------------------------------------------------------------------------
void CToolMenuBar::SetToolName( const char *pName )
{
m_pToolName->SetText( pName );
InvalidateLayout();
}
//-----------------------------------------------------------------------------
// Sets the tool bar info
//-----------------------------------------------------------------------------
void CToolMenuBar::SetInfo( const char *pInfo )
{
m_pInfo->SetText( pInfo );
InvalidateLayout();
}
//-----------------------------------------------------------------------------
// Lays out the menu bar
//-----------------------------------------------------------------------------
void CToolMenuBar::PerformLayout()
{
BaseClass::PerformLayout();
int w, h;
GetSize( w, h );
int cw, ch;
m_pInfo->GetContentSize( cw, ch );
int right = w - cw - 20;
m_pInfo->SetBounds( right, 0, cw, h );
m_pToolName->GetContentSize( cw, ch );
m_pToolName->SetBounds( right - cw - 5, 0, cw, h );
}
//-----------------------------------------------------------------------------
//
// Version that only has tool name, info, and file name
//
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CToolFileMenuBar::CToolFileMenuBar( CBaseToolSystem *parent, const char *panelName ) :
BaseClass( parent, panelName )
{
m_pFileName = new Label( this, "FileName", "" );
}
void CToolFileMenuBar::SetFileName( char const *name )
{
m_pFileName->SetText( name );
InvalidateLayout();
}
//-----------------------------------------------------------------------------
// Performs layout
//-----------------------------------------------------------------------------
void CToolFileMenuBar::PerformLayout()
{
BaseClass::PerformLayout();
int w, h;
GetSize( w, h );
int cw, ch;
m_pInfo->GetContentSize( cw, ch );
int right = w - cw - 20;
m_pToolName->GetContentSize( cw, ch );
int barx, bary;
GetContentSize( barx, bary );
int faredge = right - cw - 5- 2;
int nearedge = barx + 2;
int mid = ( nearedge + faredge ) * 0.5f;
m_pFileName->GetContentSize( cw, ch );
m_pFileName->SetBounds( mid - cw * 0.5f, 0, cw, h );
}
+58
View File
@@ -0,0 +1,58 @@
//-----------------------------------------------------------------------------
// TOOLUTILS.VPC
//
// Project Script
//-----------------------------------------------------------------------------
$Macro SRCDIR "..\.."
$Macro OUTLIBDIR "$SRCDIR\lib\public"
$Include "$SRCDIR\vpc_scripts\source_lib_win32_base.vpc"
$Project "Toolutils"
{
$Folder "Source Files"
{
$File "attributeelementchoicelist.cpp"
$File "basepropertiescontainer.cpp"
$File "basestatusbar.cpp"
$File "BaseToolSystem.cpp"
$File "ConsolePage.cpp"
$File "miniviewport.cpp"
$File "recentfilelist.cpp"
$File "savewindowpositions.cpp"
$File "ScriptEditorPanel.cpp"
$File "tool_main.cpp"
$File "tooleditmenubutton.cpp"
$File "ToolFileMenuButton.cpp"
$File "ToolHelpMenuButton.cpp"
$File "toolmenubar.cpp"
$File "ToolMenuButton.cpp"
$File "ToolSwitchMenuButton.cpp"
$File "ToolUI.cpp"
$File "vgui_tools.cpp"
}
$Folder "Header Files"
{
$File "$SRCDIR\public\toolutils\AttributeElementChoiceList.h"
$File "$SRCDIR\public\toolutils\basepropertiescontainer.h"
$File "$SRCDIR\public\toolutils\basestatusbar.h"
$File "$SRCDIR\public\toolutils\BaseToolSystem.h"
$File "$SRCDIR\public\toolutils\DmeMdlRenderable.h"
$File "$SRCDIR\public\toolutils\DmeRenderable.h"
$File "$SRCDIR\public\toolutils\enginetools_int.h"
$File "$SRCDIR\public\toolutils\miniviewport.h"
$File "$SRCDIR\public\toolutils\recentfilelist.h"
$File "$SRCDIR\public\toolutils\savewindowpositions.h"
$File "$SRCDIR\public\toolutils\ScriptEditorPanel.h"
$File "$SRCDIR\public\toolutils\ToolEditMenuButton.h"
$File "$SRCDIR\public\toolutils\ToolFileMenuButton.h"
$File "$SRCDIR\public\toolutils\ToolHelpMenuButton.h"
$File "$SRCDIR\public\toolutils\toolmenubar.h"
$File "$SRCDIR\public\toolutils\ToolMenuButton.h"
$File "$SRCDIR\public\toolutils\ToolSwitchMenuButton.h"
$File "ToolUI.h"
$File "$SRCDIR\public\toolutils\vgui_tools.h"
}
}
+13
View File
@@ -0,0 +1,13 @@
"vpc_cache"
{
"CacheVersion" "1"
"win32"
{
"CRCFile" "toolutils.vcxproj.vpc_crc"
"OutputFiles"
{
"0" "toolutils.vcxproj"
"1" "toolutils.vcxproj.filters"
}
}
}
+67
View File
@@ -0,0 +1,67 @@
//========= Copyright © 1996-2001, Valve LLC, All rights reserved. ============
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
#include "toolutils/vgui_tools.h"
#include "ienginevgui.h"
#include <vgui/isurface.h>
#include <vgui/IVGui.h>
#include <vgui/IInput.h>
#include "tier0/vprof.h"
#include <vgui_controls/Panel.h>
#include <KeyValues.h>
#include <dme_controls/dmeControls.h>
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
// Purpose:
// Input : appSystemFactory -
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool VGui_Startup( CreateInterfaceFn appSystemFactory )
{
// All of the various tools .dlls expose GetVGuiControlsModuleName() to us to make sure we don't have communication across .dlls
if ( !vgui::VGui_InitDmeInterfacesList( GetVGuiControlsModuleName(), &appSystemFactory, 1 ) )
return false;
return true;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : -
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool VGui_PostInit()
{
// Create any root panels for .dll
VGUI_CreateToolRootPanel();
// Make sure we have a panel
VPANEL root = VGui_GetToolRootPanel();
if ( !root )
{
return false;
}
return true;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : -
//-----------------------------------------------------------------------------
void VGui_Shutdown()
{
VGUI_DestroyToolRootPanel();
// Make sure anything "marked for deletion"
// actually gets deleted before this dll goes away
vgui::ivgui()->RunFrame();
}
@@ -0,0 +1,58 @@
// ----------------------------------------- //
// File generated by VPC //
// ----------------------------------------- //
Source file: F:\csgo_64\cstrike15_src\common\debug_dll_check.cpp
Debug output file: F:\csgo_64\cstrike15_src\common\debug_dll_check.cpp
Release output file: F:\csgo_64\cstrike15_src\common\debug_dll_check.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\public\interpolatortypes.cpp
Debug output file: F:\csgo_64\cstrike15_src\public\interpolatortypes.cpp
Release output file: F:\csgo_64\cstrike15_src\public\interpolatortypes.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\public\tier0\memoverride.cpp
Debug output file: F:\csgo_64\cstrike15_src\public\tier0\memoverride.cpp
Release output file: F:\csgo_64\cstrike15_src\public\tier0\memoverride.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\public\movieobjects\movieobjects.cpp
Debug output file: F:\csgo_64\cstrike15_src\public\movieobjects\movieobjects.cpp
Release output file: F:\csgo_64\cstrike15_src\public\movieobjects\movieobjects.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\public\registry.cpp
Debug output file: F:\csgo_64\cstrike15_src\public\registry.cpp
Release output file: F:\csgo_64\cstrike15_src\public\registry.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\public\sentence.cpp
Debug output file: F:\csgo_64\cstrike15_src\public\sentence.cpp
Release output file: F:\csgo_64\cstrike15_src\public\sentence.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\public\vgui_controls\vgui_controls.cpp
Debug output file: F:\csgo_64\cstrike15_src\public\vgui_controls\vgui_controls.cpp
Release output file: F:\csgo_64\cstrike15_src\public\vgui_controls\vgui_controls.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\tools\vmt\vmtdoc.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\vmt\vmtdoc.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\vmt\vmtdoc.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\tools\vmt\vmttool.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\vmt\vmttool.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\vmt\vmttool.cpp
Containing unity file:
PCH file:
+62
View File
@@ -0,0 +1,62 @@
//-----------------------------------------------------------------------------
// VMT.VPC
//
// Project Script
//-----------------------------------------------------------------------------
$Macro SRCDIR "..\.."
$Macro OUTBINDIR "$SRCDIR\..\game\bin\tools"
$Include "$SRCDIR\vpc_scripts\source_dll_win32_base.vpc"
$Configuration
{
$Compiler
{
$AdditionalIncludeDirectories "$BASE,../common"
}
$Linker
{
$AdditionalDependencies "$BASE Psapi.lib"
}
}
$Project "Vmt"
{
$Folder "Source Files"
{
$File "$SRCDIR\public\interpolatortypes.cpp"
$File "$SRCDIR\public\movieobjects\movieobjects.cpp"
$File "$SRCDIR\public\registry.cpp"
$File "$SRCDIR\public\vgui_controls\vgui_controls.cpp"
$File "$SRCDIR\public\sentence.cpp"
$File "vmtdoc.cpp"
$File "vmttool.cpp"
}
$Folder "Header Files"
{
$File "$SRCDIR\public\interpolatortypes.h"
$File "vmtdoc.h"
$File "vmttool.h"
}
$Folder "Link Libraries"
{
$File "$SRCDIR\lib\public\bitmap.lib"
$File "$SRCDIR\lib\public\bonesetup.lib"
$File "$SRCDIR\lib\public\datamodel.lib"
$File "$SRCDIR\lib\public\dmxloader.lib"
$File "$SRCDIR\lib\public\dme_controls.lib"
$File "$SRCDIR\lib\public\dmserializers.lib"
$File "$SRCDIR\lib\public\mathlib.lib"
$File "$SRCDIR\lib\public\matsys_controls.lib"
$File "$SRCDIR\lib\public\movieobjects.lib"
$File "$SRCDIR\lib\public\particles.lib"
$File "$SRCDIR\lib\public\tier2.lib"
$File "$SRCDIR\lib\public\tier3.lib"
$File "$SRCDIR\lib\public\toolutils.lib"
$File "$SRCDIR\lib\public\vgui_controls.lib"
}
}
+13
View File
@@ -0,0 +1,13 @@
"vpc_cache"
{
"CacheVersion" "1"
"win32"
{
"CRCFile" "vmt.vcxproj.vpc_crc"
"OutputFiles"
{
"0" "vmt.vcxproj"
"1" "vmt.vcxproj.filters"
}
}
}
+1084
View File
File diff suppressed because it is too large Load Diff
+133
View File
@@ -0,0 +1,133 @@
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
// $NoKeywords: $
//
//===========================================================================//
#ifndef VMTDOC_H
#define VMTDOC_H
#ifdef _WIN32
#pragma once
#endif
#include "dme_controls/inotifyui.h"
#include "datamodel/dmehandle.h"
#include "materialsystem/materialsystemutil.h"
#include "tier1/utlstring.h"
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class IVMTDocCallback;
class IShader;
enum ShaderParamType_t;
class IMaterial;
class IShader;
//-----------------------------------------------------------------------------
// Contains all editable state
//-----------------------------------------------------------------------------
class CVMTDoc : public IDmNotify
{
public:
CVMTDoc( IVMTDocCallback *pCallback );
~CVMTDoc();
// Inherited from INotifyUI
virtual void NotifyDataChanged( const char *pReason, int nNotifySource, int nNotifyFlags );
// Sets/Gets the file name
const char *GetFileName();
void SetFileName( const char *pFileName );
// Dirty bits (has it changed since the last time it was saved?)
void SetDirty( bool bDirty );
bool IsDirty() const;
// Creates a new act busy list
void CreateNew();
// Saves/loads from file
bool LoadFromFile( const char *pFileName );
bool SaveToFile( );
// Returns the root object
CDmElement *GetRootObject();
// Called when data changes (see INotifyUI for flags)
void OnDataChanged( const char *pReason, int nNotifySource, int nNotifyFlags );
// Sets the shader in the material
void SetShader( const char *pShaderName );
// Gets the preview material
IMaterial *GetPreviewMaterial();
// Sets shader parameters to the default for that shader
void SetParamsToDefault();
private:
// Creates the root element
bool CreateRootElement();
// Add attribute for shader parameter
CDmAttribute* AddAttributeForShaderParameter( CDmElement *pMaterial, const char *pParamName, ShaderParamType_t paramType );
// Add a single shader parameter if it doesn't exist
void AddNewShaderParam( CDmElement *pMaterial, const char *pParamName, ShaderParamType_t paramType, const char *pValue );
// Add all shader parameters that don't currently exist
void AddNewShaderParams( CDmElement *pMaterial, IShader *pShader );
// Is this attribute a shader parameter?
bool IsShaderParam( CDmAttribute* pAttribute );
// Remove all shader parameters that don't exist in the new shader
void RemoveUnusedShaderParams( CDmElement *pMaterial, IShader *pShader, IShader *pOldShader );
// Remove all shader parameters
void RemoveAllShaderParams( CDmElement *pMaterial );
// Finds a shader
IShader *FindShader( const char *pShaderName );
// Updates the preview material
void UpdatePreviewMaterial();
// Copies VMT parameters into the root
void CopyParamsFromVMT( CDmElement *pVMT );
// A couple methods to set param values from strings (OLD METHOD!)
bool SetVMatrixParamValue( CDmAttribute *pAttribute, const char *pValue );
bool SetVector2DParamValue( CDmAttribute *pAttribute, const char *pValue );
bool SetVector3DParamValue( CDmAttribute *pAttribute, const char *pValue );
bool SetVector4DParamValue( CDmAttribute *pAttribute, const char *pValue );
bool SetColorParamValue( CDmAttribute *pAttribute, const char *pValue );
// Sets an attribute value from the shader param default
void SetAttributeValueFromDefault( CDmElement *pMaterial, CDmAttribute *pAttribute, const char *pValue );
// Hooks the preview to an existing material, if there is one
void SetupPreviewMaterial( );
// Prior to saving to disk, extract all shader parameters which == the default
CDmElement* ExtractDefaultParameters( );
IVMTDocCallback *m_pCallback;
CMaterialReference m_pScratchMaterial;
CMaterialReference m_pPreviewMaterial;
CDmeHandle< CDmElement > m_hRoot;
CUtlString m_CurrentShader;
IShader *m_pCurrentIShader;
char m_pFileName[512];
bool m_bDirty;
};
#endif // VMTDOC_H
File diff suppressed because it is too large Load Diff
+50
View File
@@ -0,0 +1,50 @@
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======
//
// Purpose: VMT tool; main UI smarts class
//
//=============================================================================
#ifndef VMTTOOL_H
#define VMTTOOL_H
#ifdef _WIN32
#pragma once
#endif
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class CDmeEditorTypeDictionary;
//-----------------------------------------------------------------------------
// Singleton interfaces
//-----------------------------------------------------------------------------
extern CDmeEditorTypeDictionary *g_pEditorTypeDict;
//-----------------------------------------------------------------------------
// Allows the doc to call back into the VMT editor tool
//-----------------------------------------------------------------------------
class IVMTDocCallback
{
public:
// Called by the doc when the data changes
virtual void OnDocChanged( const char *pReason, int nNotifySource, int nNotifyFlags ) = 0;
// Update the editor dict based on the current material parameters
virtual void AddShaderParameter( const char *pParam, const char *pWidget, const char *pTextType ) = 0;
// Update the editor dict based on the current material parameters
virtual void RemoveShaderParameter( const char *pParam ) = 0;
// Adds flags, tool parameters
virtual void AddFlagParameter( const char *pParam ) = 0;
virtual void AddToolParameter( const char *pParam, const char *pWidget = NULL, const char *pTextType = NULL ) = 0;
virtual void RemoveAllFlagParameters() = 0;
virtual void RemoveAllToolParameters() = 0;
};
#endif // VMTTOOL_H