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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#ifndef GDVAR_H
#define GDVAR_H
#pragma once
#include <utlvector.h>
#include <TokenReader.h> // dvs: for MAX_STRING. Fix.
class MDkeyvalue;
enum GDIV_TYPE
{
ivBadType = -1,
ivAngle,
ivTargetDest,
ivTargetNameOrClass,
ivTargetSrc,
ivInteger,
ivString,
ivChoices,
ivFlags,
ivDecal,
ivColor255, // components are 0-255
ivColor1, // components are 0-1
ivStudioModel,
ivSprite,
ivSound,
ivVector,
ivNPCClass,
ivFilterClass,
ivFloat,
ivMaterial,
ivScene,
ivSide, // One brush face ID.
ivSideList, // One or more brush face IDs, space delimited.
ivOrigin, // The origin of an entity, in the form "x y z".
ivVecLine, // An origin that draws a line back to the parent entity.
ivAxis, // The axis of rotation for a rotating entity, in the form "x0 y0 z0, x1 y1 z1".
ivPointEntityClass,
ivNodeDest,
ivInstanceFile, // used for hammer to know this field should display a browse button to find map files
ivAngleNegativePitch, // used for instance rotating when just a pitch value is present
ivInstanceVariable, // used for instance variables for easy hammer editing
ivInstanceParm, // used for instance parameter declaration
ivMax // count of types
};
//-----------------------------------------------------------------------------
// Defines an element in a choices/flags list. Choices values are strings;
// flags values are integers, hence the iValue and szValue members.
//-----------------------------------------------------------------------------
typedef struct
{
unsigned long iValue; // Bitflag value for ivFlags
char szValue[MAX_STRING]; // String value for ivChoices
char szCaption[MAX_STRING]; // Name of this choice
BOOL bDefault; // Flag set by default?
} GDIVITEM;
class GDinputvariable
{
public:
GDinputvariable();
GDinputvariable( const char *szType, const char *szName );
~GDinputvariable();
BOOL InitFromTokens(TokenReader& tr);
// functions:
inline const char *GetName() { return m_szName; }
inline const char *GetLongName(void) { return m_szLongName; }
inline const char *GetDescription(void);
inline int GetFlagCount() { return m_Items.Count(); }
inline int GetFlagMask(int nFlag);
inline const char *GetFlagCaption(int nFlag);
inline int GetChoiceCount() { return m_Items.Count(); }
inline const char *GetChoiceCaption(int nChoice);
inline GDIV_TYPE GetType() { return m_eType; }
const char *GetTypeText(void);
inline void GetDefault(int *pnStore)
{
pnStore[0] = m_nDefault;
}
inline void GetDefault(char *pszStore)
{
strcpy(pszStore, m_szDefault);
}
GDIV_TYPE GetTypeFromToken(const char *pszToken);
trtoken_t GetStoreAsFromType(GDIV_TYPE eType);
const char *ItemStringForValue(const char *szValue);
const char *ItemValueForString(const char *szString);
BOOL IsFlagSet(unsigned int);
void SetFlag(unsigned int, BOOL bSet);
void ResetDefaults();
void ToKeyValue(MDkeyvalue* pkv);
void FromKeyValue(MDkeyvalue* pkv);
inline bool IsReportable(void);
inline bool IsReadOnly(void);
GDinputvariable &operator =(GDinputvariable &Other);
void Merge(GDinputvariable &Other);
static const char *GetVarTypeName( GDIV_TYPE eType );
private:
// for choices/flags:
CUtlVector<GDIVITEM> m_Items;
static char *m_pszEmpty;
char m_szName[MAX_IDENT];
char m_szLongName[MAX_STRING];
char *m_pszDescription;
GDIV_TYPE m_eType;
int m_nDefault;
char m_szDefault[MAX_STRING];
int m_nValue;
char m_szValue[MAX_STRING];
bool m_bReportable;
bool m_bReadOnly;
friend class GDclass;
};
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
const char *GDinputvariable::GetDescription(void)
{
if (m_pszDescription != NULL)
{
return(m_pszDescription);
}
return(m_pszEmpty);
}
//-----------------------------------------------------------------------------
// Purpose: Returns whether or not this variable is read only. Read only variables
// cannot be edited in the Entity Properties dialog.
//-----------------------------------------------------------------------------
bool GDinputvariable::IsReadOnly(void)
{
return(m_bReadOnly);
}
//-----------------------------------------------------------------------------
// Purpose: Returns whether or not this variable should be displayed in the Entity
// Report dialog.
//-----------------------------------------------------------------------------
bool GDinputvariable::IsReportable(void)
{
return(m_bReportable);
}
//-----------------------------------------------------------------------------
// Returns the flag mask (eg 4096) for the flag at the given index. The
// array is packed, so it isn't just 1 >> nFlag.
//-----------------------------------------------------------------------------
int GDinputvariable::GetFlagMask(int nFlag)
{
Assert(m_eType == ivFlags);
return m_Items.Element(nFlag).iValue;
}
//-----------------------------------------------------------------------------
// Returns the caption text (eg "Only break on trigger") for the flag at the given index.
//-----------------------------------------------------------------------------
const char *GDinputvariable::GetFlagCaption(int nFlag)
{
Assert(m_eType == ivFlags);
return m_Items.Element(nFlag).szCaption;
}
//-----------------------------------------------------------------------------
// Returns the caption text (eg "Yes") for the choice at the given index.
//-----------------------------------------------------------------------------
const char *GDinputvariable::GetChoiceCaption(int nChoice)
{
Assert(m_eType == ivChoices);
return m_Items.Element(nChoice).szCaption;
}
#endif // GDVAR_H
|