summaryrefslogtreecommitdiff
path: root/movieobjects/dmeeditortypedictionary.cpp
blob: f4efc0011cd669ed4885acf864a26613b1aeffdb (plain) (blame)
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Contains a bunch of information about editor types
// Editor types are arbitrary
//
// $NoKeywords: $
//
//=============================================================================//

#include "movieobjects/dmeeditortypedictionary.h"
#include "datamodel/dmelementfactoryhelper.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"


//-----------------------------------------------------------------------------
// Expose DmeEditorAttributeInfo to the scene database 
//-----------------------------------------------------------------------------
IMPLEMENT_ELEMENT_FACTORY( DmeEditorAttributeInfo, CDmeEditorAttributeInfo );


//-----------------------------------------------------------------------------
// Constructor, destructor
//-----------------------------------------------------------------------------
void CDmeEditorAttributeInfo::OnConstruction()
{
	m_Widget.Init( this, "widget" );
	m_bIsVisible.Init( this, "isVisible" );
	m_bIsReadOnly.Init( this, "isReadOnly" );
	m_ArrayEntries.Init( this, "arrayEntries" );
	m_bHideType.Init( this, "hideType" );
	m_bHideValue.Init( this, "hideValue" );
	m_Help.Init( this, "help" );

	m_bIsVisible = true;
	m_bIsReadOnly = false;
}

void CDmeEditorAttributeInfo::OnDestruction()
{
}


//-----------------------------------------------------------------------------
// Returns the attribute name this info is associated with
//-----------------------------------------------------------------------------
const char *CDmeEditorAttributeInfo::GetAttributeName() const
{
	return GetName();
}

	
//-----------------------------------------------------------------------------
// Returns the widget name
//-----------------------------------------------------------------------------
const char *CDmeEditorAttributeInfo::GetWidgetName() const
{
	return m_Widget.Get();
}

	
//-----------------------------------------------------------------------------
// Returns the info for a entry in an attribute array, if this attribute is an array type
//-----------------------------------------------------------------------------
CDmeEditorAttributeInfo *CDmeEditorAttributeInfo::GetArrayInfo()
{
	return m_ArrayEntries;
}


//-----------------------------------------------------------------------------
// Sets the info for an entry in an attribute array
//-----------------------------------------------------------------------------
void CDmeEditorAttributeInfo::SetArrayInfo( CDmeEditorAttributeInfo *pInfo )
{
	m_ArrayEntries = pInfo;
}

	
//-----------------------------------------------------------------------------
//
// CDmeEditorChoicesInfo, Base class for configuration for choices
//
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Expose DmeEditorChoicesInfo to the scene database 
//-----------------------------------------------------------------------------
IMPLEMENT_ELEMENT_FACTORY( DmeEditorChoicesInfo, CDmeEditorChoicesInfo );

    
//-----------------------------------------------------------------------------
// Constructor, destructor
//-----------------------------------------------------------------------------
void CDmeEditorChoicesInfo::OnConstruction()
{
	m_Choices.Init( this, "choices" );
	m_ChoiceType.Init( this, "choicetype" );
}

void CDmeEditorChoicesInfo::OnDestruction()
{
}


//-----------------------------------------------------------------------------
// Sets/gets choice type
//-----------------------------------------------------------------------------
void CDmeEditorChoicesInfo::SetChoiceType( const char *pChoiceType )
{
	m_ChoiceType = pChoiceType;
}

const char *CDmeEditorChoicesInfo::GetChoiceType() const
{
	return m_ChoiceType;
}

bool CDmeEditorChoicesInfo::HasChoiceType() const
{
	return m_ChoiceType.Length() > 0;
}


//-----------------------------------------------------------------------------
// Gets the choices
//-----------------------------------------------------------------------------
int CDmeEditorChoicesInfo::GetChoiceCount() const
{
	return m_Choices.Count();
}

CDmElement *CDmeEditorChoicesInfo::CreateChoice( const char *pChoiceString )
{
	CDmElement *pChoice = CreateElement< CDmElement >( "", GetFileId() );
	m_Choices.AddToTail( pChoice );
	pChoice->SetValue<CUtlString>( "string", pChoiceString );
	return pChoice;
}

const char *CDmeEditorChoicesInfo::GetChoiceString( int nIndex ) const
{
	Assert( ( nIndex < GetChoiceCount() ) && ( nIndex >= 0 ) );
	CDmElement *pChoice = m_Choices[nIndex];
	if ( !pChoice )
		return "";

	return pChoice->GetValueString( "string" );
}


//-----------------------------------------------------------------------------
// Expose DmeEditorType class to the scene database 
//-----------------------------------------------------------------------------
IMPLEMENT_ELEMENT_FACTORY( DmeEditorType, CDmeEditorType );


//-----------------------------------------------------------------------------
// Constructor, destructor
//-----------------------------------------------------------------------------
void CDmeEditorType::OnConstruction()
{
}

void CDmeEditorType::OnDestruction()
{
}


