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.

1486 lines
40 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #include "cbase.h"
  8. #include "tf_hud_itemeffectmeter.h"
  9. #include "tf_weapon_bat.h"
  10. #include "tf_weapon_jar.h"
  11. #include "tf_weapon_sword.h"
  12. #include "tf_weapon_buff_item.h"
  13. #include "tf_weapon_lunchbox.h"
  14. #include "tf_weapon_shotgun.h"
  15. #include "tf_weapon_sniperrifle.h"
  16. #include "tf_weapon_rocketlauncher.h"
  17. #include "tf_weapon_particle_cannon.h"
  18. #include "tf_weapon_raygun.h"
  19. #include "tf_weapon_flaregun.h"
  20. #include "tf_weapon_revolver.h"
  21. #include "tf_weapon_flamethrower.h"
  22. #include "tf_weapon_knife.h"
  23. #include "tf_item_powerup_bottle.h"
  24. #include "tf_imagepanel.h"
  25. #include "c_tf_weapon_builder.h"
  26. #include "tf_weapon_minigun.h"
  27. #include "tf_weapon_medigun.h"
  28. #include "tf_weapon_throwable.h"
  29. #include "tf_weapon_smg.h"
  30. #include "halloween/tf_weapon_spellbook.h"
  31. #include "tf_logic_halloween_2014.h"
  32. #include <game/client/iviewport.h>
  33. #ifdef STAGING_ONLY
  34. #include "tf_weapon_pda.h"
  35. #endif // STAGING_ONLY
  36. #include <vgui_controls/ImagePanel.h>
  37. // memdbgon must be the last include file in a .cpp file!!!
  38. #include "tier0/memdbgon.h"
  39. #define DECLARE_ITEM_EFFECT_METER( weaponClass, weaponType, beeps, resfile ) \
  40. hNewMeter = new CHudItemEffectMeter_Weapon< weaponClass >( pszElementName, pPlayer, weaponType, beeps, resfile ); \
  41. if ( hNewMeter ) \
  42. { \
  43. gHUD.AddHudElement( hNewMeter ); \
  44. outMeters.AddToHead( hNewMeter ); \
  45. hNewMeter->SetVisible( false ); \
  46. }
  47. using namespace vgui;
  48. IMPLEMENT_AUTO_LIST( IHudItemEffectMeterAutoList );
  49. CItemEffectMeterManager g_ItemEffectMeterManager;
  50. //-----------------------------------------------------------------------------
  51. // Purpose:
  52. //-----------------------------------------------------------------------------
  53. CItemEffectMeterManager::~CItemEffectMeterManager()
  54. {
  55. ClearExistingMeters();
  56. }
  57. //-----------------------------------------------------------------------------
  58. // Purpose:
  59. //-----------------------------------------------------------------------------
  60. void CItemEffectMeterManager::ClearExistingMeters()
  61. {
  62. for ( int i=0; i<m_Meters.Count(); i++ )
  63. {
  64. gHUD.RemoveHudElement( m_Meters[i].Get() );
  65. delete m_Meters[i].Get();
  66. }
  67. m_Meters.RemoveAll();
  68. }
  69. //-----------------------------------------------------------------------------
  70. // Purpose:
  71. //-----------------------------------------------------------------------------
  72. int CItemEffectMeterManager::GetNumEnabled( void )
  73. {
  74. int nCount = 0;
  75. for ( int i = 0; i < m_Meters.Count(); i++ )
  76. {
  77. if ( m_Meters[i] && m_Meters[i]->IsEnabled() )
  78. {
  79. nCount++;
  80. }
  81. }
  82. return nCount;
  83. }
  84. //-----------------------------------------------------------------------------
  85. // Purpose:
  86. //-----------------------------------------------------------------------------
  87. void CItemEffectMeterManager::SetPlayer( C_TFPlayer* pPlayer )
  88. {
  89. StopListeningForAllEvents();
  90. ListenForGameEvent( "post_inventory_application" );
  91. ListenForGameEvent( "localplayer_pickup_weapon" );
  92. ClearExistingMeters();
  93. if ( pPlayer )
  94. {
  95. CHudItemEffectMeter::CreateHudElementsForClass( pPlayer, m_Meters );
  96. }
  97. }
  98. //-----------------------------------------------------------------------------
  99. // Purpose:
  100. //-----------------------------------------------------------------------------
  101. void CItemEffectMeterManager::Update( C_TFPlayer* pPlayer )
  102. {
  103. for ( int i=0; i<m_Meters.Count(); i++ )
  104. {
  105. if ( m_Meters[i] )
  106. {
  107. m_Meters[i]->Update( pPlayer );
  108. }
  109. }
  110. }
  111. //-----------------------------------------------------------------------------
  112. // Purpose:
  113. //-----------------------------------------------------------------------------
  114. void CItemEffectMeterManager::FireGameEvent( IGameEvent *event )
  115. {
  116. const char *type = event->GetName();
  117. bool bNeedsUpdate = false;
  118. if ( FStrEq( "localplayer_pickup_weapon", type ) )
  119. {
  120. bNeedsUpdate = true;
  121. }
  122. else if ( FStrEq( "post_inventory_application", type ) )
  123. {
  124. // Force a refresh. Our items may have changed causing us to now draw, etc.
  125. // This creates a new game logic object which will re-cache necessary item data.
  126. int iUserID = event->GetInt( "userid" );
  127. C_TFPlayer* pPlayer = ToTFPlayer( C_TFPlayer::GetLocalPlayer() );
  128. if ( pPlayer && pPlayer->GetUserID() == iUserID )
  129. {
  130. bNeedsUpdate = true;
  131. }
  132. }
  133. if ( bNeedsUpdate )
  134. {
  135. SetPlayer( C_TFPlayer::GetLocalTFPlayer() );
  136. }
  137. }
  138. //-----------------------------------------------------------------------------
  139. // Purpose:
  140. //-----------------------------------------------------------------------------
  141. CHudItemEffectMeter::CHudItemEffectMeter( const char *pszElementName, C_TFPlayer* pPlayer ) : CHudElement( pszElementName ), BaseClass( NULL, "HudItemEffectMeter" )
  142. {
  143. Panel *pParent = g_pClientMode->GetViewport();
  144. SetParent( pParent );
  145. if ( !m_pProgressBar )
  146. {
  147. m_pProgressBar = new ContinuousProgressBar( this, "ItemEffectMeter" );
  148. }
  149. if ( !m_pLabel )
  150. {
  151. m_pLabel = new Label( this, "ItemEffectMeterLabel", "" );
  152. }
  153. SetHiddenBits( HIDEHUD_MISCSTATUS );
  154. m_pPlayer = pPlayer;
  155. m_bEnabled = true;
  156. m_flOldProgress = 1.f;
  157. RegisterForRenderGroup( "inspect_panel" );
  158. }
  159. //-----------------------------------------------------------------------------
  160. // Purpose:
  161. //-----------------------------------------------------------------------------
  162. CHudItemEffectMeter::~CHudItemEffectMeter()
  163. {
  164. }
  165. //-----------------------------------------------------------------------------
  166. // Purpose:
  167. //-----------------------------------------------------------------------------
  168. void CHudItemEffectMeter::CreateHudElementsForClass( C_TFPlayer* pPlayer, CUtlVector< vgui::DHANDLE< CHudItemEffectMeter > >& outMeters )
  169. {
  170. vgui::DHANDLE< CHudItemEffectMeter > hNewMeter;
  171. const char* pszElementName = "HudItemEffectMeter";
  172. switch ( pPlayer->GetPlayerClass()->GetClassIndex() )
  173. {
  174. case TF_CLASS_SCOUT:
  175. DECLARE_ITEM_EFFECT_METER( CTFBat_Wood, TF_WEAPON_BAT_WOOD, true, NULL );
  176. DECLARE_ITEM_EFFECT_METER( CTFBat_Giftwrap, TF_WEAPON_BAT_GIFTWRAP, true, NULL );
  177. DECLARE_ITEM_EFFECT_METER( CTFLunchBox_Drink, TF_WEAPON_LUNCHBOX, true, "resource/UI/HudItemEffectMeter_Scout.res" );
  178. DECLARE_ITEM_EFFECT_METER( CTFJarMilk, TF_WEAPON_JAR_MILK, true, "resource/UI/HudItemEffectMeter_Scout.res" );
  179. DECLARE_ITEM_EFFECT_METER( CTFSodaPopper, TF_WEAPON_SODA_POPPER, true, "resource/UI/HudItemEffectMeter_SodaPopper.res" );
  180. DECLARE_ITEM_EFFECT_METER( CTFPEPBrawlerBlaster, TF_WEAPON_PEP_BRAWLER_BLASTER, true, "resource/UI/HudItemEffectMeter_SodaPopper.res" );
  181. DECLARE_ITEM_EFFECT_METER( CTFCleaver, TF_WEAPON_CLEAVER, true, "resource/UI/HudItemEffectMeter_Cleaver.res" );
  182. break;
  183. case TF_CLASS_HEAVYWEAPONS:
  184. DECLARE_ITEM_EFFECT_METER( CTFLunchBox, TF_WEAPON_LUNCHBOX, true, NULL );
  185. DECLARE_ITEM_EFFECT_METER( CTFMinigun, TF_WEAPON_MINIGUN, true, "resource/UI/HudItemEffectMeter_Heavy.res" );
  186. break;
  187. case TF_CLASS_SNIPER:
  188. DECLARE_ITEM_EFFECT_METER( CTFJar, TF_WEAPON_JAR, true, NULL );
  189. DECLARE_ITEM_EFFECT_METER( CTFSniperRifleDecap, TF_WEAPON_SNIPERRIFLE_DECAP, false, "resource/UI/HudItemEffectMeter_Sniper.res" );
  190. DECLARE_ITEM_EFFECT_METER( CTFSniperRifle, TF_WEAPON_SNIPERRIFLE, true, "resource/UI/HudItemEffectMeter_SniperFocus.res" );
  191. DECLARE_ITEM_EFFECT_METER( CTFChargedSMG, TF_WEAPON_CHARGED_SMG, false, NULL );
  192. break;
  193. case TF_CLASS_DEMOMAN:
  194. DECLARE_ITEM_EFFECT_METER( CTFSword, TF_WEAPON_SWORD, false, "resource/UI/HudItemEffectMeter_Demoman.res" );
  195. break;
  196. case TF_CLASS_SOLDIER:
  197. DECLARE_ITEM_EFFECT_METER( CTFBuffItem, TF_WEAPON_BUFF_ITEM, true, NULL );
  198. DECLARE_ITEM_EFFECT_METER( CTFParticleCannon, TF_WEAPON_PARTICLE_CANNON, false, "resource/UI/HUDItemEffectMeter_ParticleCannon.res" );
  199. DECLARE_ITEM_EFFECT_METER( CTFRaygun, TF_WEAPON_RAYGUN, false, "resource/UI/HUDItemEffectMeter_Raygun.res" );
  200. DECLARE_ITEM_EFFECT_METER( CTFRocketLauncher_AirStrike, TF_WEAPON_ROCKETLAUNCHER, false, "resource/UI/HudItemEffectMeter_Demoman.res" );
  201. break;
  202. case TF_CLASS_SPY:
  203. DECLARE_ITEM_EFFECT_METER( CTFKnife, TF_WEAPON_KNIFE, true, "resource/UI/HUDItemEffectMeter_SpyKnife.res" );
  204. hNewMeter = new CHudItemEffectMeter( pszElementName, pPlayer );
  205. if ( hNewMeter )
  206. {
  207. gHUD.AddHudElement( hNewMeter );
  208. outMeters.AddToHead( hNewMeter );
  209. hNewMeter->SetVisible( false );
  210. }
  211. #ifdef STAGING_ONLY
  212. //hNewMeter = new CHudItemEffectMeter_Tranq( pszElementName, pPlayer );
  213. //if ( hNewMeter )
  214. //{
  215. // gHUD.AddHudElement( hNewMeter );
  216. // outMeters.AddToHead( hNewMeter );
  217. // hNewMeter->SetVisible( false );
  218. //}
  219. #endif // STAGING_ONLY
  220. DECLARE_ITEM_EFFECT_METER( C_TFWeaponBuilder, TF_WEAPON_BUILDER, true, "resource/UI/HudItemEffectMeter_Sapper.res" );
  221. DECLARE_ITEM_EFFECT_METER( CTFRevolver, TF_WEAPON_REVOLVER, false, "resource/UI/HUDItemEffectMeter_Spy.res" );
  222. #ifdef STAGING_ONLY
  223. DECLARE_ITEM_EFFECT_METER( CTFWeaponPDA_Spy_Build, TF_WEAPON_PDA_SPY_BUILD, false, "resource/UI/HudItemEffectMeter_Spy_Build.res" );
  224. #endif // STAGING_ONLY
  225. break;
  226. case TF_CLASS_ENGINEER:
  227. DECLARE_ITEM_EFFECT_METER( CTFShotgun_Revenge, TF_WEAPON_SENTRY_REVENGE, false, "resource/UI/HUDItemEffectMeter_Engineer.res" );
  228. DECLARE_ITEM_EFFECT_METER( CTFDRGPomson, TF_WEAPON_DRG_POMSON, false, "resource/UI/HUDItemEffectMeter_Pomson.res" );
  229. DECLARE_ITEM_EFFECT_METER( CTFRevolver, TF_WEAPON_REVOLVER, false, "resource/UI/HUDItemEffectMeter_Spy.res" );
  230. break;
  231. case TF_CLASS_PYRO:
  232. DECLARE_ITEM_EFFECT_METER( CTFFlameThrower, TF_WEAPON_FLAMETHROWER, true, NULL );
  233. DECLARE_ITEM_EFFECT_METER( CTFFlareGun_Revenge, TF_WEAPON_FLAREGUN_REVENGE, false, "resource/UI/HUDItemEffectMeter_Engineer.res" );
  234. break;
  235. case TF_CLASS_MEDIC:
  236. #ifdef STAGING_ONLY
  237. DECLARE_ITEM_EFFECT_METER( CTFCrossbow, TF_WEAPON_CROSSBOW, true, "resource/UI/HudItemEffectMeter_SodaPopper.res" );
  238. #endif // STAGING_ONLY
  239. DECLARE_ITEM_EFFECT_METER( CWeaponMedigun, TF_WEAPON_MEDIGUN, true, "resource/UI/HudItemEffectMeter_Scout.res" );
  240. break;
  241. }
  242. // ALL CLASS
  243. DECLARE_ITEM_EFFECT_METER( CTFThrowable, TF_WEAPON_THROWABLE, true, "resource/UI/HudItemEffectMeter_Action.res" );
  244. // Kill Streak
  245. DECLARE_ITEM_EFFECT_METER( CTFWeaponBase, TF_WEAPON_NONE, false, "resource/UI/HudItemEffectMeter_KillStreak.res" );
  246. DECLARE_ITEM_EFFECT_METER( CTFSpellBook, TF_WEAPON_SPELLBOOK, true, "resource/UI/HudItemEffectMeter_KartCharge.res" );
  247. /*hNewMeter = new CHudItemEffectMeter_HalloweenSouls( pszElementName, pPlayer );
  248. if ( hNewMeter )
  249. {
  250. gHUD.AddHudElement( hNewMeter );
  251. outMeters.AddToHead( hNewMeter );
  252. hNewMeter->SetVisible( false );
  253. }*/
  254. // Mvm canteen
  255. hNewMeter = new CHudItemEffectMeter_Weapon< CTFPowerupBottle >( pszElementName, pPlayer, TF_WEAPON_NONE, true, "resource/UI/HudItemEffectMeter_PowerupBottle.res" );
  256. if ( hNewMeter )
  257. {
  258. gHUD.AddHudElement( hNewMeter );
  259. outMeters.AddToHead( hNewMeter );
  260. hNewMeter->SetVisible( false );
  261. }
  262. hNewMeter = new CHudItemEffectMeter_Rune( pszElementName, pPlayer );
  263. if ( hNewMeter )
  264. {
  265. gHUD.AddHudElement( hNewMeter );
  266. outMeters.AddToHead( hNewMeter );
  267. hNewMeter->SetVisible( false );
  268. }
  269. #ifdef STAGING_ONLY
  270. // Space jump
  271. hNewMeter = new CHudItemEffectMeter_SpaceJump( pszElementName, pPlayer );
  272. if ( hNewMeter )
  273. {
  274. gHUD.AddHudElement( hNewMeter );
  275. outMeters.AddToHead( hNewMeter );
  276. hNewMeter->SetVisible( false );
  277. }
  278. #endif // STAGING_ONLY
  279. }
  280. //-----------------------------------------------------------------------------
  281. // Purpose:
  282. //-----------------------------------------------------------------------------
  283. void CHudItemEffectMeter::ApplySchemeSettings( IScheme *pScheme )
  284. {
  285. // load control settings...
  286. LoadControlSettings( GetResFile() );
  287. // Update the label.
  288. const wchar_t *pLocalized = g_pVGuiLocalize->Find( GetLabelText() );
  289. if ( pLocalized )
  290. {
  291. wchar_t wszLabel[ 128 ];
  292. V_wcsncpy( wszLabel, pLocalized, sizeof( wszLabel ) );
  293. wchar_t wszFinalLabel[ 128 ];
  294. UTIL_ReplaceKeyBindings( wszLabel, 0, wszFinalLabel, sizeof( wszFinalLabel ), GAME_ACTION_SET_FPSCONTROLS );
  295. m_pLabel->SetText( wszFinalLabel, true );
  296. }
  297. else
  298. {
  299. m_pLabel->SetText( GetLabelText() );
  300. }
  301. BaseClass::ApplySchemeSettings( pScheme );
  302. CTFImagePanel *pIcon = dynamic_cast< CTFImagePanel* >( FindChildByName( "ItemEffectIcon" ) );
  303. if ( pIcon )
  304. {
  305. pIcon->SetImage( GetIconName() );
  306. }
  307. }
  308. //-----------------------------------------------------------------------------
  309. // Purpose:
  310. //-----------------------------------------------------------------------------
  311. void CHudItemEffectMeter::PerformLayout()
  312. {
  313. BaseClass::PerformLayout();
  314. // slide over by 1 for medic
  315. int iOffset = 0;
  316. C_TFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer();
  317. if ( pPlayer && pPlayer->GetPlayerClass()->GetClassIndex() == TF_CLASS_MEDIC )
  318. {
  319. iOffset = 1;
  320. }
  321. if ( g_ItemEffectMeterManager.GetNumEnabled() + iOffset > 1 )
  322. {
  323. int xPos = 0, yPos = 0;
  324. GetPos( xPos, yPos );
  325. SetPos( xPos - m_iXOffset, yPos );
  326. }
  327. }
  328. //-----------------------------------------------------------------------------
  329. // Purpose:
  330. //-----------------------------------------------------------------------------
  331. bool CHudItemEffectMeter::ShouldDraw( void )
  332. {
  333. bool bShouldDraw = true;
  334. C_TFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer();
  335. if ( !pPlayer || !pPlayer->IsAlive() || pPlayer->m_Shared.InCond( TF_COND_HALLOWEEN_GHOST_MODE ) )
  336. {
  337. bShouldDraw = false;
  338. }
  339. else if ( CTFMinigameLogic::GetMinigameLogic() && CTFMinigameLogic::GetMinigameLogic()->GetActiveMinigame() )
  340. {
  341. bShouldDraw = false;
  342. }
  343. else if ( TFGameRules() && TFGameRules()->ShowMatchSummary() )
  344. {
  345. bShouldDraw = false;
  346. }
  347. else if ( !m_pProgressBar )
  348. {
  349. bShouldDraw = false;
  350. }
  351. else if ( IsEnabled() )
  352. {
  353. bShouldDraw = CHudElement::ShouldDraw();
  354. }
  355. else
  356. {
  357. bShouldDraw = false;
  358. }
  359. if ( IsVisible() != bShouldDraw )
  360. {
  361. SetVisible( bShouldDraw );
  362. if ( bShouldDraw )
  363. {
  364. // if we're going to be visible, redo our layout
  365. InvalidateLayout( false, true );
  366. }
  367. }
  368. return bShouldDraw;
  369. }
  370. //-----------------------------------------------------------------------------
  371. // Purpose:
  372. //-----------------------------------------------------------------------------
  373. void CHudItemEffectMeter::Update( C_TFPlayer* pPlayer, const char* pSoundScript )
  374. {
  375. if ( !IsEnabled() )
  376. return;
  377. if ( !m_pProgressBar )
  378. return;
  379. if ( !pPlayer )
  380. return;
  381. // Progress counts override progress bars.
  382. int iCount = GetCount();
  383. if ( iCount >= 0 )
  384. {
  385. if ( ShowPercentSymbol() )
  386. {
  387. SetDialogVariable( "progresscount", VarArgs( "%d%%", iCount ) );
  388. }
  389. else
  390. {
  391. SetDialogVariable( "progresscount", iCount );
  392. }
  393. }
  394. float flProgress = GetProgress();
  395. // Play a sound if we are refreshed.
  396. if ( C_TFPlayer::GetLocalTFPlayer() && flProgress >= 1.f && m_flOldProgress < 1.f &&
  397. pPlayer->IsAlive() && ShouldBeep() )
  398. {
  399. m_flOldProgress = flProgress;
  400. C_TFPlayer::GetLocalTFPlayer()->EmitSound( pSoundScript );
  401. }
  402. else
  403. {
  404. m_flOldProgress = flProgress;
  405. }
  406. // Update the meter GUI element.
  407. m_pProgressBar->SetProgress( flProgress );
  408. // Flash the bar if this class implementation requires it.
  409. if ( ShouldFlash() )
  410. {
  411. int color_offset = ((int)(gpGlobals->realtime*10)) % 10;
  412. int red = 160 + (color_offset*10);
  413. m_pProgressBar->SetFgColor( Color( red, 0, 0, 255 ) );
  414. }
  415. else
  416. {
  417. m_pProgressBar->SetFgColor( GetFgColor() );
  418. }
  419. }
  420. const char* CHudItemEffectMeter::GetLabelText( void )
  421. {
  422. CTFWeaponInvis *pWpn = (CTFWeaponInvis *)m_pPlayer->Weapon_OwnsThisID( TF_WEAPON_INVIS );
  423. if ( pWpn )
  424. {
  425. if ( pWpn->HasFeignDeath() )
  426. {
  427. return "#TF_Feign";
  428. }
  429. else if ( pWpn->HasMotionCloak() )
  430. {
  431. return "#TF_CloakDagger";
  432. }
  433. }
  434. return "#TF_CLOAK";
  435. }
  436. //-----------------------------------------------------------------------------
  437. // Purpose:
  438. //-----------------------------------------------------------------------------
  439. float CHudItemEffectMeter::GetProgress( void )
  440. {
  441. if ( m_pPlayer )
  442. return m_pPlayer->m_Shared.GetSpyCloakMeter() / 100.0f;
  443. else
  444. return 1.f;
  445. }
  446. //-----------------------------------------------------------------------------
  447. // Purpose: Tracks the weapon's regen.
  448. //-----------------------------------------------------------------------------
  449. template <class T>
  450. CHudItemEffectMeter_Weapon<T>::CHudItemEffectMeter_Weapon( const char* pszElementName, C_TFPlayer* pPlayer, int iWeaponID, bool bBeeps, const char* pszResFile )
  451. : CHudItemEffectMeter( pszElementName, pPlayer )
  452. {
  453. m_iWeaponID = iWeaponID;
  454. m_bBeeps = bBeeps;
  455. m_pszResFile = pszResFile;
  456. }
  457. //-----------------------------------------------------------------------------
  458. // Purpose:
  459. //-----------------------------------------------------------------------------
  460. template <class T>
  461. const char* CHudItemEffectMeter_Weapon<T>::GetResFile( void )
  462. {
  463. if ( m_pszResFile )
  464. {
  465. return m_pszResFile;
  466. }
  467. else
  468. {
  469. return "resource/UI/HudItemEffectMeter.res";
  470. }
  471. }
  472. //-----------------------------------------------------------------------------
  473. // Purpose: Caches the weapon reference.
  474. //-----------------------------------------------------------------------------
  475. template <class T>
  476. T* CHudItemEffectMeter_Weapon<T>::GetWeapon( void )
  477. {
  478. if ( m_bEnabled && m_pPlayer && !m_pWeapon )
  479. {
  480. m_pWeapon = dynamic_cast<T*>( m_pPlayer->Weapon_OwnsThisID( m_iWeaponID ) );
  481. if ( !m_pWeapon )
  482. {
  483. m_bEnabled = false;
  484. }
  485. }
  486. return m_pWeapon;
  487. }
  488. //-----------------------------------------------------------------------------
  489. // Purpose:
  490. //-----------------------------------------------------------------------------
  491. template <class T>
  492. bool CHudItemEffectMeter_Weapon<T>::IsEnabled( void )
  493. {
  494. T *pWeapon = GetWeapon();
  495. if ( pWeapon )
  496. return true;
  497. return CHudItemEffectMeter::IsEnabled();
  498. }
  499. //-----------------------------------------------------------------------------
  500. // Purpose:
  501. //-----------------------------------------------------------------------------
  502. template <class T>
  503. float CHudItemEffectMeter_Weapon<T>::GetProgress( void )
  504. {
  505. T *pWeapon = GetWeapon();
  506. if ( pWeapon )
  507. {
  508. return pWeapon->GetProgress();
  509. }
  510. else
  511. {
  512. return 0.f;
  513. }
  514. }
  515. //-----------------------------------------------------------------------------
  516. // Purpose:
  517. //-----------------------------------------------------------------------------
  518. template <class T>
  519. void CHudItemEffectMeter_Weapon<T>::Update( C_TFPlayer* pPlayer, const char* pSoundScript )
  520. {
  521. T *pWeapon = GetWeapon();
  522. if ( pWeapon )
  523. {
  524. CTFSniperRifle *pRifle = dynamic_cast<CTFSniperRifle*>( pWeapon );
  525. if ( pRifle && pRifle->GetBuffType() > 0 )
  526. {
  527. CHudItemEffectMeter::Update( pPlayer, "Weapon_Bison.SingleCrit" );
  528. return;
  529. }
  530. }
  531. CHudItemEffectMeter::Update( pPlayer, pSoundScript );
  532. }
  533. //-----------------------------------------------------------------------------
  534. template <class T>
  535. bool CHudItemEffectMeter_Weapon<T>::ShouldDraw( )
  536. {
  537. return CHudItemEffectMeter::ShouldDraw();
  538. }
  539. //-----------------------------------------------------------------------------
  540. // Specializations for meters that do unique things follow...
  541. //-----------------------------------------------------------------------------
  542. //-----------------------------------------------------------------------------
  543. template <>
  544. bool CHudItemEffectMeter_Weapon<CTFWeaponBase>::IsEnabled( void )
  545. {
  546. C_TFPlayer *pTFPlayer = C_TFPlayer::GetLocalTFPlayer();
  547. if ( pTFPlayer )
  548. {
  549. int iKillStreak = 0;
  550. CALL_ATTRIB_HOOK_INT_ON_OTHER( pTFPlayer, iKillStreak, killstreak_tier );
  551. return iKillStreak != 0;
  552. }
  553. return false;
  554. }
  555. //-----------------------------------------------------------------------------
  556. template <>
  557. int CHudItemEffectMeter_Weapon<CTFWeaponBase>::GetCount( void )
  558. {
  559. C_TFPlayer *pTFPlayer = C_TFPlayer::GetLocalTFPlayer();
  560. if ( pTFPlayer )
  561. {
  562. return pTFPlayer->m_Shared.GetStreak( CTFPlayerShared::kTFStreak_Kills );
  563. }
  564. return 0;
  565. }
  566. //-----------------------------------------------------------------------------
  567. template <>
  568. const char* CHudItemEffectMeter_Weapon<CTFWeaponBase>::GetLabelText( void )
  569. {
  570. return "TF_KillStreak";
  571. }
  572. //-----------------------------------------------------------------------------
  573. template <>
  574. bool CHudItemEffectMeter_Weapon<CTFWeaponBase>::IsKillstreakMeter( void )
  575. {
  576. return true;
  577. }
  578. //-----------------------------------------------------------------------------
  579. // Purpose: Specialization for the sword (to differentiate it from other sword-type weapons)
  580. //-----------------------------------------------------------------------------
  581. template <>
  582. CTFSword* CHudItemEffectMeter_Weapon<CTFSword>::GetWeapon( void )
  583. {
  584. if ( m_bEnabled && m_pPlayer && !m_pWeapon )
  585. {
  586. m_pWeapon = dynamic_cast<CTFSword*>( m_pPlayer->Weapon_OwnsThisID( m_iWeaponID ) );
  587. if ( m_pWeapon && !m_pWeapon->CanDecapitate() )
  588. m_pWeapon = NULL;
  589. if ( !m_pWeapon )
  590. {
  591. m_bEnabled = false;
  592. }
  593. }
  594. return m_pWeapon;
  595. }
  596. //-----------------------------------------------------------------------------
  597. // Purpose: Specialization for demoman head count.
  598. //-----------------------------------------------------------------------------
  599. template <>
  600. int CHudItemEffectMeter_Weapon<CTFSword>::GetCount( void )
  601. {
  602. CTFSword *pWeapon = GetWeapon();
  603. if ( pWeapon )
  604. {
  605. return pWeapon->GetCount();
  606. }
  607. else
  608. {
  609. return 0.f;
  610. }
  611. }
  612. //-----------------------------------------------------------------------------
  613. // Purpose: Soldier buff charge bar specialization for flashing...
  614. //-----------------------------------------------------------------------------
  615. template <>
  616. bool CHudItemEffectMeter_Weapon<CTFBuffItem>::ShouldFlash( void )
  617. {
  618. CTFBuffItem *pWeapon = GetWeapon();
  619. if ( pWeapon )
  620. {
  621. return pWeapon->EffectMeterShouldFlash();
  622. }
  623. else
  624. {
  625. return false;
  626. }
  627. }
  628. //-----------------------------------------------------------------------------
  629. template <>
  630. bool CHudItemEffectMeter_Weapon<CTFBuffItem>::ShouldDraw()
  631. {
  632. if ( !m_pPlayer )
  633. return false;
  634. CTFBuffItem *pWeapon = GetWeapon();
  635. if ( !pWeapon )
  636. return false;
  637. // do not draw for the parachute
  638. if ( pWeapon->GetBuffType() == EParachute )
  639. return false;
  640. return CHudItemEffectMeter::ShouldDraw();
  641. }
  642. //-----------------------------------------------------------------------------
  643. template <>
  644. bool CHudItemEffectMeter_Weapon<CTFFlameThrower>::IsEnabled( void )
  645. {
  646. if ( !m_pPlayer )
  647. return false;
  648. CTFFlameThrower *pWeapon = GetWeapon();
  649. if ( !pWeapon )
  650. return false;
  651. return ( pWeapon->GetBuffType() > 0 );
  652. }
  653. //-----------------------------------------------------------------------------
  654. // Purpose: Pyro rage bar specialization for flashing...
  655. //-----------------------------------------------------------------------------
  656. template <>
  657. bool CHudItemEffectMeter_Weapon<CTFFlameThrower>::ShouldFlash( void )
  658. {
  659. CTFFlameThrower *pWeapon = GetWeapon();
  660. if ( pWeapon )
  661. {
  662. return pWeapon->EffectMeterShouldFlash();
  663. }
  664. else
  665. {
  666. return false;
  667. }
  668. }
  669. //-----------------------------------------------------------------------------
  670. // Soda Popper Flash
  671. //-----------------------------------------------------------------------------
  672. template <>
  673. bool CHudItemEffectMeter_Weapon<CTFSodaPopper>::ShouldFlash( void )
  674. {
  675. if ( !m_pPlayer )
  676. return false;
  677. return m_pPlayer->m_Shared.GetScoutHypeMeter() >= 100.0f;
  678. }
  679. //-----------------------------------------------------------------------------
  680. // Charged SMG Flash
  681. //-----------------------------------------------------------------------------
  682. template <>
  683. bool CHudItemEffectMeter_Weapon<CTFChargedSMG>::ShouldFlash( void )
  684. {
  685. if ( !m_pPlayer )
  686. return false;
  687. CTFChargedSMG* pWeapon = GetWeapon();
  688. if ( !pWeapon )
  689. return false;
  690. return pWeapon->ShouldFlashChargeBar();
  691. }
  692. //-----------------------------------------------------------------------------
  693. // Purpose: Heavy rage bar in MvM
  694. //-----------------------------------------------------------------------------
  695. template <>
  696. bool CHudItemEffectMeter_Weapon< CTFMinigun >::IsEnabled( void )
  697. {
  698. if ( !m_pPlayer )
  699. return false;
  700. CTFMinigun *pWeapon = GetWeapon();
  701. if ( !pWeapon )
  702. return false;
  703. bool bVisible = false;
  704. float fKillComboFireRateBoost = 0.0f;
  705. CALL_ATTRIB_HOOK_FLOAT_ON_OTHER( pWeapon, fKillComboFireRateBoost, kill_combo_fire_rate_boost );
  706. if ( fKillComboFireRateBoost > 0.0f )
  707. {
  708. m_pLabel->SetVisible( false );
  709. m_pProgressBar->SetVisible( false );
  710. bVisible = true;
  711. }
  712. int iRage = 0;
  713. CALL_ATTRIB_HOOK_INT_ON_OTHER( m_pPlayer, iRage, generate_rage_on_dmg );
  714. if ( iRage )
  715. {
  716. m_pLabel->SetVisible( true );
  717. m_pProgressBar->SetVisible( true );
  718. bVisible = true;
  719. }
  720. return bVisible;
  721. }
  722. //-----------------------------------------------------------------------------
  723. // Purpose:
  724. //-----------------------------------------------------------------------------
  725. template <>
  726. bool CHudItemEffectMeter_Weapon< CTFMinigun >::ShouldFlash( void )
  727. {
  728. CTFMinigun *pWeapon = GetWeapon();
  729. if ( pWeapon )
  730. {
  731. return pWeapon->EffectMeterShouldFlash();
  732. }
  733. else
  734. {
  735. return false;
  736. }
  737. }
  738. static const char *pszClassIcons[] = {
  739. "",
  740. "../hud/leaderboard_class_scout",
  741. "../hud/leaderboard_class_sniper",
  742. "../hud/leaderboard_class_soldier",
  743. "../hud/leaderboard_class_demo",
  744. "../hud/leaderboard_class_medic",
  745. "../hud/leaderboard_class_heavy",
  746. "../hud/leaderboard_class_pyro",
  747. "../hud/leaderboard_class_spy",
  748. "../hud/leaderboard_class_engineer",
  749. };
  750. template <>
  751. void CHudItemEffectMeter_Weapon< CTFMinigun >::Update( C_TFPlayer* pPlayer, const char* pSoundScript )
  752. {
  753. CTFMinigun *pWeapon = GetWeapon();
  754. if ( pWeapon )
  755. {
  756. float fKillComboFireRateBoost = 0.0f;
  757. CALL_ATTRIB_HOOK_FLOAT_ON_OTHER( pWeapon, fKillComboFireRateBoost, kill_combo_fire_rate_boost );
  758. if ( fKillComboFireRateBoost > 0.0f )
  759. {
  760. SetControlVisible( "ItemEffectMeterLabel2", true );
  761. int nKillComboClass = pWeapon->GetKillComboClass();
  762. int nKillComboCount = pWeapon->GetKillComboCount();
  763. ImagePanel *( pImagePanel[3] ) =
  764. {
  765. assert_cast< ImagePanel* >( FindChildByName( "KillComboClassIcon1" ) ),
  766. assert_cast< ImagePanel* >( FindChildByName( "KillComboClassIcon2" ) ),
  767. assert_cast< ImagePanel* >( FindChildByName( "KillComboClassIcon3" ) )
  768. };
  769. for ( int i = 0; i < ARRAYSIZE( pImagePanel ); ++i )
  770. {
  771. if ( !pImagePanel[i] )
  772. continue;
  773. if ( nKillComboCount > i )
  774. {
  775. pImagePanel[i]->SetImage( pszClassIcons[nKillComboClass] );
  776. pImagePanel[i]->SetVisible( true );
  777. }
  778. else
  779. {
  780. pImagePanel[i]->SetVisible( false );
  781. }
  782. }
  783. }
  784. else
  785. {
  786. SetControlVisible( "ItemEffectMeterLabel2", false );
  787. SetControlVisible( "KillComboClassIcon1", false );
  788. SetControlVisible( "KillComboClassIcon2", false );
  789. SetControlVisible( "KillComboClassIcon3", false );
  790. }
  791. }
  792. CHudItemEffectMeter::Update( pPlayer, pSoundScript );
  793. }
  794. //-----------------------------------------------------------------------------
  795. // Purpose: Specialization for engineer revenge count.
  796. //-----------------------------------------------------------------------------
  797. template <>
  798. int CHudItemEffectMeter_Weapon<CTFShotgun_Revenge>::GetCount( void )
  799. {
  800. CTFShotgun_Revenge *pWeapon = GetWeapon();
  801. if ( pWeapon )
  802. {
  803. return pWeapon->GetCount();
  804. }
  805. else
  806. {
  807. return 0.f;
  808. }
  809. }
  810. template <>
  811. bool CHudItemEffectMeter_Weapon<CTFFlareGun_Revenge>::IsEnabled( void )
  812. {
  813. if ( !m_pPlayer )
  814. return false;
  815. CTFFlareGun_Revenge *pWeapon = GetWeapon();
  816. return pWeapon && pWeapon->IsActiveByLocalPlayer();
  817. }
  818. template <>
  819. int CHudItemEffectMeter_Weapon<CTFFlareGun_Revenge>::GetCount( void )
  820. {
  821. CTFFlareGun_Revenge *pWeapon = GetWeapon();
  822. if ( pWeapon )
  823. {
  824. return pWeapon->GetCount();
  825. }
  826. else
  827. {
  828. return 0.f;
  829. }
  830. }
  831. //-----------------------------------------------------------------------------
  832. // Purpose:
  833. //-----------------------------------------------------------------------------
  834. template <>
  835. int CHudItemEffectMeter_Weapon<CTFSniperRifleDecap>::GetCount( void )
  836. {
  837. CTFSniperRifleDecap *pWeapon = GetWeapon();
  838. if ( pWeapon )
  839. {
  840. return pWeapon->GetCount();
  841. }
  842. else
  843. {
  844. return 0.f;
  845. }
  846. }
  847. //-----------------------------------------------------------------------------
  848. // Purpose:
  849. //-----------------------------------------------------------------------------
  850. template <>
  851. Color CHudItemEffectMeter_Weapon<CTFParticleCannon>::GetFgColor( void )
  852. {
  853. CTFParticleCannon *pWeapon = GetWeapon();
  854. if ( pWeapon && pWeapon->CanChargeFire() )
  855. return Color( 255, 255, 255, 255 );
  856. else
  857. return Color( 255, 0, 0, 255 );
  858. }
  859. //-----------------------------------------------------------------------------
  860. // Purpose:
  861. //-----------------------------------------------------------------------------
  862. template <>
  863. int CHudItemEffectMeter_Weapon<CTFRevolver>::GetCount( void )
  864. {
  865. CTFRevolver *pWeapon = GetWeapon();
  866. if ( pWeapon )
  867. {
  868. return pWeapon->GetCount();
  869. }
  870. else
  871. {
  872. return 0;
  873. }
  874. }
  875. //-----------------------------------------------------------------------------
  876. // Purpose:
  877. //-----------------------------------------------------------------------------
  878. template <>
  879. bool CHudItemEffectMeter_Weapon<CTFRevolver>::IsEnabled( void )
  880. {
  881. CTFRevolver *pWeapon = GetWeapon();
  882. if ( pWeapon )
  883. {
  884. int iExtraDamageOnHit = 0;
  885. CALL_ATTRIB_HOOK_INT_ON_OTHER( pWeapon, iExtraDamageOnHit, extra_damage_on_hit );
  886. return pWeapon->SapperKillsCollectCrits() || iExtraDamageOnHit;
  887. }
  888. else
  889. {
  890. return false;
  891. }
  892. }
  893. //-----------------------------------------------------------------------------
  894. template <>
  895. bool CHudItemEffectMeter_Weapon<CTFRevolver>::ShowPercentSymbol( void )
  896. {
  897. CTFRevolver *pWeapon = GetWeapon();
  898. if ( pWeapon )
  899. {
  900. int iExtraDamageOnHit = 0;
  901. CALL_ATTRIB_HOOK_INT_ON_OTHER( pWeapon, iExtraDamageOnHit, extra_damage_on_hit );
  902. return iExtraDamageOnHit;
  903. }
  904. return false;
  905. }
  906. //-----------------------------------------------------------------------------
  907. // Purpose:
  908. //-----------------------------------------------------------------------------
  909. template <>
  910. bool CHudItemEffectMeter_Weapon<CTFKnife>::IsEnabled( void )
  911. {
  912. CTFKnife *pWeapon = GetWeapon();
  913. if ( pWeapon )
  914. {
  915. return pWeapon->GetKnifeType() == KNIFE_ICICLE;
  916. }
  917. else
  918. {
  919. return false;
  920. }
  921. }
  922. //-----------------------------------------------------------------------------
  923. // Purpose:
  924. //-----------------------------------------------------------------------------
  925. template <>
  926. bool CHudItemEffectMeter_Weapon<CTFSniperRifle>::IsEnabled( void )
  927. {
  928. if ( !m_pPlayer )
  929. return false;
  930. CTFSniperRifle *pWeapon = GetWeapon();
  931. if ( !pWeapon )
  932. return false;
  933. return ( pWeapon->GetBuffType() > 0 );
  934. }
  935. //-----------------------------------------------------------------------------
  936. // Purpose:
  937. //-----------------------------------------------------------------------------
  938. template <>
  939. bool CHudItemEffectMeter_Weapon<CTFSniperRifle>::ShouldFlash( void )
  940. {
  941. CTFSniperRifle *pWeapon = GetWeapon();
  942. if ( pWeapon )
  943. {
  944. return pWeapon->EffectMeterShouldFlash();
  945. }
  946. else
  947. {
  948. return false;
  949. }
  950. }
  951. //-----------------------------------------------------------------------------
  952. // Purpose:
  953. //-----------------------------------------------------------------------------
  954. template <>
  955. bool CHudItemEffectMeter_Weapon<C_TFWeaponBuilder>::IsEnabled( void )
  956. {
  957. if ( !m_pPlayer )
  958. return false;
  959. return ( TFGameRules() && TFGameRules()->IsMannVsMachineMode() );
  960. }
  961. //-----------------------------------------------------------------------------
  962. // Purpose:
  963. //-----------------------------------------------------------------------------
  964. template <>
  965. bool CHudItemEffectMeter_Weapon<C_TFWeaponBuilder>::ShouldBeep( void )
  966. {
  967. if ( !m_pPlayer )
  968. return false;
  969. int iRoboSapper = 0;
  970. CALL_ATTRIB_HOOK_INT_ON_OTHER( m_pPlayer, iRoboSapper, robo_sapper );
  971. return ( iRoboSapper > 0 );
  972. }
  973. //-----------------------------------------------------------------------------
  974. // Purpose:
  975. //-----------------------------------------------------------------------------
  976. template <>
  977. bool CHudItemEffectMeter_Weapon<C_TFWeaponBuilder>::ShouldFlash( void )
  978. {
  979. if ( !m_pPlayer )
  980. return false;
  981. C_TFWeaponBuilder *pWeapon = GetWeapon();
  982. if ( pWeapon )
  983. {
  984. return pWeapon->EffectMeterShouldFlash();
  985. }
  986. else
  987. {
  988. return false;
  989. }
  990. }
  991. template <>
  992. CTFPowerupBottle* CHudItemEffectMeter_Weapon<CTFPowerupBottle>::GetWeapon( void )
  993. {
  994. if ( m_bEnabled && m_pPlayer && !m_pWeapon )
  995. {
  996. for ( int i = 0; i < m_pPlayer->GetNumWearables(); ++i )
  997. {
  998. m_pWeapon = dynamic_cast<CTFPowerupBottle*>( m_pPlayer->GetWearable( i ) );
  999. if ( m_pWeapon )
  1000. {
  1001. break;
  1002. }
  1003. }
  1004. if ( !m_pWeapon )
  1005. {
  1006. m_bEnabled = false;
  1007. }
  1008. }
  1009. return m_pWeapon;
  1010. }
  1011. template <>
  1012. bool CHudItemEffectMeter_Weapon<CTFPowerupBottle>::IsEnabled( void )
  1013. {
  1014. if ( !m_pPlayer )
  1015. return false;
  1016. CTFPowerupBottle *pPowerupBottle = GetWeapon();
  1017. if ( pPowerupBottle )
  1018. {
  1019. return ( pPowerupBottle->GetNumCharges() > 0 );
  1020. }
  1021. return false;
  1022. }
  1023. template <>
  1024. int CHudItemEffectMeter_Weapon<CTFPowerupBottle>::GetCount( void )
  1025. {
  1026. CTFPowerupBottle *pPowerupBottle = GetWeapon();
  1027. if ( pPowerupBottle )
  1028. {
  1029. return pPowerupBottle->GetNumCharges();
  1030. }
  1031. else
  1032. {
  1033. return 0;
  1034. }
  1035. }
  1036. template <>
  1037. const char* CHudItemEffectMeter_Weapon<CTFPowerupBottle>::GetIconName( void )
  1038. {
  1039. CTFPowerupBottle *pPowerupBottle = GetWeapon();
  1040. if ( pPowerupBottle )
  1041. {
  1042. return pPowerupBottle->GetEffectIconName();
  1043. }
  1044. return CHudItemEffectMeter::GetIconName();
  1045. }
  1046. //-----------------------------------------------------------------------------
  1047. // Purpose: Medic "rage" bar in MvM
  1048. //-----------------------------------------------------------------------------
  1049. template <>
  1050. bool CHudItemEffectMeter_Weapon< CWeaponMedigun >::IsEnabled( void )
  1051. {
  1052. if ( !m_pPlayer )
  1053. return false;
  1054. int iRage = 0;
  1055. CALL_ATTRIB_HOOK_INT_ON_OTHER( m_pPlayer, iRage, generate_rage_on_heal );
  1056. if ( !iRage )
  1057. return false;
  1058. CWeaponMedigun *pWeapon = GetWeapon();
  1059. if ( !pWeapon )
  1060. return false;
  1061. return true;
  1062. }
  1063. //-----------------------------------------------------------------------------
  1064. // Purpose:
  1065. //-----------------------------------------------------------------------------
  1066. template <>
  1067. bool CHudItemEffectMeter_Weapon<CWeaponMedigun>::ShouldFlash( void )
  1068. {
  1069. CWeaponMedigun *pWeapon = GetWeapon();
  1070. if ( pWeapon )
  1071. {
  1072. return pWeapon->EffectMeterShouldFlash();
  1073. }
  1074. else
  1075. {
  1076. return false;
  1077. }
  1078. }
  1079. #ifdef STAGING_ONLY
  1080. //-----------------------------------------------------------------------------
  1081. // Purpose:
  1082. //-----------------------------------------------------------------------------
  1083. template <>
  1084. bool CHudItemEffectMeter_Weapon< CTFWeaponPDA_Spy_Build >::IsEnabled( void )
  1085. {
  1086. if ( !m_pPlayer )
  1087. return false;
  1088. if ( !m_pPlayer->m_Shared.CanBuildSpyTraps() )
  1089. return false;
  1090. return true;
  1091. }
  1092. //-----------------------------------------------------------------------------
  1093. // Purpose: Specialization for Spy traps in MvM
  1094. //-----------------------------------------------------------------------------
  1095. template <>
  1096. int CHudItemEffectMeter_Weapon< CTFWeaponPDA_Spy_Build >::GetCount( void )
  1097. {
  1098. if ( !m_pPlayer )
  1099. return false;
  1100. return m_pPlayer->GetAmmoCount( TF_AMMO_GRENADES1 );
  1101. }
  1102. #endif // STAGING_ONLY
  1103. //-----------------------------------------------------------------------------
  1104. // Purpose:
  1105. //-----------------------------------------------------------------------------
  1106. template <>
  1107. bool CHudItemEffectMeter_Weapon< CTFLunchBox >::IsEnabled( void )
  1108. {
  1109. return CHudItemEffectMeter::IsEnabled();
  1110. }
  1111. //-----------------------------------------------------------------------------
  1112. // CTFThrowable
  1113. //-----------------------------------------------------------------------------
  1114. template <>
  1115. bool CHudItemEffectMeter_Weapon<CTFThrowable>::IsEnabled( void )
  1116. {
  1117. CTFThrowable *pWep = dynamic_cast<CTFThrowable*>( GetWeapon() );
  1118. if ( pWep )
  1119. {
  1120. return pWep->ShowHudElement();
  1121. }
  1122. return false;
  1123. }
  1124. CHudItemEffectMeter_Rune::CHudItemEffectMeter_Rune( const char *pszElementName, C_TFPlayer* pPlayer ) : CHudItemEffectMeter( pszElementName, pPlayer )
  1125. {
  1126. }
  1127. //-------------------------------------------------------------------------------
  1128. bool CHudItemEffectMeter_Rune::IsEnabled( void )
  1129. {
  1130. return m_pPlayer && m_pPlayer->m_Shared.CanRuneCharge();
  1131. }
  1132. //-------------------------------------------------------------------------------
  1133. float CHudItemEffectMeter_Rune::GetProgress( void )
  1134. {
  1135. if ( m_pPlayer )
  1136. return m_pPlayer->m_Shared.GetRuneCharge() / 100.0f;
  1137. return 0;
  1138. }
  1139. //-------------------------------------------------------------------------------
  1140. bool CHudItemEffectMeter_Rune::ShouldFlash( void )
  1141. {
  1142. if ( m_pPlayer )
  1143. return m_pPlayer->m_Shared.IsRuneCharged();
  1144. return false;
  1145. }
  1146. //-------------------------------------------------------------------------------
  1147. bool CHudItemEffectMeter_Rune::ShouldDraw( void )
  1148. {
  1149. return m_pPlayer && m_pPlayer->m_Shared.CanRuneCharge();
  1150. }
  1151. #ifdef STAGING_ONLY
  1152. //---------------------------------------------------------------------------------------------------------------------------
  1153. // SPACE JUMPS
  1154. //---------------------------------------------------------------------------------------------------------------------------
  1155. CHudItemEffectMeter_SpaceJump::CHudItemEffectMeter_SpaceJump( const char *pszElementName, C_TFPlayer* pPlayer ) : CHudItemEffectMeter( pszElementName, pPlayer )
  1156. {
  1157. }
  1158. //-------------------------------------------------------------------------------
  1159. bool CHudItemEffectMeter_SpaceJump::IsEnabled( void )
  1160. {
  1161. // if ( m_pPlayer && m_pPlayer->m_Shared.InCond( TF_COND_SPACE_GRAVITY ) )
  1162. // return true;
  1163. return false;
  1164. }
  1165. //-------------------------------------------------------------------------------
  1166. float CHudItemEffectMeter_SpaceJump::GetProgress( void )
  1167. {
  1168. if ( m_pPlayer )
  1169. return m_pPlayer->m_Shared.GetSpaceJumpChargeMeter() / 100.0f;
  1170. return 0;
  1171. }
  1172. //-------------------------------------------------------------------------------
  1173. bool CHudItemEffectMeter_SpaceJump::ShouldDraw( void )
  1174. {
  1175. // if ( m_pPlayer && m_pPlayer->m_Shared.InCond( TF_COND_SPACE_GRAVITY ) )
  1176. // return true;
  1177. return false;
  1178. }
  1179. //-----------------------------------------------------------------------------
  1180. // Purpose: TRANQ
  1181. //------------------------------------------------------------------------------
  1182. CHudItemEffectMeter_Tranq::CHudItemEffectMeter_Tranq( const char *pszElementName, C_TFPlayer* pPlayer ) : CHudItemEffectMeter( pszElementName, pPlayer )
  1183. {
  1184. }
  1185. //------------------------------------------------------------------------------
  1186. float CHudItemEffectMeter_Tranq::GetProgress( void )
  1187. {
  1188. int iTranq = 0;
  1189. CALL_ATTRIB_HOOK_INT_ON_OTHER( m_pPlayer, iTranq, override_projectile_type );
  1190. if ( iTranq == TF_PROJECTILE_TRANQ )
  1191. {
  1192. float flDuration = Min( 60.0f, (float)m_pPlayer->m_Shared.m_flSpyTranqBuffDuration );
  1193. return flDuration / 60.0f;
  1194. }
  1195. return 0.0f;
  1196. }
  1197. //-----------------------------------------------------------------------------
  1198. bool CHudItemEffectMeter_Tranq::IsEnabled( void )
  1199. {
  1200. int iTranq = 0;
  1201. CALL_ATTRIB_HOOK_INT_ON_OTHER( m_pPlayer, iTranq, override_projectile_type );
  1202. return ( iTranq == TF_PROJECTILE_TRANQ );
  1203. }
  1204. //-----------------------------------------------------------------------------
  1205. template <>
  1206. bool CHudItemEffectMeter_Weapon<CTFCrossbow>::IsEnabled( void )
  1207. {
  1208. int iMilkBolt = 0;
  1209. CALL_ATTRIB_HOOK_INT_ON_OTHER( m_pPlayer, iMilkBolt, fires_milk_bolt );
  1210. return ( iMilkBolt > 0 );
  1211. }
  1212. #endif // STAGING_ONLY
  1213. //-----------------------------------------------------------------------------
  1214. // Rocket Launcher AirStrike Headcounter
  1215. //-----------------------------------------------------------------------------
  1216. template <>
  1217. int CHudItemEffectMeter_Weapon<CTFRocketLauncher_AirStrike>::GetCount( void )
  1218. {
  1219. CTFRocketLauncher_AirStrike *pWeapon = GetWeapon();
  1220. if ( pWeapon )
  1221. {
  1222. return pWeapon->GetCount();
  1223. }
  1224. else
  1225. {
  1226. return 0;
  1227. }
  1228. }
  1229. //-----------------------------------------------------------------------------
  1230. template <>
  1231. bool CHudItemEffectMeter_Weapon<CTFSpellBook>::IsEnabled( void )
  1232. {
  1233. if ( !m_pPlayer )
  1234. return false;
  1235. if ( !m_pPlayer->m_Shared.InCond( TF_COND_HALLOWEEN_KART ) )
  1236. return false;
  1237. CTFSpellBook *pWep = dynamic_cast<CTFSpellBook*>( GetWeapon() );
  1238. if ( pWep )
  1239. {
  1240. return true;
  1241. }
  1242. return false;
  1243. }
  1244. //-----------------------------------------------------------------------------
  1245. template <>
  1246. float CHudItemEffectMeter_Weapon<CTFSpellBook>::GetProgress( void )
  1247. {
  1248. if ( !m_pPlayer )
  1249. return 0;
  1250. if ( !m_pPlayer->m_Shared.InCond( TF_COND_HALLOWEEN_KART ) )
  1251. return 0;
  1252. return m_pPlayer->GetKartSpeedBoost();
  1253. }
  1254. //-----------------------------------------------------------------------------
  1255. template <>
  1256. int CHudItemEffectMeter_Weapon<CTFSpellBook>::GetCount( void )
  1257. {
  1258. if ( !m_pPlayer )
  1259. return 0;
  1260. if ( !m_pPlayer->m_Shared.InCond( TF_COND_HALLOWEEN_KART ) )
  1261. return 0;
  1262. return m_pPlayer->GetKartHealth();
  1263. }
  1264. //-----------------------------------------------------------------------------
  1265. template <>
  1266. bool CHudItemEffectMeter_Weapon<CTFSpellBook>::ShowPercentSymbol( void )
  1267. {
  1268. return true;
  1269. }
  1270. //-----------------------------------------------------------------------------
  1271. template <>
  1272. bool CHudItemEffectMeter_Weapon<CTFSpellBook>::ShouldDraw( void )
  1273. {
  1274. if ( CTFMinigameLogic::GetMinigameLogic() && CTFMinigameLogic::GetMinigameLogic()->GetActiveMinigame() )
  1275. {
  1276. if ( m_pPlayer && m_pPlayer->m_Shared.InCond( TF_COND_HALLOWEEN_GHOST_MODE ) )
  1277. return false;
  1278. IViewPortPanel *scoreboard = gViewPortInterface->FindPanelByName( PANEL_SCOREBOARD );
  1279. if ( scoreboard && scoreboard->IsVisible() )
  1280. return false;
  1281. if ( TFGameRules() && ( TFGameRules()->State_Get() != GR_STATE_RND_RUNNING ) )
  1282. return false;
  1283. return true;
  1284. }
  1285. if ( TFGameRules() && TFGameRules()->ShowMatchSummary() )
  1286. {
  1287. return false;
  1288. }
  1289. return CHudItemEffectMeter::ShouldDraw();
  1290. }