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.

1296 lines
37 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. // Author: Matthew D. Campbell ([email protected]), 2003
  7. #include "cbase.h"
  8. #include <vgui/KeyCode.h>
  9. #include "career_box.h"
  10. #include "career_button.h"
  11. #include "buypreset_listbox.h"
  12. #include <vgui_controls/TextImage.h>
  13. #include <vgui_controls/CheckButton.h>
  14. #include <vgui_controls/ComboBox.h>
  15. #include "cs_ammodef.h"
  16. #include "weapon_csbase.h"
  17. #include "backgroundpanel.h"
  18. #include "cs_gamerules.h"
  19. #include <vgui/IInput.h>
  20. #include "bot/shared_util.h"
  21. #include <vgui_controls/BitmapImagePanel.h>
  22. #include <vgui/ISurface.h>
  23. #include <vgui/ILocalize.h>
  24. // memdbgon must be the last include file in a .cpp file!!!
  25. #include <tier0/memdbgon.h>
  26. #ifndef max
  27. #define max(a,b) (((a) > (b)) ? (a) : (b))
  28. #endif
  29. using namespace vgui;
  30. //--------------------------------------------------------------------------------------------------------------
  31. class ConVarToggleCheckButton : public vgui::CheckButton
  32. {
  33. DECLARE_CLASS_SIMPLE( ConVarToggleCheckButton, vgui::CheckButton );
  34. public:
  35. ConVarToggleCheckButton( vgui::Panel *parent, const char *panelName, const char *text );
  36. ~ConVarToggleCheckButton();
  37. virtual void SetSelected( bool state );
  38. virtual void Paint();
  39. void Reset();
  40. void ApplyChanges();
  41. bool HasBeenModified();
  42. void SetConVar( const char *name );
  43. virtual void ApplySettings( KeyValues *inResourceData )
  44. {
  45. BaseClass::ApplySettings( inResourceData );
  46. const char *name = inResourceData->GetString( "convar", NULL );
  47. if ( name )
  48. {
  49. SetConVar( name );
  50. }
  51. }
  52. private:
  53. MESSAGE_FUNC( OnButtonChecked, "CheckButtonChecked" );
  54. char *m_pszCvarName;
  55. bool m_bStartValue;
  56. };
  57. //--------------------------------------------------------------------------------------------------------------
  58. ConVarToggleCheckButton::ConVarToggleCheckButton( Panel *parent, const char *panelName, const char *text )
  59. : CheckButton( parent, panelName, text )
  60. {
  61. m_pszCvarName = NULL;
  62. AddActionSignalTarget( this );
  63. }
  64. //--------------------------------------------------------------------------------------------------------------
  65. ConVarToggleCheckButton::~ConVarToggleCheckButton()
  66. {
  67. if ( m_pszCvarName )
  68. delete[] m_pszCvarName;
  69. }
  70. //--------------------------------------------------------------------------------------------------------------
  71. void ConVarToggleCheckButton::SetConVar( const char *name )
  72. {
  73. if ( m_pszCvarName )
  74. delete[] m_pszCvarName;
  75. m_pszCvarName = CloneString( name );
  76. if (m_pszCvarName && *m_pszCvarName)
  77. {
  78. Reset();
  79. }
  80. }
  81. //--------------------------------------------------------------------------------------------------------------
  82. void ConVarToggleCheckButton::Paint()
  83. {
  84. if ( !m_pszCvarName || !m_pszCvarName[ 0 ] )
  85. {
  86. BaseClass::Paint();
  87. return;
  88. }
  89. // Look up current value
  90. ConVar const *var = cvar->FindVar( m_pszCvarName );
  91. if ( !var )
  92. return;
  93. bool value = var->GetBool();
  94. if (value != m_bStartValue)
  95. {
  96. SetSelected( value );
  97. m_bStartValue = value;
  98. }
  99. BaseClass::Paint();
  100. }
  101. //--------------------------------------------------------------------------------------------------------------
  102. void ConVarToggleCheckButton::ApplyChanges()
  103. {
  104. m_bStartValue = IsSelected();
  105. ConVar *var = (ConVar *)cvar->FindVar( m_pszCvarName );
  106. if ( !var )
  107. return;
  108. var->SetValue(m_bStartValue);
  109. }
  110. //--------------------------------------------------------------------------------------------------------------
  111. void ConVarToggleCheckButton::Reset()
  112. {
  113. ConVar const *var = cvar->FindVar( m_pszCvarName );
  114. if ( !var )
  115. return;
  116. m_bStartValue = var->GetBool();
  117. SetSelected(m_bStartValue);
  118. }
  119. //--------------------------------------------------------------------------------------------------------------
  120. bool ConVarToggleCheckButton::HasBeenModified()
  121. {
  122. return IsSelected() != m_bStartValue;
  123. }
  124. //--------------------------------------------------------------------------------------------------------------
  125. void ConVarToggleCheckButton::SetSelected( bool state )
  126. {
  127. BaseClass::SetSelected( state );
  128. if ( !m_pszCvarName || !m_pszCvarName[ 0 ] )
  129. return;
  130. }
  131. //--------------------------------------------------------------------------------------------------------------
  132. void ConVarToggleCheckButton::OnButtonChecked()
  133. {
  134. if (HasBeenModified())
  135. {
  136. PostActionSignal(new KeyValues("ControlModified"));
  137. }
  138. }
  139. //--------------------------------------------------------------------------------------------------------------
  140. //--------------------------------------------------------------------------------------------------------------
  141. CCareerBaseBox::CCareerBaseBox(Panel *parent, const char *panelName, bool loadResources, bool useCareerButtons) : Frame(parent, panelName, false)
  142. {
  143. // @TODO: SetScheme("CareerBoxScheme");
  144. SetScheme("ClientScheme");
  145. SetProportional( true );
  146. SetMoveable(false);
  147. SetSizeable(false);
  148. m_bgColor = Color( 0, 0, 0, 0 );
  149. m_borderColor = Color( 0, 0, 0, 0 );
  150. m_pTextLabel = new Label( this, "TextLabel", "" );
  151. if ( useCareerButtons )
  152. {
  153. m_pOkButton = new CCareerButton( this, "OkButton", "", "", false );
  154. m_pCancelButton = new CCareerButton( this, "CancelButton", "", "", false );
  155. }
  156. else
  157. {
  158. m_pOkButton = new Button( this, "OkButton", "" );
  159. m_pCancelButton = new Button( this, "CancelButton", "" );
  160. }
  161. m_pOkButton->SetVisible(false);
  162. if ( useCareerButtons )
  163. {
  164. m_buttons.PutElement( m_pOkButton );
  165. m_buttons.PutElement( m_pCancelButton );
  166. }
  167. m_cancelFocus = false;
  168. if (loadResources)
  169. {
  170. const int BufLen = strlen(panelName) + 32;
  171. char *buf = new char[BufLen];
  172. Q_snprintf( buf, BufLen, "Resource/Career/%s.res", panelName );
  173. LoadControlSettings( buf );
  174. delete[] buf;
  175. }
  176. }
  177. //--------------------------------------------------------------------------------------------------------------
  178. vgui::Panel * CCareerBaseBox::CreateControlByName(const char *controlName)
  179. {
  180. if ( Q_stricmp( controlName, "ConVarCheckButton" ) == 0 )
  181. {
  182. ConVarToggleCheckButton *button = new ConVarToggleCheckButton( NULL, controlName, "" );
  183. m_conVarCheckButtons.PutElement( button );
  184. return button;
  185. }
  186. return BaseClass::CreateControlByName( controlName );
  187. }
  188. //--------------------------------------------------------------------------------------------------------------
  189. void CCareerBaseBox::SetCancelButtonAsDefault()
  190. {
  191. m_cancelFocus = true;
  192. }
  193. //--------------------------------------------------------------------------------------------------------------
  194. void CCareerBaseBox::SetLabelText( const wchar_t *text )
  195. {
  196. m_pTextLabel->SetText(text);
  197. }
  198. //--------------------------------------------------------------------------------------------------------------
  199. void CCareerBaseBox::SetLabelText( const char *text )
  200. {
  201. m_pTextLabel->SetText(text);
  202. }
  203. //--------------------------------------------------------------------------------------------------------------
  204. void CCareerBaseBox::ApplySchemeSettings( vgui::IScheme *pScheme )
  205. {
  206. BaseClass::ApplySchemeSettings( pScheme );
  207. for (int i=0; i<m_buttons.GetCount(); ++i)
  208. {
  209. m_buttons[i]->SetArmedSound("UI/buttonrollover.wav");
  210. m_buttons[i]->SetDepressedSound("UI/buttonclick.wav");
  211. m_buttons[i]->SetReleasedSound("UI/buttonclickrelease.wav");
  212. }
  213. m_bgColor = GetSchemeColor("Popup.BgColor", Color( 64, 64, 64, 255 ), pScheme);
  214. m_borderColor = GetSchemeColor("FgColor", Color( 64, 64, 64, 255 ), pScheme);
  215. SetBorder( pScheme->GetBorder( "BaseBorder" ) );
  216. }
  217. //--------------------------------------------------------------------------------------------------------------
  218. void CCareerBaseBox::PerformLayout( )
  219. {
  220. BaseClass::PerformLayout();
  221. int x, y, w, h;
  222. GetBounds(x, y, w, h);
  223. int screenWide, screenTall;
  224. GetHudSize( screenWide, screenTall );
  225. if ( x + w/2 != screenWide/2 )
  226. {
  227. SetPos( screenWide/2 - w/2, screenTall/2 - h/2 );
  228. GetBounds(x, y, w, h);
  229. }
  230. }
  231. //--------------------------------------------------------------------------------------------------------------
  232. void CCareerBaseBox::PaintBackground( )
  233. {
  234. int wide, tall;
  235. GetSize( wide, tall );
  236. DrawRoundedBackground( m_bgColor, wide, tall );
  237. }
  238. //--------------------------------------------------------------------------------------------------------------
  239. void CCareerBaseBox::PaintBorder( )
  240. {
  241. int wide, tall;
  242. GetSize( wide, tall );
  243. DrawRoundedBorder( m_borderColor, wide, tall );
  244. }
  245. //--------------------------------------------------------------------------------------------------------------
  246. void CCareerBaseBox::ShowWindow()
  247. {
  248. SetVisible( true );
  249. SetEnabled( true );
  250. MoveToFront();
  251. if ( m_pCancelButton->IsVisible() && m_cancelFocus )
  252. {
  253. m_pCancelButton->RequestFocus();
  254. }
  255. else if ( m_pOkButton->IsVisible() )
  256. {
  257. m_pOkButton->RequestFocus();
  258. }
  259. else // handle message boxes with no button
  260. {
  261. RequestFocus();
  262. }
  263. InvalidateLayout();
  264. }
  265. //--------------------------------------------------------------------------------------------------------------
  266. void CCareerBaseBox::DoModal()
  267. {
  268. ShowWindow();
  269. input()->SetAppModalSurface(GetVPanel());
  270. }
  271. //--------------------------------------------------------------------------------------------------------------
  272. void CCareerBaseBox::OnKeyCodeTyped(KeyCode code)
  273. {
  274. if (code == KEY_ESCAPE)
  275. {
  276. OnCommand("Cancel");
  277. }
  278. else if (code == KEY_ENTER)
  279. {
  280. BaseClass::OnKeyCodeTyped( KEY_SPACE );
  281. }
  282. else
  283. {
  284. BaseClass::OnKeyCodeTyped(code);
  285. }
  286. }
  287. //--------------------------------------------------------------------------------------------------------------
  288. void CCareerBaseBox::OnCommand(const char *command)
  289. {
  290. KeyValues *okSettings = new KeyValues( "GetCommand" );
  291. if ( m_pOkButton->RequestInfo( okSettings ) )
  292. {
  293. const char *okCommand = okSettings->GetString( "command", "Ok" );
  294. if ( stricmp(command, okCommand) == 0 )
  295. {
  296. for (int i=0; i<m_conVarCheckButtons.GetCount(); ++i)
  297. {
  298. m_conVarCheckButtons[i]->ApplyChanges();
  299. }
  300. }
  301. }
  302. if (stricmp(command, "close"))
  303. {
  304. PostActionSignal( new KeyValues("Command", "command", command) );
  305. }
  306. BaseClass::OnCommand(command);
  307. Close();
  308. }
  309. //--------------------------------------------------------------------------------------------------------------
  310. void CCareerBaseBox::AddButton( vgui::Button *pButton )
  311. {
  312. m_buttons.PutElement( pButton );
  313. }
  314. //--------------------------------------------------------------------------------------------------------------
  315. CCareerQueryBox::CCareerQueryBox(vgui::Panel *parent, const char *panelName, const char *resourceName) : CCareerBaseBox(parent, panelName, (resourceName == NULL))
  316. {
  317. if ( resourceName )
  318. {
  319. LoadControlSettings( resourceName );
  320. }
  321. }
  322. //--------------------------------------------------------------------------------------------------------------
  323. CCareerQueryBox::CCareerQueryBox(const char *title, const char *labelText, const char *panelName, vgui::Panel *parent) : CCareerBaseBox(parent, panelName)
  324. {
  325. }
  326. //--------------------------------------------------------------------------------------------------------------
  327. CCareerQueryBox::CCareerQueryBox(const wchar_t *title, const wchar_t *labelText, const char *panelName, vgui::Panel *parent) : CCareerBaseBox(parent, panelName)
  328. {
  329. }
  330. //--------------------------------------------------------------------------------------------------------------
  331. CCareerQueryBox::~CCareerQueryBox()
  332. {
  333. }
  334. // sorted order weapon list -----------------------------------------------------------------------
  335. const int NUM_SECONDARY_WEAPONS = 7;
  336. static CSWeaponID s_secondaryWeapons[NUM_SECONDARY_WEAPONS] =
  337. {
  338. WEAPON_NONE,
  339. WEAPON_USP,
  340. WEAPON_GLOCK,
  341. WEAPON_DEAGLE,
  342. WEAPON_ELITE,
  343. WEAPON_P228,
  344. WEAPON_FIVESEVEN,
  345. };
  346. const int NUM_PRIMARY_WEAPONS = 23;
  347. static CSWeaponID s_primaryWeapons[NUM_PRIMARY_WEAPONS] =
  348. {
  349. WEAPON_NONE,
  350. // Assault Rifles
  351. CSWeaponID(-WEAPONTYPE_RIFLE),
  352. WEAPON_SG552,
  353. WEAPON_AUG,
  354. WEAPON_AK47,
  355. WEAPON_M4A1,
  356. WEAPON_GALIL,
  357. WEAPON_FAMAS,
  358. // Snipers
  359. CSWeaponID(-WEAPONTYPE_SNIPER_RIFLE),
  360. WEAPON_AWP,
  361. WEAPON_SG550,
  362. WEAPON_G3SG1,
  363. WEAPON_SCOUT,
  364. // SMG
  365. CSWeaponID(-WEAPONTYPE_SUBMACHINEGUN),
  366. WEAPON_P90,
  367. WEAPON_UMP45,
  368. WEAPON_MP5NAVY,
  369. WEAPON_MAC10,
  370. WEAPON_TMP,
  371. // Heavy
  372. CSWeaponID(-WEAPONTYPE_SHOTGUN),
  373. WEAPON_M249,
  374. WEAPON_XM1014,
  375. WEAPON_M3,
  376. // WEAPON_SHIELDGUN,
  377. };
  378. //--------------------------------------------------------------------------------------------------------------
  379. //--------------------------------------------------------------------------------------------------------------
  380. class CWeaponButton : public vgui::Button
  381. {
  382. typedef vgui::Button BaseClass;
  383. public:
  384. CWeaponButton( BuyPresetListBox *pParent, CSWeaponID weaponID, bool isPrimary ) : BaseClass( pParent->GetParent(), SharedVarArgs( "WeaponButton%d", weaponID ), "" )
  385. {
  386. m_isPrimary = isPrimary;
  387. m_pImage = NULL;
  388. m_pTitleImage = new TextImage( WeaponIDToDisplayName( weaponID ) );
  389. m_pCostImage = new TextImage( L"" );
  390. m_pListBox = pParent;
  391. BuyPresetWeapon weapon( weaponID );
  392. SetWeapon( weapon );
  393. }
  394. virtual ~CWeaponButton() { delete m_pTitleImage; delete m_pCostImage; }
  395. virtual void ApplySchemeSettings( IScheme *pScheme );
  396. virtual Color GetBgColor() { return (IsCurrent()) ? m_selectedBgColor : Button::GetBgColor(); }
  397. virtual Color GetFgColor() { return (IsCurrent()) ? m_selectedFgColor : Button::GetFgColor(); }
  398. void SetCurrent() { s_current = this; }
  399. bool IsCurrent() const { return s_current == this; }
  400. void SetWeapon( const BuyPresetWeapon& weapon );
  401. const BuyPresetWeapon& GetWeapon() { return m_weapon; }
  402. virtual void Paint();
  403. virtual void PerformLayout();
  404. virtual void PaintBorder() {}
  405. virtual void OnMousePressed( MouseCode code )
  406. {
  407. if ( code == MOUSE_LEFT )
  408. {
  409. SetCurrent();
  410. m_pListBox->GetParent()->OnCommand( "select_weapon" );
  411. }
  412. Button::OnMousePressed( code );
  413. }
  414. virtual void OnMouseDoublePressed( MouseCode code )
  415. {
  416. if ( code == MOUSE_LEFT )
  417. {
  418. SetCurrent();
  419. m_pListBox->GetParent()->OnCommand( "select_weapon" );
  420. m_pListBox->GetParent()->OnCommand( "popup_ok" );
  421. }
  422. Button::OnMouseDoublePressed( code );
  423. }
  424. protected:
  425. static CWeaponButton * s_current;
  426. BuyPresetListBox * m_pListBox;
  427. BuyPresetWeapon m_weapon;
  428. IImage *m_pImage;
  429. TextImage *m_pTitleImage;
  430. TextImage *m_pCostImage;
  431. int m_imageWide;
  432. int m_imageTall;
  433. int m_imageX;
  434. int m_imageY;
  435. Color m_selectedBgColor;
  436. Color m_selectedFgColor;
  437. bool m_isPrimary;
  438. };
  439. //--------------------------------------------------------------------------------------------------------------
  440. CWeaponButton * CWeaponButton::s_current = NULL;
  441. //--------------------------------------------------------------------------------------------------------------
  442. void CWeaponButton::ApplySchemeSettings( IScheme *pScheme )
  443. {
  444. CWeaponButton * current = s_current; // save off current so Button::ApplySchemeSettings() can get the right colors
  445. s_current = NULL;
  446. Button::ApplySchemeSettings( pScheme );
  447. m_selectedBgColor = GetSchemeColor( "Button.ArmedBgColor", Button::GetBgColor(), pScheme );
  448. m_selectedFgColor = GetSchemeColor( "Button.ArmedTextColor", Button::GetFgColor(), pScheme );
  449. s_current = current;
  450. m_pTitleImage->SetColor( pScheme->GetColor( "Button.TextColor", Color() ) );
  451. m_pTitleImage->SetFont( pScheme->GetFont( "Default", IsProportional() ) );
  452. m_pTitleImage->SetWrap( true );
  453. m_pCostImage->SetColor( pScheme->GetColor( "Button.TextColor", Color() ) );
  454. m_pCostImage->SetFont( pScheme->GetFont( "Default", IsProportional() ) );
  455. m_pCostImage->SetWrap( true );
  456. SetWeapon( m_weapon );
  457. SetBorder( NULL );
  458. }
  459. //--------------------------------------------------------------------------------------------------------------
  460. void CWeaponButton::SetWeapon( const BuyPresetWeapon& weapon )
  461. {
  462. m_weapon = weapon;
  463. if ( m_weapon.GetName() )
  464. {
  465. // weapon string
  466. const wchar_t * name = m_weapon.GetName();
  467. m_pTitleImage->SetText( name );
  468. // cost string
  469. CCSWeaponInfo *info = GetWeaponInfo( m_weapon.GetWeaponID() );
  470. if ( info )
  471. {
  472. const int BufLen = 256;
  473. wchar_t wbuf[BufLen];
  474. g_pVGuiLocalize->ConstructString( wbuf, sizeof( wbuf ),
  475. g_pVGuiLocalize->Find( "#Cstrike_BuyPresetPlainCost" ),
  476. 1, NumAsWString( info->GetWeaponPrice() ) );
  477. m_pCostImage->SetText( wbuf );
  478. }
  479. else
  480. {
  481. m_pCostImage->SetText( L"" );
  482. }
  483. }
  484. else
  485. {
  486. m_pTitleImage->SetText( L"" );
  487. m_pCostImage->SetText( L"" );
  488. }
  489. m_pTitleImage->ResizeImageToContent();
  490. m_pCostImage->ResizeImageToContent();
  491. InvalidateLayout( true, false );
  492. m_pImage = scheme()->GetImage( ImageFnameFromWeaponID( m_weapon.GetWeaponID(), m_isPrimary ), true );
  493. }
  494. //--------------------------------------------------------------------------------------------------------------
  495. void CWeaponButton::PerformLayout()
  496. {
  497. BaseClass::PerformLayout();
  498. // Calculate some sizes
  499. int oldWide, oldTall;
  500. GetSize( oldWide, oldTall );
  501. const float IMAGE_PERCENT = 0.42f;
  502. const float TITLE_PERCENT = 0.45f;
  503. const float COST_PERCENT = 1.0f - TITLE_PERCENT - IMAGE_PERCENT;
  504. int maxTitleWide = (int) oldWide * TITLE_PERCENT;
  505. int maxImageWide = (int) oldWide * IMAGE_PERCENT;
  506. int maxCostWide = (int) oldWide * COST_PERCENT;
  507. int textTall = surface()->GetFontTall( m_pTitleImage->GetFont() ) * 2;
  508. if ( oldTall != textTall )
  509. {
  510. oldTall = textTall;
  511. SetSize( oldWide, oldTall );
  512. m_pListBox->InvalidateLayout();
  513. }
  514. // Position the weapon name
  515. {
  516. m_pTitleImage->SetSize( maxTitleWide, oldTall );
  517. m_pTitleImage->RecalculateNewLinePositions();
  518. m_pTitleImage->ResizeImageToContent();
  519. int textContentWide, textContentTall;
  520. m_pTitleImage->GetSize( textContentWide, textContentTall );
  521. if ( textContentTall < textTall )
  522. {
  523. m_pTitleImage->SetSize( maxTitleWide, textContentTall );
  524. m_pTitleImage->SetPos( maxImageWide, (textTall - textContentTall) / 2 );
  525. }
  526. else
  527. {
  528. m_pTitleImage->SetPos( maxImageWide, 0 );
  529. }
  530. }
  531. // Position the weapon cost
  532. {
  533. m_pCostImage->SetSize( maxCostWide, oldTall );
  534. m_pCostImage->RecalculateNewLinePositions();
  535. m_pCostImage->ResizeImageToContent();
  536. int textContentWide, textContentTall;
  537. m_pCostImage->GetSize( textContentWide, textContentTall );
  538. if ( textContentTall < textTall )
  539. {
  540. m_pCostImage->SetSize( maxCostWide, textContentTall );
  541. m_pCostImage->SetPos( oldWide - maxCostWide, (textTall - textContentTall) / 2 );
  542. }
  543. else
  544. {
  545. m_pCostImage->SetPos( oldWide - maxCostWide, 0 );
  546. }
  547. }
  548. // Position the weapon image
  549. m_pImage = scheme()->GetImage( ImageFnameFromWeaponID( m_weapon.GetWeaponID(), m_isPrimary ), true );
  550. int maxImageTall = textTall;
  551. m_pImage->GetContentSize( m_imageWide, m_imageTall );
  552. if ( m_imageTall > maxImageTall )
  553. {
  554. m_imageWide = (int) m_imageWide * 1.0f * maxImageTall / m_imageTall;
  555. m_imageTall = maxImageTall;
  556. }
  557. if ( m_imageWide > maxImageWide )
  558. {
  559. m_imageTall = (int) m_imageTall * 1.0f * maxImageWide / m_imageWide;
  560. m_imageWide = maxImageWide;
  561. }
  562. m_imageY = (textTall - m_imageTall) / 2;
  563. m_imageX = (((int) oldWide * IMAGE_PERCENT) - m_imageWide) / 2;
  564. }
  565. //--------------------------------------------------------------------------------------------------------------
  566. void CWeaponButton::Paint()
  567. {
  568. if ( m_pImage )
  569. {
  570. m_pImage->SetSize( m_imageWide, m_imageTall );
  571. m_pImage->SetPos( m_imageX, m_imageY );
  572. m_pImage->Paint();
  573. m_pImage->SetSize( 0, 0 );
  574. }
  575. m_pTitleImage->Paint();
  576. m_pCostImage->Paint();
  577. BaseClass::Paint();
  578. }
  579. //--------------------------------------------------------------------------------------------------------------
  580. //--------------------------------------------------------------------------------------------------------------
  581. class WeaponComboBox : public vgui::ComboBox
  582. {
  583. public:
  584. WeaponComboBox( CWeaponSelectBox *parent, const char *name, int numEntries, bool editable )
  585. : ComboBox( parent, name, numEntries, editable )
  586. {
  587. m_pBox = parent;
  588. }
  589. virtual void OnSetText( const wchar_t *newText )
  590. {
  591. ComboBox::OnSetText( newText );
  592. if ( m_pBox )
  593. m_pBox->UpdateClips();
  594. }
  595. private:
  596. CWeaponSelectBox *m_pBox;
  597. };
  598. //--------------------------------------------------------------------------------------------------------------
  599. //--------------------------------------------------------------------------------------------------------------
  600. CWeaponSelectBox::CWeaponSelectBox(vgui::Panel *parent, WeaponSet *pWeaponSet, bool isSecondary ) : CCareerBaseBox(parent, "BuyBoxSelectWeapon", false)
  601. {
  602. m_pWeaponSet = pWeaponSet;
  603. m_isSecondary = isSecondary;
  604. m_numWeapons = NUM_PRIMARY_WEAPONS;
  605. m_weaponIDs = s_primaryWeapons;
  606. BuyPresetWeapon *weapon;
  607. if ( !m_isSecondary )
  608. {
  609. weapon = &m_pWeaponSet->m_primaryWeapon;
  610. if ( !IsPrimaryWeapon( weapon->GetWeaponID() ) && weapon->GetWeaponID() != WEAPON_NONE )
  611. {
  612. BuyPresetWeapon tmp( WEAPON_NONE );
  613. m_pWeaponSet->m_primaryWeapon = tmp;
  614. }
  615. }
  616. else
  617. {
  618. m_numWeapons = NUM_SECONDARY_WEAPONS;
  619. m_weaponIDs = s_secondaryWeapons;
  620. weapon = &m_pWeaponSet->m_secondaryWeapon;
  621. if ( !IsSecondaryWeapon( weapon->GetWeaponID() ) && weapon->GetWeaponID() != WEAPON_NONE )
  622. {
  623. BuyPresetWeapon tmp( WEAPON_NONE );
  624. *weapon = tmp;
  625. }
  626. }
  627. int maxClips = 0;
  628. const CCSWeaponInfo *info = GetWeaponInfo( weapon->GetWeaponID() );
  629. if ( info )
  630. {
  631. int maxRounds = GetCSAmmoDef()->MaxCarry( info->iAmmoType );
  632. int buyClipSize = GetCSAmmoDef()->GetBuySize( info->iAmmoType );
  633. maxClips = (buyClipSize > 0) ? ceil(maxRounds/(float)buyClipSize) : 0;
  634. }
  635. else
  636. {
  637. maxClips = NUM_CLIPS_FOR_CURRENT; // so we can buy ammo for our current gun
  638. }
  639. m_pClips = new WeaponComboBox( this, "Clips", 2*maxClips+1, false );
  640. m_pClips->SetOpenDirection( Menu::UP );
  641. m_pListBox = new BuyPresetListBox( this, "WeaponListBox" );
  642. m_pBullets = new Label( this, "bullets", "" );
  643. int selectedWeaponIndex = -1;
  644. int i;
  645. for ( i=0; i<m_numWeapons; ++i )
  646. {
  647. if ( m_weaponIDs[i] < 0 )
  648. {
  649. const char *text = "";
  650. switch ( (int)m_weaponIDs[i] )
  651. {
  652. case -WEAPONTYPE_RIFLE:
  653. text = "#Cstrike_BuyPresetCategoryRifle";
  654. break;
  655. case -WEAPONTYPE_SNIPER_RIFLE:
  656. text = "#Cstrike_BuyPresetCategorySniper";
  657. break;
  658. case -WEAPONTYPE_SUBMACHINEGUN:
  659. text = "#Cstrike_BuyPresetCategorySMG";
  660. break;
  661. case -WEAPONTYPE_SHOTGUN:
  662. text = "#Cstrike_BuyPresetCategoryHeavy";
  663. break;
  664. }
  665. Label *pLabel = new Label( m_pListBox, SharedVarArgs("weaponlabel%d", i), text );
  666. m_pListBox->AddItem( pLabel, NULL );
  667. }
  668. else
  669. {
  670. CWeaponButton *pWeaponButton = new CWeaponButton( m_pListBox, m_weaponIDs[i], !m_isSecondary );
  671. m_pListBox->AddItem( pWeaponButton, NULL );
  672. if ( m_weaponIDs[i] == weapon->GetWeaponID() )
  673. {
  674. pWeaponButton->SetCurrent();
  675. selectedWeaponIndex = i;
  676. }
  677. }
  678. }
  679. m_pListBox->MakeItemVisible( selectedWeaponIndex );
  680. LoadControlSettings( "resource/UI/BuyPreset/BoxSelectWeapon.res" );
  681. PopulateControls();
  682. }
  683. //--------------------------------------------------------------------------------------------------------------
  684. CWeaponSelectBox::~CWeaponSelectBox()
  685. {
  686. }
  687. //--------------------------------------------------------------------------------------------------------------
  688. void CWeaponSelectBox::ActivateBuildMode()
  689. {
  690. SetClipsVisible( true );
  691. m_pListBox->DeleteAllItems();
  692. BaseClass::ActivateBuildMode();
  693. }
  694. //--------------------------------------------------------------------------------------------------------------
  695. void CWeaponSelectBox::SetClipsVisible( bool visible )
  696. {
  697. SetLabelVisible( visible );
  698. m_pClips->SetVisible( visible );
  699. }
  700. //--------------------------------------------------------------------------------------------------------------
  701. void CWeaponSelectBox::PopulateControls()
  702. {
  703. BuyPresetWeapon *weapon;
  704. if (!m_isSecondary)
  705. {
  706. weapon = &m_pWeaponSet->m_primaryWeapon;
  707. }
  708. else
  709. {
  710. weapon = &m_pWeaponSet->m_secondaryWeapon;
  711. }
  712. int i;
  713. int maxClips = 0;
  714. const CCSWeaponInfo *info = GetWeaponInfo( weapon->GetWeaponID() );
  715. if ( info )
  716. {
  717. int maxRounds = GetCSAmmoDef()->MaxCarry( info->iAmmoType );
  718. int buyClipSize = GetCSAmmoDef()->GetBuySize( info->iAmmoType );
  719. maxClips = (buyClipSize > 0) ? ceil(maxRounds/(float)buyClipSize) : 0;
  720. }
  721. else
  722. {
  723. maxClips = NUM_CLIPS_FOR_CURRENT;
  724. }
  725. m_pClips->SetNumberOfEditLines( 2*maxClips+1 );
  726. SetClipsVisible( maxClips != 0 );
  727. m_pClips->DeleteAllItems();
  728. // populate clips combo box
  729. m_pClips->AddItem( "#Cstrike_BuyPresetEditWeaponFullClips", NULL );
  730. const int BufLen = 64;
  731. wchar_t buf[BufLen];
  732. for ( i=maxClips-1; i>=0; --i )
  733. {
  734. const char* clipsOrMore = "#Cstrike_BuyPresetEditClipsOrMore";
  735. const char* clips = "#Cstrike_BuyPresetEditClips";
  736. if ( i == 1 )
  737. {
  738. clipsOrMore = "#Cstrike_BuyPresetEditClipOrMore";
  739. clips = "#Cstrike_BuyPresetEditClip";
  740. }
  741. g_pVGuiLocalize->ConstructString( buf, sizeof(buf),
  742. g_pVGuiLocalize->Find( clipsOrMore ),
  743. 1, NumAsWString( i ));
  744. m_pClips->AddItem( buf, NULL );
  745. g_pVGuiLocalize->ConstructString( buf, sizeof(buf),
  746. g_pVGuiLocalize->Find( clips ),
  747. 1, NumAsWString( i ));
  748. m_pClips->AddItem( buf, NULL );
  749. }
  750. // now select the proper entry
  751. int clipIndexToSelect = weapon->GetFillAmmo();
  752. clipIndexToSelect += 2 * weapon->GetAmmoAmount();
  753. clipIndexToSelect = maxClips*2 - clipIndexToSelect;
  754. m_pClips->ActivateItemByRow( clipIndexToSelect );
  755. if ( m_isSecondary )
  756. {
  757. Panel *pPanel = FindChildByName( "TitleLabel" );
  758. if ( pPanel )
  759. {
  760. const wchar_t *title = g_pVGuiLocalize->Find( "#Cstrike_BuyPresetWizardSecondary" );
  761. if ( title )
  762. PostMessage(pPanel, new KeyValues("SetText", "text", title));
  763. }
  764. }
  765. UpdateClips();
  766. }
  767. //--------------------------------------------------------------------------------------------------------------
  768. void CWeaponSelectBox::UpdateClips()
  769. {
  770. if ( !m_pClips )
  771. return;
  772. int numEntries = m_pClips->GetItemCount();
  773. int activeID = m_pClips->GetActiveItem();
  774. int combined = numEntries - activeID + 1;
  775. int numClips = combined/2 - 1;
  776. //bool isFill = (combined%2) != 0;
  777. BuyPresetWeapon *weapon;
  778. if (!m_isSecondary)
  779. {
  780. weapon = &m_pWeaponSet->m_primaryWeapon;
  781. }
  782. else
  783. {
  784. weapon = &m_pWeaponSet->m_secondaryWeapon;
  785. }
  786. const CCSWeaponInfo *info = GetWeaponInfo( weapon->GetWeaponID() );
  787. if ( info )
  788. {
  789. int maxRounds = GetCSAmmoDef()->MaxCarry( info->iAmmoType );
  790. int buyClipSize = GetCSAmmoDef()->GetBuySize( info->iAmmoType );
  791. m_pBullets->SetVisible( true );
  792. const int BufLen = 64;
  793. wchar_t buf[BufLen];
  794. g_pVGuiLocalize->ConstructString( buf, sizeof(buf),
  795. g_pVGuiLocalize->Find( "#Cstrike_BuyPresetsBullets" ),
  796. 2, NumAsWString( MIN( maxRounds, numClips * buyClipSize ) ), NumAsWString( maxRounds ) );
  797. m_pBullets->SetText( buf );
  798. }
  799. else
  800. {
  801. m_pBullets->SetVisible( false );
  802. }
  803. }
  804. //--------------------------------------------------------------------------------------------------------------
  805. void CWeaponSelectBox::ApplySchemeSettings( IScheme *pScheme )
  806. {
  807. BaseClass::ApplySchemeSettings(pScheme);
  808. HFont font = pScheme->GetFont("Default", IsProportional());
  809. int tall = surface()->GetFontTall(font) + 2;
  810. if ( font != INVALID_FONT )
  811. {
  812. Menu *pMenu = m_pClips->GetMenu();
  813. pMenu->SetMenuItemHeight( tall );
  814. }
  815. for ( int i=0; i<m_pListBox->GetItemCount(); ++i )
  816. {
  817. if ( m_weaponIDs[i] >= 0 )
  818. {
  819. CWeaponButton *pButton = static_cast< CWeaponButton * >(m_pListBox->GetItemPanel(i));
  820. if ( pButton && pButton->IsCurrent() )
  821. {
  822. m_pListBox->MakeItemVisible( i );
  823. }
  824. }
  825. else
  826. {
  827. // it's a caption label
  828. Label *pLabel = static_cast< Label * >(m_pListBox->GetItemPanel(i));
  829. if ( pLabel )
  830. {
  831. pLabel->SetContentAlignment( Label::a_center );
  832. pLabel->SetBorder( pScheme->GetBorder( "ButtonBorder" ) );
  833. pLabel->SetBgColor( pScheme->GetColor( "Frame.BgColor", Color( 0, 0, 0, 255 ) ) );
  834. }
  835. }
  836. }
  837. }
  838. //--------------------------------------------------------------------------------------------------------------
  839. CSWeaponID CWeaponSelectBox::GetSelectedWeaponID()
  840. {
  841. int selectedIndex = -1;
  842. for ( int i=0; i<m_pListBox->GetItemCount(); ++i )
  843. {
  844. if ( m_weaponIDs[selectedIndex] >= 0 )
  845. {
  846. CWeaponButton *pButton = static_cast< CWeaponButton * >(m_pListBox->GetItemPanel(i));
  847. if ( pButton && pButton->IsCurrent() )
  848. {
  849. selectedIndex = i;
  850. }
  851. }
  852. }
  853. if ( selectedIndex >= 0 )
  854. {
  855. return m_weaponIDs[selectedIndex];
  856. }
  857. return WEAPON_NONE;
  858. }
  859. //--------------------------------------------------------------------------------------------------------------
  860. void CWeaponSelectBox::OnCommand(const char *command)
  861. {
  862. if (!stricmp(command, "select_weapon"))
  863. {
  864. CSWeaponID weaponID = GetSelectedWeaponID();
  865. BuyPresetWeapon weapon( weaponID );
  866. if ( m_isSecondary )
  867. {
  868. m_pWeaponSet->m_secondaryWeapon = weapon;
  869. }
  870. else
  871. {
  872. m_pWeaponSet->m_primaryWeapon = weapon;
  873. }
  874. PopulateControls();
  875. return;
  876. }
  877. if (!stricmp(command, "popup_ok"))
  878. {
  879. if ( !m_pClips )
  880. return;
  881. int numEntries = m_pClips->GetItemCount();
  882. int activeID = m_pClips->GetActiveItem();
  883. int combined = numEntries - activeID + 1;
  884. int numClips = combined/2 - 1;
  885. bool isFill = (combined%2) != 0;
  886. BuyPresetWeapon weapon( GetSelectedWeaponID() );
  887. weapon.SetAmmoType( AMMO_CLIPS );
  888. weapon.SetAmmoAmount( numClips );
  889. weapon.SetFillAmmo( isFill );
  890. if ( m_isSecondary )
  891. {
  892. m_pWeaponSet->m_secondaryWeapon = weapon;
  893. }
  894. else
  895. {
  896. m_pWeaponSet->m_primaryWeapon = weapon;
  897. }
  898. BaseClass::OnCommand( command );
  899. }
  900. else
  901. {
  902. BaseClass::OnCommand(command);
  903. }
  904. }
  905. //--------------------------------------------------------------------------------------------------------------
  906. //--------------------------------------------------------------------------------------------------------------
  907. class EquipmentComboBox : public ComboBox
  908. {
  909. public:
  910. EquipmentComboBox( CBaseSelectBox *parent, const char *name, int numEntries, bool editable )
  911. : ComboBox( parent, name, numEntries, editable )
  912. {
  913. m_pBox = parent;
  914. }
  915. virtual void OnSetText( const wchar_t *newText )
  916. {
  917. ComboBox::OnSetText( newText );
  918. m_pBox->OnControlChanged();
  919. }
  920. private:
  921. CBaseSelectBox *m_pBox;
  922. };
  923. //--------------------------------------------------------------------------------------------------------------
  924. //--------------------------------------------------------------------------------------------------------------
  925. CGrenadeSelectBox::CGrenadeSelectBox( vgui::Panel *parent, WeaponSet *pWeaponSet ) : BaseClass( parent, "BuyBoxSelectGrenades", false )
  926. {
  927. m_pWeaponSet = pWeaponSet;
  928. // Equipment controls
  929. m_pHEGrenade = new EquipmentComboBox( this, "hegrenade", 2, false );
  930. m_pSmokeGrenade = new EquipmentComboBox( this, "smokegrenade", 2, false );
  931. m_pFlashbangs = new EquipmentComboBox( this, "flashbangs", 3, false );
  932. // Equipment images
  933. m_pHEGrenadeImage = new EquipmentLabel( this, "HEGrenadeImage" );
  934. m_pSmokeGrenadeImage = new EquipmentLabel( this, "SmokeGrenadeImage" );
  935. m_pFlashbangImage = new EquipmentLabel( this, "FlashbangImage" );
  936. m_pHELabel = new Label( this, "HECost", "" );
  937. m_pSmokeLabel = new Label( this, "SmokeCost", "" );
  938. m_pFlashLabel = new Label( this, "FlashCost", "" );
  939. LoadControlSettings( "Resource/UI/BuyPreset/BoxSelectGrenades.res" );
  940. // Add entries to the combo boxes
  941. m_pHEGrenade->AddItem( "0", NULL );
  942. m_pHEGrenade->AddItem( "1", NULL );
  943. m_pSmokeGrenade->AddItem( "0", NULL );
  944. m_pSmokeGrenade->AddItem( "1", NULL );
  945. m_pFlashbangs->AddItem( "0", NULL );
  946. m_pFlashbangs->AddItem( "1", NULL );
  947. m_pFlashbangs->AddItem( "2", NULL );
  948. // populate the data
  949. m_pHEGrenade->ActivateItemByRow( m_pWeaponSet->m_HEGrenade );
  950. m_pSmokeGrenade->ActivateItemByRow( m_pWeaponSet->m_smokeGrenade );
  951. m_pFlashbangs->ActivateItemByRow( m_pWeaponSet->m_flashbangs );
  952. m_pHEGrenadeImage->SetItem( "gfx/vgui/hegrenade_square", 1 );
  953. m_pSmokeGrenadeImage->SetItem( "gfx/vgui/smokegrenade_square", 1 );
  954. m_pFlashbangImage->SetItem( "gfx/vgui/flashbang_square", 1 );
  955. OnControlChanged();
  956. }
  957. //--------------------------------------------------------------------------------------------------------------
  958. void CGrenadeSelectBox::OnControlChanged()
  959. {
  960. const int BufLen = 256;
  961. wchar_t wbuf[BufLen];
  962. CCSWeaponInfo *info;
  963. int numGrenades;
  964. info = GetWeaponInfo( WEAPON_HEGRENADE );
  965. if ( info )
  966. {
  967. numGrenades = m_pHEGrenade->GetActiveItem();
  968. g_pVGuiLocalize->ConstructString( wbuf, sizeof( wbuf ),
  969. g_pVGuiLocalize->Find( "#Cstrike_BuyPresetPlainCost" ),
  970. 1, NumAsWString( info->GetWeaponPrice() * numGrenades ) );
  971. m_pHELabel->SetText( wbuf );
  972. }
  973. info = GetWeaponInfo( WEAPON_SMOKEGRENADE );
  974. if ( info )
  975. {
  976. numGrenades = m_pSmokeGrenade->GetActiveItem();
  977. g_pVGuiLocalize->ConstructString( wbuf, sizeof( wbuf ),
  978. g_pVGuiLocalize->Find( "#Cstrike_BuyPresetPlainCost" ),
  979. 1, NumAsWString( info->GetWeaponPrice() * numGrenades ) );
  980. m_pSmokeLabel->SetText( wbuf );
  981. }
  982. info = GetWeaponInfo( WEAPON_FLASHBANG );
  983. if ( info )
  984. {
  985. numGrenades = m_pFlashbangs->GetActiveItem();
  986. g_pVGuiLocalize->ConstructString( wbuf, sizeof( wbuf ),
  987. g_pVGuiLocalize->Find( "#Cstrike_BuyPresetPlainCost" ),
  988. 1, NumAsWString( info->GetWeaponPrice() * numGrenades ) );
  989. m_pFlashLabel->SetText( wbuf );
  990. }
  991. }
  992. //--------------------------------------------------------------------------------------------------------------
  993. void CGrenadeSelectBox::OnCommand( const char *command )
  994. {
  995. if (!stricmp(command, "popup_ok"))
  996. {
  997. // stuff values back in m_pWeaponSet
  998. m_pWeaponSet->m_HEGrenade = m_pHEGrenade->GetActiveItem();
  999. m_pWeaponSet->m_smokeGrenade = m_pSmokeGrenade->GetActiveItem();
  1000. m_pWeaponSet->m_flashbangs = m_pFlashbangs->GetActiveItem();
  1001. }
  1002. BaseClass::OnCommand( command );
  1003. }
  1004. //--------------------------------------------------------------------------------------------------------------
  1005. //--------------------------------------------------------------------------------------------------------------
  1006. CEquipmentSelectBox::CEquipmentSelectBox( vgui::Panel *parent, WeaponSet *pWeaponSet ) : BaseClass( parent, "BuyBoxSelectEquipment", false )
  1007. {
  1008. m_pWeaponSet = pWeaponSet;
  1009. // Equipment controls
  1010. m_pKevlar = new EquipmentComboBox( this, "kevlar", 2, false );
  1011. m_pHelmet = new EquipmentComboBox( this, "helmet", 2, false );
  1012. m_pDefuser = new EquipmentComboBox( this, "defuser", 2, false );
  1013. m_pNightvision = new EquipmentComboBox( this, "nightvision", 2, false );
  1014. // Equipment labels
  1015. m_pKevlarLabel = new Label( this, "kevlarCost", "" );
  1016. m_pHelmetLabel = new Label( this, "helmetCost", "" );
  1017. m_pDefuserLabel = new Label( this, "defuserCost", "" );
  1018. m_pNightvisionLabel = new Label( this, "nightvisionCost", "" );
  1019. // Equipment images
  1020. m_pKevlarImage = new EquipmentLabel( this, "KevlarImage" );
  1021. m_pHelmetImage = new EquipmentLabel( this, "HelmetImage" );
  1022. m_pDefuserImage = new EquipmentLabel( this, "DefuserImage" );
  1023. m_pNightvisionImage = new EquipmentLabel( this, "NightvisionImage" );
  1024. LoadControlSettings( "Resource/UI/BuyPreset/BoxSelectEquipment.res" );
  1025. // Add entries to the combo boxes
  1026. m_pKevlar->AddItem( "0", NULL );
  1027. m_pKevlar->AddItem( "1", NULL );
  1028. m_pHelmet->AddItem( "0", NULL );
  1029. m_pHelmet->AddItem( "1", NULL );
  1030. m_pDefuser->AddItem( "0", NULL );
  1031. m_pDefuser->AddItem( "1", NULL );
  1032. m_pNightvision->AddItem( "0", NULL );
  1033. m_pNightvision->AddItem( "1", NULL );
  1034. // populate the data
  1035. m_pKevlar->ActivateItemByRow( ( m_pWeaponSet->m_armor > 0 ) );
  1036. m_pHelmet->ActivateItemByRow( ( m_pWeaponSet->m_armor && m_pWeaponSet->m_helmet ) );
  1037. m_pDefuser->ActivateItemByRow( m_pWeaponSet->m_defuser );
  1038. m_pNightvision->ActivateItemByRow( m_pWeaponSet->m_nightvision );
  1039. m_pKevlarImage->SetItem( "gfx/vgui/kevlar", 1 );
  1040. m_pHelmetImage->SetItem( "gfx/vgui/helmet", 1 );
  1041. m_pDefuserImage->SetItem( "gfx/vgui/defuser", 1 );
  1042. m_pNightvisionImage->SetItem( "gfx/vgui/nightvision", 1 );
  1043. OnControlChanged();
  1044. }
  1045. //--------------------------------------------------------------------------------------------------------------
  1046. void CEquipmentSelectBox::OnControlChanged()
  1047. {
  1048. const int BufLen = 256;
  1049. wchar_t wbuf[BufLen];
  1050. int iHelmetPrice = HELMET_PRICE;
  1051. int iKevlarPrice = KEVLAR_PRICE;
  1052. int iNVGPrice = NVG_PRICE;
  1053. if ( CSGameRules()->IsBlackMarket() )
  1054. {
  1055. iHelmetPrice = CSGameRules()->GetBlackMarketPriceForWeapon( WEAPON_ASSAULTSUIT ) - CSGameRules()->GetBlackMarketPriceForWeapon( WEAPON_KEVLAR );
  1056. iKevlarPrice = CSGameRules()->GetBlackMarketPriceForWeapon( WEAPON_KEVLAR );
  1057. iNVGPrice = CSGameRules()->GetBlackMarketPriceForWeapon( WEAPON_NVG );
  1058. }
  1059. int count = m_pKevlar->GetActiveItem();
  1060. g_pVGuiLocalize->ConstructString( wbuf, sizeof( wbuf ),
  1061. g_pVGuiLocalize->Find( "#Cstrike_BuyPresetPlainCost" ),
  1062. 1, NumAsWString( iKevlarPrice * count ) );
  1063. m_pKevlarLabel->SetText( wbuf );
  1064. m_pHelmet->SetEnabled( count );
  1065. if ( !count && m_pHelmet->GetActiveItem() )
  1066. m_pHelmet->ActivateItemByRow( 0 );
  1067. count = m_pHelmet->GetActiveItem();
  1068. g_pVGuiLocalize->ConstructString( wbuf, sizeof( wbuf ),
  1069. g_pVGuiLocalize->Find( "#Cstrike_BuyPresetPlainCost" ),
  1070. 1, NumAsWString( iHelmetPrice * count ) );
  1071. m_pHelmetLabel->SetText( wbuf );
  1072. count = m_pDefuser->GetActiveItem();
  1073. g_pVGuiLocalize->ConstructString( wbuf, sizeof( wbuf ),
  1074. g_pVGuiLocalize->Find( "#Cstrike_BuyPresetPlainCost" ),
  1075. 1, NumAsWString( DEFUSEKIT_PRICE * count ) );
  1076. m_pDefuserLabel->SetText( wbuf );
  1077. count = m_pNightvision->GetActiveItem();
  1078. g_pVGuiLocalize->ConstructString( wbuf, sizeof( wbuf ),
  1079. g_pVGuiLocalize->Find( "#Cstrike_BuyPresetPlainCost" ),
  1080. 1, NumAsWString( NVG_PRICE * count ) );
  1081. m_pNightvisionLabel->SetText( wbuf );
  1082. }
  1083. //--------------------------------------------------------------------------------------------------------------
  1084. void CEquipmentSelectBox::OnCommand( const char *command )
  1085. {
  1086. if (!stricmp(command, "popup_ok"))
  1087. {
  1088. // stuff values back in m_pWeaponSet
  1089. m_pWeaponSet->m_armor = m_pKevlar->GetActiveItem() ? 100 : 0;
  1090. m_pWeaponSet->m_helmet = m_pWeaponSet->m_armor && m_pHelmet->GetActiveItem();
  1091. m_pWeaponSet->m_defuser = m_pDefuser->GetActiveItem();
  1092. m_pWeaponSet->m_nightvision = m_pNightvision->GetActiveItem();
  1093. }
  1094. BaseClass::OnCommand( command );
  1095. }
  1096. //--------------------------------------------------------------------------------------------------------------