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.

187 lines
5.9 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #if !defined( HUDELEMENT_H )
  8. #define HUDELEMENT_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "hud.h"
  13. #include "hud_element_helper.h"
  14. #include "networkvar.h"
  15. #include "GameEventListener.h"
  16. #include "tier0/memdbgon.h"
  17. #undef new
  18. class CHud;
  19. //-----------------------------------------------------------------------------
  20. // Purpose: Base class for all hud elements
  21. //-----------------------------------------------------------------------------
  22. class CHudElement : public CGameEventListener
  23. {
  24. public:
  25. DECLARE_CLASS_NOBASE( CHudElement );
  26. // constructor - registers object in global list
  27. CHudElement() {}
  28. explicit CHudElement( const char *pElementName );
  29. // destructor - removes object from the global list
  30. virtual ~CHudElement();
  31. virtual void SetHud( CHud *pHud );
  32. // called when the Hud is initialised (whenever the DLL is loaded)
  33. virtual void Init( void ) { return; }
  34. // called whenever the video mode changes, and whenever Init() would be called, so the hud can vid init itself
  35. virtual void VidInit( void ) { return; }
  36. // LevelInit's called whenever a new level's starting
  37. virtual void LevelInit( void ) { return; };
  38. // LevelShutdown's called whenever a level's finishing
  39. virtual void LevelShutdown( void ) { return; };
  40. // called whenever the hud receives "reset" message, which is (usually) every time the client respawns after getting killed
  41. virtual void Reset( void ) { return; }
  42. // Called once per frame for visible elements before general key processing
  43. virtual void ProcessInput( void ) { return; }
  44. // Called once per frame whether the element is visible or not
  45. virtual void Think( void ) {return;}
  46. // Called when time warping occurs, i.e. when instant replay rewinds or forwards client's time
  47. virtual void OnTimeJump( void ){ return; }
  48. //
  49. virtual const char *GetName( void ) const { return m_pElementName; };
  50. // Return true if this hud element should be visible in the current hud state
  51. virtual bool ShouldDraw( void );
  52. virtual bool IsActive( void ) { return m_bActive; };
  53. virtual void SetActive( bool bActive );
  54. // Hidden bits.
  55. // HIDEHUD_ flags that note when this element should be hidden in the HUD
  56. virtual void SetHiddenBits( int iBits );
  57. virtual void SetIgnoreGlobalHudDisable( bool hide );
  58. virtual bool GetIgnoreGlobalHudDisable( void );
  59. bool IsParentedToClientDLLRootPanel() const;
  60. void SetParentedToClientDLLRootPanel( bool parented );
  61. // Return true if this HUD element expects an entry in HudLayout.res
  62. virtual bool WantsHudLayoutEntry( void ) const { return true; }
  63. // memory handling, uses calloc so members are zero'd out on instantiation
  64. void *operator new( size_t stAllocateBlock )
  65. {
  66. Assert( stAllocateBlock != 0 );
  67. void *pMem = malloc( stAllocateBlock );
  68. memset( pMem, 0, stAllocateBlock );
  69. return pMem;
  70. }
  71. void* operator new( size_t stAllocateBlock, int nBlockUse, const char *pFileName, int nLine )
  72. {
  73. Assert( stAllocateBlock != 0 );
  74. void *pMem = MemAlloc_Alloc( stAllocateBlock, pFileName, nLine );
  75. memset( pMem, 0, stAllocateBlock );
  76. return pMem;
  77. }
  78. void operator delete( void *pMem )
  79. {
  80. #if defined( _DEBUG )
  81. int size = _msize( pMem );
  82. memset( pMem, 0xcd, size );
  83. #endif
  84. free( pMem );
  85. }
  86. void operator delete( void *pMem, int nBlockUse, const char *pFileName, int nLine )
  87. {
  88. operator delete( pMem );
  89. }
  90. void SetNeedsRemove( bool needsremove );
  91. void RegisterForRenderGroup( const char *pszName );
  92. void UnregisterForRenderGroup( const char *pszGroupName );
  93. void HideLowerPriorityHudElementsInGroup( const char *pszGroupName );
  94. void UnhideLowerPriorityHudElementsInGroup( const char *pszGroupName );
  95. // For now, CHUdElements declare a single priority value. They will only be hidden
  96. // by panels with a lower priority and will only lock out panels with a lower priority
  97. virtual int GetRenderGroupPriority();
  98. void SetSplitScreenPlayerSlot( int nSlot );
  99. int GetSplitScreenPlayerSlot() const;
  100. virtual void OnSplitScreenStateChanged() {}
  101. public: // IGameEventListener Interface
  102. virtual void FireGameEvent( IGameEvent * event ) {}
  103. protected:
  104. void InitCHudElementAfterConstruction( const char* pElementName );
  105. public:
  106. // True if this element is visible, and should think
  107. bool m_bActive;
  108. // m_bWantLateUpdate defaults to false. Set this to true if you need to position something based on the
  109. // position of a player or other moving game actor.
  110. // When true, your Think and ProcessInput functions will be called after the simulation updates this means
  111. // that the Flash VM will not have a chance to run until after the frame has been rendered. This is
  112. //probably not a big deal, but is good to know.
  113. bool m_bWantLateUpdate;
  114. protected:
  115. int m_iHiddenBits;
  116. int m_nSplitScreenPlayerSlot;
  117. bool m_ignoreGlobalHudDisable;
  118. private:
  119. const char *m_pElementName;
  120. bool m_bNeedsRemove;
  121. bool m_bIsParentedToClientDLLRootPanel;
  122. CUtlVector< int > m_HudRenderGroups;
  123. CHud *m_pHud;
  124. };
  125. #include "utlpriorityqueue.h"
  126. inline bool RenderGroupLessFunc( CHudElement * const &lhs, CHudElement * const &rhs )
  127. {
  128. return ( lhs->GetRenderGroupPriority() < rhs->GetRenderGroupPriority() );
  129. }
  130. // hud elements declare themselves to be part of a hud render group, by name
  131. // we register with each hudelement a list of indeces of groups they are in
  132. // then they can query by index the state of their render group
  133. class CHudRenderGroup
  134. {
  135. public:
  136. CHudRenderGroup()
  137. {
  138. m_pLockingElements.SetLessFunc( RenderGroupLessFunc );
  139. bHidden = false;
  140. }
  141. bool bHidden;
  142. CUtlPriorityQueue< CHudElement * > m_pLockingElements;
  143. };
  144. #include "tier0/memdbgoff.h"
  145. #endif // HUDELEMENT_H