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.

241 lines
5.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef VISGROUP_H
  7. #define VISGROUP_H
  8. #pragma once
  9. #include "BaseTypes.h"
  10. #include "utlvector.h"
  11. class CChunkFile;
  12. class CSaveInfo;
  13. class CMapDoc;
  14. struct LoadVisGroupData_t;
  15. enum ChunkFileResult_t;
  16. enum VisGroupState_t
  17. {
  18. VISGROUP_UNDEFINED = -1, // Used for initialization when updating state
  19. VISGROUP_HIDDEN, // All members are currently hidden
  20. VISGROUP_SHOWN, // All members are currently shown
  21. VISGROUP_PARTIAL, // Some members are currently hidden, some are shown
  22. };
  23. class CVisGroup
  24. {
  25. public:
  26. CVisGroup(void);
  27. inline unsigned int GetID(void) { return(m_dwID); }
  28. inline void SetID(unsigned int dwID) { m_dwID = dwID; }
  29. inline const char *GetName(void)
  30. {
  31. return(m_szName);
  32. }
  33. inline void SetName(const char *pszName)
  34. {
  35. if (pszName != NULL)
  36. {
  37. strncpy(m_szName, pszName, sizeof(m_szName));
  38. }
  39. }
  40. inline color32 GetColor(void);
  41. inline void SetColor(color32 rgbColor);
  42. inline void SetColor(unsigned char red, unsigned char green, unsigned char blue);
  43. inline CVisGroup *GetParent(void);
  44. inline void SetParent(CVisGroup *pNewParent);
  45. inline int GetChildCount(void);
  46. inline CVisGroup *GetChild(int nIndex);
  47. void AddChild(CVisGroup *pChild);
  48. void RemoveChild(CVisGroup *pChild);
  49. bool FindDescendent(CVisGroup *pGroup);
  50. void MoveUp(CVisGroup *pChild);
  51. void MoveDown(CVisGroup *pChild);
  52. bool CanMoveUp(CVisGroup *pChild);
  53. bool CanMoveDown(CVisGroup *pChild);
  54. VisGroupState_t GetVisible(void);
  55. void VisGroups_UpdateParent( VisGroupState_t state );
  56. inline void SetVisible(VisGroupState_t eVisible) { m_eVisible = eVisible; }
  57. static bool IsShowAllActive(void);
  58. static void ShowAllVisGroups(bool bShow);
  59. //
  60. // Serialization.
  61. //
  62. ChunkFileResult_t LoadVMF(CChunkFile *pFile, CMapDoc *pDoc);
  63. ChunkFileResult_t SaveVMF(CChunkFile *pFile, CSaveInfo *pSaveInfo);
  64. static ChunkFileResult_t LoadVisGroupCallback(CChunkFile *pFile, LoadVisGroupData_t *pLoadData);
  65. static ChunkFileResult_t LoadVisGroupsCallback(CChunkFile *pFile, CMapDoc *pDoc);
  66. static bool IsConvertingOldVisGroups();
  67. bool IsAutoVisGroup(void);
  68. void SetAuto( bool bAuto );
  69. protected:
  70. CUtlVector<CVisGroup *> m_Children;
  71. CVisGroup *m_pParent;
  72. bool m_bIsAuto;
  73. static ChunkFileResult_t LoadKeyCallback(const char *szKey, const char *szValue, CVisGroup *pGroup);
  74. static bool s_bShowAll;
  75. static bool s_bIsConvertingOldVisGroups;
  76. char m_szName[128];
  77. color32 m_rgbColor;
  78. unsigned int m_dwID;
  79. VisGroupState_t m_eVisible;
  80. };
  81. //-----------------------------------------------------------------------------
  82. // Purpose: Returns the render color of this visgroup.
  83. //-----------------------------------------------------------------------------
  84. inline color32 CVisGroup::GetColor(void)
  85. {
  86. return m_rgbColor;
  87. }
  88. //-----------------------------------------------------------------------------
  89. // Purpose: Sets the color of this visgroup.
  90. //-----------------------------------------------------------------------------
  91. inline void CVisGroup::SetColor(color32 rgbColor)
  92. {
  93. m_rgbColor = rgbColor;
  94. }
  95. //-----------------------------------------------------------------------------
  96. // Purpose: Sets the color of this visgroup using RGB values.
  97. //-----------------------------------------------------------------------------
  98. inline void CVisGroup::SetColor(unsigned char red, unsigned char green, unsigned char blue)
  99. {
  100. m_rgbColor.r = red;
  101. m_rgbColor.g = green;
  102. m_rgbColor.b = blue;
  103. m_rgbColor.a = 0;
  104. }
  105. //-----------------------------------------------------------------------------
  106. // Purpose: Returns the number of visgroups that are children of this visgroup.
  107. //-----------------------------------------------------------------------------
  108. inline int CVisGroup::GetChildCount(void)
  109. {
  110. return m_Children.Count();
  111. }
  112. //-----------------------------------------------------------------------------
  113. // Purpose: Returns the given child visgroup.
  114. //-----------------------------------------------------------------------------
  115. inline CVisGroup *CVisGroup::GetChild(int nIndex)
  116. {
  117. return m_Children.Element(nIndex);
  118. }
  119. //-----------------------------------------------------------------------------
  120. // Purpose: Returns this visgroup's parent in the hierarchy.
  121. //-----------------------------------------------------------------------------
  122. inline CVisGroup *CVisGroup::GetParent(void)
  123. {
  124. return m_pParent;
  125. }
  126. //-----------------------------------------------------------------------------
  127. // Purpose:
  128. //-----------------------------------------------------------------------------
  129. inline void CVisGroup::SetParent(CVisGroup *pNewParent)
  130. {
  131. m_pParent = pNewParent;
  132. }
  133. //-----------------------------------------------------------------------------
  134. // A list of visgroups.
  135. //-----------------------------------------------------------------------------
  136. class CVisGroupList
  137. {
  138. public:
  139. inline int AddToTail(CVisGroup *pVisGroup);
  140. inline int Count(void);
  141. inline CVisGroup *Element(int nElement);
  142. inline int Find(CVisGroup *pVisGroup);
  143. inline void FastRemove(int nElement);
  144. inline void RemoveAll(void);
  145. private:
  146. CUtlVector<CVisGroup *> m_List;
  147. };
  148. int CVisGroupList::AddToTail(CVisGroup *pVisGroup)
  149. {
  150. return m_List.AddToTail(pVisGroup);
  151. }
  152. int CVisGroupList::Count(void)
  153. {
  154. return m_List.Count();
  155. }
  156. CVisGroup *CVisGroupList::Element(int nElement)
  157. {
  158. return m_List.Element(nElement);
  159. }
  160. int CVisGroupList::Find(CVisGroup *pVisGroup)
  161. {
  162. return m_List.Find(pVisGroup);
  163. }
  164. inline void CVisGroupList::FastRemove(int nElement)
  165. {
  166. m_List.FastRemove(nElement);
  167. }
  168. inline void CVisGroupList::RemoveAll(void)
  169. {
  170. m_List.RemoveAll();
  171. }
  172. #endif // VISGROUP_H