Counter Strike : Global Offensive Source Code
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
5.1 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include <vgui_controls/Panel.h>
  8. #include <vgui/isurface.h>
  9. #include <vgui_controls/AnimationController.h>
  10. #include <vgui/ILocalize.h>
  11. #include "hud_base_account.h"
  12. #include "cs_gamerules.h"
  13. #include "iachievementmgr.h"
  14. // NOTE: This has to be the last file included!
  15. #include "tier0/memdbgon.h"
  16. using namespace vgui;
  17. CHudBaseAccount::CHudBaseAccount( const char *pName ) :
  18. CHudNumericDisplay( NULL, pName ), CHudElement( pName )
  19. {
  20. SetHiddenBits( HIDEHUD_PLAYERDEAD );
  21. SetIndent( false ); // don't indent small numbers in the drawing code - we're doing it manually
  22. }
  23. void CHudBaseAccount::LevelInit( void )
  24. {
  25. m_iPreviousAccount = -1;
  26. m_iPreviousDelta = 0;
  27. m_flLastAnimationEnd = 0.0f;
  28. m_pszLastAnimationName = NULL;
  29. m_pszQueuedAnimationName = NULL;
  30. GetAnimationController()->StartAnimationSequence("AccountMoneyInvisible");
  31. }
  32. void CHudBaseAccount::ApplySchemeSettings(vgui::IScheme *pScheme)
  33. {
  34. BaseClass::ApplySchemeSettings(pScheme);
  35. m_clrRed = pScheme->GetColor( "HudIcon_Red", Color( 255, 16, 16, 255 ) );
  36. m_clrGreen = pScheme->GetColor( "HudIcon_Green", Color( 16, 255, 16, 255 ) );
  37. m_pAccountIcon = HudIcons().GetIcon( "dollar_sign" );
  38. m_pPlusIcon = HudIcons().GetIcon( "plus_sign" );
  39. m_pMinusIcon = HudIcons().GetIcon( "minus_sign" );
  40. if( m_pAccountIcon )
  41. {
  42. icon_tall = ( GetTall() / 2 ) - YRES(2);
  43. float scale = icon_tall / (float)m_pAccountIcon->Height();
  44. icon_wide = ( scale ) * (float)m_pAccountIcon->Width();
  45. }
  46. }
  47. bool CHudBaseAccount::ShouldDraw()
  48. {
  49. // Deriving classes must implement
  50. Assert( 0 );
  51. return false;
  52. }
  53. void CHudBaseAccount::Reset( void )
  54. {
  55. // Round is restarting
  56. if ( m_flLastAnimationEnd > gpGlobals->curtime && m_pszLastAnimationName )
  57. {
  58. // if we had an animation in progress, queue it to be kicked it off again
  59. m_pszQueuedAnimationName = m_pszLastAnimationName;
  60. }
  61. }
  62. void CHudBaseAccount::Paint()
  63. {
  64. if ( CSGameRules()->IsPlayingGunGameProgressive() || CSGameRules()->IsPlayingGunGameTRBomb() )
  65. {
  66. int weaponindex = GetPlayerGunGameWeapon();
  67. // draw current gun game weapon index
  68. wchar_t unicode[32];
  69. wchar_t param1[32];
  70. wchar_t param2[32];
  71. wchar_t *pReason = g_pVGuiLocalize->Find( "Cstrike_Game_GunGameWeaponStatus" );
  72. if ( !pReason )
  73. {
  74. pReason = L"%s1 / %s2";
  75. }
  76. V_snwprintf( param1, ARRAYSIZE(param1), L"%d", weaponindex + 1 );
  77. V_snwprintf( param2, ARRAYSIZE(param2), L"%d", engine->GetAchievementMgr()->GetNumProgressiveGunGameWeapons() );
  78. g_pVGuiLocalize->ConstructString( unicode, sizeof( unicode ), pReason, 2, param1, param2 );
  79. static int width = 0;
  80. for (wchar_t *ch = unicode; *ch != 0; ch++)
  81. {
  82. width += vgui::surface()->GetCharacterWidth( m_hTextFont, *ch );
  83. }
  84. static int xpos = MIN( 0, ( digit_xpos - width ) );
  85. vgui::surface()->DrawSetTextFont(m_hTextFont);
  86. vgui::surface()->DrawSetTextColor(GetFgColor());
  87. vgui::surface()->DrawSetTextPos(xpos, digit_ypos);
  88. vgui::surface()->DrawUnicodeString( unicode );
  89. }
  90. else
  91. {
  92. int account = GetPlayerAccount();
  93. //don't show delta on initial money give
  94. if( m_iPreviousAccount < 0 )
  95. m_iPreviousAccount = account;
  96. if( m_iPreviousAccount != account )
  97. {
  98. m_iPreviousDelta = account - m_iPreviousAccount;
  99. m_pszQueuedAnimationName = NULL;
  100. if( m_iPreviousDelta < 0 )
  101. {
  102. m_pszLastAnimationName = "AccountMoneyRemoved";
  103. }
  104. else
  105. {
  106. m_pszLastAnimationName = "AccountMoneyAdded";
  107. }
  108. GetAnimationController()->StartAnimationSequence( m_pszLastAnimationName );
  109. m_flLastAnimationEnd = gpGlobals->curtime + GetAnimationController()->GetAnimationSequenceLength( m_pszLastAnimationName );
  110. m_iPreviousAccount = account;
  111. }
  112. else if ( m_pszQueuedAnimationName )
  113. {
  114. GetAnimationController()->StartAnimationSequence( m_pszQueuedAnimationName );
  115. m_pszQueuedAnimationName = NULL;
  116. }
  117. if( m_pAccountIcon )
  118. {
  119. m_pAccountIcon->DrawSelf( icon_xpos, icon_ypos, icon_wide, icon_tall, GetFgColor() );
  120. }
  121. int xpos = digit_xpos - GetNumberWidth( m_hNumberFont, account );
  122. // draw current account
  123. vgui::surface()->DrawSetTextColor(GetFgColor());
  124. PaintNumbers( m_hNumberFont, xpos, digit_ypos, account );
  125. //draw account additions / subtractions
  126. if( m_iPreviousDelta < 0 )
  127. {
  128. if( m_pMinusIcon )
  129. {
  130. m_pMinusIcon->DrawSelf( icon2_xpos, icon2_ypos, icon_wide, icon_tall, m_Ammo2Color );
  131. }
  132. }
  133. else
  134. {
  135. if( m_pPlusIcon )
  136. {
  137. m_pPlusIcon->DrawSelf( icon2_xpos, icon2_ypos, icon_wide, icon_tall, m_Ammo2Color );
  138. }
  139. }
  140. int delta = abs(m_iPreviousDelta);
  141. xpos = digit2_xpos - GetNumberWidth( m_hNumberFont, delta );
  142. // draw delta
  143. vgui::surface()->DrawSetTextColor(m_Ammo2Color);
  144. PaintNumbers( m_hNumberFont, xpos, digit2_ypos, delta );
  145. }
  146. }
  147. int CHudBaseAccount::GetNumberWidth(HFont font, int number)
  148. {
  149. int width = 0;
  150. surface()->DrawSetTextFont(font);
  151. wchar_t unicode[6];
  152. V_snwprintf(unicode, ARRAYSIZE(unicode), L"%d", number);
  153. for (wchar_t *ch = unicode; *ch != 0; ch++)
  154. {
  155. width += vgui::surface()->GetCharacterWidth( font, *ch );
  156. }
  157. return width;
  158. }