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.

177 lines
5.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef TF_HUD_TARGET_ID_H
  7. #define TF_HUD_TARGET_ID_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "hud.h"
  12. #include "hudelement.h"
  13. #include <vgui_controls/EditablePanel.h>
  14. #include "tf_imagepanel.h"
  15. #include "tf_spectatorgui.h"
  16. #include "c_tf_player.h"
  17. #include "IconPanel.h"
  18. class CFloatingHealthIcon;
  19. class CAvatarImagePanel;
  20. #define PLAYER_HINT_DISTANCE 150
  21. #define PLAYER_HINT_DISTANCE_SQ (PLAYER_HINT_DISTANCE*PLAYER_HINT_DISTANCE)
  22. #define MAX_ID_STRING 256
  23. #define MAX_PREPEND_STRING 32
  24. //-----------------------------------------------------------------------------
  25. // Purpose:
  26. //-----------------------------------------------------------------------------
  27. class CTargetID : public CHudElement, public vgui::EditablePanel
  28. {
  29. DECLARE_CLASS_SIMPLE( CTargetID, vgui::EditablePanel );
  30. public:
  31. CTargetID( const char *pElementName );
  32. virtual void LevelShutdown( void );
  33. void Reset( void );
  34. void VidInit( void );
  35. virtual bool ShouldDraw( void );
  36. virtual void PerformLayout( void );
  37. virtual void ApplySettings( KeyValues *inResourceData );
  38. virtual void ApplySchemeSettings( vgui::IScheme *scheme );
  39. void UpdateID( void );
  40. virtual int CalculateTargetIndex( C_TFPlayer *pLocalTFPlayer );
  41. virtual wchar_t *GetPrepend( void ) { return NULL; }
  42. int GetTargetIndex( void ) { return m_iTargetEntIndex; }
  43. virtual int GetRenderGroupPriority( void );
  44. virtual void FireGameEvent( IGameEvent * event );
  45. virtual bool DrawHealthIcon();
  46. virtual C_TFPlayer *GetTargetForSteamAvatar( C_TFPlayer *pTFPlayer );
  47. private:
  48. bool IsValidIDTarget( int nEntIndex, float flOldTargetRetainFOV, float &flNewTargetRetainFOV );
  49. void UpdateFloatingHealthIconVisibility( bool bVisible );
  50. protected:
  51. vgui::HFont m_hFont;
  52. int m_iLastEntIndex;
  53. float m_flLastChangeTime;
  54. float m_flTargetRetainFOV;
  55. int m_iTargetEntIndex;
  56. bool m_bLayoutOnUpdate;
  57. vgui::Label *m_pTargetNameLabel;
  58. vgui::Label *m_pTargetDataLabel;
  59. CTFImagePanel *m_pBGPanel;
  60. vgui::EditablePanel *m_pMoveableSubPanel;
  61. CIconPanel *m_pMoveableIcon;
  62. vgui::ImagePanel *m_pMoveableSymbolIcon;
  63. vgui::Label *m_pMoveableKeyLabel;
  64. CIconPanel *m_pMoveableIconBG;
  65. CTFSpectatorGUIHealth *m_pTargetHealth;
  66. vgui::ImagePanel *m_pTargetAmmoIcon;
  67. vgui::ImagePanel *m_pTargetKillStreakIcon;
  68. CAvatarImagePanel *m_pAvatarImage;
  69. int m_iRenderPriority;
  70. int m_nOriginalY;
  71. Color m_LabelColorDefault;
  72. bool m_bArenaPanelVisible;
  73. CFloatingHealthIcon *m_pFloatingHealthIcon;
  74. int m_iLastScannedEntIndex;
  75. CPanelAnimationVarAliasType( int, m_iXOffset, "x_offset", "20", "proportional_int" );
  76. CPanelAnimationVarAliasType( int, m_iYOffset, "y_offset", "20", "proportional_int" );
  77. };
  78. class CMainTargetID : public CTargetID
  79. {
  80. DECLARE_CLASS_SIMPLE( CMainTargetID, CTargetID );
  81. public:
  82. CMainTargetID( const char *pElementName ) : CTargetID( pElementName ) {}
  83. virtual bool ShouldDraw( void );
  84. };
  85. class CSpectatorTargetID : public CTargetID
  86. {
  87. DECLARE_CLASS_SIMPLE( CSpectatorTargetID, CTargetID );
  88. public:
  89. CSpectatorTargetID( const char *pElementName ) : CTargetID( pElementName ) {}
  90. virtual bool ShouldDraw( void );
  91. virtual int CalculateTargetIndex( C_TFPlayer *pLocalTFPlayer );
  92. virtual void ApplySchemeSettings( vgui::IScheme *scheme );
  93. virtual void PerformLayout( void );
  94. virtual bool DrawHealthIcon() { return true; }
  95. private:
  96. vgui::Panel *m_pBGPanel_Spec_Blue;
  97. vgui::Panel *m_pBGPanel_Spec_Red;
  98. };
  99. //-----------------------------------------------------------------------------
  100. // Purpose: Second target ID that's used for displaying a second target below the primary
  101. //-----------------------------------------------------------------------------
  102. class CSecondaryTargetID : public CTargetID
  103. {
  104. DECLARE_CLASS_SIMPLE( CSecondaryTargetID, CTargetID );
  105. public:
  106. CSecondaryTargetID( const char *pElementName );
  107. virtual bool ShouldDraw( void );
  108. virtual int CalculateTargetIndex( C_TFPlayer *pLocalTFPlayer );
  109. virtual wchar_t *GetPrepend( void ) { return m_wszPrepend; }
  110. virtual bool DrawHealthIcon() { return true; }
  111. private:
  112. wchar_t m_wszPrepend[ MAX_PREPEND_STRING ];
  113. bool m_bWasHidingLowerElements;
  114. };
  115. //-----------------------------------------------------------------------------
  116. // Purpose:
  117. //-----------------------------------------------------------------------------
  118. class CFloatingHealthIcon : public vgui::EditablePanel
  119. {
  120. DECLARE_CLASS_SIMPLE( CFloatingHealthIcon, vgui::EditablePanel );
  121. public:
  122. CFloatingHealthIcon( vgui::Panel *parent, const char *name );
  123. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  124. virtual void OnTick( void );
  125. virtual void Paint( void );
  126. virtual bool IsVisible( void );
  127. virtual void SetVisible( bool state );
  128. void Reset( void );
  129. void SetEntity( C_BaseEntity *pEntity );
  130. C_BaseEntity *GetEntity( void ) { return m_hEntity; }
  131. static CFloatingHealthIcon* AddFloatingHealthIcon( C_BaseEntity *pEntity );
  132. bool CalculatePosition();
  133. private:
  134. CTFSpectatorGUIHealth *m_pTargetHealth;
  135. CHandle< C_BaseEntity > m_hEntity;
  136. float m_flPrevHealth;
  137. int m_nPrevLevel;
  138. };
  139. #endif // TF_HUD_TARGET_ID_H