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.

864 lines
27 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "character_info_panel.h"
  8. #include "tf_statsummary.h"
  9. #include "vgui_controls/PropertySheet.h"
  10. #include "vgui/IInput.h"
  11. #include "baseviewport.h"
  12. #include "iclientmode.h"
  13. #include "charinfo_loadout_subpanel.h"
  14. #include "charinfo_armory_subpanel.h"
  15. #include "ienginevgui.h"
  16. #include "tf_hud_statpanel.h"
  17. #include "c_tf_player.h"
  18. #include "tf_item_inventory.h"
  19. #include "econ_notifications.h"
  20. #include <vgui/ILocalize.h>
  21. #include <vgui_controls/AnimationController.h>
  22. #include "econ_ui.h"
  23. #include "c_tf_gamestats.h"
  24. #include "tf_item_pickup_panel.h"
  25. #include "store/v1/tf_store_panel.h"
  26. #include "store/v2/tf_store_panel2.h"
  27. #include "store/tf_store.h"
  28. #include "tf_matchmaking_dashboard.h"
  29. // memdbgon must be the last include file in a .cpp file!!!
  30. #include <tier0/memdbgon.h>
  31. static vgui::DHANDLE<CCharacterInfoPanel> g_CharInfoPanel;
  32. IEconRootUI* EconUI( void )
  33. {
  34. if (!g_CharInfoPanel.Get())
  35. {
  36. g_CharInfoPanel = new CCharacterInfoPanel( NULL );
  37. g_CharInfoPanel->MakeReadyForUse();
  38. g_CharInfoPanel->InvalidateLayout( false, true );
  39. }
  40. return g_CharInfoPanel;
  41. }
  42. //-----------------------------------------------------------------------------
  43. // Purpose:
  44. //-----------------------------------------------------------------------------
  45. CServerNotConnectedToSteamDialog *OpenServerNotConnectedToSteamDialog( vgui::Panel *pParent );
  46. //-----------------------------------------------------------------------------
  47. // Purpose: Basic help dialog
  48. //-----------------------------------------------------------------------------
  49. CCharacterInfoPanel::CCharacterInfoPanel( Panel *parent ) : PropertyDialog(parent, "character_info")
  50. {
  51. // Character info is parented to the game UI panel
  52. vgui::VPANEL gameuiPanel = enginevgui->GetPanel( PANEL_GAMEUIDLL );
  53. SetParent( gameuiPanel );
  54. // We don't want the gameui to delete us, or things get messy
  55. SetAutoDelete( false );
  56. SetMoveable( false );
  57. SetSizeable( false );
  58. vgui::HScheme scheme = vgui::scheme()->LoadSchemeFromFileEx( enginevgui->GetPanel( PANEL_CLIENTDLL ), "resource/ClientScheme.res", "ClientScheme");
  59. SetScheme(scheme);
  60. SetProportional( true );
  61. // Character loadouts
  62. m_pLoadoutPanel = new CCharInfoLoadoutSubPanel(this);
  63. m_pLoadoutPanel->AddActionSignalTarget( this );
  64. AddPage( m_pLoadoutPanel, "#Loadout");
  65. // Stat summary
  66. CTFStatsSummaryPanel *pStatSummaryPanel = new CTFStatsSummaryPanel(this);
  67. pStatSummaryPanel->SetupForEmbedded();
  68. AddPage( pStatSummaryPanel, "#Stats");
  69. CTFStatPanel *pStatPanel = GET_HUDELEMENT( CTFStatPanel );
  70. if ( pStatPanel )
  71. {
  72. // Ask for our embedded stat summary be updated immediately
  73. pStatPanel->UpdateStatSummaryPanel();
  74. }
  75. // Achievements
  76. //AddPage(new CCharacterInfoSubAchievements(this), "#Achievements");
  77. ListenForGameEvent( "gameui_hidden" );
  78. m_pLoadoutPanel->SetVisible( false );
  79. m_pNotificationsPresentPanel = NULL;
  80. m_bPreventClosure = false;
  81. m_iClosePanel = ECONUI_BASEUI;
  82. m_iDefaultTeam = TF_TEAM_RED;
  83. }
  84. //-----------------------------------------------------------------------------
  85. // Purpose:
  86. //-----------------------------------------------------------------------------
  87. CCharacterInfoPanel::~CCharacterInfoPanel()
  88. {
  89. }
  90. //-----------------------------------------------------------------------------
  91. // Purpose:
  92. //-----------------------------------------------------------------------------
  93. void CCharacterInfoPanel::ApplySchemeSettings( vgui::IScheme *pScheme )
  94. {
  95. BaseClass::ApplySchemeSettings( pScheme );
  96. LoadControlSettings( "Resource/UI/CharInfoPanel.res" );
  97. SetOKButtonVisible(false);
  98. SetCancelButtonVisible(false);
  99. m_pNotificationsPresentPanel = FindChildByName( "NotificationsPresentPanel" );
  100. }
  101. //-----------------------------------------------------------------------------
  102. // Purpose:
  103. //-----------------------------------------------------------------------------
  104. void CCharacterInfoPanel::PerformLayout( void )
  105. {
  106. if ( GetVParent() )
  107. {
  108. int w,h;
  109. vgui::ipanel()->GetSize( GetVParent(), w, h );
  110. SetBounds(0,0,w,h);
  111. }
  112. BaseClass::PerformLayout();
  113. }
  114. //-----------------------------------------------------------------------------
  115. // Purpose:
  116. //-----------------------------------------------------------------------------
  117. void CCharacterInfoPanel::ShowPanel(bool bShow)
  118. {
  119. m_bPreventClosure = false;
  120. // Keep the MM dashboard on top of us
  121. bShow ? GetMMDashboardParentManager()->PushModalFullscreenPopup( this )
  122. : GetMMDashboardParentManager()->PopModalFullscreenPopup( this );
  123. if ( bShow )
  124. {
  125. if ( GetPropertySheet()->GetActivePage() != m_pLoadoutPanel )
  126. {
  127. GetPropertySheet()->SetActivePage( m_pLoadoutPanel );
  128. }
  129. else
  130. {
  131. // VGUI doesn't tell the starting active page that it's active, so we post a pageshow to it
  132. ivgui()->PostMessage( m_pLoadoutPanel->GetVPanel(), new KeyValues("PageShow"), GetPropertySheet()->GetVPanel() );
  133. }
  134. //InvalidateLayout( false, true );
  135. Activate();
  136. int iClass = m_pLoadoutPanel->GetCurrentClassIndex();
  137. OpenLoadoutToClass( iClass, false );
  138. }
  139. else
  140. {
  141. PostMessage( m_pLoadoutPanel, new KeyValues("CancelSelection") );
  142. }
  143. bool bWasVisible = IsVisible() && m_pLoadoutPanel->IsVisible();
  144. SetVisible( bShow );
  145. if ( bWasVisible && !bShow )
  146. {
  147. m_pLoadoutPanel->OnCharInfoClosing();
  148. // Clear this out so it doesn't affect anything the next time the econ UI is opened
  149. m_iClosePanel = ECONUI_BASEUI;
  150. m_iDefaultTeam = TF_TEAM_RED;
  151. }
  152. m_pLoadoutPanel->SetVisible( bShow );
  153. // When we first appear, if we're on a server that couldn't get our loadout, show the failure dialog.
  154. if ( !bWasVisible && bShow )
  155. {
  156. if ( engine->IsInGame() )
  157. {
  158. C_TFPlayer *pLocal = C_TFPlayer::GetLocalTFPlayer();
  159. if ( pLocal && pLocal->m_Shared.IsLoadoutUnavailable() )
  160. {
  161. OpenServerNotConnectedToSteamDialog( this );
  162. }
  163. }
  164. }
  165. }
  166. //-----------------------------------------------------------------------------
  167. // Purpose:
  168. //-----------------------------------------------------------------------------
  169. void CCharacterInfoPanel::FireGameEvent( IGameEvent *event )
  170. {
  171. const char * type = event->GetName();
  172. if ( Q_strcmp(type, "gameui_hidden") == 0 )
  173. {
  174. if ( m_bPreventClosure )
  175. {
  176. engine->ClientCmd_Unrestricted( "gameui_activate" );
  177. }
  178. else
  179. {
  180. ShowPanel( false );
  181. }
  182. }
  183. }
  184. //-----------------------------------------------------------------------------
  185. // Purpose:
  186. //-----------------------------------------------------------------------------
  187. void CCharacterInfoPanel::Close()
  188. {
  189. ShowPanel( false );
  190. PostMessage( m_pLoadoutPanel, new KeyValues("CharInfoClosing") );
  191. // If we're connected to a game server, we also close the game UI.
  192. if ( engine->IsInGame() )
  193. {
  194. bool bClose = true;
  195. if ( m_bCheckForRoomOnExit )
  196. {
  197. // Check to make sure the player has room for all his items. If not, bring up the discard panel. Otherwise, go away.
  198. // We need to do this to catch players who used the "Change Loadout" button in the pickup panel, and may be out of room.
  199. bClose = !TFInventoryManager()->CheckForRoomAndForceDiscard();
  200. }
  201. if ( bClose )
  202. {
  203. engine->ClientCmd_Unrestricted( "gameui_hide" );
  204. }
  205. }
  206. // Notify any listeners that we're closed
  207. NotifyListenersOfCloseEvent();
  208. }
  209. //-----------------------------------------------------------------------------
  210. // Purpose:
  211. //-----------------------------------------------------------------------------
  212. void CCharacterInfoPanel::NotifyListenersOfCloseEvent()
  213. {
  214. FOR_EACH_VEC( m_vecOnCloseListeners, i )
  215. {
  216. if ( m_vecOnCloseListeners[i].Get() )
  217. {
  218. PostMessage( m_vecOnCloseListeners[i].Get(), new KeyValues( "EconUIClosed" ) );
  219. }
  220. }
  221. // Clear that motherfucker out
  222. m_vecOnCloseListeners.RemoveAll();
  223. }
  224. //-----------------------------------------------------------------------------
  225. // Purpose:
  226. //-----------------------------------------------------------------------------
  227. void CCharacterInfoPanel::OnCommand( const char *command )
  228. {
  229. if ( FStrEq( command, "back" ) )
  230. {
  231. // If we're at the base loadout page, or if we want to force it, close the dialog completely...
  232. // NOTE: Right now we don't support closing from the item selection screen.
  233. const int iShowingPanel = m_pLoadoutPanel->GetShowingPanel();
  234. const int iCurrentClassIndex = m_pLoadoutPanel->GetCurrentClassIndex();
  235. const bool bIsInSelectionPanel = iShowingPanel == CHAP_LOADOUT && m_pLoadoutPanel->GetClassLoadoutPanel()->IsInSelectionPanel();
  236. const bool bNoClass = iCurrentClassIndex == TF_CLASS_UNDEFINED;
  237. const bool bAtClosePanel = !bIsInSelectionPanel &&
  238. ( ( iShowingPanel == m_iClosePanel && bNoClass ) || ( iShowingPanel == CHAP_LOADOUT && -m_iClosePanel == iCurrentClassIndex ) );
  239. const bool bAtBaseLoadoutPage = iShowingPanel == CHAP_LOADOUT && bNoClass;
  240. if ( bAtClosePanel || bAtBaseLoadoutPage )
  241. {
  242. Close();
  243. }
  244. // In the item selection panel?
  245. else if ( bIsInSelectionPanel )
  246. {
  247. m_pLoadoutPanel->GetClassLoadoutPanel()->GetItemSelectionPanel()->OnBackPressed();
  248. }
  249. // In any other panel, just go back.
  250. else
  251. {
  252. ShowPanel( true );
  253. }
  254. }
  255. else
  256. {
  257. engine->ClientCmd( const_cast<char *>( command ) );
  258. }
  259. BaseClass::OnCommand( command );
  260. }
  261. //-----------------------------------------------------------------------------
  262. // Purpose:
  263. //-----------------------------------------------------------------------------
  264. void CCharacterInfoPanel::OpenLoadoutToClass( int iClassIndex, bool bOpenClassLoadout )
  265. {
  266. Assert(iClassIndex >= TF_CLASS_UNDEFINED && iClassIndex < TF_CLASS_COUNT);
  267. m_pLoadoutPanel->SetClassIndex( iClassIndex, bOpenClassLoadout );
  268. m_pLoadoutPanel->SetTeamIndex( m_iDefaultTeam );
  269. }
  270. //-----------------------------------------------------------------------------
  271. // Purpose:
  272. //-----------------------------------------------------------------------------
  273. void CCharacterInfoPanel::OpenLoadoutToBackpack( void )
  274. {
  275. m_pLoadoutPanel->OpenToBackpack();
  276. }
  277. //-----------------------------------------------------------------------------
  278. // Purpose:
  279. //-----------------------------------------------------------------------------
  280. void CCharacterInfoPanel::OpenLoadoutToCrafting( void )
  281. {
  282. m_pLoadoutPanel->OpenToCrafting();
  283. }
  284. //-----------------------------------------------------------------------------
  285. // Purpose:
  286. //-----------------------------------------------------------------------------
  287. void CCharacterInfoPanel::OpenLoadoutToArmory( void )
  288. {
  289. m_pLoadoutPanel->OpenToArmory();
  290. }
  291. //-----------------------------------------------------------------------------
  292. // Purpose:
  293. //-----------------------------------------------------------------------------
  294. void CCharacterInfoPanel::OnOpenArmoryDirect( KeyValues *data )
  295. {
  296. int iItemDef = data->GetInt( "itemdef", 0 );
  297. m_pLoadoutPanel->OpenToArmory( iItemDef );
  298. }
  299. //-----------------------------------------------------------------------------
  300. // Purpose:
  301. //-----------------------------------------------------------------------------
  302. void CCharacterInfoPanel::OnKeyCodeTyped(vgui::KeyCode code)
  303. {
  304. if ( code == KEY_ESCAPE )
  305. {
  306. if ( !m_bPreventClosure )
  307. {
  308. OnCommand( "back" );
  309. }
  310. }
  311. else
  312. {
  313. BaseClass::OnKeyCodeTyped( code );
  314. }
  315. }
  316. //-----------------------------------------------------------------------------
  317. // Purpose:
  318. //-----------------------------------------------------------------------------
  319. void CCharacterInfoPanel::OnKeyCodePressed(vgui::KeyCode code)
  320. {
  321. ButtonCode_t nButtonCode = GetBaseButtonCode( code );
  322. if ( nButtonCode == KEY_XBUTTON_B )
  323. {
  324. if ( !m_bPreventClosure )
  325. {
  326. OnCommand( "back" );
  327. }
  328. }
  329. else
  330. {
  331. BaseClass::OnKeyCodePressed( code );
  332. }
  333. }
  334. //-----------------------------------------------------------------------------
  335. // Purpose:
  336. //-----------------------------------------------------------------------------
  337. void CCharacterInfoPanel::OnThink()
  338. {
  339. bool bShouldBeVisible = NotificationQueue_GetNumNotifications() != 0;
  340. if ( m_pNotificationsPresentPanel != NULL && m_pNotificationsPresentPanel->IsVisible() != bShouldBeVisible )
  341. {
  342. m_pNotificationsPresentPanel->SetVisible( bShouldBeVisible );
  343. if ( bShouldBeVisible )
  344. {
  345. g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( this, "NotificationsPresentBlink" );
  346. }
  347. else
  348. {
  349. g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( this, "NotificationsPresentBlinkStop" );
  350. }
  351. }
  352. }
  353. //-----------------------------------------------------------------------------
  354. // Purpose:
  355. //-----------------------------------------------------------------------------
  356. IEconRootUI *CCharacterInfoPanel::OpenEconUI( int iDirectToPage, bool bCheckForInventorySpaceOnExit )
  357. {
  358. engine->ClientCmd_Unrestricted( "gameui_activate" );
  359. ShowPanel( true );
  360. if ( iDirectToPage == ECONUI_BACKPACK )
  361. {
  362. OpenLoadoutToBackpack();
  363. }
  364. else if ( iDirectToPage == ECONUI_CRAFTING )
  365. {
  366. OpenLoadoutToCrafting();
  367. }
  368. else if ( iDirectToPage == ECONUI_ARMORY )
  369. {
  370. OpenLoadoutToArmory();
  371. }
  372. else if ( iDirectToPage < 0 )
  373. {
  374. // Negative numbers go directly to the class loadout
  375. OpenLoadoutToClass( -(iDirectToPage), true );
  376. }
  377. SetCheckForRoomOnExit( bCheckForInventorySpaceOnExit );
  378. return this;
  379. }
  380. //-----------------------------------------------------------------------------
  381. // Purpose:
  382. //-----------------------------------------------------------------------------
  383. void CCharacterInfoPanel::CloseEconUI( void )
  384. {
  385. if ( IsVisible() )
  386. {
  387. ShowPanel( false );
  388. NotifyListenersOfCloseEvent();
  389. }
  390. }
  391. //-----------------------------------------------------------------------------
  392. // Purpose:
  393. //-----------------------------------------------------------------------------
  394. bool CCharacterInfoPanel::IsUIPanelVisible( EconBaseUIPanels_t iPanel )
  395. {
  396. if ( !IsVisible() )
  397. return false;
  398. switch ( iPanel )
  399. {
  400. case ECONUI_BACKPACK:
  401. return (GetBackpackPanel() && GetBackpackPanel()->IsVisible());
  402. case ECONUI_CRAFTING:
  403. return (GetCraftingPanel() && GetCraftingPanel()->IsVisible());
  404. case ECONUI_ARMORY:
  405. return (GetArmoryPanel() && GetArmoryPanel()->IsVisible());
  406. case ECONUI_TRADING:
  407. break;
  408. default:
  409. Assert(0);
  410. break;
  411. }
  412. return false;
  413. }
  414. //-----------------------------------------------------------------------------
  415. // Purpose:
  416. //-----------------------------------------------------------------------------
  417. void Open_CharInfo( const CCommand &args )
  418. {
  419. EconUI()->OpenEconUI();
  420. }
  421. ConCommand open_charinfo( "open_charinfo", Open_CharInfo, "Open the character info panel", FCVAR_NONE );
  422. void CCharacterInfoPanel::SetPreventClosure( bool bPrevent )
  423. {
  424. m_bPreventClosure = bPrevent;
  425. Panel* pBackButton = FindChildByName( "BackButton" );
  426. if ( pBackButton )
  427. {
  428. pBackButton->SetEnabled( !bPrevent );
  429. }
  430. }
  431. //-----------------------------------------------------------------------------
  432. // Purpose:
  433. //-----------------------------------------------------------------------------
  434. void Open_CharInfoDirect( const CCommand &args )
  435. {
  436. // If we're in-game, start by opening the class we're currently playing
  437. int iClass = TF_CLASS_UNDEFINED;
  438. if ( engine->IsInGame() )
  439. {
  440. C_TFPlayer *pLocal = C_TFPlayer::GetLocalTFPlayer();
  441. if ( pLocal )
  442. {
  443. iClass = -(pLocal->m_Shared.GetDesiredPlayerClassIndex());
  444. if ( iClass == TF_CLASS_UNDEFINED )
  445. {
  446. iClass = -(pLocal->GetPlayerClass()->GetClassIndex());
  447. }
  448. }
  449. }
  450. // override with command arg
  451. if ( args.ArgC() > 1 )
  452. {
  453. iClass = -atoi( args.Arg( 1 ) );
  454. }
  455. EconUI()->OpenEconUI( iClass );
  456. }
  457. ConCommand open_charinfo_direct( "open_charinfo_direct", Open_CharInfoDirect, "Open the character info panel directly to the class you're currently playing.", FCVAR_NONE );
  458. //-----------------------------------------------------------------------------
  459. // Purpose:
  460. //-----------------------------------------------------------------------------
  461. void Open_CharInfoBackpack( const CCommand &args )
  462. {
  463. EconUI()->OpenEconUI( ECONUI_BACKPACK );
  464. }
  465. ConCommand open_charinfo_backpack( "open_charinfo_backpack", Open_CharInfoBackpack, "Open the character info panel directly to backpack.", FCVAR_NONE );
  466. //-----------------------------------------------------------------------------
  467. // Purpose:
  468. //-----------------------------------------------------------------------------
  469. void Open_CharInfoCrafting( const CCommand &args )
  470. {
  471. EconUI()->OpenEconUI( ECONUI_CRAFTING );
  472. }
  473. ConCommand open_charinfo_crafting( "open_charinfo_crafting", Open_CharInfoCrafting, "Open the character info panel directly to crafting screen.", FCVAR_NONE );
  474. //-----------------------------------------------------------------------------
  475. // Purpose:
  476. //-----------------------------------------------------------------------------
  477. void Open_CharInfoArmory( const CCommand &args )
  478. {
  479. EconUI()->OpenEconUI( ECONUI_ARMORY );
  480. }
  481. ConCommand open_charinfo_armory( "open_charinfo_armory", Open_CharInfoArmory, "Open the character info panel directly to armory.", FCVAR_NONE );
  482. //================================================================================================================================
  483. // NOT CONNECTED TO STEAM WARNING DIALOG
  484. //================================================================================================================================
  485. static vgui::DHANDLE<CServerNotConnectedToSteamDialog> g_ServerNotConnectedPanel;
  486. //-----------------------------------------------------------------------------
  487. // Purpose:
  488. //-----------------------------------------------------------------------------
  489. CServerNotConnectedToSteamDialog::CServerNotConnectedToSteamDialog( vgui::Panel *pParent, const char *pElementName ) : BaseClass( pParent, "ServerNotConnectedToSteamDialog" )
  490. {
  491. }
  492. //-----------------------------------------------------------------------------
  493. // Purpose:
  494. //-----------------------------------------------------------------------------
  495. void CServerNotConnectedToSteamDialog::ApplySchemeSettings( IScheme *pScheme )
  496. {
  497. BaseClass::ApplySchemeSettings( pScheme );
  498. // load control settings...
  499. LoadControlSettings( "resource/UI/ServerNotConnectedToSteam.res" );
  500. }
  501. //-----------------------------------------------------------------------------
  502. // Purpose:
  503. //-----------------------------------------------------------------------------
  504. void CServerNotConnectedToSteamDialog::OnCommand( const char *command )
  505. {
  506. if ( !Q_stricmp( command, "close" ) )
  507. {
  508. TFModalStack()->PopModal( this );
  509. SetVisible( false );
  510. return;
  511. }
  512. BaseClass::OnCommand( command );
  513. }
  514. //-----------------------------------------------------------------------------
  515. // Purpose:
  516. //-----------------------------------------------------------------------------
  517. CServerNotConnectedToSteamDialog *OpenServerNotConnectedToSteamDialog( vgui::Panel *pParent )
  518. {
  519. if (!g_ServerNotConnectedPanel.Get())
  520. {
  521. g_ServerNotConnectedPanel = vgui::SETUP_PANEL( new CServerNotConnectedToSteamDialog( pParent, NULL ) );
  522. }
  523. g_ServerNotConnectedPanel->InvalidateLayout( false, true );
  524. g_ServerNotConnectedPanel->SetVisible( true );
  525. g_ServerNotConnectedPanel->MakePopup();
  526. g_ServerNotConnectedPanel->MoveToFront();
  527. g_ServerNotConnectedPanel->SetKeyBoardInputEnabled(true);
  528. g_ServerNotConnectedPanel->SetMouseInputEnabled(true);
  529. TFModalStack()->PushModal( g_ServerNotConnectedPanel );
  530. return g_ServerNotConnectedPanel;
  531. }
  532. //-----------------------------------------------------------------------------
  533. // Purpose:
  534. //-----------------------------------------------------------------------------
  535. CBackpackPanel *CCharacterInfoPanel::GetBackpackPanel( void )
  536. {
  537. return m_pLoadoutPanel->GetBackpackPanel();
  538. }
  539. //-----------------------------------------------------------------------------
  540. // Purpose:
  541. //-----------------------------------------------------------------------------
  542. CCraftingPanel *CCharacterInfoPanel::GetCraftingPanel( void )
  543. {
  544. return m_pLoadoutPanel->GetCraftingPanel();
  545. }
  546. //-----------------------------------------------------------------------------
  547. // Purpose:
  548. //-----------------------------------------------------------------------------
  549. CArmoryPanel *CCharacterInfoPanel::GetArmoryPanel( void )
  550. {
  551. return m_pLoadoutPanel->GetArmoryPanel();
  552. }
  553. //-----------------------------------------------------------------------------
  554. // Purpose:
  555. //-----------------------------------------------------------------------------
  556. void CCharacterInfoPanel::Gamestats_ItemTransaction( int eventID, CEconItemView *item, const char *pszReason, int iQuality )
  557. {
  558. C_CTF_GameStats.Event_ItemTransaction( eventID, item, pszReason, iQuality );
  559. }
  560. //-----------------------------------------------------------------------------
  561. // Purpose:
  562. //-----------------------------------------------------------------------------
  563. void CCharacterInfoPanel::Gamestats_Store( int eventID, CEconItemView* item, const char* panelName, int classId,
  564. const cart_item_t* cartItem, int checkoutAttempts, const char* storeError, int totalPrice, int currencyCode )
  565. {
  566. C_CTF_GameStats.Event_Store( eventID, item, panelName, classId, cartItem, checkoutAttempts, storeError, totalPrice, currencyCode );
  567. }
  568. //-----------------------------------------------------------------------------
  569. // Purpose:
  570. //-----------------------------------------------------------------------------
  571. void CCharacterInfoPanel::SetExperimentValue( uint64 experimentValue )
  572. {
  573. C_CTF_GameStats.SetExperimentValue( experimentValue );
  574. }
  575. static vgui::DHANDLE<CTFItemPickupPanel> g_TFItemPickupPanel;
  576. static vgui::DHANDLE<CTFItemDiscardPanel> g_TFItemDiscardPanel;
  577. //-----------------------------------------------------------------------------
  578. // Purpose:
  579. //-----------------------------------------------------------------------------
  580. CItemPickupPanel *CCharacterInfoPanel::OpenItemPickupPanel( void )
  581. {
  582. if (!g_TFItemPickupPanel.Get())
  583. {
  584. g_TFItemPickupPanel = vgui::SETUP_PANEL( new CTFItemPickupPanel( NULL ) );
  585. g_TFItemPickupPanel->InvalidateLayout( false, true );
  586. }
  587. engine->ClientCmd_Unrestricted( "gameui_activate" );
  588. g_TFItemPickupPanel->ShowPanel( true );
  589. return g_TFItemPickupPanel;
  590. }
  591. //-----------------------------------------------------------------------------
  592. // Purpose:
  593. //-----------------------------------------------------------------------------
  594. CItemDiscardPanel *CCharacterInfoPanel::OpenItemDiscardPanel( void )
  595. {
  596. if (!g_TFItemDiscardPanel.Get())
  597. {
  598. g_TFItemDiscardPanel = vgui::SETUP_PANEL( new CTFItemDiscardPanel( NULL ) );
  599. g_TFItemDiscardPanel->InvalidateLayout( false, true );
  600. }
  601. engine->ClientCmd_Unrestricted( "gameui_activate" );
  602. g_TFItemDiscardPanel->ShowPanel( true );
  603. return g_TFItemDiscardPanel;
  604. }
  605. static vgui::DHANDLE<CTFBaseStorePanel> g_StorePanel;
  606. //-----------------------------------------------------------------------------
  607. // Purpose:
  608. //-----------------------------------------------------------------------------
  609. void CCharacterInfoPanel::CreateStorePanel( void )
  610. {
  611. // Clean up previous store panel?
  612. if ( g_StorePanel.Get() != NULL )
  613. {
  614. g_StorePanel->MarkForDeletion();
  615. }
  616. // Create the store panel
  617. CTFBaseStorePanel *pStorePanel = NULL;
  618. if ( ShouldUseNewStore() )
  619. {
  620. pStorePanel = new CTFStorePanel2( NULL );
  621. }
  622. else
  623. {
  624. pStorePanel = new CTFStorePanel1( NULL );
  625. }
  626. g_StorePanel = vgui::SETUP_PANEL( pStorePanel );
  627. }
  628. //-----------------------------------------------------------------------------
  629. // Purpose:
  630. //-----------------------------------------------------------------------------
  631. CStorePanel *CCharacterInfoPanel::OpenStorePanel( int iItemDef, bool bAddToCart )
  632. {
  633. // Make sure we've got the appropriate connections to Steam
  634. if ( !steamapicontext || !steamapicontext->SteamUtils() )
  635. {
  636. OpenStoreStatusDialog( NULL, "#StoreUpdate_SteamRequired", true, false );
  637. return NULL;
  638. }
  639. if ( !steamapicontext->SteamUtils()->IsOverlayEnabled() )
  640. {
  641. OpenStoreStatusDialog( NULL, "#StoreUpdate_OverlayRequired", true, false );
  642. return NULL;
  643. }
  644. if ( !CStorePanel::IsPricesheetLoaded() )
  645. {
  646. OpenStoreStatusDialog( NULL, "#StoreUpdate_Loading", false, false );
  647. CStorePanel::SetShouldShowWarnings( true );
  648. CStorePanel::RequestPricesheet();
  649. return NULL;
  650. }
  651. if ( !g_StorePanel )
  652. return NULL;
  653. engine->ClientCmd_Unrestricted( "gameui_activate" );
  654. if ( iItemDef )
  655. {
  656. g_StorePanel->StartAtItemDef( iItemDef, bAddToCart );
  657. }
  658. g_StorePanel->ShowPanel( true );
  659. return g_StorePanel;
  660. }
  661. //-----------------------------------------------------------------------------
  662. // Purpose:
  663. //-----------------------------------------------------------------------------
  664. CStorePanel *CCharacterInfoPanel::GetStorePanel( void )
  665. {
  666. return g_StorePanel;
  667. }
  668. //-----------------------------------------------------------------------------
  669. // Purpose:
  670. //-----------------------------------------------------------------------------
  671. void CCharacterInfoPanel::AddPanelCloseListener( vgui::Panel *pListener )
  672. {
  673. if ( !pListener )
  674. return;
  675. VPanelHandle hPanel;
  676. hPanel.Set( pListener->GetVPanel() );
  677. m_vecOnCloseListeners.AddToHead( hPanel );
  678. }
  679. //-----------------------------------------------------------------------------
  680. // Purpose:
  681. //-----------------------------------------------------------------------------
  682. void CCharacterInfoPanel::SetClosePanel( int iPanel )
  683. {
  684. AssertMsg( ( iPanel < 0 && IsValidTFPlayerClass( -iPanel ) ) ||
  685. ( iPanel >= ECONUI_FIRST_PANEL && iPanel <= ECONUI_LAST_PANEL ),
  686. "Panel out of range!"
  687. );
  688. m_iClosePanel = iPanel;
  689. }
  690. void CCharacterInfoPanel::SetDefaultTeam( int iTeam )
  691. {
  692. AssertMsg( iTeam == TF_TEAM_RED || iTeam == TF_TEAM_BLUE, "Invalid team" );
  693. m_iDefaultTeam = iTeam;
  694. }
  695. //================================================================================================================================
  696. // NOT CONNECTED TO STEAM WARNING DIALOG
  697. //================================================================================================================================
  698. static vgui::DHANDLE<CCheatDetectionDialog> g_CheatDetectionDialog;
  699. //-----------------------------------------------------------------------------
  700. // Purpose:
  701. //-----------------------------------------------------------------------------
  702. CCheatDetectionDialog::CCheatDetectionDialog( vgui::Panel *pParent, const char *pElementName ) : BaseClass( pParent, "CheatDetectionDialog" )
  703. {
  704. }
  705. //-----------------------------------------------------------------------------
  706. // Purpose:
  707. //-----------------------------------------------------------------------------
  708. void CCheatDetectionDialog::ApplySchemeSettings( IScheme *pScheme )
  709. {
  710. BaseClass::ApplySchemeSettings( pScheme );
  711. // load control settings...
  712. LoadControlSettings( "resource/UI/CheatDetectionDialog.res" );
  713. }
  714. //-----------------------------------------------------------------------------
  715. // Purpose:
  716. //-----------------------------------------------------------------------------
  717. void CCheatDetectionDialog::OnCommand( const char *command )
  718. {
  719. if ( !Q_stricmp( command, "close" ) )
  720. {
  721. TFModalStack()->PopModal( this );
  722. SetVisible( false );
  723. return;
  724. }
  725. BaseClass::OnCommand( command );
  726. }
  727. //-----------------------------------------------------------------------------
  728. // Purpose:
  729. //-----------------------------------------------------------------------------
  730. CCheatDetectionDialog *OpenCheatDetectionDialog( vgui::Panel *pParent, const char *pszCheatMessage )
  731. {
  732. if (!g_CheatDetectionDialog.Get())
  733. {
  734. g_CheatDetectionDialog = vgui::SETUP_PANEL( new CCheatDetectionDialog( pParent, NULL ) );
  735. }
  736. g_CheatDetectionDialog->InvalidateLayout( false, true );
  737. g_CheatDetectionDialog->SetVisible( true );
  738. g_CheatDetectionDialog->MakePopup();
  739. g_CheatDetectionDialog->MoveToFront();
  740. g_CheatDetectionDialog->SetKeyBoardInputEnabled(true);
  741. g_CheatDetectionDialog->SetMouseInputEnabled(true);
  742. TFModalStack()->PushModal( g_CheatDetectionDialog );
  743. g_CheatDetectionDialog->SetDialogVariable( "reason", g_pVGuiLocalize->Find( pszCheatMessage ) );
  744. return g_CheatDetectionDialog;
  745. }