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.

196 lines
4.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. //
  9. // BonusProgress.cpp
  10. //
  11. // implementation of CHudBonusProgress class
  12. //
  13. #include "cbase.h"
  14. #include "hud.h"
  15. #include "hud_macros.h"
  16. #include "view.h"
  17. #include "iclientmode.h"
  18. #include <KeyValues.h>
  19. #include <vgui/ISurface.h>
  20. #include <vgui/ISystem.h>
  21. #include <vgui_controls/AnimationController.h>
  22. #include <vgui/ILocalize.h>
  23. using namespace vgui;
  24. #include "hudelement.h"
  25. #include "hud_numericdisplay.h"
  26. #include "convar.h"
  27. // memdbgon must be the last include file in a .cpp file!!!
  28. #include "tier0/memdbgon.h"
  29. #define INIT_BONUS_PROGRESS -1
  30. //-----------------------------------------------------------------------------
  31. // Purpose: BonusProgress panel
  32. //-----------------------------------------------------------------------------
  33. class CHudBonusProgress : public CHudElement, public CHudNumericDisplay
  34. {
  35. DECLARE_CLASS_SIMPLE( CHudBonusProgress, CHudNumericDisplay );
  36. public:
  37. CHudBonusProgress( const char *pElementName );
  38. virtual void Init( void );
  39. virtual void VidInit( void );
  40. virtual void Reset( void );
  41. virtual void OnThink();
  42. private:
  43. void SetChallengeLabel( void );
  44. private:
  45. // old variables
  46. int m_iBonusProgress;
  47. int m_iLastChallenge;
  48. };
  49. DECLARE_HUDELEMENT( CHudBonusProgress );
  50. //-----------------------------------------------------------------------------
  51. // Purpose: Constructor
  52. //-----------------------------------------------------------------------------
  53. CHudBonusProgress::CHudBonusProgress( const char *pElementName ) : CHudElement( pElementName ), CHudNumericDisplay(NULL, "HudBonusProgress")
  54. {
  55. SetHiddenBits( HIDEHUD_BONUS_PROGRESS );
  56. }
  57. //-----------------------------------------------------------------------------
  58. // Purpose:
  59. //-----------------------------------------------------------------------------
  60. void CHudBonusProgress::Init()
  61. {
  62. Reset();
  63. }
  64. //-----------------------------------------------------------------------------
  65. // Purpose:
  66. //-----------------------------------------------------------------------------
  67. void CHudBonusProgress::Reset()
  68. {
  69. m_iBonusProgress = INIT_BONUS_PROGRESS;
  70. C_BasePlayer *local = C_BasePlayer::GetLocalPlayer();
  71. if ( local )
  72. m_iLastChallenge = local->GetBonusChallenge();
  73. SetChallengeLabel();
  74. SetDisplayValue(m_iBonusProgress);
  75. }
  76. //-----------------------------------------------------------------------------
  77. // Purpose:
  78. //-----------------------------------------------------------------------------
  79. void CHudBonusProgress::VidInit()
  80. {
  81. Reset();
  82. }
  83. //-----------------------------------------------------------------------------
  84. // Purpose:
  85. //-----------------------------------------------------------------------------
  86. void CHudBonusProgress::OnThink()
  87. {
  88. C_GameRules *pGameRules = GameRules();
  89. if ( !pGameRules )
  90. {
  91. // Not ready to init!
  92. return;
  93. }
  94. int newBonusProgress = 0;
  95. int iBonusChallenge = 0;
  96. C_BasePlayer *local = C_BasePlayer::GetLocalPlayer();
  97. if ( !local )
  98. {
  99. // Not ready to init!
  100. return;
  101. }
  102. // Never below zero
  103. newBonusProgress = MAX( local->GetBonusProgress(), 0 );
  104. iBonusChallenge = local->GetBonusChallenge();
  105. // Only update the fade if we've changed bonusProgress
  106. if ( newBonusProgress == m_iBonusProgress && m_iLastChallenge == iBonusChallenge )
  107. {
  108. return;
  109. }
  110. m_iBonusProgress = newBonusProgress;
  111. if ( m_iLastChallenge != iBonusChallenge )
  112. {
  113. m_iLastChallenge = iBonusChallenge;
  114. SetChallengeLabel();
  115. }
  116. g_pClientMode->GetViewportAnimationController()->StartAnimationSequence("BonusProgressFlash");
  117. if ( pGameRules->IsBonusChallengeTimeBased() )
  118. {
  119. SetIsTime( true );
  120. SetIndent( false );
  121. }
  122. else
  123. {
  124. SetIsTime( false );
  125. SetIndent( true );
  126. }
  127. SetDisplayValue(m_iBonusProgress);
  128. }
  129. void CHudBonusProgress::SetChallengeLabel( void )
  130. {
  131. // Blank for no challenge
  132. if ( m_iLastChallenge == 0 )
  133. {
  134. SetLabelText(L"");
  135. return;
  136. }
  137. char szBonusTextName[] = "#Valve_Hud_BONUS_PROGRESS00";
  138. int iStringLength = Q_strlen( szBonusTextName );
  139. szBonusTextName[ iStringLength - 2 ] = ( m_iLastChallenge / 10 ) + '0';
  140. szBonusTextName[ iStringLength - 1 ] = ( m_iLastChallenge % 10 ) + '0';
  141. wchar_t *tempString = g_pVGuiLocalize->Find(szBonusTextName);
  142. if (tempString)
  143. {
  144. SetLabelText(tempString);
  145. return;
  146. }
  147. // Couldn't find a special string for this challenge
  148. tempString = g_pVGuiLocalize->Find("#Valve_Hud_BONUS_PROGRESS");
  149. if (tempString)
  150. {
  151. SetLabelText(tempString);
  152. return;
  153. }
  154. // Couldn't find any localizable string
  155. SetLabelText(L"BONUS");
  156. }