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.

808 lines
21 KiB

  1. //========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include <keyvalues.h>
  9. #include "materialsystem/imaterialvar.h"
  10. #include "materialsystem/imaterial.h"
  11. #include "materialsystem/itexture.h"
  12. #include "materialsystem/imaterialsystem.h"
  13. #include "functionproxy.h"
  14. #include "c_cs_player.h"
  15. #include "weapon_csbase.h"
  16. #include "predicted_viewmodel.h"
  17. #include "cs_client_gamestats.h"
  18. #include "econ/econ_item_schema.h"
  19. #include "cstrike15_gcconstants.h"
  20. #include "imaterialproxydict.h"
  21. // memdbgon must be the last include file in a .cpp file!!!
  22. #include "tier0/memdbgon.h"
  23. //-----------------------------------------------------------------------------
  24. // Returns the proximity of the player to the entity
  25. //-----------------------------------------------------------------------------
  26. class CPlayerProximityProxy : public CResultProxy
  27. {
  28. public:
  29. bool Init( IMaterial *pMaterial, KeyValues *pKeyValues );
  30. void OnBind( void *pC_BaseEntity );
  31. private:
  32. float m_Factor;
  33. };
  34. bool CPlayerProximityProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
  35. {
  36. if (!CResultProxy::Init( pMaterial, pKeyValues ))
  37. return false;
  38. m_Factor = pKeyValues->GetFloat( "scale", 0.002 );
  39. return true;
  40. }
  41. void CPlayerProximityProxy::OnBind( void *pC_BaseEntity )
  42. {
  43. if (!pC_BaseEntity)
  44. return;
  45. // Find the distance between the player and this entity....
  46. C_BaseEntity *pEntity = BindArgToEntity( pC_BaseEntity );
  47. C_BaseEntity* pPlayer = C_BasePlayer::GetLocalPlayer();
  48. if (!pPlayer)
  49. return;
  50. Vector delta;
  51. VectorSubtract( pEntity->WorldSpaceCenter(), pPlayer->WorldSpaceCenter(), delta );
  52. Assert( m_pResult );
  53. SetFloatResult( delta.Length() * m_Factor );
  54. }
  55. EXPOSE_MATERIAL_PROXY( CPlayerProximityProxy, PlayerProximity );
  56. //-----------------------------------------------------------------------------
  57. // Returns true if the player's team matches that of the entity the proxy material is attached to
  58. //-----------------------------------------------------------------------------
  59. class CPlayerTeamMatchProxy : public CResultProxy
  60. {
  61. public:
  62. bool Init( IMaterial *pMaterial, KeyValues *pKeyValues );
  63. void OnBind( void *pC_BaseEntity );
  64. private:
  65. };
  66. bool CPlayerTeamMatchProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
  67. {
  68. if (!CResultProxy::Init( pMaterial, pKeyValues ))
  69. return false;
  70. return true;
  71. }
  72. void CPlayerTeamMatchProxy::OnBind( void *pC_BaseEntity )
  73. {
  74. if (!pC_BaseEntity)
  75. return;
  76. // Find the distance between the player and this entity....
  77. C_BaseEntity *pEntity = BindArgToEntity( pC_BaseEntity );
  78. C_BaseEntity* pPlayer = C_BasePlayer::GetLocalPlayer();
  79. if (!pPlayer)
  80. return;
  81. Assert( m_pResult );
  82. SetFloatResult( (pEntity->GetTeamNumber() == pPlayer->GetTeamNumber()) ? 1.0 : 0.0 );
  83. }
  84. EXPOSE_MATERIAL_PROXY( CPlayerTeamMatchProxy, PlayerTeamMatch );
  85. //-----------------------------------------------------------------------------
  86. // Returns the player view direction
  87. //-----------------------------------------------------------------------------
  88. class CPlayerViewProxy : public CResultProxy
  89. {
  90. public:
  91. bool Init( IMaterial *pMaterial, KeyValues *pKeyValues );
  92. void OnBind( void *pC_BaseEntity );
  93. private:
  94. float m_Factor;
  95. };
  96. bool CPlayerViewProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
  97. {
  98. if (!CResultProxy::Init( pMaterial, pKeyValues ))
  99. return false;
  100. m_Factor = pKeyValues->GetFloat( "scale", 2 );
  101. return true;
  102. }
  103. void CPlayerViewProxy::OnBind( void *pC_BaseEntity )
  104. {
  105. if (!pC_BaseEntity)
  106. return;
  107. // Find the view angle between the player and this entity....
  108. C_BaseEntity *pEntity = BindArgToEntity( pC_BaseEntity );
  109. C_BaseEntity* pPlayer = C_BasePlayer::GetLocalPlayer();
  110. if (!pPlayer)
  111. return;
  112. Vector delta;
  113. VectorSubtract( pEntity->WorldSpaceCenter(), pPlayer->WorldSpaceCenter(), delta );
  114. VectorNormalize( delta );
  115. Vector forward;
  116. AngleVectors( pPlayer->GetAbsAngles(), &forward );
  117. Assert( m_pResult );
  118. SetFloatResult( DotProduct( forward, delta ) * m_Factor );
  119. }
  120. EXPOSE_MATERIAL_PROXY( CPlayerViewProxy, PlayerView );
  121. //-----------------------------------------------------------------------------
  122. // Returns the player speed
  123. //-----------------------------------------------------------------------------
  124. class CPlayerSpeedProxy : public CResultProxy
  125. {
  126. public:
  127. bool Init( IMaterial *pMaterial, KeyValues *pKeyValues );
  128. void OnBind( void *pC_BaseEntity );
  129. private:
  130. float m_Factor;
  131. };
  132. bool CPlayerSpeedProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
  133. {
  134. if (!CResultProxy::Init( pMaterial, pKeyValues ))
  135. return false;
  136. m_Factor = pKeyValues->GetFloat( "scale", 0.005 );
  137. return true;
  138. }
  139. void CPlayerSpeedProxy::OnBind( void *pC_BaseEntity )
  140. {
  141. // Find the player speed....
  142. C_BaseEntity* pPlayer = C_BasePlayer::GetLocalPlayer();
  143. if (!pPlayer)
  144. return;
  145. Assert( m_pResult );
  146. SetFloatResult( pPlayer->GetLocalVelocity().Length() * m_Factor );
  147. }
  148. EXPOSE_MATERIAL_PROXY( CPlayerSpeedProxy, PlayerSpeed );
  149. //-----------------------------------------------------------------------------
  150. // Returns the player position
  151. //-----------------------------------------------------------------------------
  152. class CPlayerPositionProxy : public CResultProxy
  153. {
  154. public:
  155. bool Init( IMaterial *pMaterial, KeyValues *pKeyValues );
  156. void OnBind( void *pC_BaseEntity );
  157. private:
  158. float m_Factor;
  159. };
  160. bool CPlayerPositionProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
  161. {
  162. if (!CResultProxy::Init( pMaterial, pKeyValues ))
  163. return false;
  164. m_Factor = pKeyValues->GetFloat( "scale", 0.005 );
  165. return true;
  166. }
  167. void CPlayerPositionProxy::OnBind( void *pC_BaseEntity )
  168. {
  169. // Find the player speed....
  170. C_BaseEntity* pPlayer = C_BasePlayer::GetLocalPlayer();
  171. if (!pPlayer)
  172. return;
  173. // This is actually a vector...
  174. Assert( m_pResult );
  175. Vector res;
  176. VectorMultiply( pPlayer->WorldSpaceCenter(), m_Factor, res );
  177. m_pResult->SetVecValue( res.Base(), 3 );
  178. }
  179. EXPOSE_MATERIAL_PROXY( CPlayerPositionProxy, PlayerPosition );
  180. //-----------------------------------------------------------------------------
  181. // Returns the entity speed
  182. //-----------------------------------------------------------------------------
  183. class CEntitySpeedProxy : public CResultProxy
  184. {
  185. public:
  186. void OnBind( void *pC_BaseEntity );
  187. };
  188. void CEntitySpeedProxy::OnBind( void *pC_BaseEntity )
  189. {
  190. // Find the view angle between the player and this entity....
  191. if (!pC_BaseEntity)
  192. return;
  193. // Find the view angle between the player and this entity....
  194. C_BaseEntity *pEntity = BindArgToEntity( pC_BaseEntity );
  195. Assert( m_pResult );
  196. m_pResult->SetFloatValue( pEntity->GetLocalVelocity().Length() );
  197. }
  198. EXPOSE_MATERIAL_PROXY( CEntitySpeedProxy, EntitySpeed );
  199. //-----------------------------------------------------------------------------
  200. // Returns a random # from 0 - 1 specific to the entity it's applied to
  201. //-----------------------------------------------------------------------------
  202. class CEntityRandomProxy : public CResultProxy
  203. {
  204. public:
  205. bool Init( IMaterial *pMaterial, KeyValues *pKeyValues );
  206. void OnBind( void *pC_BaseEntity );
  207. private:
  208. CFloatInput m_Factor;
  209. };
  210. bool CEntityRandomProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
  211. {
  212. if (!CResultProxy::Init( pMaterial, pKeyValues ))
  213. return false;
  214. if (!m_Factor.Init( pMaterial, pKeyValues, "scale", 1 ))
  215. return false;
  216. return true;
  217. }
  218. void CEntityRandomProxy::OnBind( void *pC_BaseEntity )
  219. {
  220. // Find the view angle between the player and this entity....
  221. if (!pC_BaseEntity)
  222. return;
  223. // Find the view angle between the player and this entity....
  224. C_BaseEntity *pEntity = BindArgToEntity( pC_BaseEntity );
  225. Assert( m_pResult );
  226. m_pResult->SetFloatValue( pEntity->ProxyRandomValue() * m_Factor.GetFloat() );
  227. }
  228. EXPOSE_MATERIAL_PROXY( CEntityRandomProxy, EntityRandom );
  229. #include "utlrbtree.h"
  230. //-----------------------------------------------------------------------------
  231. // StatTrak 'kill odometer' support: given a numerical value expressed as a string, pick a texture frame to represent a given digit
  232. //-----------------------------------------------------------------------------
  233. class CStatTrakDigitProxy : public CResultProxy
  234. {
  235. public:
  236. virtual bool Init( IMaterial *pMaterial, KeyValues *pKeyValues );
  237. virtual void OnBind( void *pC_BaseEntity );
  238. virtual bool HelperOnBindGetStatTrakScore( void *pC_BaseEntity, int *piScore );
  239. private:
  240. CFloatInput m_flDisplayDigit; // the particular digit we want to display
  241. CFloatInput m_flTrimZeros;
  242. };
  243. bool CStatTrakDigitProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
  244. {
  245. if (!CResultProxy::Init( pMaterial, pKeyValues ))
  246. return false;
  247. if (!m_flDisplayDigit.Init( pMaterial, pKeyValues, "displayDigit", 0 ))
  248. return false;
  249. if (!m_flTrimZeros.Init( pMaterial, pKeyValues, "trimZeros", 0 ))
  250. return false;
  251. return true;
  252. }
  253. #include "c_cs_player.h"
  254. #include "weapon_csbase.h"
  255. #include "predicted_viewmodel.h"
  256. bool CStatTrakDigitProxy::HelperOnBindGetStatTrakScore( void *pC_BaseEntity, int *piScore )
  257. {
  258. if ( !pC_BaseEntity )
  259. return false;
  260. if ( !piScore )
  261. return false;
  262. C_BaseEntity *pEntity = BindArgToEntity( pC_BaseEntity );
  263. if ( pEntity )
  264. {
  265. // StatTrak modules are children of their accompanying viewmodels
  266. C_BaseViewModel *pViewModel = dynamic_cast< C_BaseViewModel* >( pEntity->GetMoveParent() );
  267. if ( pViewModel )
  268. {
  269. C_CSPlayer *pPlayer = ToCSPlayer( pViewModel->GetPredictionOwner() );
  270. if ( pPlayer )
  271. {
  272. CWeaponCSBase *pWeap = pPlayer->GetActiveCSWeapon();
  273. if ( pWeap )
  274. {
  275. if ( CEconItemView *pItemView = pWeap->GetEconItemView() )
  276. {
  277. // Always get headshot-trak(TM)
  278. *piScore = pItemView->GetKillEaterValueByType( 0 );
  279. }
  280. }
  281. }
  282. }
  283. }
  284. return true;
  285. }
  286. void CStatTrakDigitProxy::OnBind( void *pC_BaseEntity )
  287. {
  288. int nKillEaterAltScore = 0;
  289. bool bHasScoreToDisplay = HelperOnBindGetStatTrakScore( pC_BaseEntity, &nKillEaterAltScore );
  290. if ( !bHasScoreToDisplay )
  291. { // Force flashing numbers
  292. SetFloatResult( (int) fmod( gpGlobals->curtime, 10.0f ) );
  293. return;
  294. }
  295. int iDesiredDigit = (int)m_flDisplayDigit.GetFloat();
  296. // trim preceding zeros
  297. if ( m_flTrimZeros.GetFloat() > 0 )
  298. {
  299. if ( pow( 10.0f, iDesiredDigit ) > nKillEaterAltScore )
  300. {
  301. SetFloatResult( 10.0f ); //assumed blank frame
  302. return;
  303. }
  304. }
  305. // get the [0-9] value of the digit we want
  306. int iDigitCount = MIN( iDesiredDigit, 10 );
  307. for ( int i=0; i<iDigitCount; i++ )
  308. {
  309. nKillEaterAltScore /= 10;
  310. }
  311. nKillEaterAltScore %= 10;
  312. SetFloatResult( nKillEaterAltScore );
  313. }
  314. EXPOSE_MATERIAL_PROXY( CStatTrakDigitProxy, StatTrakDigit );
  315. //-----------------------------------------------------------------------------
  316. // StatTrak 'kill odometer' support: given a numerical value expressed as a string, pick a texture frame to represent a given digit
  317. //-----------------------------------------------------------------------------
  318. class CStatTrakDigitProxyForModelWeaponPreviewPanel : public CStatTrakDigitProxy
  319. {
  320. public:
  321. virtual bool HelperOnBindGetStatTrakScore( void *pC_BaseEntity, int *puiScore ) OVERRIDE
  322. {
  323. /* Removed for partner depot */
  324. return false;
  325. }
  326. };
  327. EXPOSE_MATERIAL_PROXY( CStatTrakDigitProxyForModelWeaponPreviewPanel, StatTrakDigitForModelWeaponPreview );
  328. #ifdef IRONSIGHT
  329. //-----------------------------------------------------------------------------
  330. // IronSightAmount proxy
  331. //-----------------------------------------------------------------------------
  332. class CIronSightAmountProxy : public CResultProxy
  333. {
  334. public:
  335. virtual bool Init(IMaterial *pMaterial, KeyValues *pKeyValues);
  336. virtual void OnBind(void *pC_BaseEntity);
  337. private:
  338. bool bInvert;
  339. };
  340. bool CIronSightAmountProxy::Init(IMaterial *pMaterial, KeyValues *pKeyValues)
  341. {
  342. if (!CResultProxy::Init(pMaterial, pKeyValues))
  343. return false;
  344. bInvert = false;
  345. CFloatInput m_flInvert;
  346. if ( m_flInvert.Init( pMaterial, pKeyValues, "invert" ) )
  347. bInvert = ( m_flInvert.GetFloat() > 0 );
  348. return true;
  349. }
  350. void CIronSightAmountProxy::OnBind(void *pC_BaseEntity)
  351. {
  352. if (!pC_BaseEntity)
  353. return;
  354. C_BaseEntity *pEntity = BindArgToEntity(pC_BaseEntity);
  355. if (pEntity)
  356. {
  357. C_BaseViewModel *pViewModel = dynamic_cast<C_BaseViewModel*>(pEntity);
  358. if (pViewModel)
  359. {
  360. C_CSPlayer *pPlayer = ToCSPlayer(pViewModel->GetPredictionOwner());
  361. if (pPlayer)
  362. {
  363. CWeaponCSBase *pWeapon = pPlayer->GetActiveCSWeapon();
  364. if ( pWeapon && pWeapon->GetIronSightController() )
  365. {
  366. if ( bInvert )
  367. {
  368. SetFloatResult(Bias( 1.0f - pWeapon->GetIronSightController()->GetIronSightAmount(), 0.2f));
  369. }
  370. else
  371. {
  372. SetFloatResult(Bias(pWeapon->GetIronSightController()->GetIronSightAmount(), 0.2f));
  373. }
  374. }
  375. }
  376. }
  377. }
  378. }
  379. EXPOSE_MATERIAL_PROXY(CIronSightAmountProxy, IronSightAmount);
  380. #endif //IRONSIGHT
  381. //-----------------------------------------------------------------------------
  382. // StatTrakIllum proxy
  383. //-----------------------------------------------------------------------------
  384. class CStatTrakIllumProxy : public CResultProxy
  385. {
  386. public:
  387. virtual bool Init( IMaterial *pMaterial, KeyValues *pKeyValues );
  388. virtual void OnBind( void *pC_BaseEntity );
  389. private:
  390. CFloatInput m_flMinVal;
  391. CFloatInput m_flMaxVal;
  392. };
  393. bool CStatTrakIllumProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
  394. {
  395. if (!CResultProxy::Init( pMaterial, pKeyValues ))
  396. return false;
  397. if (!m_flMinVal.Init( pMaterial, pKeyValues, "minVal", 0.5 ))
  398. return false;
  399. if (!m_flMaxVal.Init( pMaterial, pKeyValues, "maxVal", 1 ))
  400. return false;
  401. return true;
  402. }
  403. void CStatTrakIllumProxy::OnBind( void *pC_BaseEntity )
  404. {
  405. if (!pC_BaseEntity)
  406. return;
  407. C_BaseEntity *pEntity = BindArgToEntity( pC_BaseEntity );
  408. if ( pEntity )
  409. {
  410. // StatTrak modules are children of their accompanying viewmodels
  411. C_BaseViewModel *pViewModel = dynamic_cast< C_BaseViewModel* >( pEntity->GetMoveParent() );
  412. if ( pViewModel )
  413. {
  414. SetFloatResult( Lerp( pViewModel->GetStatTrakGlowMultiplier(), m_flMinVal.GetFloat(), m_flMaxVal.GetFloat() ) );
  415. return;
  416. }
  417. }
  418. }
  419. EXPOSE_MATERIAL_PROXY( CStatTrakIllumProxy, StatTrakIllum );
  420. //-----------------------------------------------------------------------------
  421. // WeaponLabelTextProxy
  422. //-----------------------------------------------------------------------------
  423. class CWeaponLabelTextProxy : public CResultProxy
  424. {
  425. public:
  426. bool Init( IMaterial *pMaterial, KeyValues *pKeyValues );
  427. void OnBind( void *pC_BaseEntity );
  428. virtual bool HelperOnBindGetLabel( void *pC_BaseEntity, const char **p_szLabel );
  429. private:
  430. CFloatInput m_flDisplayDigit;
  431. IMaterialVar *m_pTextureOffsetVar;
  432. };
  433. bool CWeaponLabelTextProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
  434. {
  435. if (!m_flDisplayDigit.Init( pMaterial, pKeyValues, "displayDigit", 0 ))
  436. return false;
  437. bool foundVar;
  438. m_pTextureOffsetVar = pMaterial->FindVar( "$basetexturetransform", &foundVar, false );
  439. if( !foundVar )
  440. return false;
  441. return true;
  442. }
  443. bool CWeaponLabelTextProxy::HelperOnBindGetLabel( void *pC_BaseEntity, const char **p_szLabel )
  444. {
  445. if ( !pC_BaseEntity )
  446. return false;
  447. C_BaseEntity *pEntity = BindArgToEntity( pC_BaseEntity );
  448. if ( pEntity )
  449. {
  450. // uid modules are children of their accompanying viewmodels
  451. C_BaseViewModel *pViewModel = dynamic_cast< C_BaseViewModel* >( pEntity->GetMoveParent() );
  452. if ( pViewModel )
  453. {
  454. CBaseCombatWeapon *pWeapon = pViewModel->GetWeapon();
  455. if ( pWeapon )
  456. {
  457. CEconItemView *pItem = pWeapon->GetEconItemView();
  458. if ( pItem )
  459. {
  460. *p_szLabel = pItem->GetCustomName();
  461. return true;
  462. }
  463. }
  464. }
  465. }
  466. return false;
  467. }
  468. void CWeaponLabelTextProxy::OnBind( void *pC_BaseEntity )
  469. {
  470. const char *p_szLabel = NULL;
  471. bool bHasLabel = HelperOnBindGetLabel( pC_BaseEntity, &p_szLabel );
  472. if (!bHasLabel || !p_szLabel)
  473. return;
  474. //get the digit index we need to display
  475. int nDigit = (int)m_flDisplayDigit.GetFloat();
  476. //center the text within NUM_UID_CHARS
  477. int nStrLen = (int)strlen( p_szLabel );
  478. int nPrependSpaces = ( NUM_UID_CHARS - nStrLen ) / 2;
  479. nDigit -= nPrependSpaces;
  480. int nCharIndex = 0;
  481. if ( nDigit >= 0 && nDigit < nStrLen )
  482. {
  483. nCharIndex = p_szLabel[nDigit] - 32;
  484. }
  485. int nIndexHoriz = fmod( nCharIndex, 12.0f );
  486. int nIndexVertical = nCharIndex / 12;
  487. float flOffsetX = 0.083333f * nIndexHoriz;
  488. float flOffsetY = 0.125f * nIndexVertical;
  489. VMatrix mat( 1.0f, 0.0f, 0.0f, flOffsetX,
  490. 0.0f, 1.0f, 0.0f, flOffsetY,
  491. 0.0f, 0.0f, 1.0f, 0.0f,
  492. 0.0f, 0.0f, 0.0f, 1.0f );
  493. m_pTextureOffsetVar->SetMatrixValue( mat );
  494. }
  495. EXPOSE_MATERIAL_PROXY( CWeaponLabelTextProxy, WeaponLabelText );
  496. class CWeaponLabelTextProxyForModelWeaponPreviewPanel : public CWeaponLabelTextProxy
  497. {
  498. public:
  499. virtual bool HelperOnBindGetLabel( void *pC_BaseEntity, const char **p_szLabel )
  500. {
  501. /* Removed for partner depot */
  502. return false;
  503. }
  504. };
  505. EXPOSE_MATERIAL_PROXY( CWeaponLabelTextProxyForModelWeaponPreviewPanel, WeaponLabelTextPreview );
  506. int g_HighlightedSticker = -1;
  507. int g_PeelSticker = -1;
  508. void CC_HighlightSticker(const CCommand& args)
  509. {
  510. int nParam = atoi(args[1]);
  511. if ( nParam >= 0 && nParam <= 4 )
  512. {
  513. g_HighlightedSticker = nParam;
  514. }
  515. }
  516. static ConCommand highlight_sticker("highlight_sticker", CC_HighlightSticker, "", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY );
  517. void CC_PeelSticker(const CCommand& args)
  518. {
  519. int nParam = atoi(args[1]);
  520. if (nParam >= 0 && nParam <= 4)
  521. {
  522. g_PeelSticker = nParam;
  523. }
  524. }
  525. static ConCommand peel_sticker("peel_sticker", CC_PeelSticker, "", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY);
  526. //-----------------------------------------------------------------------------
  527. // Sticker selection proxy
  528. //-----------------------------------------------------------------------------
  529. class CStickerSelectionProxy : public CResultProxy
  530. {
  531. public:
  532. virtual bool Init(IMaterial *pMaterial, KeyValues *pKeyValues);
  533. virtual void OnBind(void *pC_BaseEntity);
  534. virtual void CheckMyGlobal( void );
  535. int m_nStickerIndex;
  536. float m_flSelectedness;
  537. };
  538. bool CStickerSelectionProxy::Init(IMaterial *pMaterial, KeyValues *pKeyValues)
  539. {
  540. if (!CResultProxy::Init(pMaterial, pKeyValues))
  541. return false;
  542. CFloatInput flStickerIndex;
  543. if (!flStickerIndex.Init(pMaterial, pKeyValues, "stickerindex", 0))
  544. return false;
  545. m_nStickerIndex = (int)flStickerIndex.GetFloat();
  546. m_flSelectedness = 0.0f;
  547. return true;
  548. }
  549. void CStickerSelectionProxy::CheckMyGlobal( void )
  550. {
  551. if (g_HighlightedSticker > -1 && m_nStickerIndex == g_HighlightedSticker)
  552. {
  553. m_flSelectedness = 1.0f;
  554. g_HighlightedSticker = -1;
  555. }
  556. }
  557. void CStickerSelectionProxy::OnBind(void *pC_BaseEntity)
  558. {
  559. //if (!pC_BaseEntity)
  560. // return;
  561. CheckMyGlobal();
  562. if ( m_flSelectedness > 0.01f )
  563. {
  564. m_flSelectedness = Approach( 0.0f, m_flSelectedness, gpGlobals->frametime * 0.5f );
  565. SetFloatResult( m_flSelectedness );
  566. }
  567. else if ( m_flSelectedness > 0.0f )
  568. {
  569. SetFloatResult( 0.0f );
  570. }
  571. }
  572. EXPOSE_MATERIAL_PROXY(CStickerSelectionProxy, StickerSelection);
  573. class CStickerPeelProxy : public CStickerSelectionProxy
  574. {
  575. public:
  576. virtual void CheckMyGlobal( void );
  577. };
  578. void CStickerPeelProxy::CheckMyGlobal(void)
  579. {
  580. if (g_PeelSticker > -1 && m_nStickerIndex == g_PeelSticker)
  581. {
  582. m_flSelectedness = 1.0f;
  583. g_PeelSticker = -1;
  584. }
  585. }
  586. EXPOSE_MATERIAL_PROXY(CStickerPeelProxy, StickerPeel);
  587. //-----------------------------------------------------------------------------
  588. // CrosshairColor proxy
  589. //-----------------------------------------------------------------------------
  590. extern ConVar cl_crosshaircolor_r;
  591. extern ConVar cl_crosshaircolor_g;
  592. extern ConVar cl_crosshaircolor_b;
  593. class CCrossHairColorProxy : public CResultProxy
  594. {
  595. public:
  596. virtual bool Init(IMaterial *pMaterial, KeyValues *pKeyValues);
  597. virtual void OnBind(void *pC_BaseEntity);
  598. Vector m_vecLocalCrossHairColor;
  599. };
  600. bool CCrossHairColorProxy::Init(IMaterial *pMaterial, KeyValues *pKeyValues)
  601. {
  602. if (!CResultProxy::Init(pMaterial, pKeyValues))
  603. return false;
  604. m_vecLocalCrossHairColor.Init();
  605. return true;
  606. }
  607. void CCrossHairColorProxy::OnBind(void *pC_BaseEntity)
  608. {
  609. if ( m_vecLocalCrossHairColor.x != cl_crosshaircolor_r.GetFloat() ||
  610. m_vecLocalCrossHairColor.y != cl_crosshaircolor_g.GetFloat() ||
  611. m_vecLocalCrossHairColor.z != cl_crosshaircolor_b.GetFloat() )
  612. {
  613. m_vecLocalCrossHairColor.x = cl_crosshaircolor_r.GetFloat();
  614. m_vecLocalCrossHairColor.y = cl_crosshaircolor_g.GetFloat();
  615. m_vecLocalCrossHairColor.z = cl_crosshaircolor_b.GetFloat();
  616. SetVecResult( (float)m_vecLocalCrossHairColor.x * 0.0039,
  617. (float)m_vecLocalCrossHairColor.y * 0.0039,
  618. (float)m_vecLocalCrossHairColor.z * 0.0039, 1);
  619. }
  620. }
  621. EXPOSE_MATERIAL_PROXY(CCrossHairColorProxy, CrossHairColor);
  622. float g_flEconInspectPreviewTime = 0;
  623. class CEconInspectPreviewTimeProxy : public CResultProxy
  624. {
  625. public:
  626. bool Init( IMaterial *pMaterial, KeyValues *pKeyValues );
  627. void OnBind( void *pC_BaseEntity );
  628. };
  629. bool CEconInspectPreviewTimeProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
  630. {
  631. if ( !CResultProxy::Init( pMaterial, pKeyValues ) )
  632. return false;
  633. return true;
  634. }
  635. void CEconInspectPreviewTimeProxy::OnBind( void *pC_BaseEntity )
  636. {
  637. Assert( m_pResult );
  638. SetFloatResult( gpGlobals->curtime - g_flEconInspectPreviewTime );
  639. }
  640. EXPOSE_MATERIAL_PROXY( CEconInspectPreviewTimeProxy, EconInspectPreviewTime );