Team Fortress 2 Source Code as on 22/4/2020
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.

219 lines
5.8 KiB

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