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.

172 lines
5.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include <KeyValues.h>
  8. #include <vgui/IScheme.h>
  9. #include <vgui/ISurface.h>
  10. #include <vgui/ISystem.h>
  11. #include <vgui_controls/AnimationController.h>
  12. #include <vgui_controls/EditablePanel.h>
  13. #include <vgui_controls/ImagePanel.h>
  14. #include <vgui/ISurface.h>
  15. #include "c_dod_team.h"
  16. #include "c_dod_playerresource.h"
  17. #include "c_dod_player.h"
  18. #include "dodcornercutpanel.h"
  19. #include "dod_hud_playerstatus_stamina.h"
  20. //-----------------------------------------------------------------------------
  21. // Purpose:
  22. //-----------------------------------------------------------------------------
  23. void CDoDHudStaminaProgressBar::ApplySchemeSettings( vgui::IScheme *pScheme )
  24. {
  25. BaseClass::ApplySchemeSettings( pScheme );
  26. m_clrActive = pScheme->GetColor( "HudStaminaBar.Active", GetFgColor() );
  27. m_clrActiveLow = pScheme->GetColor( "HudStaminaBar.ActiveLow", GetFgColor() );
  28. m_clrInactive = pScheme->GetColor( "HudStaminaBar.InActive", GetFgColor() );
  29. m_clrInactiveLow = pScheme->GetColor( "HudStaminaBar.InActiveLow", GetFgColor() );
  30. }
  31. //-----------------------------------------------------------------------------
  32. // Purpose:
  33. //-----------------------------------------------------------------------------
  34. void CDoDHudStaminaProgressBar::Paint()
  35. {
  36. BaseClass::Paint();
  37. int xpos = 0, ypos = 0;
  38. int x, y, w, t;
  39. GetBounds( x, y, w, t );
  40. if ( m_flPercentage < m_flWarningLevel )
  41. {
  42. vgui::surface()->DrawSetColor( m_clrActiveLow );
  43. }
  44. else
  45. {
  46. vgui::surface()->DrawSetColor( m_clrActive );
  47. }
  48. int nActiveLimit = w * m_flPercentage;
  49. while ( xpos + m_flSliceWidth < w )
  50. {
  51. if ( xpos + m_flSliceWidth > nActiveLimit )
  52. {
  53. if ( m_flPercentage < m_flWarningLevel )
  54. {
  55. vgui::surface()->DrawSetColor( m_clrInactiveLow );
  56. }
  57. else
  58. {
  59. vgui::surface()->DrawSetColor( m_clrInactive );
  60. }
  61. }
  62. vgui::surface()->DrawFilledRect( xpos, ypos, xpos + m_flSliceWidth, ypos + t );
  63. xpos += m_flSliceWidth + m_flSliceSpacer;
  64. }
  65. }
  66. //-----------------------------------------------------------------------------
  67. // Purpose:
  68. //-----------------------------------------------------------------------------
  69. CDoDHudStaminaIcon::CDoDHudStaminaIcon( vgui::Panel *parent, const char *name ) : vgui::ImagePanel( parent, name )
  70. {
  71. m_icon = NULL;
  72. memset( m_szIcon, 0, sizeof( m_szIcon ) );
  73. }
  74. //-----------------------------------------------------------------------------
  75. // Purpose:
  76. //-----------------------------------------------------------------------------
  77. void CDoDHudStaminaIcon::ApplySettings( KeyValues *inResourceData )
  78. {
  79. BaseClass::ApplySettings( inResourceData );
  80. Q_strncpy( m_szIcon, inResourceData->GetString( "stamina_icon", "stamina_icon" ), sizeof( m_szIcon ) );
  81. }
  82. //-----------------------------------------------------------------------------
  83. // Purpose:
  84. //-----------------------------------------------------------------------------
  85. void CDoDHudStaminaIcon::ApplySchemeSettings( vgui::IScheme *pScheme )
  86. {
  87. BaseClass::ApplySchemeSettings( pScheme );
  88. m_clrActive = pScheme->GetColor( "HudStaminaIcon.Active", GetFgColor() );
  89. m_clrActiveLow = pScheme->GetColor( "HudStaminaIcon.ActiveLow", GetFgColor() );
  90. if ( !m_icon )
  91. {
  92. m_icon = gHUD.GetIcon( m_szIcon );
  93. }
  94. }
  95. //-----------------------------------------------------------------------------
  96. // Purpose:
  97. //-----------------------------------------------------------------------------
  98. void CDoDHudStaminaIcon::Paint()
  99. {
  100. int x, y, w, t;
  101. GetBounds( x, y, w, t );
  102. if ( m_icon )
  103. {
  104. m_icon->DrawSelf( 0, -3, w, t, ( m_flPercentage < m_flWarningLevel ) ? m_clrActiveLow : m_clrActive );
  105. }
  106. }
  107. //-----------------------------------------------------------------------------
  108. // Purpose:
  109. //-----------------------------------------------------------------------------
  110. CDoDHudStamina::CDoDHudStamina( vgui::Panel *parent, const char *name ) : vgui::EditablePanel( parent, name )
  111. {
  112. m_pBackground = new CDoDCutEditablePanel( this, "StaminaBackground" );
  113. m_pIcon = new CDoDHudStaminaIcon( this, "StaminaIcon" );
  114. m_pProgressBar = new CDoDHudStaminaProgressBar( this, "StaminaProgressBar" );
  115. // load control settings...
  116. LoadControlSettings( "resource/UI/HudPlayerStatusStamina.res" );
  117. }
  118. //-----------------------------------------------------------------------------
  119. // Purpose:
  120. //-----------------------------------------------------------------------------
  121. void CDoDHudStamina::OnScreenSizeChanged( int iOldWide, int iOldTall )
  122. {
  123. LoadControlSettings( "resource/UI/HudPlayerStatusStamina.res" );
  124. }
  125. //-----------------------------------------------------------------------------
  126. // Purpose:
  127. //-----------------------------------------------------------------------------
  128. void CDoDHudStamina::OnThink()
  129. {
  130. BaseClass::OnThink();
  131. C_DODPlayer *pPlayer = C_DODPlayer::GetLocalDODPlayer();
  132. if ( pPlayer )
  133. {
  134. float flPercentage = (float)( pPlayer->m_Shared.GetStamina() ) / 100.0f;
  135. if ( m_pProgressBar )
  136. {
  137. m_pProgressBar->SetPercentage( flPercentage );
  138. }
  139. if ( m_pIcon )
  140. {
  141. m_pIcon->SetPercentage( flPercentage );
  142. }
  143. }
  144. }