mirror of
https://github.com/celisej567/source-engine.git
synced 2025-12-31 21:48:22 +03:00
1
This commit is contained in:
54
tools/actbusy/actbusy.vpc
Normal file
54
tools/actbusy/actbusy.vpc
Normal file
@@ -0,0 +1,54 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// ACTBUSY.VPC
|
||||
//
|
||||
// Project Script
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
$Macro SRCDIR "..\.."
|
||||
$Macro OUTBINDIR "$SRCDIR\..\game\bin\tools"
|
||||
|
||||
$Include "$SRCDIR\vpc_scripts\source_dll_base.vpc"
|
||||
|
||||
$Configuration
|
||||
{
|
||||
$Linker
|
||||
{
|
||||
$AdditionalDependencies "$BASE psapi.lib"
|
||||
}
|
||||
}
|
||||
|
||||
$Project "Actbusy"
|
||||
{
|
||||
$Folder "Source Files"
|
||||
{
|
||||
$File "actbusydoc.cpp"
|
||||
$File "actbusytool.cpp"
|
||||
$File "$SRCDIR\public\interpolatortypes.cpp"
|
||||
$File "$SRCDIR\public\movieobjects\movieobjects.cpp"
|
||||
$File "$SRCDIR\public\registry.cpp"
|
||||
$File "$SRCDIR\public\vgui_controls\vgui_controls.cpp"
|
||||
}
|
||||
|
||||
$Folder "Header Files"
|
||||
{
|
||||
$File "actbusydoc.h"
|
||||
$File "actbusytool.h"
|
||||
$File "$SRCDIR\public\interpolatortypes.h"
|
||||
}
|
||||
|
||||
$Folder "Link Libraries"
|
||||
{
|
||||
$Lib dmxloader
|
||||
$Lib datamodel
|
||||
$Lib dme_controls
|
||||
$Lib dmserializers
|
||||
$Lib mathlib
|
||||
$Lib matsys_controls
|
||||
$Lib movieobjects
|
||||
$Lib sfmobjects
|
||||
$Lib tier2
|
||||
$Lib tier3
|
||||
$Lib toolutils
|
||||
$Lib vgui_controls
|
||||
}
|
||||
}
|
||||
184
tools/actbusy/actbusydoc.cpp
Normal file
184
tools/actbusy/actbusydoc.cpp
Normal file
@@ -0,0 +1,184 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#include "actbusydoc.h"
|
||||
#include "datamodel/dmelement.h"
|
||||
#include "actbusytool.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CActBusyDoc::CActBusyDoc( IActBusyDocCallback *pCallback ) : m_pCallback( pCallback )
|
||||
{
|
||||
m_hRoot = NULL;
|
||||
m_pFileName[0] = 0;
|
||||
m_bDirty = false;
|
||||
g_pDataModel->InstallNotificationCallback( this );
|
||||
}
|
||||
|
||||
CActBusyDoc::~CActBusyDoc()
|
||||
{
|
||||
g_pDataModel->RemoveNotificationCallback( this );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Inherited from INotifyUI
|
||||
//-----------------------------------------------------------------------------
|
||||
void CActBusyDoc::NotifyDataChanged( const char *pReason, int nNotifySource, int nNotifyFlags )
|
||||
{
|
||||
OnDataChanged( pReason, nNotifySource, nNotifyFlags );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets the file name
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *CActBusyDoc::GetFileName()
|
||||
{
|
||||
return m_pFileName;
|
||||
}
|
||||
|
||||
void CActBusyDoc::SetFileName( const char *pFileName )
|
||||
{
|
||||
Q_strncpy( m_pFileName, pFileName, sizeof( m_pFileName ) );
|
||||
SetDirty( true );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Dirty bits
|
||||
//-----------------------------------------------------------------------------
|
||||
void CActBusyDoc::SetDirty( bool bDirty )
|
||||
{
|
||||
m_bDirty = bDirty;
|
||||
}
|
||||
|
||||
bool CActBusyDoc::IsDirty() const
|
||||
{
|
||||
return m_bDirty;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Creates a new act busy
|
||||
//-----------------------------------------------------------------------------
|
||||
void CActBusyDoc::CreateNew()
|
||||
{
|
||||
Assert( !m_hRoot.Get() );
|
||||
|
||||
// This is not undoable
|
||||
CDisableUndoScopeGuard guard;
|
||||
|
||||
Q_strncpy( m_pFileName, "untitled", sizeof( m_pFileName ) );
|
||||
DmFileId_t fileid = g_pDataModel->FindOrCreateFileId( m_pFileName );
|
||||
|
||||
// Create the main element
|
||||
m_hRoot = g_pDataModel->CreateElement( "DmElement", "ActBusyList", fileid );
|
||||
if ( m_hRoot == DMELEMENT_HANDLE_INVALID )
|
||||
return;
|
||||
|
||||
g_pDataModel->SetFileRoot( fileid, m_hRoot );
|
||||
|
||||
// Each act busy list needs to have an editortype associated with it so it displays nicely in editors
|
||||
m_hRoot->SetValue( "editorType", "actBusyList" );
|
||||
m_hRoot->AddAttribute( "children", AT_ELEMENT_ARRAY );
|
||||
|
||||
SetDirty( false );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Saves/loads from file
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CActBusyDoc::LoadFromFile( const char *pFileName )
|
||||
{
|
||||
Assert( !m_hRoot.Get() );
|
||||
|
||||
SetDirty( false );
|
||||
m_hRoot = NULL;
|
||||
|
||||
Q_strncpy( m_pFileName, pFileName, sizeof( m_pFileName ) );
|
||||
if ( !m_pFileName[0] )
|
||||
return false;
|
||||
|
||||
// This is not undoable
|
||||
CDisableUndoScopeGuard guard;
|
||||
|
||||
CDmElement *root = NULL;
|
||||
g_pDataModel->RestoreFromFile( m_pFileName, NULL, "actbusy", &root );
|
||||
m_hRoot = root;
|
||||
OnDataChanged( "CActBusyDoc::LoadFromFile", NOTIFY_SOURCE_APPLICATION, NOTIFY_CHANGE_TOPOLOGICAL );
|
||||
SetDirty( false );
|
||||
return true;
|
||||
}
|
||||
|
||||
void CActBusyDoc::SaveToFile( )
|
||||
{
|
||||
if ( m_hRoot.Get() && m_pFileName && m_pFileName[0] )
|
||||
{
|
||||
g_pDataModel->SaveToFile( m_pFileName, NULL, "keyvalues", "actbusy", m_hRoot );
|
||||
}
|
||||
|
||||
SetDirty( false );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Creates a new act busy
|
||||
//-----------------------------------------------------------------------------
|
||||
void CActBusyDoc::CreateActBusy()
|
||||
{
|
||||
CDmElement *pRoot = GetRootObject();
|
||||
if ( !pRoot )
|
||||
return;
|
||||
|
||||
// This is undoable
|
||||
CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, "Add ActBusy", "Add ActBusy" );
|
||||
|
||||
DmFileId_t fileid = g_pDataModel->FindOrCreateFileId( m_pFileName );
|
||||
|
||||
// Create the main element
|
||||
CDmeHandle<CDmElement> hActBusy = g_pDataModel->CreateElement( "DmElement", "ActBusy", fileid );
|
||||
if ( hActBusy == DMELEMENT_HANDLE_INVALID )
|
||||
return;
|
||||
|
||||
hActBusy->SetValue( "editorType", "actBusy" );
|
||||
hActBusy->SetValue( "busy_anim", "" );
|
||||
hActBusy->SetValue( "entry_anim", "" );
|
||||
hActBusy->SetValue( "exit_anim", "" );
|
||||
hActBusy->SetValue( "busy_sequence", "" );
|
||||
hActBusy->SetValue( "entry_sequence", "" );
|
||||
hActBusy->SetValue( "exit_sequence", "" );
|
||||
hActBusy->SetValue( "min_time", 0.0f );
|
||||
hActBusy->SetValue( "max_time", 0.0f );
|
||||
hActBusy->SetValue( "interrupts", "BA_INT_NONE" );
|
||||
|
||||
CDmrElementArray<> children( pRoot, "children" );
|
||||
children.AddToTail( hActBusy );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the root object
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmElement *CActBusyDoc::GetRootObject()
|
||||
{
|
||||
return m_hRoot;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called when data changes
|
||||
//-----------------------------------------------------------------------------
|
||||
void CActBusyDoc::OnDataChanged( const char *pReason, int nNotifySource, int nNotifyFlags )
|
||||
{
|
||||
SetDirty( nNotifyFlags & NOTIFY_SETDIRTYFLAG ? true : false );
|
||||
m_pCallback->OnDocChanged( pReason, nNotifySource, nNotifyFlags );
|
||||
}
|
||||
71
tools/actbusy/actbusydoc.h
Normal file
71
tools/actbusy/actbusydoc.h
Normal file
@@ -0,0 +1,71 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef ACTBUSYDOC_H
|
||||
#define ACTBUSYDOC_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "dme_controls/inotifyui.h"
|
||||
#include "datamodel/dmehandle.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class IActBusyDocCallback;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Contains all editable state
|
||||
//-----------------------------------------------------------------------------
|
||||
class CActBusyDoc : public IDmNotify
|
||||
{
|
||||
public:
|
||||
CActBusyDoc( IActBusyDocCallback *pCallback );
|
||||
~CActBusyDoc();
|
||||
|
||||
// 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 );
|
||||
void SaveToFile( );
|
||||
|
||||
// Returns the root object
|
||||
CDmElement *GetRootObject();
|
||||
|
||||
// Called when data changes
|
||||
void OnDataChanged( const char *pReason, int nNotifySource, int nNotifyFlags );
|
||||
|
||||
// Creates a new actbusy
|
||||
void CreateActBusy();
|
||||
|
||||
private:
|
||||
IActBusyDocCallback *m_pCallback;
|
||||
CDmeHandle< CDmElement > m_hRoot;
|
||||
char m_pFileName[512];
|
||||
bool m_bDirty;
|
||||
};
|
||||
|
||||
|
||||
#endif // ACTBUSYDOC_H
|
||||
1224
tools/actbusy/actbusytool.cpp
Normal file
1224
tools/actbusy/actbusytool.cpp
Normal file
File diff suppressed because it is too large
Load Diff
38
tools/actbusy/actbusytool.h
Normal file
38
tools/actbusy/actbusytool.h
Normal file
@@ -0,0 +1,38 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Act busy tool; main UI smarts class
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#ifndef ACTBUSYTOOL_H
|
||||
#define ACTBUSYTOOL_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class CDmeEditorTypeDictionary;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Singleton interfaces
|
||||
//-----------------------------------------------------------------------------
|
||||
extern CDmeEditorTypeDictionary *g_pEditorTypeDict;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Allows the doc to call back into the act busy tool
|
||||
//-----------------------------------------------------------------------------
|
||||
class IActBusyDocCallback
|
||||
{
|
||||
public:
|
||||
// Called by the doc when the data changes
|
||||
virtual void OnDocChanged( const char *pReason, int nNotifySource, int nNotifyFlags ) = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif // ACTBUSYTOOL_H
|
||||
64
tools/commedit/commedit.vpc
Normal file
64
tools/commedit/commedit.vpc
Normal file
@@ -0,0 +1,64 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// COMMEDIT.VPC
|
||||
//
|
||||
// Project Script
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
$Macro SRCDIR "..\.."
|
||||
$Macro OUTBINDIR "$SRCDIR\..\game\bin\tools"
|
||||
|
||||
$Include "$SRCDIR\vpc_scripts\source_dll_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"
|
||||
{
|
||||
$Lib datamodel
|
||||
$Lib dme_controls
|
||||
$Lib dmserializers
|
||||
$Lib mathlib
|
||||
$Lib matsys_controls
|
||||
$Lib movieobjects
|
||||
$Lib sfmobjects
|
||||
$Lib tier2
|
||||
$Lib tier3
|
||||
$Lib toolutils
|
||||
$Lib vgui_controls
|
||||
}
|
||||
}
|
||||
443
tools/commedit/commeditdoc.cpp
Normal file
443
tools/commedit/commeditdoc.cpp
Normal file
@@ -0,0 +1,443 @@
|
||||
//========= Copyright 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;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Handles creation of the right element for a keyvalue
|
||||
//-----------------------------------------------------------------------------
|
||||
class CElementForKeyValueCallback : public IElementForKeyValueCallback
|
||||
{
|
||||
public:
|
||||
const char *GetElementForKeyValue( const char *pszKeyName, int iNestingLevel )
|
||||
{
|
||||
if ( iNestingLevel == 1 && !Q_strncmp(pszKeyName, "entity", 6) )
|
||||
return "DmeCommentaryNodeEntity";
|
||||
|
||||
return NULL;
|
||||
}
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// 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 guardFile;
|
||||
|
||||
CDmElement *pTXT = NULL;
|
||||
|
||||
CElementForKeyValueCallback KeyValuesCallback;
|
||||
g_pDataModel->SetKeyValuesElementCallback( &KeyValuesCallback );
|
||||
DmFileId_t fileid = g_pDataModel->RestoreFromFile( pFileName, NULL, "keyvalues", &pTXT );
|
||||
g_pDataModel->SetKeyValuesElementCallback( NULL );
|
||||
|
||||
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::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<CUtlString>( "precommands", "" );
|
||||
pNode->SetValue<CUtlString>( "postcommands", "" );
|
||||
pNode->SetValue<CUtlString>( "commentaryfile", "" );
|
||||
pNode->SetValue<CUtlString>( "viewtarget", "" );
|
||||
pNode->SetValue<CUtlString>( "viewposition", "" );
|
||||
pNode->SetValue<int>( "prevent_movement", 0 );
|
||||
pNode->SetValue<CUtlString>( "speakers", "" );
|
||||
pNode->SetValue<CUtlString>( "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" ) )
|
||||
{
|
||||
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 );
|
||||
}
|
||||
|
||||
|
||||
92
tools/commedit/commeditdoc.h
Normal file
92
tools/commedit/commeditdoc.h
Normal file
@@ -0,0 +1,92 @@
|
||||
//========= Copyright 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 );
|
||||
|
||||
// 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
|
||||
1284
tools/commedit/commedittool.cpp
Normal file
1284
tools/commedit/commedittool.cpp
Normal file
File diff suppressed because it is too large
Load Diff
231
tools/commedit/commedittool.h
Normal file
231
tools/commedit/commedittool.h
Normal file
@@ -0,0 +1,231 @@
|
||||
//========= Copyright 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();
|
||||
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:
|
||||
// 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;
|
||||
bool m_bDroppingCommentaryNodes;
|
||||
CDmeHandle< CDmeCommentaryNodeEntity > m_hPreviewNode;
|
||||
CDmeHandle< CDmeCommentaryNodeEntity > m_hPreviewTarget;
|
||||
CToolWindowFactory< ToolWindow > m_ToolWindowFactory;
|
||||
};
|
||||
|
||||
extern CCommEditTool *g_pCommEditTool;
|
||||
|
||||
#endif // COMMEDITTOOL_H
|
||||
283
tools/commedit/commentarynodebrowserpanel.cpp
Normal file
283
tools/commedit/commentarynodebrowserpanel.cpp
Normal file
@@ -0,0 +1,283 @@
|
||||
//========= Copyright 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();
|
||||
}
|
||||
|
||||
67
tools/commedit/commentarynodebrowserpanel.h
Normal file
67
tools/commedit/commentarynodebrowserpanel.h
Normal file
@@ -0,0 +1,67 @@
|
||||
//========= Copyright 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
|
||||
458
tools/commedit/commentarypropertiespanel.cpp
Normal file
458
tools/commedit/commentarypropertiespanel.cpp
Normal file
@@ -0,0 +1,458 @@
|
||||
//========= Copyright 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_pCommentaryNodeScroll = new vgui::ScrollableEditablePanel( this, m_pCommentaryNode, "CommentaryNodeScroll" );
|
||||
m_pInfoTargetScroll = new vgui::ScrollableEditablePanel( this, m_pInfoTarget, "InfoTargetScroll" );
|
||||
|
||||
LoadControlSettings( "resource/commentarypropertiespanel.res" );
|
||||
|
||||
m_pCommentaryNodeScroll->SetVisible( false );
|
||||
m_pInfoTargetScroll->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 )
|
||||
{
|
||||
Vector vec;
|
||||
for ( int i = 0; i < 3; ++i )
|
||||
{
|
||||
int nLen = pEntry[i]->GetTextLength();
|
||||
char *pBuf = (char*)_alloca( nLen+1 );
|
||||
pEntry[i]->GetText( pBuf, nLen+1 );
|
||||
vec[i] = atof( pBuf );
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// 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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets the object to look at
|
||||
//-----------------------------------------------------------------------------
|
||||
void CCommentaryPropertiesPanel::SetObject( CDmeCommentaryNodeEntity *pEntity )
|
||||
{
|
||||
m_hEntity = pEntity;
|
||||
m_pCommentaryNodeScroll->SetVisible( false );
|
||||
m_pInfoTargetScroll->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(), "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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// 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->SetDeleteSelfOnClose( 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 );
|
||||
}
|
||||
|
||||
|
||||
113
tools/commedit/commentarypropertiespanel.h
Normal file
113
tools/commedit/commentarypropertiespanel.h
Normal file
@@ -0,0 +1,113 @@
|
||||
//========= Copyright 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();
|
||||
|
||||
// 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();
|
||||
|
||||
// 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_pCommentaryNode;
|
||||
vgui::EditablePanel *m_pInfoTarget;
|
||||
|
||||
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];
|
||||
|
||||
CDmeHandle< CDmeCommentaryNodeEntity > m_hEntity;
|
||||
};
|
||||
|
||||
|
||||
#endif // COMMENTARYPROPERTIESPANEL_H
|
||||
339
tools/commedit/dmecommentarynodeentity.cpp
Normal file
339
tools/commedit/dmecommentarynodeentity.cpp
Normal file
@@ -0,0 +1,339 @@
|
||||
//========= Copyright 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 );
|
||||
if ( !Q_stricmp( m_ClassName, "point_commentary_node" ) )
|
||||
{
|
||||
SetModelName( "models/extras/info_speech.mdl" );
|
||||
GetMDL()->m_flPlaybackRate = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
SetModelName( NULL );
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Is the renderable transparent?
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeCommentaryNodeEntity::IsTransparent( void )
|
||||
{
|
||||
return m_bIsDirty || m_bInfoTarget || BaseClass::IsTransparent();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// 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 )
|
||||
{
|
||||
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 );
|
||||
}
|
||||
|
||||
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
tools/commedit/dmecommentarynodeentity.h
Normal file
100
tools/commedit/dmecommentarynodeentity.h
Normal file
@@ -0,0 +1,100 @@
|
||||
//========= Copyright 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 );
|
||||
virtual void GetRenderBounds( Vector& mins, Vector& maxs );
|
||||
virtual bool IsTransparent( 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
tools/commedit/entityreportpanel.cpp
Normal file
581
tools/commedit/entityreportpanel.cpp
Normal file
@@ -0,0 +1,581 @@
|
||||
//========= Copyright 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
|
||||
246
tools/foundry/DmeVMFEntity.cpp
Normal file
246
tools/foundry/DmeVMFEntity.cpp
Normal file
@@ -0,0 +1,246 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "DmeVMFEntity.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 "foundrytool.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( DmeVMFEntity, CDmeVMFEntity );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeVMFEntity::OnConstruction()
|
||||
{
|
||||
m_ClassName.Init( this, "classname" );
|
||||
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_hEngineEntity = HTOOLHANDLE_INVALID;
|
||||
|
||||
m_Wireframe.Init( "debug/debugwireframe", "editor" );
|
||||
}
|
||||
|
||||
void CDmeVMFEntity::OnDestruction()
|
||||
{
|
||||
// Unhook it from the engine
|
||||
AttachToEngineEntity( false );
|
||||
m_Wireframe.Shutdown();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called whem attributes change
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeVMFEntity::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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the entity ID
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeVMFEntity::GetEntityId() const
|
||||
{
|
||||
return atoi( GetName() );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Entity Key iteration
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeVMFEntity::IsEntityKey( CDmAttribute *pEntityKey )
|
||||
{
|
||||
return pEntityKey->IsFlagSet( FATTRIB_USERDEFINED );
|
||||
}
|
||||
|
||||
CDmAttribute *CDmeVMFEntity::FirstEntityKey()
|
||||
{
|
||||
for ( CDmAttribute *pAttribute = FirstAttribute(); pAttribute; pAttribute = pAttribute->NextAttribute() )
|
||||
{
|
||||
if ( IsEntityKey( pAttribute ) )
|
||||
return pAttribute;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CDmAttribute *CDmeVMFEntity::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 CDmeVMFEntity::AttachToEngineEntity( bool bAttach )
|
||||
{
|
||||
if ( !bAttach )
|
||||
{
|
||||
m_hEngineEntity = HTOOLHANDLE_INVALID;
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Draws the helper for the entity
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeVMFEntity::DrawModel( int flags )
|
||||
{
|
||||
Assert( IsDrawingInEngine() );
|
||||
|
||||
matrix3x4_t mat;
|
||||
AngleMatrix( m_vecLocalAngles, m_vecLocalOrigin, mat );
|
||||
|
||||
CMatRenderContextPtr rc( g_pMaterialSystem->GetRenderContext() );
|
||||
|
||||
rc->MatrixMode( MATERIAL_MODEL );
|
||||
rc->PushMatrix();
|
||||
rc->LoadMatrix( mat );
|
||||
|
||||
int nTheta = 20, nPhi = 20;
|
||||
float flRadius = SPHERE_RADIUS;
|
||||
int nVertices = nTheta * nPhi;
|
||||
int nIndices = 2 * ( nTheta + 1 ) * ( nPhi - 1 );
|
||||
|
||||
rc->FogMode( MATERIAL_FOG_NONE );
|
||||
rc->SetNumBoneWeights( 0 );
|
||||
rc->Bind( m_Wireframe );
|
||||
rc->CullMode( MATERIAL_CULLMODE_CW );
|
||||
|
||||
IMesh* pMesh = rc->GetDynamicMesh();
|
||||
|
||||
CMeshBuilder meshBuilder;
|
||||
meshBuilder.Begin( pMesh, MATERIAL_TRIANGLE_STRIP, nVertices, nIndices );
|
||||
|
||||
//
|
||||
// Build the index buffer.
|
||||
//
|
||||
int i, j;
|
||||
for ( i = 0; i < nPhi; ++i )
|
||||
{
|
||||
for ( j = 0; j < nTheta; ++j )
|
||||
{
|
||||
float u = j / ( float )(nTheta - 1);
|
||||
float v = i / ( float )(nPhi - 1);
|
||||
float theta = ( j != nTheta-1 ) ? 2.0f * M_PI * u : 0.0f;
|
||||
float phi = M_PI * v;
|
||||
|
||||
Vector vecPos;
|
||||
vecPos.x = flRadius * sin(phi) * cos(theta);
|
||||
vecPos.y = flRadius * cos(phi);
|
||||
vecPos.z = -flRadius * sin(phi) * sin(theta);
|
||||
|
||||
unsigned char red = (int)( u * 255.0f );
|
||||
unsigned char green = (int)( v * 255.0f );
|
||||
unsigned char blue = (int)( v * 255.0f );
|
||||
unsigned char alpha = (int)( v * 255.0f );
|
||||
|
||||
meshBuilder.Position3fv( vecPos.Base() );
|
||||
meshBuilder.Color4ub( red, green, blue, alpha );
|
||||
meshBuilder.TexCoord2f( 0, u, v );
|
||||
meshBuilder.BoneWeight( 0, 1.0f );
|
||||
meshBuilder.BoneMatrix( 0, 0 );
|
||||
meshBuilder.AdvanceVertex();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Emit the triangle strips.
|
||||
//
|
||||
int idx = 0;
|
||||
for ( i = 0; i < nPhi - 1; ++i )
|
||||
{
|
||||
for ( j = 0; j < nTheta; ++j )
|
||||
{
|
||||
idx = nTheta * i + j;
|
||||
|
||||
meshBuilder.FastIndex( idx );
|
||||
meshBuilder.FastIndex( idx + nTheta );
|
||||
}
|
||||
|
||||
//
|
||||
// Emit a degenerate triangle to skip to the next row without
|
||||
// a connecting triangle.
|
||||
//
|
||||
if ( i < nPhi - 2 )
|
||||
{
|
||||
meshBuilder.FastIndex( idx + 1 );
|
||||
meshBuilder.FastIndex( idx + 1 + nTheta );
|
||||
}
|
||||
}
|
||||
|
||||
meshBuilder.End();
|
||||
pMesh->Draw();
|
||||
|
||||
rc->CullMode( MATERIAL_CULLMODE_CCW );
|
||||
rc->MatrixMode( MATERIAL_MODEL );
|
||||
rc->PopMatrix();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Position and bounds for the model
|
||||
//-----------------------------------------------------------------------------
|
||||
const Vector &CDmeVMFEntity::GetRenderOrigin( void )
|
||||
{
|
||||
return m_vecLocalOrigin;
|
||||
}
|
||||
|
||||
const QAngle &CDmeVMFEntity::GetRenderAngles( void )
|
||||
{
|
||||
return m_vecLocalAngles;
|
||||
}
|
||||
|
||||
void CDmeVMFEntity::GetRenderBounds( Vector& mins, Vector& maxs )
|
||||
{
|
||||
mins.Init( -SPHERE_RADIUS, -SPHERE_RADIUS, -SPHERE_RADIUS );
|
||||
maxs.Init( SPHERE_RADIUS, SPHERE_RADIUS, SPHERE_RADIUS );
|
||||
}
|
||||
88
tools/foundry/DmeVMFEntity.h
Normal file
88
tools/foundry/DmeVMFEntity.h
Normal file
@@ -0,0 +1,88 @@
|
||||
//========= Copyright 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/dmerenderable.h"
|
||||
#include "datamodel/dmelement.h"
|
||||
#include "toolframework/itoolentity.h"
|
||||
#include "materialsystem/MaterialSystemUtil.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Represents an editable entity; draws its helpers
|
||||
//-----------------------------------------------------------------------------
|
||||
class CDmeVMFEntity : public CDmeVisibilityControl< CDmeRenderable< CDmElement > >
|
||||
{
|
||||
DEFINE_ELEMENT( CDmeVMFEntity, CDmeVisibilityControl< CDmeRenderable< 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 );
|
||||
virtual void GetRenderBounds( Vector& mins, Vector& maxs );
|
||||
|
||||
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( bool bAttach );
|
||||
|
||||
private:
|
||||
bool IsEntityKey( CDmAttribute *pEntityKey );
|
||||
|
||||
CDmaVar<Vector> m_vecLocalOrigin;
|
||||
CDmaVar<QAngle> m_vecLocalAngles;
|
||||
|
||||
CDmaString m_ClassName;
|
||||
CDmaString m_TargetName;
|
||||
CDmaVar<bool> m_bIsPlaceholder;
|
||||
|
||||
// The entity it's connected to in the engine
|
||||
HTOOLHANDLE m_hEngineEntity;
|
||||
|
||||
CMaterialReference m_Wireframe;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Inline methods
|
||||
//-----------------------------------------------------------------------------
|
||||
inline const char *CDmeVMFEntity::GetClassName() const
|
||||
{
|
||||
return m_ClassName;
|
||||
}
|
||||
|
||||
inline const char *CDmeVMFEntity::GetTargetName() const
|
||||
{
|
||||
return m_TargetName;
|
||||
}
|
||||
|
||||
inline bool CDmeVMFEntity::IsPlaceholder() const
|
||||
{
|
||||
return m_bIsPlaceholder;
|
||||
}
|
||||
|
||||
|
||||
#endif // DMEVMFENTITY_H
|
||||
639
tools/foundry/entityreportpanel.cpp
Normal file
639
tools/foundry/entityreportpanel.cpp
Normal file
@@ -0,0 +1,639 @@
|
||||
//========= Copyright 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 "dmevmfentity.h"
|
||||
#include "foundrydoc.h"
|
||||
#include "foundrytool.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( CFoundryDoc *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_pFoundryTool->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_pFoundryTool->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 );
|
||||
CDmeVMFEntity *pEntity = (CDmeVMFEntity *)kv->GetPtr( "entity" );
|
||||
g_pFoundryTool->ShowEntityInEntityProperties( pEntity );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Deletes the marked objects.
|
||||
//-----------------------------------------------------------------------------
|
||||
void CEntityReportPanel::OnDeleteEntities(void)
|
||||
{
|
||||
// This is undoable
|
||||
CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, "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 );
|
||||
CDmeVMFEntity *pEntity = (CDmeVMFEntity *)kv->GetPtr( "entity" );
|
||||
if ( pEntity )
|
||||
{
|
||||
m_pDoc->DeleteEntity( pEntity );
|
||||
}
|
||||
}
|
||||
|
||||
guard.Release();
|
||||
|
||||
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( "#FoundryDeleteObjects", "#FoundryDeleteObjectsMsg", g_pFoundryTool->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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CEntityReportPanel::ShouldAddEntityToList( CDmeVMFEntity *pEntity )
|
||||
{
|
||||
// nope.
|
||||
if ( !m_bFilterByHidden && !pEntity->IsVisible() )
|
||||
return false;
|
||||
|
||||
/*
|
||||
if (!pDlg->m_pDoc->selection.IsEmpty() && !pEntity->IsSelected())
|
||||
return true;
|
||||
*/
|
||||
|
||||
if ( m_iFilterByType == FILTER_SHOW_POINT_ENTITIES && pEntity->IsPlaceholder() )
|
||||
return false;
|
||||
|
||||
if ( m_iFilterByType == FILTER_SHOW_BRUSH_ENTITIES && !pEntity->IsPlaceholder() )
|
||||
return false;
|
||||
|
||||
const char* pClassName = pEntity->GetClassName();
|
||||
|
||||
if ( m_bFilterByClass )
|
||||
{
|
||||
if ( !m_szFilterClass.IsEmpty() )
|
||||
{
|
||||
if ( !Q_stristr( pClassName, m_szFilterClass ) )
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !m_bFilterByKeyvalue || m_szFilterValue.IsEmpty() )
|
||||
return true;
|
||||
|
||||
CUtlBuffer buf( 256, 0, CUtlBuffer::TEXT_BUFFER );
|
||||
for ( CDmAttribute *pKey = pEntity->FirstEntityKey(); pKey; pKey = pEntity->NextEntityKey( pKey ) )
|
||||
{
|
||||
// first, check key
|
||||
if ( m_szFilterKey.IsEmpty() || !Q_stricmp( m_szFilterKey, pKey->GetName() ) )
|
||||
{
|
||||
// now, check value (as a string)
|
||||
buf.Clear();
|
||||
pKey->Serialize( buf );
|
||||
const char *pValue = (const char*)buf.Base();
|
||||
if ( (!m_bExact && Q_stristr( pValue, m_szFilterValue ) ) || !Q_stricmp( pValue, m_szFilterValue ) )
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CEntityReportPanel::UpdateEntityList(void)
|
||||
{
|
||||
if ( m_bSuppressEntityListUpdate )
|
||||
return;
|
||||
|
||||
m_bFilterTextChanged = false;
|
||||
|
||||
m_pEntities->RemoveAll();
|
||||
|
||||
const CDmrElementArray<CDmElement> entityList( m_pDoc->GetEntityList() );
|
||||
int nCount = entityList.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
CDmeVMFEntity *pEntity = CastElement<CDmeVMFEntity>( entityList[i] );
|
||||
if ( ShouldAddEntityToList( pEntity ) )
|
||||
{
|
||||
const char *pClassName = pEntity->GetClassName( );
|
||||
const char *pTargetName = pEntity->GetTargetName( );
|
||||
if ( !pTargetName || !pTargetName[0] )
|
||||
{
|
||||
pTargetName = "<no name>";
|
||||
}
|
||||
if ( !pClassName || !pClassName[0] )
|
||||
{
|
||||
pClassName = "<no class>";
|
||||
}
|
||||
|
||||
KeyValues *kv = new KeyValues( "node", "targetname", pTargetName );
|
||||
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
|
||||
122
tools/foundry/entityreportpanel.h
Normal file
122
tools/foundry/entityreportpanel.h
Normal file
@@ -0,0 +1,122 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef ENTITYREPORTPANEL_H
|
||||
#define ENTITYREPORTPANEL_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "vgui_controls/editablepanel.h"
|
||||
#include "tier1/utlstring.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class CFoundryDoc;
|
||||
class CDmeVMFEntity;
|
||||
|
||||
namespace vgui
|
||||
{
|
||||
class ComboBox;
|
||||
class Button;
|
||||
class TextEntry;
|
||||
class ListPanel;
|
||||
class CheckButton;
|
||||
class RadioButton;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Panel that shows all entities in the level
|
||||
//-----------------------------------------------------------------------------
|
||||
class CEntityReportPanel : public vgui::EditablePanel
|
||||
{
|
||||
DECLARE_CLASS_SIMPLE( CEntityReportPanel, vgui::EditablePanel );
|
||||
|
||||
public:
|
||||
CEntityReportPanel( CFoundryDoc *pDoc, vgui::Panel* pParent, const char *pName ); // standard constructor
|
||||
|
||||
// Inherited from Panel
|
||||
virtual void OnTick();
|
||||
virtual void OnCommand( const char *pCommand );
|
||||
|
||||
private:
|
||||
enum FilterType_t
|
||||
{
|
||||
FILTER_SHOW_EVERYTHING = 0,
|
||||
FILTER_SHOW_POINT_ENTITIES = 1,
|
||||
FILTER_SHOW_BRUSH_ENTITIES = 2
|
||||
};
|
||||
|
||||
// Messages handled
|
||||
MESSAGE_FUNC_PARAMS( OnTextChanged, "TextChanged", kv );
|
||||
MESSAGE_FUNC_PARAMS( OnButtonToggled, "ButtonToggled", kv );
|
||||
MESSAGE_FUNC( OnDeleteEntities, "DeleteEntities" );
|
||||
|
||||
// FIXME: Necessary because SetSelected doesn't cause a ButtonToggled message to trigger
|
||||
MESSAGE_FUNC_PARAMS( OnCheckButtonChecked, "CheckButtonChecked", kv );
|
||||
MESSAGE_FUNC_PARAMS( OnRadioButtonChecked, "RadioButtonChecked", kv );
|
||||
|
||||
// Methods related to filtering
|
||||
void OnFilterByHidden( bool bState );
|
||||
void OnFilterByKeyvalue( bool bState );
|
||||
void OnFilterByClass( bool bState );
|
||||
void OnFilterKeyValueExact( bool bState );
|
||||
void OnFilterByType( FilterType_t type );
|
||||
void OnChangeFilterkey( const char *pText );
|
||||
void OnChangeFiltervalue( const char *pText );
|
||||
void OnChangeFilterclass( const char *pText );
|
||||
|
||||
// Methods related to updating the listpanel
|
||||
void UpdateEntityList();
|
||||
bool ShouldAddEntityToList( CDmeVMFEntity *pEntity );
|
||||
|
||||
// Methods related to saving settings
|
||||
void ReadSettingsFromRegistry();
|
||||
void SaveSettingsToRegistry();
|
||||
|
||||
// Call this when our settings are dirty
|
||||
void MarkDirty( bool bFilterDirty );
|
||||
|
||||
// Shows the most recent selected object in properties window
|
||||
void OnProperties();
|
||||
|
||||
CFoundryDoc *m_pDoc;
|
||||
FilterType_t m_iFilterByType;
|
||||
bool m_bFilterByClass;
|
||||
bool m_bFilterByHidden;
|
||||
bool m_bFilterByKeyvalue;
|
||||
bool m_bExact;
|
||||
bool m_bSuppressEntityListUpdate;
|
||||
|
||||
CUtlString m_szFilterKey;
|
||||
CUtlString m_szFilterValue;
|
||||
CUtlString m_szFilterClass;
|
||||
|
||||
bool m_bFilterTextChanged;
|
||||
float m_flFilterTime;
|
||||
|
||||
bool m_bRegistrySettingsChanged;
|
||||
float m_flRegistryTime;
|
||||
|
||||
vgui::CheckButton *m_pExact;
|
||||
vgui::ComboBox *m_pFilterClass;
|
||||
vgui::CheckButton *m_pFilterByClass;
|
||||
vgui::ListPanel *m_pEntities;
|
||||
vgui::TextEntry *m_pFilterKey;
|
||||
vgui::TextEntry *m_pFilterValue;
|
||||
vgui::CheckButton *m_pFilterByKeyvalue;
|
||||
vgui::CheckButton *m_pFilterByHidden;
|
||||
|
||||
vgui::RadioButton *m_pFilterEverything;
|
||||
vgui::RadioButton *m_pFilterPointEntities;
|
||||
vgui::RadioButton *m_pFilterBrushModels;
|
||||
};
|
||||
|
||||
|
||||
#endif // ENTITYREPORTPANEL_H
|
||||
67
tools/foundry/foundry.vpc
Normal file
67
tools/foundry/foundry.vpc
Normal file
@@ -0,0 +1,67 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// FOUNDRY.VPC
|
||||
//
|
||||
// Project Script
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
$Macro SRCDIR "..\.."
|
||||
$Macro OUTBINDIR "$SRCDIR\..\game\bin\tools"
|
||||
|
||||
$Include "$SRCDIR\vpc_scripts\source_dll_base.vpc"
|
||||
|
||||
$Configuration
|
||||
{
|
||||
$Compiler
|
||||
{
|
||||
$AdditionalIncludeDirectories "$BASE,.\,$SRCDIR\game\shared"
|
||||
$PreprocessorDefinitions "$BASE;FOUNDRY_EXPORTS"
|
||||
}
|
||||
|
||||
$Linker
|
||||
{
|
||||
$AdditionalDependencies "$BASE Psapi.lib"
|
||||
}
|
||||
}
|
||||
|
||||
$Project "foundry"
|
||||
{
|
||||
$Folder "Source Files"
|
||||
{
|
||||
$File "DmeVMFEntity.cpp"
|
||||
$File "DmeVMFEntity.h"
|
||||
$File "entityreportpanel.cpp"
|
||||
$File "entityreportpanel.h"
|
||||
$File "foundrydoc.cpp"
|
||||
$File "foundrytool.cpp"
|
||||
$File "$SRCDIR\public\interpolatortypes.cpp"
|
||||
$File "$SRCDIR\public\registry.cpp"
|
||||
$File "$SRCDIR\public\vgui_controls\vgui_controls.cpp"
|
||||
}
|
||||
|
||||
$Folder "Header Files"
|
||||
{
|
||||
$File "foundrydoc.h"
|
||||
$File "foundrytool.h"
|
||||
}
|
||||
|
||||
$Folder "Public Header Files"
|
||||
{
|
||||
$File "$SRCDIR\public\mathlib\mathlib.h"
|
||||
}
|
||||
|
||||
$Folder "Link Libraries"
|
||||
{
|
||||
$Lib datamodel
|
||||
$Lib dmxloader
|
||||
$Lib dme_controls
|
||||
$Lib dmserializers
|
||||
$Lib mathlib
|
||||
$Lib matsys_controls
|
||||
$Lib movieobjects
|
||||
$Lib sfmobjects
|
||||
$Lib tier2
|
||||
$Lib tier3
|
||||
$Lib toolutils
|
||||
$Lib vgui_controls
|
||||
}
|
||||
}
|
||||
345
tools/foundry/foundrydoc.cpp
Normal file
345
tools/foundry/foundrydoc.cpp
Normal file
@@ -0,0 +1,345 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#include "foundrydoc.h"
|
||||
#include "tier1/KeyValues.h"
|
||||
#include "tier1/utlbuffer.h"
|
||||
#include "datamodel/dmelement.h"
|
||||
#include "toolutils/enginetools_int.h"
|
||||
#include "filesystem.h"
|
||||
#include "foundrytool.h"
|
||||
#include "toolframework/ienginetool.h"
|
||||
#include "dmevmfentity.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CFoundryDoc::CFoundryDoc( IFoundryDocCallback *pCallback ) : m_pCallback( pCallback )
|
||||
{
|
||||
m_hRoot = NULL;
|
||||
m_pBSPFileName[0] = 0;
|
||||
m_pVMFFileName[0] = 0;
|
||||
m_bDirty = false;
|
||||
g_pDataModel->InstallNotificationCallback( this );
|
||||
}
|
||||
|
||||
CFoundryDoc::~CFoundryDoc()
|
||||
{
|
||||
g_pDataModel->RemoveNotificationCallback( this );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Inherited from INotifyUI
|
||||
//-----------------------------------------------------------------------------
|
||||
void CFoundryDoc::NotifyDataChanged( const char *pReason, int nNotifySource, int nNotifyFlags )
|
||||
{
|
||||
OnDataChanged( pReason, nNotifySource, nNotifyFlags );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets the file name
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *CFoundryDoc::GetBSPFileName()
|
||||
{
|
||||
return m_pBSPFileName;
|
||||
}
|
||||
|
||||
const char *CFoundryDoc::GetVMFFileName()
|
||||
{
|
||||
return m_pVMFFileName;
|
||||
}
|
||||
|
||||
void CFoundryDoc::SetVMFFileName( const char *pFileName )
|
||||
{
|
||||
Q_strncpy( m_pVMFFileName, pFileName, sizeof( m_pVMFFileName ) );
|
||||
Q_FixSlashes( m_pVMFFileName );
|
||||
SetDirty( true );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Dirty bits
|
||||
//-----------------------------------------------------------------------------
|
||||
void CFoundryDoc::SetDirty( bool bDirty )
|
||||
{
|
||||
m_bDirty = bDirty;
|
||||
}
|
||||
|
||||
bool CFoundryDoc::IsDirty() const
|
||||
{
|
||||
return m_bDirty;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Saves/loads from file
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CFoundryDoc::LoadFromFile( const char *pFileName )
|
||||
{
|
||||
Assert( !m_hRoot.Get() );
|
||||
|
||||
// This is not undoable
|
||||
CAppDisableUndoScopeGuard guard( "CFoundryDoc::LoadFromFile", 0 );
|
||||
SetDirty( false );
|
||||
|
||||
if ( !pFileName[0] )
|
||||
return false;
|
||||
|
||||
// Store the BSP file name
|
||||
Q_strncpy( m_pBSPFileName, pFileName, sizeof( m_pBSPFileName ) );
|
||||
|
||||
// Construct VMF file name from the BSP
|
||||
const char *pGame = Q_stristr( pFileName, "\\game\\" );
|
||||
if ( !pGame )
|
||||
return false;
|
||||
|
||||
// Compute the map name
|
||||
char mapname[ 256 ];
|
||||
const char *pMaps = Q_stristr( pFileName, "\\maps\\" );
|
||||
if ( !pMaps )
|
||||
return false;
|
||||
|
||||
Q_strncpy( mapname, pMaps + 6, sizeof( mapname ) );
|
||||
|
||||
int nLen = (int)( (size_t)pGame - (size_t)pFileName ) + 1;
|
||||
Q_strncpy( m_pVMFFileName, pFileName, nLen );
|
||||
Q_strncat( m_pVMFFileName, "\\content\\", sizeof(m_pVMFFileName) );
|
||||
Q_strncat( m_pVMFFileName, pGame + 6, sizeof(m_pVMFFileName) );
|
||||
Q_SetExtension( m_pVMFFileName, ".vmf", sizeof(m_pVMFFileName) );
|
||||
|
||||
CDmElement *pVMF = NULL;
|
||||
if ( g_pDataModel->RestoreFromFile( m_pVMFFileName, NULL, "vmf", &pVMF ) == DMFILEID_INVALID )
|
||||
{
|
||||
m_pBSPFileName[0] = 0;
|
||||
m_pVMFFileName[0] = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_hRoot = pVMF;
|
||||
|
||||
guard.Release();
|
||||
SetDirty( false );
|
||||
|
||||
char cmd[ 256 ];
|
||||
Q_snprintf( cmd, sizeof( cmd ), "disconnect; map %s\n", mapname );
|
||||
enginetools->Command( cmd );
|
||||
enginetools->Execute( );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CFoundryDoc::SaveToFile( )
|
||||
{
|
||||
if ( m_hRoot.Get() && m_pVMFFileName && m_pVMFFileName[0] )
|
||||
{
|
||||
g_pDataModel->SaveToFile( m_pVMFFileName, NULL, "keyvalues", "vmf", m_hRoot );
|
||||
}
|
||||
|
||||
SetDirty( false );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the root object
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmElement *CFoundryDoc::GetRootObject()
|
||||
{
|
||||
return m_hRoot;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the entity list
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmAttribute *CFoundryDoc::GetEntityList()
|
||||
{
|
||||
return m_hRoot ? m_hRoot->GetAttribute( "entities", AT_ELEMENT_ARRAY ) : NULL;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Deletes an entity
|
||||
//-----------------------------------------------------------------------------
|
||||
void CFoundryDoc::DeleteEntity( CDmeVMFEntity *pEntity )
|
||||
{
|
||||
CDmrElementArray<> entities( GetEntityList() );
|
||||
if ( !entities.IsValid() )
|
||||
return;
|
||||
|
||||
int nCount = entities.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
if ( pEntity == CastElement< CDmeVMFEntity >( entities[i] ) )
|
||||
{
|
||||
entities.FastRemove( i );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called when data changes
|
||||
//-----------------------------------------------------------------------------
|
||||
void CFoundryDoc::OnDataChanged( const char *pReason, int nNotifySource, int nNotifyFlags )
|
||||
{
|
||||
SetDirty( nNotifyFlags & NOTIFY_SETDIRTYFLAG ? true : false );
|
||||
m_pCallback->OnDocChanged( pReason, nNotifySource, nNotifyFlags );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// List of all entity classnames to copy over from the original block
|
||||
//-----------------------------------------------------------------------------
|
||||
static const char *s_pUseOriginalClasses[] =
|
||||
{
|
||||
"worldspawn",
|
||||
"func_occluder",
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Always copy the worldspawn and other entities that had data built into them by VBSP out
|
||||
//-----------------------------------------------------------------------------
|
||||
void CFoundryDoc::AddOriginalEntities( CUtlBuffer &entityBuf, const char *pActualEntityData )
|
||||
{
|
||||
while ( *pActualEntityData )
|
||||
{
|
||||
pActualEntityData = strchr( pActualEntityData, '{' );
|
||||
if ( !pActualEntityData )
|
||||
break;
|
||||
|
||||
const char *pBlockStart = pActualEntityData;
|
||||
|
||||
pActualEntityData = strstr( pActualEntityData, "\"classname\"" );
|
||||
if ( !pActualEntityData )
|
||||
break;
|
||||
|
||||
// Skip "classname"
|
||||
pActualEntityData += 11;
|
||||
|
||||
pActualEntityData = strchr( pActualEntityData, '\"' );
|
||||
if ( !pActualEntityData )
|
||||
break;
|
||||
|
||||
// Skip "
|
||||
++pActualEntityData;
|
||||
|
||||
char pClassName[512];
|
||||
int j = 0;
|
||||
while (*pActualEntityData != 0 && *pActualEntityData != '\"' )
|
||||
{
|
||||
pClassName[j++] = *pActualEntityData++;
|
||||
}
|
||||
pClassName[j] = 0;
|
||||
|
||||
pActualEntityData = strchr( pActualEntityData, '}' );
|
||||
if ( !pActualEntityData )
|
||||
break;
|
||||
|
||||
// Skip }
|
||||
++pActualEntityData;
|
||||
|
||||
for ( int i = 0; s_pUseOriginalClasses[i]; ++i )
|
||||
{
|
||||
if ( !Q_stricmp( pClassName, s_pUseOriginalClasses[i] ) )
|
||||
{
|
||||
// Found one we need to keep, add it to the buffer
|
||||
int nBytes = (int)( (size_t)pActualEntityData - (size_t)pBlockStart );
|
||||
entityBuf.Put( pBlockStart, nBytes );
|
||||
entityBuf.PutChar( '\n' );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copy in other entities from the editable VMF
|
||||
//-----------------------------------------------------------------------------
|
||||
void CFoundryDoc::AddVMFEntities( CUtlBuffer &entityBuf, const char *pActualEntityData )
|
||||
{
|
||||
const CDmrElementArray<CDmElement> entityArray( m_hRoot, "entities" );
|
||||
if ( !entityArray.IsValid() )
|
||||
return;
|
||||
|
||||
int nCount = entityArray.Count();
|
||||
for ( int iEntity = 0; iEntity < nCount; ++iEntity )
|
||||
{
|
||||
CDmElement *pEntity = entityArray[iEntity];
|
||||
const char *pClassName = pEntity->GetValueString( "classname" );
|
||||
if ( !pClassName || !pClassName[0] )
|
||||
continue;
|
||||
|
||||
// Don't spawn those classes we grab from the actual compiled map
|
||||
bool bDontUse = false;
|
||||
for ( int i = 0; s_pUseOriginalClasses[i]; ++i )
|
||||
{
|
||||
if ( !Q_stricmp( pClassName, s_pUseOriginalClasses[i] ) )
|
||||
{
|
||||
bDontUse = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( bDontUse )
|
||||
continue;
|
||||
|
||||
entityBuf.PutString( "{\n" );
|
||||
entityBuf.Printf( "\"id\" \"%d\"\n", atol( pEntity->GetName() ) );
|
||||
|
||||
for( CDmAttribute *pAttribute = pEntity->FirstAttribute(); pAttribute; pAttribute = pAttribute->NextAttribute() )
|
||||
{
|
||||
if ( pAttribute->IsFlagSet( FATTRIB_STANDARD ) )
|
||||
continue;
|
||||
|
||||
if ( IsArrayType( pAttribute->GetType() ) )
|
||||
continue;
|
||||
|
||||
if ( !Q_stricmp( pAttribute->GetName(), "editorType" ) || !Q_stricmp( pAttribute->GetName(), "editor" ) )
|
||||
continue;
|
||||
|
||||
entityBuf.Printf( "\"%s\" ", pAttribute->GetName() );
|
||||
|
||||
// FIXME: Set up standard delimiters
|
||||
entityBuf.PutChar( '\"' );
|
||||
pAttribute->Serialize( entityBuf );
|
||||
entityBuf.PutString( "\"\n" );
|
||||
}
|
||||
|
||||
entityBuf.PutString( "}\n" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Create a text block the engine can parse containing the entity data to spawn
|
||||
//-----------------------------------------------------------------------------
|
||||
const char* CFoundryDoc::GenerateEntityData( const char *pActualEntityData )
|
||||
{
|
||||
if ( !m_hRoot.Get() )
|
||||
return pActualEntityData;
|
||||
|
||||
// Contains the text block the engine can parse containing the entity data to spawn
|
||||
static CUtlBuffer entityBuf( 2048, 2048, CUtlBuffer::TEXT_BUFFER );
|
||||
entityBuf.Clear();
|
||||
|
||||
// Always copy the worldspawn and other entities that had data built into them by VBSP out
|
||||
AddOriginalEntities( entityBuf, pActualEntityData );
|
||||
|
||||
// Copy in other entities from the editable VMF
|
||||
AddVMFEntities( entityBuf, pActualEntityData );
|
||||
|
||||
return (const char*)entityBuf.Base();
|
||||
}
|
||||
|
||||
83
tools/foundry/foundrydoc.h
Normal file
83
tools/foundry/foundrydoc.h
Normal file
@@ -0,0 +1,83 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef FOUNDRYDOC_H
|
||||
#define FOUNDRYDOC_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "dme_controls/inotifyui.h"
|
||||
#include "datamodel/dmehandle.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class IFoundryDocCallback;
|
||||
class CDmeVMFEntity;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Contains all editable state
|
||||
//-----------------------------------------------------------------------------
|
||||
class CFoundryDoc : public IDmNotify
|
||||
{
|
||||
public:
|
||||
CFoundryDoc( IFoundryDocCallback *pCallback );
|
||||
~CFoundryDoc();
|
||||
|
||||
// Inherited from INotifyUI
|
||||
virtual void NotifyDataChanged( const char *pReason, int nNotifySource, int nNotifyFlags );
|
||||
|
||||
// Sets/Gets the file name
|
||||
const char *GetBSPFileName();
|
||||
const char *GetVMFFileName();
|
||||
void SetVMFFileName( 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 );
|
||||
|
||||
// Create a text block the engine can parse containing the entity data to spawn
|
||||
const char* GenerateEntityData( const char *pActualEntityData );
|
||||
|
||||
// Returns the entity list
|
||||
CDmAttribute *GetEntityList();
|
||||
|
||||
// Deletes an entity
|
||||
void DeleteEntity( CDmeVMFEntity *pEntity );
|
||||
|
||||
private:
|
||||
// Always copy the worldspawn and other entities that had data built into them by VBSP out
|
||||
void AddOriginalEntities( CUtlBuffer &entityBuf, const char *pActualEntityData );
|
||||
|
||||
// Copy in other entities from the editable VMF
|
||||
void AddVMFEntities( CUtlBuffer &entityBuf, const char *pActualEntityData );
|
||||
|
||||
IFoundryDocCallback *m_pCallback;
|
||||
CDmeHandle< CDmElement > m_hRoot;
|
||||
char m_pBSPFileName[512];
|
||||
char m_pVMFFileName[512];
|
||||
bool m_bDirty;
|
||||
};
|
||||
|
||||
|
||||
#endif // FOUNDRYDOC_H
|
||||
1172
tools/foundry/foundrytool.cpp
Normal file
1172
tools/foundry/foundrytool.cpp
Normal file
File diff suppressed because it is too large
Load Diff
65
tools/foundry/foundrytool.h
Normal file
65
tools/foundry/foundrytool.h
Normal file
@@ -0,0 +1,65 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Foundry tool; main UI smarts class
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#ifndef FOUNDRYTOOL_H
|
||||
#define FOUNDRYTOOL_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "tier0/platform.h"
|
||||
#include "datamodel/idatamodel.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class CDmeEditorTypeDictionary;
|
||||
class CDmeVMFEntity;
|
||||
|
||||
namespace vgui
|
||||
{
|
||||
class Panel;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Singleton interfaces
|
||||
//-----------------------------------------------------------------------------
|
||||
extern CDmeEditorTypeDictionary *g_pEditorTypeDict;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Allows the doc to call back into the Foundry editor tool
|
||||
//-----------------------------------------------------------------------------
|
||||
abstract_class IFoundryDocCallback
|
||||
{
|
||||
public:
|
||||
// Called by the doc when the data changes
|
||||
virtual void OnDocChanged( const char *pReason, int nNotifySource, int nNotifyFlags ) = 0;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Global methods of the foundry tool
|
||||
//-----------------------------------------------------------------------------
|
||||
abstract_class IFoundryTool
|
||||
{
|
||||
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( CDmeVMFEntity *pEntity ) = 0;
|
||||
};
|
||||
|
||||
extern IFoundryTool *g_pFoundryTool;
|
||||
|
||||
|
||||
#endif // FOUNDRYTOOL_H
|
||||
182
tools/gameevents/gameeventeditdoc.cpp
Normal file
182
tools/gameevents/gameeventeditdoc.cpp
Normal file
@@ -0,0 +1,182 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#include "gameeventeditdoc.h"
|
||||
#include "tier1/KeyValues.h"
|
||||
#include "tier1/utlbuffer.h"
|
||||
#include "toolutils/enginetools_int.h"
|
||||
#include "filesystem.h"
|
||||
#include "toolframework/ienginetool.h"
|
||||
#include "datamodel/idatamodel.h"
|
||||
#include "toolutils/attributeelementchoicelist.h"
|
||||
#include "vgui_controls/messagebox.h"
|
||||
|
||||
// FIXME: This document currently stores a whole lot of nothing.
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CGameEventEditDoc::CGameEventEditDoc()
|
||||
{
|
||||
m_hRoot = NULL;
|
||||
m_pTXTFileName[0] = 0;
|
||||
m_bDirty = false;
|
||||
g_pDataModel->InstallNotificationCallback( this );
|
||||
}
|
||||
|
||||
CGameEventEditDoc::~CGameEventEditDoc()
|
||||
{
|
||||
g_pDataModel->RemoveNotificationCallback( this );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Inherited from INotifyUI
|
||||
//-----------------------------------------------------------------------------
|
||||
void CGameEventEditDoc::NotifyDataChanged( const char *pReason, int nNotifySource, int nNotifyFlags )
|
||||
{
|
||||
//OnDataChanged( pReason, nNotifySource, nNotifyFlags );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets the file name
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *CGameEventEditDoc::GetTXTFileName()
|
||||
{
|
||||
return m_pTXTFileName;
|
||||
}
|
||||
|
||||
void CGameEventEditDoc::SetTXTFileName( const char *pFileName )
|
||||
{
|
||||
Q_strncpy( m_pTXTFileName, pFileName, sizeof( m_pTXTFileName ) );
|
||||
Q_FixSlashes( m_pTXTFileName );
|
||||
SetDirty( true );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Dirty bits
|
||||
//-----------------------------------------------------------------------------
|
||||
void CGameEventEditDoc::SetDirty( bool bDirty )
|
||||
{
|
||||
m_bDirty = bDirty;
|
||||
}
|
||||
|
||||
bool CGameEventEditDoc::IsDirty() const
|
||||
{
|
||||
return m_bDirty;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Saves/loads from file
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CGameEventEditDoc::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;
|
||||
|
||||
CElementForKeyValueCallback KeyValuesCallback;
|
||||
g_pDataModel->SetKeyValuesElementCallback( &KeyValuesCallback );
|
||||
DmFileId_t fileid = g_pDataModel->RestoreFromFile( pFileName, NULL, "keyvalues", &pTXT );
|
||||
g_pDataModel->SetKeyValuesElementCallback( NULL );
|
||||
|
||||
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 CGameEventEditDoc::SaveToFile( )
|
||||
{
|
||||
if ( m_hRoot.Get() && m_pTXTFileName && m_pTXTFileName[0] )
|
||||
{
|
||||
g_pDataModel->SaveToFile( m_pTXTFileName, NULL, "keyvalues", "keyvalues", m_hRoot );
|
||||
}
|
||||
|
||||
SetDirty( false );
|
||||
}
|
||||
94
tools/gameevents/gameeventeditdoc.h
Normal file
94
tools/gameevents/gameeventeditdoc.h
Normal file
@@ -0,0 +1,94 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef GAMEEVENTEDITDOC_H
|
||||
#define GAMEEVENTEDITDOC_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 CGameEventEditDoc : public IDmNotify
|
||||
{
|
||||
public:
|
||||
CGameEventEditDoc();
|
||||
~CGameEventEditDoc();
|
||||
|
||||
// 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 );
|
||||
|
||||
// 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 // GAMEEVENTEDITDOC_H
|
||||
240
tools/gameevents/gameeventeditpanel.cpp
Normal file
240
tools/gameevents/gameeventeditpanel.cpp
Normal file
@@ -0,0 +1,240 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//===========================================================================//
|
||||
#include "gameeventeditpanel.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 "datamodel/dmelement.h"
|
||||
#include "matsys_controls/picker.h"
|
||||
#include "vgui_controls/fileopendialog.h"
|
||||
#include "filesystem.h"
|
||||
#include "tier2/fileutils.h"
|
||||
#include "igameevents.h"
|
||||
#include "toolutils/enginetools_int.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
char *VarArgs( PRINTF_FORMAT_STRING const char *format, ... )
|
||||
{
|
||||
va_list argptr;
|
||||
static char string[1024];
|
||||
|
||||
va_start (argptr, format);
|
||||
Q_vsnprintf (string, sizeof( string ), format,argptr);
|
||||
va_end (argptr);
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CGameEventEditPanel::CGameEventEditPanel( CGameEventEditDoc *pDoc, vgui::Panel* pParent )
|
||||
: BaseClass( pParent, "GameEventEditPanel" ), m_pDoc( pDoc )
|
||||
{
|
||||
SetPaintBackgroundEnabled( true );
|
||||
SetKeyBoardInputEnabled( true );
|
||||
|
||||
m_pEvents = new KeyValues( "events" );
|
||||
|
||||
m_EventFiles.RemoveAll();
|
||||
m_EventFileNames.RemoveAll();
|
||||
|
||||
// load the game events
|
||||
LoadEventsFromFile( "resource/GameEvents.res" );
|
||||
LoadEventsFromFile( "resource/ModEvents.res" );
|
||||
|
||||
m_pEventCombo = new vgui::ComboBox( this, "EventComboBox", 30, false );
|
||||
m_pEventCombo->SetNumberOfEditLines( 30 );
|
||||
|
||||
KeyValues *subkey = m_pEvents->GetFirstSubKey();
|
||||
while ( subkey )
|
||||
{
|
||||
m_pEventCombo->AddItem( subkey->GetName(), subkey );
|
||||
subkey = subkey->GetNextKey();
|
||||
}
|
||||
|
||||
if ( m_pEventCombo->GetItemCount() > 0 )
|
||||
{
|
||||
m_pEventCombo->ActivateItemByRow( 0 );
|
||||
}
|
||||
|
||||
for ( int i=0;i<MAX_GAME_EVENT_PARAMS;i++ )
|
||||
{
|
||||
m_pParamLabels[i] = new vgui::Label( this, VarArgs( "ParamLabel%d", i+1 ), VarArgs( "event param %d:", i+1 ) );
|
||||
m_pParamLabels[i]->AddActionSignalTarget( this );
|
||||
|
||||
m_pParams[i] = new vgui::TextEntry( this, VarArgs( "Param%d", i+1 ) );
|
||||
m_pParams[i]->AddActionSignalTarget( this );
|
||||
}
|
||||
|
||||
m_pSendEventButton = new vgui::Button( this, "SendEvent", "", this, "SendEvent" );
|
||||
|
||||
m_pFilterBox = new vgui::TextEntry( this, "FilterBox" );
|
||||
|
||||
LoadControlSettings( "resource/gameeventeditpanel.res" );
|
||||
}
|
||||
|
||||
CGameEventEditPanel::~CGameEventEditPanel()
|
||||
{
|
||||
m_pEvents->deleteThis();
|
||||
}
|
||||
|
||||
void CGameEventEditPanel::OnTextChanged( KeyValues *params )
|
||||
{
|
||||
Panel *panel = reinterpret_cast<vgui::Panel *>( params->GetPtr("panel") );
|
||||
|
||||
if ( panel == m_pFilterBox )
|
||||
{
|
||||
// repopulate the list based on the filter substr
|
||||
char filter[128];
|
||||
m_pFilterBox->GetText( filter, sizeof(filter) );
|
||||
int len = Q_strlen(filter);
|
||||
|
||||
m_pEventCombo->RemoveAll();
|
||||
|
||||
KeyValues *subkey = m_pEvents->GetFirstSubKey();
|
||||
while ( subkey )
|
||||
{
|
||||
if ( len == 0 || Q_strstr( subkey->GetName(), filter ) )
|
||||
{
|
||||
m_pEventCombo->AddItem( subkey->GetName(), subkey );
|
||||
}
|
||||
|
||||
subkey = subkey->GetNextKey();
|
||||
}
|
||||
|
||||
if ( m_pEventCombo->GetItemCount() > 0 )
|
||||
{
|
||||
m_pEventCombo->ActivateItemByRow( 0 );
|
||||
}
|
||||
}
|
||||
|
||||
if ( panel == m_pEventCombo )
|
||||
{
|
||||
Msg( "%s", params->GetName() );
|
||||
|
||||
KeyValues *kv = m_pEventCombo->GetActiveItemUserData();
|
||||
|
||||
int i = 0;
|
||||
|
||||
if ( kv )
|
||||
{
|
||||
KeyValues *subkey = kv->GetFirstSubKey();
|
||||
while ( subkey && i < MAX_GAME_EVENT_PARAMS )
|
||||
{
|
||||
Msg( subkey->GetName() );
|
||||
|
||||
char buf[128];
|
||||
Q_snprintf( buf, sizeof(buf), "%s (%s)", subkey->GetName(), subkey->GetString() );
|
||||
|
||||
m_pParamLabels[i]->SetText( buf );
|
||||
m_pParamLabels[i]->SetVisible( true );
|
||||
|
||||
const char *type = subkey->GetString();
|
||||
|
||||
if ( !Q_strcmp( type, "string" ) )
|
||||
{
|
||||
m_pParams[i]->SetAllowNumericInputOnly( false );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pParams[i]->SetAllowNumericInputOnly( true );
|
||||
}
|
||||
m_pParams[i]->SetText( "" );
|
||||
m_pParams[i]->SetVisible( true );
|
||||
|
||||
subkey = subkey->GetNextKey();
|
||||
i++;
|
||||
}
|
||||
|
||||
while( i < MAX_GAME_EVENT_PARAMS )
|
||||
{
|
||||
m_pParamLabels[i]->SetVisible( false );
|
||||
m_pParams[i]->SetVisible( false );
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called when buttons are clicked
|
||||
//-----------------------------------------------------------------------------
|
||||
void CGameEventEditPanel::OnCommand( const char *pCommand )
|
||||
{
|
||||
if ( !Q_stricmp( pCommand, "SendEvent" ) )
|
||||
{
|
||||
KeyValues *pData = m_pEventCombo->GetActiveItemUserData();
|
||||
|
||||
if ( pData )
|
||||
{
|
||||
const char *pEventName = pData->GetName();
|
||||
|
||||
IGameEvent *event = gameeventmanager->CreateEvent( pEventName );
|
||||
if ( event )
|
||||
{
|
||||
KeyValues *subkey = pData->GetFirstSubKey();
|
||||
|
||||
int i = 0;
|
||||
|
||||
while( subkey && i < MAX_GAME_EVENT_PARAMS )
|
||||
{
|
||||
char text[128];
|
||||
m_pParams[i]->GetText( text, sizeof(text) );
|
||||
event->SetString( subkey->GetName(), text );
|
||||
|
||||
subkey = subkey->GetNextKey();
|
||||
i++;
|
||||
}
|
||||
|
||||
gameeventmanager->FireEvent( event );
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
BaseClass::OnCommand( pCommand );
|
||||
}
|
||||
|
||||
void CGameEventEditPanel::LoadEventsFromFile( const char *filename )
|
||||
{
|
||||
if ( UTL_INVAL_SYMBOL == m_EventFiles.Find( filename ) )
|
||||
{
|
||||
CUtlSymbol id = m_EventFiles.AddString( filename );
|
||||
m_EventFileNames.AddToTail( id );
|
||||
}
|
||||
|
||||
KeyValues * key = new KeyValues(filename);
|
||||
KeyValues::AutoDelete autodelete_key( key );
|
||||
|
||||
if ( !key->LoadFromFile( g_pFileSystem, filename, "GAME" ) )
|
||||
return;
|
||||
|
||||
KeyValues *subkey = key->GetFirstSubKey();
|
||||
while ( subkey )
|
||||
{
|
||||
KeyValues *copy = subkey->MakeCopy();
|
||||
|
||||
m_pEvents->AddSubKey( copy );
|
||||
|
||||
subkey = subkey->GetNextKey();
|
||||
}
|
||||
}
|
||||
90
tools/gameevents/gameeventeditpanel.h
Normal file
90
tools/gameevents/gameeventeditpanel.h
Normal file
@@ -0,0 +1,90 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef GAMEEVENTEDITPANEL_H
|
||||
#define GAMEEVENTEDITPANEL_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "vgui_controls/editablepanel.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "datamodel/dmehandle.h"
|
||||
#include "igameevents.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class CGameEventEditDoc;
|
||||
|
||||
namespace vgui
|
||||
{
|
||||
class ComboBox;
|
||||
class Button;
|
||||
class TextEntry;
|
||||
class ListPanel;
|
||||
class CheckButton;
|
||||
class RadioButton;
|
||||
}
|
||||
|
||||
#define MAX_GAME_EVENT_PARAMS 20
|
||||
|
||||
extern IGameEventManager2 *gameeventmanager;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Panel that shows all entities in the level
|
||||
//-----------------------------------------------------------------------------
|
||||
class CGameEventEditPanel : public vgui::EditablePanel
|
||||
{
|
||||
DECLARE_CLASS_SIMPLE( CGameEventEditPanel, vgui::EditablePanel );
|
||||
|
||||
public:
|
||||
CGameEventEditPanel( CGameEventEditDoc *pDoc, vgui::Panel* pParent ); // standard constructor
|
||||
~CGameEventEditPanel();
|
||||
|
||||
// Inherited from Panel
|
||||
virtual void OnCommand( const char *pCommand );
|
||||
|
||||
private:
|
||||
// Text to attribute...
|
||||
//void TextEntryToAttribute( vgui::TextEntry *pEntry, const char *pAttributeName );
|
||||
//void TextEntriesToVector( vgui::TextEntry *pEntry[3], const char *pAttributeName );
|
||||
|
||||
// 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 );*/
|
||||
|
||||
//MESSAGE_FUNC( OnEventSend, "SendEvent" );
|
||||
|
||||
MESSAGE_FUNC_PARAMS( OnTextChanged, "TextChanged", kv );
|
||||
|
||||
void LoadEventsFromFile( const char *filename );
|
||||
|
||||
CGameEventEditDoc *m_pDoc;
|
||||
|
||||
// drop down of available events
|
||||
|
||||
vgui::ComboBox *m_pEventCombo;
|
||||
|
||||
vgui::Label *m_pParamLabels[MAX_GAME_EVENT_PARAMS];
|
||||
vgui::TextEntry *m_pParams[MAX_GAME_EVENT_PARAMS];
|
||||
|
||||
vgui::Button *m_pSendEventButton;
|
||||
|
||||
CUtlSymbolTable m_EventFiles; // list of all loaded event files
|
||||
CUtlVector<CUtlSymbol> m_EventFileNames;
|
||||
|
||||
KeyValues *m_pEvents;
|
||||
|
||||
vgui::TextEntry *m_pFilterBox;
|
||||
};
|
||||
|
||||
|
||||
#endif // GAMEEVENTEDITPANEL_H
|
||||
625
tools/gameevents/gameevents.cpp
Normal file
625
tools/gameevents/gameevents.cpp
Normal file
@@ -0,0 +1,625 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "toolutils/basetoolsystem.h"
|
||||
#include "toolutils/recentfilelist.h"
|
||||
#include "toolutils/toolmenubar.h"
|
||||
#include "toolutils/toolswitchmenubutton.h"
|
||||
#include "toolutils/toolfilemenubutton.h"
|
||||
#include "toolutils/toolmenubutton.h"
|
||||
#include "vgui_controls/Menu.h"
|
||||
#include "tier1/KeyValues.h"
|
||||
#include "toolutils/enginetools_int.h"
|
||||
#include "toolframework/ienginetool.h"
|
||||
#include "vgui/IInput.h"
|
||||
#include "vgui/KeyCode.h"
|
||||
#include "vgui_controls/FileOpenDialog.h"
|
||||
#include "filesystem.h"
|
||||
#include "vgui/ilocalize.h"
|
||||
#include "dme_controls/elementpropertiestree.h"
|
||||
#include "tier0/icommandline.h"
|
||||
#include "materialsystem/imaterialsystem.h"
|
||||
#include "VGuiMatSurface/IMatSystemSurface.h"
|
||||
#include "tier3/tier3.h"
|
||||
#include "tier2/fileutils.h"
|
||||
#include "gameeventeditdoc.h"
|
||||
#include "gameeventeditpanel.h"
|
||||
#include "toolutils/toolwindowfactory.h"
|
||||
#include "toolutils/savewindowpositions.h" // for windowposmgr
|
||||
#include "toolutils/ConsolePage.h"
|
||||
#include "igameevents.h"
|
||||
|
||||
IGameEventManager2 *gameeventmanager = NULL;
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
|
||||
const char *GetVGuiControlsModuleName()
|
||||
{
|
||||
return "GameEvents";
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Connect, disconnect
|
||||
//-----------------------------------------------------------------------------
|
||||
bool ConnectTools( CreateInterfaceFn factory )
|
||||
{
|
||||
gameeventmanager = ( IGameEventManager2 * )factory( INTERFACEVERSION_GAMEEVENTSMANAGER2, NULL );
|
||||
|
||||
if ( !gameeventmanager )
|
||||
{
|
||||
Warning( "Game Event Tool missing required interface\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
return (materials != NULL) && (g_pMatSystemSurface != NULL);
|
||||
}
|
||||
|
||||
void DisconnectTools( )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Implementation of the game events tool
|
||||
//-----------------------------------------------------------------------------
|
||||
class CGameEventTool : public CBaseToolSystem, public IFileMenuCallbacks
|
||||
{
|
||||
DECLARE_CLASS_SIMPLE( CGameEventTool, CBaseToolSystem );
|
||||
|
||||
public:
|
||||
CGameEventTool();
|
||||
|
||||
// Inherited from IToolSystem
|
||||
virtual const char *GetToolName() { return "Game Events"; }
|
||||
virtual const char *GetBindingsContextFile() { return "cfg/GameEvents.kb"; }
|
||||
virtual bool Init( );
|
||||
virtual void Shutdown();
|
||||
|
||||
// Inherited from IFileMenuCallbacks
|
||||
virtual int GetFileMenuItemsEnabled( );
|
||||
virtual void AddRecentFilesToMenu( vgui::Menu *menu );
|
||||
virtual bool GetPerforceFileName( char *pFileName, int nMaxLen ) { return false; }
|
||||
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 "SampleTool"; }
|
||||
virtual vgui::MenuBar *CreateMenuBar( CBaseToolSystem *pParent );
|
||||
|
||||
public:
|
||||
MESSAGE_FUNC( OnNew, "OnNew" );
|
||||
MESSAGE_FUNC( OnOpen, "OnOpen" );
|
||||
MESSAGE_FUNC( OnSave, "OnSave" );
|
||||
MESSAGE_FUNC( OnSaveAs, "OnSaveAs" );
|
||||
MESSAGE_FUNC( OnClose, "OnClose" );
|
||||
MESSAGE_FUNC( OnCloseNoSave, "OnCloseNoSave" );
|
||||
MESSAGE_FUNC( OnMarkNotDirty, "OnMarkNotDirty" );
|
||||
MESSAGE_FUNC( OnExit, "OnExit" );
|
||||
|
||||
void NewDocument();
|
||||
|
||||
void OpenFileFromHistory( int slot );
|
||||
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 );
|
||||
|
||||
// Get at the edit panel
|
||||
CGameEventEditPanel *GetGameEventEditPanel();
|
||||
|
||||
private:
|
||||
// Loads up a new document
|
||||
bool LoadDocument( const char *pDocName );
|
||||
|
||||
// Creates, destroys tools
|
||||
void CreateTools( CGameEventEditDoc *doc );
|
||||
void InitTools();
|
||||
void DestroyTools();
|
||||
|
||||
void OnDefaultLayout();
|
||||
|
||||
// Updates the menu bar based on the current file
|
||||
void UpdateMenuBar( );
|
||||
|
||||
// Shows element properties
|
||||
void ShowElementProperties( );
|
||||
|
||||
virtual const char *GetLogoTextureName();
|
||||
|
||||
CConsolePage *GetConsole();
|
||||
void OnToggleConsole();
|
||||
|
||||
void ShowToolWindow( Panel *tool, char const *toolName, bool visible );
|
||||
void ToggleToolWindow( Panel *tool, char const *toolName );
|
||||
|
||||
CToolWindowFactory< ToolWindow > m_ToolWindowFactory;
|
||||
|
||||
|
||||
// The entity report
|
||||
vgui::DHANDLE< CGameEventEditPanel > m_hGameEventEditPanel;
|
||||
|
||||
// Document
|
||||
CGameEventEditDoc *m_pDoc;
|
||||
|
||||
// The menu bar
|
||||
CToolFileMenuBar *m_pMenuBar;
|
||||
|
||||
// console tab in viewport
|
||||
vgui::DHANDLE< CConsolePage > m_hConsole;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Singleton
|
||||
//-----------------------------------------------------------------------------
|
||||
CGameEventTool *g_pSampleTool = NULL;
|
||||
|
||||
void CreateTools()
|
||||
{
|
||||
g_pSampleTool = new CGameEventTool();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CGameEventTool::CGameEventTool()
|
||||
{
|
||||
m_pMenuBar = NULL;
|
||||
m_pDoc = NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Init, shutdown
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CGameEventTool::Init( )
|
||||
{
|
||||
m_RecentFiles.LoadFromRegistry( GetRegistryName() );
|
||||
|
||||
// NOTE: This has to happen before BaseClass::Init
|
||||
g_pVGuiLocalize->AddFile( "resource/toolgameevents_%language%.txt" );
|
||||
|
||||
if ( !BaseClass::Init( ) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CGameEventTool::Shutdown()
|
||||
{
|
||||
m_RecentFiles.SaveToRegistry( GetRegistryName() );
|
||||
BaseClass::Shutdown();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Derived classes can implement this to get a new scheme to be applied to this tool
|
||||
//-----------------------------------------------------------------------------
|
||||
vgui::HScheme CGameEventTool::GetToolScheme()
|
||||
{
|
||||
return vgui::scheme()->LoadSchemeFromFile( "Resource/BoxRocket.res", "SampleTool" );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Initializes the menu bar
|
||||
//-----------------------------------------------------------------------------
|
||||
vgui::MenuBar *CGameEventTool::CreateMenuBar( CBaseToolSystem *pParent )
|
||||
{
|
||||
m_pMenuBar = new CToolFileMenuBar( pParent, "Main Menu Bar" );
|
||||
|
||||
// Sets info in the menu bar
|
||||
char title[ 64 ];
|
||||
ComputeMenuBarTitle( title, sizeof( title ) );
|
||||
m_pMenuBar->SetInfo( title );
|
||||
m_pMenuBar->SetToolName( GetToolName() );
|
||||
|
||||
// Add menu buttons
|
||||
CToolMenuButton *pFileButton = CreateToolFileMenuButton( m_pMenuBar, "File", "&File", GetActionTarget(), this );
|
||||
CToolMenuButton *pSwitchButton = CreateToolSwitchMenuButton( m_pMenuBar, "Switcher", "&Tools", GetActionTarget() );
|
||||
|
||||
m_pMenuBar->AddButton( pFileButton );
|
||||
m_pMenuBar->AddButton( pSwitchButton );
|
||||
|
||||
return m_pMenuBar;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Creates the action menu
|
||||
//-----------------------------------------------------------------------------
|
||||
vgui::Menu *CGameEventTool::CreateActionMenu( vgui::Panel *pParent )
|
||||
{
|
||||
vgui::Menu *pActionMenu = new Menu( pParent, "ActionMenu" );
|
||||
pActionMenu->AddMenuItem( "#ToolHide", new KeyValues( "Command", "command", "HideActionMenu" ), GetActionTarget() );
|
||||
return pActionMenu;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Inherited from IFileMenuCallbacks
|
||||
//-----------------------------------------------------------------------------
|
||||
int CGameEventTool::GetFileMenuItemsEnabled( )
|
||||
{
|
||||
int nFlags = FILE_ALL;
|
||||
if ( m_RecentFiles.IsEmpty() )
|
||||
{
|
||||
nFlags &= ~(FILE_RECENT | FILE_CLEAR_RECENT);
|
||||
}
|
||||
return nFlags;
|
||||
}
|
||||
|
||||
void CGameEventTool::AddRecentFilesToMenu( vgui::Menu *pMenu )
|
||||
{
|
||||
m_RecentFiles.AddToMenu( pMenu, GetActionTarget(), "OnRecent" );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : -
|
||||
//-----------------------------------------------------------------------------
|
||||
void CGameEventTool::OnExit()
|
||||
{
|
||||
enginetools->Command( "quit\n" );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Handle commands from the action menu and other menus
|
||||
//-----------------------------------------------------------------------------
|
||||
void CGameEventTool::OnCommand( const char *cmd )
|
||||
{
|
||||
if ( !V_stricmp( cmd, "HideActionMenu" ) )
|
||||
{
|
||||
if ( GetActionMenu() )
|
||||
{
|
||||
GetActionMenu()->SetVisible( false );
|
||||
}
|
||||
}
|
||||
else if ( const char *pOnRecentSuffix = StringAfterPrefix( cmd, "OnRecent" ) )
|
||||
{
|
||||
int idx = Q_atoi( pOnRecentSuffix );
|
||||
OpenFileFromHistory( idx );
|
||||
}
|
||||
else if( const char *pOnToolSuffix = StringAfterPrefix( cmd, "OnTool" ) )
|
||||
{
|
||||
int idx = Q_atoi( pOnToolSuffix );
|
||||
enginetools->SwitchToTool( idx );
|
||||
}
|
||||
else
|
||||
{
|
||||
BaseClass::OnCommand( cmd );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Command handlers
|
||||
//-----------------------------------------------------------------------------
|
||||
void CGameEventTool::OnNew()
|
||||
{
|
||||
if ( m_pDoc )
|
||||
{
|
||||
if ( m_pDoc->IsDirty() )
|
||||
{
|
||||
SaveFile( m_pDoc->GetTXTFileName(), "xt", FOSM_SHOW_PERFORCE_DIALOGS | FOSM_SHOW_SAVE_QUERY,
|
||||
new KeyValues( "OnNew" ) );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
NewDocument();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Loads up a new document
|
||||
//-----------------------------------------------------------------------------
|
||||
void CGameEventTool::NewDocument( )
|
||||
{
|
||||
Assert( !m_pDoc );
|
||||
|
||||
m_pDoc = new CGameEventEditDoc(/* this */);
|
||||
|
||||
CreateTools( m_pDoc );
|
||||
UpdateMenuBar();
|
||||
InitTools();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called when the File->Open menu is selected
|
||||
//-----------------------------------------------------------------------------
|
||||
void CGameEventTool::OnOpen( )
|
||||
{
|
||||
int nFlags = 0;
|
||||
const char *pSaveFileName = NULL;
|
||||
if ( m_pDoc && m_pDoc->IsDirty() )
|
||||
{
|
||||
nFlags = FOSM_SHOW_PERFORCE_DIALOGS | FOSM_SHOW_SAVE_QUERY;
|
||||
pSaveFileName = m_pDoc->GetTXTFileName();
|
||||
}
|
||||
|
||||
OpenFile( "txt", pSaveFileName, "txt", nFlags );
|
||||
}
|
||||
|
||||
bool CGameEventTool::OnReadFileFromDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues )
|
||||
{
|
||||
OnCloseNoSave();
|
||||
if ( !LoadDocument( pFileName ) )
|
||||
return false;
|
||||
|
||||
m_RecentFiles.Add( pFileName, pFileFormat );
|
||||
m_RecentFiles.SaveToRegistry( GetRegistryName() );
|
||||
UpdateMenuBar();
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Updates the menu bar based on the current file
|
||||
//-----------------------------------------------------------------------------
|
||||
void CGameEventTool::UpdateMenuBar( )
|
||||
{
|
||||
if ( !m_pDoc )
|
||||
{
|
||||
m_pMenuBar->SetFileName( "#CommEditNoFile" );
|
||||
return;
|
||||
}
|
||||
|
||||
const char *pTXTFile = m_pDoc->GetTXTFileName();
|
||||
if ( !pTXTFile[0] )
|
||||
{
|
||||
m_pMenuBar->SetFileName( "#CommEditNoFile" );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( m_pDoc->IsDirty() )
|
||||
{
|
||||
char sz[ 512 ];
|
||||
Q_snprintf( sz, sizeof( sz ), "* %s", pTXTFile );
|
||||
m_pMenuBar->SetFileName( sz );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pMenuBar->SetFileName( pTXTFile );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CGameEventTool::OnSave()
|
||||
{
|
||||
// FIXME: Implement
|
||||
}
|
||||
|
||||
void CGameEventTool::OnSaveAs()
|
||||
{
|
||||
SaveFile( NULL, NULL, 0 );
|
||||
}
|
||||
|
||||
bool CGameEventTool::OnWriteFileToDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues )
|
||||
{
|
||||
// FIXME: Implement
|
||||
|
||||
m_RecentFiles.Add( pFileName, pFileFormat );
|
||||
return true;
|
||||
}
|
||||
|
||||
void CGameEventTool::OnClose()
|
||||
{
|
||||
// FIXME: Implement
|
||||
}
|
||||
|
||||
void CGameEventTool::OnCloseNoSave()
|
||||
{
|
||||
// FIXME: Implement
|
||||
}
|
||||
|
||||
void CGameEventTool::OnMarkNotDirty()
|
||||
{
|
||||
// FIXME: Implement
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Show the save document query dialog
|
||||
//-----------------------------------------------------------------------------
|
||||
void CGameEventTool::OpenFileFromHistory( int slot )
|
||||
{
|
||||
const char *pFileName = m_RecentFiles.GetFile( slot );
|
||||
OnReadFileFromDisk( pFileName, NULL, 0 );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called when file operations complete
|
||||
//-----------------------------------------------------------------------------
|
||||
void CGameEventTool::OnFileOperationCompleted( const char *pFileType, bool bWroteFile, vgui::FileOpenStateMachine::CompletionState_t state, KeyValues *pContextKeyValues )
|
||||
{
|
||||
// FIXME: Implement
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Show the File browser dialog
|
||||
//-----------------------------------------------------------------------------
|
||||
void CGameEventTool::SetupFileOpenDialog( vgui::FileOpenDialog *pDialog, bool bOpenFile, const char *pFileFormat, KeyValues *pContextKeyValues )
|
||||
{
|
||||
char pStartingDir[ MAX_PATH ];
|
||||
GetModSubdirectory( NULL, pStartingDir, sizeof(pStartingDir) );
|
||||
|
||||
pDialog->SetTitle( "Choose SampleTool .txt file", true );
|
||||
pDialog->SetStartDirectoryContext( "sample_session", pStartingDir );
|
||||
pDialog->AddFilter( "*.txt", "SampleTool (*.txt)", true );
|
||||
}
|
||||
|
||||
const char *CGameEventTool::GetLogoTextureName()
|
||||
{
|
||||
return "vgui/tools/sampletool/sampletool_logo";
|
||||
}
|
||||
|
||||
CGameEventEditPanel *CGameEventTool::GetGameEventEditPanel()
|
||||
{
|
||||
return m_hGameEventEditPanel.Get();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Creates
|
||||
//-----------------------------------------------------------------------------
|
||||
void CGameEventTool::CreateTools( CGameEventEditDoc *doc )
|
||||
{
|
||||
if ( !m_hGameEventEditPanel.Get() )
|
||||
{
|
||||
m_hGameEventEditPanel = new CGameEventEditPanel( m_pDoc, this );
|
||||
}
|
||||
|
||||
if ( !m_hConsole.Get() )
|
||||
{
|
||||
m_hConsole = new CConsolePage( NULL, false );
|
||||
}
|
||||
|
||||
RegisterToolWindow( m_hGameEventEditPanel );
|
||||
RegisterToolWindow( m_hConsole );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Initializes the tools
|
||||
//-----------------------------------------------------------------------------
|
||||
void CGameEventTool::InitTools()
|
||||
{
|
||||
//ShowElementProperties();
|
||||
|
||||
windowposmgr->RegisterPanel( "gameeventedit", m_hGameEventEditPanel, false );
|
||||
windowposmgr->RegisterPanel( "Console", m_hConsole, false ); // No context menu
|
||||
|
||||
if ( !windowposmgr->LoadPositions( "cfg/commedit.txt", this, &m_ToolWindowFactory, "CommEdit" ) )
|
||||
{
|
||||
OnDefaultLayout();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CGameEventTool::DestroyTools()
|
||||
{
|
||||
UnregisterAllToolWindows();
|
||||
|
||||
if ( m_hGameEventEditPanel.Get() )
|
||||
{
|
||||
windowposmgr->UnregisterPanel( m_hGameEventEditPanel.Get() );
|
||||
delete m_hGameEventEditPanel.Get();
|
||||
m_hGameEventEditPanel = NULL;
|
||||
}
|
||||
|
||||
if ( m_hConsole.Get() )
|
||||
{
|
||||
windowposmgr->UnregisterPanel( m_hConsole.Get() );
|
||||
delete m_hConsole.Get();
|
||||
m_hConsole = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Loads up a new document
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CGameEventTool::LoadDocument( const char *pDocName )
|
||||
{
|
||||
Assert( !m_pDoc );
|
||||
|
||||
DestroyTools();
|
||||
|
||||
m_pDoc = new CGameEventEditDoc(/* this */);
|
||||
if ( !m_pDoc->LoadFromFile( pDocName ) )
|
||||
{
|
||||
delete m_pDoc;
|
||||
m_pDoc = NULL;
|
||||
Warning( "Fatal error loading '%s'\n", pDocName );
|
||||
return false;
|
||||
}
|
||||
|
||||
ShowMiniViewport( true );
|
||||
|
||||
CreateTools( m_pDoc );
|
||||
InitTools();
|
||||
return true;
|
||||
}
|
||||
|
||||
CConsolePage *CGameEventTool::GetConsole()
|
||||
{
|
||||
return m_hConsole;
|
||||
}
|
||||
|
||||
|
||||
void CGameEventTool::ShowToolWindow( Panel *tool, char const *toolName, bool visible )
|
||||
{
|
||||
Assert( tool );
|
||||
|
||||
if ( tool->GetParent() == NULL && visible )
|
||||
{
|
||||
m_ToolWindowFactory.InstanceToolWindow( this, false, tool, toolName, false );
|
||||
}
|
||||
else if ( !visible )
|
||||
{
|
||||
ToolWindow *tw = dynamic_cast< ToolWindow * >( tool->GetParent()->GetParent() );
|
||||
Assert( tw );
|
||||
tw->RemovePage( tool );
|
||||
}
|
||||
}
|
||||
|
||||
void CGameEventTool::ToggleToolWindow( Panel *tool, char const *toolName )
|
||||
{
|
||||
Assert( tool );
|
||||
|
||||
if ( tool->GetParent() == NULL )
|
||||
{
|
||||
ShowToolWindow( tool, toolName, true );
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowToolWindow( tool, toolName, false );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CGameEventTool::OnToggleConsole()
|
||||
{
|
||||
if ( m_hConsole.Get() )
|
||||
{
|
||||
ToggleToolWindow( m_hConsole.Get(), "#BxConsole" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets up the default layout
|
||||
//-----------------------------------------------------------------------------
|
||||
void CGameEventTool::OnDefaultLayout()
|
||||
{
|
||||
int y = m_pMenuBar->GetTall();
|
||||
|
||||
int usew, useh;
|
||||
GetSize( usew, useh );
|
||||
|
||||
int c = ToolWindow::GetToolWindowCount();
|
||||
for ( int i = c - 1; i >= 0 ; --i )
|
||||
{
|
||||
ToolWindow *kill = ToolWindow::GetToolWindow( i );
|
||||
delete kill;
|
||||
}
|
||||
|
||||
Assert( ToolWindow::GetToolWindowCount() == 0 );
|
||||
|
||||
CGameEventEditPanel *pEditPanel = GetGameEventEditPanel();
|
||||
CConsolePage *pConsole = GetConsole();
|
||||
|
||||
// Need three containers
|
||||
ToolWindow *pEditPanelWindow = m_ToolWindowFactory.InstanceToolWindow( GetClientArea(), false, pEditPanel, "#CommEditProperties", false );
|
||||
ToolWindow *pMiniViewport = dynamic_cast< ToolWindow* >( GetMiniViewport() );
|
||||
pMiniViewport->AddPage( pConsole, "#BxConsole", false );
|
||||
|
||||
int quarterScreen = usew / 4;
|
||||
SetMiniViewportBounds( quarterScreen, y, 3*quarterScreen, useh - y );
|
||||
pEditPanelWindow->SetBounds( 0, y, quarterScreen, useh - y );
|
||||
}
|
||||
|
||||
|
||||
60
tools/gameevents/gameevents.vpc
Normal file
60
tools/gameevents/gameevents.vpc
Normal file
@@ -0,0 +1,60 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// GAMEEVENTS.VPC
|
||||
//
|
||||
// Project Script
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
$Macro SRCDIR "..\.."
|
||||
$Macro OUTBINDIR "$SRCDIR\..\game\bin\tools"
|
||||
|
||||
$Include "$SRCDIR\vpc_scripts\source_dll_base.vpc"
|
||||
|
||||
$Configuration
|
||||
{
|
||||
$Compiler
|
||||
{
|
||||
$AdditionalIncludeDirectories "$BASE,.\,..\common,$SRCDIR\game\shared"
|
||||
$PreprocessorDefinitions "$BASE;GAMEEVENTS_EXPORTS"
|
||||
}
|
||||
|
||||
$Linker
|
||||
{
|
||||
$AdditionalDependencies "$BASE Psapi.lib"
|
||||
}
|
||||
}
|
||||
|
||||
$Project "GameEvents"
|
||||
{
|
||||
$Folder "Source Files"
|
||||
{
|
||||
$File "gameevents.cpp"
|
||||
$File "gameeventeditdoc.cpp"
|
||||
$File "gameeventeditpanel.cpp"
|
||||
|
||||
$File "$SRCDIR\public\interpolatortypes.cpp"
|
||||
$File "$SRCDIR\public\registry.cpp"
|
||||
$File "$SRCDIR\public\vgui_controls\vgui_controls.cpp"
|
||||
}
|
||||
|
||||
$Folder "Header Files"
|
||||
{
|
||||
$File "gameeventeditdoc.h"
|
||||
$File "gameeventeditpanel.h"
|
||||
$File "$SRCDIR\public\mathlib\mathlib.h"
|
||||
}
|
||||
|
||||
$Folder "Link Libraries"
|
||||
{
|
||||
$Lib datamodel
|
||||
$Lib dme_controls
|
||||
$Lib dmserializers
|
||||
$Lib mathlib
|
||||
$Lib matsys_controls
|
||||
$Lib movieobjects
|
||||
$Lib sfmobjects
|
||||
$Lib tier2
|
||||
$Lib tier3
|
||||
$Lib toolutils
|
||||
$Lib vgui_controls
|
||||
}
|
||||
}
|
||||
599
tools/pet/particlesystemdefinitionbrowser.cpp
Normal file
599
tools/pet/particlesystemdefinitionbrowser.cpp
Normal file
@@ -0,0 +1,599 @@
|
||||
//========= Copyright 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 "filesystem.h"
|
||||
#include "vgui_controls/FileOpenDialog.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_pParticleSystemsDefinitions = new vgui::ListPanel( this, "ParticleSystems" );
|
||||
m_pParticleSystemsDefinitions->AddColumnHeader( 0, "name", "Name", 52, ListPanel::COLUMN_RESIZEWITHWINDOW );
|
||||
m_pParticleSystemsDefinitions->SetColumnSortable( 0, true );
|
||||
m_pParticleSystemsDefinitions->SetEmptyListText( "No Particle System Definitions" );
|
||||
m_pParticleSystemsDefinitions->AddActionSignalTarget( this );
|
||||
m_pParticleSystemsDefinitions->SetSortFunc( 0, ParticleSystemNameSortFunc );
|
||||
m_pParticleSystemsDefinitions->SetSortColumn( 0 );
|
||||
|
||||
LoadControlSettingsAndUserConfig( "resource/particlesystemdefinitionbrowser.res" );
|
||||
|
||||
UpdateParticleSystemList();
|
||||
}
|
||||
|
||||
CParticleSystemDefinitionBrowser::~CParticleSystemDefinitionBrowser()
|
||||
{
|
||||
SaveUserConfig();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets the ith selected particle system
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeParticleSystemDefinition* CParticleSystemDefinitionBrowser::GetSelectedParticleSystem( int i )
|
||||
{
|
||||
int iSel = m_pParticleSystemsDefinitions->GetSelectedItem( i );
|
||||
KeyValues *kv = m_pParticleSystemsDefinitions->GetItem( iSel );
|
||||
return GetElementKeyValue< CDmeParticleSystemDefinition >( kv, "particleSystem" );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Deletes the marked objects.
|
||||
//-----------------------------------------------------------------------------
|
||||
void CParticleSystemDefinitionBrowser::DeleteParticleSystems()
|
||||
{
|
||||
int iSel = m_pParticleSystemsDefinitions->GetSelectedItem( 0 );
|
||||
int nRow = m_pParticleSystemsDefinitions->GetItemCurrentRow( iSel ) - 1;
|
||||
{
|
||||
// This is undoable
|
||||
CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, "Delete Particle Systems", "Delete Particle Systems" );
|
||||
|
||||
//
|
||||
// Build a list of objects to delete.
|
||||
//
|
||||
CUtlVector< CDmeParticleSystemDefinition* > itemsToDelete;
|
||||
int nCount = m_pParticleSystemsDefinitions->GetSelectedItemsCount();
|
||||
for (int i = 0; i < nCount; i++)
|
||||
{
|
||||
CDmeParticleSystemDefinition *pParticleSystem = GetSelectedParticleSystem( i );
|
||||
if ( pParticleSystem )
|
||||
{
|
||||
itemsToDelete.AddToTail( pParticleSystem );
|
||||
}
|
||||
}
|
||||
|
||||
nCount = itemsToDelete.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
m_pDoc->DeleteParticleSystemDefinition( itemsToDelete[i] );
|
||||
}
|
||||
}
|
||||
|
||||
// Update the list box selection.
|
||||
if ( m_pParticleSystemsDefinitions->GetItemCount() > 0 )
|
||||
{
|
||||
if ( nRow < 0 )
|
||||
{
|
||||
nRow = 0;
|
||||
}
|
||||
else if ( nRow >= m_pParticleSystemsDefinitions->GetItemCount() )
|
||||
{
|
||||
nRow = m_pParticleSystemsDefinitions->GetItemCount() - 1;
|
||||
}
|
||||
|
||||
iSel = m_pParticleSystemsDefinitions->GetItemIDFromRow( nRow );
|
||||
m_pParticleSystemsDefinitions->SetSingleSelectedItem( iSel );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pParticleSystemsDefinitions->ClearSelectedItems();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void CParticleSystemDefinitionBrowser::LoadKVSection( CDmeParticleSystemDefinition *pNew, KeyValues *pOverridesKv, ParticleFunctionType_t eType )
|
||||
{
|
||||
// Operator KV
|
||||
KeyValues *pOperator = pOverridesKv->FindKey( GetParticleFunctionTypeName(eType), NULL );
|
||||
if ( !pOperator )
|
||||
return;
|
||||
|
||||
// Function
|
||||
FOR_EACH_TRUE_SUBKEY( pOperator, pFunctionBlock )
|
||||
{
|
||||
int iFunction = pNew->FindFunction( eType, pFunctionBlock->GetName() );
|
||||
if ( iFunction >= 0 )
|
||||
{
|
||||
CDmeParticleFunction *pDmeFunction = pNew->GetParticleFunction( eType, iFunction );
|
||||
// Elements
|
||||
FOR_EACH_SUBKEY( pFunctionBlock, pAttributeItem )
|
||||
{
|
||||
CDmAttribute *pAttribute = pDmeFunction->GetAttribute( pAttributeItem->GetName() );
|
||||
if ( !pAttribute )
|
||||
{
|
||||
Warning( "Unable to Find Attribute [%s] in Function [%s] in Operator [%s] for Definition [%s]\n", pAttributeItem->GetName(), pFunctionBlock->GetName(), GetParticleFunctionTypeName(eType), pNew->GetName() );
|
||||
}
|
||||
else
|
||||
{
|
||||
pAttribute->SetValueFromString( pAttributeItem->GetString() );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Warning( "Function [%s] not found under Operator [%s] for Definition [%s]\n", pFunctionBlock->GetName(), GetParticleFunctionTypeName(eType), pNew->GetName() );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Given a KV, create, add and return an effect
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeParticleSystemDefinition* CParticleSystemDefinitionBrowser::CreateParticleFromKV( KeyValues *pKeyValue )
|
||||
{
|
||||
CDmeParticleSystemDefinition* pBaseParticleDef = NULL;
|
||||
|
||||
// Get the Base Particle Effect Def
|
||||
const char* pBaseParticleName = pKeyValue->GetString( "base_effect", "" );
|
||||
for ( int i = 0; i < m_pParticleSystemsDefinitions->GetItemCount(); ++i )
|
||||
{
|
||||
KeyValues *kv = m_pParticleSystemsDefinitions->GetItem( i );
|
||||
if ( !V_strcmp( kv->GetString( "name", "" ), pBaseParticleName ) )
|
||||
{
|
||||
//
|
||||
pBaseParticleDef = GetElementKeyValue< CDmeParticleSystemDefinition >( kv, "particleSystem" );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Base Particle could not be found, end;
|
||||
if ( !pBaseParticleDef )
|
||||
{
|
||||
Warning( "Unable to to find base particle system [%s]", pBaseParticleName );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Create a Copy of the Base Effect
|
||||
const char *pszNewParticleName = pKeyValue->GetName();
|
||||
//CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, "Copy Particle System", "Copy Particle System" );
|
||||
CDmeParticleSystemDefinition *pNew = CastElement<CDmeParticleSystemDefinition>( pBaseParticleDef->Copy() );
|
||||
pNew->SetName( pszNewParticleName );
|
||||
|
||||
// Overrides
|
||||
//
|
||||
//"properties"
|
||||
KeyValues *pProperties = pKeyValue->FindKey( "Properties", NULL );
|
||||
if ( pProperties )
|
||||
{
|
||||
FOR_EACH_SUBKEY( pProperties, pProperty )
|
||||
{
|
||||
CDmAttribute *pAttribute = pNew->GetAttribute( pProperty->GetName() );
|
||||
if ( !pAttribute )
|
||||
{
|
||||
Warning( "Unable to Find Attribute [%s] in Function [%s]\n", pProperty->GetName(), "Properties" );
|
||||
}
|
||||
else
|
||||
{
|
||||
pAttribute->SetValueFromString( pProperty->GetString() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LoadKVSection( pNew, pKeyValue, FUNCTION_RENDERER );
|
||||
LoadKVSection( pNew, pKeyValue, FUNCTION_OPERATOR );
|
||||
LoadKVSection( pNew, pKeyValue, FUNCTION_INITIALIZER );
|
||||
LoadKVSection( pNew, pKeyValue, FUNCTION_EMITTER );
|
||||
LoadKVSection( pNew, pKeyValue, FUNCTION_FORCEGENERATOR );
|
||||
LoadKVSection( pNew, pKeyValue, FUNCTION_CONSTRAINT );
|
||||
|
||||
// Remove copied children
|
||||
int iChildrenCount = pNew->GetParticleFunctionCount( FUNCTION_CHILDREN );
|
||||
for ( int i = iChildrenCount - 1; i >= 0; i-- )
|
||||
{
|
||||
pNew->RemoveFunction( FUNCTION_CHILDREN, i );
|
||||
}
|
||||
|
||||
// Search Children
|
||||
KeyValues *pChildren = pKeyValue->FindKey( "Children", NULL );
|
||||
if ( pChildren )
|
||||
{
|
||||
FOR_EACH_TRUE_SUBKEY( pChildren, pChild )
|
||||
{
|
||||
// each Child is its own effect so we need to add it and return it
|
||||
CDmeParticleSystemDefinition* pChildEffect = CreateParticleFromKV( pChild );
|
||||
if ( pChildEffect )
|
||||
{
|
||||
pNew->AddChild( pChildEffect );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_pDoc->ReplaceParticleSystemDefinition( pNew );
|
||||
m_pDoc->UpdateAllParticleSystems();
|
||||
return pNew;
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
// Create from KV
|
||||
void CParticleSystemDefinitionBrowser::CreateParticleSystemsFromKV( const char *pFileName )
|
||||
{
|
||||
//
|
||||
//const char * pFileName = "particles\\_weapon_prefab_override_kv.txt";
|
||||
|
||||
CUtlBuffer bufRawData;
|
||||
bool bReadFileOK = g_pFullFileSystem->ReadFile( pFileName, "MOD", bufRawData );
|
||||
if ( !bReadFileOK )
|
||||
{
|
||||
Warning( "Unable to Open KV file [%s]\n", pFileName );
|
||||
return;
|
||||
}
|
||||
|
||||
// Wrap it with a text buffer reader
|
||||
CUtlBuffer bufText( bufRawData.Base(), bufRawData.TellPut(), CUtlBuffer::READ_ONLY | CUtlBuffer::TEXT_BUFFER );
|
||||
|
||||
KeyValues *pBaseKeyValue = NULL;
|
||||
pBaseKeyValue = new KeyValues( "CCreateParticlesFromKV" );
|
||||
|
||||
if ( !pBaseKeyValue->LoadFromBuffer( NULL, bufText ) )
|
||||
{
|
||||
Warning( "Unable to Read KV file [%s]\n", pFileName );
|
||||
pBaseKeyValue->deleteThis();
|
||||
return;
|
||||
}
|
||||
|
||||
FOR_EACH_TRUE_SUBKEY( pBaseKeyValue, pKVOver )
|
||||
{
|
||||
CreateParticleFromKV( pKVOver );
|
||||
}
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CParticleSystemDefinitionBrowser::OnKeyCodeTyped( vgui::KeyCode code )
|
||||
{
|
||||
if ( code == KEY_DELETE )
|
||||
{
|
||||
DeleteParticleSystems();
|
||||
}
|
||||
else
|
||||
{
|
||||
BaseClass::OnKeyCodeTyped( code );
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void CParticleSystemDefinitionBrowser::OnFileSelected(const char *fullpath)
|
||||
{
|
||||
CreateParticleSystemsFromKV( fullpath );
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called when the selection changes
|
||||
//-----------------------------------------------------------------------------
|
||||
void CParticleSystemDefinitionBrowser::UpdateParticleSystemSelection()
|
||||
{
|
||||
if ( m_pParticleSystemsDefinitions->GetSelectedItemsCount() == 1 )
|
||||
{
|
||||
CDmeParticleSystemDefinition *pParticleSystem = GetSelectedParticleSystem( 0 );
|
||||
g_pPetTool->SetCurrentParticleSystem( pParticleSystem, false );
|
||||
}
|
||||
else
|
||||
{
|
||||
g_pPetTool->SetCurrentParticleSystem( NULL, false );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Item selection/deselection
|
||||
//-----------------------------------------------------------------------------
|
||||
void CParticleSystemDefinitionBrowser::OnItemSelected( void )
|
||||
{
|
||||
UpdateParticleSystemSelection();
|
||||
}
|
||||
|
||||
void CParticleSystemDefinitionBrowser::OnItemDeselected( void )
|
||||
{
|
||||
UpdateParticleSystemSelection();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Select a particular node
|
||||
//-----------------------------------------------------------------------------
|
||||
void CParticleSystemDefinitionBrowser::SelectParticleSystem( CDmeParticleSystemDefinition *pFind )
|
||||
{
|
||||
m_pParticleSystemsDefinitions->ClearSelectedItems();
|
||||
for ( int nItemID = m_pParticleSystemsDefinitions->FirstItem(); nItemID != m_pParticleSystemsDefinitions->InvalidItemID(); nItemID = m_pParticleSystemsDefinitions->NextItem( nItemID ) )
|
||||
{
|
||||
KeyValues *kv = m_pParticleSystemsDefinitions->GetItem( nItemID );
|
||||
CDmeParticleSystemDefinition *pParticleSystem = GetElementKeyValue<CDmeParticleSystemDefinition>( kv, "particleSystem" );
|
||||
if ( pParticleSystem == pFind )
|
||||
{
|
||||
m_pParticleSystemsDefinitions->AddSelectedItem( nItemID );
|
||||
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" ) )
|
||||
{
|
||||
int nCount = m_pParticleSystemsDefinitions->GetSelectedItemsCount();
|
||||
if ( nCount )
|
||||
{
|
||||
CDmeParticleSystemDefinition *pParticleSystem = GetSelectedParticleSystem( 0 );
|
||||
CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, "Copy Particle System",
|
||||
"Copy Particle System" );
|
||||
CDmeParticleSystemDefinition * pNew =
|
||||
CastElement<CDmeParticleSystemDefinition>( pParticleSystem->Copy( ) );
|
||||
pNew->SetName( pText );
|
||||
m_pDoc->AddNewParticleSystemDefinition( pNew, guard );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copy to clipboard
|
||||
//-----------------------------------------------------------------------------
|
||||
void CParticleSystemDefinitionBrowser::CopyToClipboard( )
|
||||
{
|
||||
int nCount = m_pParticleSystemsDefinitions->GetSelectedItemsCount();
|
||||
|
||||
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( "pcf", (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::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 )
|
||||
{
|
||||
const char *pData = list[i]->GetString( "pcf" );
|
||||
if ( !pData )
|
||||
continue;
|
||||
|
||||
int nLen = Q_strlen( pData );
|
||||
CUtlBuffer buf( pData, nLen, CUtlBuffer::TEXT_BUFFER | CUtlBuffer::READ_ONLY );
|
||||
|
||||
DmElementHandle_t hRoot;
|
||||
if ( !g_pDataModel->Unserialize( buf, "keyvalues2", "pcf", NULL, "paste", CR_FORCE_COPY, hRoot ) )
|
||||
continue;
|
||||
|
||||
CDmeParticleSystemDefinition *pDef = GetElement<CDmeParticleSystemDefinition>( hRoot );
|
||||
if ( !pDef )
|
||||
continue;
|
||||
|
||||
ReplaceDef_r( guard, pDef );
|
||||
bRefreshAll = true;
|
||||
}
|
||||
|
||||
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" ) )
|
||||
{
|
||||
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("copy") );
|
||||
return;
|
||||
}
|
||||
if ( !Q_stricmp( pCommand, "Create From KeyValue" ) )
|
||||
{
|
||||
vgui::FileOpenDialog *pDialog = new vgui::FileOpenDialog( g_pPetTool->GetRootPanel(), "Select KV File", vgui::FOD_OPEN );
|
||||
pDialog->SetTitle( "Choose KeyValue File", true );
|
||||
pDialog->AddFilter( "*.txt", "KeyValue File (*.txt)", true );
|
||||
pDialog->AddActionSignalTarget( this );
|
||||
|
||||
char szParticlesDir[MAX_PATH];
|
||||
pDialog->SetStartDirectory( g_pFullFileSystem->RelativePathToFullPath( "particles", "MOD", szParticlesDir, sizeof(szParticlesDir) ) );
|
||||
pDialog->DoModal( new KeyValues( "Create From KeyValue" ) );
|
||||
|
||||
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(void)
|
||||
{
|
||||
const CDmrParticleSystemList particleSystemList = m_pDoc->GetParticleSystemDefinitionList();
|
||||
if ( !particleSystemList.IsValid() )
|
||||
return;
|
||||
|
||||
// Maintain selection if possible
|
||||
CUtlVector< CUtlString > selectedItems;
|
||||
int nCount = m_pParticleSystemsDefinitions->GetSelectedItemsCount();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
CDmeParticleSystemDefinition *pParticleSystem = GetSelectedParticleSystem( i );
|
||||
if ( pParticleSystem )
|
||||
{
|
||||
selectedItems.AddToTail( pParticleSystem->GetName() );
|
||||
}
|
||||
}
|
||||
|
||||
m_pParticleSystemsDefinitions->RemoveAll();
|
||||
int nSelectedItemCount = selectedItems.Count();
|
||||
nCount = particleSystemList.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
CDmeParticleSystemDefinition *pParticleSystem = particleSystemList[i];
|
||||
if ( !pParticleSystem )
|
||||
continue;
|
||||
|
||||
const char *pName = pParticleSystem->GetName();
|
||||
if ( !pName || !pName[0] )
|
||||
{
|
||||
pName = "<no name>";
|
||||
}
|
||||
|
||||
KeyValues *kv = new KeyValues( "node" );
|
||||
kv->SetString( "name", pName );
|
||||
SetElementKeyValue( kv, "particleSystem", pParticleSystem );
|
||||
|
||||
int nItemID = m_pParticleSystemsDefinitions->AddItem( kv, 0, false, false );
|
||||
|
||||
for ( int j = 0; j < nSelectedItemCount; ++j )
|
||||
{
|
||||
if ( Q_stricmp( selectedItems[j], pName ) )
|
||||
continue;
|
||||
|
||||
m_pParticleSystemsDefinitions->AddSelectedItem( nItemID );
|
||||
selectedItems.FastRemove(j);
|
||||
--nSelectedItemCount;
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_pParticleSystemsDefinitions->SortList();
|
||||
}
|
||||
|
||||
90
tools/pet/particlesystemdefinitionbrowser.h
Normal file
90
tools/pet/particlesystemdefinitionbrowser.h
Normal file
@@ -0,0 +1,90 @@
|
||||
//========= Copyright 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"
|
||||
#include "particles/particles.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class CPetDoc;
|
||||
class CDmeParticleSystemDefinition;
|
||||
class CUndoScopeGuard;
|
||||
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 );
|
||||
MESSAGE_FUNC_CHARPTR( OnFileSelected, "FileSelected", fullpath );
|
||||
// Methods related to updating the listpanel
|
||||
void UpdateParticleSystemList();
|
||||
|
||||
// Select a particular node
|
||||
void SelectParticleSystem( CDmeParticleSystemDefinition *pParticleSystem );
|
||||
|
||||
// Copy, paste.
|
||||
void CopyToClipboard( );
|
||||
void PasteFromClipboard( );
|
||||
|
||||
private:
|
||||
// Messages handled
|
||||
MESSAGE_FUNC( OnItemDeselected, "ItemDeselected" );
|
||||
MESSAGE_FUNC( OnItemSelected, "ItemSelected" );
|
||||
MESSAGE_FUNC_PARAMS( OnInputCompleted, "InputCompleted", kv );
|
||||
|
||||
void ReplaceDef_r( CUndoScopeGuard& guard, CDmeParticleSystemDefinition *pDef );
|
||||
|
||||
// Gets the ith selected particle system
|
||||
CDmeParticleSystemDefinition* GetSelectedParticleSystem( int i );
|
||||
|
||||
// Called when the selection changes
|
||||
void UpdateParticleSystemSelection();
|
||||
|
||||
// Deletes selected particle systems
|
||||
void DeleteParticleSystems();
|
||||
|
||||
// Create from KV
|
||||
void LoadKVSection( CDmeParticleSystemDefinition *pNew, KeyValues *pOverridesKv, ParticleFunctionType_t eType );
|
||||
CDmeParticleSystemDefinition* CreateParticleFromKV( KeyValues *pKeyValue );
|
||||
void CreateParticleSystemsFromKV( const char *pFilepath );
|
||||
|
||||
// Shows the most recent selected object in properties window
|
||||
void OnProperties();
|
||||
|
||||
CPetDoc *m_pDoc;
|
||||
vgui::ListPanel *m_pParticleSystemsDefinitions;
|
||||
};
|
||||
|
||||
|
||||
#endif // PARTICLESYSTEMDEFINITIONBROWSER_H
|
||||
73
tools/pet/particlesystempropertiescontainer.cpp
Normal file
73
tools/pet/particlesystempropertiescontainer.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
//========= Copyright 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 );
|
||||
}
|
||||
}
|
||||
|
||||
45
tools/pet/particlesystempropertiescontainer.h
Normal file
45
tools/pet/particlesystempropertiescontainer.h
Normal file
@@ -0,0 +1,45 @@
|
||||
//========= Copyright 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
tools/pet/pet.vpc
Normal file
64
tools/pet/pet.vpc
Normal file
@@ -0,0 +1,64 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// PET.VPC
|
||||
//
|
||||
// Project Script
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
$Macro SRCDIR "..\.."
|
||||
$Macro OUTBINDIR "$SRCDIR\..\game\bin\tools"
|
||||
|
||||
$Include "$SRCDIR\vpc_scripts\source_dll_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"
|
||||
{
|
||||
$Lib datamodel
|
||||
$Lib dme_controls
|
||||
$Lib dmserializers
|
||||
$Lib dmxloader
|
||||
$Lib mathlib
|
||||
$Lib matsys_controls
|
||||
$Lib movieobjects
|
||||
$Lib particles
|
||||
$Lib sfmobjects
|
||||
$Lib tier2
|
||||
$Lib tier3
|
||||
$Lib toolutils
|
||||
$Lib vgui_controls
|
||||
}
|
||||
}
|
||||
536
tools/pet/petdoc.cpp
Normal file
536
tools/pet/petdoc.cpp
Normal file
@@ -0,0 +1,536 @@
|
||||
//========= Copyright 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/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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
SetDirty( false );
|
||||
return true;
|
||||
}
|
||||
|
||||
void CPetDoc::SaveToFile( )
|
||||
{
|
||||
if ( m_hRoot.Get() && m_pFileName && m_pFileName[0] )
|
||||
{
|
||||
g_pDataModel->SaveToFile( m_pFileName, NULL, "binary", PET_FILE_FORMAT, m_hRoot );
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
void CPetDoc::AddNewParticleSystemDefinition( CDmeParticleSystemDefinition *pNew, CUndoScopeGuard &Guard )
|
||||
{
|
||||
CDmrParticleSystemList particleSystemList( GetParticleSystemDefinitionList() );
|
||||
|
||||
particleSystemList.AddToTail( pNew );
|
||||
Guard.Release();
|
||||
|
||||
// Force a resolve to get the particle created
|
||||
g_pDmElementFramework->Operate( true );
|
||||
g_pDmElementFramework->BeginEdit();
|
||||
|
||||
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, "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, "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;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Deletes 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 );
|
||||
}
|
||||
|
||||
|
||||
122
tools/pet/petdoc.h
Normal file
122
tools/pet/petdoc.h
Normal file
@@ -0,0 +1,122 @@
|
||||
//========= Copyright 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();
|
||||
|
||||
// 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
|
||||
1078
tools/pet/pettool.cpp
Normal file
1078
tools/pet/pettool.cpp
Normal file
File diff suppressed because it is too large
Load Diff
209
tools/pet/pettool.h
Normal file
209
tools/pet/pettool.h
Normal file
@@ -0,0 +1,209 @@
|
||||
//========= Copyright 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 CDmeParticleSystemDefinition;
|
||||
enum ParticleFunctionType_t;
|
||||
|
||||
namespace vgui
|
||||
{
|
||||
class Panel;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// 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();
|
||||
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();
|
||||
|
||||
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( OnCopy, "OnCopy" );
|
||||
MESSAGE_FUNC( OnPaste, "OnPaste" );
|
||||
|
||||
// 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( 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_copy, KEY_C, vgui::MODIFIER_CONTROL, OnCopy, "#edit_copy_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();
|
||||
|
||||
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;
|
||||
|
||||
// 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
|
||||
9
tools/sampletool/cbase.cpp
Normal file
9
tools/sampletool/cbase.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "cbase.h"
|
||||
|
||||
// This file causes the .pch to be built
|
||||
46
tools/sampletool/cbase.h
Normal file
46
tools/sampletool/cbase.h
Normal file
@@ -0,0 +1,46 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#ifndef CBASE_H
|
||||
#define CBASE_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
// Silence certain warnings
|
||||
#pragma warning(disable : 4244) // int or float down-conversion
|
||||
#pragma warning(disable : 4305) // int or float data truncation
|
||||
#pragma warning(disable : 4201) // nameless struct/union
|
||||
#pragma warning(disable : 4511) // copy constructor could not be generated
|
||||
#pragma warning(disable : 4675) // resolved overload was found by argument dependent lookup
|
||||
#pragma warning(disable : 4706) // assignment within conditional expression
|
||||
#endif
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define DEBUG 1
|
||||
#endif
|
||||
|
||||
// Misc C-runtime library headers
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include "minmax.h"
|
||||
|
||||
// tier 0
|
||||
#include "tier0/dbg.h"
|
||||
#include "tier0/platform.h"
|
||||
#include "basetypes.h"
|
||||
|
||||
// tier 1
|
||||
#include "tier1/strtools.h"
|
||||
#include "utlvector.h"
|
||||
#include "mathlib/vmatrix.h"
|
||||
#include "filesystem.h"
|
||||
|
||||
#include "tier1/ConVar.h"
|
||||
#include "icvar.h"
|
||||
|
||||
#endif // CBASE_H
|
||||
342
tools/sampletool/sampletool.cpp
Normal file
342
tools/sampletool/sampletool.cpp
Normal file
@@ -0,0 +1,342 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Core Movie Maker UI API
|
||||
//
|
||||
//=============================================================================
|
||||
#include "cbase.h"
|
||||
|
||||
#include "toolutils/basetoolsystem.h"
|
||||
#include "toolutils/recentfilelist.h"
|
||||
#include "toolutils/toolmenubar.h"
|
||||
#include "toolutils/toolswitchmenubutton.h"
|
||||
#include "toolutils/toolfilemenubutton.h"
|
||||
#include "toolutils/toolmenubutton.h"
|
||||
#include "vgui_controls/Menu.h"
|
||||
#include "tier1/KeyValues.h"
|
||||
#include "toolutils/enginetools_int.h"
|
||||
#include "toolframework/ienginetool.h"
|
||||
#include "vgui/IInput.h"
|
||||
#include "vgui/KeyCode.h"
|
||||
#include "vgui_controls/FileOpenDialog.h"
|
||||
#include "filesystem.h"
|
||||
#include "vgui/ilocalize.h"
|
||||
#include "dme_controls/elementpropertiestree.h"
|
||||
#include "tier0/icommandline.h"
|
||||
#include "materialsystem/imaterialsystem.h"
|
||||
#include "VGuiMatSurface/IMatSystemSurface.h"
|
||||
#include "tier3/tier3.h"
|
||||
#include "tier2/fileutils.h"
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
|
||||
const char *GetVGuiControlsModuleName()
|
||||
{
|
||||
return "SampleTool";
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Connect, disconnect
|
||||
//-----------------------------------------------------------------------------
|
||||
bool ConnectTools( CreateInterfaceFn factory )
|
||||
{
|
||||
return (materials != NULL) && (g_pMatSystemSurface != NULL);
|
||||
}
|
||||
|
||||
void DisconnectTools( )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Implementation of the sample tool
|
||||
//-----------------------------------------------------------------------------
|
||||
class CSampleTool : public CBaseToolSystem, public IFileMenuCallbacks
|
||||
{
|
||||
DECLARE_CLASS_SIMPLE( CSampleTool, CBaseToolSystem );
|
||||
|
||||
public:
|
||||
CSampleTool();
|
||||
|
||||
// Inherited from IToolSystem
|
||||
virtual const char *GetToolName() { return "Sample Tool"; }
|
||||
virtual const char *GetBindingsContextFile() { return "cfg/SampleTool.kb"; }
|
||||
virtual bool Init( );
|
||||
virtual void Shutdown();
|
||||
|
||||
// Inherited from IFileMenuCallbacks
|
||||
virtual int GetFileMenuItemsEnabled( );
|
||||
virtual void AddRecentFilesToMenu( vgui::Menu *menu );
|
||||
virtual bool GetPerforceFileName( char *pFileName, int nMaxLen ) { return false; }
|
||||
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 "SampleTool"; }
|
||||
virtual vgui::MenuBar *CreateMenuBar( CBaseToolSystem *pParent );
|
||||
|
||||
public:
|
||||
MESSAGE_FUNC( OnNew, "OnNew" );
|
||||
MESSAGE_FUNC( OnOpen, "OnOpen" );
|
||||
MESSAGE_FUNC( OnSave, "OnSave" );
|
||||
MESSAGE_FUNC( OnSaveAs, "OnSaveAs" );
|
||||
MESSAGE_FUNC( OnClose, "OnClose" );
|
||||
MESSAGE_FUNC( OnCloseNoSave, "OnCloseNoSave" );
|
||||
MESSAGE_FUNC( OnMarkNotDirty, "OnMarkNotDirty" );
|
||||
MESSAGE_FUNC( OnExit, "OnExit" );
|
||||
|
||||
void OpenFileFromHistory( int slot );
|
||||
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 );
|
||||
|
||||
private:
|
||||
// Loads up a new document
|
||||
void LoadDocument( const char *pDocName );
|
||||
|
||||
// Updates the menu bar based on the current file
|
||||
void UpdateMenuBar( );
|
||||
|
||||
// Shows element properties
|
||||
void ShowElementProperties( );
|
||||
|
||||
virtual const char *GetLogoTextureName();
|
||||
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Singleton
|
||||
//-----------------------------------------------------------------------------
|
||||
CSampleTool *g_pSampleTool = NULL;
|
||||
|
||||
void CreateTools()
|
||||
{
|
||||
g_pSampleTool = new CSampleTool();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CSampleTool::CSampleTool()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Init, shutdown
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CSampleTool::Init( )
|
||||
{
|
||||
m_RecentFiles.LoadFromRegistry( GetRegistryName() );
|
||||
|
||||
// NOTE: This has to happen before BaseClass::Init
|
||||
// g_pVGuiLocalize->AddFile( "resource/toolsample_%language%.txt" );
|
||||
|
||||
if ( !BaseClass::Init( ) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CSampleTool::Shutdown()
|
||||
{
|
||||
m_RecentFiles.SaveToRegistry( GetRegistryName() );
|
||||
BaseClass::Shutdown();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Derived classes can implement this to get a new scheme to be applied to this tool
|
||||
//-----------------------------------------------------------------------------
|
||||
vgui::HScheme CSampleTool::GetToolScheme()
|
||||
{
|
||||
return vgui::scheme()->LoadSchemeFromFile( "Resource/BoxRocket.res", "SampleTool" );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Initializes the menu bar
|
||||
//-----------------------------------------------------------------------------
|
||||
vgui::MenuBar *CSampleTool::CreateMenuBar( CBaseToolSystem *pParent )
|
||||
{
|
||||
CToolMenuBar *pMenuBar = new CToolMenuBar( pParent, "Main Menu Bar" );
|
||||
|
||||
// Sets info in the menu bar
|
||||
char title[ 64 ];
|
||||
ComputeMenuBarTitle( title, sizeof( title ) );
|
||||
pMenuBar->SetInfo( title );
|
||||
pMenuBar->SetToolName( GetToolName() );
|
||||
|
||||
// Add menu buttons
|
||||
CToolMenuButton *pFileButton = CreateToolFileMenuButton( pMenuBar, "File", "&File", GetActionTarget(), this );
|
||||
CToolMenuButton *pSwitchButton = CreateToolSwitchMenuButton( pMenuBar, "Switcher", "&Tools", GetActionTarget() );
|
||||
|
||||
pMenuBar->AddButton( pFileButton );
|
||||
pMenuBar->AddButton( pSwitchButton );
|
||||
|
||||
return pMenuBar;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Creates the action menu
|
||||
//-----------------------------------------------------------------------------
|
||||
vgui::Menu *CSampleTool::CreateActionMenu( vgui::Panel *pParent )
|
||||
{
|
||||
vgui::Menu *pActionMenu = new Menu( pParent, "ActionMenu" );
|
||||
pActionMenu->AddMenuItem( "#ToolHide", new KeyValues( "Command", "command", "HideActionMenu" ), GetActionTarget() );
|
||||
return pActionMenu;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Inherited from IFileMenuCallbacks
|
||||
//-----------------------------------------------------------------------------
|
||||
int CSampleTool::GetFileMenuItemsEnabled( )
|
||||
{
|
||||
int nFlags = FILE_ALL;
|
||||
if ( m_RecentFiles.IsEmpty() )
|
||||
{
|
||||
nFlags &= ~(FILE_RECENT | FILE_CLEAR_RECENT);
|
||||
}
|
||||
return nFlags;
|
||||
}
|
||||
|
||||
void CSampleTool::AddRecentFilesToMenu( vgui::Menu *pMenu )
|
||||
{
|
||||
m_RecentFiles.AddToMenu( pMenu, GetActionTarget(), "OnRecent" );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : -
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSampleTool::OnExit()
|
||||
{
|
||||
enginetools->Command( "quit\n" );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Handle commands from the action menu and other menus
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSampleTool::OnCommand( const char *cmd )
|
||||
{
|
||||
if ( !V_stricmp( cmd, "HideActionMenu" ) )
|
||||
{
|
||||
if ( GetActionMenu() )
|
||||
{
|
||||
GetActionMenu()->SetVisible( false );
|
||||
}
|
||||
}
|
||||
else if ( const char *pSuffix = StringAfterPrefix( cmd, "OnRecent" ) )
|
||||
{
|
||||
int idx = Q_atoi( pSuffix );
|
||||
OpenFileFromHistory( idx );
|
||||
}
|
||||
else if( const char *pSuffix = StringAfterPrefix( cmd, "OnTool" ) )
|
||||
{
|
||||
int idx = Q_atoi( pSuffix );
|
||||
enginetools->SwitchToTool( idx );
|
||||
}
|
||||
else
|
||||
{
|
||||
BaseClass::OnCommand( cmd );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Command handlers
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSampleTool::OnNew()
|
||||
{
|
||||
// FIXME: Implement
|
||||
}
|
||||
|
||||
void CSampleTool::OnOpen()
|
||||
{
|
||||
OpenFile( "txt" );
|
||||
}
|
||||
|
||||
bool CSampleTool::OnReadFileFromDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues )
|
||||
{
|
||||
// FIXME: Implement
|
||||
|
||||
m_RecentFiles.Add( pFileName, pFileFormat );
|
||||
return true;
|
||||
}
|
||||
|
||||
void CSampleTool::OnSave()
|
||||
{
|
||||
// FIXME: Implement
|
||||
}
|
||||
|
||||
void CSampleTool::OnSaveAs()
|
||||
{
|
||||
SaveFile( NULL, NULL, 0 );
|
||||
}
|
||||
|
||||
bool CSampleTool::OnWriteFileToDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues )
|
||||
{
|
||||
// FIXME: Implement
|
||||
|
||||
m_RecentFiles.Add( pFileName, pFileFormat );
|
||||
return true;
|
||||
}
|
||||
|
||||
void CSampleTool::OnClose()
|
||||
{
|
||||
// FIXME: Implement
|
||||
}
|
||||
|
||||
void CSampleTool::OnCloseNoSave()
|
||||
{
|
||||
// FIXME: Implement
|
||||
}
|
||||
|
||||
void CSampleTool::OnMarkNotDirty()
|
||||
{
|
||||
// FIXME: Implement
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Show the save document query dialog
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSampleTool::OpenFileFromHistory( int slot )
|
||||
{
|
||||
const char *pFileName = m_RecentFiles.GetFile( slot );
|
||||
OnReadFileFromDisk( pFileName, NULL, 0 );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called when file operations complete
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSampleTool::OnFileOperationCompleted( const char *pFileType, bool bWroteFile, vgui::FileOpenStateMachine::CompletionState_t state, KeyValues *pContextKeyValues )
|
||||
{
|
||||
// FIXME: Implement
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Show the File browser dialog
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSampleTool::SetupFileOpenDialog( vgui::FileOpenDialog *pDialog, bool bOpenFile, const char *pFileFormat, KeyValues *pContextKeyValues )
|
||||
{
|
||||
char pStartingDir[ MAX_PATH ];
|
||||
GetModSubdirectory( NULL, pStartingDir, sizeof(pStartingDir) );
|
||||
|
||||
pDialog->SetTitle( "Choose SampleTool .txt file", true );
|
||||
pDialog->SetStartDirectoryContext( "sample_session", pStartingDir );
|
||||
pDialog->AddFilter( "*.txt", "SampleTool (*.txt)", true );
|
||||
}
|
||||
|
||||
const char *CSampleTool::GetLogoTextureName()
|
||||
{
|
||||
return "vgui/tools/sampletool/sampletool_logo";
|
||||
}
|
||||
79
tools/sampletool/sampletool.vpc
Normal file
79
tools/sampletool/sampletool.vpc
Normal file
@@ -0,0 +1,79 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// SAMPLETOOL.VPC
|
||||
//
|
||||
// Project Script
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
$Macro SRCDIR "..\.."
|
||||
$Macro OUTBINDIR "$SRCDIR\..\game\bin\tools"
|
||||
|
||||
$Include "$SRCDIR\vpc_scripts\source_dll_base.vpc"
|
||||
|
||||
$Configuration
|
||||
{
|
||||
$Compiler
|
||||
{
|
||||
$AdditionalIncludeDirectories "$BASE,.\,..\common,$SRCDIR\game\shared"
|
||||
$PreprocessorDefinitions "$BASE;SAMPLETOOL_EXPORTS"
|
||||
$Create/UsePrecompiledHeader "Use Precompiled Header (/Yu)"
|
||||
$Create/UsePCHThroughFile "cbase.h"
|
||||
}
|
||||
|
||||
$Linker
|
||||
{
|
||||
$AdditionalDependencies "$BASE Psapi.lib"
|
||||
}
|
||||
}
|
||||
|
||||
$Project "Sampletool"
|
||||
{
|
||||
$Folder "Source Files"
|
||||
{
|
||||
$File "sampletool.cpp"
|
||||
$File "cbase.cpp"
|
||||
{
|
||||
$Configuration
|
||||
{
|
||||
$Compiler
|
||||
{
|
||||
$Create/UsePrecompiledHeader "Create Precompiled Header (/Yc)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$File "$SRCDIR\public\interpolatortypes.cpp" \
|
||||
"$SRCDIR\public\registry.cpp" \
|
||||
"$SRCDIR\public\vgui_controls\vgui_controls.cpp"
|
||||
{
|
||||
$Configuration
|
||||
{
|
||||
$Compiler
|
||||
{
|
||||
$Create/UsePrecompiledHeader "Not Using Precompiled Headers"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$Folder "Header Files"
|
||||
{
|
||||
$File "cbase.h"
|
||||
$File "$SRCDIR\public\interpolatortypes.h"
|
||||
$File "$SRCDIR\public\mathlib\mathlib.h"
|
||||
}
|
||||
|
||||
$Folder "Link Libraries"
|
||||
{
|
||||
$Lib datamodel
|
||||
$Lib dme_controls
|
||||
$Lib dmserializers
|
||||
$Lib mathlib
|
||||
$Lib matsys_controls
|
||||
$Lib movieobjects
|
||||
$Lib sfmobjects
|
||||
$Lib tier2
|
||||
$Lib tier3
|
||||
$Lib toolutils
|
||||
$Lib vgui_controls
|
||||
}
|
||||
}
|
||||
1156
tools/toolutils/BaseToolSystem.cpp
Normal file
1156
tools/toolutils/BaseToolSystem.cpp
Normal file
File diff suppressed because it is too large
Load Diff
45
tools/toolutils/ConsolePage.cpp
Normal file
45
tools/toolutils/ConsolePage.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
//========= Copyright 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);
|
||||
}
|
||||
251
tools/toolutils/ToolFileMenuButton.cpp
Normal file
251
tools/toolutils/ToolFileMenuButton.cpp
Normal file
@@ -0,0 +1,251 @@
|
||||
//========= Copyright 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 );
|
||||
|
||||
AddMenuItem( "clearrecent", "#ToolFileClearRecent", new KeyValues ( "OnClearRecent" ), pActionSignalTarget );
|
||||
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 );
|
||||
id = m_Items.Find( "clearrecent" );
|
||||
SetItemEnabled( id, (nEnableMask & IFileMenuCallbacks::FILE_CLEAR_RECENT) != 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();
|
||||
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
tools/toolutils/ToolHelpMenuButton.cpp
Normal file
60
tools/toolutils/ToolHelpMenuButton.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
//========= Copyright 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);
|
||||
}
|
||||
185
tools/toolutils/ToolMenuButton.cpp
Normal file
185
tools/toolutils/ToolMenuButton.cpp
Normal file
@@ -0,0 +1,185 @@
|
||||
//========= Copyright 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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
72
tools/toolutils/ToolSwitchMenuButton.cpp
Normal file
72
tools/toolutils/ToolSwitchMenuButton.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
//========= Copyright 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"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Menu to switch between tools
|
||||
//-----------------------------------------------------------------------------
|
||||
class CToolSwitchMenuButton : public CToolMenuButton
|
||||
{
|
||||
DECLARE_CLASS_SIMPLE( CToolSwitchMenuButton, CToolMenuButton );
|
||||
|
||||
public:
|
||||
CToolSwitchMenuButton( vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionTarget );
|
||||
virtual void OnShowMenu(vgui::Menu *menu);
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Global function to create the switch menu
|
||||
//-----------------------------------------------------------------------------
|
||||
CToolMenuButton* CreateToolSwitchMenuButton( vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionTarget )
|
||||
{
|
||||
return new CToolSwitchMenuButton( parent, panelName, text, pActionTarget );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CToolSwitchMenuButton::CToolSwitchMenuButton( vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionTarget ) :
|
||||
BaseClass( parent, panelName, text, pActionTarget )
|
||||
{
|
||||
SetMenu(m_pMenu);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Is called when the menu is made visible
|
||||
//-----------------------------------------------------------------------------
|
||||
void CToolSwitchMenuButton::OnShowMenu(vgui::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 ) ) );
|
||||
}
|
||||
}
|
||||
118
tools/toolutils/ToolUI.cpp
Normal file
118
tools/toolutils/ToolUI.cpp
Normal file
@@ -0,0 +1,118 @@
|
||||
//========= Copyright 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"
|
||||
#include "toolutils/toolmenubar.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
tools/toolutils/ToolUI.h
Normal file
66
tools/toolutils/ToolUI.h
Normal file
@@ -0,0 +1,66 @@
|
||||
//========= Copyright 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
|
||||
137
tools/toolutils/attributeelementchoicelist.cpp
Normal file
137
tools/toolutils/attributeelementchoicelist.cpp
Normal file
@@ -0,0 +1,137 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#include "toolutils/attributeelementchoicelist.h"
|
||||
#include "datamodel/dmelement.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 = g_pDataModel->GetString( CDmElement::GetStaticTypeSymbol() );
|
||||
}
|
||||
|
||||
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 = g_pDataModel->GetString( CDmElement::GetStaticTypeSymbol() );
|
||||
}
|
||||
|
||||
ElementDict_t dict( 0, 0, DefLessFunc( CDmElement * ) );
|
||||
AddElementsRecursively_R( pElement, list, dict, pElementType );
|
||||
}
|
||||
47
tools/toolutils/basepropertiescontainer.cpp
Normal file
47
tools/toolutils/basepropertiescontainer.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
//========= Copyright 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
tools/toolutils/basestatusbar.cpp
Normal file
151
tools/toolutils/basestatusbar.cpp
Normal file
@@ -0,0 +1,151 @@
|
||||
//========= Copyright 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;
|
||||
}
|
||||
457
tools/toolutils/miniviewport.cpp
Normal file
457
tools/toolutils/miniviewport.cpp
Normal file
@@ -0,0 +1,457 @@
|
||||
//========= Copyright 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 "tier2/tier2.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;
|
||||
|
||||
extern IMatSystemSurface *g_pMatSystemSurface;
|
||||
|
||||
#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 );
|
||||
|
||||
// Called when the layoff texture needs to be released
|
||||
void ReleaseLayoffTexture();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called when the layoff texture needs to be released
|
||||
//-----------------------------------------------------------------------------
|
||||
void CMiniViewportEngineRenderArea::ReleaseLayoffTexture()
|
||||
{
|
||||
m_ScreenBuffer.Shutdown();
|
||||
m_ScreenMaterial.Shutdown();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// 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 );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called when the layoff texture needs to be released
|
||||
//-----------------------------------------------------------------------------
|
||||
void CMiniViewport::ReleaseLayoffTexture()
|
||||
{
|
||||
if ( m_hPage.Get() )
|
||||
{
|
||||
m_hPage->GetViewportArea()->ReleaseLayoffTexture();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
157
tools/toolutils/recentfilelist.cpp
Normal file
157
tools/toolutils/recentfilelist.cpp
Normal file
@@ -0,0 +1,157 @@
|
||||
//========= Copyright 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 CRecentFileList::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 CRecentFileList::Clear()
|
||||
{
|
||||
m_RecentFiles.RemoveAll();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns true if there's no files in the file list
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CRecentFileList::IsEmpty() const
|
||||
{
|
||||
return m_RecentFiles.Count() == 0;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets the file in a particular slot
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *CRecentFileList::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 *CRecentFileList::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 CRecentFileList::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 CRecentFileList::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 CRecentFileList::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 );
|
||||
}
|
||||
}
|
||||
286
tools/toolutils/savewindowpositions.cpp
Normal file
286
tools/toolutils/savewindowpositions.cpp
Normal file
@@ -0,0 +1,286 @@
|
||||
//========= Copyright 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;
|
||||
}
|
||||
}
|
||||
233
tools/toolutils/tool_main.cpp
Normal file
233
tools/toolutils/tool_main.cpp
Normal file
@@ -0,0 +1,233 @@
|
||||
//========= Copyright 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"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Singleton interfaces
|
||||
//-----------------------------------------------------------------------------
|
||||
IEngineTool *enginetools = NULL;
|
||||
IEngineVGui *enginevgui = NULL;
|
||||
IFileSystem *g_pFileSystem = NULL;
|
||||
IVDebugOverlay *debugoverlay = 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 );
|
||||
|
||||
if ( !enginevgui || !debugoverlay || !g_pCVar || !enginetools || !g_pFileSystem )
|
||||
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
tools/toolutils/tooleditmenubutton.cpp
Normal file
131
tools/toolutils/tooleditmenubutton.cpp
Normal file
@@ -0,0 +1,131 @@
|
||||
//========= Copyright 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
tools/toolutils/toolmenubar.cpp
Normal file
132
tools/toolutils/toolmenubar.cpp
Normal file
@@ -0,0 +1,132 @@
|
||||
//========= Copyright 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 );
|
||||
}
|
||||
54
tools/toolutils/toolutils.vpc
Normal file
54
tools/toolutils/toolutils.vpc
Normal file
@@ -0,0 +1,54 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// TOOLUTILS.VPC
|
||||
//
|
||||
// Project Script
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
$Macro SRCDIR "..\.."
|
||||
$Include "$SRCDIR\vpc_scripts\source_lib_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 "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\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"
|
||||
}
|
||||
}
|
||||
67
tools/toolutils/vgui_tools.cpp
Normal file
67
tools/toolutils/vgui_tools.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
//========= Copyright Valve Corporation, 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();
|
||||
}
|
||||
664
tools/vcdblock/dmevmfentity.cpp
Normal file
664
tools/vcdblock/dmevmfentity.cpp
Normal file
@@ -0,0 +1,664 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "DmeVMFEntity.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 "vcdblocktool.h"
|
||||
#include "tier1/KeyValues.h"
|
||||
|
||||
// for tracing
|
||||
#include "cmodel.h"
|
||||
#include "engine/ienginetrace.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( DmeVMFEntity, CDmeVMFEntity );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Used to store the next unique entity id;
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeVMFEntity::s_nNextEntityId;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeVMFEntity::OnConstruction()
|
||||
{
|
||||
m_ClassName.Init( this, "classname", 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" );
|
||||
m_bIsDeleted.Init( this, "deleted" );
|
||||
|
||||
if ( m_Name.Length() == 0 )
|
||||
{
|
||||
// Assign a unique ID to the name
|
||||
char pNameString[128];
|
||||
Q_snprintf( pNameString, sizeof(pNameString), "%d", GetNextEntityId() );
|
||||
m_Name = pNameString;
|
||||
}
|
||||
|
||||
// See if we need to bump the unique id up
|
||||
int nEntityId = GetEntityId();
|
||||
if ( s_nNextEntityId <= nEntityId )
|
||||
{
|
||||
s_nNextEntityId = nEntityId + 1;
|
||||
}
|
||||
|
||||
// Get called back when the name changes
|
||||
m_Name.GetAttribute()->AddFlag( FATTRIB_HAS_CALLBACK );
|
||||
|
||||
// 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_bIsDirty = false;
|
||||
m_bInfoTarget = false;
|
||||
m_hEngineEntity = HTOOLHANDLE_INVALID;
|
||||
|
||||
m_Wireframe.Init( "debug/debugwireframevertexcolor", "editor" );
|
||||
|
||||
// FIXME: Need to abstract out rendering into a separate class
|
||||
// based on information parsed from the FGD
|
||||
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( "__vcdblock_info_target", pVMTKeyValues );
|
||||
|
||||
pVMTKeyValues = new KeyValues( "UnlitGeneric" );
|
||||
pVMTKeyValues->SetInt( "$nocull", 1 );
|
||||
pVMTKeyValues->SetString( "$color", "{64 64 64}" );
|
||||
pVMTKeyValues->SetInt( "$vertexalpha", 1 );
|
||||
pVMTKeyValues->SetInt( "$no_fullbright", 1 );
|
||||
pVMTKeyValues->SetInt( "$additive", 1 );
|
||||
m_SelectedInfoTarget.Init( "__selected_vcdblock_info_target", pVMTKeyValues );
|
||||
}
|
||||
|
||||
void CDmeVMFEntity::OnDestruction()
|
||||
{
|
||||
// Unhook it from the engine
|
||||
AttachToEngineEntity( false );
|
||||
m_Wireframe.Shutdown();
|
||||
m_SelectedInfoTarget.Shutdown();
|
||||
m_InfoTargetSprite.Shutdown();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called whem attributes change
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeVMFEntity::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 );
|
||||
|
||||
// FIXME: Change the model based on the current class
|
||||
SetModelName( NULL );
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure we have unique ids for all entities
|
||||
if ( pAttribute == m_Name.GetAttribute() )
|
||||
{
|
||||
int nEntityId = GetEntityId();
|
||||
if ( s_nNextEntityId <= nEntityId )
|
||||
{
|
||||
s_nNextEntityId = nEntityId + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the entity ID
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeVMFEntity::GetEntityId() const
|
||||
{
|
||||
return atoi( GetName() );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the next available entity id
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeVMFEntity::GetNextEntityId()
|
||||
{
|
||||
return s_nNextEntityId;
|
||||
}
|
||||
|
||||
void CDmeVMFEntity::SetNextEntityId( int nEntityId )
|
||||
{
|
||||
s_nNextEntityId = nEntityId;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Mark the entity as being dirty
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeVMFEntity::MarkDirty( bool bDirty )
|
||||
{
|
||||
m_bIsDirty = bDirty;
|
||||
|
||||
// FIXME: this is doing two operations!!
|
||||
CopyToServer();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Is the renderable transparent?
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeVMFEntity::IsTransparent( void )
|
||||
{
|
||||
return m_bIsDirty || m_bInfoTarget || BaseClass::IsTransparent();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Entity Key iteration
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeVMFEntity::IsEntityKey( CDmAttribute *pEntityKey )
|
||||
{
|
||||
return pEntityKey->IsFlagSet( FATTRIB_USERDEFINED );
|
||||
}
|
||||
|
||||
CDmAttribute *CDmeVMFEntity::FirstEntityKey()
|
||||
{
|
||||
for ( CDmAttribute *pAttribute = FirstAttribute(); pAttribute; pAttribute = pAttribute->NextAttribute() )
|
||||
{
|
||||
if ( IsEntityKey( pAttribute ) )
|
||||
return pAttribute;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CDmAttribute *CDmeVMFEntity::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 CDmeVMFEntity::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 &CDmeVMFEntity::GetRenderOrigin( void )
|
||||
{
|
||||
return m_vecLocalOrigin;
|
||||
}
|
||||
|
||||
const QAngle &CDmeVMFEntity::GetRenderAngles( void )
|
||||
{
|
||||
return *(QAngle *)(&m_vecLocalAngles);
|
||||
}
|
||||
|
||||
void CDmeVMFEntity::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 CDmeVMFEntity::SetRenderOrigin( const Vector &vecOrigin )
|
||||
{
|
||||
m_vecLocalOrigin = vecOrigin;
|
||||
clienttools->MarkClientRenderableDirty( this );
|
||||
}
|
||||
|
||||
void CDmeVMFEntity::SetRenderAngles( const QAngle &angles )
|
||||
{
|
||||
m_vecLocalAngles.Set( Vector( angles.x, angles.y, angles.z ) ); // FIXME: angles is a vector due to the vmf "angles" having a problem parsing...
|
||||
clienttools->MarkClientRenderableDirty( this );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Draws the helper for the entity
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeVMFEntity::DrawSprite( IMaterial *pMaterial )
|
||||
{
|
||||
CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
|
||||
|
||||
float t = 0.5f * sin( Plat_FloatTime() * M_PI / 1.0f ) + 0.5f;
|
||||
|
||||
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.BoneWeight( 0, 1.0f );
|
||||
meshBuilder.BoneMatrix( 0, 0 );
|
||||
meshBuilder.AdvanceVertex();
|
||||
|
||||
meshBuilder.Position3f( SPHERE_RADIUS, -SPHERE_RADIUS, 0.0f );
|
||||
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
|
||||
meshBuilder.TexCoord2f( 0, 1.0f, 1.0f );
|
||||
meshBuilder.BoneWeight( 0, 1.0f );
|
||||
meshBuilder.BoneMatrix( 0, 0 );
|
||||
meshBuilder.AdvanceVertex();
|
||||
|
||||
meshBuilder.Position3f( SPHERE_RADIUS, SPHERE_RADIUS, 0.0f );
|
||||
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
|
||||
meshBuilder.TexCoord2f( 0, 1.0f, 0.0f );
|
||||
meshBuilder.BoneWeight( 0, 1.0f );
|
||||
meshBuilder.BoneMatrix( 0, 0 );
|
||||
meshBuilder.AdvanceVertex();
|
||||
|
||||
meshBuilder.Position3f( -SPHERE_RADIUS, SPHERE_RADIUS, 0.0f );
|
||||
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
|
||||
meshBuilder.TexCoord2f( 0, 0.0f, 0.0f );
|
||||
meshBuilder.BoneWeight( 0, 1.0f );
|
||||
meshBuilder.BoneMatrix( 0, 0 );
|
||||
meshBuilder.AdvanceVertex();
|
||||
|
||||
meshBuilder.FastIndex( 0 );
|
||||
meshBuilder.FastIndex( 1 );
|
||||
meshBuilder.FastIndex( 3 );
|
||||
meshBuilder.FastIndex( 2 );
|
||||
|
||||
meshBuilder.End();
|
||||
pMesh->Draw();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Draws the helper for the entity
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeVMFEntity::DrawDragHelpers( IMaterial *pMaterial )
|
||||
{
|
||||
CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
|
||||
|
||||
float t = 0.5f * sin( Plat_FloatTime() * M_PI / 1.0f ) + 0.5f;
|
||||
|
||||
VMatrix worldToCamera;
|
||||
// pRenderContext->GetMatrix( MATERIAL_VIEW, &worldToCamera );
|
||||
worldToCamera.Identity();
|
||||
worldToCamera.SetTranslation( m_vecLocalOrigin );
|
||||
|
||||
pRenderContext->MatrixMode( MATERIAL_MODEL );
|
||||
pRenderContext->PushMatrix();
|
||||
pRenderContext->LoadMatrix( worldToCamera );
|
||||
|
||||
pRenderContext->FogMode( MATERIAL_FOG_NONE );
|
||||
pRenderContext->SetNumBoneWeights( 0 );
|
||||
pRenderContext->CullMode( MATERIAL_CULLMODE_CW );
|
||||
|
||||
pRenderContext->Bind( pMaterial );
|
||||
IMesh* pMesh = pRenderContext->GetDynamicMesh();
|
||||
|
||||
CMeshBuilder meshBuilder;
|
||||
meshBuilder.Begin( pMesh, MATERIAL_LINES, 3 );
|
||||
|
||||
unsigned char nBaseR = 255;
|
||||
unsigned char nBaseG = 255;
|
||||
unsigned char nBaseB = 255;
|
||||
unsigned char nAlpha = m_bIsDirty ? (unsigned char)(255 * t) : 255;
|
||||
|
||||
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
|
||||
meshBuilder.Position3f( 0, 0, 0 );
|
||||
meshBuilder.AdvanceVertex();
|
||||
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
|
||||
meshBuilder.Position3f( SPHERE_RADIUS * 10, 0, 0 );
|
||||
meshBuilder.AdvanceVertex();
|
||||
|
||||
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
|
||||
meshBuilder.Position3f( 0, 0, 0 );
|
||||
meshBuilder.AdvanceVertex();
|
||||
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
|
||||
meshBuilder.Position3f( 0, SPHERE_RADIUS * 10, 0 );
|
||||
meshBuilder.AdvanceVertex();
|
||||
|
||||
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
|
||||
meshBuilder.Position3f( 0, 0, 0 );
|
||||
meshBuilder.AdvanceVertex();
|
||||
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
|
||||
meshBuilder.Position3f( 0, 0, SPHERE_RADIUS * 10 );
|
||||
meshBuilder.AdvanceVertex();
|
||||
|
||||
meshBuilder.End();
|
||||
pMesh->Draw();
|
||||
|
||||
pRenderContext->CullMode( MATERIAL_CULLMODE_CCW );
|
||||
pRenderContext->MatrixMode( MATERIAL_MODEL );
|
||||
pRenderContext->PopMatrix();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Draws the helper for the entity
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeVMFEntity::DrawFloorTarget( IMaterial *pMaterial )
|
||||
{
|
||||
CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
|
||||
|
||||
float t = 0.5f * sin( Plat_FloatTime() * M_PI / 1.0f ) + 0.5f;
|
||||
|
||||
// test movement
|
||||
Ray_t ray;
|
||||
CTraceFilterWorldAndPropsOnly traceFilter;
|
||||
CBaseTrace tr;
|
||||
ray.Init( m_vecLocalOrigin.Get()+ Vector( 0, 0, 10 ), m_vecLocalOrigin.Get() + Vector( 0,0, -128 ), Vector( -13, -13, 0 ), Vector( 13, 13, 10 ) );
|
||||
enginetools->TraceRayServer( ray, MASK_OPAQUE, &traceFilter, &tr );
|
||||
|
||||
|
||||
VMatrix worldToCamera;
|
||||
// pRenderContext->GetMatrix( MATERIAL_VIEW, &worldToCamera );
|
||||
worldToCamera.Identity();
|
||||
worldToCamera.SetTranslation( tr.endpos );
|
||||
|
||||
pRenderContext->MatrixMode( MATERIAL_MODEL );
|
||||
pRenderContext->PushMatrix();
|
||||
pRenderContext->LoadMatrix( worldToCamera );
|
||||
|
||||
pRenderContext->FogMode( MATERIAL_FOG_NONE );
|
||||
pRenderContext->SetNumBoneWeights( 0 );
|
||||
pRenderContext->CullMode( MATERIAL_CULLMODE_CW );
|
||||
|
||||
pRenderContext->Bind( pMaterial );
|
||||
IMesh* pMesh = pRenderContext->GetDynamicMesh();
|
||||
|
||||
CMeshBuilder meshBuilder;
|
||||
meshBuilder.Begin( pMesh, MATERIAL_LINES, 3 );
|
||||
|
||||
unsigned char nBaseR = 255;
|
||||
unsigned char nBaseG = 255;
|
||||
unsigned char nBaseB = 0;
|
||||
unsigned char nAlpha = m_bIsDirty ? (unsigned char)(255 * t) : 255;
|
||||
|
||||
float block[4][2][3] = {
|
||||
{ { -13, -13, 0 }, { -13, -13, 10 } },
|
||||
{ { 13, -13, 0 }, { 13, -13, 10 } },
|
||||
{ { 13, 13, 0 }, { 13, 13, 10 } },
|
||||
{ { -13, 13, 0 }, { -13, 13, 10 } } };
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
int j = (i + 1) % 4;
|
||||
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
|
||||
meshBuilder.Position3f( block[i][0][0], block[i][0][1], block[i][0][2] );
|
||||
meshBuilder.AdvanceVertex();
|
||||
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
|
||||
meshBuilder.Position3f( block[i][1][0], block[i][1][1], block[i][1][2] );
|
||||
meshBuilder.AdvanceVertex();
|
||||
|
||||
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
|
||||
meshBuilder.Position3f( block[i][0][0], block[i][0][1], block[i][0][2] );
|
||||
meshBuilder.AdvanceVertex();
|
||||
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
|
||||
meshBuilder.Position3f( block[j][0][0], block[j][0][1], block[j][0][2] );
|
||||
meshBuilder.AdvanceVertex();
|
||||
|
||||
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
|
||||
meshBuilder.Position3f( block[i][1][0], block[i][1][1], block[i][1][2] );
|
||||
meshBuilder.AdvanceVertex();
|
||||
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
|
||||
meshBuilder.Position3f( block[j][1][0], block[j][1][1], block[j][1][2] );
|
||||
meshBuilder.AdvanceVertex();
|
||||
}
|
||||
|
||||
// positive X
|
||||
meshBuilder.Color4ub( 255, 0, 0, nAlpha );
|
||||
meshBuilder.Position3f( 0, 0, 10 );
|
||||
meshBuilder.AdvanceVertex();
|
||||
meshBuilder.Color4ub( 255, 0, 0, nAlpha );
|
||||
meshBuilder.Position3f( 10, 0, 10 );
|
||||
meshBuilder.AdvanceVertex();
|
||||
|
||||
// positive Y
|
||||
meshBuilder.Color4ub( 0, 255, 0, nAlpha );
|
||||
meshBuilder.Position3f( 0, 0, 10 );
|
||||
meshBuilder.AdvanceVertex();
|
||||
meshBuilder.Color4ub( 0, 255, 0, nAlpha );
|
||||
meshBuilder.Position3f( 0, 10, 10 );
|
||||
meshBuilder.AdvanceVertex();
|
||||
|
||||
// just Z
|
||||
meshBuilder.Color4ub( 255, 255, 255, nAlpha );
|
||||
meshBuilder.Position3f( 0, 0, 10 );
|
||||
meshBuilder.AdvanceVertex();
|
||||
meshBuilder.Color4ub( 255, 255, 255, nAlpha );
|
||||
meshBuilder.Position3f( 0, 0, 0 );
|
||||
meshBuilder.AdvanceVertex();
|
||||
|
||||
meshBuilder.End();
|
||||
pMesh->Draw();
|
||||
|
||||
pRenderContext->CullMode( MATERIAL_CULLMODE_CCW );
|
||||
pRenderContext->MatrixMode( MATERIAL_MODEL );
|
||||
pRenderContext->PopMatrix();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Draws the helper for the entity
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeVMFEntity::DrawModel( int flags )
|
||||
{
|
||||
CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
|
||||
|
||||
bool bSelected = ( g_pVcdBlockTool->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 );
|
||||
}
|
||||
|
||||
Assert( IsDrawingInEngine() );
|
||||
|
||||
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 );
|
||||
|
||||
DrawFloorTarget( m_Wireframe );
|
||||
|
||||
if (g_pVcdBlockTool->IsInNodeDrag())
|
||||
{
|
||||
DrawDragHelpers( m_Wireframe );
|
||||
}
|
||||
// DrawLine( Vector( 0, 0, 0 ), Vector( 10, 0, 0 ), 0, 255, 255, 255 );
|
||||
}
|
||||
|
||||
pRenderContext->CullMode( MATERIAL_CULLMODE_CCW );
|
||||
pRenderContext->MatrixMode( MATERIAL_MODEL );
|
||||
pRenderContext->PopMatrix();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
bool CDmeVMFEntity::CopyFromServer( CBaseEntity *pServerEnt )
|
||||
{
|
||||
CopyFromServer( pServerEnt, "targetname" );
|
||||
CopyFromServer( pServerEnt, "classname" );
|
||||
CopyFromServer( pServerEnt, "origin" );
|
||||
CopyFromServer( pServerEnt, "angles" );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CDmeVMFEntity::CopyFromServer( CBaseEntity *pServerEnt, const char *szField )
|
||||
{
|
||||
return CopyFromServer( pServerEnt, szField, szField );
|
||||
}
|
||||
|
||||
bool CDmeVMFEntity::CopyFromServer( CBaseEntity *pServerEnt, const char *szSrcField, const char *szDstField )
|
||||
{
|
||||
char text[256];
|
||||
if ( servertools->GetKeyValue( pServerEnt, szSrcField, text, sizeof( text ) ) )
|
||||
{
|
||||
SetValueFromString( szDstField, text );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CDmeVMFEntity::CopyToServer( void )
|
||||
{
|
||||
if (GetEntityId() != 0)
|
||||
{
|
||||
CBaseEntity *pServerEntity = servertools->FindEntityByHammerID( GetEntityId() );
|
||||
if (pServerEntity != NULL)
|
||||
{
|
||||
servertools->SetKeyValue( pServerEntity, "origin", m_vecLocalOrigin.Get() );
|
||||
// FIXME: isn't there a string to vector conversion?
|
||||
Vector tmp( m_vecLocalAngles.Get().x, m_vecLocalAngles.Get().y, m_vecLocalAngles.Get().z );
|
||||
servertools->SetKeyValue( pServerEntity, "angles", tmp );
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// FIXME: does one need to be spawned?
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CDmeVMFEntity::IsSameOnServer( CBaseEntity *pServerEntity )
|
||||
{
|
||||
char text[256];
|
||||
|
||||
if (!pServerEntity)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// FIXME: check targetname? Can it be edited?
|
||||
Vector mapOrigin;
|
||||
servertools->GetKeyValue( pServerEntity, "origin", text, sizeof( text ) );
|
||||
sscanf( text, "%f %f %f", &mapOrigin.x, &mapOrigin.y, &mapOrigin.z );
|
||||
Vector mapAngles;
|
||||
servertools->GetKeyValue( pServerEntity, "angles", text, sizeof( text ) );
|
||||
sscanf( text, "%f %f %f", &mapAngles.x, &mapAngles.y, &mapAngles.z );
|
||||
|
||||
return ( mapOrigin == m_vecLocalOrigin.Get() && mapAngles == m_vecLocalAngles.Get() );
|
||||
}
|
||||
|
||||
bool CDmeVMFEntity::CreateOnServer( void )
|
||||
{
|
||||
CBaseEntity *pServerEntity = servertools->CreateEntityByName( m_ClassName.Get() );
|
||||
|
||||
if (pServerEntity)
|
||||
{
|
||||
// test movement
|
||||
Ray_t ray;
|
||||
CTraceFilterWorldAndPropsOnly traceFilter;
|
||||
CBaseTrace tr;
|
||||
ray.Init( m_vecLocalOrigin.Get()+ Vector( 0, 0, 10 ), m_vecLocalOrigin.Get() + Vector( 0,0, -1000 ) );
|
||||
enginetools->TraceRayServer( ray, MASK_OPAQUE, &traceFilter, &tr );
|
||||
m_vecLocalOrigin.Set( tr.endpos );
|
||||
|
||||
servertools->SetKeyValue( pServerEntity, "hammerid", GetEntityId() );
|
||||
servertools->SetKeyValue( pServerEntity, "targetname", m_TargetName.Get() );
|
||||
servertools->SetKeyValue( pServerEntity, "origin", m_vecLocalOrigin.Get() );
|
||||
servertools->SetKeyValue( pServerEntity, "angles", m_vecLocalAngles.Get() );
|
||||
servertools->DispatchSpawn( pServerEntity );
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
131
tools/vcdblock/dmevmfentity.h
Normal file
131
tools/vcdblock/dmevmfentity.h
Normal file
@@ -0,0 +1,131 @@
|
||||
//========= Copyright 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 CDmeVMFEntity : public CDmeMdlRenderable<CDmElement>
|
||||
{
|
||||
DEFINE_ELEMENT( CDmeVMFEntity, 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 );
|
||||
virtual bool IsTransparent( void );
|
||||
virtual void GetRenderBounds( Vector& mins, Vector& maxs );
|
||||
|
||||
public:
|
||||
int GetEntityId() const;
|
||||
|
||||
// Returns the next available entity id
|
||||
static int GetNextEntityId();
|
||||
static void SetNextEntityId( int nEntityId );
|
||||
|
||||
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 );
|
||||
bool IsDirty( void ) { return m_bIsDirty; };
|
||||
|
||||
void MarkDeleted( bool bDeleted = true );
|
||||
bool IsDeleted( void ) { return m_bIsDeleted; };
|
||||
|
||||
bool CopyFromServer( CBaseEntity *pServerEnt );
|
||||
bool CopyFromServer( CBaseEntity *pServerEnt, const char *szField );
|
||||
bool CopyFromServer( CBaseEntity *pServerEnt, const char *szSrcField, const char *szDstField );
|
||||
bool CopyToServer( void );
|
||||
|
||||
bool IsSameOnServer( CBaseEntity *pServerEntity );
|
||||
bool CreateOnServer( void );
|
||||
|
||||
private:
|
||||
bool IsEntityKey( CDmAttribute *pEntityKey );
|
||||
|
||||
// Draws the helper for the entity
|
||||
void DrawSprite( IMaterial *pMaterial );
|
||||
void DrawDragHelpers( IMaterial *pMaterial );
|
||||
void DrawFloorTarget( IMaterial *pMaterial );
|
||||
|
||||
CDmaVar<Vector> m_vecLocalOrigin;
|
||||
// CDmAttributeVar<QAngle> m_vecLocalAngles;
|
||||
CDmaVar<Vector> m_vecLocalAngles; // something funky with the vmf importer, it asserts when it's a QAngle
|
||||
|
||||
CDmaString m_ClassName;
|
||||
CDmaString m_TargetName;
|
||||
CDmaVar<bool> m_bIsPlaceholder;
|
||||
|
||||
// The entity it's connected to in the engine
|
||||
HTOOLHANDLE m_hEngineEntity;
|
||||
|
||||
CMaterialReference m_Wireframe;
|
||||
|
||||
CMaterialReference m_SelectedInfoTarget;
|
||||
CMaterialReference m_InfoTargetSprite;
|
||||
|
||||
// pretty sure this entity is edited
|
||||
bool m_bIsDirty;
|
||||
|
||||
// entity needs to be deleted
|
||||
CDmaVar<bool> m_bIsDeleted;
|
||||
|
||||
// FIXME: This is a hack for info targets
|
||||
bool m_bInfoTarget;
|
||||
|
||||
// Used to store the next unique entity id;
|
||||
static int s_nNextEntityId;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Inline methods
|
||||
//-----------------------------------------------------------------------------
|
||||
inline const char *CDmeVMFEntity::GetClassName() const
|
||||
{
|
||||
return m_ClassName;
|
||||
}
|
||||
|
||||
inline const char *CDmeVMFEntity::GetTargetName() const
|
||||
{
|
||||
return m_TargetName;
|
||||
}
|
||||
|
||||
inline bool CDmeVMFEntity::IsPlaceholder() const
|
||||
{
|
||||
return m_bIsPlaceholder;
|
||||
}
|
||||
|
||||
|
||||
#endif // DMEVMFENTITY_H
|
||||
297
tools/vcdblock/infotargetbrowserpanel.cpp
Normal file
297
tools/vcdblock/infotargetbrowserpanel.cpp
Normal file
@@ -0,0 +1,297 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Singleton dialog that generates and presents the entity report.
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#include "InfoTargetBrowserPanel.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 "vcdblockdoc.h"
|
||||
#include "vcdblocktool.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
|
||||
//-----------------------------------------------------------------------------
|
||||
CInfoTargetBrowserPanel::CInfoTargetBrowserPanel( CVcdBlockDoc *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 info_targets" );
|
||||
// m_pEntities->SetDragEnabled( true );
|
||||
m_pEntities->AddActionSignalTarget( this );
|
||||
m_pEntities->SetSortFunc( 0, TargetNameSortFunc );
|
||||
m_pEntities->SetSortFunc( 1, ClassNameSortFunc );
|
||||
m_pEntities->SetSortColumn( 0 );
|
||||
|
||||
LoadControlSettingsAndUserConfig( "resource/infotargetbrowserpanel.res" );
|
||||
|
||||
UpdateEntityList();
|
||||
}
|
||||
|
||||
CInfoTargetBrowserPanel::~CInfoTargetBrowserPanel()
|
||||
{
|
||||
SaveUserConfig();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Shows the most recent selected object in properties window
|
||||
//-----------------------------------------------------------------------------
|
||||
void CInfoTargetBrowserPanel::OnProperties(void)
|
||||
{
|
||||
int iSel = m_pEntities->GetSelectedItem( 0 );
|
||||
KeyValues *kv = m_pEntities->GetItem( iSel );
|
||||
CDmeVMFEntity *pEntity = CastElement< CDmeVMFEntity >( (CDmElement *)kv->GetPtr( "entity" ) );
|
||||
g_pVcdBlockTool->ShowEntityInEntityProperties( pEntity );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Deletes the marked objects.
|
||||
//-----------------------------------------------------------------------------
|
||||
void CInfoTargetBrowserPanel::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 );
|
||||
CDmeVMFEntity *pEntity = (CDmeVMFEntity *)kv->GetPtr( "entity" );
|
||||
if ( pEntity )
|
||||
{
|
||||
m_pDoc->DeleteInfoTarget( pEntity );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update the list box selection.
|
||||
if (iSel >= m_pEntities->GetItemCount())
|
||||
{
|
||||
iSel = m_pEntities->GetItemCount() - 1;
|
||||
}
|
||||
m_pEntities->SetSingleSelectedItem( iSel );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CInfoTargetBrowserPanel::OnKeyCodeTyped( vgui::KeyCode code )
|
||||
{
|
||||
if ( code == KEY_DELETE )
|
||||
{
|
||||
OnDeleteEntities();
|
||||
}
|
||||
else
|
||||
{
|
||||
BaseClass::OnKeyCodeTyped( code );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CInfoTargetBrowserPanel::OnItemSelected( void )
|
||||
{
|
||||
OnProperties();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Select a particular node
|
||||
//-----------------------------------------------------------------------------
|
||||
void CInfoTargetBrowserPanel::SelectNode( CDmeVMFEntity *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 CInfoTargetBrowserPanel::OnCommand( const char *pCommand )
|
||||
{
|
||||
if ( !Q_stricmp( pCommand, "delete" ) )
|
||||
{
|
||||
// Confirm we want to do it
|
||||
MessageBox *pConfirm = new MessageBox( "#VcdBlockDeleteObjects", "#VcdBlockDeleteObjectsMsg", g_pVcdBlockTool->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_pVcdBlockTool->Save();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !Q_stricmp( pCommand, "RestartMap" ) )
|
||||
{
|
||||
g_pVcdBlockTool->RestartMap();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !Q_stricmp( pCommand, "DropInfoTargets" ) )
|
||||
{
|
||||
g_pVcdBlockTool->EnterTargetDropMode();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !Q_stricmp( pCommand, "quicksave" ) )
|
||||
{
|
||||
g_pVcdBlockTool->QuickSave();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !Q_stricmp( pCommand, "quickload" ) )
|
||||
{
|
||||
g_pVcdBlockTool->QuickLoad();
|
||||
return;
|
||||
}
|
||||
|
||||
BaseClass::OnCommand( pCommand );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CInfoTargetBrowserPanel::UpdateEntityList(void)
|
||||
{
|
||||
m_pEntities->RemoveAll();
|
||||
|
||||
const CDmrElementArray<CDmElement> entityList( m_pDoc->GetEntityList() );
|
||||
if ( !entityList.IsValid() )
|
||||
return;
|
||||
|
||||
int nCount = entityList.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
CDmElement *pEntity = entityList[i];
|
||||
|
||||
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 );
|
||||
|
||||
int nItemID = m_pEntities->AddItem( kv, 0, false, false );
|
||||
|
||||
// Hide everything that isn't an info_target
|
||||
m_pEntities->SetItemVisible( nItemID, !Q_stricmp( pClassName, "info_target" ) );
|
||||
}
|
||||
m_pEntities->SortList();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CInfoTargetBrowserPanel::Refresh(void)
|
||||
{
|
||||
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" );
|
||||
|
||||
const char *pTargetname = pEntity->GetValueString( "targetname" );
|
||||
if ( !pTargetname || !pTargetname[0] )
|
||||
{
|
||||
pTargetname = "<no targetname>";
|
||||
}
|
||||
kv->SetString( "targetname", pTargetname );
|
||||
}
|
||||
}
|
||||
|
||||
68
tools/vcdblock/infotargetbrowserpanel.h
Normal file
68
tools/vcdblock/infotargetbrowserpanel.h
Normal file
@@ -0,0 +1,68 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef INFOTARGETBROWSERPANEL_H
|
||||
#define INFOTARGETBROWSERPANEL_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "vgui_controls/editablepanel.h"
|
||||
#include "tier1/utlstring.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class CVcdBlockDoc;
|
||||
class CDmeVMFEntity;
|
||||
namespace vgui
|
||||
{
|
||||
class ComboBox;
|
||||
class Button;
|
||||
class TextEntry;
|
||||
class ListPanel;
|
||||
class CheckButton;
|
||||
class RadioButton;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Panel that shows all entities in the level
|
||||
//-----------------------------------------------------------------------------
|
||||
class CInfoTargetBrowserPanel : public vgui::EditablePanel
|
||||
{
|
||||
DECLARE_CLASS_SIMPLE( CInfoTargetBrowserPanel, vgui::EditablePanel );
|
||||
|
||||
public:
|
||||
CInfoTargetBrowserPanel( CVcdBlockDoc *pDoc, vgui::Panel* pParent, const char *pName ); // standard constructor
|
||||
virtual ~CInfoTargetBrowserPanel();
|
||||
|
||||
// Inherited from Panel
|
||||
virtual void OnCommand( const char *pCommand );
|
||||
virtual void OnKeyCodeTyped( vgui::KeyCode code );
|
||||
|
||||
// Methods related to updating the listpanel
|
||||
void UpdateEntityList();
|
||||
void Refresh();
|
||||
|
||||
// Select a particular node
|
||||
void SelectNode( CDmeVMFEntity *pNode );
|
||||
|
||||
private:
|
||||
// Messages handled
|
||||
MESSAGE_FUNC( OnDeleteEntities, "DeleteEntities" );
|
||||
MESSAGE_FUNC( OnItemSelected, "ItemSelected" );
|
||||
|
||||
// Shows the most recent selected object in properties window
|
||||
void OnProperties();
|
||||
|
||||
CVcdBlockDoc *m_pDoc;
|
||||
vgui::ListPanel *m_pEntities;
|
||||
};
|
||||
|
||||
|
||||
#endif // INFOTARGETBROWSERPANEL_H
|
||||
225
tools/vcdblock/infotargetpropertiespanel.cpp
Normal file
225
tools/vcdblock/infotargetpropertiespanel.cpp
Normal file
@@ -0,0 +1,225 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Singleton dialog that generates and presents the entity report.
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#include "InfoTargetPropertiesPanel.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 "vcdblockdoc.h"
|
||||
#include "vcdblocktool.h"
|
||||
#include "datamodel/dmelement.h"
|
||||
#include "dmevmfentity.h"
|
||||
#include "dme_controls/soundpicker.h"
|
||||
#include "dme_controls/soundrecordpanel.h"
|
||||
#include "matsys_controls/picker.h"
|
||||
#include "vgui_controls/fileopendialog.h"
|
||||
#include "filesystem.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
class CScrollableEditablePanel : public vgui::EditablePanel
|
||||
{
|
||||
DECLARE_CLASS_SIMPLE( CScrollableEditablePanel, vgui::EditablePanel );
|
||||
|
||||
public:
|
||||
CScrollableEditablePanel( vgui::Panel *pParent, vgui::EditablePanel *pChild, const char *pName );
|
||||
virtual ~CScrollableEditablePanel() {}
|
||||
virtual void PerformLayout();
|
||||
|
||||
MESSAGE_FUNC( OnScrollBarSliderMoved, "ScrollBarSliderMoved" );
|
||||
|
||||
private:
|
||||
vgui::ScrollBar *m_pScrollBar;
|
||||
vgui::EditablePanel *m_pChild;
|
||||
};
|
||||
|
||||
|
||||
CScrollableEditablePanel::CScrollableEditablePanel( vgui::Panel *pParent, vgui::EditablePanel *pChild, const char *pName ) :
|
||||
BaseClass( pParent, pName )
|
||||
{
|
||||
m_pChild = pChild;
|
||||
m_pChild->SetParent( this );
|
||||
|
||||
m_pScrollBar = new vgui::ScrollBar( this, "VerticalScrollBar", true );
|
||||
m_pScrollBar->SetWide( 16 );
|
||||
m_pScrollBar->SetAutoResize( PIN_TOPRIGHT, AUTORESIZE_DOWN, 0, 0, -16, 0 );
|
||||
m_pScrollBar->AddActionSignalTarget( this );
|
||||
}
|
||||
|
||||
void CScrollableEditablePanel::PerformLayout()
|
||||
{
|
||||
BaseClass::PerformLayout();
|
||||
|
||||
m_pChild->SetWide( GetWide() - 16 );
|
||||
m_pScrollBar->SetRange( 0, m_pChild->GetTall() );
|
||||
m_pScrollBar->SetRangeWindow( GetTall() );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called when the scroll bar moves
|
||||
//-----------------------------------------------------------------------------
|
||||
void CScrollableEditablePanel::OnScrollBarSliderMoved()
|
||||
{
|
||||
InvalidateLayout();
|
||||
|
||||
int nScrollAmount = m_pScrollBar->GetValue();
|
||||
m_pChild->SetPos( 0, -nScrollAmount );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CInfoTargetPropertiesPanel::CInfoTargetPropertiesPanel( CVcdBlockDoc *pDoc, vgui::Panel* pParent )
|
||||
: BaseClass( pParent, "InfoTargetPropertiesPanel" ), m_pDoc( pDoc )
|
||||
{
|
||||
SetPaintBackgroundEnabled( true );
|
||||
SetKeyBoardInputEnabled( true );
|
||||
|
||||
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/infotargetpropertiessubpanel_target.res" );
|
||||
|
||||
m_pInfoTargetScroll = new CScrollableEditablePanel( this, m_pInfoTarget, "InfoTargetScroll" );
|
||||
|
||||
LoadControlSettings( "resource/infotargetpropertiespanel.res" );
|
||||
|
||||
m_pInfoTargetScroll->SetVisible( false );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Text to attribute...
|
||||
//-----------------------------------------------------------------------------
|
||||
void CInfoTargetPropertiesPanel::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 CInfoTargetPropertiesPanel::TextEntriesToVector( vgui::TextEntry *pEntry[3], const char *pAttributeName )
|
||||
{
|
||||
Vector vec;
|
||||
for ( int i = 0; i < 3; ++i )
|
||||
{
|
||||
int nLen = pEntry[i]->GetTextLength();
|
||||
char *pBuf = (char*)_alloca( nLen+1 );
|
||||
pEntry[i]->GetText( pBuf, nLen+1 );
|
||||
vec[i] = atof( pBuf );
|
||||
}
|
||||
m_hEntity->SetValue( pAttributeName, vec );
|
||||
clienttools->MarkClientRenderableDirty( m_hEntity );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Updates entity state when text fields change
|
||||
//-----------------------------------------------------------------------------
|
||||
void CInfoTargetPropertiesPanel::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();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Populates the info_target fields
|
||||
//-----------------------------------------------------------------------------
|
||||
void CInfoTargetPropertiesPanel::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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets the object to look at
|
||||
//-----------------------------------------------------------------------------
|
||||
void CInfoTargetPropertiesPanel::SetObject( CDmeVMFEntity *pEntity )
|
||||
{
|
||||
m_hEntity = pEntity;
|
||||
m_pInfoTargetScroll->SetVisible( false );
|
||||
|
||||
if ( pEntity )
|
||||
{
|
||||
if ( !Q_stricmp( pEntity->GetClassName(), "info_target" ) )
|
||||
{
|
||||
PopulateInfoTargetFields();
|
||||
m_pInfoTargetScroll->SetVisible( true );
|
||||
m_pTargetName->RequestFocus();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called when text is changed
|
||||
//-----------------------------------------------------------------------------
|
||||
void CInfoTargetPropertiesPanel::OnTextChanged( KeyValues *pParams )
|
||||
{
|
||||
vgui::Panel *pPanel = (vgui::Panel*)pParams->GetPtr( "panel" );
|
||||
if ( pPanel->GetParent() == m_pInfoTarget )
|
||||
{
|
||||
UpdateInfoTarget();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
76
tools/vcdblock/infotargetpropertiespanel.h
Normal file
76
tools/vcdblock/infotargetpropertiespanel.h
Normal file
@@ -0,0 +1,76 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef INFOTARGETPROPERTIESPANEL_H
|
||||
#define INFOTARGETPROPERTIESPANEL_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "vgui_controls/editablepanel.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "datamodel/dmehandle.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class CVcdBlockDoc;
|
||||
class CDmeVMFEntity;
|
||||
class CScrollableEditablePanel;
|
||||
|
||||
namespace vgui
|
||||
{
|
||||
class ComboBox;
|
||||
class Button;
|
||||
class TextEntry;
|
||||
class ListPanel;
|
||||
class CheckButton;
|
||||
class RadioButton;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Panel that shows all entities in the level
|
||||
//-----------------------------------------------------------------------------
|
||||
class CInfoTargetPropertiesPanel : public vgui::EditablePanel
|
||||
{
|
||||
DECLARE_CLASS_SIMPLE( CInfoTargetPropertiesPanel, vgui::EditablePanel );
|
||||
|
||||
public:
|
||||
CInfoTargetPropertiesPanel( CVcdBlockDoc *pDoc, vgui::Panel* pParent ); // standard constructor
|
||||
|
||||
// Sets the object to look at
|
||||
void SetObject( CDmeVMFEntity *pEntity );
|
||||
|
||||
private:
|
||||
// Populates the info_target fields
|
||||
void PopulateInfoTargetFields();
|
||||
|
||||
// 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 UpdateInfoTarget();
|
||||
|
||||
// Messages handled
|
||||
MESSAGE_FUNC_PARAMS( OnTextChanged, "TextChanged", kv );
|
||||
|
||||
CVcdBlockDoc *m_pDoc;
|
||||
|
||||
vgui::EditablePanel *m_pInfoTargetScroll;
|
||||
vgui::EditablePanel *m_pInfoTarget;
|
||||
|
||||
vgui::TextEntry *m_pTargetName;
|
||||
vgui::TextEntry *m_pTargetPosition[3];
|
||||
vgui::TextEntry *m_pTargetOrientation[3];
|
||||
|
||||
CDmeHandle< CDmeVMFEntity > m_hEntity;
|
||||
};
|
||||
|
||||
|
||||
#endif // INFOTARGETPROPERTIESPANEL_H
|
||||
64
tools/vcdblock/vcdblock.vpc
Normal file
64
tools/vcdblock/vcdblock.vpc
Normal file
@@ -0,0 +1,64 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// VCDBLOCK.VPC
|
||||
//
|
||||
// Project Script
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
$Macro SRCDIR "..\.."
|
||||
$Macro OUTBINDIR "$SRCDIR\..\game\bin\tools"
|
||||
|
||||
$Include "$SRCDIR\vpc_scripts\source_dll_base.vpc"
|
||||
|
||||
$Configuration
|
||||
{
|
||||
$Compiler
|
||||
{
|
||||
$AdditionalIncludeDirectories "$BASE,.\,..\common;$SRCDIR\game\shared"
|
||||
$PreprocessorDefinitions "$BASE;VCDBLOCK_EXPORTS"
|
||||
}
|
||||
|
||||
$Linker
|
||||
{
|
||||
$AdditionalDependencies "$BASE Psapi.lib"
|
||||
}
|
||||
}
|
||||
|
||||
$Project "Vcdblock"
|
||||
{
|
||||
$Folder "Source Files"
|
||||
{
|
||||
$File "dmevmfentity.cpp"
|
||||
$File "infotargetbrowserpanel.cpp"
|
||||
$File "infotargetpropertiespanel.cpp"
|
||||
$File "$SRCDIR\public\interpolatortypes.cpp"
|
||||
$File "$SRCDIR\public\registry.cpp"
|
||||
$File "vcdblockdoc.cpp"
|
||||
$File "vcdblocktool.cpp"
|
||||
$File "$SRCDIR\public\vgui_controls\vgui_controls.cpp"
|
||||
}
|
||||
|
||||
$Folder "Header Files"
|
||||
{
|
||||
$File "dmevmfentity.h"
|
||||
$File "infotargetbrowserpanel.h"
|
||||
$File "infotargetpropertiespanel.h"
|
||||
$File "$SRCDIR\public\mathlib\mathlib.h"
|
||||
$File "vcdblockdoc.h"
|
||||
$File "vcdblocktool.h"
|
||||
}
|
||||
|
||||
$Folder "Link Libraries"
|
||||
{
|
||||
$Lib datamodel
|
||||
$Lib dme_controls
|
||||
$Lib dmserializers
|
||||
$Lib mathlib
|
||||
$Lib matsys_controls
|
||||
$Lib movieobjects
|
||||
$Lib sfmobjects
|
||||
$Lib tier2
|
||||
$Lib tier3
|
||||
$Lib toolutils
|
||||
$Lib vgui_controls
|
||||
}
|
||||
}
|
||||
630
tools/vcdblock/vcdblockdoc.cpp
Normal file
630
tools/vcdblock/vcdblockdoc.cpp
Normal file
@@ -0,0 +1,630 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#include "vcdblockdoc.h"
|
||||
#include "tier1/KeyValues.h"
|
||||
#include "tier1/utlbuffer.h"
|
||||
#include "toolutils/enginetools_int.h"
|
||||
#include "filesystem.h"
|
||||
#include "vcdblocktool.h"
|
||||
#include "toolframework/ienginetool.h"
|
||||
#include "dmevmfentity.h"
|
||||
#include "datamodel/idatamodel.h"
|
||||
#include "toolutils/attributeelementchoicelist.h"
|
||||
#include "infotargetbrowserpanel.h"
|
||||
#include "vgui_controls/messagebox.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CVcdBlockDoc::CVcdBlockDoc( IVcdBlockDocCallback *pCallback ) : m_pCallback( pCallback )
|
||||
{
|
||||
m_hVMFRoot = NULL;
|
||||
m_hEditRoot = NULL;
|
||||
m_pBSPFileName[0] = 0;
|
||||
m_pVMFFileName[0] = 0;
|
||||
m_pEditFileName[0] = 0;
|
||||
m_bDirty = false;
|
||||
g_pDataModel->InstallNotificationCallback( this );
|
||||
}
|
||||
|
||||
CVcdBlockDoc::~CVcdBlockDoc()
|
||||
{
|
||||
g_pDataModel->RemoveNotificationCallback( this );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Inherited from INotifyUI
|
||||
//-----------------------------------------------------------------------------
|
||||
void CVcdBlockDoc::NotifyDataChanged( const char *pReason, int nNotifySource, int nNotifyFlags )
|
||||
{
|
||||
OnDataChanged( pReason, nNotifySource, nNotifyFlags );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets the file name
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *CVcdBlockDoc::GetBSPFileName()
|
||||
{
|
||||
return m_pBSPFileName;
|
||||
}
|
||||
|
||||
const char *CVcdBlockDoc::GetVMFFileName()
|
||||
{
|
||||
return m_pVMFFileName;
|
||||
}
|
||||
|
||||
void CVcdBlockDoc::SetVMFFileName( const char *pFileName )
|
||||
{
|
||||
Q_strncpy( m_pVMFFileName, pFileName, sizeof( m_pVMFFileName ) );
|
||||
Q_FixSlashes( m_pVMFFileName );
|
||||
SetDirty( true );
|
||||
}
|
||||
|
||||
const char *CVcdBlockDoc::GetEditFileName()
|
||||
{
|
||||
return m_pEditFileName;
|
||||
}
|
||||
|
||||
void CVcdBlockDoc::SetEditFileName( const char *pFileName )
|
||||
{
|
||||
Q_strncpy( m_pEditFileName, pFileName, sizeof( m_pEditFileName ) );
|
||||
Q_FixSlashes( m_pEditFileName );
|
||||
SetDirty( true );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Dirty bits
|
||||
//-----------------------------------------------------------------------------
|
||||
void CVcdBlockDoc::SetDirty( bool bDirty )
|
||||
{
|
||||
m_bDirty = bDirty;
|
||||
}
|
||||
|
||||
bool CVcdBlockDoc::IsDirty() const
|
||||
{
|
||||
return m_bDirty;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Saves/loads from file
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CVcdBlockDoc::LoadFromFile( const char *pFileName )
|
||||
{
|
||||
Assert( !m_hVMFRoot.Get() );
|
||||
Assert( !m_hEditRoot.Get() );
|
||||
|
||||
CAppDisableUndoScopeGuard guard( "CVcdBlockDoc::LoadFromFile", NOTIFY_CHANGE_OTHER );
|
||||
SetDirty( false );
|
||||
|
||||
if ( !pFileName[0] )
|
||||
return false;
|
||||
|
||||
// Construct VMF file name from the BSP
|
||||
const char *pGame = Q_stristr( pFileName, "\\game\\" );
|
||||
if ( !pGame )
|
||||
{
|
||||
pGame = Q_stristr( pFileName, "\\content\\" );
|
||||
if ( !pGame )
|
||||
return false;
|
||||
}
|
||||
|
||||
// Compute the map name
|
||||
const char *pMaps = Q_stristr( pFileName, "\\maps\\" );
|
||||
if ( !pMaps )
|
||||
return false;
|
||||
|
||||
// Build map name
|
||||
char mapname[ 256 ];
|
||||
Q_StripExtension( pFileName, mapname, sizeof(mapname) );
|
||||
char *pszFileName = (char*)Q_UnqualifiedFileName(mapname);
|
||||
|
||||
int nLen = (int)( (size_t)pGame - (size_t)pFileName ) + 1;
|
||||
Q_strncpy( m_pVMFFileName, pFileName, nLen );
|
||||
Q_strncat( m_pVMFFileName, "\\content\\", sizeof(m_pVMFFileName) );
|
||||
Q_strncat( m_pVMFFileName, pGame + 6, sizeof(m_pVMFFileName) );
|
||||
Q_SetExtension( m_pVMFFileName, ".vmf", sizeof(m_pVMFFileName) );
|
||||
|
||||
// Make sure new entities start with ids at 0
|
||||
CDmeVMFEntity::SetNextEntityId( 0 );
|
||||
|
||||
// Build the Edit file name
|
||||
Q_StripExtension( m_pVMFFileName, m_pEditFileName, sizeof(m_pEditFileName) );
|
||||
Q_strncat( m_pEditFileName, ".vle", sizeof( m_pEditFileName ) );
|
||||
|
||||
// Store the BSP file name
|
||||
Q_strncpy( m_pBSPFileName, pFileName, sizeof( m_pBSPFileName ) );
|
||||
|
||||
// Set the txt file name.
|
||||
// If we loaded a .bsp, clear out what we're doing
|
||||
// load the Edits file into memory, assign it as our "root"
|
||||
CDmElement *pEdit = NULL;
|
||||
if ( !V_stricmp( Q_GetFileExtension( pFileName ), "vle" ) )
|
||||
{
|
||||
if ( g_pDataModel->RestoreFromFile( m_pEditFileName, NULL, "vmf", &pEdit ) != DMFILEID_INVALID )
|
||||
{
|
||||
// If we successfully read the file in, ask it for the max hammer id
|
||||
//int nMaxHammerId = pVMF->GetAttributeValue<int>( "maxHammerId" );
|
||||
//CDmeVMFEntity::SetNextEntityId( nMaxHammerId + 1 );
|
||||
m_hEditRoot = pEdit;
|
||||
SetDirty( false );
|
||||
}
|
||||
}
|
||||
|
||||
if (pEdit == NULL)
|
||||
{
|
||||
if ( g_pFileSystem->FileExists( m_pEditFileName ) )
|
||||
{
|
||||
char pBuf[1024];
|
||||
Q_snprintf( pBuf, sizeof(pBuf), "File %s already exists!\n", m_pEditFileName );
|
||||
m_pEditFileName[0] = 0;
|
||||
vgui::MessageBox *pMessageBox = new vgui::MessageBox( "Unable to overwrite file!\n", pBuf, g_pVcdBlockTool );
|
||||
pMessageBox->DoModal( );
|
||||
return false;
|
||||
}
|
||||
|
||||
DmFileId_t fileid = g_pDataModel->FindOrCreateFileId( m_pEditFileName );
|
||||
m_hEditRoot = CreateElement<CDmElement>( "root", fileid );
|
||||
m_hEditRoot->AddAttribute( "entities", AT_ELEMENT_ARRAY );
|
||||
g_pDataModel->SetFileRoot( fileid, m_hEditRoot );
|
||||
SetDirty( true );
|
||||
}
|
||||
|
||||
guard.Release();
|
||||
|
||||
// tell the engine to actually load the map
|
||||
char cmd[ 256 ];
|
||||
Q_snprintf( cmd, sizeof( cmd ), "disconnect; map %s\n", pszFileName );
|
||||
enginetools->Command( cmd );
|
||||
enginetools->Execute( );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void CVcdBlockDoc::SaveToFile( )
|
||||
{
|
||||
if ( m_hEditRoot.Get() && m_pEditFileName && m_pEditFileName[0] )
|
||||
{
|
||||
g_pDataModel->SaveToFile( m_pEditFileName, NULL, "keyvalues", "vmf", m_hEditRoot );
|
||||
}
|
||||
|
||||
SetDirty( false );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the root object
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmElement *CVcdBlockDoc::GetRootObject()
|
||||
{
|
||||
return m_hEditRoot;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the entity list
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmAttribute *CVcdBlockDoc::GetEntityList()
|
||||
{
|
||||
return m_hEditRoot ? m_hEditRoot->GetAttribute( "entities", AT_ELEMENT_ARRAY ) : NULL;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CVcdBlockDoc::AddNewInfoTarget( const Vector &vecOrigin, const QAngle &angAngles )
|
||||
{
|
||||
CDmrElementArray<> entities = GetEntityList();
|
||||
|
||||
CDmeVMFEntity *pTarget;
|
||||
{
|
||||
CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, "Add Info Target", "Add Info Target" );
|
||||
|
||||
pTarget = CreateElement<CDmeVMFEntity>( "", entities.GetOwner()->GetFileId() );
|
||||
pTarget->SetValue( "classname", "info_target" );
|
||||
pTarget->SetRenderOrigin( vecOrigin );
|
||||
pTarget->SetRenderAngles( angAngles );
|
||||
|
||||
entities.AddToTail( pTarget );
|
||||
pTarget->MarkDirty();
|
||||
pTarget->DrawInEngine( true );
|
||||
}
|
||||
|
||||
g_pVcdBlockTool->GetInfoTargetBrowser()->SelectNode( pTarget );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CVcdBlockDoc::AddNewInfoTarget( void )
|
||||
{
|
||||
Vector vecOrigin;
|
||||
QAngle angAngles;
|
||||
float flFov;
|
||||
clienttools->GetLocalPlayerEyePosition( vecOrigin, angAngles, flFov );
|
||||
AddNewInfoTarget( vecOrigin, vec3_angle );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Deletes a commentary node
|
||||
//-----------------------------------------------------------------------------
|
||||
void CVcdBlockDoc::DeleteInfoTarget( CDmeVMFEntity *pNode )
|
||||
{
|
||||
CDmrElementArray<CDmElement> entities = GetEntityList();
|
||||
int nCount = entities.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
if ( pNode == entities[i] )
|
||||
{
|
||||
CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, "Delete Info Target", "Delete Info Target" );
|
||||
CDmeVMFEntity *pNode = CastElement< CDmeVMFEntity >( entities[ i ] );
|
||||
pNode->DrawInEngine( false );
|
||||
entities.FastRemove( i );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : &vecOrigin -
|
||||
// &angAbsAngles -
|
||||
// Output : CDmeVMFEntity
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeVMFEntity *CVcdBlockDoc::GetInfoTargetForLocation( Vector &vecOrigin, QAngle &angAbsAngles )
|
||||
{
|
||||
const CDmrElementArray<> entities = GetEntityList();
|
||||
int nCount = entities.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
CDmeVMFEntity *pNode = CastElement< CDmeVMFEntity >( entities[ i ] );
|
||||
Vector &vecAngles = *(Vector*)(&pNode->GetRenderAngles());
|
||||
if ( pNode->GetRenderOrigin().DistTo( vecOrigin ) < 1e-3 && vecAngles.DistTo( *(Vector*)&angAbsAngles ) < 1e-1 )
|
||||
return pNode;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : &vecStart -
|
||||
// &vecEnd -
|
||||
// Output : CDmeVMFEntity
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeVMFEntity *CVcdBlockDoc::GetInfoTargetForLocation( Vector &vecStart, Vector &vecEnd )
|
||||
{
|
||||
Vector vecDelta;
|
||||
float flEndDist;
|
||||
|
||||
vecDelta = vecEnd - vecStart;
|
||||
flEndDist = VectorNormalize( vecDelta );
|
||||
|
||||
CDmeVMFEntity *pSelectedNode = NULL;
|
||||
float flMinDistFromLine = 1E30;
|
||||
|
||||
const CDmrElementArray<CDmElement> entities = GetEntityList();
|
||||
int nCount = entities.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
CDmeVMFEntity *pNode = CastElement< CDmeVMFEntity >( entities[ i ] );
|
||||
float flDistAway = DotProduct( pNode->GetRenderOrigin() - vecStart, vecDelta );
|
||||
|
||||
if (flDistAway > 0.0 && flDistAway < flEndDist)
|
||||
{
|
||||
float flDistFromLine = (pNode->GetRenderOrigin() - vecStart - vecDelta * flDistAway).Length();
|
||||
if (flDistFromLine < flMinDistFromLine)
|
||||
{
|
||||
pSelectedNode = pNode;
|
||||
flMinDistFromLine = flDistFromLine;
|
||||
}
|
||||
}
|
||||
}
|
||||
return pSelectedNode;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Populate string choice lists
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CVcdBlockDoc::GetStringChoiceList( const char *pChoiceListType, CDmElement *pElement,
|
||||
const char *pAttributeName, bool bArrayElement, StringChoiceList_t &list )
|
||||
{
|
||||
if ( !Q_stricmp( pChoiceListType, "info_targets" ) )
|
||||
{
|
||||
const CDmrElementArray<> 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 )
|
||||
{
|
||||
CDmeVMFEntity *pNode = CastElement< CDmeVMFEntity >( entities[ i ] );
|
||||
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 CVcdBlockDoc::GetElementChoiceList( const char *pChoiceListType, CDmElement *pElement,
|
||||
const char *pAttributeName, bool bArrayElement, ElementChoiceList_t &list )
|
||||
{
|
||||
if ( !Q_stricmp( pChoiceListType, "allelements" ) )
|
||||
{
|
||||
AddElementsRecursively( m_hEditRoot, list );
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( !Q_stricmp( pChoiceListType, "info_targets" ) )
|
||||
{
|
||||
const CDmrElementArray<> entities = GetEntityList();
|
||||
|
||||
bool bFound = false;
|
||||
int nCount = entities.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
CDmeVMFEntity *pNode = CastElement< CDmeVMFEntity >( entities[ i ] );
|
||||
if ( !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_hEditRoot, list, pChoiceListType );
|
||||
|
||||
return list.Count() > 0;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called when data changes
|
||||
//-----------------------------------------------------------------------------
|
||||
void CVcdBlockDoc::OnDataChanged( const char *pReason, int nNotifySource, int nNotifyFlags )
|
||||
{
|
||||
SetDirty( nNotifyFlags & NOTIFY_SETDIRTYFLAG ? true : false );
|
||||
m_pCallback->OnDocChanged( pReason, nNotifySource, nNotifyFlags );
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// List of all entity classnames to copy over from the original block
|
||||
//-----------------------------------------------------------------------------
|
||||
static const char *s_pUseOriginalClasses[] =
|
||||
{
|
||||
"worldspawn",
|
||||
"func_occluder",
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The server just loaded, populate the list with the entities is has
|
||||
//-----------------------------------------------------------------------------
|
||||
void CVcdBlockDoc::ServerLevelInitPostEntity( void )
|
||||
{
|
||||
CDmrElementArray<> entityList = GetEntityList();
|
||||
|
||||
if ( entityList.Count() )
|
||||
{
|
||||
VerifyAllEdits( entityList );
|
||||
}
|
||||
else
|
||||
{
|
||||
InitializeFromServer( entityList );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Create a list of entities based on what the server has
|
||||
//-----------------------------------------------------------------------------
|
||||
void CVcdBlockDoc::InitializeFromServer( CDmrElementArray<> &entityList )
|
||||
{
|
||||
CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, "Initialize From Server" );
|
||||
|
||||
entityList.RemoveAll();
|
||||
|
||||
// initialize list with entities on the server
|
||||
CBaseEntity *pServerEnt = servertools->FirstEntity();
|
||||
while (pServerEnt)
|
||||
{
|
||||
char classname[256];
|
||||
|
||||
if (servertools->GetKeyValue( pServerEnt, "classname", classname, sizeof( classname ) ) )
|
||||
{
|
||||
if ( !Q_stricmp( classname, "info_target" ))
|
||||
{
|
||||
char hammerid[256];
|
||||
if ( servertools->GetKeyValue( pServerEnt, "hammerid", hammerid, sizeof( hammerid ) ) )
|
||||
{
|
||||
int nextId = CDmeVMFEntity::GetNextEntityId();
|
||||
CDmeVMFEntity::SetNextEntityId( atoi( hammerid ) );
|
||||
|
||||
CDmeVMFEntity *pTarget = CreateElement<CDmeVMFEntity>( "", entityList.GetOwner()->GetFileId() );
|
||||
|
||||
CDmeVMFEntity::SetNextEntityId( nextId );
|
||||
|
||||
if ( pTarget->CopyFromServer( pServerEnt ) )
|
||||
{
|
||||
entityList.AddToTail( pTarget );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pServerEnt = servertools->NextEntity( pServerEnt );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Check the list of entities on the server against the edits that are already made
|
||||
//-----------------------------------------------------------------------------
|
||||
void CVcdBlockDoc::VerifyAllEdits( const CDmrElementArray<> &entityList )
|
||||
{
|
||||
// already filled in
|
||||
for (int i = 0; i < entityList.Count(); i++)
|
||||
{
|
||||
CDmeVMFEntity *pEntity = CastElement<CDmeVMFEntity>( entityList[i] );
|
||||
|
||||
CBaseEntity *pServerEntity = servertools->FindEntityByHammerID( pEntity->GetEntityId() );
|
||||
|
||||
if (pServerEntity != NULL)
|
||||
{
|
||||
if (!pEntity->IsSameOnServer( pServerEntity ))
|
||||
{
|
||||
pEntity->MarkDirty();
|
||||
}
|
||||
else
|
||||
{
|
||||
pEntity->MarkDirty(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pEntity->CreateOnServer();
|
||||
pEntity->MarkDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Load the VMF file, merge in all the edits, write it back out
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CVcdBlockDoc::CopyEditsToVMF( )
|
||||
{
|
||||
const CDmrElementArray<CDmElement> entityList = GetEntityList();
|
||||
|
||||
CDmElement *pVMF = NULL;
|
||||
DmFileId_t fileid = g_pDataModel->FindOrCreateFileId( m_pVMFFileName );
|
||||
if ( g_pDataModel->RestoreFromFile( m_pVMFFileName, NULL, "vmf", &pVMF ) == DMFILEID_INVALID )
|
||||
{
|
||||
// needs some kind of error message
|
||||
return false;
|
||||
}
|
||||
|
||||
CDmrElementArray<CDmElement> vmfEntities( pVMF, "entities" );
|
||||
|
||||
int nVMFCount = vmfEntities.Count();
|
||||
for (int i = 0; i < nVMFCount; i++)
|
||||
{
|
||||
CDmElement *pVMFEntity = vmfEntities[i];
|
||||
|
||||
char classname[256];
|
||||
pVMFEntity->GetValueAsString( "classname", classname, sizeof( classname ) );
|
||||
|
||||
if ( Q_stricmp( "info_target", classname ) )
|
||||
continue;
|
||||
|
||||
int nHammerID = atoi( pVMFEntity->GetName() );
|
||||
|
||||
// find a match.
|
||||
int nCount = entityList.Count();
|
||||
for (int j = 0; j < nCount; j++)
|
||||
{
|
||||
CDmeVMFEntity *pEntity = CastElement<CDmeVMFEntity>( entityList[j] );
|
||||
|
||||
if ( pEntity->IsDirty() && pEntity->GetEntityId() == nHammerID)
|
||||
{
|
||||
char text[256];
|
||||
pEntity->GetValueAsString( "targetname", text, sizeof( text ) );
|
||||
pVMFEntity->SetValueFromString( "targetname", text );
|
||||
pEntity->GetValueAsString( "origin", text, sizeof( text ) );
|
||||
pVMFEntity->SetValueFromString( "origin", text );
|
||||
pEntity->GetValueAsString( "angles", text, sizeof( text ) );
|
||||
pVMFEntity->SetValueFromString( "angles", text );
|
||||
|
||||
pEntity->MarkDirty(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add the new entities
|
||||
int nCount = entityList.Count();
|
||||
for (int j = 0; j < nCount; j++)
|
||||
{
|
||||
CDmeVMFEntity *pEntity = CastElement<CDmeVMFEntity>( entityList[j] );
|
||||
|
||||
if ( pEntity->IsDirty())
|
||||
{
|
||||
CDmElement *pVMFEntity = CreateElement<CDmElement>( pEntity->GetName(), fileid );
|
||||
|
||||
char text[256];
|
||||
pEntity->GetValueAsString( "classname", text, sizeof( text ) );
|
||||
pVMFEntity->SetValue( "classname", text );
|
||||
pEntity->GetValueAsString( "targetname", text, sizeof( text ) );
|
||||
pVMFEntity->SetValue( "targetname", text );
|
||||
pEntity->GetValueAsString( "origin", text, sizeof( text ) );
|
||||
pVMFEntity->SetValue( "origin", text );
|
||||
pEntity->GetValueAsString( "angles", text, sizeof( text ) );
|
||||
pVMFEntity->SetValue( "angles", text );
|
||||
|
||||
vmfEntities.AddToTail( pVMFEntity );
|
||||
|
||||
pEntity->MarkDirty(false);
|
||||
}
|
||||
}
|
||||
|
||||
// currently, don't overwrite the vmf, not sure if this is serializing correctly yet
|
||||
char tmpname[ 256 ];
|
||||
Q_StripExtension( m_pVMFFileName, tmpname, sizeof(tmpname) );
|
||||
Q_SetExtension( tmpname, ".vme", sizeof(tmpname) );
|
||||
|
||||
if (!g_pDataModel->SaveToFile( tmpname, NULL, "keyvalues", "vmf", pVMF ))
|
||||
{
|
||||
// needs some kind of error message
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
// If we successfully read the file in, ask it for the max hammer id
|
||||
int nMaxHammerId = pVMF->GetAttributeValue<int>( "maxHammerId" );
|
||||
CDmeVMFEntity::SetNextEntityId( nMaxHammerId + 1 );
|
||||
m_hVMFRoot = pVMF;
|
||||
*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool CVcdBlockDoc::RememberPlayerPosition()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
108
tools/vcdblock/vcdblockdoc.h
Normal file
108
tools/vcdblock/vcdblockdoc.h
Normal file
@@ -0,0 +1,108 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef VCDBLOCKDOC_H
|
||||
#define VCDBLOCKDOC_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "dme_controls/inotifyui.h"
|
||||
#include "datamodel/dmehandle.h"
|
||||
#include "datamodel/dmelement.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class IVcdBlockDocCallback;
|
||||
class CVcdBlockDoc;
|
||||
class CDmeVMFEntity;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Contains all editable state
|
||||
//-----------------------------------------------------------------------------
|
||||
class CVcdBlockDoc : public IDmNotify
|
||||
{
|
||||
public:
|
||||
CVcdBlockDoc( IVcdBlockDocCallback *pCallback );
|
||||
~CVcdBlockDoc();
|
||||
|
||||
// Inherited from INotifyUI
|
||||
virtual void NotifyDataChanged( const char *pReason, int nNotifySource, int nNotifyFlags );
|
||||
|
||||
// Sets/Gets the file name
|
||||
const char *GetBSPFileName();
|
||||
const char *GetVMFFileName();
|
||||
const char *GetEditFileName();
|
||||
void SetVMFFileName( const char *pFileName );
|
||||
void SetEditFileName( 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 );
|
||||
|
||||
// Create a text block the engine can parse containing the entity data to spawn
|
||||
void ServerLevelInitPostEntity( void );
|
||||
|
||||
// Returns the entity list
|
||||
CDmAttribute *GetEntityList();
|
||||
|
||||
// Adds a new info_target
|
||||
void AddNewInfoTarget( void );
|
||||
void AddNewInfoTarget( const Vector &vecOrigin, const QAngle &angAngles );
|
||||
|
||||
// Deletes a commentary node
|
||||
void DeleteInfoTarget( CDmeVMFEntity *pNode );
|
||||
|
||||
// Returns the commentary node at the specified location
|
||||
CDmeVMFEntity *GetInfoTargetForLocation( Vector &vecOrigin, QAngle &angAbsAngles );
|
||||
|
||||
// Returns the info target that's closest to this line
|
||||
CDmeVMFEntity *GetInfoTargetForLocation( Vector &vecStart, Vector &vecEnd );
|
||||
|
||||
// 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 );
|
||||
|
||||
|
||||
void VerifyAllEdits( const CDmrElementArray<> &entityList );
|
||||
void InitializeFromServer( CDmrElementArray<> &entityList );
|
||||
|
||||
bool CopyEditsToVMF( void );
|
||||
|
||||
bool RememberPlayerPosition( void );
|
||||
|
||||
private:
|
||||
IVcdBlockDocCallback *m_pCallback;
|
||||
CDmeHandle< CDmElement > m_hVMFRoot; // VMF file
|
||||
CDmeHandle< CDmElement > m_hEditRoot; // VMF Edits file
|
||||
char m_pBSPFileName[512];
|
||||
char m_pVMFFileName[512];
|
||||
char m_pEditFileName[512];
|
||||
bool m_bDirty;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // VCDBLOCKDOC_H
|
||||
1300
tools/vcdblock/vcdblocktool.cpp
Normal file
1300
tools/vcdblock/vcdblocktool.cpp
Normal file
File diff suppressed because it is too large
Load Diff
239
tools/vcdblock/vcdblocktool.h
Normal file
239
tools/vcdblock/vcdblocktool.h
Normal file
@@ -0,0 +1,239 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: VcdBlock tool; main UI smarts class
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#ifndef VCDBLOCKTOOL_H
|
||||
#define VCDBLOCKTOOL_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 "dmevmfentity.h"
|
||||
#include "toolframework/ienginetool.h"
|
||||
#include "toolutils/enginetools_int.h"
|
||||
#include "toolutils/savewindowpositions.h"
|
||||
#include "toolutils/toolwindowfactory.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class CDmElement;
|
||||
class CVcdBlockDoc;
|
||||
class CInfoTargetPropertiesPanel;
|
||||
class CInfoTargetBrowserPanel;
|
||||
|
||||
namespace vgui
|
||||
{
|
||||
class Panel;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Allows the doc to call back into the VcdBlock editor tool
|
||||
//-----------------------------------------------------------------------------
|
||||
abstract_class IVcdBlockDocCallback
|
||||
{
|
||||
public:
|
||||
// Called by the doc when the data changes
|
||||
virtual void OnDocChanged( const char *pReason, int nNotifySource, int nNotifyFlags ) = 0;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Global methods of the VCD Blocking tool
|
||||
//-----------------------------------------------------------------------------
|
||||
abstract_class IVcdBlockTool
|
||||
{
|
||||
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( CDmeVMFEntity *pEntity ) = 0;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Implementation of the VcdBlock tool
|
||||
//-----------------------------------------------------------------------------
|
||||
class CVcdBlockTool : public CBaseToolSystem, public IFileMenuCallbacks, public IVcdBlockDocCallback, public IVcdBlockTool
|
||||
{
|
||||
DECLARE_CLASS_SIMPLE( CVcdBlockTool, CBaseToolSystem );
|
||||
|
||||
public:
|
||||
CVcdBlockTool();
|
||||
|
||||
// Inherited from IToolSystem
|
||||
virtual const char *GetToolName() { return "VCD Blocking Tool"; }
|
||||
virtual bool Init( );
|
||||
virtual void Shutdown();
|
||||
virtual bool CanQuit();
|
||||
virtual void OnToolActivate();
|
||||
virtual void OnToolDeactivate();
|
||||
virtual void ServerLevelInitPostEntity();
|
||||
virtual void DrawEntitiesInEngine( 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 IVcdBlockDocCallback
|
||||
virtual void OnDocChanged( const char *pReason, int nNotifySource, int nNotifyFlags );
|
||||
virtual vgui::Panel *GetRootPanel() { return this; }
|
||||
virtual void ShowEntityInEntityProperties( CDmeVMFEntity *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 "VcdBlockTool"; }
|
||||
virtual const char *GetBindingsContextFile() { return "cfg/VcdBlock.kb"; }
|
||||
virtual vgui::MenuBar *CreateMenuBar( CBaseToolSystem *pParent );
|
||||
|
||||
MESSAGE_FUNC( Save, "OnSave" );
|
||||
void SaveAndTest();
|
||||
void RestartMap();
|
||||
|
||||
// Enter mode where we preview dropping nodes
|
||||
void EnterTargetDropMode();
|
||||
void LeaveTargetDropMode();
|
||||
|
||||
bool IsMiniViewportCursor( int x, int y, Vector &org, Vector &forward );
|
||||
|
||||
// Save/Load game state
|
||||
void SetRememberPlayerPosition( bool state = true ) { m_bRememberPlayerPosition = state; };
|
||||
bool GetRememberPlayerPosition( void ) { return m_bRememberPlayerPosition; };
|
||||
void QuickLoad();
|
||||
void QuickSave();
|
||||
|
||||
bool IsInNodeDrag( void ) { return m_bInNodeDragMode; };
|
||||
|
||||
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 VcdBlock menu
|
||||
MESSAGE_FUNC( OnAddNewNodes, "AddNewNodes" );
|
||||
MESSAGE_FUNC( OnCopyEditsToVMF, "CopyEditsToVMF" );
|
||||
MESSAGE_FUNC( OnRememberPosition, "RememberPosition" );
|
||||
|
||||
// Methods related to the view menu
|
||||
MESSAGE_FUNC( OnToggleProperties, "OnToggleProperties" );
|
||||
MESSAGE_FUNC( OnToggleEntityReport, "OnToggleEntityReport" );
|
||||
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( VcdBlockAddNewNodes, KEY_A, vgui::MODIFIER_CONTROL, OnAddNewNodes, "#VcdBlockAddNewNodesHelp", 0 );
|
||||
|
||||
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
|
||||
CVcdBlockDoc *GetDocument();
|
||||
|
||||
// Gets at tool windows
|
||||
CInfoTargetPropertiesPanel *GetProperties();
|
||||
CInfoTargetBrowserPanel *GetInfoTargetBrowser();
|
||||
|
||||
CDmeHandle< CDmeVMFEntity > 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( CVcdBlockDoc *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 );
|
||||
|
||||
private:
|
||||
// Document
|
||||
CVcdBlockDoc *m_pDoc;
|
||||
|
||||
// The menu bar
|
||||
CToolFileMenuBar *m_pMenuBar;
|
||||
|
||||
// Element properties for editing material
|
||||
vgui::DHANDLE< CInfoTargetPropertiesPanel > m_hProperties;
|
||||
|
||||
// The entity report
|
||||
vgui::DHANDLE< CInfoTargetBrowserPanel > m_hInfoTargetBrowser;
|
||||
|
||||
// The currently viewed entity
|
||||
CDmeHandle< CDmeVMFEntity > m_hCurrentEntity;
|
||||
|
||||
// Separate undo context for the act busy tool
|
||||
bool m_bInNodeDropMode;
|
||||
bool m_bInNodeDragMode;
|
||||
int m_iDragX;
|
||||
int m_iDragY;
|
||||
CDmeHandle< CDmeVMFEntity > m_hPreviewTarget;
|
||||
CToolWindowFactory< ToolWindow > m_ToolWindowFactory;
|
||||
|
||||
// remembered player position
|
||||
bool m_bRememberPlayerPosition;
|
||||
bool m_bHasPlayerPosition;
|
||||
Vector m_vecPlayerOrigin;
|
||||
QAngle m_vecPlayerAngles;
|
||||
};
|
||||
|
||||
extern CVcdBlockTool *g_pVcdBlockTool;
|
||||
|
||||
#endif // VCDBLOCKTOOL_H
|
||||
59
tools/vmt/vmt.vpc
Normal file
59
tools/vmt/vmt.vpc
Normal file
@@ -0,0 +1,59 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// VMT.VPC
|
||||
//
|
||||
// Project Script
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
$Macro SRCDIR "..\.."
|
||||
$Macro OUTBINDIR "$SRCDIR\..\game\bin\tools"
|
||||
|
||||
$Include "$SRCDIR\vpc_scripts\source_dll_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 "vmtdoc.cpp"
|
||||
$File "vmttool.cpp"
|
||||
}
|
||||
|
||||
$Folder "Header Files"
|
||||
{
|
||||
$File "$SRCDIR\public\interpolatortypes.h"
|
||||
$File "vmtdoc.h"
|
||||
$File "vmttool.h"
|
||||
}
|
||||
|
||||
$Folder "Link Libraries"
|
||||
{
|
||||
$Lib datamodel
|
||||
$Lib dmxloader
|
||||
$Lib dme_controls
|
||||
$Lib dmserializers
|
||||
$Lib mathlib
|
||||
$Lib matsys_controls
|
||||
$Lib movieobjects
|
||||
$Lib sfmobjects
|
||||
$Lib tier2
|
||||
$Lib tier3
|
||||
$Lib toolutils
|
||||
$Lib vgui_controls
|
||||
}
|
||||
}
|
||||
1078
tools/vmt/vmtdoc.cpp
Normal file
1078
tools/vmt/vmtdoc.cpp
Normal file
File diff suppressed because it is too large
Load Diff
133
tools/vmt/vmtdoc.h
Normal file
133
tools/vmt/vmtdoc.h
Normal file
@@ -0,0 +1,133 @@
|
||||
//========= Copyright 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
|
||||
1337
tools/vmt/vmttool.cpp
Normal file
1337
tools/vmt/vmttool.cpp
Normal file
File diff suppressed because it is too large
Load Diff
50
tools/vmt/vmttool.h
Normal file
50
tools/vmt/vmttool.h
Normal file
@@ -0,0 +1,50 @@
|
||||
//========= Copyright 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
|
||||
Reference in New Issue
Block a user