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.

713 lines
20 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include <vgui/ILocalize.h>
  8. #include "vgui_controls/TextEntry.h"
  9. #include "trading_start_dialog.h"
  10. #include "econ_controls.h"
  11. #include "econ_trading.h"
  12. #include "c_playerresource.h"
  13. #include "gcsdk/gcmsg.h"
  14. #include "econ_item_inventory.h"
  15. #include "econ_gcmessages.h"
  16. #include "gc_clientsystem.h"
  17. // memdbgon must be the last include file in a .cpp file!!!
  18. #include <tier0/memdbgon.h>
  19. //-----------------------------------------------------------------------------
  20. // Purpose:
  21. //-----------------------------------------------------------------------------
  22. CTradingStartDialog::CTradingStartDialog( vgui::Panel *parent ) : vgui::EditablePanel( parent, "TradingStartDialog" )
  23. {
  24. m_pSelectFromServerButton = NULL;
  25. m_pCancelButton = NULL;
  26. m_pButtonKV = NULL;
  27. m_bReapplyButtonKVs = false;
  28. m_pURLFailLabel = NULL;
  29. m_pURLSearchingLabel = NULL;
  30. for ( int i = 0; i < TDS_NUM_STATES; i++ )
  31. {
  32. m_pStatePanels[i] = new vgui::EditablePanel( this, VarArgs("StatePanel%d",i) );
  33. }
  34. m_pPlayerList = new vgui::EditablePanel( this, "PlayerList" );
  35. m_pPlayerListScroller = new vgui::ScrollableEditablePanel( this, m_pPlayerList, "PlayerListScroller" );
  36. ListenForGameEvent( "gameui_hidden" );
  37. Reset();
  38. }
  39. //-----------------------------------------------------------------------------
  40. // Purpose:
  41. //-----------------------------------------------------------------------------
  42. CTradingStartDialog::~CTradingStartDialog( void )
  43. {
  44. if ( m_pButtonKV )
  45. {
  46. m_pButtonKV->deleteThis();
  47. m_pButtonKV = NULL;
  48. }
  49. }
  50. //-----------------------------------------------------------------------------
  51. // Purpose:
  52. //-----------------------------------------------------------------------------
  53. void CTradingStartDialog::Reset( void )
  54. {
  55. m_iCurrentState = TDS_SELECTING_PLAYER;
  56. m_bGiftMode = false;
  57. m_giftItem = CEconItemView();
  58. }
  59. //-----------------------------------------------------------------------------
  60. // Purpose:
  61. //-----------------------------------------------------------------------------
  62. void CTradingStartDialog::ApplySettings( KeyValues *inResourceData )
  63. {
  64. BaseClass::ApplySettings( inResourceData );
  65. KeyValues *pItemKV = inResourceData->FindKey( "button_kv" );
  66. if ( pItemKV )
  67. {
  68. if ( m_pButtonKV )
  69. {
  70. m_pButtonKV->deleteThis();
  71. }
  72. m_pButtonKV = new KeyValues("button_kv");
  73. pItemKV->CopySubkeys( m_pButtonKV );
  74. m_bReapplyButtonKVs = true;
  75. }
  76. }
  77. //-----------------------------------------------------------------------------
  78. // Purpose:
  79. //-----------------------------------------------------------------------------
  80. void CTradingStartDialog::ApplySchemeSettings( vgui::IScheme *pScheme )
  81. {
  82. BaseClass::ApplySchemeSettings( pScheme );
  83. LoadControlSettings( "resource/ui/econ/TradingStartDialog.res" );
  84. m_pCancelButton = dynamic_cast<CExButton*>( FindChildByName( "CancelButton" ) );
  85. // Find all the sub buttons, and set their action signals to point to this panel
  86. for ( int i = 0; i < TDS_NUM_STATES; i++ )
  87. {
  88. int iButton = 0;
  89. CExButton *pButton = NULL;
  90. do
  91. {
  92. pButton = dynamic_cast<CExButton*>( m_pStatePanels[i]->FindChildByName( VarArgs("subbutton%d",iButton)) );
  93. if ( pButton )
  94. {
  95. pButton->AddActionSignalTarget( this );
  96. // The second button on the first state is the server button
  97. if ( iButton == 1 )
  98. {
  99. m_pSelectFromServerButton = pButton;
  100. }
  101. iButton++;
  102. }
  103. } while (pButton);
  104. }
  105. m_pURLFailLabel = dynamic_cast<vgui::Label*>( m_pStatePanels[TDS_SELECTING_FROM_PROFILE]->FindChildByName( "URLFailLabel" ) );
  106. m_pURLSearchingLabel = dynamic_cast<vgui::Label*>( m_pStatePanels[TDS_SELECTING_FROM_PROFILE]->FindChildByName( "URLSearchingLabel" ) );
  107. UpdateState();
  108. }
  109. //-----------------------------------------------------------------------------
  110. // Purpose:
  111. //-----------------------------------------------------------------------------
  112. void CTradingStartDialog::PerformLayout( void )
  113. {
  114. BaseClass::PerformLayout();
  115. // Layout the player list buttons
  116. if ( m_pPlayerPanels.Count() )
  117. {
  118. int iButtonH = m_pPlayerPanels[0]->GetTall() + YRES(2);
  119. m_pPlayerList->SetSize( m_pPlayerList->GetWide(), YRES(2) + (iButtonH * m_pPlayerPanels.Count()) );
  120. // These need to all be layout-complete before we can position the player panels,
  121. // because the scrollbar will cause the playerlist entries to move when it lays out.
  122. m_pPlayerList->InvalidateLayout( true );
  123. m_pPlayerListScroller->InvalidateLayout( true );
  124. m_pPlayerListScroller->GetScrollbar()->InvalidateLayout( true );
  125. for ( int i = 0; i < m_pPlayerPanels.Count(); i++ )
  126. {
  127. m_pPlayerPanels[i]->SetPos( 0, YRES(2) + (iButtonH * i) );
  128. }
  129. }
  130. }
  131. //-----------------------------------------------------------------------------
  132. // Purpose:
  133. //-----------------------------------------------------------------------------
  134. void CTradingStartDialog::FireGameEvent( IGameEvent *event )
  135. {
  136. const char *type = event->GetName();
  137. if ( Q_strcmp(type, "gameui_hidden") == 0 )
  138. {
  139. Close();
  140. }
  141. }
  142. //-----------------------------------------------------------------------------
  143. // Purpose:
  144. //-----------------------------------------------------------------------------
  145. void CTradingStartDialog::Close( void )
  146. {
  147. TFModalStack()->PopModal( this );
  148. SetVisible( false );
  149. MarkForDeletion();
  150. PostMessage( GetParent(), new KeyValues("CancelSelection") );
  151. }
  152. //-----------------------------------------------------------------------------
  153. // Purpose:
  154. //-----------------------------------------------------------------------------
  155. void CTradingStartDialog::OnCommand( const char *command )
  156. {
  157. if ( !Q_stricmp( command, "cancel" ) )
  158. {
  159. if ( m_iCurrentState != TDS_SELECTING_PLAYER )
  160. {
  161. m_iCurrentState = TDS_SELECTING_PLAYER;
  162. UpdateState();
  163. return;
  164. }
  165. Close();
  166. return;
  167. }
  168. else if ( !Q_stricmp( command, "friends" ) )
  169. {
  170. m_iCurrentState = TDS_SELECTING_FROM_FRIENDS;
  171. UpdateState();
  172. return;
  173. }
  174. else if ( !Q_stricmp( command, "server" ) )
  175. {
  176. m_iCurrentState = TDS_SELECTING_FROM_SERVER;
  177. UpdateState();
  178. return;
  179. }
  180. else if ( !Q_stricmp( command, "profile" ) )
  181. {
  182. m_iCurrentState = TDS_SELECTING_FROM_PROFILE;
  183. UpdateState();
  184. return;
  185. }
  186. else if ( !Q_strnicmp( command, "select_player", 13 ) )
  187. {
  188. int iPlayer = atoi( command + 13 ) - 1;
  189. if ( iPlayer >= 0 && iPlayer < m_PlayerInfoList.Count() )
  190. {
  191. StartTradeWith( m_PlayerInfoList[iPlayer].m_steamID );
  192. }
  193. return;
  194. }
  195. else if ( !Q_stricmp( command, "url_ok" ) )
  196. {
  197. vgui::TextEntry *pEntry = dynamic_cast<vgui::TextEntry*>( m_pStatePanels[m_iCurrentState]->FindChildByName("URLEntry") );
  198. if ( pEntry )
  199. {
  200. const int maxURLLength = 512;
  201. char inputURL[ maxURLLength ];
  202. pEntry->GetText( inputURL, maxURLLength );
  203. if ( m_pURLSearchingLabel )
  204. {
  205. m_pURLSearchingLabel->SetVisible( false );
  206. }
  207. bool bSuccess = ExtractSteamIDFromURL( inputURL );
  208. if ( m_pURLFailLabel )
  209. {
  210. m_pURLFailLabel->SetVisible( !bSuccess );
  211. }
  212. }
  213. return;
  214. }
  215. BaseClass::OnCommand( command );
  216. }
  217. //-----------------------------------------------------------------------------
  218. // Purpose:
  219. //-----------------------------------------------------------------------------
  220. void CTradingStartDialog::SendGiftTo( CSteamID steamID )
  221. {
  222. Trading_SendGift( steamID, m_giftItem );
  223. }
  224. //-----------------------------------------------------------------------------
  225. // Purpose:
  226. //-----------------------------------------------------------------------------
  227. void CTradingStartDialog::StartTradeWith( CSteamID steamID )
  228. {
  229. m_iCurrentState = TDS_SELECTING_PLAYER;
  230. OnCommand( "cancel" );
  231. if ( !m_bGiftMode )
  232. {
  233. Trading_RequestTrade( steamID );
  234. return;
  235. }
  236. Trading_SendGift( steamID, m_giftItem );
  237. }
  238. //-----------------------------------------------------------------------------
  239. // Purpose:
  240. //-----------------------------------------------------------------------------
  241. bool CTradingStartDialog::ExtractSteamIDFromURL( char *inputURL )
  242. {
  243. if ( !inputURL || !inputURL[0] )
  244. return false;
  245. EUniverse localUniverse = GetUniverse();
  246. if ( localUniverse == k_EUniverseInvalid )
  247. return false;
  248. CSteamID steamID;
  249. int iLen = Q_strlen(inputURL);
  250. // First, see if it's a profile link. If it is, clip the SteamID from it.
  251. const char *pszProfilePrepend = ( localUniverse == k_EUniversePublic ) ? "http://steamcommunity.com/profiles/" : "http://beta.steamcommunity.com/profiles/";
  252. int iProfilePrependLen = Q_strlen(pszProfilePrepend);
  253. if ( Q_strnicmp( pszProfilePrepend, inputURL, iProfilePrependLen ) == 0 )
  254. {
  255. if ( iLen > iProfilePrependLen )
  256. {
  257. steamID.SetFromString( &inputURL[iProfilePrependLen], localUniverse );
  258. if ( steamID.IsValid() )
  259. {
  260. StartTradeWith( steamID );
  261. return true;
  262. }
  263. }
  264. }
  265. else
  266. {
  267. // If it's an id link, we download it and extract the steam ID from it.
  268. const char *pszIDPrepend = ( localUniverse == k_EUniversePublic ) ? "http://steamcommunity.com/id/" : "http://beta.steamcommunity.com/id/";
  269. int iIDPrependLen = Q_strlen(pszIDPrepend);
  270. if ( Q_strnicmp( pszIDPrepend, inputURL, iIDPrependLen ) == 0 )
  271. {
  272. if ( iLen > iIDPrependLen )
  273. {
  274. // Trim off a trailing slash
  275. if ( inputURL[iLen-1] == '/' || inputURL[iLen-1] == '\\' )
  276. {
  277. inputURL[iLen-1] = '\0';
  278. }
  279. GCSDK::CGCMsg<MsgGCLookupAccount_t> msg( k_EMsgGCLookupAccount );
  280. msg.Body().m_uiFindType = GCSDK::k_EFindAccountTypeURL;
  281. msg.AddStrData( &inputURL[iIDPrependLen] );
  282. GCClientSystem()->BSendMessage( msg );
  283. // For now, return true and wait.
  284. if ( m_pURLSearchingLabel )
  285. {
  286. m_pURLSearchingLabel->SetVisible( true );
  287. }
  288. return true;
  289. }
  290. }
  291. }
  292. return false;
  293. }
  294. //-----------------------------------------------------------------------------
  295. // Purpose:
  296. //-----------------------------------------------------------------------------
  297. void CTradingStartDialog::OnLookupAccountResponse( uint64 iAccountID )
  298. {
  299. if ( m_pURLSearchingLabel )
  300. {
  301. m_pURLSearchingLabel->SetVisible( false );
  302. }
  303. CSteamID steamID( iAccountID );
  304. if ( steamID.IsValid() )
  305. {
  306. if ( m_pURLFailLabel )
  307. {
  308. m_pURLFailLabel->SetVisible( false );
  309. }
  310. StartTradeWith( steamID );
  311. }
  312. else
  313. {
  314. if ( m_pURLFailLabel )
  315. {
  316. m_pURLFailLabel->SetVisible( true );
  317. }
  318. }
  319. }
  320. //-----------------------------------------------------------------------------
  321. // Purpose: Sets a gift for the dialog to hand out. If pGiftItem is NULL, which is
  322. // fine, make sure to clear our our own existing gift.
  323. //-----------------------------------------------------------------------------
  324. void CTradingStartDialog::SetGift( CEconItemView* pGiftItem )
  325. {
  326. if ( pGiftItem )
  327. {
  328. m_giftItem = *pGiftItem;
  329. m_bGiftMode = true;
  330. }
  331. else
  332. {
  333. // Reset to default
  334. m_giftItem = CEconItemView();
  335. m_bGiftMode = false;
  336. }
  337. }
  338. //-----------------------------------------------------------------------------
  339. // Purpose:
  340. //-----------------------------------------------------------------------------
  341. void CTradingStartDialog::OnTextChanged( KeyValues *data )
  342. {
  343. vgui::TextEntry *pEntry = dynamic_cast<vgui::TextEntry*>( m_pStatePanels[m_iCurrentState]->FindChildByName("URLEntry") );
  344. if ( !pEntry )
  345. return;
  346. Panel *pPanel = reinterpret_cast<vgui::Panel *>( data->GetPtr("panel") );
  347. if ( pEntry == pPanel )
  348. {
  349. CExButton *pButton = dynamic_cast<CExButton*>( m_pStatePanels[m_iCurrentState]->FindChildByName( "subbutton0" ) );
  350. if ( pButton )
  351. {
  352. pButton->SetEnabled( pEntry->GetTextLength() > 0 );
  353. }
  354. if ( m_pURLFailLabel )
  355. {
  356. m_pURLFailLabel->SetVisible( false );
  357. }
  358. }
  359. }
  360. //-----------------------------------------------------------------------------
  361. // Purpose:
  362. //-----------------------------------------------------------------------------
  363. void CTradingStartDialog::UpdateState( void )
  364. {
  365. for ( int i = 0; i < TDS_NUM_STATES; i++ )
  366. {
  367. if ( !m_pStatePanels[i] )
  368. continue;
  369. m_pStatePanels[i]->SetVisible( m_iCurrentState == i );
  370. }
  371. if ( m_pSelectFromServerButton )
  372. {
  373. m_pSelectFromServerButton->SetEnabled( engine->IsInGame() );
  374. }
  375. if ( m_iCurrentState == TDS_SELECTING_PLAYER )
  376. {
  377. m_pCancelButton->SetText( g_pVGuiLocalize->Find( "#Cancel" ) );
  378. }
  379. else
  380. {
  381. m_pCancelButton->SetText( g_pVGuiLocalize->Find( "#TF_Back" ) );
  382. }
  383. switch ( m_iCurrentState )
  384. {
  385. case TDS_SELECTING_FROM_FRIENDS:
  386. SetupSelectFriends();
  387. break;
  388. case TDS_SELECTING_FROM_SERVER:
  389. SetupSelectServer();
  390. break;
  391. case TDS_SELECTING_FROM_PROFILE:
  392. SetupSelectProfile();
  393. break;
  394. case TDS_SELECTING_PLAYER:
  395. default:
  396. m_pPlayerListScroller->SetVisible( false );
  397. break;
  398. }
  399. }
  400. //-----------------------------------------------------------------------------
  401. // Purpose:
  402. //-----------------------------------------------------------------------------
  403. void CTradingStartDialog::SetupSelectFriends( void )
  404. {
  405. m_PlayerInfoList.Purge();
  406. if ( steamapicontext && steamapicontext->SteamFriends() )
  407. {
  408. // Get our game info so we can use that to test if our friends are connected to the same game as us
  409. FriendGameInfo_t myGameInfo;
  410. CSteamID mySteamID = steamapicontext->SteamUser()->GetSteamID();
  411. steamapicontext->SteamFriends()->GetFriendGamePlayed( mySteamID, &myGameInfo );
  412. int iFriends = steamapicontext->SteamFriends()->GetFriendCount( k_EFriendFlagImmediate );
  413. for ( int i = 0; i < iFriends; i++ )
  414. {
  415. CSteamID friendSteamID = steamapicontext->SteamFriends()->GetFriendByIndex( i, k_EFriendFlagImmediate );
  416. FriendGameInfo_t gameInfo;
  417. if ( !steamapicontext->SteamFriends()->GetFriendGamePlayed( friendSteamID, &gameInfo ) )
  418. continue;
  419. // Friends is in-game. Make sure it's TF2.
  420. if ( gameInfo.m_gameID.IsValid() && gameInfo.m_gameID == myGameInfo.m_gameID )
  421. {
  422. const char *pszName = steamapicontext->SteamFriends()->GetFriendPersonaName( friendSteamID );
  423. int idx = m_PlayerInfoList.AddToTail();
  424. trade_partner_info_t &info = m_PlayerInfoList[idx];
  425. info.m_steamID = friendSteamID;
  426. info.m_name = pszName;
  427. }
  428. }
  429. }
  430. UpdatePlayerList();
  431. }
  432. //-----------------------------------------------------------------------------
  433. // Purpose:
  434. //-----------------------------------------------------------------------------
  435. void CTradingStartDialog::SetupSelectServer( void )
  436. {
  437. m_PlayerInfoList.Purge();
  438. if ( steamapicontext && steamapicontext->SteamUtils() )
  439. {
  440. for( int iPlayerIndex = 1 ; iPlayerIndex <= MAX_PLAYERS; iPlayerIndex++ )
  441. {
  442. // find all players who are on the local player's team
  443. int iLocalPlayerIndex = GetLocalPlayerIndex();
  444. if( ( iPlayerIndex != iLocalPlayerIndex ) && ( g_PR->IsConnected( iPlayerIndex ) ) )
  445. {
  446. player_info_t pi;
  447. if ( !engine->GetPlayerInfo( iPlayerIndex, &pi ) )
  448. continue;
  449. if ( !pi.friendsID )
  450. continue;
  451. CSteamID steamID( pi.friendsID, 1, GetUniverse(), k_EAccountTypeIndividual );
  452. int idx = m_PlayerInfoList.AddToTail();
  453. trade_partner_info_t &info = m_PlayerInfoList[idx];
  454. info.m_steamID = steamID;
  455. info.m_name = pi.name;
  456. }
  457. }
  458. }
  459. UpdatePlayerList();
  460. }
  461. //-----------------------------------------------------------------------------
  462. // Purpose:
  463. //-----------------------------------------------------------------------------
  464. void CTradingStartDialog::SetupSelectProfile( void )
  465. {
  466. vgui::TextEntry *pEntry = dynamic_cast<vgui::TextEntry*>( m_pStatePanels[m_iCurrentState]->FindChildByName("URLEntry") );
  467. if ( pEntry )
  468. {
  469. pEntry->SetText( "" );
  470. pEntry->RequestFocus();
  471. pEntry->AddActionSignalTarget( this );
  472. }
  473. if ( m_pURLFailLabel )
  474. {
  475. m_pURLFailLabel->SetVisible( false );
  476. }
  477. if ( m_pURLSearchingLabel )
  478. {
  479. m_pURLSearchingLabel->SetVisible( false );
  480. }
  481. CExButton *pButton = dynamic_cast<CExButton*>( m_pStatePanels[m_iCurrentState]->FindChildByName( "subbutton0" ) );
  482. if ( pButton )
  483. {
  484. pButton->SetEnabled( false );
  485. }
  486. m_pPlayerListScroller->SetVisible( false );
  487. }
  488. //-----------------------------------------------------------------------------
  489. // Purpose:
  490. //-----------------------------------------------------------------------------
  491. void CTradingStartDialog::UpdatePlayerList( void )
  492. {
  493. vgui::Label *pLabelEmpty = dynamic_cast<vgui::Label*>( m_pStatePanels[m_iCurrentState]->FindChildByName("EmptyPlayerListLabel") );
  494. vgui::Label *pLabelQuery = dynamic_cast<vgui::Label*>( m_pStatePanels[m_iCurrentState]->FindChildByName("QueryLabel") );
  495. // If we have no players in our list, show the no-player label.
  496. if ( m_PlayerInfoList.Count() == 0 )
  497. {
  498. if ( pLabelEmpty )
  499. {
  500. pLabelEmpty->SetVisible( true );
  501. }
  502. if ( pLabelQuery )
  503. {
  504. pLabelQuery->SetVisible( false );
  505. }
  506. return;
  507. }
  508. // First, reapply any KVs we have to reapply
  509. if ( m_bReapplyButtonKVs )
  510. {
  511. m_bReapplyButtonKVs = false;
  512. if ( m_pButtonKV )
  513. {
  514. FOR_EACH_VEC( m_pPlayerPanels, i )
  515. {
  516. m_pPlayerPanels[i]->ApplySettings( m_pButtonKV );
  517. }
  518. }
  519. }
  520. // Otherwise, build the player panels from the list of steam IDs
  521. for ( int i = 0; i < m_PlayerInfoList.Count(); i++ )
  522. {
  523. if ( m_pPlayerPanels.Count() <= i )
  524. {
  525. m_pPlayerPanels.AddToTail();
  526. m_pPlayerPanels[i] = new CTradeTargetPanel( m_pPlayerList, VarArgs("player%d",i) );
  527. m_pPlayerPanels[i]->GetButton()->SetCommand( VarArgs("select_player%d",i+1) );
  528. m_pPlayerPanels[i]->GetButton()->AddActionSignalTarget( this );
  529. m_pPlayerPanels[i]->GetAvatar()->SetShouldDrawFriendIcon( false );
  530. m_pPlayerPanels[i]->GetAvatar()->SetMouseInputEnabled( false );
  531. if ( m_pButtonKV )
  532. {
  533. m_pPlayerPanels[i]->ApplySettings( m_pButtonKV );
  534. m_pPlayerPanels[i]->InvalidateLayout( true );
  535. }
  536. }
  537. m_pPlayerPanels[i]->SetInfo( m_PlayerInfoList[i].m_steamID, m_PlayerInfoList[i].m_name.Get() );
  538. }
  539. m_pPlayerListScroller->GetScrollbar()->SetAutohideButtons( true );
  540. m_pPlayerListScroller->GetScrollbar()->SetValue( 0 );
  541. // Remove any extra player panels
  542. for ( int i = m_pPlayerPanels.Count()-1; i >= m_PlayerInfoList.Count(); i-- )
  543. {
  544. m_pPlayerPanels[i]->MarkForDeletion();
  545. m_pPlayerPanels.Remove(i);
  546. }
  547. if ( pLabelEmpty )
  548. {
  549. pLabelEmpty->SetVisible( false );
  550. }
  551. if ( pLabelQuery )
  552. {
  553. pLabelQuery->SetVisible( true );
  554. }
  555. m_pPlayerListScroller->SetVisible( true );
  556. InvalidateLayout();
  557. }
  558. //-----------------------------------------------------------------------------
  559. // Purpose:
  560. //-----------------------------------------------------------------------------
  561. void CTradeTargetPanel::SetInfo( const CSteamID &steamID, const char *pszName )
  562. {
  563. if ( !steamapicontext || !steamapicontext->SteamFriends() )
  564. return;
  565. m_pAvatar->SetPlayer( steamID, k_EAvatarSize64x64 );
  566. m_pButton->SetText( pszName );
  567. }
  568. static vgui::DHANDLE<CTradingStartDialog> g_hTradingStartDialog;
  569. //-----------------------------------------------------------------------------
  570. // Purpose:
  571. //-----------------------------------------------------------------------------
  572. CTradingStartDialog *OpenTradingStartDialog( vgui::Panel *pParent, CEconItemView* pOptGiftItem )
  573. {
  574. if (!g_hTradingStartDialog.Get())
  575. {
  576. g_hTradingStartDialog = vgui::SETUP_PANEL( new CTradingStartDialog( pParent ) );
  577. }
  578. g_hTradingStartDialog->InvalidateLayout( false, true );
  579. g_hTradingStartDialog->Reset();
  580. g_hTradingStartDialog->SetVisible( true );
  581. g_hTradingStartDialog->MakePopup();
  582. g_hTradingStartDialog->MoveToFront();
  583. g_hTradingStartDialog->SetKeyBoardInputEnabled(true);
  584. g_hTradingStartDialog->SetMouseInputEnabled(true);
  585. g_hTradingStartDialog->SetGift( pOptGiftItem );
  586. TFModalStack()->PushModal( g_hTradingStartDialog );
  587. return g_hTradingStartDialog;
  588. }
  589. //-----------------------------------------------------------------------------
  590. // Purpose: GC Msg handler to receive the Lookup Account response
  591. //-----------------------------------------------------------------------------
  592. class CGCLookupAccountResponse : public GCSDK::CGCClientJob
  593. {
  594. public:
  595. CGCLookupAccountResponse( GCSDK::CGCClient *pClient ) : GCSDK::CGCClientJob( pClient ) {}
  596. virtual bool BYieldingRunGCJob( GCSDK::IMsgNetPacket *pNetPacket )
  597. {
  598. GCSDK::CGCMsg<MsgGCStandardResponse_t> msg( pNetPacket );
  599. uint8 iAccounts = 0;
  600. uint64 iAccountID = 0;
  601. if ( msg.BReadUint8Data( &iAccounts ) )
  602. {
  603. // We only care about the first account we find in this panel.
  604. if ( iAccounts > 0 )
  605. {
  606. msg.BReadUint64Data( &iAccountID );
  607. }
  608. }
  609. if ( g_hTradingStartDialog.Get() )
  610. {
  611. g_hTradingStartDialog->OnLookupAccountResponse( iAccountID );
  612. }
  613. return true;
  614. }
  615. };
  616. GC_REG_JOB( GCSDK::CGCClient, CGCLookupAccountResponse, "CGCLookupAccountResponse", k_EMsgGCLookupAccountResponse, GCSDK::k_EServerTypeGCClient );