Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

225 lines
6.0 KiB

  1. //========= Copyright (c) 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef GDVAR_H
  8. #define GDVAR_H
  9. #pragma once
  10. #include <utlvector.h>
  11. #include <tier2/tokenreader.h> // dvs: for MAX_STRING. Fix.
  12. class MDkeyvalue;
  13. enum GDIV_TYPE
  14. {
  15. ivBadType = -1,
  16. ivAngle,
  17. ivTargetDest,
  18. ivTargetNameOrClass,
  19. ivTargetSrc,
  20. ivInteger,
  21. ivString,
  22. ivStringInstanced,
  23. ivChoices,
  24. ivFlags,
  25. ivDecal,
  26. ivColor255, // components are 0-255
  27. ivColor1, // components are 0-1
  28. ivStudioModel,
  29. ivSprite,
  30. ivSound,
  31. ivVector,
  32. ivNPCClass,
  33. ivFilterClass,
  34. ivFloat,
  35. ivMaterial,
  36. ivScene,
  37. ivSide, // One brush face ID.
  38. ivSideList, // One or more brush face IDs, space delimited.
  39. ivOrigin, // The origin of an entity, in the form "x y z".
  40. ivVecLine, // An origin that draws a line back to the parent entity.
  41. ivAxis, // The axis of rotation for a rotating entity, in the form "x0 y0 z0, x1 y1 z1".
  42. ivPointEntityClass,
  43. ivNodeDest,
  44. ivScript,
  45. ivScriptList,
  46. ivParticleSystem,
  47. ivInstanceFile, // used for hammer to know this field should display a browse button to find map files
  48. ivAngleNegativePitch, // used for instance rotating when just a negative pitch value is present ( light_ pitch fields )
  49. ivInstanceVariable, // used for instance variables for easy hammer editing
  50. ivInstanceParm, // used for instance parameter declaration
  51. ivBoolean,
  52. ivNodeID, // used for instance node id remapping
  53. ivMax // count of types
  54. };
  55. //-----------------------------------------------------------------------------
  56. // Defines an element in a choices/flags list. Choices values are strings;
  57. // flags values are integers, hence the iValue and szValue members.
  58. //-----------------------------------------------------------------------------
  59. typedef struct
  60. {
  61. unsigned long iValue; // Bitflag value for ivFlags
  62. char szValue[MAX_STRING]; // String value for ivChoices
  63. char szCaption[MAX_STRING]; // Name of this choice
  64. BOOL bDefault; // Flag set by default?
  65. } GDIVITEM;
  66. class GDinputvariable
  67. {
  68. public:
  69. GDinputvariable();
  70. GDinputvariable( const char *szType, const char *szName );
  71. ~GDinputvariable();
  72. BOOL InitFromTokens(TokenReader& tr);
  73. // functions:
  74. inline const char *GetName() { return m_szName; }
  75. inline const char *GetLongName(void) { return m_szLongName; }
  76. inline const char *GetDescription(void);
  77. inline int GetFlagCount() { return m_Items.Count(); }
  78. inline int GetFlagMask(int nFlag);
  79. inline const char *GetFlagCaption(int nFlag);
  80. inline int GetChoiceCount() { return m_Items.Count(); }
  81. inline const char *GetChoiceCaption(int nChoice);
  82. inline GDIV_TYPE GetType() { return m_eType; }
  83. const char *GetTypeText(void);
  84. inline void GetDefault(int *pnStore)
  85. {
  86. pnStore[0] = m_nDefault;
  87. }
  88. inline void GetDefault(char *pszStore)
  89. {
  90. strcpy(pszStore, m_szDefault);
  91. }
  92. GDIV_TYPE GetTypeFromToken(const char *pszToken);
  93. trtoken_t GetStoreAsFromType(GDIV_TYPE eType);
  94. const char *ItemStringForValue(const char *szValue);
  95. const char *ItemValueForString(const char *szString);
  96. BOOL IsFlagSet(unsigned int);
  97. void SetFlag(unsigned int, BOOL bSet);
  98. void ResetDefaults();
  99. void ToKeyValue(MDkeyvalue* pkv);
  100. void FromKeyValue(MDkeyvalue* pkv);
  101. inline bool IsReportable(void);
  102. inline bool IsReadOnly(void);
  103. GDinputvariable &operator =(GDinputvariable &Other);
  104. void Merge(GDinputvariable &Other);
  105. static const char *GetVarTypeName( GDIV_TYPE eType );
  106. private:
  107. // for choices/flags:
  108. CUtlVector<GDIVITEM> m_Items;
  109. static char *m_pszEmpty;
  110. char m_szName[MAX_IDENT];
  111. char m_szLongName[MAX_STRING];
  112. char *m_pszDescription;
  113. GDIV_TYPE m_eType;
  114. int m_nDefault;
  115. char m_szDefault[MAX_STRING];
  116. int m_nValue;
  117. char m_szValue[MAX_STRING];
  118. bool m_bReportable;
  119. bool m_bReadOnly;
  120. friend class GDclass;
  121. };
  122. //-----------------------------------------------------------------------------
  123. // Purpose:
  124. //-----------------------------------------------------------------------------
  125. const char *GDinputvariable::GetDescription(void)
  126. {
  127. if (m_pszDescription != NULL)
  128. {
  129. return(m_pszDescription);
  130. }
  131. return(m_pszEmpty);
  132. }
  133. //-----------------------------------------------------------------------------
  134. // Purpose: Returns whether or not this variable is read only. Read only variables
  135. // cannot be edited in the Entity Properties dialog.
  136. //-----------------------------------------------------------------------------
  137. bool GDinputvariable::IsReadOnly(void)
  138. {
  139. return(m_bReadOnly);
  140. }
  141. //-----------------------------------------------------------------------------
  142. // Purpose: Returns whether or not this variable should be displayed in the Entity
  143. // Report dialog.
  144. //-----------------------------------------------------------------------------
  145. bool GDinputvariable::IsReportable(void)
  146. {
  147. return(m_bReportable);
  148. }
  149. //-----------------------------------------------------------------------------
  150. // Returns the flag mask (eg 4096) for the flag at the given index. The
  151. // array is packed, so it isn't just 1 >> nFlag.
  152. //-----------------------------------------------------------------------------
  153. int GDinputvariable::GetFlagMask(int nFlag)
  154. {
  155. Assert(m_eType == ivFlags);
  156. return m_Items.Element(nFlag).iValue;
  157. }
  158. //-----------------------------------------------------------------------------
  159. // Returns the caption text (eg "Only break on trigger") for the flag at the given index.
  160. //-----------------------------------------------------------------------------
  161. const char *GDinputvariable::GetFlagCaption(int nFlag)
  162. {
  163. Assert(m_eType == ivFlags);
  164. return m_Items.Element(nFlag).szCaption;
  165. }
  166. //-----------------------------------------------------------------------------
  167. // Returns the caption text (eg "Yes") for the choice at the given index.
  168. //-----------------------------------------------------------------------------
  169. const char *GDinputvariable::GetChoiceCaption(int nChoice)
  170. {
  171. Assert(m_eType == ivChoices);
  172. return m_Items.Element(nChoice).szCaption;
  173. }
  174. #endif // GDVAR_H