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

View File

@@ -0,0 +1,64 @@
// ----------------------------------------- //
// File generated by VPC //
// ----------------------------------------- //
Source file: F:\csgo_64\cstrike15_src\tools\commedit\commeditdoc.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\commedit\commeditdoc.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\commedit\commeditdoc.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\tools\commedit\commedittool.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\commedit\commedittool.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\commedit\commedittool.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\tools\commedit\commentarynodebrowserpanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\commedit\commentarynodebrowserpanel.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\commedit\commentarynodebrowserpanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\tools\commedit\commentarypropertiespanel.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\commedit\commentarypropertiespanel.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\commedit\commentarypropertiespanel.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\common\debug_dll_check.cpp
Debug output file: F:\csgo_64\cstrike15_src\common\debug_dll_check.cpp
Release output file: F:\csgo_64\cstrike15_src\common\debug_dll_check.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\tools\commedit\dmecommentarynodeentity.cpp
Debug output file: F:\csgo_64\cstrike15_src\tools\commedit\dmecommentarynodeentity.cpp
Release output file: F:\csgo_64\cstrike15_src\tools\commedit\dmecommentarynodeentity.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\public\interpolatortypes.cpp
Debug output file: F:\csgo_64\cstrike15_src\public\interpolatortypes.cpp
Release output file: F:\csgo_64\cstrike15_src\public\interpolatortypes.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\public\tier0\memoverride.cpp
Debug output file: F:\csgo_64\cstrike15_src\public\tier0\memoverride.cpp
Release output file: F:\csgo_64\cstrike15_src\public\tier0\memoverride.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\public\registry.cpp
Debug output file: F:\csgo_64\cstrike15_src\public\registry.cpp
Release output file: F:\csgo_64\cstrike15_src\public\registry.cpp
Containing unity file:
PCH file:
Source file: F:\csgo_64\cstrike15_src\public\vgui_controls\vgui_controls.cpp
Debug output file: F:\csgo_64\cstrike15_src\public\vgui_controls\vgui_controls.cpp
Release output file: F:\csgo_64\cstrike15_src\public\vgui_controls\vgui_controls.cpp
Containing unity file:
PCH file:

View File

@@ -0,0 +1,66 @@
//-----------------------------------------------------------------------------
// COMMEDIT.VPC
//
// Project Script
//-----------------------------------------------------------------------------
$Macro SRCDIR "..\.."
$Macro OUTBINDIR "$SRCDIR\..\game\bin\tools"
$Include "$SRCDIR\vpc_scripts\source_dll_win32_base.vpc"
$Configuration
{
$Compiler
{
$AdditionalIncludeDirectories "$BASE,.\,..\common,$SRCDIR\game\shared"
$PreprocessorDefinitions "$BASE;COMMEDIT_EXPORTS"
}
$Linker
{
$AdditionalDependencies "$BASE Psapi.lib"
}
}
$Project "Commedit"
{
$Folder "Source Files"
{
$File "commeditdoc.cpp"
$File "commedittool.cpp"
$File "commentarynodebrowserpanel.cpp"
$File "commentarypropertiespanel.cpp"
$File "dmecommentarynodeentity.cpp"
$File "$SRCDIR\public\interpolatortypes.cpp"
$File "$SRCDIR\public\registry.cpp"
$File "$SRCDIR\public\vgui_controls\vgui_controls.cpp"
}
$Folder "Header Files"
{
$File "commeditdoc.h"
$File "commedittool.h"
$File "commentarynodebrowserpanel.h"
$File "commentarypropertiespanel.h"
$File "dmecommentarynodeentity.h"
$File "$SRCDIR\public\mathlib\mathlib.h"
}
$Folder "Link Libraries"
{
$File "$SRCDIR\lib\public\bonesetup.lib"
$File "$SRCDIR\lib\public\datamodel.lib"
$File "$SRCDIR\lib\public\dmxloader.lib"
$File "$SRCDIR\lib\public\dme_controls.lib"
$File "$SRCDIR\lib\public\dmserializers.lib"
$File "$SRCDIR\lib\public\dmxloader.lib"
$File "$SRCDIR\lib\public\mathlib.lib"
$File "$SRCDIR\lib\public\matsys_controls.lib"
$File "$SRCDIR\lib\public\movieobjects.lib"
$File "$SRCDIR\lib\public\tier2.lib"
$File "$SRCDIR\lib\public\tier3.lib"
$File "$SRCDIR\lib\public\toolutils.lib"
$File "$SRCDIR\lib\public\vgui_controls.lib"
}
}

View File

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

View File

