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.

932 lines
28 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "confirm_dialog.h"
  8. #include "ienginevgui.h"
  9. #include "econ_controls.h"
  10. #include "vgui/IInput.h"
  11. #include "vgui/ISurface.h"
  12. #include "vgui_controls/TextImage.h"
  13. #include "vgui_controls/CheckButton.h"
  14. #include "econ_ui.h"
  15. #include "store/store_panel.h"
  16. #ifdef TF_CLIENT_DLL
  17. #include "tf_playerpanel.h"
  18. #endif // TF_CLIENT_DLL
  19. // memdbgon must be the last include file in a .cpp file!!!
  20. #include <tier0/memdbgon.h>
  21. static const wchar_t* GetSCGlyph( const char* action )
  22. {
  23. auto origin = g_pInputSystem->GetSteamControllerActionOrigin( action, GAME_ACTION_SET_FPSCONTROLS );
  24. return g_pInputSystem->GetSteamControllerFontCharacterForActionOrigin( origin );
  25. }
  26. //-----------------------------------------------------------------------------
  27. // Purpose:
  28. //-----------------------------------------------------------------------------
  29. CConfirmDialog::CConfirmDialog( vgui::Panel *parent )
  30. : BaseClass( parent, "ConfirmDialog" ),
  31. m_pCancelButton( NULL ),
  32. m_pConfirmButton( NULL ),
  33. m_pIcon( NULL )
  34. {
  35. }
  36. //-----------------------------------------------------------------------------
  37. // Purpose:
  38. //-----------------------------------------------------------------------------
  39. void CConfirmDialog::ApplySchemeSettings( vgui::IScheme *pScheme )
  40. {
  41. BaseClass::ApplySchemeSettings( pScheme );
  42. LoadControlSettings( GetResFile(), "GAME" );
  43. SetBorder( pScheme->GetBorder("EconItemBorder") );
  44. // Cache off button ptrs
  45. m_pConfirmButton = dynamic_cast< CExButton* >( FindChildByName( "ConfirmButton" ) );
  46. m_pCancelButton = dynamic_cast< CExButton* >( FindChildByName( "CancelButton" ) );
  47. m_pIcon = dynamic_cast< vgui::ImagePanel* >( FindChildByName( "Icon" ) );
  48. SetDialogVariable( "text", GetText() );
  49. if ( ::input->IsSteamControllerActive() )
  50. {
  51. auto iconConfirm = GetSCGlyph( "cl_trigger_first_notification" );
  52. auto iconCancel = GetSCGlyph( "cl_decline_first_notification" );
  53. auto confirmHint = dynamic_cast< CExLabel* >( FindChildByName( "ConfirmButtonHintIcon" ) );
  54. auto cancelHint = dynamic_cast< CExLabel* >( FindChildByName( "CancelButtonHintIcon" ) );
  55. if ( confirmHint )
  56. {
  57. confirmHint->SetText( iconConfirm );
  58. }
  59. if ( cancelHint )
  60. {
  61. cancelHint->SetText( iconCancel );
  62. }
  63. }
  64. }
  65. //-----------------------------------------------------------------------------
  66. // Purpose:
  67. //-----------------------------------------------------------------------------
  68. void CConfirmDialog::Show( bool bMakePopup )
  69. {
  70. SetVisible( true );
  71. if ( bMakePopup )
  72. {
  73. MakePopup();
  74. }
  75. MoveToFront();
  76. SetKeyBoardInputEnabled( true );
  77. InvalidateLayout( true, true );
  78. if ( ::input->IsSteamControllerActive() )
  79. {
  80. auto iconConfirm = GetSCGlyph( "vote_option1" );
  81. auto iconCancel = GetSCGlyph( "vote_option2" );
  82. bool bControllerMapped = iconConfirm[0] && iconCancel[0];
  83. if ( bControllerMapped )
  84. {
  85. SetMouseInputEnabled( false );
  86. }
  87. else
  88. {
  89. SetMouseInputEnabled( true );
  90. }
  91. }
  92. else
  93. {
  94. SetMouseInputEnabled( true );
  95. }
  96. TFModalStack()->PushModal( this );
  97. }
  98. //-----------------------------------------------------------------------------
  99. // Purpose:
  100. //-----------------------------------------------------------------------------
  101. void CConfirmDialog::SetIconImage( const char *pszIcon )
  102. {
  103. Assert( m_pIcon );
  104. if ( m_pIcon )
  105. {
  106. m_pIcon->SetImage( pszIcon );
  107. m_pIcon->SetVisible( ( pszIcon ? true : false ) );
  108. }
  109. }
  110. //-----------------------------------------------------------------------------
  111. // Purpose:
  112. //-----------------------------------------------------------------------------
  113. void CConfirmDialog::OnCommand( const char *command )
  114. {
  115. if ( !Q_strnicmp( command, "cancel", 6 ) )
  116. {
  117. FinishUp();
  118. PostMessage( GetParent(), new KeyValues( "ConfirmDlgResult", "confirmed", 0 ) );
  119. }
  120. else if ( !Q_strnicmp( command, "confirm", 7 ) )
  121. {
  122. FinishUp();
  123. PostMessage( GetParent(), new KeyValues( "ConfirmDlgResult", "confirmed", 1 ) );
  124. }
  125. else
  126. {
  127. engine->ClientCmd( const_cast<char *>( command ) );
  128. }
  129. BaseClass::OnCommand( command );
  130. }
  131. //-----------------------------------------------------------------------------
  132. // Purpose:
  133. //-----------------------------------------------------------------------------
  134. void CConfirmDialog::OnKeyCodeTyped( vgui::KeyCode code )
  135. {
  136. if( code == KEY_ESCAPE )
  137. {
  138. OnCommand( "cancel" );
  139. }
  140. else
  141. {
  142. BaseClass::OnKeyCodePressed( code );
  143. }
  144. }
  145. ///-----------------------------------------------------------------------------
  146. // Purpose:
  147. //-----------------------------------------------------------------------------
  148. void CConfirmDialog::OnKeyCodePressed( vgui::KeyCode code )
  149. {
  150. ButtonCode_t nButtonCode = GetBaseButtonCode( code );
  151. // We map the voting action buttons to the pseudo-buttons F1/F2 so that players can use them to interact with dialogs on the fly
  152. if( nButtonCode == KEY_XBUTTON_B || nButtonCode == STEAMCONTROLLER_F2 || nButtonCode == STEAMCONTROLLER_B )
  153. {
  154. OnCommand( "cancel" );
  155. }
  156. else if ( nButtonCode == KEY_ENTER || nButtonCode == KEY_SPACE || nButtonCode == KEY_XBUTTON_A || nButtonCode == STEAMCONTROLLER_F1 || nButtonCode == STEAMCONTROLLER_A )
  157. {
  158. OnCommand( "confirm" );
  159. }
  160. else
  161. {
  162. BaseClass::OnKeyCodePressed( code );
  163. }
  164. }
  165. //-----------------------------------------------------------------------------
  166. // Purpose:
  167. //-----------------------------------------------------------------------------
  168. const char *CConfirmDialog::GetResFile()
  169. {
  170. if ( ::input->IsSteamControllerActive() )
  171. {
  172. return "Resource/UI/econ/ConfirmDialog_SC.res";
  173. }
  174. else
  175. {
  176. return "Resource/UI/econ/ConfirmDialog.res";
  177. }
  178. }
  179. //-----------------------------------------------------------------------------
  180. // Purpose: Hide the panel, mark for deletion, remove from modal stack.
  181. //-----------------------------------------------------------------------------
  182. void CConfirmDialog::FinishUp()
  183. {
  184. SetVisible( false );
  185. TFModalStack()->PopModal( this );
  186. MarkForDeletion();
  187. }
  188. //-----------------------------------------------------------------------------
  189. // Purpose:
  190. //-----------------------------------------------------------------------------
  191. void CConfirmDialog::OnSizeChanged( int nNewWide, int nNewTall )
  192. {
  193. int nX, nY;
  194. // Shift buttons up
  195. if ( m_pCancelButton )
  196. {
  197. m_pCancelButton->GetPos( nX, nY );
  198. m_pCancelButton->SetPos( nX, nNewTall - m_pCancelButton->GetTall() - YRES(15) );
  199. }
  200. if ( m_pConfirmButton )
  201. {
  202. m_pConfirmButton->GetPos( nX, nY );
  203. m_pConfirmButton->SetPos( nX, nNewTall - m_pConfirmButton->GetTall() - YRES(15) );
  204. }
  205. }
  206. //-----------------------------------------------------------------------------
  207. // Purpose:
  208. //-----------------------------------------------------------------------------
  209. CTFGenericConfirmDialog::CTFGenericConfirmDialog( const char *pTitle, const char *pTextKey,
  210. const char *pConfirmBtnText, const char *pCancelBtnText,
  211. GenericConfirmDialogCallback callback, vgui::Panel *pParent )
  212. : BaseClass( pParent ),
  213. m_pTextKey( pTextKey )
  214. {
  215. CommonInit( pTitle, pConfirmBtnText, pCancelBtnText, callback, pParent );
  216. }
  217. //-----------------------------------------------------------------------------
  218. // Purpose:
  219. //-----------------------------------------------------------------------------
  220. CTFGenericConfirmDialog::CTFGenericConfirmDialog( const char *pTitle, const wchar_t *pText,
  221. const char *pConfirmBtnText, const char *pCancelBtnText,
  222. GenericConfirmDialogCallback callback, vgui::Panel *pParent )
  223. : BaseClass( pParent ),
  224. m_pTextKey( NULL )
  225. {
  226. CommonInit( pTitle, pConfirmBtnText, pCancelBtnText, callback, pParent );
  227. V_wcsncpy( m_wszBuffer, pText, sizeof( m_wszBuffer ) );
  228. }
  229. //-----------------------------------------------------------------------------
  230. // Purpose:
  231. //-----------------------------------------------------------------------------
  232. void CTFGenericConfirmDialog::CommonInit( const char *pTitle, const char *pConfirmBtnText, const char *pCancelBtnText,
  233. GenericConfirmDialogCallback callback, vgui::Panel *pParent )
  234. {
  235. if ( pParent == NULL )
  236. {
  237. vgui::HScheme scheme = vgui::scheme()->LoadSchemeFromFileEx( enginevgui->GetPanel( PANEL_CLIENTDLL ), "resource/ClientScheme.res", "ClientScheme");
  238. SetScheme(scheme);
  239. SetProportional( true );
  240. }
  241. m_pTitle = pTitle;
  242. m_pConfirmBtnText = pConfirmBtnText;
  243. m_pCancelBtnText = pCancelBtnText;
  244. m_pCallback = callback;
  245. m_pContext = NULL;
  246. m_pKeyValues = NULL;
  247. }
  248. //-----------------------------------------------------------------------------
  249. // Purpose:
  250. //-----------------------------------------------------------------------------
  251. CTFGenericConfirmDialog::~CTFGenericConfirmDialog()
  252. {
  253. if ( m_pKeyValues )
  254. {
  255. m_pKeyValues->deleteThis();
  256. }
  257. }
  258. //-----------------------------------------------------------------------------
  259. // Purpose:
  260. //-----------------------------------------------------------------------------
  261. const wchar_t *CTFGenericConfirmDialog::GetText()
  262. {
  263. if ( m_pTextKey )
  264. {
  265. g_pVGuiLocalize->ConstructString_safe( m_wszBuffer, m_pTextKey, m_pKeyValues );
  266. return m_wszBuffer;
  267. }
  268. return m_wszBuffer;
  269. }
  270. //-----------------------------------------------------------------------------
  271. // Purpose:
  272. //-----------------------------------------------------------------------------
  273. void CTFGenericConfirmDialog::ApplySchemeSettings( vgui::IScheme *pScheme )
  274. {
  275. BaseClass::ApplySchemeSettings( pScheme );
  276. if ( m_pConfirmButton && m_pConfirmBtnText )
  277. {
  278. m_pConfirmButton->SetText( m_pConfirmBtnText );
  279. }
  280. if ( m_pCancelButton && m_pCancelBtnText )
  281. {
  282. m_pCancelButton->SetText (m_pCancelBtnText );
  283. }
  284. SetXToRed( m_pConfirmButton );
  285. SetXToRed( m_pCancelButton );
  286. CExLabel *pTitle = dynamic_cast< CExLabel* >( FindChildByName( "TitleLabel" ) );
  287. if ( pTitle )
  288. {
  289. pTitle->SetText( m_pTitle );
  290. }
  291. }
  292. //-----------------------------------------------------------------------------
  293. // Purpose:
  294. //-----------------------------------------------------------------------------
  295. void CTFGenericConfirmDialog::PerformLayout()
  296. {
  297. // Center it, keeping requested size
  298. int x, y, ww, wt, wide, tall;
  299. vgui::surface()->GetWorkspaceBounds( x, y, ww, wt );
  300. GetSize(wide, tall);
  301. SetPos(x + ((ww - wide) / 2), y + ((wt - tall) / 2));
  302. }
  303. //-----------------------------------------------------------------------------
  304. // Purpose:
  305. //-----------------------------------------------------------------------------
  306. void CTFGenericConfirmDialog::OnCommand( const char *command )
  307. {
  308. bool bFinishUp = false;
  309. bool bConfirmed = false;
  310. if ( !Q_strnicmp( command, "cancel", 6 ) )
  311. {
  312. bConfirmed = false;
  313. bFinishUp = true;
  314. }
  315. else if ( !Q_strnicmp( command, "confirm", 7 ) )
  316. {
  317. bConfirmed = true;
  318. bFinishUp = true;
  319. }
  320. if ( bFinishUp )
  321. {
  322. FinishUp();
  323. if ( m_pCallback )
  324. {
  325. m_pCallback( bConfirmed, m_pContext );
  326. }
  327. return;
  328. }
  329. BaseClass::OnCommand( command );
  330. }
  331. //-----------------------------------------------------------------------------
  332. // Purpose:
  333. //-----------------------------------------------------------------------------
  334. void CTFGenericConfirmDialog::SetStringTokens( KeyValues *pKeyValues )
  335. {
  336. if ( m_pKeyValues != NULL )
  337. {
  338. m_pKeyValues->deleteThis();
  339. }
  340. m_pKeyValues = pKeyValues->MakeCopy();
  341. }
  342. //-----------------------------------------------------------------------------
  343. // Purpose:
  344. //-----------------------------------------------------------------------------
  345. void CTFGenericConfirmDialog::AddStringToken( const char* pToken, const wchar_t* pValue )
  346. {
  347. if ( m_pKeyValues == NULL )
  348. {
  349. m_pKeyValues = new KeyValues( "GenericConfirmDialog" );
  350. }
  351. m_pKeyValues->SetWString( pToken, pValue );
  352. InvalidateLayout( false, true );
  353. }
  354. //-----------------------------------------------------------------------------
  355. // Purpose:
  356. //-----------------------------------------------------------------------------
  357. void CTFGenericConfirmDialog::SetContext( void *pContext )
  358. {
  359. m_pContext = pContext;
  360. }
  361. //-----------------------------------------------------------------------------
  362. // Purpose:
  363. //-----------------------------------------------------------------------------
  364. CTFGenericConfirmOptOutDialog::CTFGenericConfirmOptOutDialog( const char *pTitle,
  365. const char *pText,
  366. const char *pConfirmBtnText,
  367. const char *pCancelBtnText,
  368. const char *pOptOutText,
  369. const char *pOptOutConVarName,
  370. GenericConfirmDialogCallback callback,
  371. vgui::Panel *parent ) :
  372. CTFGenericConfirmDialog( pTitle, pText, pConfirmBtnText, pCancelBtnText, callback, parent )
  373. {
  374. m_optOutText = pOptOutText;
  375. m_optOutCheckbox = NULL;
  376. m_optOutConVarName = pOptOutConVarName;
  377. }
  378. //-----------------------------------------------------------------------------
  379. // Purpose:
  380. //-----------------------------------------------------------------------------
  381. void CTFGenericConfirmOptOutDialog::ApplySchemeSettings( vgui::IScheme *pScheme )
  382. {
  383. BaseClass::ApplySchemeSettings( pScheme );
  384. m_optOutCheckbox = dynamic_cast< vgui::CheckButton * >( FindChildByName( "OptOutCheckbox" ) );
  385. if ( m_optOutCheckbox && m_optOutText )
  386. {
  387. m_optOutCheckbox->SetMouseInputEnabled( true );
  388. m_optOutCheckbox->SetText( m_optOutText );
  389. // center horizontally
  390. vgui::Panel *parent = m_optOutCheckbox->GetParent();
  391. if ( parent )
  392. {
  393. float parentWidth = parent->GetWide();
  394. int checkBoxWidth, checkBoxHeight;
  395. m_optOutCheckbox->GetContentSize( checkBoxWidth, checkBoxHeight );
  396. // fudge in checkbox width
  397. checkBoxWidth += 34.0f;
  398. int checkX, checkY;
  399. m_optOutCheckbox->GetPos( checkX, checkY );
  400. m_optOutCheckbox->SetPos( ( parentWidth - checkBoxWidth ) / 2.0f, checkY );
  401. }
  402. }
  403. }
  404. //-----------------------------------------------------------------------------
  405. // Purpose:
  406. //-----------------------------------------------------------------------------
  407. const char *CTFGenericConfirmOptOutDialog::GetResFile()
  408. {
  409. return "Resource/UI/econ/ConfirmDialogOptOut.res";
  410. }
  411. //-----------------------------------------------------------------------------
  412. // Purpose:
  413. //-----------------------------------------------------------------------------
  414. void CTFGenericConfirmOptOutDialog::OnButtonChecked( KeyValues *pData )
  415. {
  416. ConVarRef var( m_optOutConVarName );
  417. if ( !var.IsValid() )
  418. return;
  419. if ( !m_optOutCheckbox )
  420. return;
  421. var.SetValue( m_optOutCheckbox->IsSelected() );
  422. }
  423. //-----------------------------------------------------------------------------
  424. // Purpose:
  425. //-----------------------------------------------------------------------------
  426. void CTFUpgradeBoxDialog::OnCommand( const char *command )
  427. {
  428. if ( !Q_stricmp( command, "upgrade" ) )
  429. {
  430. FinishUp();
  431. // Open the store, and show the upgrade advice
  432. EconUI()->CloseEconUI();
  433. EconUI()->OpenStorePanel( STOREPANEL_SHOW_UPGRADESTEPS, false );
  434. }
  435. else
  436. {
  437. BaseClass::OnCommand( command );
  438. }
  439. }
  440. //-----------------------------------------------------------------------------
  441. // Purpose:
  442. //-----------------------------------------------------------------------------
  443. CTFGenericConfirmDialog *ShowConfirmDialog( const char *pTitle, const char *pText, const char *pConfirmBtnText, const char *pCancelBtnText, GenericConfirmDialogCallback callback,
  444. vgui::Panel *parent/*=NULL*/, void *pContext/*=NULL*/, const char *pSound/*=NULL*/ )
  445. {
  446. CTFGenericConfirmDialog *pDialog = vgui::SETUP_PANEL(
  447. new CTFGenericConfirmDialog(
  448. pTitle, pText,
  449. pConfirmBtnText, pCancelBtnText,
  450. callback, parent
  451. )
  452. );
  453. if ( pDialog )
  454. {
  455. pDialog->Show();
  456. // Play a sound, if one was supplied.
  457. if ( pSound && pSound[0] )
  458. {
  459. vgui::surface()->PlaySound( pSound );
  460. }
  461. }
  462. if ( pContext )
  463. {
  464. pDialog->SetContext( pContext );
  465. }
  466. return pDialog;
  467. }
  468. //-----------------------------------------------------------------------------
  469. // Purpose:
  470. //-----------------------------------------------------------------------------
  471. CTFMessageBoxDialog *ShowMessageBox( const char *pTitle, const char *pText, const char *pConfirmBtnText, GenericConfirmDialogCallback callback, vgui::Panel *parent, void *pContext )
  472. {
  473. return ShowMessageBox( pTitle, pText, NULL, pConfirmBtnText, callback, parent, pContext );
  474. }
  475. //-----------------------------------------------------------------------------
  476. // Purpose:
  477. //-----------------------------------------------------------------------------
  478. CTFMessageBoxDialog *ShowMessageBox( const char *pTitle, const wchar_t *pText, const char *pConfirmBtnText, GenericConfirmDialogCallback callback, vgui::Panel *parent , void *pContext)
  479. {
  480. CTFMessageBoxDialog *pDialog = vgui::SETUP_PANEL(
  481. new CTFMessageBoxDialog(
  482. pTitle, pText,
  483. pConfirmBtnText,
  484. callback, parent
  485. )
  486. );
  487. if ( pDialog )
  488. {
  489. if ( pContext )
  490. {
  491. pDialog->SetContext( pContext );
  492. }
  493. pDialog->Show();
  494. }
  495. return pDialog;
  496. }
  497. //-----------------------------------------------------------------------------
  498. // Purpose:
  499. //-----------------------------------------------------------------------------
  500. CTFMessageBoxDialog *ShowMessageBox( const char *pTitle, const char *pText, KeyValues *pKeyValues, const char *pConfirmBtnText, GenericConfirmDialogCallback callback, vgui::Panel *parent , void *pContext)
  501. {
  502. CTFMessageBoxDialog *pDialog = vgui::SETUP_PANEL( new CTFMessageBoxDialog( pTitle, pText,
  503. pConfirmBtnText,
  504. callback, parent ) );
  505. if ( pDialog )
  506. {
  507. if ( pContext )
  508. {
  509. pDialog->SetContext( pContext );
  510. }
  511. if ( pKeyValues )
  512. {
  513. pDialog->SetStringTokens( pKeyValues );
  514. pDialog->SetDialogVariable( "text", pDialog->GetText() );
  515. }
  516. pDialog->Show();
  517. }
  518. return pDialog;
  519. }
  520. //-----------------------------------------------------------------------------
  521. // Purpose: Pop up a model yes/no dialog with an "opt out" checkbox that persists via a ConVar
  522. //-----------------------------------------------------------------------------
  523. CTFGenericConfirmOptOutDialog *ShowConfirmOptOutDialog( const char *pTitle, const char *pText, const char *pConfirmBtnText, const char *pCancelBtnText, const char *pOptOutText, const char *pOptOutConVarName, GenericConfirmDialogCallback callback, vgui::Panel *parent)
  524. {
  525. CTFGenericConfirmOptOutDialog *pDialog = vgui::SETUP_PANEL( new CTFGenericConfirmOptOutDialog( pTitle, pText,
  526. pConfirmBtnText, pCancelBtnText,
  527. pOptOutText, pOptOutConVarName,
  528. callback, parent ) );
  529. if ( pDialog )
  530. {
  531. pDialog->Show();
  532. }
  533. return pDialog;
  534. }
  535. //-----------------------------------------------------------------------------
  536. // Purpose:
  537. //-----------------------------------------------------------------------------
  538. CTFMessageBoxDialog *ShowUpgradeMessageBox( const char *pTitle, const char *pText,
  539. const char *pConfirmBtnText,
  540. GenericConfirmDialogCallback callback,
  541. vgui::Panel *parent, void *pContext )
  542. {
  543. CTFMessageBoxDialog *pDialog = vgui::SETUP_PANEL(
  544. new CTFUpgradeBoxDialog(
  545. pTitle, pText,
  546. pConfirmBtnText, callback, parent
  547. )
  548. );
  549. if ( pDialog )
  550. {
  551. pDialog->SetContext( pContext );
  552. pDialog->Show();
  553. }
  554. return pDialog;
  555. }
  556. //-----------------------------------------------------------------------------
  557. // Purpose: Pop up a dialog prompting the player to go to the store to upgrade
  558. //-----------------------------------------------------------------------------
  559. CTFMessageBoxDialog *ShowUpgradeMessageBox( const char *pTitle, const char *pText )
  560. {
  561. return ShowUpgradeMessageBox( pTitle, pText, "#GameUI_OK", NULL, NULL, NULL );
  562. }
  563. //-----------------------------------------------------------------------------
  564. // Purpose:
  565. //-----------------------------------------------------------------------------
  566. CTFMessageBoxDialogWithSound *ShowMessageBoxWithSound( const char *pTitle, const char *pText, const char *pszSound, float flDelay, const char *pConfirmBtnText, GenericConfirmDialogCallback callback, vgui::Panel *parent, void *pContext )
  567. {
  568. return ShowMessageBoxWithSound( pTitle, pText, NULL, pszSound, flDelay, pConfirmBtnText, callback, parent, pContext );
  569. }
  570. //-----------------------------------------------------------------------------
  571. // Purpose:
  572. //-----------------------------------------------------------------------------
  573. CTFMessageBoxDialogWithSound *ShowMessageBoxWithSound( const char *pTitle, const wchar_t *pText, const char *pszSound, float flDelay, const char *pConfirmBtnText , GenericConfirmDialogCallback callback, vgui::Panel *parent, void *pContext )
  574. {
  575. CTFMessageBoxDialogWithSound *pDialog = vgui::SETUP_PANEL( new CTFMessageBoxDialogWithSound( pTitle, pText, pszSound, flDelay, pConfirmBtnText, callback, parent ) );
  576. if ( pDialog )
  577. {
  578. if ( pContext )
  579. {
  580. pDialog->SetContext( pContext );
  581. }
  582. pDialog->Show();
  583. }
  584. return pDialog;
  585. }
  586. //-----------------------------------------------------------------------------
  587. // Purpose:
  588. //-----------------------------------------------------------------------------
  589. CTFMessageBoxDialogWithSound *ShowMessageBoxWithSound( const char *pTitle, const char *pText, KeyValues *pKeyValues, const char *pszSound, float flDelay, const char *pConfirmBtnText, GenericConfirmDialogCallback callback, vgui::Panel *parent, void *pContext )
  590. {
  591. CTFMessageBoxDialogWithSound *pDialog = vgui::SETUP_PANEL( new CTFMessageBoxDialogWithSound( pTitle, pText, pszSound, flDelay, pConfirmBtnText, callback, parent ) );
  592. if ( pDialog )
  593. {
  594. if ( pContext )
  595. {
  596. pDialog->SetContext( pContext );
  597. }
  598. if ( pKeyValues )
  599. {
  600. pDialog->SetStringTokens( pKeyValues );
  601. pDialog->SetDialogVariable( "text", pDialog->GetText() );
  602. }
  603. pDialog->Show();
  604. }
  605. return pDialog;
  606. }
  607. //-----------------------------------------------------------------------------
  608. // Purpose:
  609. //-----------------------------------------------------------------------------
  610. CTFMessageBoxDialogWithSound::CTFMessageBoxDialogWithSound( const char *pTitle, const char *pText, const char *pszSound, float flDelay, const char *pConfirmBtnText, GenericConfirmDialogCallback callback, vgui::Panel *parent )
  611. : CTFMessageBoxDialog( pTitle, pText, pConfirmBtnText, callback, parent )
  612. {
  613. m_szSound[0] = 0;
  614. if ( pszSound )
  615. {
  616. V_strcpy_safe( m_szSound, pszSound );
  617. }
  618. m_flSoundTime = gpGlobals->curtime + flDelay;
  619. m_bPlayedSound = false;
  620. vgui::ivgui()->AddTickSignal( GetVPanel(), 50 );
  621. }
  622. //-----------------------------------------------------------------------------
  623. // Purpose:
  624. //-----------------------------------------------------------------------------
  625. CTFMessageBoxDialogWithSound::CTFMessageBoxDialogWithSound( const char *pTitle, const wchar_t *pText, const char *pszSound, float flDelay, const char *pConfirmBtnText, GenericConfirmDialogCallback callback, vgui::Panel *parent )
  626. : CTFMessageBoxDialog( pTitle, pText, pConfirmBtnText, callback, parent )
  627. {
  628. m_szSound[0] = 0;
  629. if ( pszSound )
  630. {
  631. V_strcpy_safe( m_szSound, pszSound );
  632. }
  633. m_flSoundTime = gpGlobals->curtime + flDelay;
  634. m_bPlayedSound = false;
  635. vgui::ivgui()->AddTickSignal( GetVPanel(), 50 );
  636. }
  637. //-----------------------------------------------------------------------------
  638. // Purpose:
  639. //-----------------------------------------------------------------------------
  640. void CTFMessageBoxDialogWithSound::OnTick()
  641. {
  642. BaseClass::OnTick();
  643. if ( !m_bPlayedSound && ( m_flSoundTime < gpGlobals->curtime ) )
  644. {
  645. m_bPlayedSound = true;
  646. if ( Q_strlen( m_szSound ) > 0 )
  647. {
  648. C_BasePlayer *pLocalPlayer = C_BasePlayer::GetLocalPlayer();
  649. if ( pLocalPlayer )
  650. {
  651. pLocalPlayer->EmitSound( m_szSound );
  652. }
  653. }
  654. }
  655. }
  656. #ifdef TF_CLIENT_DLL
  657. //-----------------------------------------------------------------------------
  658. // Purpose:
  659. //-----------------------------------------------------------------------------
  660. CTFReviveDialog::CTFReviveDialog( const char *pTitle, const char *pText, const char *pConfirmBtnText, GenericConfirmDialogCallback callback, vgui::Panel *parent )
  661. : CTFMessageBoxDialog( pTitle, pText, pConfirmBtnText, callback, parent )
  662. {
  663. m_pTargetHealth = new CTFSpectatorGUIHealth( this, "SpectatorGUIHealth" );
  664. m_pTargetHealth->SetAllowAnimations( false );
  665. m_pTargetHealth->HideHealthBonusImage();
  666. vgui::ivgui()->AddTickSignal( GetVPanel(), 50 );
  667. OnTick();
  668. }
  669. //-----------------------------------------------------------------------------
  670. // Purpose:
  671. //-----------------------------------------------------------------------------
  672. void CTFReviveDialog::PerformLayout()
  673. {
  674. // Skipping base class
  675. }
  676. //-----------------------------------------------------------------------------
  677. // Purpose:
  678. //-----------------------------------------------------------------------------
  679. void CTFReviveDialog::OnTick()
  680. {
  681. BaseClass::OnTick();
  682. if ( !m_pTargetHealth )
  683. return;
  684. if ( !m_hEntity )
  685. return;
  686. float flHealth = m_hEntity->GetHealth();
  687. if ( flHealth != m_flPrevHealth )
  688. {
  689. float flMaxHealth = m_hEntity->GetMaxHealth();
  690. m_pTargetHealth->SetHealth( flHealth, flMaxHealth, flMaxHealth );
  691. m_flPrevHealth = flHealth;
  692. }
  693. }
  694. //-----------------------------------------------------------------------------
  695. // Purpose:
  696. //-----------------------------------------------------------------------------
  697. void CTFReviveDialog::SetOwner( CBaseEntity *pEntity )
  698. {
  699. if ( pEntity )
  700. {
  701. m_hEntity = pEntity;
  702. }
  703. }
  704. //-----------------------------------------------------------------------------
  705. // Purpose: In-game dialog that avoids the crosshair area and is much smaller
  706. //-----------------------------------------------------------------------------
  707. CTFReviveDialog *ShowRevivePrompt( CBaseEntity *pOwner,
  708. const char *pTitle,
  709. const char *pText,
  710. const char *pConfirmBtnText,
  711. GenericConfirmDialogCallback callback,
  712. vgui::Panel *parent, void *pContext )
  713. {
  714. CTFReviveDialog *pDialog = vgui::SETUP_PANEL( new CTFReviveDialog( pTitle, pText, pConfirmBtnText, callback, parent ) );
  715. if ( pDialog )
  716. {
  717. if ( pContext )
  718. {
  719. pDialog->SetContext( pContext );
  720. }
  721. pDialog->SetOwner( pOwner );
  722. pDialog->Show();
  723. }
  724. return pDialog;
  725. }
  726. //-----------------------------------------------------------------------------
  727. // Purpose:
  728. //-----------------------------------------------------------------------------
  729. CEconRequirementDialog::CEconRequirementDialog( const char *pTitle, const char *pTextKey, const char *pItemDefName )
  730. : CTFGenericConfirmDialog( pTitle, pTextKey, NULL, NULL, NULL, NULL )
  731. , m_hItemDef( pItemDefName )
  732. {
  733. }
  734. //-----------------------------------------------------------------------------
  735. // Purpose:
  736. //-----------------------------------------------------------------------------
  737. const char *CEconRequirementDialog::GetResFile()
  738. {
  739. return "Resource/UI/MvMEconRequirementDialog.res";
  740. }
  741. //-----------------------------------------------------------------------------
  742. // Purpose:
  743. //-----------------------------------------------------------------------------
  744. void CEconRequirementDialog::ApplySchemeSettings( vgui::IScheme *pScheme )
  745. {
  746. BaseClass::ApplySchemeSettings( pScheme );
  747. vgui::ImagePanel *pItemImagePanel = dynamic_cast<vgui::ImagePanel *>( FindChildByName( "ItemImagePanel", true ) ); Assert( pItemImagePanel );
  748. Assert( pItemImagePanel );
  749. if ( pItemImagePanel && m_hItemDef )
  750. {
  751. pItemImagePanel->SetImage( CFmtStr( "../%s_large", m_hItemDef->GetInventoryImage() ) );
  752. }
  753. }
  754. //-----------------------------------------------------------------------------
  755. // Purpose:
  756. //-----------------------------------------------------------------------------
  757. void CEconRequirementDialog::OnCommand( const char *command )
  758. {
  759. if ( m_hItemDef && !Q_stricmp( command, "show_in_store" ) )
  760. {
  761. FinishUp();
  762. // Open the store, and show the upgrade advice
  763. EconUI()->CloseEconUI();
  764. EconUI()->OpenStorePanel( m_hItemDef->GetDefinitionIndex(), false );
  765. }
  766. else
  767. {
  768. BaseClass::OnCommand( command );
  769. }
  770. }
  771. //-----------------------------------------------------------------------------
  772. // Purpose:
  773. //-----------------------------------------------------------------------------
  774. void ShowEconRequirementDialog( const char *pTitle, const char *pText, const char *pItemDefName )
  775. {
  776. CEconRequirementDialog *pDialog = vgui::SETUP_PANEL( new CEconRequirementDialog( pTitle, pText, pItemDefName ) );
  777. if ( pDialog )
  778. {
  779. pDialog->Show();
  780. }
  781. }
  782. //-----------------------------------------------------------------------------
  783. // Purpose: Get the correct res file to use (depends on Steam Controller state)
  784. //-----------------------------------------------------------------------------
  785. const char* CTFMessageBoxDialog::GetResFile()
  786. {
  787. if ( ::input->IsSteamControllerActive() )
  788. {
  789. return "Resource/UI/econ/MessageBoxDialog_SC.res";
  790. }
  791. else
  792. {
  793. return "Resource/UI/econ/MessageBoxDialog.res";
  794. }
  795. }
  796. #endif // TF_CLIENT_DLL