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.

700 lines
19 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "iclientmode.h"
  8. #include "c_dod_player.h"
  9. #include <vgui/IScheme.h>
  10. #include <vgui/ISurface.h>
  11. #include <vgui_controls/AnimationController.h>
  12. #include "dod_hud_playerstatus_ammo.h"
  13. #include "ihudlcd.h"
  14. float GetScale( int nIconWidth, int nIconHeight, int nWidth, int nHeight )
  15. {
  16. float flScale = 1.0;
  17. if ( nIconWidth == nWidth && nIconHeight <= nHeight ) // no scaling necessary
  18. {
  19. return flScale;
  20. }
  21. else if ( nIconHeight == nHeight && nIconWidth <= nWidth ) // no scaling necessary
  22. {
  23. return flScale;
  24. }
  25. else if ( nIconWidth < nWidth && nIconHeight < nHeight ) // scale the image up
  26. {
  27. float scaleW = 0.0, scaleH = 0.0;
  28. if ( nIconWidth < nWidth )
  29. {
  30. scaleW = (float)nWidth / (float)nIconWidth;
  31. }
  32. if ( nIconHeight < nHeight )
  33. {
  34. scaleH = (float)nHeight / (float)nIconHeight;
  35. }
  36. if ( scaleW != 0.0 && scaleH != 0.0 )
  37. {
  38. if ( scaleW < scaleH )
  39. {
  40. flScale = scaleW;
  41. }
  42. else
  43. {
  44. flScale = scaleH;
  45. }
  46. }
  47. else if ( scaleW != 0.0 )
  48. {
  49. flScale = scaleW;
  50. }
  51. else
  52. {
  53. flScale = scaleH;
  54. }
  55. }
  56. else // scale the image down
  57. {
  58. float scaleW = 0.0, scaleH = 0.0;
  59. if ( nIconWidth > nWidth )
  60. {
  61. scaleW = (float)nWidth / (float)nIconWidth;
  62. }
  63. if ( nIconHeight > nHeight )
  64. {
  65. scaleH = (float)nHeight / (float)nIconHeight;
  66. }
  67. if ( scaleW != 0.0 && scaleH != 0.0 )
  68. {
  69. if ( scaleW < scaleH )
  70. {
  71. flScale = scaleW;
  72. }
  73. else
  74. {
  75. flScale = scaleH;
  76. }
  77. }
  78. else if ( scaleW != 0.0 )
  79. {
  80. flScale = scaleW;
  81. }
  82. else
  83. {
  84. flScale = scaleH;
  85. }
  86. }
  87. return flScale;
  88. }
  89. //-----------------------------------------------------------------------------
  90. // Purpose: Constructor
  91. //-----------------------------------------------------------------------------
  92. CDoDHudAmmo::CDoDHudAmmo( vgui::Panel *parent, const char *name ) : vgui::Panel( parent, name )
  93. {
  94. m_iAdditiveWhiteID = vgui::surface()->CreateNewTextureID();
  95. vgui::surface()->DrawSetTextureFile( m_iAdditiveWhiteID, "vgui/white_additive", true, false );
  96. m_clrIcon = Color( 255, 255, 255, 255 );
  97. hudlcd->SetGlobalStat( "(ammo_primary)", "0" );
  98. hudlcd->SetGlobalStat( "(ammo_secondary)", "0" );
  99. hudlcd->SetGlobalStat( "(weapon_print_name)", "" );
  100. hudlcd->SetGlobalStat( "(weapon_name)", "" );
  101. }
  102. //-----------------------------------------------------------------------------
  103. // Purpose:
  104. //-----------------------------------------------------------------------------
  105. void CDoDHudAmmo::Init( void )
  106. {
  107. m_iAmmo = -1;
  108. m_iAmmo2 = -1;
  109. }
  110. //-----------------------------------------------------------------------------
  111. // Purpose:
  112. //-----------------------------------------------------------------------------
  113. void CDoDHudAmmo::ApplySchemeSettings( vgui::IScheme *pScheme )
  114. {
  115. BaseClass::ApplySchemeSettings( pScheme );
  116. m_clrTextColor = pScheme->GetColor( "HudAmmoCount", GetFgColor() );
  117. m_clrTextXColor = pScheme->GetColor( "HudPanelBorder", GetFgColor() );
  118. }
  119. //-----------------------------------------------------------------------------
  120. // Purpose: called every frame to get ammo info from the weapon
  121. //-----------------------------------------------------------------------------
  122. void CDoDHudAmmo::OnThink()
  123. {
  124. C_BaseCombatWeapon *wpn = GetActiveWeapon();
  125. C_BasePlayer *player = C_BasePlayer::GetLocalPlayer();
  126. hudlcd->SetGlobalStat( "(weapon_print_name)", wpn ? wpn->GetPrintName() : " " );
  127. hudlcd->SetGlobalStat( "(weapon_name)", wpn ? wpn->GetName() : " " );
  128. if ( !wpn || !player || !wpn->UsesPrimaryAmmo() )
  129. {
  130. hudlcd->SetGlobalStat( "(ammo_primary)", "n/a" );
  131. hudlcd->SetGlobalStat( "(ammo_secondary)", "n/a" );
  132. SetPaintEnabled( false );
  133. SetPaintBackgroundEnabled( false );
  134. return;
  135. }
  136. else
  137. {
  138. SetPaintEnabled( true );
  139. SetPaintBackgroundEnabled( true );
  140. }
  141. // get the ammo in our clip
  142. int ammo1 = wpn->Clip1();
  143. int ammo2;
  144. if ( ammo1 < 0 )
  145. {
  146. // we don't use clip ammo, just use the total ammo count
  147. ammo1 = player->GetAmmoCount( wpn->GetPrimaryAmmoType() );
  148. ammo2 = 0;
  149. }
  150. else
  151. {
  152. // we use clip ammo, so the second ammo is the total ammo
  153. ammo2 = player->GetAmmoCount( wpn->GetPrimaryAmmoType() );
  154. }
  155. hudlcd->SetGlobalStat( "(ammo_primary)", VarArgs( "%d", ammo1 ) );
  156. hudlcd->SetGlobalStat( "(ammo_secondary)", VarArgs( "%d", ammo2 ) );
  157. if ( wpn == m_hCurrentActiveWeapon )
  158. {
  159. // same weapon, just update counts
  160. SetAmmo( ammo1, true );
  161. SetAmmo2( ammo2, true );
  162. }
  163. else
  164. {
  165. // diferent weapon, change without triggering
  166. SetAmmo( ammo1, false );
  167. SetAmmo2( ammo2, false );
  168. // update whether or not we show the total ammo display
  169. m_bUsesClips = wpn->UsesClipsForAmmo1();
  170. m_hCurrentActiveWeapon = wpn;
  171. }
  172. }
  173. //-----------------------------------------------------------------------------
  174. // Purpose: Updates ammo display
  175. //-----------------------------------------------------------------------------
  176. void CDoDHudAmmo::SetAmmo( int ammo, bool playAnimation )
  177. {
  178. if ( ammo != m_iAmmo )
  179. {
  180. m_iAmmo = ammo;
  181. }
  182. }
  183. //-----------------------------------------------------------------------------
  184. // Purpose: Updates 2nd ammo display
  185. //-----------------------------------------------------------------------------
  186. void CDoDHudAmmo::SetAmmo2( int ammo2, bool playAnimation )
  187. {
  188. if ( ammo2 != m_iAmmo2 )
  189. {
  190. m_iAmmo2 = ammo2;
  191. }
  192. }
  193. //-----------------------------------------------------------------------------
  194. // Purpose:
  195. //-----------------------------------------------------------------------------
  196. void CDoDHudAmmo::DrawAmmoCount( int count )
  197. {
  198. char buf[16];
  199. Q_snprintf( buf, sizeof(buf), "x" );
  200. DrawText( buf, clip_count_text_xpos, clip_count_text_ypos, m_clrTextXColor );
  201. Q_snprintf( buf, sizeof(buf), " %d", count );
  202. DrawText( buf, clip_count_text_xpos, clip_count_text_ypos, m_clrTextColor );
  203. }
  204. //-----------------------------------------------------------------------------
  205. // Purpose:
  206. //-----------------------------------------------------------------------------
  207. void CDoDHudAmmo::PaintGrenadeAmmo( CWeaponDODBase *pWpn )
  208. {
  209. const CHudTexture *pAmmoIcon = pWpn->GetSpriteAmmo();
  210. Assert( pAmmoIcon );
  211. int xpos = small_icon_xpos, ypos = small_icon_ypos;
  212. int w = small_icon_width, t = small_icon_height;
  213. int nIconWidth = 0, nIconHeight = 0;
  214. float scale = 1.0f;
  215. if ( pAmmoIcon )
  216. {
  217. nIconWidth = pAmmoIcon->Width();
  218. nIconHeight = pAmmoIcon->Height();
  219. scale = GetScale( nIconWidth, nIconHeight, w, t );
  220. nIconWidth *= scale;
  221. nIconHeight *= scale;
  222. if ( nIconWidth < small_icon_width - XRES(2) ) // 2 is our buffer for when we need to re-calculate the xpos
  223. {
  224. xpos = small_icon_xpos + small_icon_width / 2.0 - nIconWidth / 2.0;
  225. }
  226. if ( nIconHeight < small_icon_height - YRES(2) ) // 2 is our buffer for when we need to re-calculate the ypos
  227. {
  228. ypos = small_icon_ypos + small_icon_height / 2.0 - nIconHeight / 2.0;
  229. }
  230. if ( m_iAmmo > 0 )
  231. {
  232. pAmmoIcon->DrawSelf( xpos, ypos, nIconWidth, nIconHeight, m_clrIcon );
  233. DrawAmmoCount( m_iAmmo );
  234. }
  235. }
  236. }
  237. //-----------------------------------------------------------------------------
  238. // Purpose:
  239. //-----------------------------------------------------------------------------
  240. void CDoDHudAmmo::PaintRifleGrenadeAmmo( CWeaponDODBase *pWpn )
  241. {
  242. const CHudTexture *pAmmoIcon = pWpn->GetSpriteAmmo();
  243. Assert( pAmmoIcon );
  244. int xpos = small_icon_xpos, ypos = small_icon_ypos;
  245. int w = small_icon_width, t = small_icon_height;
  246. int nIconWidth = 0, nIconHeight = 0;
  247. float scale = 1.0f;
  248. if ( pAmmoIcon )
  249. {
  250. nIconWidth = pAmmoIcon->Width();
  251. nIconHeight = pAmmoIcon->Height();
  252. scale = GetScale( nIconWidth, nIconHeight, w, t );
  253. nIconWidth *= scale;
  254. nIconHeight *= scale;
  255. if ( nIconWidth < small_icon_width - XRES(2) ) // 2 is our buffer for when we need to re-calculate the xpos
  256. {
  257. xpos = small_icon_xpos + small_icon_width / 2.0 - nIconWidth / 2.0;
  258. }
  259. if ( nIconHeight < small_icon_height - YRES(2) ) // 2 is our buffer for when we need to re-calculate the ypos
  260. {
  261. ypos = small_icon_ypos + small_icon_height / 2.0 - nIconHeight / 2.0;
  262. }
  263. int ammo = m_iAmmo + m_iAmmo2;
  264. if ( ammo > 0 )
  265. {
  266. pAmmoIcon->DrawSelf( xpos, ypos, nIconWidth, nIconHeight, m_clrIcon );
  267. DrawAmmoCount( ammo );
  268. }
  269. }
  270. }
  271. //-----------------------------------------------------------------------------
  272. // Purpose:
  273. //-----------------------------------------------------------------------------
  274. void CDoDHudAmmo::PaintBazookaAmmo( CWeaponDODBase *pWpn )
  275. {
  276. int panelX, panelY, panelW, panelT;
  277. GetBounds( panelX, panelY, panelW, panelT );
  278. const CHudTexture *pTubeIcon = pWpn->GetSpriteAmmo2();
  279. const CHudTexture *pRocketIcon = pWpn->GetSpriteAmmo();
  280. const CHudTexture *pExtraIcon = pWpn->GetSpriteAutoaim();
  281. Assert( pTubeIcon );
  282. Assert( pRocketIcon );
  283. Assert( pExtraIcon );
  284. int xpos = 0, ypos = 0;
  285. int nIconWidth = 0, nIconHeight = 0;
  286. float scale = 1.0f;
  287. if ( pTubeIcon && pRocketIcon )
  288. {
  289. nIconWidth = pTubeIcon->Width();
  290. nIconHeight = pTubeIcon->Height();
  291. xpos = large_icon_xpos;
  292. ypos = large_icon_ypos;
  293. // mad hax
  294. int width = large_icon_width + XRES(10);
  295. scale = GetScale( nIconWidth, nIconHeight, width, large_icon_height );
  296. nIconWidth *= scale;
  297. nIconHeight *= scale;
  298. if ( nIconWidth < large_icon_width - XRES(2) ) // 2 is our buffer for when we need to re-calculate the xpos
  299. {
  300. xpos = small_icon_xpos + small_icon_width / 2.0 - nIconWidth / 2.0;
  301. }
  302. if ( nIconHeight < large_icon_height - YRES(2) ) // 2 is our buffer for when we need to re-calculate the ypos
  303. {
  304. ypos = small_icon_ypos + small_icon_height / 2.0 - nIconHeight / 2.0;
  305. }
  306. pTubeIcon->DrawSelf( xpos, ypos, nIconWidth, nIconHeight, m_clrIcon );
  307. // If our clip is full, draw the rocket
  308. if( pRocketIcon )
  309. {
  310. if( m_iAmmo > 0 )
  311. {
  312. pRocketIcon->DrawSelf( xpos, ypos, nIconWidth, nIconHeight, m_clrIcon );
  313. }
  314. }
  315. }
  316. // Draw the extra rockets
  317. if( m_iAmmo2 > 0 && pExtraIcon )
  318. {
  319. // Align the extra clip on the same baseline as the large clip
  320. xpos = extra_clip_xpos;
  321. ypos = extra_clip_ypos;
  322. nIconWidth = pExtraIcon->Width();
  323. nIconHeight = pExtraIcon->Height();
  324. if ( nIconWidth > extra_clip_width || nIconHeight > extra_clip_height )
  325. {
  326. scale = GetScale( nIconWidth, nIconHeight, extra_clip_width, extra_clip_height );
  327. nIconWidth *= scale;
  328. nIconHeight *= scale;
  329. }
  330. if ( nIconWidth < extra_clip_width - XRES(2) ) // 2 is our buffer for when we need to re-calculate the ypos
  331. {
  332. xpos = extra_clip_xpos + extra_clip_width / 2.0 - nIconWidth / 2.0;
  333. }
  334. if ( nIconHeight < extra_clip_height - YRES(2) ) // 2 is our buffer for when we need to re-calculate the ypos
  335. {
  336. ypos = extra_clip_ypos + extra_clip_height / 2.0 - nIconHeight / 2.0;
  337. }
  338. pExtraIcon->DrawSelf( xpos, ypos, pExtraIcon->Width() * scale, pExtraIcon->Height() * scale, m_clrIcon );
  339. DrawAmmoCount( m_iAmmo2 );
  340. }
  341. }
  342. //-----------------------------------------------------------------------------
  343. // Purpose:
  344. //-----------------------------------------------------------------------------
  345. void CDoDHudAmmo::PaintMGAmmo( CWeaponDODBase *pWpn )
  346. {
  347. int panelX, panelY, panelW, panelT;
  348. GetBounds( panelX, panelY, panelW, panelT );
  349. const CHudTexture *pFullClip = pWpn->GetSpriteAmmo();
  350. const CHudTexture *pExtraClip = pWpn->GetSpriteAmmo2();
  351. Assert( pFullClip );
  352. Assert( pExtraClip );
  353. int xpos = 0, ypos = 0;
  354. int nIconWidth = 0, nIconHeight = 0;
  355. float scale = 1.0f;
  356. if ( pFullClip )
  357. {
  358. nIconWidth = pFullClip->Width();
  359. nIconHeight = pFullClip->Height();
  360. xpos = large_icon_xpos;
  361. ypos = large_icon_ypos;
  362. scale = GetScale( nIconWidth, nIconHeight, large_icon_width, large_icon_height );
  363. nIconWidth *= scale;
  364. nIconHeight *= scale;
  365. if ( nIconWidth < large_icon_width - XRES(2) ) // 2 is our buffer for when we need to re-calculate the xpos
  366. {
  367. xpos = small_icon_xpos + small_icon_width / 2.0 - nIconWidth / 2.0;
  368. }
  369. if ( nIconHeight < large_icon_height - YRES(2) ) // 2 is our buffer for when we need to re-calculate the ypos
  370. {
  371. ypos = small_icon_ypos + small_icon_height / 2.0 - nIconHeight / 2.0;
  372. }
  373. pFullClip->DrawSelf( xpos, ypos, nIconWidth, nIconHeight, m_clrIcon );
  374. char buf[16];
  375. Q_snprintf( buf, sizeof(buf), "%d", m_iAmmo );
  376. DrawText( buf, xpos + nIconWidth - ( (float)nIconWidth / 3.0 ), ypos + nIconHeight - ( (float)nIconHeight / 3.0 ), m_clrTextColor );
  377. }
  378. //how many full or partially full clips do we have?
  379. int clips = m_iAmmo2 / pWpn->GetMaxClip1();
  380. //account for the partial clip, if it exists
  381. if( clips * pWpn->GetMaxClip1() < m_iAmmo2 )
  382. {
  383. clips++;
  384. }
  385. if( clips > 0 && pExtraClip )
  386. {
  387. //align the extra clip on the same baseline as the large clip
  388. xpos = extra_clip_xpos;
  389. ypos = extra_clip_ypos;
  390. nIconWidth = pExtraClip->Width();
  391. nIconHeight = pExtraClip->Height();
  392. if ( nIconWidth > extra_clip_width || nIconHeight > extra_clip_height )
  393. {
  394. scale = GetScale( nIconWidth, nIconHeight, extra_clip_width, extra_clip_height );
  395. nIconWidth *= scale;
  396. nIconHeight *= scale;
  397. }
  398. if ( nIconWidth < extra_clip_width - XRES(2) ) // 2 is our buffer for when we need to re-calculate the ypos
  399. {
  400. xpos = extra_clip_xpos + extra_clip_width / 2.0 - nIconWidth / 2.0;
  401. }
  402. if ( nIconHeight < extra_clip_height - YRES(2) ) // 2 is our buffer for when we need to re-calculate the ypos
  403. {
  404. ypos = extra_clip_ypos + extra_clip_height / 2.0 - nIconHeight / 2.0;
  405. }
  406. pExtraClip->DrawSelf( xpos, ypos, pExtraClip->Width() * scale, pExtraClip->Height() * scale, m_clrIcon );
  407. DrawAmmoCount( clips );
  408. }
  409. }
  410. //-----------------------------------------------------------------------------
  411. // Purpose:
  412. //-----------------------------------------------------------------------------
  413. void CDoDHudAmmo::PaintGunAmmo( CWeaponDODBase *pWpn )
  414. {
  415. int panelX, panelY, panelW, panelT;
  416. GetBounds( panelX, panelY, panelW, panelT );
  417. //regular gun
  418. const CHudTexture *pEmptyClip = pWpn->GetSpriteAmmo();
  419. const CHudTexture *pFullClip = pWpn->GetSpriteAmmo2();
  420. const CHudTexture *pExtraClip = pWpn->GetSpriteAutoaim();
  421. Assert( pEmptyClip );
  422. Assert( pFullClip );
  423. Assert( pExtraClip );
  424. int xpos = 0, ypos = 0;
  425. int nIconWidth = 0, nIconHeight = 0;
  426. float scale = 1.0f;
  427. if ( pFullClip && pEmptyClip )
  428. {
  429. nIconWidth = pFullClip->Width();
  430. nIconHeight = pFullClip->Height();
  431. xpos = large_icon_xpos;
  432. ypos = large_icon_ypos;
  433. scale = GetScale( nIconWidth, nIconHeight, large_icon_width, large_icon_height );
  434. nIconWidth *= scale;
  435. nIconHeight *= scale;
  436. if ( nIconWidth < large_icon_width - XRES(2) ) // 2 is our buffer for when we need to re-calculate the xpos
  437. {
  438. xpos = small_icon_xpos + small_icon_width / 2.0 - nIconWidth / 2.0;
  439. }
  440. if ( nIconHeight < large_icon_height - YRES(2) ) // 2 is our buffer for when we need to re-calculate the ypos
  441. {
  442. ypos = small_icon_ypos + small_icon_height / 2.0 - nIconHeight / 2.0;
  443. }
  444. pFullClip->DrawSelf( xpos, ypos, nIconWidth, nIconHeight, m_clrIcon );
  445. // base percent is how much of the bullet clip to always draw.
  446. // total cropped height of the bullet sprite will be
  447. // base percent + bullet height * bullets
  448. float flBasePercent = (float)pWpn->GetDODWpnData().m_iHudClipBaseHeight / (float)pWpn->GetDODWpnData().m_iHudClipHeight;
  449. float flBulletHeightPercent = (float)pWpn->GetDODWpnData().m_iHudClipBulletHeight / (float)pWpn->GetDODWpnData().m_iHudClipHeight;
  450. float flHeight = (float)pEmptyClip->Height();
  451. //Now we draw the bullets inside based on how full our clip is
  452. float flDrawHeight = flHeight * ( 1.0 - ( flBasePercent + flBulletHeightPercent * m_iAmmo ) );
  453. int nOffset = (int)flDrawHeight;
  454. int yPosOffset = nOffset * scale;
  455. pEmptyClip->DrawSelfCropped( xpos, ypos + yPosOffset, 0, nOffset, pEmptyClip->Width(), pEmptyClip->Height() - nOffset, nIconWidth, nIconHeight - yPosOffset, m_clrIcon );
  456. }
  457. // how many full or partially full clips do we have?
  458. int clips = m_iAmmo2 / pWpn->GetMaxClip1();
  459. // account for the partial clip, if it exists
  460. if( clips * pWpn->GetMaxClip1() < m_iAmmo2 )
  461. {
  462. clips++;
  463. }
  464. if( clips > 0 && pExtraClip )
  465. {
  466. //align the extra clip on the same baseline as the large clip
  467. xpos = extra_clip_xpos;
  468. ypos = extra_clip_ypos;
  469. nIconWidth = pExtraClip->Width();
  470. nIconHeight = pExtraClip->Height();
  471. if ( nIconWidth > extra_clip_width || nIconHeight > extra_clip_height )
  472. {
  473. scale = GetScale( nIconWidth, nIconHeight, extra_clip_width, extra_clip_height );
  474. nIconWidth *= scale;
  475. nIconHeight *= scale;
  476. }
  477. if ( nIconWidth < extra_clip_width - XRES(2) ) // 2 is our buffer for when we need to re-calculate the ypos
  478. {
  479. xpos = extra_clip_xpos + extra_clip_width / 2.0 - nIconWidth / 2.0;
  480. }
  481. if ( nIconHeight < extra_clip_height - YRES(2) ) // 2 is our buffer for when we need to re-calculate the ypos
  482. {
  483. ypos = extra_clip_ypos + extra_clip_height / 2.0 - nIconHeight / 2.0;
  484. }
  485. pExtraClip->DrawSelf( xpos, ypos, pExtraClip->Width() * scale, pExtraClip->Height() * scale, m_clrIcon );
  486. DrawAmmoCount( clips );
  487. }
  488. }
  489. //-----------------------------------------------------------------------------
  490. // Purpose:
  491. //-----------------------------------------------------------------------------
  492. void CDoDHudAmmo::Paint( void )
  493. {
  494. C_DODPlayer *pPlayer = C_DODPlayer::GetLocalDODPlayer();
  495. if( !pPlayer )
  496. return;
  497. CWeaponDODBase *pWpn = pPlayer->GetActiveDODWeapon();
  498. if( !pWpn )
  499. return;
  500. switch( pWpn->GetDODWpnData().m_WeaponType )
  501. {
  502. case WPN_TYPE_GRENADE:
  503. PaintGrenadeAmmo( pWpn );
  504. break;
  505. case WPN_TYPE_RIFLEGRENADE:
  506. PaintRifleGrenadeAmmo( pWpn );
  507. break;
  508. case WPN_TYPE_BAZOOKA:
  509. PaintBazookaAmmo( pWpn );
  510. break;
  511. case WPN_TYPE_MG:
  512. PaintMGAmmo( pWpn );
  513. break;
  514. case WPN_TYPE_CAMERA:
  515. break;
  516. default:
  517. PaintGunAmmo( pWpn );
  518. break;
  519. }
  520. }
  521. //-----------------------------------------------------------------------------
  522. // Purpose:
  523. //-----------------------------------------------------------------------------
  524. void CDoDHudAmmo::DrawText( char *text, int x, int y, Color clrText )
  525. {
  526. vgui::surface()->DrawSetTextColor( clrText );
  527. vgui::surface()->DrawSetTextFont( m_hNumberFont );
  528. vgui::surface()->DrawSetTextPos( x, y );
  529. for (char *pch = text; *pch != 0; pch++)
  530. {
  531. vgui::surface()->DrawUnicodeChar(*pch);
  532. }
  533. }
  534. //-----------------------------------------------------------------------------
  535. // Purpose:
  536. //-----------------------------------------------------------------------------
  537. void CDoDHudAmmo::DrawNumbers( int num, int x, int y )
  538. {
  539. if ( !m_pMGNumbers[0] )
  540. {
  541. int i;
  542. for ( i = 0 ; i < 10 ; i++ )
  543. {
  544. char buf[8];
  545. Q_snprintf( buf, sizeof(buf), "mg_%d", i );
  546. m_pMGNumbers[i] = gHUD.GetIcon( buf );
  547. }
  548. }
  549. Assert( num < 1000 );
  550. int xpos = x;
  551. int ypos = y;
  552. int num_working = num;
  553. int iconWidth = m_pMGNumbers[0]->Width();
  554. int hundreds = num_working / 100;
  555. num_working -= hundreds * 100;
  556. m_pMGNumbers[hundreds]->DrawSelf( xpos, ypos, m_clrIcon );
  557. xpos += iconWidth;
  558. int tens = num_working / 10;
  559. num_working -= tens * 10;
  560. m_pMGNumbers[tens]->DrawSelf( xpos, ypos, m_clrIcon );
  561. xpos += iconWidth;
  562. m_pMGNumbers[num_working]->DrawSelf( xpos, ypos, m_clrIcon );
  563. xpos += iconWidth;
  564. }