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.

828 lines
25 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "collection_crafting_panel.h"
  8. #include "cdll_client_int.h"
  9. #include "ienginevgui.h"
  10. #include "econ_item_tools.h"
  11. #include "econ_ui.h"
  12. #include <vgui_controls/AnimationController.h>
  13. #include "clientmode_tf.h"
  14. #include "softline.h"
  15. #include "drawing_panel.h"
  16. #include "tf_item_inventory.h"
  17. // memdbgon must be the last include file in a .cpp file!!!
  18. #include <tier0/memdbgon.h>
  19. //-----------------------------------------------------------------------------
  20. // Purpose:
  21. //-----------------------------------------------------------------------------
  22. CCollectionCraftingPanel::CCollectionCraftingPanel( vgui::Panel *parent, CItemModelPanelToolTip* pTooltip )
  23. : BaseClass( parent, "CollectionCraftingPanel" )
  24. , m_pKVItemPanels( NULL )
  25. , m_pModelPanel( NULL )
  26. , m_bWaitingForGCResponse( false )
  27. , m_bEnvelopeReadyToSend( false )
  28. , m_pMouseOverTooltip( pTooltip )
  29. , m_bShowing( false )
  30. , m_bShowImmediately( false )
  31. {
  32. ListenForGameEvent( "gameui_hidden" );
  33. m_pSelectingItemModelPanel = NULL;
  34. m_pTradeUpContainer = new EditablePanel( this, "TradeUpContainer" );
  35. m_pInspectPanel = new CTFItemInspectionPanel( this, "NewItemPanel" );
  36. m_pCosmeticResultItemModelPanel = new CItemModelPanel( m_pInspectPanel, "CosmeticResultItemModelPanel" );
  37. m_pStampPanel = new ImagePanel( this, "Stamp" );
  38. m_pStampButton = new CExButton( this, "ApplyStampButton", "" );
  39. EditablePanel* pPaperContainer = new EditablePanel( m_pTradeUpContainer, "PaperContainer" );
  40. m_pOKButton = new CExButton( pPaperContainer, "OkButton", "" );
  41. m_pNextItemButton = new CExButton( this, "NextItemButton", "" );
  42. m_pDrawingPanel = new CDrawingPanel( this, "drawingpanel" );
  43. }
  44. //-----------------------------------------------------------------------------
  45. // Purpose:
  46. //-----------------------------------------------------------------------------
  47. CCollectionCraftingPanel::~CCollectionCraftingPanel( void )
  48. {
  49. if ( m_hSelectionPanel )
  50. {
  51. m_hSelectionPanel->MarkForDeletion();
  52. }
  53. if ( m_pKVItemPanels )
  54. {
  55. m_pKVItemPanels->deleteThis();
  56. }
  57. }
  58. //-----------------------------------------------------------------------------
  59. void CCollectionCraftingPanel::SetItemPanelCount( )
  60. {
  61. // only do this once
  62. if ( m_vecItemContainers.Count() != 0 )
  63. return;
  64. const int nNumItems = GetInputItemCount();
  65. const int nNumOutput = GetOutputItemCount();
  66. EditablePanel* pPaperContainer = dynamic_cast<vgui::EditablePanel*>( m_pTradeUpContainer->FindChildByName( "PaperContainer" ) );
  67. if ( pPaperContainer )
  68. {
  69. m_vecItemContainers.SetCount( nNumItems );
  70. FOR_EACH_VEC( m_vecItemContainers, i )
  71. {
  72. m_vecItemContainers[i] = new EditablePanel( pPaperContainer, "itemcontainer" );
  73. }
  74. m_vecOutputItemContainers.SetCount( nNumOutput );
  75. FOR_EACH_VEC( m_vecOutputItemContainers, i )
  76. {
  77. m_vecOutputItemContainers[i] = new EditablePanel( pPaperContainer, "itemcontainer" );
  78. }
  79. }
  80. }
  81. //-----------------------------------------------------------------------------
  82. void CCollectionCraftingPanel::CreateSelectionPanel()
  83. {
  84. m_hSelectionPanel = new CCollectionCraftingSelectionPanel( this );
  85. }
  86. //-----------------------------------------------------------------------------
  87. // Purpose:
  88. //-----------------------------------------------------------------------------
  89. void CCollectionCraftingPanel::ApplySchemeSettings( vgui::IScheme *pScheme )
  90. {
  91. BaseClass::ApplySchemeSettings( pScheme );
  92. LoadControlSettings( GetResFile() );
  93. m_pModelPanel = FindControl< CBaseModelPanel >( "ReturnModel" );
  94. if ( m_pModelPanel )
  95. {
  96. m_pModelPanel->SetLookAtCamera( false );
  97. }
  98. if ( m_pDrawingPanel )
  99. {
  100. m_pDrawingPanel->SetType( DRAWING_PANEL_TYPE_CRAFTING );
  101. }
  102. m_pItemNamePanel = m_pInspectPanel->FindControl< CItemModelPanel >( "ItemName" );
  103. Assert( m_pItemNamePanel );
  104. }
  105. //-----------------------------------------------------------------------------
  106. // Purpose:
  107. //-----------------------------------------------------------------------------
  108. void CCollectionCraftingPanel::ApplySettings( KeyValues *inResourceData )
  109. {
  110. BaseClass::ApplySettings( inResourceData );
  111. KeyValues *pItemKV = inResourceData->FindKey( "ItemContainerKV" );
  112. if ( pItemKV )
  113. {
  114. if ( m_pKVItemPanels )
  115. {
  116. m_pKVItemPanels->deleteThis();
  117. }
  118. m_pKVItemPanels = new KeyValues("ItemContainerKV");
  119. pItemKV->CopySubkeys( m_pKVItemPanels );
  120. }
  121. m_vecImagePanels.Purge();
  122. m_vecItemPanels.Purge();
  123. KeyValues *pBoxTopsKV = inResourceData->FindKey( "BoxTops" );
  124. if ( pBoxTopsKV )
  125. {
  126. m_vecBoxTopNames.Purge();
  127. FOR_EACH_VALUE( pBoxTopsKV, pValue )
  128. {
  129. m_vecBoxTopNames.AddToTail( pValue->GetString() );
  130. }
  131. }
  132. Assert( m_vecBoxTopNames.Count() );
  133. KeyValues *pStampNames = inResourceData->FindKey( "stampimages" );
  134. if ( pStampNames )
  135. {
  136. m_vecStampNames.Purge();
  137. FOR_EACH_VALUE( pStampNames, pValue )
  138. {
  139. m_vecStampNames.AddToTail( pValue->GetString() );
  140. }
  141. }
  142. Assert( m_vecStampNames.Count() );
  143. KeyValues *pResulStrings = inResourceData->FindKey( "resultstring" );
  144. if ( pResulStrings )
  145. {
  146. m_vecResultStrings.Purge();
  147. FOR_EACH_VALUE( pResulStrings, pValue )
  148. {
  149. m_vecResultStrings.AddToTail( pValue->GetString() );
  150. }
  151. }
  152. Assert( m_vecResultStrings.Count() );
  153. KeyValues *pLocalizedPanelNames = inResourceData->FindKey( "localizedpanels" );
  154. if ( pLocalizedPanelNames )
  155. {
  156. m_vecLocalizedPanels.Purge();
  157. FOR_EACH_TRUE_SUBKEY( pLocalizedPanelNames, pValue )
  158. {
  159. m_vecLocalizedPanels.AddToTail( { pValue->GetString( "panelname" ), pValue->GetBool( "show_for_english", false ) } );
  160. }
  161. }
  162. CreateItemPanels();
  163. }
  164. //-----------------------------------------------------------------------------
  165. // Purpose:
  166. //-----------------------------------------------------------------------------
  167. void CCollectionCraftingPanel::PerformLayout()
  168. {
  169. BaseClass::PerformLayout();
  170. if ( m_pModelPanel )
  171. {
  172. m_pModelPanel->SetMDL( "models/player/items/crafting/mannco_crate_tradeup.mdl" );
  173. }
  174. FOR_EACH_VEC( m_vecItemContainers, i )
  175. {
  176. m_vecItemContainers[ i ]->SetPos( m_iButtonsStartX + m_iButtonsStepX * ( i % 5 )
  177. , m_iButtonsStartY + m_iButtonsStepY * ( i / 5 ) );
  178. }
  179. FOR_EACH_VEC( m_vecOutputItemContainers, i )
  180. {
  181. m_vecOutputItemContainers[i]->SetPos( m_iOutputItemStartX + m_iOutputItemStepX * ( i % 5 )
  182. , m_iOutputItemStartY + m_iOutputItemStepY * ( i / 5 ) );
  183. }
  184. if ( steamapicontext && steamapicontext->SteamApps() )
  185. {
  186. char uilanguage[ 64 ];
  187. uilanguage[0] = 0;
  188. engine->GetUILanguage( uilanguage, sizeof( uilanguage ) );
  189. ELanguage language = PchLanguageToELanguage( uilanguage );
  190. FOR_EACH_VEC( m_vecLocalizedPanels, i )
  191. {
  192. bool bShow = language == k_Lang_English && m_vecLocalizedPanels[ i ].m_bShowForEnglish;
  193. Panel* pPanel = m_pTradeUpContainer->FindChildByName( m_vecLocalizedPanels[ i ].m_strPanel, true );
  194. if ( pPanel )
  195. {
  196. pPanel->SetVisible( bShow );
  197. }
  198. }
  199. }
  200. UpdateOKButton();
  201. }
  202. //-----------------------------------------------------------------------------
  203. // Purpose:
  204. //-----------------------------------------------------------------------------
  205. void CCollectionCraftingPanel::CreateItemPanels()
  206. {
  207. SetItemPanelCount();
  208. m_vecImagePanels.SetCount( m_vecItemContainers.Count() );
  209. m_vecItemPanels.SetCount( m_vecItemContainers.Count() );
  210. FOR_EACH_VEC( m_vecItemContainers, i )
  211. {
  212. m_vecItemContainers[ i ]->ApplySettings( m_pKVItemPanels );
  213. m_vecImagePanels[ i ] = m_vecItemContainers[ i ]->FindControl< ImagePanel >( "imagepanel" );
  214. m_vecItemPanels[ i ] = m_vecItemContainers[ i ]->FindControl< CItemModelPanel >( "itempanel" );
  215. m_vecItemPanels[ i ]->SetActAsButton( true, true );
  216. m_vecItemPanels[ i ]->SetTooltip( m_pMouseOverTooltip, "" );
  217. CExButton* pButton = m_vecItemContainers[ i ]->FindControl< CExButton >( "BackgroundButton" );
  218. if ( pButton )
  219. {
  220. pButton->SetCommand( CFmtStr( "select%d", i ) );
  221. pButton->AddActionSignalTarget( this );
  222. }
  223. }
  224. m_vecOutputImagePanels.SetCount( m_vecOutputItemContainers.Count() );
  225. m_vecOutputItemPanels.SetCount( m_vecOutputItemContainers.Count() );
  226. FOR_EACH_VEC( m_vecOutputItemContainers, i )
  227. {
  228. m_vecOutputItemContainers[i]->ApplySettings( m_pKVItemPanels );
  229. m_vecOutputImagePanels[i] = m_vecOutputItemContainers[i]->FindControl< ImagePanel >( "imagepanel" );
  230. m_vecOutputItemPanels[i] = m_vecOutputItemContainers[i]->FindControl< CItemModelPanel >( "itempanel" );
  231. m_vecOutputItemPanels[i]->SetTooltip( m_pMouseOverTooltip, "" );
  232. }
  233. }
  234. //-----------------------------------------------------------------------------
  235. // Purpose:
  236. //-----------------------------------------------------------------------------
  237. void CCollectionCraftingPanel::OnCommand( const char *command )
  238. {
  239. if ( !Q_stricmp( command, "reloadscheme" ) )
  240. {
  241. InvalidateLayout( false, true );
  242. return;
  243. }
  244. if ( FStrEq( "doneselectingitems", command ) )
  245. {
  246. g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( this, "CollectionCrafting_LetterStart" );
  247. m_bEnvelopeReadyToSend = false;
  248. if ( m_vecStampNames.Count() )
  249. {
  250. m_pStampPanel->SetImage( m_vecStampNames[ RandomInt( 0, m_vecStampNames.Count() - 1 ) ] );
  251. }
  252. return;
  253. }
  254. else if ( FStrEq( "cancel", command ) )
  255. {
  256. SetVisible( false );
  257. return;
  258. }
  259. else if ( Q_strnicmp( "select", command, 6 ) == 0 )
  260. {
  261. SelectPanel( atoi( command + 6 ) );
  262. return;
  263. }
  264. else if ( FStrEq( "envelopesend", command ) )
  265. {
  266. GCSDK::CProtoBufMsg<CMsgCraftCollectionUpgrade> msg( k_EMsgGCCraftCollectionUpgrade );
  267. // Construct message
  268. FOR_EACH_VEC( m_vecItemPanels, i )
  269. {
  270. if ( m_vecItemPanels[ i ]->GetItem() == NULL )
  271. return;
  272. msg.Body().add_item_id( m_vecItemPanels[ i ]->GetItem()->GetItemID() );
  273. }
  274. // Send if off
  275. GCClientSystem()->BSendMessage( msg );
  276. m_bWaitingForGCResponse = true;
  277. m_nFoundItemID.Purge();
  278. m_timerResponse.Start( 5.f );
  279. g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( this, "CollectionCrafting_LetterSend" );
  280. return;
  281. }
  282. else if ( FStrEq( "placestamp", command ) )
  283. {
  284. g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( this, "CollectionCrafting_PlaceStamp" );
  285. return;
  286. }
  287. else if( Q_strnicmp( "playcratesequence", command, 17 ) == 0 )
  288. {
  289. m_pModelPanel->SetSequence( atoi( command + 17 ), true );
  290. return;
  291. }
  292. else if( FStrEq( "itemget", command ) )
  293. {
  294. g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( this, "CollectionCrafting_ItemRecieved" );
  295. wchar_t *pszLocalized = NULL;
  296. //
  297. if ( m_eEconItemOrigin == kEconItemOrigin_FoundInCrate )
  298. {
  299. pszLocalized = g_pVGuiLocalize->Find( "#NewItemMethod_FoundInCrate" );
  300. }
  301. else if ( m_vecResultStrings.Count() )
  302. {
  303. pszLocalized = g_pVGuiLocalize->Find( m_vecResultStrings[ RandomInt( 0, m_vecResultStrings.Count() - 1 ) ] );
  304. }
  305. m_pInspectPanel->SetDialogVariable( "resultstring", pszLocalized );
  306. return;
  307. }
  308. else if( Q_strnicmp( "playsound", command, 9 ) == 0 )
  309. {
  310. vgui::surface()->PlaySound( command + 10 );
  311. return;
  312. }
  313. else if( FStrEq( "startexplanation1", command ) )
  314. {
  315. CExplanationPopup *pPopup = dynamic_cast<CExplanationPopup*>( FindChildByName("StartExplanation") );
  316. if ( pPopup )
  317. {
  318. pPopup->Popup();
  319. }
  320. return;
  321. }
  322. else if( FStrEq( "startexplanation2", command ) )
  323. {
  324. CExplanationPopup *pPopup = dynamic_cast<CExplanationPopup*>( FindChildByName("SigningExplanation") );
  325. if ( pPopup )
  326. {
  327. pPopup->Popup();
  328. }
  329. return;
  330. }
  331. else if ( FStrEq( "nextitem", command ) )
  332. {
  333. if ( m_nFoundItemID.Count() > 1 )
  334. {
  335. // Remove head, reset timer to drop next item
  336. m_nFoundItemID.Remove( 0 );
  337. m_timerResponse.Start( 5.f );
  338. m_bShowImmediately = true;
  339. }
  340. }
  341. else if( FStrEq( "reload", command ) )
  342. {
  343. g_pVGuiLocalize->ReloadLocalizationFiles();
  344. InvalidateLayout( false, true );
  345. SetVisible( true );
  346. return;
  347. }
  348. BaseClass::OnCommand( command );
  349. }
  350. void CCollectionCraftingPanel::SelectPanel( int nPanel )
  351. {
  352. m_pSelectingItemModelPanel = m_vecItemPanels[ nPanel ];
  353. CCopyableUtlVector< const CEconItemView* > vecCurrentItems;
  354. FOR_EACH_VEC( m_vecItemPanels, i )
  355. {
  356. if ( m_vecItemPanels[ i ]->GetItem() )
  357. {
  358. vecCurrentItems.AddToTail( m_vecItemPanels[ i ]->GetItem() );
  359. }
  360. }
  361. if ( !m_hSelectionPanel )
  362. {
  363. CreateSelectionPanel();
  364. m_hSelectionPanel->SetAutoDelete( false );
  365. }
  366. if ( m_hSelectionPanel )
  367. {
  368. // Clicked on an item in the crafting area. Open up the selection panel.
  369. m_hSelectionPanel->SetCorrespondingItems( vecCurrentItems );
  370. m_hSelectionPanel->ShowDuplicateCounts( true );
  371. m_hSelectionPanel->ShowPanel( 0, true );
  372. m_hSelectionPanel->SetCaller( this );
  373. m_hSelectionPanel->SetZPos( GetZPos() + 1 );
  374. }
  375. }
  376. void CCollectionCraftingPanel::FireGameEvent( IGameEvent *event )
  377. {
  378. if ( FStrEq( event->GetName(), "gameui_hidden" ) )
  379. {
  380. SetVisible( false );
  381. return;
  382. }
  383. }
  384. //-----------------------------------------------------------------------------
  385. // Purpose:
  386. //-----------------------------------------------------------------------------
  387. void CCollectionCraftingPanel::OnItemPanelMousePressed( vgui::Panel *panel )
  388. {
  389. CItemModelPanel *pItemPanel = dynamic_cast < CItemModelPanel * > ( panel );
  390. if ( pItemPanel && IsVisible() && !pItemPanel->IsGreyedOut() )
  391. {
  392. auto idx = m_vecItemPanels.Find( pItemPanel );
  393. if ( idx != m_vecItemPanels.InvalidIndex() )
  394. {
  395. OnCommand( CFmtStr( "select%d", idx ) );
  396. }
  397. }
  398. }
  399. //-----------------------------------------------------------------------------
  400. // Purpose:
  401. //-----------------------------------------------------------------------------
  402. void CCollectionCraftingPanel::OnSelectionReturned( KeyValues *data )
  403. {
  404. Assert( m_pSelectingItemModelPanel );
  405. m_hSelectionPanel->SetVisible( false );
  406. if ( data && m_pSelectingItemModelPanel )
  407. {
  408. uint64 ulIndex = data->GetUint64( "itemindex", INVALID_ITEM_ID );
  409. CEconItemView* pSelectedItem = InventoryManager()->GetLocalInventory()->GetInventoryItemByItemID( ulIndex );
  410. if ( pSelectedItem )
  411. {
  412. vgui::surface()->PlaySound( "ui/trade_up_apply_sticker.wav" );
  413. }
  414. auto idx = m_vecItemPanels.Find( m_pSelectingItemModelPanel );
  415. SetItem( pSelectedItem, idx );
  416. }
  417. m_pSelectingItemModelPanel = NULL;
  418. }
  419. //-----------------------------------------------------------------------------
  420. // Purpose:
  421. //-----------------------------------------------------------------------------
  422. void CCollectionCraftingPanel::UpdateOKButton()
  423. {
  424. bool bOKEnabled = true;
  425. FOR_EACH_VEC( m_vecItemPanels, i )
  426. {
  427. bOKEnabled &= m_vecItemPanels[ i ]->GetItem() != NULL;
  428. }
  429. m_pOKButton->SetEnabled( bOKEnabled );
  430. if ( bOKEnabled )
  431. {
  432. g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( m_pOKButton->GetParent(), "CollectionCrafting_OKBlink" );
  433. }
  434. }
  435. //-----------------------------------------------------------------------------
  436. // Purpose:
  437. //-----------------------------------------------------------------------------
  438. void CCollectionCraftingPanel::SetVisible( bool bVisible )
  439. {
  440. BaseClass::SetVisible( bVisible );
  441. if ( bVisible )
  442. {
  443. m_pInspectPanel->SetVisible( false );
  444. EditablePanel* pDimmer = FindControl< EditablePanel >( "Dimmer" );
  445. if ( pDimmer )
  446. {
  447. pDimmer->SetAlpha( 0 );
  448. }
  449. EditablePanel* pBG = FindControl< EditablePanel >( "BG" );
  450. if ( pBG )
  451. {
  452. pBG->SetPos( pBG->GetXPos(), GetTall() );
  453. }
  454. m_pTradeUpContainer->SetVisible( true );
  455. m_pTradeUpContainer->SetPos( m_pTradeUpContainer->GetXPos(), -700 );
  456. g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( this, "CollectionCrafting_Intro" );
  457. vgui::surface()->PlaySound( "ui/trade_up_panel_slide.wav" );
  458. m_pDrawingPanel->ClearLines( GetLocalPlayerIndex() );
  459. }
  460. else
  461. {
  462. if ( m_hSelectionPanel )
  463. {
  464. m_hSelectionPanel->SetVisible( false );
  465. }
  466. if ( m_bShowing )
  467. {
  468. EconUI()->SetPreventClosure( false );
  469. }
  470. m_bShowing = false;
  471. }
  472. }
  473. //-----------------------------------------------------------------------------
  474. // Purpose:
  475. //-----------------------------------------------------------------------------
  476. void CCollectionCraftingPanel::SOCreated( const CSteamID & steamIDOwner, const GCSDK::CSharedObject *pObject, GCSDK::ESOCacheEvent eEvent )
  477. {
  478. tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ );
  479. if ( m_bWaitingForGCResponse )
  480. {
  481. if( pObject->GetTypeID() != CEconItem::k_nTypeID )
  482. return;
  483. CEconItem *pItem = (CEconItem *)pObject;
  484. if ( IsUnacknowledged( pItem->GetInventoryToken() ) && ( pItem->GetOrigin() == m_eEconItemOrigin ) )
  485. {
  486. //Assert( m_nFoundItemID == INVALID_ITEM_ID );
  487. //m_bWaitingForGCResponse = false;
  488. m_nFoundItemID.AddToTail( pItem->GetItemID() );
  489. CEconItemView* pNewEconItemView = InventoryManager()->GetLocalInventory()->GetInventoryItemByItemID( pItem->GetItemID() );
  490. if ( pNewEconItemView )
  491. {
  492. // Acknowledge the item
  493. InventoryManager()->AcknowledgeItem( pNewEconItemView, true );
  494. InventoryManager()->SaveAckFile();
  495. }
  496. }
  497. }
  498. }
  499. //-----------------------------------------------------------------------------
  500. // Purpose:
  501. //-----------------------------------------------------------------------------
  502. void CCollectionCraftingPanel::Show( CUtlVector< const CEconItemView* >& vecStartingItems )
  503. {
  504. FOR_EACH_VEC( m_vecItemPanels, i )
  505. {
  506. const CEconItemView* pItem = i < vecStartingItems.Count() ? vecStartingItems[ i ] : NULL;
  507. SetItem( pItem, i );
  508. }
  509. m_bShowing = true;
  510. EconUI()->SetPreventClosure( true );
  511. SetVisible( true );
  512. m_eEconItemOrigin = kEconItemOrigin_TradeUp;
  513. }
  514. //-----------------------------------------------------------------------------
  515. void CCollectionCraftingPanel::SetWaitingForItem( eEconItemOrigin eOrigin )
  516. {
  517. // Clear Panels
  518. FOR_EACH_VEC( m_vecItemPanels, i )
  519. {
  520. SetItem( NULL, i );
  521. }
  522. m_bShowing = true;
  523. EconUI()->SetPreventClosure( true );
  524. m_pInspectPanel->SetVisible( false );
  525. EditablePanel* pDimmer = FindControl< EditablePanel >( "Dimmer" );
  526. if ( pDimmer )
  527. {
  528. pDimmer->SetAlpha( 0 );
  529. }
  530. EditablePanel* pBG = FindControl< EditablePanel >( "BG" );
  531. if ( pBG )
  532. {
  533. pBG->SetPos( pBG->GetXPos(), GetTall() );
  534. }
  535. m_pTradeUpContainer->SetVisible( false );
  536. // reset
  537. m_pInspectPanel->SetItemCopy( NULL );
  538. m_pCosmeticResultItemModelPanel->SetItem( NULL );
  539. // Do not use Derived SetVisible since it does extra animations we do not want here
  540. BaseClass::SetVisible( true );
  541. m_eEconItemOrigin = eOrigin;
  542. m_bWaitingForGCResponse = true;
  543. m_nFoundItemID.Purge();
  544. m_timerResponse.Start( 5.f );
  545. g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( this, "CollectionCrafting_WaitForItemsOnly" );
  546. return;
  547. }
  548. //-----------------------------------------------------------------------------
  549. // Purpose:
  550. //-----------------------------------------------------------------------------
  551. void CCollectionCraftingPanel::SetItem( const CEconItemView* pItem, int nIndex )
  552. {
  553. if ( nIndex != m_vecItemPanels.InvalidIndex() )
  554. {
  555. m_vecImagePanels[ nIndex ]->SetVisible( pItem != NULL );
  556. m_vecItemPanels[ nIndex ]->SetVisible( pItem != NULL );
  557. m_vecItemPanels[ nIndex ]->SetItem( pItem );
  558. if ( pItem && m_vecBoxTopNames.Count() )
  559. {
  560. CUniformRandomStream randomStream;
  561. randomStream.SetSeed( pItem->GetItemID() );
  562. m_vecImagePanels[ nIndex ]->SetImage( m_vecBoxTopNames[ randomStream.RandomInt( 0, m_vecBoxTopNames.Count() - 1 ) ] );
  563. }
  564. }
  565. UpdateOKButton();
  566. }
  567. //-----------------------------------------------------------------------------
  568. // Purpose:
  569. //-----------------------------------------------------------------------------
  570. void CCollectionCraftingPanel::OnThink()
  571. {
  572. BaseClass::OnThink();
  573. const float flSoonestAirDropTime = 2.f;
  574. if ( m_timerResponse.HasStarted() )
  575. {
  576. // Elapsed is bad. This means the item server didnt get back to us
  577. if ( m_timerResponse.IsElapsed() )
  578. {
  579. m_nFoundItemID.Purge();
  580. m_bWaitingForGCResponse = false;
  581. m_timerResponse.Invalidate();
  582. g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( this, "CollectionCrafting_HideWaiting" );
  583. g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( this, "CollectionCrafting_ShowFailure" );
  584. }
  585. else if ( m_timerResponse.GetElapsedTime() > flSoonestAirDropTime || m_bShowImmediately )
  586. {
  587. m_bShowImmediately = false;
  588. // At 2 seconds we want to either show that we're still waiting, or show the item
  589. if ( m_nFoundItemID.Count() > 0 )
  590. {
  591. OnCommand( "itemget" );
  592. m_timerResponse.Invalidate();
  593. g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( this, "CollectionCrafting_HideWaiting" );
  594. // Setup the item in the panel
  595. CEconItemView* pNewEconItemView = InventoryManager()->GetLocalInventory()->GetInventoryItemByItemID( m_nFoundItemID[0] );
  596. if ( pNewEconItemView )
  597. {
  598. static CSchemaAttributeDefHandle pAttrib_WeaponAllowInspect( "weapon_allow_inspect" );
  599. if ( pNewEconItemView->FindAttribute( pAttrib_WeaponAllowInspect ) )
  600. {
  601. m_pInspectPanel->SetItemCopy( pNewEconItemView );
  602. m_pInspectPanel->SetSpecialAttributesOnly( true );
  603. m_pCosmeticResultItemModelPanel->SetItem( NULL );
  604. }
  605. else //( IsMiscSlot( pNewEconItemView->GetStaticData()->GetDefaultLoadoutSlot() ) )
  606. {
  607. m_pCosmeticResultItemModelPanel->SetItem( pNewEconItemView );
  608. m_pCosmeticResultItemModelPanel->SetNameOnly( false );
  609. m_pInspectPanel->SetSpecialAttributesOnly( true );
  610. m_pInspectPanel->SetItemCopy( NULL );
  611. }
  612. // Acknowledge the item
  613. InventoryManager()->AcknowledgeItem( pNewEconItemView, true );
  614. InventoryManager()->SaveAckFile();
  615. if ( m_pItemNamePanel )
  616. {
  617. m_pItemNamePanel->SetItem( pNewEconItemView );
  618. }
  619. }
  620. m_bWaitingForGCResponse = false;
  621. // only show if more then 1 item in queue
  622. m_pNextItemButton->SetVisible( m_nFoundItemID.Count() > 1 );
  623. }
  624. else
  625. {
  626. // Say that we're waiting
  627. g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( this, "CollectionCrafting_ShowWaiting" );
  628. }
  629. }
  630. }
  631. bool bEnvelopReadyToSendThisFrame = true;
  632. // They need to have drawn a little bit
  633. bEnvelopReadyToSendThisFrame &= m_pDrawingPanel->GetLines( GetLocalPlayerIndex() ).Count() > 10;
  634. // And placed a stamp
  635. bEnvelopReadyToSendThisFrame &= m_pStampPanel->IsVisible();
  636. // Show the send button?
  637. if ( bEnvelopReadyToSendThisFrame && !m_bEnvelopeReadyToSend )
  638. {
  639. g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( this, "CollectionCrafting_ShowSendButton" );
  640. }
  641. m_bEnvelopeReadyToSend = bEnvelopReadyToSendThisFrame;
  642. }
  643. //* **************************************************************************************************************************************
  644. // Stat Clock Crafting
  645. //-----------------------------------------------------------------------------
  646. // Purpose:
  647. //-----------------------------------------------------------------------------
  648. CCraftCommonStatClockPanel::CCraftCommonStatClockPanel( vgui::Panel *parent, CItemModelPanelToolTip* pTooltip )
  649. : BaseClass( parent, pTooltip )
  650. {
  651. }
  652. //-----------------------------------------------------------------------------
  653. // Purpose:
  654. //-----------------------------------------------------------------------------
  655. CCraftCommonStatClockPanel::~CCraftCommonStatClockPanel( void )
  656. {
  657. }
  658. //-----------------------------------------------------------------------------
  659. void CCraftCommonStatClockPanel::Show( CUtlVector< const CEconItemView* >& vecStartingItems )
  660. {
  661. BaseClass::Show( vecStartingItems );
  662. // Create output
  663. static CSchemaItemDefHandle pItemDef_CommonStatClock( "Common Stat Clock" );
  664. m_outputItem.SetItemDefIndex( pItemDef_CommonStatClock->GetDefinitionIndex() );
  665. m_outputItem.SetItemQuality( AE_UNIQUE ); // Unique by default
  666. m_outputItem.SetItemLevel( 0 ); // Hide this?
  667. m_outputItem.SetItemID( 0 );
  668. m_outputItem.SetInitialized( true );
  669. m_vecOutputImagePanels[0]->SetVisible( true );
  670. m_vecOutputItemPanels[0]->SetVisible( true );
  671. m_vecOutputItemPanels[0]->SetItem( &m_outputItem );
  672. if ( m_vecBoxTopNames.Count() )
  673. {
  674. CUniformRandomStream randomStream;
  675. randomStream.SetSeed( 0 );
  676. m_vecOutputImagePanels[0]->SetImage( m_vecBoxTopNames[randomStream.RandomInt( 0, m_vecBoxTopNames.Count() - 1 )] );
  677. }
  678. }
  679. //-----------------------------------------------------------------------------
  680. void CCraftCommonStatClockPanel::CreateSelectionPanel()
  681. {
  682. CStatClockCraftingSelectionPanel *pSelectionPanel = new CStatClockCraftingSelectionPanel( this );
  683. m_hSelectionPanel = (CCollectionCraftingSelectionPanel*)pSelectionPanel;
  684. }
  685. //-----------------------------------------------------------------------------
  686. // Purpose:
  687. //-----------------------------------------------------------------------------
  688. void CCraftCommonStatClockPanel::OnCommand( const char *command )
  689. {
  690. if ( FStrEq( "envelopesend", command ) )
  691. {
  692. GCSDK::CProtoBufMsg<CMsgCraftCommonStatClock> msg( k_EMsgGCCraftCommonStatClock );
  693. // Find out if the user owns this item or not and place in the proper bucket
  694. CPlayerInventory *pLocalInv = TFInventoryManager()->GetLocalInventory();
  695. if ( !pLocalInv )
  696. return;
  697. FOR_EACH_VEC( m_vecItemPanels, i )
  698. {
  699. if ( m_vecItemPanels[i]->GetItem() == NULL )
  700. return;
  701. msg.Body().add_item_id( m_vecItemPanels[i]->GetItem()->GetItemID() );
  702. }
  703. // Send if off
  704. GCClientSystem()->BSendMessage( msg );
  705. m_bWaitingForGCResponse = true;
  706. m_nFoundItemID.Purge();
  707. m_timerResponse.Start( 5.f );
  708. g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( this, "CollectionCrafting_LetterSend" );
  709. return;
  710. }
  711. BaseClass::OnCommand( command );
  712. }