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.

250 lines
6.4 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 "weapon_mg42.h"
  19. #include "dodcornercutpanel.h"
  20. #include "dod_hud_playerstatus_mgheat.h"
  21. //-----------------------------------------------------------------------------
  22. // Purpose:
  23. //-----------------------------------------------------------------------------
  24. void CDoDHudMGHeatProgressBar::ApplySchemeSettings( vgui::IScheme *pScheme )
  25. {
  26. BaseClass::ApplySchemeSettings( pScheme );
  27. m_clrActive = pScheme->GetColor( "HudMGHeatBar.Active", GetFgColor() );
  28. m_clrActiveLow = pScheme->GetColor( "HudMGHeatBar.ActiveLow", GetFgColor() );
  29. m_clrInactive = pScheme->GetColor( "HudMGHeatBar.InActive", GetFgColor() );
  30. m_clrInactiveLow = pScheme->GetColor( "HudMGHeatBar.InActiveLow", GetFgColor() );
  31. }
  32. //-----------------------------------------------------------------------------
  33. // Purpose:
  34. //-----------------------------------------------------------------------------
  35. void CDoDHudMGHeatProgressBar::Paint()
  36. {
  37. BaseClass::Paint();
  38. int xpos = 0, ypos = 0;
  39. int x, y, w, t;
  40. GetBounds( x, y, w, t );
  41. if ( m_flPercentage > m_flWarningLevel )
  42. {
  43. vgui::surface()->DrawSetColor( m_clrInactiveLow );
  44. }
  45. else
  46. {
  47. vgui::surface()->DrawSetColor( m_clrInactive );
  48. }
  49. int nActiveLimit = w * ( 1.0f - m_flPercentage );
  50. while ( xpos + m_flSliceWidth < w )
  51. {
  52. if ( xpos + m_flSliceWidth > nActiveLimit )
  53. {
  54. if ( m_flPercentage > m_flWarningLevel )
  55. {
  56. vgui::surface()->DrawSetColor( m_clrActiveLow );
  57. }
  58. else
  59. {
  60. vgui::surface()->DrawSetColor( m_clrActive );
  61. }
  62. }
  63. vgui::surface()->DrawFilledRect( xpos, ypos, xpos + m_flSliceWidth, ypos + t );
  64. xpos += m_flSliceWidth + m_flSliceSpacer;
  65. }
  66. }
  67. //-----------------------------------------------------------------------------
  68. // Purpose:
  69. //-----------------------------------------------------------------------------
  70. void CDoDHudMGHeatIcon::SetType( int nType )
  71. {
  72. m_nType = nType;
  73. switch( nType )
  74. {
  75. // case WEAPON_30CAL:
  76. // m_icon = gHUD.GetIcon( m_szIcon30cal );
  77. // break;
  78. case WEAPON_MG42:
  79. default:
  80. m_icon = gHUD.GetIcon( m_szIconMg42 );
  81. break;
  82. }
  83. }
  84. //-----------------------------------------------------------------------------
  85. // Purpose:
  86. //-----------------------------------------------------------------------------
  87. void CDoDHudMGHeatIcon::ApplySettings( KeyValues *inResourceData )
  88. {
  89. // Q_strncpy( m_szIcon30cal, inResourceData->GetString( "icon_30cal", "mgheat_30cal" ), sizeof( m_szIcon30cal ) );
  90. Q_strncpy( m_szIconMg42, inResourceData->GetString( "icon_mg42", "mgheat_mg42" ), sizeof( m_szIconMg42 ) );
  91. BaseClass::ApplySettings( inResourceData );
  92. }
  93. //-----------------------------------------------------------------------------
  94. // Purpose:
  95. //-----------------------------------------------------------------------------
  96. void CDoDHudMGHeatIcon::ApplySchemeSettings( vgui::IScheme *pScheme )
  97. {
  98. BaseClass::ApplySchemeSettings( pScheme );
  99. m_clrActive = pScheme->GetColor( "HudMGHeatIcon.Active", GetFgColor() );
  100. m_clrActiveLow = pScheme->GetColor( "HudMGHeatIcon.ActiveLow", GetFgColor() );
  101. }
  102. //-----------------------------------------------------------------------------
  103. // Purpose:
  104. //-----------------------------------------------------------------------------
  105. void CDoDHudMGHeatIcon::Paint()
  106. {
  107. BaseClass::Paint();
  108. int x, y, w, t;
  109. GetBounds( x, y, w, t );
  110. if ( m_icon )
  111. {
  112. m_icon->DrawSelf( 0, 0, w, t, ( m_flPercentage > m_flWarningLevel ) ? m_clrActiveLow : m_clrActive );
  113. }
  114. }
  115. //-----------------------------------------------------------------------------
  116. // Purpose:
  117. //-----------------------------------------------------------------------------
  118. CDoDHudMGHeat::CDoDHudMGHeat( vgui::Panel *parent, const char *name ) : vgui::EditablePanel( parent, name )
  119. {
  120. m_pBackground = new CDoDCutEditablePanel( this, "MGHeatBackground" );
  121. m_pIcon = new CDoDHudMGHeatIcon( this, "MGHeatIcon" );
  122. m_pProgressBar = new CDoDHudMGHeatProgressBar( this, "MGHeatProgressBar" );
  123. }
  124. void CDoDHudMGHeat::ApplySchemeSettings( vgui::IScheme *pScheme )
  125. {
  126. // load control settings...
  127. LoadControlSettings( "resource/UI/HudPlayerStatusMGHeat.res" );
  128. BaseClass::ApplySchemeSettings( pScheme );
  129. }
  130. //-----------------------------------------------------------------------------
  131. // Purpose:
  132. //-----------------------------------------------------------------------------
  133. void CDoDHudMGHeat::SetVisible( bool state )
  134. {
  135. if ( m_pBackground && m_pBackground->IsVisible() != state )
  136. {
  137. m_pBackground->SetVisible( state );
  138. }
  139. if ( m_pIcon && m_pIcon->IsVisible() != state )
  140. {
  141. m_pIcon->SetVisible( state );
  142. }
  143. if ( m_pProgressBar && m_pProgressBar->IsVisible() != state )
  144. {
  145. m_pProgressBar->SetVisible( state );
  146. }
  147. }
  148. //-----------------------------------------------------------------------------
  149. // Purpose:
  150. //-----------------------------------------------------------------------------
  151. void CDoDHudMGHeat::OnThink()
  152. {
  153. BaseClass::OnThink();
  154. C_DODPlayer *pPlayer = C_DODPlayer::GetLocalDODPlayer();
  155. if ( pPlayer )
  156. {
  157. CWeaponDODBase *pWeapon = pPlayer->GetActiveDODWeapon();
  158. if ( pWeapon )
  159. {
  160. /* if ( pWeapon->IsA( WEAPON_30CAL ) )
  161. {
  162. CWeapon30cal *p30Cal = (CWeapon30cal *)pWeapon;
  163. if( p30Cal )
  164. {
  165. float flPercentage = (float)p30Cal->GetWeaponHeat() / 100.0;
  166. if ( m_pProgressBar )
  167. {
  168. m_pProgressBar->SetPercentage( flPercentage );
  169. }
  170. if ( m_pIcon )
  171. {
  172. m_pIcon->SetPercentage( flPercentage );
  173. }
  174. }
  175. if ( m_pIcon )
  176. {
  177. m_pIcon->SetType( WEAPON_30CAL );
  178. }
  179. SetVisible( true );
  180. }
  181. */
  182. if ( pWeapon->IsA( WEAPON_MG42 ) )
  183. {
  184. CWeaponMG42 *pMG42 = (CWeaponMG42 *)pWeapon;
  185. if( pMG42 )
  186. {
  187. float flPercentage = (float)pMG42->GetWeaponHeat() / 100.0;
  188. if ( m_pProgressBar )
  189. {
  190. m_pProgressBar->SetPercentage( flPercentage );
  191. }
  192. if ( m_pIcon )
  193. {
  194. m_pIcon->SetPercentage( flPercentage );
  195. }
  196. }
  197. if ( m_pIcon )
  198. {
  199. m_pIcon->SetType( WEAPON_MG42 );
  200. }
  201. SetVisible( true );
  202. }
  203. else
  204. {
  205. SetVisible( false );
  206. }
  207. }
  208. }
  209. }