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.

132 lines
3.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include <KeyValues.h>
  8. #include <vgui/IScheme.h>
  9. #include <vgui/ISurface.h>
  10. #include <vgui/ISystem.h>
  11. #include <vgui_controls/EditablePanel.h>
  12. #include <vgui_controls/ImagePanel.h>
  13. #include <vgui/ISurface.h>
  14. #include "c_dod_player.h"
  15. #include "dodcornercutpanel.h"
  16. #include "dod_hud_playerstatus_tnt.h"
  17. #include "dod_gamerules.h"
  18. #include "clientmode_dod.h"
  19. //-----------------------------------------------------------------------------
  20. // Purpose:
  21. //-----------------------------------------------------------------------------
  22. CDoDHudTNT::CDoDHudTNT( vgui::Panel *parent, const char *name ) : CDoDCutEditablePanel( parent, name )
  23. {
  24. m_pIconTNT = new CIconPanel( this, "Icon_TNT" );
  25. m_pIconTNT_Missing = new CIconPanel( this, "Icon_TNT_Missing" );
  26. SetProportional( true );
  27. LoadControlSettings( "resource/UI/HudPlayerStatusTNT.res" );
  28. m_pIconTNT->SetVisible( false );
  29. m_pIconTNT_Missing->SetVisible( true );
  30. m_bHasTNT = false;
  31. }
  32. //-----------------------------------------------------------------------------
  33. // Purpose:
  34. //-----------------------------------------------------------------------------
  35. void CDoDHudTNT::ApplySchemeSettings( vgui::IScheme *pScheme )
  36. {
  37. LoadControlSettings( "resource/UI/HudPlayerStatusTNT.res" );
  38. BaseClass::ApplySchemeSettings( pScheme );
  39. }
  40. //-----------------------------------------------------------------------------
  41. // Purpose:
  42. //-----------------------------------------------------------------------------
  43. void CDoDHudTNT::ApplySettings( KeyValues *inResourceData )
  44. {
  45. BaseClass::ApplySettings( inResourceData );
  46. // Get icon loc, dims
  47. m_iIconX = vgui::scheme()->GetProportionalScaledValueEx( GetScheme(), inResourceData->GetInt( "icon_x", 0 ) );
  48. m_iIconY = vgui::scheme()->GetProportionalScaledValueEx( GetScheme(), inResourceData->GetInt( "icon_y", 0 ) );
  49. m_iIconW = vgui::scheme()->GetProportionalScaledValueEx( GetScheme(), inResourceData->GetInt( "icon_w", 32 ) );
  50. m_iIconH = vgui::scheme()->GetProportionalScaledValueEx( GetScheme(), inResourceData->GetInt( "icon_h", 32 ) );
  51. }
  52. //-----------------------------------------------------------------------------
  53. // Purpose:
  54. //-----------------------------------------------------------------------------
  55. void CDoDHudTNT::SetVisible( bool state )
  56. {
  57. }
  58. //-----------------------------------------------------------------------------
  59. // Purpose:
  60. //-----------------------------------------------------------------------------
  61. void CDoDHudTNT::OnThink()
  62. {
  63. BaseClass::OnThink();
  64. C_DODPlayer *pPlayer = C_DODPlayer::GetLocalDODPlayer();
  65. if ( !pPlayer )
  66. {
  67. return;
  68. }
  69. if ( DODGameRules()->IsBombingTeam( pPlayer->GetTeamNumber() ) )
  70. {
  71. SetAlpha( 255 );
  72. C_BaseCombatWeapon *pBomb = NULL;
  73. for ( int i = 0; i < MAX_WEAPONS; i++ )
  74. {
  75. C_BaseCombatWeapon *pWeapon = pPlayer->GetWeapon( i );
  76. if ( pWeapon == NULL )
  77. {
  78. continue;
  79. }
  80. if ( pWeapon->GetSlot() == WPN_SLOT_BOMB )
  81. {
  82. pBomb = pWeapon;
  83. break;
  84. }
  85. }
  86. if ( pBomb )
  87. {
  88. if ( m_bHasTNT == false )
  89. {
  90. m_bHasTNT = true;
  91. m_pIconTNT->SetVisible( true );
  92. m_pIconTNT_Missing->SetVisible( false );
  93. }
  94. }
  95. else
  96. {
  97. if ( m_bHasTNT == true )
  98. {
  99. m_bHasTNT = false;
  100. m_pIconTNT->SetVisible( false );
  101. m_pIconTNT_Missing->SetVisible( true );
  102. }
  103. }
  104. }
  105. else
  106. {
  107. SetAlpha( 0 );
  108. }
  109. }