//-----------------------------------------------------------------------------
// Computes the actual attribute name stored in the type
//-----------------------------------------------------------------------------
const char *CDmeEditorType::GetActualAttributeName( const char *pAttributeName )
{
	// Fixup the names of the attribute info for the 3 standard fields (name, type, id)
	if ( !V_stricmp( "name", pAttributeName ) )
		return "__name";

	if ( !V_stricmp( "id", pAttributeName ) )
		return "__id";

	if ( !V_stricmp( "type", pAttributeName ) )
		return "__type";

	return pAttributeName;
}


//-----------------------------------------------------------------------------
// Returns the editor info associated with an editor type
//-----------------------------------------------------------------------------
void CDmeEditorType::AddAttributeInfo( const char *pAttributeName, CDmeEditorAttributeInfo *pInfo )
{
	pAttributeName = GetActualAttributeName( pAttributeName );
	SetValue( pAttributeName, pInfo ); 
}


//-----------------------------------------------------------------------------
// Removes a editor type associated with a particular attribute
//-----------------------------------------------------------------------------
void CDmeEditorType::RemoveAttributeInfo( const char *pAttributeName )
{
	pAttributeName = GetActualAttributeName( pAttributeName );
	if ( HasAttribute( pAttributeName ) )
	{
		RemoveAttribute( pAttributeName ); 
	}
}

	
//-----------------------------------------------------------------------------
// Returns the editor info associated with an editor type
//-----------------------------------------------------------------------------
CDmeEditorAttributeInfo *CDmeEditorType::GetAttributeInfo( const char *pAttributeName )
{
	pAttributeName = GetActualAttributeName( pAttributeName );
	if ( !HasAttribute( pAttributeName ) )
		return NULL;

	return GetValueElement< CDmeEditorAttributeInfo >( pAttributeName );
}


//-----------------------------------------------------------------------------
// Returns the editor info associated with a single entry in an attribute array
//-----------------------------------------------------------------------------
CDmeEditorAttributeInfo *CDmeEditorType::GetAttributeArrayInfo( const char *pAttributeName )
{
	CDmeEditorAttributeInfo *pAttributeInfo = GetAttributeInfo( pAttributeName );
	if ( !pAttributeInfo )
		return NULL;

	return pAttributeInfo->GetArrayInfo();
}


//-----------------------------------------------------------------------------
// Expose DmeEditorTypeDictionary class to the scene database 
//-----------------------------------------------------------------------------
IMPLEMENT_ELEMENT_FACTORY( DmeEditorTypeDictionary, CDmeEditorTypeDictionary );


//-----------------------------------------------------------------------------
// Constructor, destructor
//-----------------------------------------------------------------------------
void CDmeEditorTypeDictionary::OnConstruction()
{
}

void CDmeEditorTypeDictionary::OnDestruction()
{
}


//-----------------------------------------------------------------------------
// Constructor, destructor
//-----------------------------------------------------------------------------
void CDmeEditorTypeDictionary::AddEditorType( CDmeEditorType *pEditorType )
{
	const char *pEditorTypeName = pEditorType->GetName();
	if ( HasAttribute( pEditorTypeName ) )
	{
		Warning( "Editor type %s is already defined! Ignoring...\n", pEditorTypeName );
		return;
	}

	SetValue( pEditorTypeName, pEditorType->GetHandle() );
}

void CDmeEditorTypeDictionary::AddEditorTypesFromFile( const char *pFileName, const char *pPathID )
{
}


//-----------------------------------------------------------------------------
// Returns the editor type to use with an element
//-----------------------------------------------------------------------------
CDmeEditorType *CDmeEditorTypeDictionary::GetEditorType( CDmElement *pElement )
{
	if ( !pElement )
		return NULL;

	const char *pEditorTypeName = NULL;
	if ( pElement->HasAttribute( "editorType" ) )
	{
		pEditorTypeName = pElement->GetValueString( "editorType" );
	}

	if ( !pEditorTypeName || !pEditorTypeName[0] )
	{
		// Try to use the type name as an editor
		pEditorTypeName = pElement->GetTypeString();
	}

	if ( !pEditorTypeName || !pEditorTypeName[0] )
		return NULL;

	if ( !HasAttribute( pEditorTypeName ) )
		return NULL;

	return GetValueElement< CDmeEditorType >( pEditorTypeName );
}


//-----------------------------------------------------------------------------
// Returns the editor info associated with an editor type
//-----------------------------------------------------------------------------
CDmeEditorAttributeInfo *CDmeEditorTypeDictionary::GetAttributeInfo( CDmElement *pElement, const char *pAttributeName )
{
	CDmeEditorType *pEditorType = GetEditorType( pElement );
	if ( !pEditorType )
		return NULL;
	return pEditorType->GetAttributeInfo( pAttributeName );
}


//-----------------------------------------------------------------------------
// Returns the editor info associated with an editor type
//-----------------------------------------------------------------------------
CDmeEditorAttributeInfo *CDmeEditorTypeDictionary::GetAttributeArrayInfo( CDmElement *pElement, const char *pAttributeName )
{
	CDmeEditorType *pEditorType = GetEditorType( pElement );
	if ( !pEditorType )
		return NULL;
	return pEditorType->GetAttributeArrayInfo( pAttributeName );
}