1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
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 );
}
|