summaryrefslogtreecommitdiff
path: root/tools/gameevents/gameeventeditdoc.cpp
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /tools/gameevents/gameeventeditdoc.cpp
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'tools/gameevents/gameeventeditdoc.cpp')
-rw-r--r--tools/gameevents/gameeventeditdoc.cpp182
1 files changed, 182 insertions, 0 deletions
diff --git a/tools/gameevents/gameeventeditdoc.cpp b/tools/gameevents/gameeventeditdoc.cpp
new file mode 100644
index 0000000..909f16e
--- /dev/null
+++ b/tools/gameevents/gameeventeditdoc.cpp
@@ -0,0 +1,182 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//
+//=============================================================================//
+
+#include "gameeventeditdoc.h"
+#include "tier1/KeyValues.h"
+#include "tier1/utlbuffer.h"
+#include "toolutils/enginetools_int.h"
+#include "filesystem.h"
+#include "toolframework/ienginetool.h"
+#include "datamodel/idatamodel.h"
+#include "toolutils/attributeelementchoicelist.h"
+#include "vgui_controls/messagebox.h"
+
+// FIXME: This document currently stores a whole lot of nothing.
+
+//-----------------------------------------------------------------------------
+// Constructor
+//-----------------------------------------------------------------------------
+CGameEventEditDoc::CGameEventEditDoc()
+{
+ m_hRoot = NULL;
+ m_pTXTFileName[0] = 0;
+ m_bDirty = false;
+ g_pDataModel->InstallNotificationCallback( this );
+}
+
+CGameEventEditDoc::~CGameEventEditDoc()
+{
+ g_pDataModel->RemoveNotificationCallback( this );
+}
+
+//-----------------------------------------------------------------------------
+// Inherited from INotifyUI
+//-----------------------------------------------------------------------------
+void CGameEventEditDoc::NotifyDataChanged( const char *pReason, int nNotifySource, int nNotifyFlags )
+{
+ //OnDataChanged( pReason, nNotifySource, nNotifyFlags );
+}
+
+//-----------------------------------------------------------------------------
+// Gets the file name
+//-----------------------------------------------------------------------------
+const char *CGameEventEditDoc::GetTXTFileName()
+{
+ return m_pTXTFileName;
+}
+
+void CGameEventEditDoc::SetTXTFileName( const char *pFileName )
+{
+ Q_strncpy( m_pTXTFileName, pFileName, sizeof( m_pTXTFileName ) );
+ Q_FixSlashes( m_pTXTFileName );
+ SetDirty( true );
+}
+
+//-----------------------------------------------------------------------------
+// Dirty bits
+//-----------------------------------------------------------------------------
+void CGameEventEditDoc::SetDirty( bool bDirty )
+{
+ m_bDirty = bDirty;
+}
+
+bool CGameEventEditDoc::IsDirty() const
+{
+ return m_bDirty;
+}
+
+//-----------------------------------------------------------------------------
+// Saves/loads from file
+//-----------------------------------------------------------------------------
+bool CGameEventEditDoc::LoadFromFile( const char *pFileName )
+{
+/*
+ Assert( !m_hRoot.Get() );
+
+ CAppDisableUndoScopeGuard guard( "CCommEditDoc::LoadFromFile", 0 );
+ SetDirty( false );
+
+ if ( !pFileName[0] )
+ return false;
+
+ char mapname[ 256 ];
+
+ // Compute the map name
+ const char *pMaps = Q_stristr( pFileName, "\\maps\\" );
+ if ( !pMaps )
+ return false;
+
+ // Build map name
+ //int nNameLen = (int)( (size_t)pComm - (size_t)pMaps ) - 5;
+ Q_StripExtension( pFileName, mapname, sizeof(mapname) );
+ char *pszFileName = (char*)Q_UnqualifiedFileName(mapname);
+
+ // Set the txt file name.
+ // If we loaded an existing commentary file, keep the same filename.
+ // If we loaded a .bsp, change the name & the extension.
+ if ( !V_stricmp( Q_GetFileExtension( pFileName ), "bsp" ) )
+ {
+ const char *pCommentaryAppend = "_commentary.txt";
+ Q_StripExtension( pFileName, m_pTXTFileName, sizeof(m_pTXTFileName)- strlen(pCommentaryAppend) - 1 );
+ Q_strcat( m_pTXTFileName, pCommentaryAppend, sizeof( m_pTXTFileName ) );
+
+ if ( g_pFileSystem->FileExists( m_pTXTFileName ) )
+ {
+ char pBuf[1024];
+ Q_snprintf( pBuf, sizeof(pBuf), "File %s already exists!\n", m_pTXTFileName );
+ m_pTXTFileName[0] = 0;
+ vgui::MessageBox *pMessageBox = new vgui::MessageBox( "Unable to overwrite file!\n", pBuf, g_pCommEditTool );
+ pMessageBox->DoModal( );
+ return false;
+ }
+
+ DmFileId_t fileid = g_pDataModel->FindOrCreateFileId( m_pTXTFileName );
+
+ m_hRoot = CreateElement<CDmElement>( "root", fileid );
+ CDmrElementArray<> subkeys( m_hRoot->AddAttribute( "subkeys", AT_ELEMENT_ARRAY ) );
+ CDmElement *pRoot2 = CreateElement<CDmElement>( "Entities", fileid );
+ pRoot2->AddAttribute( "subkeys", AT_ELEMENT_ARRAY );
+ subkeys.AddToTail( pRoot2 );
+ g_pDataModel->SetFileRoot( fileid, m_hRoot );
+ }
+ else
+ {
+ char *pComm = Q_stristr( pszFileName, "_commentary" );
+ if ( !pComm )
+ {
+ char pBuf[1024];
+ Q_snprintf( pBuf, sizeof(pBuf), "File %s is not a commentary file!\nThe file name must end in _commentary.txt.\n", m_pTXTFileName );
+ m_pTXTFileName[0] = 0;
+ vgui::MessageBox *pMessageBox = new vgui::MessageBox( "Bad file name!\n", pBuf, g_pCommEditTool );
+ pMessageBox->DoModal( );
+ return false;
+ }
+
+ // Clip off the "_commentary" at the end of the filename
+ *pComm = '\0';
+
+ // This is not undoable
+ CDisableUndoScopeGuard guard;
+
+ CDmElement *pTXT = NULL;
+
+ CElementForKeyValueCallback KeyValuesCallback;
+ g_pDataModel->SetKeyValuesElementCallback( &KeyValuesCallback );
+ DmFileId_t fileid = g_pDataModel->RestoreFromFile( pFileName, NULL, "keyvalues", &pTXT );
+ g_pDataModel->SetKeyValuesElementCallback( NULL );
+
+ if ( fileid == DMFILEID_INVALID )
+ {
+ m_pTXTFileName[0] = 0;
+ return false;
+ }
+
+ SetTXTFileName( pFileName );
+ m_hRoot = pTXT;
+ }
+
+ guard.Release();
+ SetDirty( false );
+
+ char cmd[ 256 ];
+ Q_snprintf( cmd, sizeof( cmd ), "disconnect; map %s\n", pszFileName );
+ enginetools->Command( cmd );
+ enginetools->Execute( );*/
+
+ return true;
+}
+
+void CGameEventEditDoc::SaveToFile( )
+{
+ if ( m_hRoot.Get() && m_pTXTFileName && m_pTXTFileName[0] )
+ {
+ g_pDataModel->SaveToFile( m_pTXTFileName, NULL, "keyvalues", "keyvalues", m_hRoot );
+ }
+
+ SetDirty( false );
+} \ No newline at end of file