@@ -0,0 +1,465 @@
//====== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. =======//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "commeditdoc.h"
#include "tier1/keyvalues.h"
#include "tier1/utlbuffer.h"
#include "toolutils/enginetools_int.h"
#include "filesystem.h"
#include "commedittool.h"
#include "toolframework/ienginetool.h"
#include "dmecommentarynodeentity.h"
#include "datamodel/idatamodel.h"
#include "toolutils/attributeelementchoicelist.h"
#include "commentarynodebrowserpanel.h"
#include "vgui_controls/messagebox.h"
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CCommEditDoc::CCommEditDoc( ICommEditDocCallback *pCallback ) : m_pCallback( pCallback )
{
m_hRoot = NULL;
m_pTXTFileName[0] = 0;
m_bDirty = false;
g_pDataModel->InstallNotificationCallback( this );
}
CCommEditDoc::~CCommEditDoc()
{
g_pDataModel->RemoveNotificationCallback( this );
}
//-----------------------------------------------------------------------------
// Inherited from INotifyUI
//-----------------------------------------------------------------------------
void CCommEditDoc::NotifyDataChanged( const char *pReason, int nNotifySource, int nNotifyFlags )
{
OnDataChanged( pReason, nNotifySource, nNotifyFlags );
}
//-----------------------------------------------------------------------------
// Gets the file name
//-----------------------------------------------------------------------------
const char *CCommEditDoc::GetTXTFileName()
{
return m_pTXTFileName;
}
void CCommEditDoc::SetTXTFileName( const char *pFileName )
{
Q_strncpy( m_pTXTFileName, pFileName, sizeof( m_pTXTFileName ) );
Q_FixSlashes( m_pTXTFileName );
SetDirty( true );
}
//-----------------------------------------------------------------------------
// Dirty bits
//-----------------------------------------------------------------------------
void CCommEditDoc::SetDirty( bool bDirty )
{
m_bDirty = bDirty;
}
bool CCommEditDoc::IsDirty() const
{
return m_bDirty;
}
//-----------------------------------------------------------------------------
// Saves/loads from file
//-----------------------------------------------------------------------------
bool CCommEditDoc::LoadFromFile( const char *pFileName )
{
Assert( !m_hRoot.Get() );
CAppDisableUndoScopeGuard guard( "CCommEditDoc::LoadFromFile", 0 );
SetDirty( false );
if ( !pFileName[0] )
return false;
char mapname[ 256 ];
// Compute the map name
const char *pMaps = Q_stristr( pFileName, "\\maps\\" );
if ( !pMaps )
return false;
// Build map name
//int nNameLen = (int)( (size_t)pComm - (size_t)pMaps ) - 5;
Q_StripExtension( pFileName, mapname, sizeof(mapname) );
char *pszFileName = (char*)Q_UnqualifiedFileName(mapname);
// Set the txt file name.
// If we loaded an existing commentary file, keep the same filename.
// If we loaded a .bsp, change the name & the extension.
if ( !V_stricmp( Q_GetFileExtension( pFileName ), "bsp" ) )
{
const char *pCommentaryAppend = "_commentary.txt";
Q_StripExtension( pFileName, m_pTXTFileName, sizeof(m_pTXTFileName)- strlen(pCommentaryAppend) - 1 );
Q_strcat( m_pTXTFileName, pCommentaryAppend, sizeof( m_pTXTFileName ) );
if ( g_pFileSystem->FileExists( m_pTXTFileName ) )
{
char pBuf[1024];
Q_snprintf( pBuf, sizeof(pBuf), "File %s already exists!\n", m_pTXTFileName );
m_pTXTFileName[0] = 0;
vgui::MessageBox *pMessageBox = new vgui::MessageBox( "Unable to overwrite file!\n", pBuf, g_pCommEditTool );
pMessageBox->DoModal( );
return false;
}
DmFileId_t fileid = g_pDataModel->FindOrCreateFileId( m_pTXTFileName );
m_hRoot = CreateElement<CDmElement>( "root", fileid );
CDmrElementArray<> subkeys( m_hRoot->AddAttribute( "subkeys", AT_ELEMENT_ARRAY ) );
CDmElement *pRoot2 = CreateElement<CDmElement>( "Entities", fileid );
pRoot2->AddAttribute( "subkeys", AT_ELEMENT_ARRAY );
subkeys.AddToTail( pRoot2 );
g_pDataModel->SetFileRoot( fileid, m_hRoot );
}
else
{
char *pComm = Q_stristr( pszFileName, "_commentary" );
if ( !pComm )
{
char pBuf[1024];
Q_snprintf( pBuf, sizeof(pBuf), "File %s is not a commentary file!\nThe file name must end in _commentary.txt.\n", m_pTXTFileName );
m_pTXTFileName[0] = 0;
vgui::MessageBox *pMessageBox = new vgui::MessageBox( "Bad file name!\n", pBuf, g_pCommEditTool );
pMessageBox->DoModal( );
return false;
}
// Clip off the "_commentary" at the end of the filename
*pComm = '\0';
// This is not undoable
CDisableUndoScopeGuard guard;
CDmElement *pTXT = NULL;
DmFileId_t fileid = g_pDataModel->RestoreFromFile( pFileName, NULL, "commentary", &pTXT );
if ( fileid == DMFILEID_INVALID )
{
m_pTXTFileName[0] = 0;
return false;
}
SetTXTFileName( pFileName );
m_hRoot = pTXT;
}
guard.Release();
SetDirty( false );
char cmd[ 256 ];
Q_snprintf( cmd, sizeof( cmd ), "disconnect; map %s\n", pszFileName );
enginetools->Command( cmd );
enginetools->Execute( );
return true;
}
void CCommEditDoc::SaveToFile( )
{
if ( m_hRoot.Get() && m_pTXTFileName && m_pTXTFileName[0] )
{
g_pDataModel->SaveToFile( m_pTXTFileName, NULL, "keyvalues", "keyvalues", m_hRoot );
}
SetDirty( false );
}
//-----------------------------------------------------------------------------
// Returns the root object
//-----------------------------------------------------------------------------
CDmElement *CCommEditDoc::GetRootObject()
{
return m_hRoot;
}
//-----------------------------------------------------------------------------
// Returns the entity list
//-----------------------------------------------------------------------------
CDmAttribute *CCommEditDoc::GetEntityList()
{
CDmrElementArray<> mainKeys( m_hRoot, "subkeys" );
if ( !mainKeys.IsValid() || mainKeys.Count() == 0 )
return NULL;
CDmeHandle<CDmElement> hEntityList;
hEntityList = mainKeys[ 0 ];
return hEntityList ? hEntityList->GetAttribute( "subkeys", AT_ELEMENT_ARRAY ) : NULL;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCommEditDoc::AddNewInfoRemarkable( const Vector &vecOrigin, const QAngle &angAngles )
{
CDmrCommentaryNodeEntityList entities( GetEntityList() );
if ( !entities.IsValid() )
return;
CDmeCommentaryNodeEntity *pTarget;
{
CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, "Add Info Remarkable", "Add Info Remarkable" );
pTarget = CreateElement<CDmeCommentaryNodeEntity>( "remarkable", entities.GetOwner()->GetFileId() );
pTarget->SetName( "entity" );
pTarget->SetValue( "classname", "info_remarkable" );
pTarget->SetRenderOrigin( vecOrigin );
pTarget->SetRenderAngles( angAngles );
entities.AddToTail( pTarget );
pTarget->MarkDirty();
pTarget->DrawInEngine( true );
}
g_pCommEditTool->GetCommentaryNodeBrowser()->SelectNode( pTarget );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCommEditDoc::AddNewInfoRemarkable( void )
{
Vector vecOrigin;
QAngle angAngles;
float flFov;
clienttools->GetLocalPlayerEyePosition( vecOrigin, angAngles, flFov );
AddNewInfoRemarkable( vecOrigin, vec3_angle );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCommEditDoc::AddNewInfoTarget( const Vector &vecOrigin, const QAngle &angAngles )
{
CDmrCommentaryNodeEntityList entities( GetEntityList() );
if ( !entities.IsValid() )
return;
CDmeCommentaryNodeEntity *pTarget;
{
CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, "Add Info Target", "Add Info Target" );
pTarget = CreateElement<CDmeCommentaryNodeEntity>( "target", entities.GetOwner()->GetFileId() );
pTarget->SetName( "entity" );
pTarget->SetValue( "classname", "info_target" );
pTarget->SetRenderOrigin( vecOrigin );
pTarget->SetRenderAngles( angAngles );
entities.AddToTail( pTarget );
pTarget->MarkDirty();
pTarget->DrawInEngine( true );
}
g_pCommEditTool->GetCommentaryNodeBrowser()->SelectNode( pTarget );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCommEditDoc::AddNewInfoTarget( void )
{
Vector vecOrigin;
QAngle angAngles;
float flFov;
clienttools->GetLocalPlayerEyePosition( vecOrigin, angAngles, flFov );
AddNewInfoTarget( vecOrigin, vec3_angle );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCommEditDoc::AddNewCommentaryNode( const Vector &vecOrigin, const QAngle &angAngles )
{
CDmrCommentaryNodeEntityList entities = GetEntityList();
CDmeCommentaryNodeEntity *pNode;
{
CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, "Add Commentary Node", "Add Commentary Node" );
pNode = CreateElement<CDmeCommentaryNodeEntity>( "node", entities.GetOwner()->GetFileId() );
pNode->SetName( "entity" );
pNode->SetValue( "classname", "point_commentary_node" );
pNode->SetRenderOrigin( vecOrigin );
pNode->SetRenderAngles( angAngles );
pNode->SetValue( "precommands", "" );
pNode->SetValue( "postcommands", "" );
pNode->SetValue( "commentaryfile", "" );
pNode->SetValue( "viewtarget", "" );
pNode->SetValue( "viewposition", "" );
pNode->SetValue<int>( "prevent_movement", 0 );
pNode->SetValue( "speakers", "" );
pNode->SetValue( "synopsis", "" );
entities.AddToTail( pNode );
pNode->MarkDirty();
pNode->DrawInEngine( true );
}
g_pCommEditTool->GetCommentaryNodeBrowser()->SelectNode( pNode );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCommEditDoc::AddNewCommentaryNode( void )
{
Vector vecOrigin;
QAngle angAngles;
float flFov;
clienttools->GetLocalPlayerEyePosition( vecOrigin, angAngles, flFov );
AddNewCommentaryNode( vecOrigin, vec3_angle );
}
//-----------------------------------------------------------------------------
// Deletes a commentary node
//-----------------------------------------------------------------------------
void CCommEditDoc::DeleteCommentaryNode( CDmElement *pRemoveNode )
{
CDmrCommentaryNodeEntityList entities = GetEntityList();
int nCount = entities.Count();
for ( int i = 0; i < nCount; ++i )
{
if ( pRemoveNode == entities[i] )
{
CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, "Delete Commentary Node", "Delete Commentary Node" );
CDmeCommentaryNodeEntity *pNode = entities[ i ];
pNode->DrawInEngine( false );
entities.FastRemove( i );
return;
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : &vecOrigin -
// &angAbsAngles -
// Output : CDmeCommentaryNodeEntity
//-----------------------------------------------------------------------------
CDmeCommentaryNodeEntity *CCommEditDoc::GetCommentaryNodeForLocation( Vector &vecOrigin, QAngle &angAbsAngles )
{
CDmrCommentaryNodeEntityList entities = GetEntityList();
int nCount = entities.Count();
for ( int i = 0; i < nCount; ++i )
{
CDmeCommentaryNodeEntity *pNode = entities[ i ];
if ( !pNode )
continue;
Vector &vecAngles = *(Vector*)(&pNode->GetRenderAngles());
if ( pNode->GetRenderOrigin().DistTo( vecOrigin ) < 1e-3 && vecAngles.DistTo( *(Vector*)&angAbsAngles ) < 1e-1 )
return pNode;
}
return NULL;
}
//-----------------------------------------------------------------------------
// Populate string choice lists
//-----------------------------------------------------------------------------
bool CCommEditDoc::GetStringChoiceList( const char *pChoiceListType, CDmElement *pElement,
const char *pAttributeName, bool bArrayElement, StringChoiceList_t &list )
{
if ( !Q_stricmp( pChoiceListType, "info_targets" ) )
{
CDmrCommentaryNodeEntityList entities = GetEntityList();
StringChoice_t sChoice;
sChoice.m_pValue = "";
sChoice.m_pChoiceString = "";
list.AddToTail( sChoice );
int nCount = entities.Count();
for ( int i = 0; i < nCount; ++i )
{
CDmeCommentaryNodeEntity *pNode = entities[ i ];
if ( !pNode )
continue;
if ( !V_stricmp( pNode->GetClassName(), "info_target" ) )
{
StringChoice_t sChoice;
sChoice.m_pValue = pNode->GetTargetName();
sChoice.m_pChoiceString = pNode->GetTargetName();
list.AddToTail( sChoice );
}
}
return true;
}
return false;
}
//-----------------------------------------------------------------------------
// Populate element choice lists
//-----------------------------------------------------------------------------
bool CCommEditDoc::GetElementChoiceList( const char *pChoiceListType, CDmElement *pElement,
const char *pAttributeName, bool bArrayElement, ElementChoiceList_t &list )
{
if ( !Q_stricmp( pChoiceListType, "allelements" ) )
{
AddElementsRecursively( m_hRoot, list );
return true;
}
if ( !Q_stricmp( pChoiceListType, "info_targets" ) )
{
CDmrCommentaryNodeEntityList entities = GetEntityList();
bool bFound = false;
int nCount = entities.Count();
for ( int i = 0; i < nCount; ++i )
{
CDmeCommentaryNodeEntity *pNode = entities[ i ];
if ( pNode && !V_stricmp( pNode->GetClassName(), "info_target" ) )
{
bFound = true;
ElementChoice_t sChoice;
sChoice.m_pValue = pNode;
sChoice.m_pChoiceString = pNode->GetTargetName();
list.AddToTail( sChoice );
}
}
return bFound;
}
// by default, try to treat the choice list type as a Dme element type
AddElementsRecursively( m_hRoot, list, pChoiceListType );
return list.Count() > 0;
}
//-----------------------------------------------------------------------------
// Called when data changes
//-----------------------------------------------------------------------------
void CCommEditDoc::OnDataChanged( const char *pReason, int nNotifySource, int nNotifyFlags )
{
SetDirty( nNotifyFlags & NOTIFY_SETDIRTYFLAG ? true : false );
m_pCallback->OnDocChanged( pReason, nNotifySource, nNotifyFlags );
}

View File

@@ -0,0 +1,96 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
// $NoKeywords: $
//
//===========================================================================//
#ifndef COMMEDITDOC_H
#define COMMEDITDOC_H
#ifdef _WIN32
#pragma once
#endif
#include "dme_controls/inotifyui.h"
#include "datamodel/dmehandle.h"
#include "datamodel/dmelement.h"
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class ICommEditDocCallback;
class CCommEditDoc;
class CDmeCommentaryNodeEntity;
typedef CDmrElementArray<CDmeCommentaryNodeEntity> CDmrCommentaryNodeEntityList;
//-----------------------------------------------------------------------------
// Contains all editable state
//-----------------------------------------------------------------------------
class CCommEditDoc : public IDmNotify
{
public:
CCommEditDoc( ICommEditDocCallback *pCallback );
~CCommEditDoc();
// Inherited from INotifyUI
virtual void NotifyDataChanged( const char *pReason, int nNotifySource, int nNotifyFlags );
// Sets/Gets the file name
const char *GetTXTFileName();
void SetTXTFileName( const char *pFileName );
// Dirty bits (has it changed since the last time it was saved?)
void SetDirty( bool bDirty );
bool IsDirty() const;
// Saves/loads from file
bool LoadFromFile( const char *pFileName );
void SaveToFile( );
// Returns the root object
CDmElement *GetRootObject();
// Called when data changes (see INotifyUI for flags)
void OnDataChanged( const char *pReason, int nNotifySource, int nNotifyFlags );
// Returns the entity list
CDmAttribute *GetEntityList();
// Adds a new info_target
void AddNewInfoTarget( void );
void AddNewInfoTarget( const Vector &vecOrigin, const QAngle &angAngles );
// Adds a new commentary node
void AddNewCommentaryNode( void );
void AddNewCommentaryNode( const Vector &vecOrigin, const QAngle &angAngles );
// Adds an info remarkable
void AddNewInfoRemarkable( void );
void AddNewInfoRemarkable( const Vector &vecOrigin, const QAngle &angAngles );
// Deletes a commentary node
void DeleteCommentaryNode( CDmElement *pNode );
// Returns the commentary node at the specified location
CDmeCommentaryNodeEntity *GetCommentaryNodeForLocation( Vector &vecOrigin, QAngle &angAbsAngles );
// For element choice lists. Return false if it's an unknown choice list type
virtual bool GetStringChoiceList( const char *pChoiceListType, CDmElement *pElement,
const char *pAttributeName, bool bArrayElement, StringChoiceList_t &list );
virtual bool GetElementChoiceList( const char *pChoiceListType, CDmElement *pElement,
const char *pAttributeName, bool bArrayElement, ElementChoiceList_t &list );
private:
ICommEditDocCallback *m_pCallback;
CDmeHandle< CDmElement > m_hRoot;
char m_pTXTFileName[512];
bool m_bDirty;
};
#endif // COMMEDITDOC_H

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,239 @@
//====== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. =======
//
// Purpose: CommEdit tool; main UI smarts class
//
//=============================================================================
#ifndef COMMEDITTOOL_H
#define COMMEDITTOOL_H
#ifdef _WIN32
#pragma once
#endif
#include "tier0/platform.h"
#include "toolutils/basetoolsystem.h"
#include "toolutils/recentfilelist.h"
#include "toolutils/toolmenubar.h"
#include "toolutils/toolswitchmenubutton.h"
#include "toolutils/tooleditmenubutton.h"
#include "toolutils/toolfilemenubutton.h"
#include "toolutils/toolmenubutton.h"
#include "datamodel/dmelement.h"
#include "dmecommentarynodeentity.h"
#include "toolframework/ienginetool.h"
#include "toolutils/enginetools_int.h"
#include "toolutils/savewindowpositions.h"
#include "toolutils/toolwindowfactory.h"
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class CDmElement;
class CConsolePage;
class CCommEditDoc;
class CCommentaryPropertiesPanel;
class CCommentaryNodeBrowserPanel;
namespace vgui
{
class Panel;
}
//-----------------------------------------------------------------------------
// Allows the doc to call back into the CommEdit editor tool
//-----------------------------------------------------------------------------
abstract_class ICommEditDocCallback
{
public:
// Called by the doc when the data changes
virtual void OnDocChanged( const char *pReason, int nNotifySource, int nNotifyFlags ) = 0;
};
//-----------------------------------------------------------------------------
// Global methods of the commedit tool
//-----------------------------------------------------------------------------
abstract_class ICommEditTool
{
public:
// Gets at the rool panel (for modal dialogs)
virtual vgui::Panel *GetRootPanel() = 0;
// Gets the registry name (for saving settings)
virtual const char *GetRegistryName() = 0;
// Shows a particular entity in the entity properties dialog
virtual void ShowEntityInEntityProperties( CDmeCommentaryNodeEntity *pEntity ) = 0;
};
//-----------------------------------------------------------------------------
// Implementation of the CommEdit tool
//-----------------------------------------------------------------------------
class CCommEditTool : public CBaseToolSystem, public IFileMenuCallbacks, public ICommEditDocCallback, public ICommEditTool
{
DECLARE_CLASS_SIMPLE( CCommEditTool, CBaseToolSystem );
public:
CCommEditTool();
// Inherited from IToolSystem
virtual const char *GetToolName() { return "Commentary Editor"; }
virtual bool Init( );
virtual void Shutdown();
virtual bool CanQuit( const char *pExitMsg );
virtual void OnToolActivate();
virtual void OnToolDeactivate();
virtual const char* GetEntityData( const char *pActualEntityData );
virtual void DrawCommentaryNodeEntitiesInEngine( bool bDrawInEngine );
virtual void ClientLevelInitPostEntity();
virtual void ClientLevelShutdownPreEntity();
virtual bool TrapKey( ButtonCode_t key, bool down );
virtual void ClientPreRender();
// Inherited from IFileMenuCallbacks
virtual int GetFileMenuItemsEnabled( );
virtual void AddRecentFilesToMenu( vgui::Menu *menu );
virtual bool GetPerforceFileName( char *pFileName, int nMaxLen );
// Inherited from ICommEditDocCallback
virtual void OnDocChanged( const char *pReason, int nNotifySource, int nNotifyFlags );
virtual vgui::Panel *GetRootPanel() { return this; }
virtual void ShowEntityInEntityProperties( CDmeCommentaryNodeEntity *pEntity );
// Inherited from CBaseToolSystem
virtual vgui::HScheme GetToolScheme();
virtual vgui::Menu *CreateActionMenu( vgui::Panel *pParent );
virtual void OnCommand( const char *cmd );
virtual const char *GetRegistryName() { return "CommEditTool"; }
virtual const char *GetBindingsContextFile() { return "cfg/CommEdit.kb"; }
virtual vgui::MenuBar *CreateMenuBar( CBaseToolSystem *pParent );
MESSAGE_FUNC( Save, "OnSave" );
void SaveAndTest();
void CenterView( CDmeCommentaryNodeEntity* pEntity );
// Enter mode where we preview dropping nodes
void EnterNodeDropMode();
void LeaveNodeDropMode();
public:
MESSAGE_FUNC( OnRestartLevel, "RestartLevel" );
MESSAGE_FUNC( OnNew, "OnNew" );
MESSAGE_FUNC( OnOpen, "OnOpen" );
MESSAGE_FUNC( OnSaveAs, "OnSaveAs" );
MESSAGE_FUNC( OnClose, "OnClose" );
MESSAGE_FUNC( OnCloseNoSave, "OnCloseNoSave" );
MESSAGE_FUNC( OnMarkNotDirty, "OnMarkNotDirty" );
MESSAGE_FUNC( OnExit, "OnExit" );
// Commands related to the edit menu
void OnDescribeUndo();
// Methods related to the CommEdit menu
MESSAGE_FUNC( OnAddNewNodes, "AddNewNodes" );
// Methods related to the view menu
MESSAGE_FUNC( OnToggleProperties, "OnToggleProperties" );
MESSAGE_FUNC( OnToggleEntityReport, "OnToggleEntityReport" );
MESSAGE_FUNC( OnToggleConsole, "ToggleConsole" );
MESSAGE_FUNC( OnDefaultLayout, "OnDefaultLayout" );
// Keybindings
KEYBINDING_FUNC( undo, KEY_Z, vgui::MODIFIER_CONTROL, OnUndo, "#undo_help", 0 );
KEYBINDING_FUNC( redo, KEY_Z, vgui::MODIFIER_CONTROL | vgui::MODIFIER_SHIFT, OnRedo, "#redo_help", 0 );
KEYBINDING_FUNC_NODECLARE( CommEditAddNewNodes, KEY_A, vgui::MODIFIER_CONTROL, OnAddNewNodes, "#CommEditAddNewNodesHelp", 0 );
void PerformNew();
void OpenFileFromHistory( int slot );
void OpenSpecificFile( const char *pFileName );
virtual void SetupFileOpenDialog( vgui::FileOpenDialog *pDialog, bool bOpenFile, const char *pFileFormat, KeyValues *pContextKeyValues );
virtual bool OnReadFileFromDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues );
virtual bool OnWriteFileToDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues );
virtual void OnFileOperationCompleted( const char *pFileType, bool bWroteFile, vgui::FileOpenStateMachine::CompletionState_t state, KeyValues *pContextKeyValues );
void AttachAllEngineEntities();
// returns the document
CCommEditDoc *GetDocument();
// Gets at tool windows
CCommentaryPropertiesPanel *GetProperties();
CCommentaryNodeBrowserPanel *GetCommentaryNodeBrowser();
CConsolePage *GetConsole();
CDmeHandle< CDmeCommentaryNodeEntity > GetCurrentEntity( void ) { return m_hCurrentEntity; }
private:
// Loads up a new document
bool LoadDocument( const char *pDocName );
// Updates the menu bar based on the current file
void UpdateMenuBar( );
// Shows element properties
void ShowElementProperties( );
virtual const char *GetLogoTextureName();
// Creates, destroys tools
void CreateTools( CCommEditDoc *doc );
void DestroyTools();
// Initializes the tools
void InitTools();
// Shows, toggles tool windows
void ToggleToolWindow( Panel *tool, char const *toolName );
void ShowToolWindow( Panel *tool, char const *toolName, bool visible );
// Kills all tool windows
void DestroyToolContainers();
// Gets the position of the preview object
void GetPlacementInfo( Vector &vecOrigin, QAngle &angles );
// Brings the console to front
void BringConsoleToFront();
private:
enum DropNodeMode_t
{
DROP_MODE_COMMENTARY = 0,
DROP_MODE_TARGET,
DROP_MODE_REMARKABLE,
DROP_MODE_COUNT,
};
// Document
CCommEditDoc *m_pDoc;
// The menu bar
CToolFileMenuBar *m_pMenuBar;
// Element properties for editing material
vgui::DHANDLE< CCommentaryPropertiesPanel > m_hProperties;
// The entity report
vgui::DHANDLE< CCommentaryNodeBrowserPanel > m_hCommentaryNodeBrowser;
// The console
vgui::DHANDLE< CConsolePage > m_hConsole;
// The currently viewed entity
CDmeHandle< CDmeCommentaryNodeEntity > m_hCurrentEntity;
// Separate undo context for the act busy tool
bool m_bInNodeDropMode;
DropNodeMode_t m_nDropMode;
CDmeHandle< CDmeCommentaryNodeEntity > m_hPreviewEntity[DROP_MODE_COUNT];
CToolWindowFactory< ToolWindow > m_ToolWindowFactory;
};
extern CCommEditTool *g_pCommEditTool;
#endif // COMMEDITTOOL_H

View File

@@ -0,0 +1,283 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose: Singleton dialog that generates and presents the entity report.
//
//===========================================================================//
#include "CommentaryNodeBrowserPanel.h"
#include "tier1/keyvalues.h"
#include "tier1/utlbuffer.h"
#include "iregistry.h"
#include "vgui/ivgui.h"
#include "vgui_controls/listpanel.h"
#include "vgui_controls/textentry.h"
#include "vgui_controls/checkbutton.h"
#include "vgui_controls/combobox.h"
#include "vgui_controls/radiobutton.h"
#include "vgui_controls/messagebox.h"
#include "commeditdoc.h"
#include "commedittool.h"
#include "datamodel/dmelement.h"
#include "vgui/keycode.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
using namespace vgui;
//-----------------------------------------------------------------------------
// Sort by target name
//-----------------------------------------------------------------------------
static int __cdecl TargetNameSortFunc( vgui::ListPanel *pPanel, const ListPanelItem &item1, const ListPanelItem &item2 )
{
const char *string1 = item1.kv->GetString("targetname");
const char *string2 = item2.kv->GetString("targetname");
int nRetVal = Q_stricmp( string1, string2 );
if ( nRetVal != 0 )
return nRetVal;
string1 = item1.kv->GetString("classname");
string2 = item2.kv->GetString("classname");
return Q_stricmp( string1, string2 );
}
//-----------------------------------------------------------------------------
// Sort by class name
//-----------------------------------------------------------------------------
static int __cdecl ClassNameSortFunc( vgui::ListPanel *pPanel, const ListPanelItem &item1, const ListPanelItem &item2 )
{
const char *string1 = item1.kv->GetString("classname");
const char *string2 = item2.kv->GetString("classname");
int nRetVal = Q_stricmp( string1, string2 );
if ( nRetVal != 0 )
return nRetVal;
string1 = item1.kv->GetString("targetname");
string2 = item2.kv->GetString("targetname");
return Q_stricmp( string1, string2 );
}
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CCommentaryNodeBrowserPanel::CCommentaryNodeBrowserPanel( CCommEditDoc *pDoc, vgui::Panel* pParent, const char *pName )
: BaseClass( pParent, pName ), m_pDoc( pDoc )
{
SetPaintBackgroundEnabled( true );
m_pEntities = new vgui::ListPanel( this, "Entities" );
m_pEntities->AddColumnHeader( 0, "targetname", "Name", 52, ListPanel::COLUMN_RESIZEWITHWINDOW );
m_pEntities->AddColumnHeader( 1, "classname", "Class Name", 52, ListPanel::COLUMN_RESIZEWITHWINDOW );
m_pEntities->SetColumnSortable( 0, true );
m_pEntities->SetColumnSortable( 1, true );
m_pEntities->SetEmptyListText( "No Entities" );
// m_pEntities->SetDragEnabled( true );
m_pEntities->AddActionSignalTarget( this );
m_pEntities->SetSortFunc( 0, TargetNameSortFunc );
m_pEntities->SetSortFunc( 1, ClassNameSortFunc );
m_pEntities->SetSortColumn( 0 );
LoadControlSettingsAndUserConfig( "resource/commentarynodebrowserpanel.res" );
UpdateEntityList();
}
CCommentaryNodeBrowserPanel::~CCommentaryNodeBrowserPanel()
{
SaveUserConfig();
}
//-----------------------------------------------------------------------------
// Purpose: Shows the most recent selected object in properties window
//-----------------------------------------------------------------------------
void CCommentaryNodeBrowserPanel::OnProperties( )
{
if ( m_pEntities->GetSelectedItemsCount() == 0 )
{
g_pCommEditTool->ShowEntityInEntityProperties( NULL );
return;
}
int iSel = m_pEntities->GetSelectedItem( 0 );
KeyValues *kv = m_pEntities->GetItem( iSel );
CDmeCommentaryNodeEntity *pEntity = CastElement< CDmeCommentaryNodeEntity >( (CDmElement *)kv->GetPtr( "entity" ) );
g_pCommEditTool->ShowEntityInEntityProperties( pEntity );
}
//-----------------------------------------------------------------------------
// Purpose: Deletes the marked objects.
//-----------------------------------------------------------------------------
void CCommentaryNodeBrowserPanel::OnDeleteEntities(void)
{
int iSel = m_pEntities->GetSelectedItem( 0 );
{
// This is undoable
CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, "Delete Entities", "Delete Entities" );
//
// Build a list of objects to delete.
//
int nCount = m_pEntities->GetSelectedItemsCount();
for (int i = 0; i < nCount; i++)
{
int nItemID = m_pEntities->GetSelectedItem(i);
KeyValues *kv = m_pEntities->GetItem( nItemID );
CDmElement *pEntity = (CDmElement *)kv->GetPtr( "entity" );
if ( pEntity )
{
m_pDoc->DeleteCommentaryNode( pEntity );
}
}
}
// Update the list box selection.
if (iSel >= m_pEntities->GetItemCount())
{
iSel = m_pEntities->GetItemCount() - 1;
}
m_pEntities->SetSingleSelectedItem( iSel );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCommentaryNodeBrowserPanel::OnKeyCodeTyped( vgui::KeyCode code )
{
if ( code == KEY_DELETE )
{
OnDeleteEntities();
}
else
{
BaseClass::OnKeyCodeTyped( code );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCommentaryNodeBrowserPanel::OnItemSelected( void )
{
OnProperties();
}
//-----------------------------------------------------------------------------
// Select a particular node
//-----------------------------------------------------------------------------
void CCommentaryNodeBrowserPanel::SelectNode( CDmeCommentaryNodeEntity *pNode )
{
m_pEntities->ClearSelectedItems();
for ( int nItemID = m_pEntities->FirstItem(); nItemID != m_pEntities->InvalidItemID(); nItemID = m_pEntities->NextItem( nItemID ) )
{
KeyValues *kv = m_pEntities->GetItem( nItemID );
CDmElement *pEntity = (CDmElement *)kv->GetPtr( "entity" );
if ( pEntity == pNode )
{
m_pEntities->AddSelectedItem( nItemID );
break;
}
}
}
//-----------------------------------------------------------------------------
// Called when buttons are clicked
//-----------------------------------------------------------------------------
void CCommentaryNodeBrowserPanel::OnCommand( const char *pCommand )
{
if ( !Q_stricmp( pCommand, "delete" ) )
{
// Confirm we want to do it
MessageBox *pConfirm = new MessageBox( "#CommEditDeleteObjects", "#CommEditDeleteObjectsMsg", g_pCommEditTool->GetRootPanel() );
pConfirm->AddActionSignalTarget( this );
pConfirm->SetOKButtonText( "Yes" );
pConfirm->SetCommand( new KeyValues( "DeleteEntities" ) );
pConfirm->SetCancelButtonVisible( true );
pConfirm->SetCancelButtonText( "No" );
pConfirm->DoModal();
return;
}
if ( !Q_stricmp( pCommand, "Save" ) )
{
g_pCommEditTool->Save();
return;
}
if ( !Q_stricmp( pCommand, "CenterView" ) )
{
if ( m_pEntities->GetSelectedItemsCount() == 1 )
{
int iSel = m_pEntities->GetSelectedItem( 0 );
KeyValues *kv = m_pEntities->GetItem( iSel );
CDmeCommentaryNodeEntity *pEntity = CastElement< CDmeCommentaryNodeEntity >( (CDmElement *)kv->GetPtr( "entity" ) );
g_pCommEditTool->CenterView( pEntity );
}
return;
}
if ( !Q_stricmp( pCommand, "SaveAndTest" ) )
{
g_pCommEditTool->SaveAndTest();
return;
}
if ( !Q_stricmp( pCommand, "DropNodes" ) )
{
g_pCommEditTool->EnterNodeDropMode();
return;
}
BaseClass::OnCommand( pCommand );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCommentaryNodeBrowserPanel::UpdateEntityList(void)
{
m_pEntities->RemoveAll();
CDmrCommentaryNodeEntityList entityList( m_pDoc->GetEntityList() );
if ( !entityList.IsValid() )
return;
int nCount = entityList.Count();
for ( int i = 0; i < nCount; ++i )
{
CDmElement *pEntity = entityList[i];
Assert( pEntity );
if ( !pEntity )
continue;
const char *pClassName = pEntity->GetValueString( "classname" );
if ( !pClassName || !pClassName[0] )
{
pClassName = "<no class>";
}
KeyValues *kv = new KeyValues( "node" );
kv->SetString( "classname", pClassName );
kv->SetPtr( "entity", pEntity );
const char *pTargetname = pEntity->GetValueString( "targetname" );
if ( !pTargetname || !pTargetname[0] )
{
pTargetname = "<no targetname>";
}
kv->SetString( "targetname", pTargetname );
m_pEntities->AddItem( kv, 0, false, false );
}
m_pEntities->SortList();
}

View File

@@ -0,0 +1,67 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
//===========================================================================//
#ifndef COMMENTARYNODEBROWSERPANEL_H
#define COMMENTARYNODEBROWSERPANEL_H
#ifdef _WIN32
#pragma once
#endif
#include "vgui_controls/editablepanel.h"
#include "tier1/utlstring.h"
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class CCommEditDoc;
class CDmeCommentaryNodeEntity;
namespace vgui
{
class ComboBox;
class Button;
class TextEntry;
class ListPanel;
class CheckButton;
class RadioButton;
}
//-----------------------------------------------------------------------------
// Panel that shows all entities in the level
//-----------------------------------------------------------------------------
class CCommentaryNodeBrowserPanel : public vgui::EditablePanel
{
DECLARE_CLASS_SIMPLE( CCommentaryNodeBrowserPanel, vgui::EditablePanel );
public:
CCommentaryNodeBrowserPanel( CCommEditDoc *pDoc, vgui::Panel* pParent, const char *pName ); // standard constructor
virtual ~CCommentaryNodeBrowserPanel();
// Inherited from Panel
virtual void OnCommand( const char *pCommand );
virtual void OnKeyCodeTyped( vgui::KeyCode code );
// Methods related to updating the listpanel
void UpdateEntityList();
// Select a particular node
void SelectNode( CDmeCommentaryNodeEntity *pNode );
private:
// Messages handled
MESSAGE_FUNC( OnDeleteEntities, "DeleteEntities" );
MESSAGE_FUNC( OnItemSelected, "ItemSelected" );
// Shows the most recent selected object in properties window
void OnProperties();
CCommEditDoc *m_pDoc;
vgui::ListPanel *m_pEntities;
};
#endif // COMMENTARYNODEBROWSERPANEL_H

View File

@@ -0,0 +1,530 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose: Singleton dialog that generates and presents the entity report.
//
//===========================================================================//
#include "CommentaryPropertiesPanel.h"
#include "tier1/keyvalues.h"
#include "tier1/utlbuffer.h"
#include "iregistry.h"
#include "vgui/ivgui.h"
#include "vgui_controls/listpanel.h"
#include "vgui_controls/textentry.h"
#include "vgui_controls/checkbutton.h"
#include "vgui_controls/combobox.h"
#include "vgui_controls/radiobutton.h"
#include "vgui_controls/messagebox.h"
#include "vgui_controls/scrollbar.h"
#include "vgui_controls/scrollableeditablepanel.h"
#include "commeditdoc.h"
#include "commedittool.h"
#include "datamodel/dmelement.h"
#include "dmecommentarynodeentity.h"
#include "dme_controls/soundpicker.h"
#include "dme_controls/soundrecordpanel.h"
#include "matsys_controls/picker.h"
#include "vgui_controls/fileopendialog.h"
#include "filesystem.h"
#include "tier2/fileutils.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
using namespace vgui;
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CCommentaryPropertiesPanel::CCommentaryPropertiesPanel( CCommEditDoc *pDoc, vgui::Panel* pParent )
: BaseClass( pParent, "CommentaryPropertiesPanel" ), m_pDoc( pDoc )
{
SetPaintBackgroundEnabled( true );
SetKeyBoardInputEnabled( true );
m_pCommentaryNode = new vgui::EditablePanel( (vgui::Panel*)NULL, "CommentaryNode" );
m_pNodeName = new vgui::TextEntry( m_pCommentaryNode, "CommentaryNodeName" );
m_pNodeName->AddActionSignalTarget( this );
m_pSoundFilePicker = new vgui::Button( m_pCommentaryNode, "AudioFilePickerButton", "", this, "PickSound" );
m_pSoundFileName = new vgui::TextEntry( m_pCommentaryNode, "AudioFileName" );
m_pSoundFileName->AddActionSignalTarget( this );
m_pRecordSound = new vgui::Button( m_pCommentaryNode, "RecordAudioButton", "", this, "Record" );
m_pSpeakerName = new vgui::TextEntry( m_pCommentaryNode, "Speaker" );
m_pSpeakerName->AddActionSignalTarget( this );
m_pSynopsis = new vgui::TextEntry( m_pCommentaryNode, "Synopsis" );
m_pSynopsis->AddActionSignalTarget( this );
m_pViewPositionPicker = new vgui::Button( m_pCommentaryNode, "ViewPositionPickerButton", "", this, "PickViewPosition" );
m_pViewTargetPicker = new vgui::Button( m_pCommentaryNode, "ViewTargetPickerButton", "", this, "PickViewTarget" );
m_pViewPosition = new vgui::TextEntry( m_pCommentaryNode, "ViewPosition" );
m_pViewPosition->AddActionSignalTarget( this );
m_pViewTarget = new vgui::TextEntry( m_pCommentaryNode, "ViewTarget" );
m_pViewTarget->AddActionSignalTarget( this );
m_pPreventMovement = new vgui::CheckButton( m_pCommentaryNode, "PreventMovement", "" );
m_pPreventMovement->SetCommand( "PreventMovementClicked" );
m_pPreventMovement->AddActionSignalTarget( this );
m_pStartCommands = new vgui::TextEntry( m_pCommentaryNode, "StartCommands" );
m_pStartCommands->AddActionSignalTarget( this );
m_pEndCommands = new vgui::TextEntry( m_pCommentaryNode, "EndCommands" );
m_pEndCommands->AddActionSignalTarget( this );
m_pPosition[0] = new vgui::TextEntry( m_pCommentaryNode, "PositionX" );
m_pPosition[0]->AddActionSignalTarget( this );
m_pPosition[1] = new vgui::TextEntry( m_pCommentaryNode, "PositionY" );
m_pPosition[1]->AddActionSignalTarget( this );
m_pPosition[2] = new vgui::TextEntry( m_pCommentaryNode, "PositionZ" );
m_pPosition[2]->AddActionSignalTarget( this );
m_pOrientation[0] = new vgui::TextEntry( m_pCommentaryNode, "Pitch" );
m_pOrientation[0]->AddActionSignalTarget( this );
m_pOrientation[1] = new vgui::TextEntry( m_pCommentaryNode, "Yaw" );
m_pOrientation[1]->AddActionSignalTarget( this );
m_pOrientation[2] = new vgui::TextEntry( m_pCommentaryNode, "Roll" );
m_pOrientation[2]->AddActionSignalTarget( this );
m_pCommentaryNode->LoadControlSettings( "resource/commentarypropertiessubpanel_node.res" );
m_pInfoTarget = new vgui::EditablePanel( (vgui::Panel*)NULL, "InfoTarget" );
m_pTargetName = new vgui::TextEntry( m_pInfoTarget, "TargetName" );
m_pTargetName->AddActionSignalTarget( this );
m_pTargetPosition[0] = new vgui::TextEntry( m_pInfoTarget, "PositionX" );
m_pTargetPosition[0]->AddActionSignalTarget( this );
m_pTargetPosition[1] = new vgui::TextEntry( m_pInfoTarget, "PositionY" );
m_pTargetPosition[1]->AddActionSignalTarget( this );
m_pTargetPosition[2] = new vgui::TextEntry( m_pInfoTarget, "PositionZ" );
m_pTargetPosition[2]->AddActionSignalTarget( this );
m_pTargetOrientation[0] = new vgui::TextEntry( m_pInfoTarget, "Pitch" );
m_pTargetOrientation[0]->AddActionSignalTarget( this );
m_pTargetOrientation[1] = new vgui::TextEntry( m_pInfoTarget, "Yaw" );
m_pTargetOrientation[1]->AddActionSignalTarget( this );
m_pTargetOrientation[2] = new vgui::TextEntry( m_pInfoTarget, "Roll" );
m_pTargetOrientation[2]->AddActionSignalTarget( this );
m_pInfoTarget->LoadControlSettings( "resource/commentarypropertiessubpanel_target.res" );
m_pInfoRemarkable = new vgui::EditablePanel( (vgui::Panel*)NULL, "InfoRemarkable" );
m_pInfoRemarkableName = new vgui::TextEntry( m_pInfoRemarkable, "RemarkableName" );
m_pInfoRemarkableName->AddActionSignalTarget( this );
m_pRemarkablePosition[0] = new vgui::TextEntry( m_pInfoRemarkable, "PositionX" );
m_pRemarkablePosition[0]->AddActionSignalTarget( this );
m_pRemarkablePosition[1] = new vgui::TextEntry( m_pInfoRemarkable, "PositionY" );
m_pRemarkablePosition[1]->AddActionSignalTarget( this );
m_pRemarkablePosition[2] = new vgui::TextEntry( m_pInfoRemarkable, "PositionZ" );
m_pRemarkablePosition[2]->AddActionSignalTarget( this );
m_pInfoRemarkableSubject = new vgui::TextEntry( m_pInfoRemarkable, "RemarkableSubject" );
m_pInfoRemarkableSubject->AddActionSignalTarget( this );
m_pInfoRemarkable->LoadControlSettings( "resource/commentarypropertiessubpanel_remarkable.res" );
m_pCommentaryNodeScroll = new vgui::ScrollableEditablePanel( this, m_pCommentaryNode, "CommentaryNodeScroll" );
m_pInfoTargetScroll = new vgui::ScrollableEditablePanel( this, m_pInfoTarget, "InfoTargetScroll" );
m_pInfoRemarkableScroll = new vgui::ScrollableEditablePanel( this, m_pInfoRemarkable, "InfoRemarkableScroll" );
LoadControlSettings( "resource/commentarypropertiespanel.res" );
m_pCommentaryNodeScroll->SetVisible( false );
m_pInfoTargetScroll->SetVisible( false );
m_pInfoRemarkableScroll->SetVisible( false );
}
//-----------------------------------------------------------------------------
// Text to attribute...
//-----------------------------------------------------------------------------
void CCommentaryPropertiesPanel::TextEntryToAttribute( vgui::TextEntry *pEntry, const char *pAttributeName )
{
int nLen = pEntry->GetTextLength();
char *pBuf = (char*)_alloca( nLen+1 );
pEntry->GetText( pBuf, nLen+1 );
m_hEntity->SetValue( pAttributeName, pBuf );
}
void CCommentaryPropertiesPanel::TextEntriesToVector( vgui::TextEntry *pEntry[3], const char *pAttributeName )
{
CUtlVectorFixedGrowable< char, 256 > buf;
Vector vec;
for ( int i = 0; i < 3; ++i )
{
int nLen = pEntry[i]->GetTextLength();
buf.EnsureCount( nLen + 1 );
pEntry[i]->GetText( buf.Base(), nLen+1 );
vec[i] = atof( buf.Base() );
}
m_hEntity->SetValue( pAttributeName, vec );
clienttools->MarkClientRenderableDirty( m_hEntity );
}
//-----------------------------------------------------------------------------
// Updates entity state when text fields change
//-----------------------------------------------------------------------------
void CCommentaryPropertiesPanel::UpdateCommentaryNode()
{
if ( !m_hEntity.Get() )
return;
CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, "Commentary Node Change", "Commentary Node Change" );
TextEntryToAttribute( m_pNodeName, "targetname" );
TextEntryToAttribute( m_pStartCommands, "precommands" );
TextEntryToAttribute( m_pEndCommands, "postcommands" );
TextEntryToAttribute( m_pViewPosition, "viewposition" );
TextEntryToAttribute( m_pViewTarget, "viewtarget" );
TextEntryToAttribute( m_pSynopsis, "synopsis" );
TextEntryToAttribute( m_pSpeakerName, "speakers" );
TextEntryToAttribute( m_pSoundFileName, "commentaryfile" );
TextEntriesToVector( m_pPosition, "origin" );
TextEntriesToVector( m_pOrientation, "angles" );
m_hEntity->SetValue<int>( "prevent_movement", m_pPreventMovement->IsSelected() ? 1 : 0 );
m_hEntity->MarkDirty();
}
void CCommentaryPropertiesPanel::UpdateInfoTarget()
{
if ( !m_hEntity.Get() )
return;
CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, "Info Target Change", "Info Target Change" );
TextEntryToAttribute( m_pTargetName, "targetname" );
TextEntriesToVector( m_pTargetPosition, "origin" );
TextEntriesToVector( m_pTargetOrientation, "angles" );
m_hEntity->MarkDirty();
}
void CCommentaryPropertiesPanel::UpdateInfoRemarkable()
{
if ( !m_hEntity.Get() )
return;
CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, "Info Remarkable Change", "Info Remarkable Change" );
TextEntryToAttribute( m_pInfoRemarkableName, "targetname" );
TextEntryToAttribute( m_pInfoRemarkableSubject, "contextsubject" );
TextEntriesToVector( m_pRemarkablePosition, "origin" );
m_hEntity->MarkDirty();
}
//-----------------------------------------------------------------------------
// Populates the commentary node fields
//-----------------------------------------------------------------------------
void CCommentaryPropertiesPanel::PopulateCommentaryNodeFields()
{
if ( !m_hEntity.Get() )
return;
m_pNodeName->SetText( m_hEntity->GetTargetName() );
m_pStartCommands->SetText( m_hEntity->GetValueString( "precommands" ) );
m_pEndCommands->SetText( m_hEntity->GetValueString( "postcommands" ) );
m_pViewPosition->SetText( m_hEntity->GetValueString( "viewposition" ) );
m_pViewTarget->SetText( m_hEntity->GetValueString( "viewtarget" ) );
m_pSynopsis->SetText( m_hEntity->GetValueString( "synopsis" ) );
m_pSpeakerName->SetText( m_hEntity->GetValueString( "speakers" ) );
m_pSoundFileName->SetText( m_hEntity->GetValueString( "commentaryfile" ) );
Vector vecPosition = m_hEntity->GetRenderOrigin();
QAngle vecAngles = m_hEntity->GetRenderAngles();
for ( int i = 0; i < 3; ++i )
{
char pTemp[512];
Q_snprintf( pTemp, sizeof(pTemp), "%.2f", vecPosition[i] );
m_pPosition[i]->SetText( pTemp );
Q_snprintf( pTemp, sizeof(pTemp), "%.2f", vecAngles[i] );
m_pOrientation[i]->SetText( pTemp );
}
m_pPreventMovement->SetSelected( m_hEntity->GetValue<int>( "prevent_movement" ) != 0 );
}
//-----------------------------------------------------------------------------
// Populates the info_target fields
//-----------------------------------------------------------------------------
void CCommentaryPropertiesPanel::PopulateInfoTargetFields()
{
if ( !m_hEntity.Get() )
return;
m_pTargetName->SetText( m_hEntity->GetTargetName() );
Vector vecPosition = m_hEntity->GetRenderOrigin();
QAngle vecAngles = m_hEntity->GetRenderAngles();
for ( int i = 0; i < 3; ++i )
{
char pTemp[512];
Q_snprintf( pTemp, sizeof(pTemp), "%.2f", vecPosition[i] );
m_pTargetPosition[i]->SetText( pTemp );
Q_snprintf( pTemp, sizeof(pTemp), "%.2f", vecAngles[i] );
m_pTargetOrientation[i]->SetText( pTemp );
}
}
//-----------------------------------------------------------------------------
// Populates the info_target fields
//-----------------------------------------------------------------------------
void CCommentaryPropertiesPanel::PopulateInfoRemarkableFields()
{
if ( !m_hEntity.Get() )
return;
m_pInfoRemarkableName->SetText( m_hEntity->GetTargetName() );
Vector vecPosition = m_hEntity->GetRenderOrigin();
QAngle vecAngles = m_hEntity->GetRenderAngles();
for ( int i = 0; i < 3; ++i )
{
char pTemp[512];
Q_snprintf( pTemp, sizeof(pTemp), "%.2f", vecPosition[i] );
m_pRemarkablePosition[i]->SetText( pTemp );
}
m_pInfoRemarkableSubject->SetText( m_hEntity->GetValueString( "contextsubject" ) );
}
//-----------------------------------------------------------------------------
// Sets the object to look at
//-----------------------------------------------------------------------------
void CCommentaryPropertiesPanel::SetObject( CDmeCommentaryNodeEntity *pEntity )
{
m_hEntity = pEntity;
m_pCommentaryNodeScroll->SetVisible( false );
m_pInfoTargetScroll->SetVisible( false );
m_pInfoRemarkableScroll->SetVisible( false );
if ( pEntity )
{
if ( !Q_stricmp( pEntity->GetClassName(), "info_target" ) )
{
PopulateInfoTargetFields();
m_pInfoTargetScroll->SetVisible( true );
m_pTargetName->RequestFocus();
return;
}
if ( !Q_stricmp( pEntity->GetClassName(), "info_remarkable" ) )
{
PopulateInfoRemarkableFields();
m_pInfoRemarkableScroll->SetVisible( true );
m_pInfoRemarkableName->RequestFocus();
return;
}
if ( !Q_stricmp( pEntity->GetClassName(), "point_commentary_node" ) )
{
PopulateCommentaryNodeFields();
m_pCommentaryNodeScroll->SetVisible( true );
m_pNodeName->RequestFocus();
return;
}
}
}
//-----------------------------------------------------------------------------
// Called when text is changed
//-----------------------------------------------------------------------------
void CCommentaryPropertiesPanel::OnTextChanged( KeyValues *pParams )
{
vgui::Panel *pPanel = (vgui::Panel*)pParams->GetPtr( "panel" );
if ( pPanel->GetParent() == m_pCommentaryNode )
{
UpdateCommentaryNode();
return;
}
if ( pPanel->GetParent() == m_pInfoTarget )
{
UpdateInfoTarget();
return;
}
if ( pPanel->GetParent() == m_pInfoRemarkable )
{
UpdateInfoRemarkable();
return;
}
}
//-----------------------------------------------------------------------------
// Called when the audio picker has picked something
//-----------------------------------------------------------------------------
void CCommentaryPropertiesPanel::OnSoundSelected( KeyValues *pParams )
{
const char *pAssetName = pParams->GetString( "wav" );
m_pSoundFileName->SetText( pAssetName );
UpdateCommentaryNode();
}
//-----------------------------------------------------------------------------
// Called when the audio picker button is selected
//-----------------------------------------------------------------------------
void CCommentaryPropertiesPanel::PickSound()
{
CSoundPickerFrame *pSoundPickerDialog = new CSoundPickerFrame( g_pCommEditTool->GetRootPanel(), "Select commentary audio file", CSoundPicker::PICK_WAVFILES );
pSoundPickerDialog->AddActionSignalTarget( this );
pSoundPickerDialog->DoModal( CSoundPicker::PICK_NONE, NULL );
}
//-----------------------------------------------------------------------------
// Called when the string picker has picked something
//-----------------------------------------------------------------------------
void CCommentaryPropertiesPanel::OnPicked( KeyValues *pParams )
{
const char *pInfoTargetName = pParams->GetString( "choice" );
KeyValues *pContextKeyValues = pParams->FindKey( "context" );
vgui::TextEntry *pTextEntry = (vgui::TextEntry *)pContextKeyValues->GetPtr( "widget" );
pTextEntry->SetText( pInfoTargetName );
UpdateCommentaryNode();
}
//-----------------------------------------------------------------------------
// Called when the audio picker button is selected
//-----------------------------------------------------------------------------
void CCommentaryPropertiesPanel::PickInfoTarget( vgui::TextEntry *pControl )
{
CDmrCommentaryNodeEntityList entities( m_pDoc->GetEntityList() );
int nCount = entities.Count();
PickerList_t vec( 0, nCount+1 );
int j = vec.AddToTail( );
vec[j].m_pChoiceString = "<no target>";
vec[j].m_pChoiceValue = "";
for ( int i = 0; i < nCount; ++i )
{
CDmeCommentaryNodeEntity *pNode = entities[ i ];
const char *pTargetName = pNode->GetTargetName();
if ( !pTargetName || !pTargetName[0] )
continue;
if ( !Q_stricmp( pNode->GetClassName(), "info_target" ) )
{
j = vec.AddToTail( );
vec[j].m_pChoiceString = pTargetName;
vec[j].m_pChoiceValue = pTargetName;
}
}
CPickerFrame *pInfoTargetPickerDialog = new CPickerFrame( g_pCommEditTool->GetRootPanel(), "Select Target", "InfoTarget", NULL );
KeyValues *pContextKeyValues = new KeyValues( "context" );
pContextKeyValues->SetPtr( "widget", pControl );
pInfoTargetPickerDialog->AddActionSignalTarget( this );
pInfoTargetPickerDialog->DoModal( vec, pContextKeyValues );
}
//-----------------------------------------------------------------------------
// Called when a sound is successfully recorded
//-----------------------------------------------------------------------------
void CCommentaryPropertiesPanel::OnSoundRecorded( KeyValues *pKeyValues )
{
const char *pFileName = pKeyValues->GetString( "relativepath" );
m_pSoundFileName->SetText( pFileName );
UpdateCommentaryNode();
}
//-----------------------------------------------------------------------------
// Used to open a particular file in perforce, and deal with all the lovely dialogs
//-----------------------------------------------------------------------------
void CCommentaryPropertiesPanel::OnFileSelected( KeyValues *pKeyValues )
{
const char *pFileName = pKeyValues->GetString( "fullpath" );
if ( g_pFileSystem->FileExists( pFileName ) )
{
char pBuf[1024];
Q_snprintf( pBuf, sizeof(pBuf), "File %s already exists!\nRecording audio will not overwrite existing files.", pFileName );
vgui::MessageBox *pMessageBox = new vgui::MessageBox( "File already Exists!\n", pBuf, g_pCommEditTool );
pMessageBox->DoModal( );
return;
}
CSoundRecordPanel *pSoundRecordPanel = new CSoundRecordPanel( g_pCommEditTool->GetRootPanel(), "Record Commentary" );
pSoundRecordPanel->AddActionSignalTarget( this );
pSoundRecordPanel->DoModal( pFileName );
}
//-----------------------------------------------------------------------------
// Called when sound recording is requested
//-----------------------------------------------------------------------------
void CCommentaryPropertiesPanel::RecordSound( )
{
char pStartingDir[ MAX_PATH ];
GetModSubdirectory( "sound", pStartingDir, sizeof(pStartingDir) );
vgui::FileOpenDialog *pDialog = new vgui::FileOpenDialog( this, "Save As", false );
pDialog->SetTitle( "Enter New Audio File", true );
pDialog->SetStartDirectoryContext( "commedit_audio_record", pStartingDir );
pDialog->AddFilter( "*.wav", "Audio File (*.wav)", true );
pDialog->AddActionSignalTarget( this );
pDialog->DoModal( true );
}
//-----------------------------------------------------------------------------
// Called when buttons are clicked
//-----------------------------------------------------------------------------
void CCommentaryPropertiesPanel::OnCommand( const char *pCommand )
{
if ( !Q_stricmp( pCommand, "PickSound" ) )
{
PickSound();
return;
}
if ( !Q_stricmp( pCommand, "Record" ) )
{
RecordSound();
return;
}
if ( !Q_stricmp( pCommand, "PickViewPosition" ) )
{
PickInfoTarget( m_pViewPosition );
return;
}
if ( !Q_stricmp( pCommand, "PickViewTarget" ) )
{
PickInfoTarget( m_pViewTarget );
return;
}
if ( !Q_stricmp( pCommand, "PreventMovementClicked" ) )
{
UpdateCommentaryNode();
return;
}
BaseClass::OnCommand( pCommand );
}

View File

@@ -0,0 +1,123 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
//===========================================================================//
#ifndef COMMENTARYPROPERTIESPANEL_H
#define COMMENTARYPROPERTIESPANEL_H
#ifdef _WIN32
#pragma once
#endif
#include "vgui_controls/editablepanel.h"
#include "tier1/utlstring.h"
#include "datamodel/dmehandle.h"
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class CCommEditDoc;
class CDmeCommentaryNodeEntity;
namespace vgui
{
class ComboBox;
class Button;
class TextEntry;
class ListPanel;
class CheckButton;
class RadioButton;
}
//-----------------------------------------------------------------------------
// Panel that shows all entities in the level
//-----------------------------------------------------------------------------
class CCommentaryPropertiesPanel : public vgui::EditablePanel
{
DECLARE_CLASS_SIMPLE( CCommentaryPropertiesPanel, vgui::EditablePanel );
public:
CCommentaryPropertiesPanel( CCommEditDoc *pDoc, vgui::Panel* pParent ); // standard constructor
// Inherited from Panel
virtual void OnCommand( const char *pCommand );
// Sets the object to look at
void SetObject( CDmeCommentaryNodeEntity *pEntity );
private:
// Populates the commentary node fields
void PopulateCommentaryNodeFields();
// Populates the info_target fields
void PopulateInfoTargetFields();
// Populates the info_remarkable fields
void PopulateInfoRemarkableFields();
// Text to attribute...
void TextEntryToAttribute( vgui::TextEntry *pEntry, const char *pAttributeName );
void TextEntriesToVector( vgui::TextEntry *pEntry[3], const char *pAttributeName );
// Updates entity state when text fields change
void UpdateCommentaryNode();
void UpdateInfoTarget();
void UpdateInfoRemarkable();
// Called when the audio picker button is selected
void PickSound();
// Called when sound recording is requested
void RecordSound( );
// Called when the audio picker button is selected
void PickInfoTarget( vgui::TextEntry *pControl );
// Messages handled
MESSAGE_FUNC_PARAMS( OnTextChanged, "TextChanged", kv );
MESSAGE_FUNC_PARAMS( OnSoundSelected, "SoundSelected", kv );
MESSAGE_FUNC_PARAMS( OnPicked, "Picked", kv );
MESSAGE_FUNC_PARAMS( OnFileSelected, "FileSelected", kv );
MESSAGE_FUNC_PARAMS( OnSoundRecorded, "SoundRecorded", kv );
CCommEditDoc *m_pDoc;
vgui::EditablePanel *m_pCommentaryNodeScroll;
vgui::EditablePanel *m_pInfoTargetScroll;
vgui::EditablePanel *m_pInfoRemarkableScroll;
vgui::EditablePanel *m_pCommentaryNode;
vgui::EditablePanel *m_pInfoTarget;
vgui::EditablePanel *m_pInfoRemarkable;
vgui::TextEntry *m_pNodeName;
vgui::Button *m_pSoundFilePicker;
vgui::TextEntry *m_pSoundFileName;
vgui::Button *m_pRecordSound;
vgui::TextEntry *m_pSpeakerName;
vgui::TextEntry *m_pSynopsis;
vgui::TextEntry *m_pViewPosition;
vgui::Button *m_pViewPositionPicker;
vgui::TextEntry *m_pViewTarget;
vgui::Button *m_pViewTargetPicker;
vgui::TextEntry *m_pStartCommands;
vgui::TextEntry *m_pEndCommands;
vgui::CheckButton *m_pPreventMovement;
vgui::TextEntry *m_pPosition[3];
vgui::TextEntry *m_pOrientation[3];
vgui::TextEntry *m_pTargetName;
vgui::TextEntry *m_pTargetPosition[3];
vgui::TextEntry *m_pTargetOrientation[3];
vgui::TextEntry *m_pInfoRemarkableName;
vgui::TextEntry *m_pInfoRemarkableSubject;
vgui::TextEntry *m_pRemarkablePosition[3];
CDmeHandle< CDmeCommentaryNodeEntity > m_hEntity;
};
#endif // COMMENTARYPROPERTIESPANEL_H

View File

@@ -0,0 +1,343 @@
//====== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. =======
//
// Purpose:
//
//=============================================================================
#include "dmecommentarynodeentity.h"
#include "datamodel/dmelementfactoryhelper.h"
#include "toolframework/itoolentity.h"
#include "materialsystem/imesh.h"
#include "materialsystem/imaterial.h"
#include "materialsystem/imaterialsystem.h"
#include "engine/iclientleafsystem.h"
#include "toolutils/enginetools_int.h"
#include "commedittool.h"
#include "keyvalues.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
#define SPHERE_RADIUS 16
//-----------------------------------------------------------------------------
// Expose this class to the scene database
//-----------------------------------------------------------------------------
IMPLEMENT_ELEMENT_FACTORY( DmeCommentaryNodeEntity, CDmeCommentaryNodeEntity );
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CDmeCommentaryNodeEntity::OnConstruction()
{
m_ClassName.InitAndSet( this, "classname", false, FATTRIB_HAS_CALLBACK );
m_TargetName.Init( this, "targetname" );
m_bIsPlaceholder.InitAndSet( this, "_placeholder", false, FATTRIB_DONTSAVE );
m_vecLocalOrigin.Init( this, "origin" );
m_vecLocalAngles.Init( this, "angles" );
// Used to make sure these aren't saved if they aren't changed
m_TargetName.GetAttribute()->AddFlag( FATTRIB_DONTSAVE | FATTRIB_HAS_CALLBACK );
m_vecLocalAngles.GetAttribute()->AddFlag( FATTRIB_DONTSAVE | FATTRIB_HAS_CALLBACK );
m_bInfoTarget = false;
m_bIsDirty = false;
m_hEngineEntity = HTOOLHANDLE_INVALID;
KeyValues *pVMTKeyValues = new KeyValues( "UnlitGeneric" );
pVMTKeyValues->SetString( "$basetexture", "editor/info_target" );
pVMTKeyValues->SetInt( "$nocull", 1 );
pVMTKeyValues->SetInt( "$vertexcolor", 1 );
pVMTKeyValues->SetInt( "$vertexalpha", 1 );
pVMTKeyValues->SetInt( "$no_fullbright", 1 );
pVMTKeyValues->SetInt( "$translucent", 1 );
m_InfoTargetSprite.Init( "__commentary_info_target", pVMTKeyValues );
pVMTKeyValues = new KeyValues( "UnlitGeneric" );
pVMTKeyValues->SetInt( "$nocull", 1 );
pVMTKeyValues->SetString( "$color", "{255 0 0}" );
pVMTKeyValues->SetInt( "$vertexalpha", 1 );
pVMTKeyValues->SetInt( "$no_fullbright", 1 );
pVMTKeyValues->SetInt( "$additive", 1 );
m_SelectedInfoTarget.Init( "__selected_commentary_info_target", pVMTKeyValues );
}
void CDmeCommentaryNodeEntity::OnDestruction()
{
// Unhook it from the engine
AttachToEngineEntity( HTOOLHANDLE_INVALID );
m_SelectedInfoTarget.Shutdown();
m_InfoTargetSprite.Shutdown();
}
//-----------------------------------------------------------------------------
// Called whem attributes change
//-----------------------------------------------------------------------------
void CDmeCommentaryNodeEntity::OnAttributeChanged( CDmAttribute *pAttribute )
{
BaseClass::OnAttributeChanged( pAttribute );
// Once these have changed, then save them out, and don't bother calling back
if ( pAttribute == m_TargetName.GetAttribute() ||
pAttribute == m_vecLocalAngles.GetAttribute() )
{
pAttribute->RemoveFlag( FATTRIB_DONTSAVE | FATTRIB_HAS_CALLBACK );
return;
}
if ( pAttribute == m_ClassName.GetAttribute() )
{
m_bInfoTarget = !Q_strncmp( m_ClassName, "info_target", 11 ) || !Q_strcmp( m_ClassName, "info_remarkable" );
if ( !Q_stricmp( m_ClassName, "point_commentary_node" ) )
{
SetModelName( "models/extras/info_speech.mdl" );
GetMDL()->m_flPlaybackRate = 0.0f;
}
else
{
SetModelName( NULL );
}
OnTranslucencyTypeChanged();
return;
}
}
//-----------------------------------------------------------------------------
// Returns the entity ID
//-----------------------------------------------------------------------------
int CDmeCommentaryNodeEntity::GetEntityId() const
{
return atoi( GetName() );
}
//-----------------------------------------------------------------------------
// Mark the entity as being dirty
//-----------------------------------------------------------------------------
void CDmeCommentaryNodeEntity::MarkDirty( bool bDirty )
{
m_bIsDirty = bDirty;
OnTranslucencyTypeChanged();
}
//-----------------------------------------------------------------------------
// Is the renderable transparent?
//-----------------------------------------------------------------------------
RenderableTranslucencyType_t CDmeCommentaryNodeEntity::ComputeTranslucencyType( void )
{
if ( m_bIsDirty || m_bInfoTarget )
return RENDERABLE_IS_TRANSLUCENT;
return BaseClass::ComputeTranslucencyType();
}
//-----------------------------------------------------------------------------
// Entity Key iteration
//-----------------------------------------------------------------------------
bool CDmeCommentaryNodeEntity::IsEntityKey( CDmAttribute *pEntityKey )
{
return pEntityKey->IsFlagSet( FATTRIB_USERDEFINED );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CDmAttribute *CDmeCommentaryNodeEntity::FirstEntityKey()
{
for ( CDmAttribute *pAttribute = FirstAttribute(); pAttribute; pAttribute = pAttribute->NextAttribute() )
{
if ( IsEntityKey( pAttribute ) )
return pAttribute;
}
return NULL;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CDmAttribute *CDmeCommentaryNodeEntity::NextEntityKey( CDmAttribute *pEntityKey )
{
if ( !pEntityKey )
return NULL;
for ( CDmAttribute *pAttribute = pEntityKey->NextAttribute(); pAttribute; pAttribute = pAttribute->NextAttribute() )
{
if ( IsEntityKey( pAttribute ) )
return pAttribute;
}
return NULL;
}
//-----------------------------------------------------------------------------
// Attach/detach from an engine entity with the same editor index
//-----------------------------------------------------------------------------
void CDmeCommentaryNodeEntity::AttachToEngineEntity( HTOOLHANDLE hToolHandle )
{
if ( m_hEngineEntity != HTOOLHANDLE_INVALID )
{
clienttools->SetEnabled( m_hEngineEntity, true );
}
m_hEngineEntity = hToolHandle;
if ( m_hEngineEntity != HTOOLHANDLE_INVALID )
{
clienttools->SetEnabled( m_hEngineEntity, false );
}
}
//-----------------------------------------------------------------------------
// Position and bounds for the model
//-----------------------------------------------------------------------------
const Vector &CDmeCommentaryNodeEntity::GetRenderOrigin( void )
{
return m_vecLocalOrigin;
}
const QAngle &CDmeCommentaryNodeEntity::GetRenderAngles( void )
{
return *(QAngle*)(&m_vecLocalAngles.Get());
}
//-----------------------------------------------------------------------------
// Draws the helper for the entity
//-----------------------------------------------------------------------------
void CDmeCommentaryNodeEntity::DrawSprite( IMaterial *pMaterial )
{
float t = 0.5f * sin( Plat_FloatTime() * M_PI / 1.0f ) + 0.5f;
CMatRenderContextPtr pRenderContext( materials );
pRenderContext->Bind( pMaterial );
IMesh* pMesh = pRenderContext->GetDynamicMesh();
CMeshBuilder meshBuilder;
meshBuilder.Begin( pMesh, MATERIAL_TRIANGLE_STRIP, 4, 4 );
unsigned char nBaseR = 255;
unsigned char nBaseG = 255;
unsigned char nBaseB = 255;
unsigned char nAlpha = m_bIsDirty ? (unsigned char)(255 * t) : 255;
meshBuilder.Position3f( -SPHERE_RADIUS, -SPHERE_RADIUS, 0.0f );
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
meshBuilder.TexCoord2f( 0, 0.0f, 1.0f );
meshBuilder.AdvanceVertex();
meshBuilder.Position3f( SPHERE_RADIUS, -SPHERE_RADIUS, 0.0f );
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
meshBuilder.TexCoord2f( 0, 1.0f, 1.0f );
meshBuilder.AdvanceVertex();
meshBuilder.Position3f( SPHERE_RADIUS, SPHERE_RADIUS, 0.0f );
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
meshBuilder.TexCoord2f( 0, 1.0f, 0.0f );
meshBuilder.AdvanceVertex();
meshBuilder.Position3f( -SPHERE_RADIUS, SPHERE_RADIUS, 0.0f );
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
meshBuilder.TexCoord2f( 0, 0.0f, 0.0f );
meshBuilder.AdvanceVertex();
meshBuilder.FastIndex( 0 );
meshBuilder.FastIndex( 1 );
meshBuilder.FastIndex( 3 );
meshBuilder.FastIndex( 2 );
meshBuilder.End();
pMesh->Draw();
}
//-----------------------------------------------------------------------------
// Draws the helper for the entity
//-----------------------------------------------------------------------------
int CDmeCommentaryNodeEntity::DrawModel( int flags, const RenderableInstance_t &instance )
{
bool bSelected = ( g_pCommEditTool->GetCurrentEntity().Get() == this );
if ( !m_bInfoTarget )
{
// If we have a visible engine entity, we don't need to draw it here
// info targets always draw though, because they have no visible model.
CDisableUndoScopeGuard guard;
float t = 0.5f * sin( Plat_FloatTime() * M_PI / 1.0f ) + 0.5f;
unsigned char nAlpha = m_bIsDirty ? (unsigned char)(255 * t) : 255;
if ( bSelected )
{
GetMDL()->m_Color.SetColor( 255, 64, 64, nAlpha );
}
else
{
GetMDL()->m_Color.SetColor( 255, 255, 255, nAlpha );
}
return BaseClass::DrawModel( flags, instance );
}
Assert( IsDrawingInEngine() );
CMatRenderContextPtr pRenderContext( materials );
matrix3x4_t mat;
VMatrix worldToCamera, cameraToWorld;
pRenderContext->GetMatrix( MATERIAL_VIEW, &worldToCamera );
MatrixInverseTR( worldToCamera, cameraToWorld );
MatrixCopy( cameraToWorld.As3x4(), mat );
MatrixSetColumn( m_vecLocalOrigin, 3, mat );
pRenderContext->MatrixMode( MATERIAL_MODEL );
pRenderContext->PushMatrix();
pRenderContext->LoadMatrix( mat );
pRenderContext->FogMode( MATERIAL_FOG_NONE );
pRenderContext->SetNumBoneWeights( 0 );
pRenderContext->CullMode( MATERIAL_CULLMODE_CW );
DrawSprite( m_InfoTargetSprite );
if ( bSelected )
{
DrawSprite( m_SelectedInfoTarget );
}
pRenderContext->CullMode( MATERIAL_CULLMODE_CCW );
pRenderContext->MatrixMode( MATERIAL_MODEL );
pRenderContext->PopMatrix();
return 1;
}
//-----------------------------------------------------------------------------
// Position and bounds for the model
//-----------------------------------------------------------------------------
void CDmeCommentaryNodeEntity::GetRenderBounds( Vector& mins, Vector& maxs )
{
if ( !m_bInfoTarget )
{
BaseClass::GetRenderBounds( mins, maxs );
return;
}
mins.Init( -SPHERE_RADIUS, -SPHERE_RADIUS, -SPHERE_RADIUS );
maxs.Init( SPHERE_RADIUS, SPHERE_RADIUS, SPHERE_RADIUS );
}
//-----------------------------------------------------------------------------
// Update renderable position
//-----------------------------------------------------------------------------
void CDmeCommentaryNodeEntity::SetRenderOrigin( const Vector &vecOrigin )
{
m_vecLocalOrigin = vecOrigin;
clienttools->MarkClientRenderableDirty( this );
}
void CDmeCommentaryNodeEntity::SetRenderAngles( const QAngle &angles )
{
m_vecLocalAngles = *(Vector*)&angles;
clienttools->MarkClientRenderableDirty( this );
}

View File

@@ -0,0 +1,100 @@
//====== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. =======
//
// Purpose: Represents an entity in a VMF
//
//=============================================================================
#ifndef DMEVMFENTITY_H
#define DMEVMFENTITY_H
#ifdef _WIN32
#pragma once
#endif
#include "toolutils/dmemdlrenderable.h"
#include "datamodel/dmelement.h"
#include "toolframework/itoolentity.h"
#include "materialsystem/materialsystemutil.h"
//-----------------------------------------------------------------------------
// Represents an editable entity; draws its helpers
//-----------------------------------------------------------------------------
class CDmeCommentaryNodeEntity : public CDmeMdlRenderable<CDmElement>
{
DEFINE_ELEMENT( CDmeCommentaryNodeEntity, CDmeMdlRenderable<CDmElement> );
public:
// Inherited from CDmElement
virtual void OnAttributeChanged( CDmAttribute *pAttribute );
public:
// Inherited from DmeRenderable
virtual const Vector &GetRenderOrigin( void );
virtual const QAngle &GetRenderAngles( void );
virtual int DrawModel( int flags, const RenderableInstance_t &instance );
virtual void GetRenderBounds( Vector& mins, Vector& maxs );
virtual RenderableTranslucencyType_t ComputeTranslucencyType( void );
public:
int GetEntityId() const;
const char *GetClassName() const;
const char *GetTargetName() const;
bool IsPlaceholder() const;
// Entity Key iteration
CDmAttribute *FirstEntityKey();
CDmAttribute *NextEntityKey( CDmAttribute *pEntityKey );
// Attach/detach from an engine entity with the same editor index
void AttachToEngineEntity( HTOOLHANDLE hToolHandle );
void SetRenderOrigin( const Vector &vecOrigin );
void SetRenderAngles( const QAngle &angles );
void MarkDirty( bool bDirty = true );
private:
bool IsEntityKey( CDmAttribute *pEntityKey );
// Draws the helper for the entity
void DrawSprite( IMaterial *pMaterial );
CDmaVar<Vector> m_vecLocalOrigin;
CDmaVar<Vector> m_vecLocalAngles;
CDmaString m_ClassName;
CDmaString m_TargetName;
CDmaVar<bool> m_bIsPlaceholder;
bool m_bInfoTarget;
bool m_bIsDirty;
// The entity it's connected to in the engine
HTOOLHANDLE m_hEngineEntity;
CMaterialReference m_SelectedInfoTarget;
CMaterialReference m_InfoTargetSprite;
};
//-----------------------------------------------------------------------------
// Inline methods
//-----------------------------------------------------------------------------
inline const char *CDmeCommentaryNodeEntity::GetClassName() const
{
return m_ClassName;
}
inline const char *CDmeCommentaryNodeEntity::GetTargetName() const
{
return m_TargetName;
}
inline bool CDmeCommentaryNodeEntity::IsPlaceholder() const
{
return m_bIsPlaceholder;
}
#endif // DMEVMFENTITY_H

View File

@@ -0,0 +1,581 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose: Singleton dialog that generates and presents the entity report.
//
//===========================================================================//
#include "EntityReportPanel.h"
#include "tier1/keyvalues.h"
#include "tier1/utlbuffer.h"
#include "iregistry.h"
#include "vgui/ivgui.h"
#include "vgui_controls/listpanel.h"
#include "vgui_controls/textentry.h"
#include "vgui_controls/checkbutton.h"
#include "vgui_controls/combobox.h"
#include "vgui_controls/radiobutton.h"
#include "vgui_controls/messagebox.h"
#include "commeditdoc.h"
#include "commedittool.h"
#include "datamodel/dmelement.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
using namespace vgui;
//-----------------------------------------------------------------------------
// Sort by target name
//-----------------------------------------------------------------------------
static int __cdecl TargetNameSortFunc( vgui::ListPanel *pPanel, const ListPanelItem &item1, const ListPanelItem &item2 )
{
const char *string1 = item1.kv->GetString("targetname");
const char *string2 = item2.kv->GetString("targetname");
int nRetVal = Q_stricmp( string1, string2 );
if ( nRetVal != 0 )
return nRetVal;
string1 = item1.kv->GetString("classname");
string2 = item2.kv->GetString("classname");
return Q_stricmp( string1, string2 );
}
//-----------------------------------------------------------------------------
// Sort by class name
//-----------------------------------------------------------------------------
static int __cdecl ClassNameSortFunc( vgui::ListPanel *pPanel, const ListPanelItem &item1, const ListPanelItem &item2 )
{
const char *string1 = item1.kv->GetString("classname");
const char *string2 = item2.kv->GetString("classname");
int nRetVal = Q_stricmp( string1, string2 );
if ( nRetVal != 0 )
return nRetVal;
string1 = item1.kv->GetString("targetname");
string2 = item2.kv->GetString("targetname");
return Q_stricmp( string1, string2 );
}
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CEntityReportPanel::CEntityReportPanel( CCommEditDoc *pDoc, vgui::Panel* pParent, const char *pName )
: BaseClass( pParent, pName ), m_pDoc( pDoc )
{
m_bSuppressEntityListUpdate = false;
m_iFilterByType = FILTER_SHOW_EVERYTHING;
m_bFilterByKeyvalue = false;
m_bFilterByClass = false;
m_bFilterByHidden = false;
m_bFilterByKeyvalue = false;
m_bExact = false;
m_bFilterTextChanged = false;
SetPaintBackgroundEnabled( true );
m_pEntities = new vgui::ListPanel( this, "Entities" );
m_pEntities->AddColumnHeader( 0, "targetname", "Name", 52, ListPanel::COLUMN_RESIZEWITHWINDOW );
m_pEntities->AddColumnHeader( 1, "classname", "Class Name", 52, ListPanel::COLUMN_RESIZEWITHWINDOW );
m_pEntities->SetColumnSortable( 0, true );
m_pEntities->SetColumnSortable( 1, true );
m_pEntities->SetEmptyListText( "No Entities" );
// m_pEntities->SetDragEnabled( true );
m_pEntities->AddActionSignalTarget( this );
m_pEntities->SetSortFunc( 0, TargetNameSortFunc );
m_pEntities->SetSortFunc( 1, ClassNameSortFunc );
m_pEntities->SetSortColumn( 0 );
// Filtering checkboxes
m_pFilterByClass = new vgui::CheckButton( this, "ClassnameCheck", "" );
m_pFilterByClass->AddActionSignalTarget( this );
m_pFilterByKeyvalue = new vgui::CheckButton( this, "KeyvalueCheck", "" );
m_pFilterByKeyvalue->AddActionSignalTarget( this );
m_pFilterByHidden = new vgui::CheckButton( this, "HiddenCheck", "" );
m_pFilterByHidden->AddActionSignalTarget( this );
m_pExact = new vgui::CheckButton( this, "ExactCheck", "" );
m_pExact->AddActionSignalTarget( this );
// Filtering text entries
m_pFilterKey = new vgui::TextEntry( this, "KeyTextEntry" );
m_pFilterValue = new vgui::TextEntry( this, "ValueTextEntry" );
// Classname combobox
m_pFilterClass = new vgui::ComboBox( this, "ClassNameComboBox", 16, true );
// Filter by type radio buttons
m_pFilterEverything = new vgui::RadioButton( this, "EverythingRadio", "" );
m_pFilterPointEntities = new vgui::RadioButton( this, "PointRadio", "" );
m_pFilterBrushModels = new vgui::RadioButton( this, "BrushRadio", "" );
LoadControlSettings( "resource/entityreportpanel.res" );
ReadSettingsFromRegistry();
// Used for updating filter while changing text
ivgui()->AddTickSignal( GetVPanel(), 300 );
}
//-----------------------------------------------------------------------------
// Reads settings from registry
//-----------------------------------------------------------------------------
void CEntityReportPanel::ReadSettingsFromRegistry()
{
m_bSuppressEntityListUpdate = true;
const char *pKeyBase = g_pCommEditTool->GetRegistryName();
m_pFilterByKeyvalue->SetSelected( registry->ReadInt(pKeyBase, "FilterByKeyvalue", 0) );
m_pFilterByClass->SetSelected( registry->ReadInt(pKeyBase, "FilterByClass", 0) );
m_pFilterByHidden->SetSelected( registry->ReadInt(pKeyBase, "FilterByHidden", 1) );
m_pExact->SetSelected( registry->ReadInt(pKeyBase, "Exact", 0) );
m_iFilterByType = (FilterType_t)registry->ReadInt(pKeyBase, "FilterByType", FILTER_SHOW_EVERYTHING);
m_pFilterEverything->SetSelected( m_iFilterByType == FILTER_SHOW_EVERYTHING );
m_pFilterPointEntities->SetSelected( m_iFilterByType == FILTER_SHOW_POINT_ENTITIES );
m_pFilterBrushModels->SetSelected( m_iFilterByType == FILTER_SHOW_BRUSH_ENTITIES );
// Gotta call change functions manually since SetText doesn't post an action signal
const char *pValue = registry->ReadString( pKeyBase, "FilterClass", "" );
m_pFilterClass->SetText( pValue );
OnChangeFilterclass( pValue );
pValue = registry->ReadString( pKeyBase, "FilterKey", "" );
m_pFilterKey->SetText( pValue );
OnChangeFilterkey( pValue );
pValue = registry->ReadString( pKeyBase, "FilterValue", "" );
m_pFilterValue->SetText( pValue );
OnChangeFiltervalue( pValue );
m_bSuppressEntityListUpdate = false;
UpdateEntityList();
}
//-----------------------------------------------------------------------------
// Writes settings to registry
//-----------------------------------------------------------------------------
void CEntityReportPanel::SaveSettingsToRegistry()
{
const char *pKeyBase = g_pCommEditTool->GetRegistryName();
registry->WriteInt(pKeyBase, "FilterByKeyvalue", m_bFilterByKeyvalue);
registry->WriteInt(pKeyBase, "FilterByClass", m_bFilterByClass);
registry->WriteInt(pKeyBase, "FilterByHidden", m_bFilterByHidden);
registry->WriteInt(pKeyBase, "FilterByType", m_iFilterByType);
registry->WriteInt(pKeyBase, "Exact", m_bExact);
registry->WriteString(pKeyBase, "FilterClass", m_szFilterClass);
registry->WriteString(pKeyBase, "FilterKey", m_szFilterKey);
registry->WriteString(pKeyBase, "FilterValue", m_szFilterValue);
}
//-----------------------------------------------------------------------------
// Purpose: Shows the most recent selected object in properties window
//-----------------------------------------------------------------------------
void CEntityReportPanel::OnProperties(void)
{
int iSel = m_pEntities->GetSelectedItem( 0 );
KeyValues *kv = m_pEntities->GetItem( iSel );
CDmElement *pEntity = (CDmElement *)kv->GetPtr( "entity" );
g_pCommEditTool->ShowEntityInEntityProperties( pEntity );
}
//-----------------------------------------------------------------------------
// Purpose: Deletes the marked objects.
//-----------------------------------------------------------------------------
void CEntityReportPanel::OnDeleteEntities(void)
{
// This is undoable
CUndoScopeGuard guard( g_pDataModel, "Delete Entities", "Delete Entities" );
int iSel = m_pEntities->GetSelectedItem( 0 );
//
// Build a list of objects to delete.
//
int nCount = m_pEntities->GetSelectedItemsCount();
for (int i = 0; i < nCount; i++)
{
int nItemID = m_pEntities->GetSelectedItem(i);
KeyValues *kv = m_pEntities->GetItem( nItemID );
CDmElement *pEntity = (CDmElement *)kv->GetPtr( "entity" );
if ( pEntity )
{
m_pDoc->DeleteCommentaryNode( pEntity );
}
}
UpdateEntityList();
// Update the list box selection.
if (iSel >= m_pEntities->GetItemCount())
{
iSel = m_pEntities->GetItemCount() - 1;
}
m_pEntities->SetSingleSelectedItem( iSel );
}
//-----------------------------------------------------------------------------
// Called when buttons are clicked
//-----------------------------------------------------------------------------
void CEntityReportPanel::OnCommand( const char *pCommand )
{
if ( !Q_stricmp( pCommand, "delete" ) )
{
// Confirm we want to do it
MessageBox *pConfirm = new MessageBox( "#CommEditDeleteObjects", "#CommEditDeleteObjectsMsg", g_pCommEditTool->GetRootPanel() );
pConfirm->AddActionSignalTarget( this );
pConfirm->SetOKButtonText( "Yes" );
pConfirm->SetCommand( new KeyValues( "DeleteEntities" ) );
pConfirm->SetCancelButtonVisible( true );
pConfirm->SetCancelButtonText( "No" );
pConfirm->DoModal();
return;
}
if ( !Q_stricmp( pCommand, "ShowProperties" ) )
{
OnProperties();
return;
}
}
//-----------------------------------------------------------------------------
// Call this when our settings are dirty
//-----------------------------------------------------------------------------
void CEntityReportPanel::MarkDirty( bool bFilterDirty )
{
float flTime = Plat_FloatTime();
m_bRegistrySettingsChanged = true;
m_flRegistryTime = flTime;
if ( bFilterDirty && !m_bFilterTextChanged )
{
m_bFilterTextChanged = true;
m_flFilterTime = flTime;
}
}
//-----------------------------------------------------------------------------
// Methods related to filtering
//-----------------------------------------------------------------------------
void CEntityReportPanel::OnFilterByHidden( bool bState )
{
m_bFilterByHidden = bState;
UpdateEntityList();
MarkDirty( false );
}
void CEntityReportPanel::OnFilterByKeyvalue( bool bState )
{
m_bFilterByKeyvalue = bState;
UpdateEntityList();
MarkDirty( false );
m_pFilterKey->SetEnabled( bState );
m_pFilterValue->SetEnabled( bState );
m_pExact->SetEnabled( bState );
}
void CEntityReportPanel::OnFilterKeyValueExact( bool bState )
{
m_bExact = bState;
UpdateEntityList();
MarkDirty( false );
}
void CEntityReportPanel::OnFilterByType( FilterType_t type )
{
m_iFilterByType = type;
UpdateEntityList();
MarkDirty( false );
}
void CEntityReportPanel::OnFilterByClass( bool bState )
{
m_bFilterByClass = bState;
UpdateEntityList();
MarkDirty( false );
m_pFilterClass->SetEnabled( bState );
}
void CEntityReportPanel::OnChangeFilterkey( const char *pText )
{
m_szFilterKey = pText;
MarkDirty( true );
}
void CEntityReportPanel::OnChangeFiltervalue( const char *pText )
{
m_szFilterValue = pText;
MarkDirty( true );
}
void CEntityReportPanel::OnChangeFilterclass( const char *pText )
{
m_szFilterClass = pText;
MarkDirty( true );
}
//-----------------------------------------------------------------------------
// Deals with all check buttons
//-----------------------------------------------------------------------------
void CEntityReportPanel::OnTextChanged( KeyValues *kv )
{
TextEntry *pPanel = (TextEntry*)kv->GetPtr( "panel", NULL );
int nLength = pPanel->GetTextLength();
char *pBuf = (char*)_alloca( nLength + 1 );
pPanel->GetText( pBuf, nLength+1 );
if ( pPanel == m_pFilterClass )
{
OnChangeFilterclass( pBuf );
return;
}
if ( pPanel == m_pFilterKey )
{
OnChangeFilterkey( pBuf );
return;
}
if ( pPanel == m_pFilterValue )
{
OnChangeFiltervalue( pBuf );
return;
}
}
//-----------------------------------------------------------------------------
// Deals with all check buttons
//-----------------------------------------------------------------------------
void CEntityReportPanel::OnButtonToggled( KeyValues *kv )
{
Panel *pPanel = (Panel*)kv->GetPtr( "panel", NULL );
bool bState = kv->GetInt( "state", 0 ) != 0;
if ( pPanel == m_pFilterByClass )
{
OnFilterByClass( bState );
return;
}
if ( pPanel == m_pFilterByKeyvalue )
{
OnFilterByKeyvalue( bState );
return;
}
if ( pPanel == m_pFilterByHidden )
{
OnFilterByHidden( bState );
return;
}
if ( pPanel == m_pExact )
{
OnFilterKeyValueExact( bState );
return;
}
if ( pPanel == m_pFilterEverything )
{
OnFilterByType( FILTER_SHOW_EVERYTHING );
return;
}
if ( pPanel == m_pFilterPointEntities )
{
OnFilterByType( FILTER_SHOW_POINT_ENTITIES );
return;
}
if ( pPanel == m_pFilterBrushModels )
{
OnFilterByType( FILTER_SHOW_BRUSH_ENTITIES );
return;
}
}
//-----------------------------------------------------------------------------
// FIXME: Necessary because SetSelected doesn't cause a ButtonToggled message to trigger
//-----------------------------------------------------------------------------
void CEntityReportPanel::OnCheckButtonChecked( KeyValues *kv )
{
OnButtonToggled( kv );
}
void CEntityReportPanel::OnRadioButtonChecked( KeyValues *kv )
{
OnButtonToggled( kv );
}
#if 0
//-----------------------------------------------------------------------------
// Purpose: Centers the 2D and 3D views on the selected entities.
//-----------------------------------------------------------------------------
void CEntityReportPanel::OnGoto()
{
MarkSelectedEntities();
m_pDoc->CenterViewsOnSelection();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEntityReportPanel::MarkSelectedEntities()
{
m_pDoc->SelectObject(NULL, CMapDoc::scClear);
for(int i = 0; i < m_cEntities.GetCount(); i++)
{
if(!m_cEntities.GetSel(i))
continue;
CMapEntity *pEntity = (CMapEntity*) m_cEntities.GetItemDataPtr(i);
m_pDoc->SelectObject(pEntity, CMapDoc::scSelect);
}
m_pDoc->SelectObject(NULL, CMapDoc::scUpdateDisplay);
}
#endif
void CEntityReportPanel::OnTick( )
{
BaseClass::OnTick();
// check filters
float flTime = Plat_FloatTime();
if ( m_bFilterTextChanged )
{
if ( (flTime - m_flFilterTime) > 1e-3 )
{
m_bFilterTextChanged = false;
m_flFilterTime = flTime;
UpdateEntityList();
}
}
if ( m_bRegistrySettingsChanged )
{
if ( (flTime - m_flRegistryTime) > 1e-3 )
{
m_bRegistrySettingsChanged = false;
m_flRegistryTime = flTime;
SaveSettingsToRegistry();
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEntityReportPanel::UpdateEntityList(void)
{
if ( m_bSuppressEntityListUpdate )
return;
m_bFilterTextChanged = false;
m_pEntities->RemoveAll();
CDmAttribute *pEntityList = m_pDoc->GetEntityList();
int nCount = pEntityList->Count();
for ( int i = 0; i < nCount; ++i )
{
CDmElement *pEntity = GetElement< CDmElement >( pEntityList->Get(i) );
const char *pClassName = pEntity->GetAttributeValueString( "classname" );
if ( !pClassName || !pClassName[0] )
{
pClassName = "<no class>";
}
KeyValues *kv = new KeyValues( "node" );
kv->SetString( "classname", pClassName );
kv->SetPtr( "entity", pEntity );
m_pEntities->AddItem( kv, 0, false, false );
}
m_pEntities->SortList();
}
#if 0
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEntityReportPanel::GenerateReport()
{
POSITION p = pGD->Classes.GetHeadPosition();
CString str;
while(p)
{
GDclass *pc = pGD->Classes.GetNext(p);
if(!pc->IsBaseClass())
{
str = pc->GetName();
if(str != "worldspawn")
m_cFilterClass.AddString(str);
}
}
SetTimer(1, 500, NULL);
OnFilterbykeyvalue();
OnFilterbytype();
OnFilterbyclass();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEntityReportPanel::OnSelChangeEntityList()
{
MarkSelectedEntities();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEntityReportPanel::OnDblClkEntityList()
{
m_pDoc->CenterViewsOnSelection();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEntityReportPanel::OnOK()
{
DestroyWindow();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEntityReportPanel::OnClose()
{
DestroyWindow();
}
//-----------------------------------------------------------------------------
// Purpose: Called when our window is being destroyed.
//-----------------------------------------------------------------------------
void CEntityReportPanel::OnDestroy()
{
SaveToIni();
s_pDlg = NULL;
delete this;
}
#endif