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.

121 lines
2.3 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/Panel.h>
  9. #include <vgui/ISurface.h>
  10. #include "c_dod_player.h"
  11. #include "iclientmode.h"
  12. #include "c_dod_playerresource.h"
  13. #include "weapon_mg42.h"
  14. class CHudMGHeatIcon : public CHudElement, public vgui::Panel
  15. {
  16. public:
  17. DECLARE_CLASS_SIMPLE( CHudMGHeatIcon, vgui::Panel );
  18. CHudMGHeatIcon( const char *name );
  19. virtual void Paint();
  20. virtual void Init();
  21. virtual bool ShouldDraw();
  22. private:
  23. CHudTexture *m_pBarrel;
  24. CHudTexture *m_pHotBarrel;
  25. Color m_clrIcon;
  26. };
  27. DECLARE_HUDELEMENT( CHudMGHeatIcon );
  28. CHudMGHeatIcon::CHudMGHeatIcon( const char *pName ) :
  29. vgui::Panel( NULL, "HudMGHeatIcon" ), CHudElement( pName )
  30. {
  31. SetParent( g_pClientMode->GetViewport() );
  32. m_clrIcon = Color(255,255,255,255);
  33. SetHiddenBits( HIDEHUD_PLAYERDEAD );
  34. }
  35. void CHudMGHeatIcon::Init()
  36. {
  37. if( !m_pBarrel )
  38. {
  39. m_pBarrel = gHUD.GetIcon( "hud_barrel" );
  40. }
  41. if( !m_pHotBarrel )
  42. {
  43. m_pHotBarrel = gHUD.GetIcon( "hud_barrelo" );
  44. }
  45. }
  46. bool CHudMGHeatIcon::ShouldDraw()
  47. {
  48. C_DODPlayer *pPlayer = C_DODPlayer::GetLocalDODPlayer();
  49. if( !pPlayer )
  50. return false;
  51. //is their active weapon an mg42 ?
  52. CWeaponDODBase *pWeapon = pPlayer->GetActiveDODWeapon();
  53. if( pWeapon && pWeapon->IsA( WEAPON_MG42 ) )
  54. return true;
  55. return false;
  56. }
  57. void CHudMGHeatIcon::Paint()
  58. {
  59. int x,y,w,h;
  60. GetBounds( x,y,w,h );
  61. if( !m_pBarrel )
  62. {
  63. m_pBarrel = gHUD.GetIcon( "hud_barrel" );
  64. }
  65. if( !m_pHotBarrel )
  66. {
  67. m_pHotBarrel = gHUD.GetIcon( "hud_barrelo" );
  68. }
  69. //draw the base
  70. m_pBarrel->DrawSelf( 0, 0, m_clrIcon );
  71. float flPercentHotness = 0.0f;
  72. C_DODPlayer *pPlayer = C_DODPlayer::GetLocalDODPlayer();
  73. if( !pPlayer )
  74. return;
  75. CWeaponDODBase *pWeapon = pPlayer->GetActiveDODWeapon();
  76. if( pWeapon && pWeapon->IsA( WEAPON_MG42 ) )
  77. {
  78. CWeaponMG42 *pMG42 = (CWeaponMG42 *)pWeapon;
  79. if( pMG42 )
  80. {
  81. flPercentHotness = (float)pMG42->GetWeaponHeat() / 100.0;
  82. }
  83. }
  84. int nOffset = m_pHotBarrel->Height() * ( 1.0 - flPercentHotness );
  85. if ( nOffset < m_pHotBarrel->Height() )
  86. {
  87. m_pHotBarrel->DrawSelfCropped( 0, nOffset, 0, nOffset, m_pHotBarrel->Width(), m_pHotBarrel->Height() - nOffset, m_clrIcon );
  88. }
  89. }