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.

155 lines
4.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #include "cbase.h"
  8. #include "hud.h"
  9. #include "hudelement.h"
  10. #include "iclientmode.h"
  11. #include "ienginevgui.h"
  12. #include <vgui/ILocalize.h>
  13. #include <vgui/ISurface.h>
  14. #include <vgui/IVGui.h>
  15. #include <vgui_controls/EditablePanel.h>
  16. #include <vgui_controls/ImagePanel.h>
  17. #include <vgui_controls/ProgressBar.h>
  18. #include "c_monster_resource.h"
  19. #include "tf_hud_boss_health.h"
  20. // memdbgon must be the last include file in a .cpp file!!!
  21. #include "tier0/memdbgon.h"
  22. using namespace vgui;
  23. DECLARE_HUDELEMENT( CHudBossHealthMeter );
  24. ConVar cl_boss_show_stun( "cl_boss_show_stun", "0", FCVAR_DEVELOPMENTONLY );
  25. //-----------------------------------------------------------------------------
  26. CHudBossHealthMeter::CHudBossHealthMeter( const char *pElementName ) : CHudElement( pElementName ), BaseClass( NULL, "HudBossHealth" )
  27. {
  28. Panel *pParent = g_pClientMode->GetViewport();
  29. SetParent( pParent );
  30. m_pStunMeter = NULL;
  31. m_pHealthBarPanel = new vgui::EditablePanel( this, "HealthBarPanel" );
  32. SetHiddenBits( HIDEHUD_MISCSTATUS );
  33. m_inactiveColor = Color( 0, 255, 0, 255 );
  34. vgui::ivgui()->AddTickSignal( GetVPanel() );
  35. }
  36. //-----------------------------------------------------------------------------
  37. void CHudBossHealthMeter::ApplySchemeSettings( IScheme *pScheme )
  38. {
  39. // load control settings...
  40. LoadControlSettings( "resource/UI/HudBossHealth.res" );
  41. m_pStunMeter = dynamic_cast< ContinuousProgressBar * >( FindChildByName( "StunMeter" ) );
  42. //BarImage
  43. m_pBarImagePanel = dynamic_cast<ImagePanel*>( m_pHealthBarPanel->FindChildByName( "BarImage" ) );
  44. m_bossActiveBarColor = m_pBarImagePanel ? m_pBarImagePanel->GetDrawColor() : m_inactiveColor;
  45. // BorderImage
  46. m_pBorderImagePanel = dynamic_cast< ImagePanel* >( FindChildByName( "BorderImage" ) );
  47. m_bossActiveBorderColor = m_pBorderImagePanel ? m_pBorderImagePanel->GetDrawColor() : m_inactiveColor;
  48. BaseClass::ApplySchemeSettings( pScheme );
  49. }
  50. //-----------------------------------------------------------------------------
  51. void CHudBossHealthMeter::Init( void )
  52. {
  53. }
  54. //-----------------------------------------------------------------------------
  55. bool CHudBossHealthMeter::ShouldDraw( void )
  56. {
  57. CBasePlayer *pPlayer = CBasePlayer::GetLocalPlayer();
  58. if ( !pPlayer || pPlayer->GetObserverMode() == OBS_MODE_FREEZECAM )
  59. {
  60. return false;
  61. }
  62. if ( CHudElement::ShouldDraw() && g_pMonsterResource )
  63. {
  64. return g_pMonsterResource->GetBossHealthPercentage() > 0.0f ? true : false;
  65. }
  66. if ( pPlayer->GetTeamNumber() <= TEAM_SPECTATOR )
  67. {
  68. return false;
  69. }
  70. return false;
  71. }
  72. void CHudBossHealthMeter::OnTick( void )
  73. {
  74. int nXPos, nYPos;
  75. GetPos( nXPos, nYPos );
  76. nYPos = m_nHealthDeadPosY;
  77. C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
  78. if ( pPlayer && !pPlayer->IsObserver() )
  79. {
  80. nYPos = m_nHealthAlivePosY;
  81. }
  82. SetPos( nXPos, nYPos );
  83. }
  84. //-----------------------------------------------------------------------------
  85. // Update HUD due to data changes
  86. void CHudBossHealthMeter::Update( void )
  87. {
  88. if ( g_pMonsterResource )
  89. {
  90. m_pHealthBarPanel->SetWide( m_nHealthBarWide * g_pMonsterResource->GetBossHealthPercentage() );
  91. if ( m_pStunMeter )
  92. {
  93. float stun = g_pMonsterResource->GetBossStunPercentage();
  94. if ( stun > 0.0f && cl_boss_show_stun.GetBool() )
  95. {
  96. if ( !m_pStunMeter->IsVisible() )
  97. {
  98. m_pStunMeter->SetVisible( true );
  99. }
  100. m_pStunMeter->SetProgress( g_pMonsterResource->GetBossStunPercentage() );
  101. }
  102. else if ( m_pStunMeter->IsVisible() )
  103. {
  104. m_pStunMeter->SetVisible( false );
  105. }
  106. }
  107. int iState = g_pMonsterResource->GetBossState();
  108. if ( m_pBarImagePanel )
  109. {
  110. Color barColor = ( iState == 0 ) ? m_bossActiveBarColor : m_inactiveColor;
  111. m_pBarImagePanel->SetDrawColor( barColor );
  112. }
  113. if ( m_pBorderImagePanel )
  114. {
  115. Color borderColor = ( iState == 0 ) ? m_bossActiveBorderColor : m_inactiveColor;
  116. m_pBorderImagePanel->SetDrawColor( borderColor );
  117. }
  118. }
  119. }