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.

170 lines
5.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. #include "cbase.h"
  3. #include "hud_baseachievement_tracker.h"
  4. #include "c_tf_player.h"
  5. #include "iachievementmgr.h"
  6. #include "achievementmgr.h"
  7. #include "hud_vote.h"
  8. #include "baseachievement.h"
  9. // memdbgon must be the last include file in a .cpp file!!!
  10. #include "tier0/memdbgon.h"
  11. using namespace vgui;
  12. ConVar hud_achievement_count_engineer( "hud_achievement_count_engineer", "3", FCVAR_ARCHIVE, "Max number of achievements that can be shown on the HUD when you're an engineer" );
  13. class CHudAchievementTracker : public CHudBaseAchievementTracker
  14. {
  15. DECLARE_CLASS_SIMPLE( CHudAchievementTracker, CHudBaseAchievementTracker );
  16. public:
  17. CHudAchievementTracker( const char *pElementName );
  18. virtual void OnThink();
  19. virtual void PerformLayout();
  20. virtual int GetMaxAchievementsShown();
  21. virtual bool ShouldShowAchievement( IAchievement *pAchievement );
  22. virtual bool ShouldDraw();
  23. private:
  24. int m_iPlayerClass;
  25. CPanelAnimationVarAliasType( int, m_iNormalY, "NormalY", "5", "proportional_int" );
  26. CPanelAnimationVarAliasType( int, m_iEngineerY, "EngineerY", "170", "proportional_int" );
  27. };
  28. DECLARE_HUDELEMENT( CHudAchievementTracker );
  29. CHudAchievementTracker::CHudAchievementTracker( const char *pElementName ) : BaseClass( pElementName )
  30. {
  31. m_iPlayerClass = -1;
  32. }
  33. // layout panel again if player class changes
  34. void CHudAchievementTracker::OnThink()
  35. {
  36. C_TFPlayer *pPlayer = CTFPlayer::GetLocalTFPlayer();
  37. if ( pPlayer )
  38. {
  39. C_TFPlayerClass *pClass = pPlayer->GetPlayerClass();
  40. if ( pClass && m_iPlayerClass != pClass->GetClassIndex() )
  41. {
  42. InvalidateLayout();
  43. m_iPlayerClass = pClass->GetClassIndex();
  44. m_flNextThink = gpGlobals->curtime - 0.1f;
  45. }
  46. }
  47. BaseClass::OnThink();
  48. }
  49. // Show less achievements on the HUD for the engineer
  50. int CHudAchievementTracker::GetMaxAchievementsShown()
  51. {
  52. C_TFPlayer *pPlayer = CTFPlayer::GetLocalTFPlayer();
  53. if ( pPlayer && pPlayer->IsPlayerClass( TF_CLASS_ENGINEER ) )
  54. {
  55. return hud_achievement_count_engineer.GetInt();
  56. }
  57. return BaseClass::GetMaxAchievementsShown();
  58. }
  59. // shift panel down for the engineer
  60. void CHudAchievementTracker::PerformLayout()
  61. {
  62. BaseClass::PerformLayout();
  63. C_TFPlayer *pPlayer = CTFPlayer::GetLocalTFPlayer();
  64. int x, y;
  65. GetPos( x, y );
  66. if ( pPlayer && pPlayer->IsPlayerClass( TF_CLASS_ENGINEER ) )
  67. {
  68. SetPos( x, m_iEngineerY );
  69. }
  70. else
  71. {
  72. SetPos( x, m_iNormalY );
  73. }
  74. }
  75. bool CHudAchievementTracker::ShouldShowAchievement( IAchievement *pAchievement )
  76. {
  77. if ( !BaseClass::ShouldShowAchievement( pAchievement ) )
  78. return false;
  79. C_TFPlayer *pPlayer = CTFPlayer::GetLocalTFPlayer();
  80. if ( !pPlayer )
  81. return false;
  82. // filter out class specific achievements
  83. int id = pAchievement->GetAchievementID();
  84. if ( id >= ACHIEVEMENT_TF_MEDIC_START_RANGE && id <= ACHIEVEMENT_TF_MEDIC_END_RANGE )
  85. {
  86. if ( !pPlayer->IsPlayerClass( TF_CLASS_MEDIC ) )
  87. return false;
  88. }
  89. else if ( id >= ACHIEVEMENT_TF_PYRO_START_RANGE && id <= ACHIEVEMENT_TF_PYRO_END_RANGE )
  90. {
  91. if ( !pPlayer->IsPlayerClass( TF_CLASS_PYRO ) )
  92. return false;
  93. }
  94. else if ( id >= ACHIEVEMENT_TF_HEAVY_START_RANGE && id <= ACHIEVEMENT_TF_HEAVY_END_RANGE )
  95. {
  96. if ( !pPlayer->IsPlayerClass( TF_CLASS_HEAVYWEAPONS ) )
  97. return false;
  98. }
  99. else if ( id >= ACHIEVEMENT_TF_SCOUT_START_RANGE && id <= ACHIEVEMENT_TF_SCOUT_END_RANGE )
  100. {
  101. if ( !pPlayer->IsPlayerClass( TF_CLASS_SCOUT ) )
  102. return false;
  103. }
  104. else if ( id >= ACHIEVEMENT_TF_SNIPER_START_RANGE && id <= ACHIEVEMENT_TF_SNIPER_END_RANGE )
  105. {
  106. if ( !pPlayer->IsPlayerClass( TF_CLASS_SNIPER ) )
  107. return false;
  108. }
  109. else if ( id >= ACHIEVEMENT_TF_SPY_START_RANGE && id <= ACHIEVEMENT_TF_SPY_END_RANGE )
  110. {
  111. if ( !pPlayer->IsPlayerClass( TF_CLASS_SPY ) )
  112. return false;
  113. }
  114. else if ( id >= ACHIEVEMENT_TF_SOLDIER_START_RANGE && id <= ACHIEVEMENT_TF_SOLDIER_END_RANGE )
  115. {
  116. if ( !pPlayer->IsPlayerClass( TF_CLASS_SOLDIER ) )
  117. return false;
  118. }
  119. else if ( id >= ACHIEVEMENT_TF_DEMOMAN_START_RANGE && id <= ACHIEVEMENT_TF_DEMOMAN_END_RANGE )
  120. {
  121. if ( !pPlayer->IsPlayerClass( TF_CLASS_DEMOMAN ) )
  122. return false;
  123. }
  124. else if ( id >= ACHIEVEMENT_TF_ENGINEER_START_RANGE && id <= ACHIEVEMENT_TF_ENGINEER_END_RANGE )
  125. {
  126. if ( !pPlayer->IsPlayerClass( TF_CLASS_ENGINEER ) )
  127. return false;
  128. }
  129. CBaseAchievement *pBaseAchievement = dynamic_cast< CBaseAchievement * >( pAchievement );
  130. if ( pBaseAchievement && pBaseAchievement->GetMapNameFilter() && pBaseAchievement->GetAchievementMgr() )
  131. {
  132. if ( Q_strcmp( pBaseAchievement->GetAchievementMgr()->GetMapName(), pBaseAchievement->GetMapNameFilter() ) != 0 )
  133. return false;
  134. }
  135. return true;
  136. }
  137. //-----------------------------------------------------------------------------
  138. // Purpose:
  139. //-----------------------------------------------------------------------------
  140. bool CHudAchievementTracker::ShouldDraw()
  141. {
  142. C_TFPlayer *pPlayer = CTFPlayer::GetLocalTFPlayer();
  143. if ( pPlayer && pPlayer->IsPlayerClass( TF_CLASS_ENGINEER ) )
  144. {
  145. CHudVote *pHudVote = GET_HUDELEMENT( CHudVote );
  146. if ( pHudVote && pHudVote->ShouldDraw() )
  147. return false;
  148. }
  149. return BaseClass::ShouldDraw();
  150. }