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.

154 lines
3.8 KiB

  1. //========= Copyright 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 "hud_base_account.h"
  11. using namespace vgui;
  12. CHudBaseAccount::CHudBaseAccount( const char *pName ) :
  13. CHudNumericDisplay( NULL, pName ), CHudElement( pName )
  14. {
  15. SetHiddenBits( HIDEHUD_PLAYERDEAD );
  16. SetIndent( false ); // don't indent small numbers in the drawing code - we're doing it manually
  17. }
  18. void CHudBaseAccount::LevelInit( void )
  19. {
  20. m_iPreviousAccount = -1;
  21. m_iPreviousDelta = 0;
  22. m_flLastAnimationEnd = 0.0f;
  23. m_pszLastAnimationName = NULL;
  24. m_pszQueuedAnimationName = NULL;
  25. GetAnimationController()->StartAnimationSequence("AccountMoneyInvisible");
  26. }
  27. void CHudBaseAccount::ApplySchemeSettings(vgui::IScheme *pScheme)
  28. {
  29. BaseClass::ApplySchemeSettings(pScheme);
  30. m_clrRed = pScheme->GetColor( "HudIcon_Red", Color( 255, 16, 16, 255 ) );
  31. m_clrGreen = pScheme->GetColor( "HudIcon_Green", Color( 16, 255, 16, 255 ) );
  32. m_pAccountIcon = gHUD.GetIcon( "dollar_sign" );
  33. m_pPlusIcon = gHUD.GetIcon( "plus_sign" );
  34. m_pMinusIcon = gHUD.GetIcon( "minus_sign" );
  35. if( m_pAccountIcon )
  36. {
  37. icon_tall = ( GetTall() / 2 ) - YRES(2);
  38. float scale = icon_tall / (float)m_pAccountIcon->Height();
  39. icon_wide = ( scale ) * (float)m_pAccountIcon->Width();
  40. }
  41. }
  42. bool CHudBaseAccount::ShouldDraw()
  43. {
  44. // Deriving classes must implement
  45. Assert( 0 );
  46. return false;
  47. }
  48. void CHudBaseAccount::Reset( void )
  49. {
  50. // Round is restarting
  51. if ( m_flLastAnimationEnd > gpGlobals->curtime && m_pszLastAnimationName )
  52. {
  53. // if we had an animation in progress, queue it to be kicked it off again
  54. m_pszQueuedAnimationName = m_pszLastAnimationName;
  55. }
  56. }
  57. void CHudBaseAccount::Paint()
  58. {
  59. int account = GetPlayerAccount();
  60. //don't show delta on initial money give
  61. if( m_iPreviousAccount < 0 )
  62. m_iPreviousAccount = account;
  63. if( m_iPreviousAccount != account )
  64. {
  65. m_iPreviousDelta = account - m_iPreviousAccount;
  66. m_pszQueuedAnimationName = NULL;
  67. if( m_iPreviousDelta < 0 )
  68. {
  69. m_pszLastAnimationName = "AccountMoneyRemoved";
  70. }
  71. else
  72. {
  73. m_pszLastAnimationName = "AccountMoneyAdded";
  74. }
  75. GetAnimationController()->StartAnimationSequence( m_pszLastAnimationName );
  76. m_flLastAnimationEnd = gpGlobals->curtime + GetAnimationController()->GetAnimationSequenceLength( m_pszLastAnimationName );
  77. m_iPreviousAccount = account;
  78. }
  79. else if ( m_pszQueuedAnimationName )
  80. {
  81. GetAnimationController()->StartAnimationSequence( m_pszQueuedAnimationName );
  82. m_pszQueuedAnimationName = NULL;
  83. }
  84. if( m_pAccountIcon )
  85. {
  86. m_pAccountIcon->DrawSelf( icon_xpos, icon_ypos, icon_wide, icon_tall, GetFgColor() );
  87. }
  88. int xpos = digit_xpos - GetNumberWidth( m_hNumberFont, account );
  89. // draw current account
  90. vgui::surface()->DrawSetTextColor(GetFgColor());
  91. PaintNumbers( m_hNumberFont, xpos, digit_ypos, account );
  92. //draw account additions / subtractions
  93. if( m_iPreviousDelta < 0 )
  94. {
  95. if( m_pMinusIcon )
  96. {
  97. m_pMinusIcon->DrawSelf( icon2_xpos, icon2_ypos, icon_wide, icon_tall, m_Ammo2Color );
  98. }
  99. }
  100. else
  101. {
  102. if( m_pPlusIcon )
  103. {
  104. m_pPlusIcon->DrawSelf( icon2_xpos, icon2_ypos, icon_wide, icon_tall, m_Ammo2Color );
  105. }
  106. }
  107. int delta = abs(m_iPreviousDelta);
  108. xpos = digit2_xpos - GetNumberWidth( m_hNumberFont, delta );
  109. // draw delta
  110. vgui::surface()->DrawSetTextColor(m_Ammo2Color);
  111. PaintNumbers( m_hNumberFont, xpos, digit2_ypos, delta );
  112. }
  113. int CHudBaseAccount::GetNumberWidth(HFont font, int number)
  114. {
  115. int width = 0;
  116. surface()->DrawSetTextFont(font);
  117. wchar_t unicode[6];
  118. V_snwprintf(unicode, ARRAYSIZE(unicode), L"%d", number);
  119. for (wchar_t *ch = unicode; *ch != 0; ch++)
  120. {
  121. width += vgui::surface()->GetCharacterWidth( font, *ch );
  122. }
  123. return width;
  124. }