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.

184 lines
4.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "hudelement.h"
  8. #include <vgui_controls/EditablePanel.h>
  9. #include <vgui_controls/ImagePanel.h>
  10. #include <vgui/ISurface.h>
  11. #include "c_dod_player.h"
  12. #include "clientmode_dod.h"
  13. #include "dodcornercutpanel.h"
  14. #include "c_dod_objective_resource.h"
  15. #include "c_dod_playerresource.h"
  16. #include "dod_hud_playerstatus_ammo.h"
  17. #include "dod_hud_playerstatus_health.h"
  18. #include "dod_hud_playerstatus_weapon.h"
  19. #include "dod_hud_playerstatus_stamina.h"
  20. #include "dod_hud_playerstatus_mgheat.h"
  21. #include "dod_hud_playerstatus_fireselect.h"
  22. #include "dod_hud_playerstatus_tnt.h"
  23. class CDoDHudPlayerStatusPanel : public CHudElement, public vgui::EditablePanel
  24. {
  25. public:
  26. DECLARE_CLASS_SIMPLE( CDoDHudPlayerStatusPanel, vgui::EditablePanel );
  27. CDoDHudPlayerStatusPanel( const char *pElementName );
  28. virtual void Init();
  29. virtual void OnThink();
  30. virtual void PerformLayout();
  31. virtual void ApplySchemeSettings( IScheme *pScheme );
  32. private:
  33. CDoDCutEditablePanel *m_pMainBar;
  34. ImagePanel *m_pAlliesIcon;
  35. ImagePanel *m_pAxisIcon;
  36. CDoDHudAmmo *m_pAmmoStatus;
  37. CDoDHudHealth *m_pHealthStatus;
  38. CDoDHudCurrentWeapon *m_pCurrentWeapon;
  39. CDoDHudStamina *m_pStamina;
  40. CDoDHudMGHeat *m_pMGHeat;
  41. CDoDHudFireSelect *m_pFireSelect;
  42. CDoDHudTNT *m_pTNT;
  43. };
  44. DECLARE_HUDELEMENT( CDoDHudPlayerStatusPanel );
  45. //-----------------------------------------------------------------------------
  46. // Purpose: Constructor
  47. //-----------------------------------------------------------------------------
  48. CDoDHudPlayerStatusPanel::CDoDHudPlayerStatusPanel( const char *pElementName ) : CHudElement( pElementName ), BaseClass( NULL, "HudPlayerStatusPanel" )
  49. {
  50. SetParent( g_pClientMode->GetViewport() );
  51. m_pMainBar = new CDoDCutEditablePanel( this, "PlayerStatusMainBackground" );
  52. m_pAlliesIcon = new ImagePanel( this, "PlayerStatusAlliesIcon" );
  53. m_pAxisIcon = new ImagePanel( this, "PlayerStatusAxisIcon" );
  54. m_pAmmoStatus = new CDoDHudAmmo( this, "PlayerStatusAmmo" );
  55. m_pCurrentWeapon = new CDoDHudCurrentWeapon( this, "PlayerStatusCurrentWeapon" );
  56. m_pHealthStatus = new CDoDHudHealth( this, "PlayerStatusHealth" );
  57. m_pStamina = new CDoDHudStamina( this, "PlayerStatusStamina" );
  58. m_pMGHeat = new CDoDHudMGHeat( this, "PlayerStatusMGHeat" );
  59. m_pFireSelect = new CDoDHudFireSelect( this, "PlayerStatusFireSelect" );
  60. m_pTNT = new CDoDHudTNT( this, "PlayerStatusTNT" );
  61. }
  62. void CDoDHudPlayerStatusPanel::ApplySchemeSettings( IScheme *pScheme )
  63. {
  64. // load control settings...
  65. LoadControlSettings( "resource/UI/HudPlayerStatusPanel.res" );
  66. BaseClass::ApplySchemeSettings( pScheme );
  67. }
  68. //-----------------------------------------------------------------------------
  69. // Purpose:
  70. //-----------------------------------------------------------------------------
  71. void CDoDHudPlayerStatusPanel::Init()
  72. {
  73. if ( m_pMainBar )
  74. {
  75. m_pMainBar->SetVisible( true );
  76. }
  77. if ( m_pStamina )
  78. {
  79. m_pStamina->SetVisible( true );
  80. }
  81. if ( m_pAlliesIcon )
  82. {
  83. m_pAlliesIcon->SetVisible( false );
  84. }
  85. if ( m_pAxisIcon )
  86. {
  87. m_pAxisIcon->SetVisible( false );
  88. }
  89. }
  90. //-----------------------------------------------------------------------------
  91. // Purpose:
  92. //-----------------------------------------------------------------------------
  93. void CDoDHudPlayerStatusPanel::PerformLayout()
  94. {
  95. BaseClass::PerformLayout();
  96. int x, y, w, t;
  97. GetBounds( x, y, w, t );
  98. if ( w != ScreenWidth() )
  99. {
  100. // doing this because of the 16:9 and 16:10 resolutions (VGUI doesn't scale properly for them)
  101. SetBounds( x, y, ScreenWidth(), t );
  102. }
  103. }
  104. //-----------------------------------------------------------------------------
  105. // Purpose:
  106. //-----------------------------------------------------------------------------
  107. void CDoDHudPlayerStatusPanel::OnThink()
  108. {
  109. BaseClass::OnThink();
  110. C_DODPlayer *pPlayer = C_DODPlayer::GetLocalDODPlayer();
  111. if ( pPlayer )
  112. {
  113. // turn off the panel and children if the player is dead
  114. if ( !pPlayer->IsAlive() )
  115. {
  116. if ( IsVisible() )
  117. {
  118. SetVisible( false );
  119. }
  120. return;
  121. }
  122. else
  123. {
  124. if ( !IsVisible() )
  125. {
  126. SetVisible( true );
  127. }
  128. }
  129. // set our team icon
  130. int nTeam = pPlayer->GetTeamNumber();
  131. switch( nTeam )
  132. {
  133. case TEAM_AXIS:
  134. if ( m_pAlliesIcon && m_pAlliesIcon->IsVisible() )
  135. {
  136. m_pAlliesIcon->SetVisible( false );
  137. }
  138. if ( m_pAxisIcon && !m_pAxisIcon->IsVisible() )
  139. {
  140. m_pAxisIcon->SetVisible( true );
  141. }
  142. break;
  143. case TEAM_ALLIES:
  144. default:
  145. if ( m_pAlliesIcon && !m_pAlliesIcon->IsVisible() )
  146. {
  147. m_pAlliesIcon->SetVisible( true );
  148. }
  149. if ( m_pAxisIcon && m_pAxisIcon->IsVisible() )
  150. {
  151. m_pAxisIcon->SetVisible( false );
  152. }
  153. break;
  154. }
  155. }
  156. }