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.

154 lines
4.6 KiB

  1. //========= Copyright 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. //-----------------------------------------------------------------------------
  19. // Purpose: Base class for all hud elements
  20. //-----------------------------------------------------------------------------
  21. class CHudElement : public CGameEventListener
  22. {
  23. public:
  24. DECLARE_CLASS_NOBASE( CHudElement );
  25. // constructor - registers object in global list
  26. CHudElement( const char *pElementName );
  27. // destructor - removes object from the global list
  28. virtual ~CHudElement();
  29. // called when the Hud is initialised (whenever the DLL is loaded)
  30. virtual void Init( void ) { return; }
  31. // called whenever the video mode changes, and whenever Init() would be called, so the hud can vid init itself
  32. virtual void VidInit( void ) { return; }
  33. // LevelInit's called whenever a new level is starting
  34. virtual void LevelInit( void ) { return; };
  35. // LevelShutdown's called whenever a level is finishing
  36. virtual void LevelShutdown( void ) { return; };
  37. // called whenever the hud receives "reset" message, which is (usually) every time the client respawns after getting killed
  38. virtual void Reset( void ) { return; }
  39. // Called once per frame for visible elements before general key processing
  40. virtual void ProcessInput( void ) { return; }
  41. //
  42. virtual const char *GetName( void ) const { return m_pElementName; };
  43. // Return true if this hud element should be visible in the current hud state
  44. virtual bool ShouldDraw( void );
  45. virtual bool IsActive( void ) { return m_bActive; };
  46. virtual void SetActive( bool bActive );
  47. virtual GameActionSet_t GetPreferredActionSet() { return GAME_ACTION_SET_NONE; }
  48. // Hidden bits.
  49. // HIDEHUD_ flags that note when this element should be hidden in the HUD
  50. virtual void SetHiddenBits( int iBits );
  51. bool IsParentedToClientDLLRootPanel() const;
  52. void SetParentedToClientDLLRootPanel( bool parented );
  53. // memory handling, uses calloc so members are zero'd out on instantiation
  54. void *operator new( size_t stAllocateBlock )
  55. {
  56. Assert( stAllocateBlock != 0 );
  57. void *pMem = malloc( stAllocateBlock );
  58. memset( pMem, 0, stAllocateBlock );
  59. return pMem;
  60. }
  61. void* operator new( size_t stAllocateBlock, int nBlockUse, const char *pFileName, int nLine )
  62. {
  63. Assert( stAllocateBlock != 0 );
  64. void *pMem = MemAlloc_Alloc( stAllocateBlock, pFileName, nLine );
  65. memset( pMem, 0, stAllocateBlock );
  66. return pMem;
  67. }
  68. void operator delete( void *pMem )
  69. {
  70. #if defined( _DEBUG )
  71. int size = _msize( pMem );
  72. memset( pMem, 0xcd, size );
  73. #endif
  74. free( pMem );
  75. }
  76. void operator delete( void *pMem, int nBlockUse, const char *pFileName, int nLine )
  77. {
  78. operator delete( pMem );
  79. }
  80. void SetNeedsRemove( bool needsremove );
  81. void RegisterForRenderGroup( const char *pszName );
  82. void UnregisterForRenderGroup( const char *pszGroupName );
  83. void HideLowerPriorityHudElementsInGroup( const char *pszGroupName );
  84. void UnhideLowerPriorityHudElementsInGroup( const char *pszGroupName );
  85. // For now, CHUdElements declare a single priority value. They will only be hidden
  86. // by panels with a lower priority and will only lock out panels with a lower priority
  87. virtual int GetRenderGroupPriority();
  88. public: // IGameEventListener Interface
  89. virtual void FireGameEvent( IGameEvent * event ) {}
  90. public:
  91. // True if this element is visible, and should think
  92. bool m_bActive;
  93. protected:
  94. int m_iHiddenBits;
  95. private:
  96. const char *m_pElementName;
  97. bool m_bNeedsRemove;
  98. bool m_bIsParentedToClientDLLRootPanel;
  99. CUtlVector< int > m_HudRenderGroups;
  100. };
  101. #include "utlpriorityqueue.h"
  102. inline bool RenderGroupLessFunc( CHudElement * const &lhs, CHudElement * const &rhs )
  103. {
  104. return ( lhs->GetRenderGroupPriority() < rhs->GetRenderGroupPriority() );
  105. }
  106. // hud elements declare themselves to be part of a hud render group, by name
  107. // we register with each hudelement a list of indeces of groups they are in
  108. // then they can query by index the state of their render group
  109. class CHudRenderGroup
  110. {
  111. public:
  112. CHudRenderGroup()
  113. {
  114. m_pLockingElements.SetLessFunc( RenderGroupLessFunc );
  115. bHidden = false;
  116. }
  117. bool bHidden;
  118. CUtlPriorityQueue< CHudElement * > m_pLockingElements;
  119. };
  120. #include "tier0/memdbgoff.h"
  121. #endif // HUDELEMENT_H