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.

1758 lines
48 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //=============================================================================
  3. //
  4. //=============================================================================
  5. // Standard includes
  6. #define WIN32_LEAN_AND_MEAN
  7. #include <direct.h>
  8. #include <Windows.h>
  9. // Valve includes
  10. #include "itemtest/itemtest_controls.h"
  11. #include "vgui/IVGui.h"
  12. #include "vgui/IInput.h"
  13. #include "vgui/ISystem.h"
  14. #include "vgui/IPanel.h"
  15. #include "vgui_controls/CheckButton.h"
  16. #include "vgui_controls/ComboBox.h"
  17. #include "vgui_controls/FileOpenDialog.h"
  18. #include "vgui_controls/Menu.h"
  19. #include "vgui_controls/MenuItem.h"
  20. #include "vgui_controls/MessageBox.h"
  21. #include "vgui_controls/PanelListPanel.h"
  22. #include "vgui_controls/ScrollBar.h"
  23. #include "vgui_controls/TextImage.h"
  24. #include "tier1/fmtstr.h"
  25. // Local includes
  26. #include "dualpanellist.h"
  27. // Last include
  28. #include <tier0/memdbgon.h>
  29. //-----------------------------------------------------------------------------
  30. //
  31. //-----------------------------------------------------------------------------
  32. CItemUploadDialog *g_pItemUploadDialog = NULL;
  33. //=============================================================================
  34. //
  35. //=============================================================================
  36. CStatusLabel::CStatusLabel( vgui::Panel *pPanel, const char *pszName, bool bValid /* = false */ )
  37. : BaseClass( pPanel, pszName, "" )
  38. , m_bValid( bValid )
  39. , m_cValid( 0, 192, 0, 255 )
  40. , m_cInvalid( 192, 0, 0, 255 )
  41. {
  42. SetText( m_bValid ? "#valid" : "#invalid" );
  43. }
  44. //-----------------------------------------------------------------------------
  45. //
  46. //-----------------------------------------------------------------------------
  47. void CStatusLabel::ApplySchemeSettings( vgui::IScheme *pScheme )
  48. {
  49. BaseClass::ApplySchemeSettings( pScheme );
  50. SetContentAlignment( vgui::Label::a_center );
  51. m_cValid = pScheme->GetColor( "StatusLabel.ValidColor", m_cValid );
  52. m_cInvalid = pScheme->GetColor( "StatusLabel.InvalidColor", m_cInvalid );
  53. UpdateColors();
  54. }
  55. //-----------------------------------------------------------------------------
  56. //
  57. //-----------------------------------------------------------------------------
  58. void CStatusLabel::SetValid( bool bValid )
  59. {
  60. if ( bValid == m_bValid )
  61. return;
  62. m_bValid = bValid;
  63. SetText( m_bValid ? "#valid" : "#invalid" );
  64. UpdateColors();
  65. }
  66. //-----------------------------------------------------------------------------
  67. //
  68. //-----------------------------------------------------------------------------
  69. bool CStatusLabel::GetValid() const
  70. {
  71. return m_bValid;
  72. }
  73. //-----------------------------------------------------------------------------
  74. //
  75. //-----------------------------------------------------------------------------
  76. void CStatusLabel::UpdateColors()
  77. {
  78. // TODO: Set valid/invalid colors in scheme .res file...
  79. if ( GetValid() )
  80. {
  81. SetBgColor( m_cValid );
  82. }
  83. else
  84. {
  85. SetBgColor( m_cInvalid );
  86. }
  87. }
  88. //=============================================================================
  89. //
  90. //=============================================================================
  91. CItemUploadSubPanel::CItemUploadSubPanel( vgui::Panel *pParent, const char *pszName, const char *pszNextName )
  92. : BaseClass( pParent, pszName )
  93. , m_sNextName( pszNextName )
  94. {
  95. // Set the Wizard panel if the parent is a Wizard panel (it should be)
  96. vgui::WizardPanel *pWizardPanel = dynamic_cast< vgui::WizardPanel * >( pParent );
  97. if ( pWizardPanel )
  98. {
  99. SetWizardPanel( pWizardPanel );
  100. }
  101. CFmtStr sTmp;
  102. // Create the two standard widgets
  103. if ( CItemUpload::GetDevMode() )
  104. {
  105. sTmp.sprintf( "#itemtest_wizard_%s_info_dev", GetName() );
  106. const char *pszCheck = g_pVGuiLocalize->FindAsUTF8( sTmp );
  107. if ( pszCheck == sTmp.Access() )
  108. {
  109. sTmp.Clear();
  110. }
  111. }
  112. if ( sTmp.Length() <= 0 )
  113. {
  114. sTmp.sprintf( "#itemtest_wizard_%s_info", GetName() );
  115. }
  116. m_pLabel = new vgui::Label( this, "info", sTmp );
  117. m_pPanelListPanel = new vgui::PanelListPanel( this, "list" );
  118. m_pStatusLabel = new CStatusLabel( this, "statusLabel", false );
  119. m_pStatusText = new vgui::Label( this, "statusText", "wonk" );
  120. sTmp.sprintf( "itemtest_wizard_%s.res", GetName() );
  121. LoadControlSettings( sTmp );
  122. m_pLabel->SetAutoResize( PIN_TOPLEFT, AUTORESIZE_RIGHT, 0, 0, 0, 0 );
  123. m_pLabel->SizeToContents(); // Supposedly doesn't work until layout but kind of does...
  124. m_pLabel->SetWrap( true );
  125. m_pStatusLabel->SetAutoResize( PIN_BOTTOMLEFT, AUTORESIZE_NO, 0, 0, 0, 0 );
  126. if ( GetWizardPanel() && pszNextName == NULL )
  127. {
  128. GetWizardPanel()->SetFinishButtonEnabled( false );
  129. }
  130. }
  131. //-----------------------------------------------------------------------------
  132. //
  133. //-----------------------------------------------------------------------------
  134. void CItemUploadSubPanel::PerformLayout()
  135. {
  136. BaseClass::PerformLayout();
  137. int nOldWide = m_pLabel->GetWide();
  138. m_pLabel->SizeToContents();
  139. m_pLabel->SetWide( nOldWide );
  140. int nX = 0;
  141. int nY = 0;
  142. m_pLabel->GetPos( nX, nY );
  143. int nX1 = 0;
  144. int nY1 = 0;
  145. m_pStatusLabel->GetPos( nX1, nY1 );
  146. m_pPanelListPanel->SetBounds( nX, nY + m_pLabel->GetTall() + 10, m_pLabel->GetWide(), nY1 - nY - m_pLabel->GetTall() - 20 );
  147. bool bDone = false;
  148. for ( int i = 1; i < m_pPanelListPanel->GetItemCount(); i += 2 )
  149. {
  150. vgui::Panel *pPanelA0 = m_pPanelListPanel->GetItemLabel( i - 1 );
  151. vgui::Panel *pPanelA1 = m_pPanelListPanel->GetItemPanel( i - 1 );
  152. vgui::Panel *pPanelB0 = m_pPanelListPanel->GetItemLabel( i );
  153. vgui::Panel *pPanelB1 = m_pPanelListPanel->GetItemPanel( i );
  154. pPanelA0->SetTall( pPanelA1->GetTall() );
  155. pPanelB1->SetTall( pPanelB0->GetTall() );
  156. if ( !bDone )
  157. {
  158. bDone = true;
  159. m_pStatusLabel->SetSize( pPanelA0->GetWide(), pPanelB0->GetTall() );
  160. }
  161. }
  162. m_pStatusLabel->GetPos( nX, nY );
  163. m_pStatusText->SetPos( nX + m_pStatusLabel->GetWide() + 5, nY );
  164. m_pStatusText->SetWide( m_pLabel->GetWide() - nX );
  165. }
  166. //-----------------------------------------------------------------------------
  167. //
  168. //-----------------------------------------------------------------------------
  169. void CItemUploadSubPanel::ApplySchemeSettings( vgui::IScheme *pScheme )
  170. {
  171. BaseClass::ApplySchemeSettings( pScheme );
  172. if ( dynamic_cast< CGlobalSubPanel * >( this ) )
  173. return;
  174. if ( dynamic_cast< CGeometrySubPanel * >( this ) )
  175. return;
  176. /*
  177. #ifdef _DEBUG
  178. m_pLabel->SetBgColor( Color( 255, 127, 0, 255 ) );
  179. m_pPanelListPanel->SetBgColor( Color( 0, 127, 0 ) );
  180. for ( int i = 1; i < m_pPanelListPanel->GetItemCount(); i += 2 )
  181. {
  182. vgui::Panel *pPanel = m_pPanelListPanel->GetItemPanel( i );
  183. if ( pPanel )
  184. {
  185. pPanel->SetBgColor( Color( 0, 0, 255 ) );
  186. }
  187. }
  188. #endif // _DEBUG
  189. */
  190. }
  191. //-----------------------------------------------------------------------------
  192. //
  193. //-----------------------------------------------------------------------------
  194. void CItemUploadSubPanel::OnDisplay()
  195. {
  196. UpdateGUI();
  197. // UpdateStatus();
  198. }
  199. //-----------------------------------------------------------------------------
  200. //
  201. //-----------------------------------------------------------------------------
  202. vgui::WizardSubPanel *CItemUploadSubPanel::GetNextSubPanel()
  203. {
  204. return dynamic_cast< WizardSubPanel * >( GetWizardPanel()->FindChildByName( m_sNextName.Get() ) );
  205. }
  206. //-----------------------------------------------------------------------------
  207. //
  208. //-----------------------------------------------------------------------------
  209. bool CItemUploadSubPanel::UpdateStatus()
  210. {
  211. CItemUploadWizard *pItemUploadWizard = dynamic_cast< CItemUploadWizard * >( GetWizardPanel() );
  212. if ( !pItemUploadWizard )
  213. return false;
  214. if ( pItemUploadWizard->GetCurrentItemUploadSubPanel() != this )
  215. return false;
  216. CAsset &asset = pItemUploadWizard->Asset();
  217. CFmtStr sTmp;
  218. sTmp.sprintf( "#itemtest_wizard_%s_title", GetName() );
  219. CUtlString sRelativeDir;
  220. asset.GetRelativeDir( sRelativeDir, NULL );
  221. const char *pszTitle = g_pVGuiLocalize->FindAsUTF8( sTmp );
  222. CUtlString sStatusMsg;
  223. if ( asset.IsOk( sStatusMsg ) && !sRelativeDir.IsEmpty() && pszTitle )
  224. {
  225. sTmp.sprintf( "%s : %s", pszTitle, sRelativeDir.Get() );
  226. }
  227. else if ( !sStatusMsg.IsEmpty() )
  228. {
  229. }
  230. pItemUploadWizard->SetTitle( sTmp, true );
  231. bool bValid = true;
  232. for ( int i = 1; bValid && i < m_pPanelListPanel->GetItemCount(); i += 2 )
  233. {
  234. CStatusLabel *pStatusLabel = dynamic_cast< CStatusLabel * >( m_pPanelListPanel->GetItemLabel( i ) );
  235. if ( !pStatusLabel )
  236. continue;
  237. bValid = bValid && pStatusLabel->GetValid();
  238. }
  239. m_pStatusLabel->SetValid( bValid );
  240. sTmp.sprintf( "#itemtest_wizard_%s_%s", GetName(), bValid ? "valid" : "invalid" );
  241. m_pStatusText->SetText( sTmp );
  242. pItemUploadWizard->SetNextButtonEnabled( bValid );
  243. if ( pItemUploadWizard->GetCurrentSubPanel() == this )
  244. {
  245. pItemUploadWizard->SetFinishButtonEnabled( m_sNextName.IsEmpty() ? true : false );
  246. }
  247. return bValid;
  248. }
  249. //-----------------------------------------------------------------------------
  250. //
  251. //-----------------------------------------------------------------------------
  252. void CItemUploadSubPanel::AddStatusPanels( const char *pszPrefix )
  253. {
  254. CFmtStr sTmp;
  255. sTmp.sprintf( "%sStatusLabel", pszPrefix );
  256. CStatusLabel *pStatusLabel = new CStatusLabel( this, sTmp );
  257. sTmp.sprintf( "%sStatusText", pszPrefix );
  258. vgui::Label *pStatusText = new vgui::Label( this, sTmp, "" );
  259. m_pPanelListPanel->AddItem( pStatusLabel, pStatusText );
  260. }
  261. //-----------------------------------------------------------------------------
  262. //
  263. //-----------------------------------------------------------------------------
  264. void CItemUploadSubPanel::SetStatus( bool bValid, const char *pszPrefix, const char *pszMessage /* = NULL */, bool bHide /* = false */ )
  265. {
  266. CFmtStr sTmp;
  267. sTmp.sprintf( "%sStatusLabel", pszPrefix );
  268. CStatusLabel *pStatusLabel = dynamic_cast< CStatusLabel * >( m_pPanelListPanel->FindChildByName( sTmp, true ) );
  269. if ( pStatusLabel )
  270. {
  271. pStatusLabel->SetValid( bValid );
  272. pStatusLabel->SetVisible( !bHide );
  273. }
  274. sTmp.sprintf( "%sStatusText", pszPrefix );
  275. vgui::Label *pStatusText = dynamic_cast< vgui::Label * >( m_pPanelListPanel->FindChildByName( sTmp, true ) );
  276. if ( pStatusText )
  277. {
  278. if ( pszMessage )
  279. {
  280. pStatusText->SetText( pszMessage );
  281. }
  282. else
  283. {
  284. sTmp.sprintf( "#%s%s", pszPrefix, bValid ? "Valid" : "Invalid" );
  285. pStatusText->SetText( sTmp );
  286. }
  287. pStatusText->SetVisible( !bHide );
  288. }
  289. }
  290. //=============================================================================
  291. //
  292. //=============================================================================
  293. class CFileLocationPanel : public vgui::Panel
  294. {
  295. DECLARE_CLASS_SIMPLE( CFileLocationPanel, vgui::Panel );
  296. public:
  297. CFileLocationPanel( vgui::Panel *pParent, int nLodIndex )
  298. : BaseClass( pParent )
  299. {
  300. m_pButtonBrowse = new vgui::Button( this, "BrowseButton", "#BrowseButton", pParent );
  301. m_pButtonBrowse->SetCommand( new KeyValues( "Open" ) );
  302. m_pButtonBrowse->AddActionSignalTarget( pParent );
  303. m_pLabel = new vgui::Label( this, "FileLabel", "" );
  304. }
  305. virtual void PerformLayout()
  306. {
  307. BaseClass::PerformLayout();
  308. int w = 0;
  309. int h = 0;
  310. GetSize( w, h );
  311. m_pButtonBrowse->SizeToContents();
  312. SetTall( m_pButtonBrowse->GetTall() );
  313. m_pButtonBrowse->SetPos( w - m_pButtonBrowse->GetWide(), 0 );
  314. m_pLabel->SetSize( w - m_pButtonBrowse->GetWide(), m_pButtonBrowse->GetTall() );
  315. m_pLabel->SetPos( 0, 0 );
  316. }
  317. vgui::Button *m_pButtonBrowse;
  318. vgui::Label *m_pLabel;
  319. };
  320. //=============================================================================
  321. //
  322. //=============================================================================
  323. class CLODFileLocationPanel : public vgui::Panel
  324. {
  325. DECLARE_CLASS_SIMPLE( CLODFileLocationPanel, vgui::Panel );
  326. public:
  327. CLODFileLocationPanel( vgui::Panel *pParent, int nLodIndex )
  328. : BaseClass( pParent )
  329. {
  330. CFmtStr sButtonDelete;
  331. sButtonDelete.sprintf( "#LOD%dDelete", nLodIndex );
  332. m_pButtonDelete = new vgui::Button( this, sButtonDelete, sButtonDelete );
  333. m_pButtonDelete->SetCommand( new KeyValues( "Delete", "nLODIndex", nLodIndex ) );
  334. m_pButtonDelete->AddActionSignalTarget( pParent );
  335. CFmtStr sButton;
  336. sButton.sprintf( "#LOD%dButton", nLodIndex );
  337. m_pButtonBrowse = new vgui::Button( this, sButton, sButton, pParent );
  338. m_pButtonBrowse->SetCommand( new KeyValues( "Open", "nLODIndex", nLodIndex ) );
  339. m_pButtonBrowse->AddActionSignalTarget( pParent );
  340. CFmtStr sTextEntry;
  341. sTextEntry.sprintf( "#LOD%dTextEntry", nLodIndex );
  342. m_pLabel = new vgui::Label( this, sTextEntry, "" );
  343. }
  344. virtual void PerformLayout()
  345. {
  346. BaseClass::PerformLayout();
  347. int w = 0;
  348. int h = 0;
  349. GetSize( w, h );
  350. m_pButtonDelete->SizeToContents();
  351. m_pButtonBrowse->SizeToContents();
  352. SetTall( m_pButtonBrowse->GetTall() );
  353. m_pButtonDelete->SetPos( w - m_pButtonDelete->GetWide(), 0 );
  354. m_pButtonBrowse->SetPos( w - ( m_pButtonDelete->GetWide() + m_pButtonBrowse->GetWide() ), 0 );
  355. m_pLabel->SetSize( w - ( m_pButtonDelete->GetWide() + m_pButtonBrowse->GetWide() ), m_pButtonBrowse->GetTall() );
  356. m_pLabel->SetPos( 0, 0 );
  357. }
  358. vgui::Button *m_pButtonBrowse;
  359. vgui::Button *m_pButtonDelete;
  360. vgui::Label *m_pLabel;
  361. };
  362. //-----------------------------------------------------------------------------
  363. //
  364. //-----------------------------------------------------------------------------
  365. CGeometrySubPanel::CGeometrySubPanel( vgui::Panel *pParent, const char *pszName, const char *pszNextName )
  366. : BaseClass( pParent, pszName, pszNextName )
  367. {
  368. m_pFileOpenStateMachine = new vgui::FileOpenStateMachine( this, this );
  369. m_pFileOpenStateMachine->AddActionSignalTarget( this );
  370. }
  371. //-----------------------------------------------------------------------------
  372. //
  373. //-----------------------------------------------------------------------------
  374. void CGeometrySubPanel::UpdateGUI()
  375. {
  376. CItemUploadWizard *pItemUploadWizard = dynamic_cast< CItemUploadWizard * >( GetWizardPanel() );
  377. if ( !pItemUploadWizard )
  378. return;
  379. CAsset &asset = pItemUploadWizard->Asset();
  380. int nGeometryCount = m_pPanelListPanel->GetItemCount() / 2;
  381. for ( int i = 0; i < asset.TargetDMXCount(); ++i )
  382. {
  383. if ( i >= nGeometryCount )
  384. {
  385. AddGeometry();
  386. nGeometryCount = m_pPanelListPanel->GetItemCount() / 2;
  387. }
  388. if ( i >= nGeometryCount )
  389. break; // unrecoverable error
  390. CLODFileLocationPanel *pFileLocationPanel = dynamic_cast< CLODFileLocationPanel * >( m_pPanelListPanel->GetItemPanel( i * 2 ) );
  391. if ( !pFileLocationPanel )
  392. continue;
  393. vgui::Label *pLabel = pFileLocationPanel->m_pLabel;
  394. if ( !pLabel )
  395. continue;
  396. CSmartPtr< CTargetDMX > pTargetDmx = asset.GetTargetDMX( i );
  397. if ( !pTargetDmx )
  398. continue;
  399. pLabel->SetText( pTargetDmx->GetInputFile().Get() );
  400. }
  401. // Ensure an empty blank one at the end
  402. if ( nGeometryCount == asset.TargetDMXCount() )
  403. {
  404. AddGeometry();
  405. }
  406. else
  407. {
  408. // Remove superfluous
  409. while ( m_pPanelListPanel->GetItemCount() / 2 > ( asset.TargetDMXCount() + 1 ) )
  410. {
  411. m_pPanelListPanel->RemoveItem( m_pPanelListPanel->GetItemCount() - 1 );
  412. m_pPanelListPanel->RemoveItem( m_pPanelListPanel->GetItemCount() - 1 );
  413. }
  414. // Set last one to empty
  415. if ( ( m_pPanelListPanel->GetItemCount() / 2 ) == ( asset.TargetDMXCount() + 1 ) )
  416. {
  417. CLODFileLocationPanel *pFileLocationPanel = dynamic_cast< CLODFileLocationPanel * >( m_pPanelListPanel->GetItemPanel( m_pPanelListPanel->GetItemCount() - 2 ) );
  418. if ( pFileLocationPanel )
  419. {
  420. vgui::Label *pLabel = pFileLocationPanel->m_pLabel;
  421. if ( pLabel )
  422. {
  423. pLabel->SetText( "" );
  424. }
  425. }
  426. }
  427. }
  428. UpdateStatus();
  429. }
  430. //-----------------------------------------------------------------------------
  431. //
  432. //-----------------------------------------------------------------------------
  433. bool CGeometrySubPanel::UpdateStatus()
  434. {
  435. CItemUploadWizard *pItemUploadWizard = dynamic_cast< CItemUploadWizard * >( GetWizardPanel() );
  436. if ( !pItemUploadWizard )
  437. return false;
  438. CAsset &asset = pItemUploadWizard->Asset();
  439. CFmtStr sTmp;
  440. CFmtStr sErrString;
  441. int nLODIndex = 0;
  442. int nThisPolyCount = 0;
  443. int nLastPolyCount = 0;
  444. for ( int i = 0; i < m_pPanelListPanel->GetItemCount(); i += 2, ++nLODIndex )
  445. {
  446. CLODFileLocationPanel *pFileLocationPanel = dynamic_cast< CLODFileLocationPanel * >( m_pPanelListPanel->GetItemPanel( i ) );
  447. if ( !pFileLocationPanel )
  448. continue;
  449. vgui::Label *pLabel = pFileLocationPanel->m_pLabel;
  450. if ( !pLabel )
  451. continue;
  452. if ( i == ( m_pPanelListPanel->GetItemCount() - 4 ) )
  453. {
  454. pFileLocationPanel->m_pButtonDelete->SetEnabled( true );
  455. }
  456. else
  457. {
  458. pFileLocationPanel->m_pButtonDelete->SetEnabled( false );
  459. }
  460. sTmp.sprintf( "LOD%d", nLODIndex );
  461. if ( i < ( m_pPanelListPanel->GetItemCount() - 2 ) )
  462. {
  463. CSmartPtr< CTargetDMX > pTargetDMX = asset.GetTargetDMX( nLODIndex );
  464. if ( !pTargetDMX )
  465. {
  466. sErrString.sprintf( "Invalid Geometry: LOD %d is NULL", nLODIndex );
  467. SetStatus( false, sTmp, sErrString );
  468. continue;
  469. }
  470. CUtlString sStatusMsg;
  471. if ( !pTargetDMX->IsOk( sStatusMsg ) )
  472. {
  473. SetStatus( false, sStatusMsg.Get() );
  474. continue;
  475. }
  476. nLastPolyCount = nThisPolyCount;
  477. nThisPolyCount = pTargetDMX->GetPolyCount();
  478. if ( nThisPolyCount <= 0 )
  479. {
  480. sErrString.sprintf( "LOD %d has bad polygon count: %d", i, nThisPolyCount );
  481. SetStatus( false, sTmp, sErrString );
  482. continue;
  483. }
  484. if ( ( i > 0 ) && ( nThisPolyCount == nLastPolyCount ) )
  485. {
  486. sErrString.sprintf( "LOD %d (%d polys) has the same number of polygons as previous LOD %d (%d polys)",
  487. nLODIndex, nThisPolyCount, nLODIndex - 1, nLastPolyCount );
  488. SetStatus( false, sTmp, sErrString );
  489. continue;
  490. }
  491. if ( ( i > 0 ) && ( nThisPolyCount >= nLastPolyCount ) )
  492. {
  493. sErrString.sprintf( "LOD %d (%d polys) has more polygons than previous LOD %d (%d polys)",
  494. nLODIndex, nThisPolyCount, nLODIndex - 1, nLastPolyCount );
  495. SetStatus( false, sTmp, sErrString );
  496. continue;
  497. }
  498. SetStatus( true, sTmp );
  499. }
  500. else
  501. {
  502. SetStatus( true, sTmp, NULL, true );
  503. }
  504. }
  505. bool bValid = BaseClass::UpdateStatus();
  506. // In this case there are more validation checks to be performed
  507. // Ensure each LOD is non-empty
  508. if ( bValid )
  509. {
  510. sErrString.Clear();
  511. // Ensure at least two LODs
  512. if ( CItemUpload::GetDevMode() )
  513. {
  514. if ( asset.TargetDMXCount() < 1 )
  515. {
  516. bValid = false;
  517. sErrString.sprintf( "At least 1 LOD is required" );
  518. }
  519. }
  520. else if ( asset.TargetDMXCount() < 2 )
  521. {
  522. bValid = false;
  523. sErrString.sprintf( "At least 2 LODs are required" );
  524. }
  525. // Any other overall checks can go here
  526. m_pStatusLabel->SetValid( bValid );
  527. if ( !bValid )
  528. {
  529. // Not sure how to translate this message with parameters, etc...
  530. m_pStatusText->SetText( sErrString );
  531. }
  532. pItemUploadWizard->SetNextButtonEnabled( bValid );
  533. }
  534. return bValid;
  535. }
  536. //-----------------------------------------------------------------------------
  537. //
  538. //-----------------------------------------------------------------------------
  539. void CGeometrySubPanel::SetupFileOpenDialog(
  540. vgui::FileOpenDialog *pDialog,
  541. bool bOpenFile,
  542. const char *pszFileName,
  543. KeyValues *pContextKeyValues )
  544. {
  545. char pszStartingDir[ MAX_PATH ];
  546. if ( !vgui::system()->GetRegistryString(
  547. "HKEY_CURRENT_USER\\Software\\Valve\\itemtest\\geometry\\opendir",
  548. pszStartingDir, sizeof( pszStartingDir ) ) )
  549. {
  550. _getcwd( pszStartingDir, ARRAYSIZE( pszStartingDir ));
  551. CUtlString sVMod;
  552. CUtlString sContentDir;
  553. if ( CItemUpload::GetVMod( sVMod ) && !sVMod.IsEmpty() && CItemUpload::GetContentDir( sContentDir ) && !sContentDir.IsEmpty() && CItemUpload::FileExists( sContentDir.Get() ) )
  554. {
  555. sContentDir += "/";
  556. sContentDir += sVMod;
  557. sContentDir += "/models";
  558. CUtlString sTmp = sContentDir;
  559. sTmp += "/player";
  560. if ( CItemUpload::FileExists( sTmp.Get() ) )
  561. {
  562. sContentDir = sTmp;
  563. sTmp += "/items";
  564. if ( CItemUpload::FileExists( sTmp.Get() ) )
  565. {
  566. CItemUploadWizard *pItemUploadWizard = dynamic_cast< CItemUploadWizard * >( GetWizardPanel() );
  567. if ( pItemUploadWizard )
  568. {
  569. CAsset &asset = pItemUploadWizard->Asset();
  570. sContentDir = sTmp;
  571. sTmp += "/";
  572. sTmp += asset.GetClass();
  573. }
  574. // TODO: Add steam id?
  575. V_FixupPathName( pszStartingDir, ARRAYSIZE( pszStartingDir ), sTmp.Get() );
  576. }
  577. }
  578. }
  579. }
  580. pDialog->SetStartDirectoryContext( "itemtest_geometry_browser", pszStartingDir );
  581. if ( bOpenFile )
  582. {
  583. pDialog->AddFilter( "*.obj", "OBJ File (*.obj)", true, "obj" );
  584. pDialog->AddFilter( "*.smd", "Valve SMD File (*.smd)", false, "smd" );
  585. pDialog->AddFilter( "*.dmx", "Valve DMX File (*.dmx)", false, "dmx" );
  586. pDialog->AddFilter( "*.*", "All Files (*.*)", false, "geometry" );
  587. pDialog->SetTitle( "Open Geometry ( OBJ/SMD/DMX ) File", true );
  588. }
  589. }
  590. //-----------------------------------------------------------------------------
  591. //
  592. //-----------------------------------------------------------------------------
  593. bool CGeometrySubPanel::OnReadFileFromDisk(
  594. const char *pszFileName,
  595. const char *pszFileFormat,
  596. KeyValues *pContextKeyValues )
  597. {
  598. CItemUploadWizard *pItemUploadWizard = dynamic_cast< CItemUploadWizard * >( GetWizardPanel() );
  599. if ( !pItemUploadWizard )
  600. return false;
  601. const int nLODIndex = pContextKeyValues->GetInt( "nLODIndex", -1 );
  602. if ( nLODIndex < 0 )
  603. return false;
  604. char szBuf0[ MAX_PATH ];
  605. char szBuf1[ MAX_PATH ];
  606. // Extract path and save to registry to open browser there next time
  607. {
  608. V_strncpy( szBuf0, pszFileName, sizeof( szBuf0 ) );
  609. V_FixSlashes( szBuf0 );
  610. V_StripFilename( szBuf0 );
  611. _fullpath( szBuf1, szBuf0, ARRAYSIZE( szBuf1 ) );
  612. vgui::system()->SetRegistryString(
  613. "HKEY_CURRENT_USER\\Software\\Valve\\itemtest\\geometry\\opendir",
  614. szBuf1 );
  615. }
  616. // Get the full path
  617. _fullpath( szBuf1, pszFileName, ARRAYSIZE( szBuf1 ) );
  618. CAsset &asset = pItemUploadWizard->Asset();
  619. for ( int i = 0; i < asset.TargetDMXCount(); ++i )
  620. {
  621. CSmartPtr< CTargetDMX > pTargetDMX = asset.GetTargetDMX( i );
  622. if ( !pTargetDMX )
  623. continue;
  624. if ( !V_strcmp( pTargetDMX->GetInputFile().Get(), szBuf1 ) )
  625. {
  626. vgui::MessageBox *pMessageBox = new vgui::MessageBox( "#duplicate_file_title", "#duplicate_file_text", this );
  627. if ( pMessageBox )
  628. {
  629. pMessageBox->SetSize( 640, 480 );
  630. pMessageBox->SetMinimumSize( 320, 120 );
  631. pMessageBox->DoModal();
  632. }
  633. return false;
  634. }
  635. }
  636. bool bRet = false;
  637. if ( nLODIndex < asset.TargetDMXCount() )
  638. {
  639. bRet = asset.SetTargetDMX( nLODIndex, szBuf1 );
  640. }
  641. else if ( nLODIndex == asset.TargetDMXCount() )
  642. {
  643. const int nCheck = asset.AddTargetDMX( szBuf1 );
  644. Assert( nCheck == nLODIndex );
  645. bRet = ( nCheck >= 0 );
  646. }
  647. UpdateGUI();
  648. return bRet;
  649. }
  650. //-----------------------------------------------------------------------------
  651. //
  652. //-----------------------------------------------------------------------------
  653. bool CGeometrySubPanel::OnWriteFileToDisk(
  654. const char *pszFileName,
  655. const char *pszFileFormat,
  656. KeyValues *pContextKeyValues )
  657. {
  658. return false;
  659. }
  660. //-----------------------------------------------------------------------------
  661. //
  662. //-----------------------------------------------------------------------------
  663. void CGeometrySubPanel::OnOpen( int nLodIndex )
  664. {
  665. KeyValues *pContextKeyValues = new KeyValues( "FileOpen", "nLODIndex", nLodIndex );
  666. m_pFileOpenStateMachine->OpenFile( "geometry", pContextKeyValues );
  667. }
  668. //-----------------------------------------------------------------------------
  669. //
  670. //-----------------------------------------------------------------------------
  671. void CGeometrySubPanel::OnDelete( int nLodIndex )
  672. {
  673. CItemUploadWizard *pItemUploadWizard = dynamic_cast< CItemUploadWizard * >( GetWizardPanel() );
  674. if ( !pItemUploadWizard )
  675. return;
  676. CAsset &asset = pItemUploadWizard->Asset();
  677. asset.RemoveTargetDMX( nLodIndex );
  678. UpdateGUI();
  679. }
  680. //-----------------------------------------------------------------------------
  681. //
  682. //-----------------------------------------------------------------------------
  683. void CGeometrySubPanel::AddGeometry()
  684. {
  685. const int nLodIndex = m_pPanelListPanel->GetItemCount() / 2;
  686. CFmtStr sLabel;
  687. sLabel.sprintf( "#LOD%dLabel", nLodIndex );
  688. vgui::Label *pLabel = new vgui::Label( this, sLabel, sLabel );
  689. pLabel->SetContentAlignment( vgui::Label::a_center );
  690. CLODFileLocationPanel *pFileLocationPanel = new CLODFileLocationPanel( this, nLodIndex );
  691. m_pPanelListPanel->AddItem( pLabel, pFileLocationPanel );
  692. pFileLocationPanel->m_pLabel->AddActionSignalTarget( this );
  693. pFileLocationPanel->m_pButtonBrowse->AddActionSignalTarget( this );
  694. sLabel.sprintf( "lod%d", nLodIndex );
  695. AddStatusPanels( sLabel );
  696. }
  697. //=============================================================================
  698. //
  699. //=============================================================================
  700. class CVmtEntry : public CDualPanelList
  701. {
  702. DECLARE_CLASS_SIMPLE( CVmtEntry, CDualPanelList );
  703. public:
  704. MESSAGE_FUNC_PTR( OnTextChanged, "TextChanged", panel );
  705. MESSAGE_FUNC_PTR( OnOpen, "Open", panel );
  706. CVmtEntry( CMaterialSubPanel *pMaterialSubPanel, const char *pszName, int nVmtIndex )
  707. : CDualPanelList( pMaterialSubPanel, pszName )
  708. , m_pMaterialSubPanel( pMaterialSubPanel )
  709. , m_nVmtIndex( nVmtIndex )
  710. {
  711. {
  712. vgui::Label *pMaterialLabel = new vgui::Label( this, "MaterialLabel", "#MaterialLabel" );
  713. m_pMaterialName = new vgui::Label( this, "MaterialName", "#MaterialName" );
  714. AddItem( pMaterialLabel, m_pMaterialName );
  715. }
  716. {
  717. vgui::Label *pMaterialTypeLabel = new vgui::Label( this, "MaterialTypeLabel", "#MaterialTypeLabel" );
  718. m_pMaterialType = new vgui::ComboBox( this, "MaterialTypeComboBox", 0, false );
  719. m_pMaterialType->AddItem( "#Invalid", new KeyValues( "Invalid" ) );
  720. m_pMaterialType->AddItem( "#Primary", new KeyValues( "Primary" ) );
  721. m_pMaterialType->AddItem( "#Secondary", new KeyValues( "Secondary" ) );
  722. m_pMaterialType->AddItem( "#DuplicateOfPrimary", new KeyValues( "DuplicateOfPrimary" ) );
  723. m_pMaterialType->AddItem( "#DuplicateOfSecondary", new KeyValues( "DuplicateOfSecondary" ) );
  724. m_pMaterialType->AddActionSignalTarget( this );
  725. AddItem( pMaterialTypeLabel, m_pMaterialType );
  726. }
  727. {
  728. vgui::Label *pRedBlueLabel = new vgui::Label( this, "CommonRedBlueLabel", "#CommonRedBlueLabel" );
  729. m_pCommonRedBlue = new vgui::ComboBox( this, "CommonRedBlue", 0, false );
  730. m_pCommonRedBlue->AddItem( "#Common", new KeyValues( "Common" ) );
  731. m_pCommonRedBlue->AddItem( "#RedAndBlue", new KeyValues( "RedAndBlue" ) );
  732. m_pCommonRedBlue->AddActionSignalTarget( this );
  733. m_nCommonRedBlueId = AddItem( pRedBlueLabel, m_pCommonRedBlue );
  734. }
  735. {
  736. vgui::Label *pCommonTextureLabel = new vgui::Label( this, "CommonTextureLabel", "#CommonTextureLabel" );
  737. m_pCommonTextureFileLocation = new CFileLocationPanel( this, 0 );
  738. m_nCommonId = AddItem( pCommonTextureLabel, m_pCommonTextureFileLocation );
  739. }
  740. {
  741. vgui::Label *pRedTextureLabel = new vgui::Label( this, "RedTextureLabel", "#RedTextureLabel" );
  742. m_pRedTextureFileLocation = new CFileLocationPanel( this, 1 );
  743. m_nRedId = AddItem( pRedTextureLabel, m_pRedTextureFileLocation );
  744. }
  745. {
  746. vgui::Label *pBlueTextureLabel = new vgui::Label( this, "BlueTextureLabel", "#BlueTextureLabel" );
  747. m_pBlueTextureFileLocation = new CFileLocationPanel( this, 1 );
  748. m_nBlueId = AddItem( pBlueTextureLabel, m_pBlueTextureFileLocation );
  749. }
  750. {
  751. vgui::Label *pColorAlphaLabel = new vgui::Label( this, "ColorAlphaLabel", "#ColorAlphaLabel" );
  752. m_pColorAlpha = new vgui::ComboBox( this, "ColorAlphaComboBox", 0, false );
  753. m_pColorAlpha->AddItem( "#Nothing", new KeyValues( "None" ) );
  754. m_pColorAlpha->AddItem( "#Transparency", new KeyValues( "Transparency" ) );
  755. m_pColorAlpha->AddItem( "#Paintable", new KeyValues( "Paintable" ) );
  756. m_pColorAlpha->AddItem( "#SpecPhong", new KeyValues( "SpecPhong" ) );
  757. m_pColorAlpha->AddActionSignalTarget( this );
  758. m_nColorAlphaId = AddItem( pColorAlphaLabel, m_pColorAlpha );
  759. }
  760. {
  761. vgui::Label *pNormalMapLabel = new vgui::Label( this, "NormalMapLabel", "#NormalMapLabel" );
  762. m_pNormalTextureFileLocation = new CFileLocationPanel( this, 2 );
  763. m_nNormalId = AddItem( pNormalMapLabel, m_pNormalTextureFileLocation );
  764. }
  765. {
  766. vgui::Label *pNormalAlphaLabel = new vgui::Label( this, "NormalAlphaLabel", "#NormalAlphaLabel" );
  767. m_pNormalAlpha = new vgui::ComboBox( this, "NormalAlphaComboBox", 0, false );
  768. m_pNormalAlpha->AddItem( "#Nothing", new KeyValues( "None" ) );
  769. m_pNormalAlpha->AddItem( "#SpecPhong", new KeyValues( "SpecPhong" ) );
  770. m_pNormalAlpha->AddActionSignalTarget( this );
  771. m_nNormalAlphaId = AddItem( pNormalAlphaLabel, m_pNormalAlpha );
  772. }
  773. m_pCommonRedBlue->ActivateItem( 0 );
  774. SetItemVisible( m_nColorAlphaId, false );
  775. m_pColorAlpha->SilentActivateItem( 0 );
  776. SetItemVisible( m_nNormalAlphaId, false );
  777. m_pNormalAlpha->SilentActivateItem( 0 );
  778. }
  779. int m_nCommonRedBlueId;
  780. int m_nCommonId;
  781. int m_nRedId;
  782. int m_nBlueId;
  783. int m_nColorAlphaId;
  784. int m_nNormalId;
  785. int m_nNormalAlphaId;
  786. vgui::Label *m_pMaterialName;
  787. vgui::ComboBox *m_pMaterialType;
  788. vgui::ComboBox *m_pCommonRedBlue;
  789. CFileLocationPanel *m_pCommonTextureFileLocation;
  790. CFileLocationPanel *m_pRedTextureFileLocation;
  791. CFileLocationPanel *m_pBlueTextureFileLocation;
  792. vgui::ComboBox *m_pColorAlpha;
  793. CFileLocationPanel *m_pNormalTextureFileLocation;
  794. vgui::ComboBox *m_pNormalAlpha;
  795. CMaterialSubPanel *m_pMaterialSubPanel;
  796. int m_nVmtIndex;
  797. void SetMaterialId( const char *pszMaterialName )
  798. {
  799. if ( !m_pMaterialName )
  800. return;
  801. m_pMaterialName->SetText( pszMaterialName );
  802. }
  803. };
  804. //-----------------------------------------------------------------------------
  805. //
  806. //-----------------------------------------------------------------------------
  807. void CVmtEntry::OnTextChanged( vgui::Panel *pPanel )
  808. {
  809. CTargetVMT *pTargetVMT = m_pMaterialSubPanel->GetTargetVMT( m_nVmtIndex );
  810. if ( !pTargetVMT )
  811. return;
  812. bool bUpdate = false;
  813. if ( pPanel == m_pMaterialType )
  814. {
  815. KeyValues *pUserData = m_pMaterialType->GetActiveItemUserData();
  816. if ( pUserData )
  817. {
  818. if ( !V_strcmp( "Invalid", pUserData->GetName() ) )
  819. {
  820. pTargetVMT->SetMaterialType( CTargetVMT::kInvalidMaterialType );
  821. }
  822. else if ( !V_strcmp( "Primary", pUserData->GetName() ) )
  823. {
  824. pTargetVMT->SetMaterialType( CTargetVMT::kPrimary );
  825. }
  826. else if ( !V_strcmp( "Secondary", pUserData->GetName() ) )
  827. {
  828. pTargetVMT->SetMaterialType( CTargetVMT::kSecondary );
  829. }
  830. else if ( !V_strcmp( "DuplicateOfPrimary", pUserData->GetName() ) )
  831. {
  832. pTargetVMT->SetDuplicate( CTargetVMT::kPrimary );
  833. }
  834. else if ( !V_strcmp( "DuplicateOfSecondary", pUserData->GetName() ) )
  835. {
  836. pTargetVMT->SetDuplicate( CTargetVMT::kSecondary );
  837. }
  838. else
  839. {
  840. AssertMsg1( 0, "Unknown Material Type: %s\n", pUserData->GetName() );
  841. }
  842. bUpdate = true;
  843. }
  844. }
  845. else if ( pPanel == m_pCommonRedBlue )
  846. {
  847. KeyValues *pUserData = m_pCommonRedBlue->GetActiveItemUserData();
  848. if ( pUserData )
  849. {
  850. const bool bCommon = !V_strcmp( "Common", pUserData->GetName() );
  851. pTargetVMT->SetColorMapCommon( bCommon );
  852. bUpdate = true;
  853. }
  854. }
  855. else if ( pPanel == m_pColorAlpha )
  856. {
  857. KeyValues *pUserData = m_pColorAlpha->GetActiveItemUserData();
  858. if ( pUserData )
  859. {
  860. const char *pszUserData = pUserData->GetName();
  861. if ( StringHasPrefix( pszUserData, "T" ) )
  862. {
  863. pTargetVMT->SetColorAlphaType( CTargetVMT::kTransparency );
  864. }
  865. else if ( StringHasPrefix( pszUserData, "P" ) )
  866. {
  867. pTargetVMT->SetColorAlphaType( CTargetVMT::kPaintable );
  868. }
  869. else if ( StringHasPrefix( pszUserData, "S" ) )
  870. {
  871. pTargetVMT->SetColorAlphaType( CTargetVMT::kColorSpecPhong );
  872. }
  873. else
  874. {
  875. pTargetVMT->SetColorAlphaType( CTargetVMT::kNoColorAlpha );
  876. }
  877. bUpdate = true;
  878. }
  879. }
  880. else if ( pPanel == m_pNormalAlpha )
  881. {
  882. KeyValues *pUserData = m_pNormalAlpha->GetActiveItemUserData();
  883. if ( pUserData )
  884. {
  885. const char *pszUserData = pUserData->GetName();
  886. if ( StringHasPrefix( pszUserData, "S" ) )
  887. {
  888. pTargetVMT->SetNormalAlphaType( CTargetVMT::kNormalSpecPhong );
  889. }
  890. else
  891. {
  892. pTargetVMT->SetNormalAlphaType( CTargetVMT::kNoNormalAlpha );
  893. }
  894. bUpdate = true;
  895. }
  896. }
  897. if ( bUpdate )
  898. {
  899. InvalidateLayout();
  900. m_pMaterialSubPanel->InvalidateLayout();
  901. m_pMaterialSubPanel->UpdateGUI();
  902. }
  903. }
  904. //-----------------------------------------------------------------------------
  905. //
  906. //-----------------------------------------------------------------------------
  907. void CVmtEntry::OnOpen( vgui::Panel *pPanel )
  908. {
  909. if ( !m_pMaterialSubPanel )
  910. return;
  911. if ( pPanel == m_pCommonTextureFileLocation->m_pButtonBrowse )
  912. {
  913. m_pMaterialSubPanel->Browse( this, CMaterialSubPanel::kCommon );
  914. }
  915. else if ( pPanel == m_pRedTextureFileLocation->m_pButtonBrowse )
  916. {
  917. m_pMaterialSubPanel->Browse( this, CMaterialSubPanel::kRed );
  918. }
  919. else if ( pPanel == m_pBlueTextureFileLocation->m_pButtonBrowse )
  920. {
  921. m_pMaterialSubPanel->Browse( this, CMaterialSubPanel::kBlue );
  922. }
  923. else if ( pPanel == m_pNormalTextureFileLocation->m_pButtonBrowse )
  924. {
  925. m_pMaterialSubPanel->Browse( this, CMaterialSubPanel::kNormal );
  926. }
  927. }
  928. //=============================================================================
  929. //
  930. //=============================================================================
  931. CMaterialSubPanel::CMaterialSubPanel( vgui::Panel *pParent, const char *pszName, const char *pszNextName )
  932. : BaseClass( pParent, pszName, pszNextName )
  933. {
  934. m_pFileOpenStateMachine = new vgui::FileOpenStateMachine( this, this );
  935. m_pFileOpenStateMachine->AddActionSignalTarget( this );
  936. }
  937. //-----------------------------------------------------------------------------
  938. //
  939. //-----------------------------------------------------------------------------
  940. void CMaterialSubPanel::InvalidateLayout()
  941. {
  942. BaseClass::InvalidateLayout();
  943. m_pPanelListPanel->InvalidateLayout();
  944. }
  945. //-----------------------------------------------------------------------------
  946. //
  947. //-----------------------------------------------------------------------------
  948. void CMaterialSubPanel::UpdateGUI()
  949. {
  950. CItemUploadWizard *pItemUploadWizard = dynamic_cast< CItemUploadWizard * >( GetWizardPanel() );
  951. if ( !pItemUploadWizard )
  952. return;
  953. CAsset &asset = pItemUploadWizard->Asset();
  954. int nMaterialCount = m_pPanelListPanel->GetItemCount() / 2;
  955. CFmtStr sTmp;
  956. // Add new gui elements & update existing
  957. for ( int i = 0; i < asset.GetTargetVMTCount(); ++i )
  958. {
  959. if ( i >= nMaterialCount )
  960. {
  961. AddMaterial();
  962. nMaterialCount = m_pPanelListPanel->GetItemCount() / 2;
  963. }
  964. if ( i >= nMaterialCount )
  965. break; // unrecoverable error
  966. CTargetVMT *pTargetVmt = asset.GetTargetVMT( i );
  967. Assert( pTargetVmt );
  968. if ( !pTargetVmt )
  969. continue;
  970. CVmtEntry *pVmtEntry = dynamic_cast< CVmtEntry * >( m_pPanelListPanel->GetItemPanel( i * 2 ) );
  971. if ( !pVmtEntry )
  972. continue;
  973. CUtlString sMaterialId;
  974. pTargetVmt->GetMaterialId( sMaterialId );
  975. pVmtEntry->SetMaterialId( sMaterialId.Get() );
  976. const bool bCommon = pTargetVmt->GetColorMapCommon();
  977. pVmtEntry->m_pCommonRedBlue->SilentActivateItemByRow( bCommon ? 0 : 1 );
  978. bool bVisible = true;
  979. if ( pTargetVmt->GetDuplicate() )
  980. {
  981. bVisible = false;
  982. switch ( pTargetVmt->GetMaterialType() )
  983. {
  984. case CTargetVMT::kInvalidMaterialType:
  985. pVmtEntry->m_pMaterialType->SilentActivateItemByRow( 0 );
  986. break;
  987. case CTargetVMT::kPrimary:
  988. pVmtEntry->m_pMaterialType->SilentActivateItemByRow( 3 );
  989. break;
  990. case CTargetVMT::kSecondary:
  991. pVmtEntry->m_pMaterialType->SilentActivateItemByRow( 4 );
  992. break;
  993. default:
  994. pVmtEntry->m_pMaterialType->ActivateItem( 0 );
  995. break;
  996. }
  997. }
  998. else
  999. {
  1000. switch ( pTargetVmt->GetMaterialType() )
  1001. {
  1002. case CTargetVMT::kInvalidMaterialType:
  1003. pVmtEntry->m_pMaterialType->SilentActivateItemByRow( 0 );
  1004. break;
  1005. case CTargetVMT::kPrimary:
  1006. pVmtEntry->m_pMaterialType->SilentActivateItemByRow( 1 );
  1007. break;
  1008. case CTargetVMT::kSecondary:
  1009. pVmtEntry->m_pMaterialType->SilentActivateItemByRow( 2 );
  1010. break;
  1011. default:
  1012. pVmtEntry->m_pMaterialType->ActivateItem( 0 );
  1013. break;
  1014. }
  1015. }
  1016. pVmtEntry->SetItemVisible( pVmtEntry->m_nCommonRedBlueId, bVisible );
  1017. pVmtEntry->SetItemVisible( pVmtEntry->m_nCommonId, bVisible && bCommon );
  1018. pVmtEntry->SetItemVisible( pVmtEntry->m_nRedId, bVisible && !bCommon );
  1019. pVmtEntry->SetItemVisible( pVmtEntry->m_nBlueId, bVisible && !bCommon );
  1020. pVmtEntry->SetItemVisible( pVmtEntry->m_nNormalId, bVisible );
  1021. bool bColorVisible = false;
  1022. CSmartPtr< CTargetVTF > pCommonTargetVTF = pTargetVmt->GetCommonTargetVTF();
  1023. if ( pCommonTargetVTF.IsValid() )
  1024. {
  1025. pVmtEntry->m_pCommonTextureFileLocation->m_pLabel->SetText( pCommonTargetVTF->GetInputFile() );
  1026. if ( pTargetVmt->GetColorMapCommon() && pCommonTargetVTF->HasAlpha() )
  1027. {
  1028. bColorVisible = true;
  1029. }
  1030. }
  1031. else
  1032. {
  1033. pVmtEntry->m_pCommonTextureFileLocation->m_pLabel->SetText( "" );
  1034. bColorVisible = false;
  1035. }
  1036. switch ( pTargetVmt->GetColorAlphaType() )
  1037. {
  1038. case CTargetVMT::kNoColorAlpha:
  1039. pVmtEntry->m_pColorAlpha->SilentActivateItemByRow( CTargetVMT::kNoColorAlpha );
  1040. break;
  1041. case CTargetVMT::kTransparency:
  1042. pVmtEntry->m_pColorAlpha->SilentActivateItemByRow( CTargetVMT::kTransparency );
  1043. break;
  1044. case CTargetVMT::kPaintable:
  1045. pVmtEntry->m_pColorAlpha->SilentActivateItemByRow( CTargetVMT::kPaintable );
  1046. break;
  1047. case CTargetVMT::kColorSpecPhong:
  1048. pVmtEntry->m_pColorAlpha->SilentActivateItemByRow( CTargetVMT::kColorSpecPhong );
  1049. break;
  1050. default:
  1051. pVmtEntry->m_pColorAlpha->SilentActivateItemByRow( CTargetVMT::kNoColorAlpha );
  1052. break;
  1053. }
  1054. CSmartPtr< CTargetVTF > pRedTargetVTF = pTargetVmt->GetRedTargetVTF();
  1055. CSmartPtr< CTargetVTF > pBlueTargetVTF = pTargetVmt->GetBlueTargetVTF();
  1056. if ( pRedTargetVTF.IsValid() )
  1057. {
  1058. pVmtEntry->m_pRedTextureFileLocation->m_pLabel->SetText( pRedTargetVTF->GetInputFile() );
  1059. }
  1060. else
  1061. {
  1062. pVmtEntry->m_pRedTextureFileLocation->m_pLabel->SetText( "" );
  1063. }
  1064. if ( pBlueTargetVTF.IsValid() )
  1065. {
  1066. pVmtEntry->m_pBlueTextureFileLocation->m_pLabel->SetText( pBlueTargetVTF->GetInputFile() );
  1067. }
  1068. else
  1069. {
  1070. pVmtEntry->m_pBlueTextureFileLocation->m_pLabel->SetText( "" );
  1071. }
  1072. if ( !pTargetVmt->GetColorMapCommon() && pRedTargetVTF.IsValid() && pBlueTargetVTF.IsValid() )
  1073. {
  1074. if ( pRedTargetVTF->HasAlpha() && pBlueTargetVTF->HasAlpha() )
  1075. {
  1076. bColorVisible = true;
  1077. }
  1078. }
  1079. pVmtEntry->SetItemVisible( pVmtEntry->m_nColorAlphaId, bVisible && bColorVisible );
  1080. bool bNormalVisible = false;
  1081. CSmartPtr< CTargetVTF > pNormalTargetVTF = pTargetVmt->GetNormalTargetVTF();
  1082. if ( pNormalTargetVTF.IsValid() )
  1083. {
  1084. pVmtEntry->m_pNormalTextureFileLocation->m_pLabel->SetText( pNormalTargetVTF->GetInputFile() );
  1085. if ( pNormalTargetVTF->HasAlpha() )
  1086. {
  1087. bNormalVisible = true;
  1088. }
  1089. }
  1090. switch ( pTargetVmt->GetNormalAlphaType() )
  1091. {
  1092. case CTargetVMT::kNoNormalAlpha:
  1093. pVmtEntry->m_pNormalAlpha->SilentActivateItemByRow( CTargetVMT::kNoNormalAlpha );
  1094. break;
  1095. case CTargetVMT::kNormalSpecPhong:
  1096. pVmtEntry->m_pNormalAlpha->SilentActivateItemByRow( CTargetVMT::kNormalSpecPhong );
  1097. break;
  1098. default:
  1099. pVmtEntry->m_pNormalAlpha->SilentActivateItemByRow( CTargetVMT::kNoNormalAlpha );
  1100. break;
  1101. }
  1102. pVmtEntry->SetItemVisible( pVmtEntry->m_nNormalAlphaId, bVisible && bNormalVisible );
  1103. pVmtEntry->InvalidateLayout();
  1104. }
  1105. // Remove superfluous
  1106. while ( ( m_pPanelListPanel->GetItemCount() / 2 ) > asset.GetTargetVMTCount() )
  1107. {
  1108. m_pPanelListPanel->RemoveItem( m_pPanelListPanel->GetItemCount() - 1 );
  1109. m_pPanelListPanel->RemoveItem( m_pPanelListPanel->GetItemCount() - 1 );
  1110. }
  1111. InvalidateLayout();
  1112. UpdateStatus();
  1113. }
  1114. //-----------------------------------------------------------------------------
  1115. // TODO: Set status
  1116. //-----------------------------------------------------------------------------
  1117. bool CMaterialSubPanel::UpdateStatus()
  1118. {
  1119. CFmtStr sTmp;
  1120. int nIndex = 0;
  1121. for ( int i = 0; i < m_pPanelListPanel->GetItemCount(); i += 2, ++nIndex )
  1122. {
  1123. CVmtEntry *pVmtEntry = dynamic_cast< CVmtEntry * >( m_pPanelListPanel->GetItemPanel( i ) );
  1124. if ( !pVmtEntry )
  1125. continue;
  1126. CTargetVMT *pTargetVMT = GetTargetVMT( pVmtEntry->m_nVmtIndex );
  1127. Assert( pTargetVMT );
  1128. if ( !pTargetVMT )
  1129. continue;
  1130. sTmp.sprintf( "VMT%d", nIndex );
  1131. CUtlString sMsg;
  1132. if ( pTargetVMT->IsOk( sMsg ) )
  1133. {
  1134. SetStatus( true, sTmp );
  1135. continue;
  1136. }
  1137. if ( sMsg.IsEmpty() )
  1138. {
  1139. SetStatus( false, sTmp, "VMT is not valid\n" );
  1140. }
  1141. else
  1142. {
  1143. SetStatus( false, sTmp, sMsg.Get() );
  1144. }
  1145. }
  1146. bool bValid = BaseClass::UpdateStatus();
  1147. return bValid;
  1148. }
  1149. //-----------------------------------------------------------------------------
  1150. //
  1151. //-----------------------------------------------------------------------------
  1152. void CMaterialSubPanel::SetupFileOpenDialog(
  1153. vgui::FileOpenDialog *pDialog,
  1154. bool bOpenFile,
  1155. const char *pszFileName,
  1156. KeyValues *pContextKeyValues )
  1157. {
  1158. char pszStartingDir[ MAX_PATH ];
  1159. if ( !vgui::system()->GetRegistryString(
  1160. "HKEY_CURRENT_USER\\Software\\Valve\\itemtest\\texture\\opendir",
  1161. pszStartingDir, sizeof( pszStartingDir ) ) )
  1162. {
  1163. _getcwd( pszStartingDir, ARRAYSIZE( pszStartingDir ));
  1164. CUtlString sVMod;
  1165. CUtlString sContentDir;
  1166. if ( CItemUpload::GetVMod( sVMod ) && !sVMod.IsEmpty() && CItemUpload::GetContentDir( sContentDir ) && !sContentDir.IsEmpty() && CItemUpload::FileExists( sContentDir.Get() ) )
  1167. {
  1168. sContentDir += "/";
  1169. sContentDir += sVMod;
  1170. sContentDir += "/materialsrc/models";
  1171. CUtlString sTmp = sContentDir;
  1172. sTmp += "/player";
  1173. if ( CItemUpload::FileExists( sTmp.Get() ) )
  1174. {
  1175. sContentDir = sTmp;
  1176. sTmp += "/items";
  1177. if ( CItemUpload::FileExists( sTmp.Get() ) )
  1178. {
  1179. CItemUploadWizard *pItemUploadWizard = dynamic_cast< CItemUploadWizard * >( GetWizardPanel() );
  1180. if ( pItemUploadWizard )
  1181. {
  1182. CAsset &asset = pItemUploadWizard->Asset();
  1183. sContentDir = sTmp;
  1184. sTmp += "/";
  1185. sTmp += asset.GetClass();
  1186. }
  1187. // TODO: Add steam id?
  1188. V_FixupPathName( pszStartingDir, ARRAYSIZE( pszStartingDir ), sTmp.Get() );
  1189. }
  1190. }
  1191. }
  1192. }
  1193. pDialog->SetStartDirectoryContext( "itemtest_texture_browser", pszStartingDir );
  1194. // TODO: Remember the mask the user likes
  1195. if ( bOpenFile )
  1196. {
  1197. pDialog->AddFilter( "*.tga", "Targa TrueVision File (*.tga)", true, "tga" );
  1198. pDialog->AddFilter( "*.psd", "Photoshop Document (*.psd)", false, "psd" );
  1199. pDialog->SetTitle( "Open Texture File", true );
  1200. }
  1201. }
  1202. //-----------------------------------------------------------------------------
  1203. //
  1204. //-----------------------------------------------------------------------------
  1205. bool CMaterialSubPanel::OnReadFileFromDisk(
  1206. const char *pszFileName,
  1207. const char *pszFileFormat,
  1208. KeyValues *pContextKeyValues )
  1209. {
  1210. CItemUploadWizard *pItemUploadWizard = dynamic_cast< CItemUploadWizard * >( GetWizardPanel() );
  1211. if ( !pItemUploadWizard )
  1212. return false;
  1213. char szBuf0[ MAX_PATH ];
  1214. char szBuf1[ MAX_PATH ];
  1215. // Extract path and save to registry to open browser there next time
  1216. {
  1217. V_strncpy( szBuf0, pszFileName, sizeof( szBuf0 ) );
  1218. V_FixSlashes( szBuf0 );
  1219. V_StripFilename( szBuf0 );
  1220. _fullpath( szBuf1, szBuf0, ARRAYSIZE( szBuf1 ) );
  1221. vgui::system()->SetRegistryString(
  1222. "HKEY_CURRENT_USER\\Software\\Valve\\itemtest\\texture\\opendir",
  1223. szBuf1 );
  1224. }
  1225. // Get the full path
  1226. _fullpath( szBuf1, pszFileName, ARRAYSIZE( szBuf1 ) );
  1227. CAsset &asset = pItemUploadWizard->Asset();
  1228. CVmtEntry *pVmtEntry = reinterpret_cast< CVmtEntry * >( pContextKeyValues->GetPtr( "pVmtEntry" ) );
  1229. const Browse_t nBrowseType = static_cast< Browse_t >( pContextKeyValues->GetInt( "nBrowseType" ) );
  1230. bool bReturnVal = false;
  1231. for ( int i = 0; i < m_pPanelListPanel->GetItemCount(); i += 2 )
  1232. {
  1233. if ( pVmtEntry == dynamic_cast< CVmtEntry * >( m_pPanelListPanel->GetItemPanel( i ) ) )
  1234. {
  1235. const int nVmtIndex = i / 2;
  1236. CTargetVMT *pTargetVMT = asset.GetTargetVMT( nVmtIndex );
  1237. if ( pTargetVMT )
  1238. {
  1239. bReturnVal = true;
  1240. switch( nBrowseType )
  1241. {
  1242. case CMaterialSubPanel::kCommon:
  1243. pTargetVMT->SetCommonTargetVTF( szBuf1 );
  1244. break;
  1245. case CMaterialSubPanel::kRed:
  1246. pTargetVMT->SetRedTargetVTF( szBuf1 );
  1247. break;
  1248. case CMaterialSubPanel::kBlue:
  1249. pTargetVMT->SetBlueTargetVTF( szBuf1 );
  1250. break;
  1251. case CMaterialSubPanel::kNormal:
  1252. pTargetVMT->SetNormalTargetVTF( szBuf1 );
  1253. break;
  1254. default:
  1255. bReturnVal = false;
  1256. break;
  1257. }
  1258. }
  1259. break;
  1260. }
  1261. }
  1262. UpdateGUI();
  1263. return bReturnVal;
  1264. }
  1265. //-----------------------------------------------------------------------------
  1266. //
  1267. //-----------------------------------------------------------------------------
  1268. bool CMaterialSubPanel::OnWriteFileToDisk(
  1269. const char *pszFileName,
  1270. const char *pszFileFormat,
  1271. KeyValues *pContextKeyValues )
  1272. {
  1273. return false;
  1274. }
  1275. //-----------------------------------------------------------------------------
  1276. //
  1277. //-----------------------------------------------------------------------------
  1278. void CMaterialSubPanel::Browse( CVmtEntry *pVmtEntry, Browse_t nBrowseType )
  1279. {
  1280. if ( !pVmtEntry )
  1281. return;
  1282. KeyValues *pContextKeyValues = new KeyValues( "FileOpen", "nBrowseType", nBrowseType );
  1283. pContextKeyValues->SetPtr( "pVmtEntry", pVmtEntry );
  1284. m_pFileOpenStateMachine->OpenFile( "geometry", pContextKeyValues );
  1285. }
  1286. //-----------------------------------------------------------------------------
  1287. //
  1288. //-----------------------------------------------------------------------------
  1289. CTargetVMT *CMaterialSubPanel::GetTargetVMT( int nTargetVMTIndex )
  1290. {
  1291. CItemUploadWizard *pItemUploadWizard = dynamic_cast< CItemUploadWizard * >( GetWizardPanel() );
  1292. if ( !pItemUploadWizard )
  1293. return NULL;
  1294. return pItemUploadWizard->Asset().GetTargetVMT( nTargetVMTIndex );
  1295. }
  1296. //-----------------------------------------------------------------------------
  1297. //
  1298. //-----------------------------------------------------------------------------
  1299. void CMaterialSubPanel::AddMaterial()
  1300. {
  1301. const int nIndex = m_pPanelListPanel->GetItemCount() / 2;
  1302. CFmtStr sLabel;
  1303. sLabel.sprintf( "#VMT%dLabel", nIndex );
  1304. vgui::Label *pLabel = new vgui::Label( this, sLabel, sLabel );
  1305. pLabel->SetContentAlignment( vgui::Label::a_center );
  1306. sLabel.sprintf( "#VMT%dLabel2", nIndex );
  1307. CVmtEntry *pVmtEntry = new CVmtEntry( this, sLabel, nIndex );
  1308. pVmtEntry->SetAutoResize( PIN_TOPLEFT, AUTORESIZE_RIGHT, 0, 0, 0, 0 );
  1309. m_pPanelListPanel->AddItem( pLabel, pVmtEntry );
  1310. sLabel.sprintf( "vmt%d", nIndex );
  1311. AddStatusPanels( sLabel );
  1312. }
  1313. //-----------------------------------------------------------------------------
  1314. //
  1315. //-----------------------------------------------------------------------------
  1316. CItemUploadWizard::CItemUploadWizard(
  1317. vgui::Panel *pParent,
  1318. const char *pszName )
  1319. : BaseClass( pParent, pszName )
  1320. {
  1321. SetSize( 1024, 768 );
  1322. SetMinimumSize( 640, 480 );
  1323. vgui::WizardSubPanel *pSubPanel = NULL;
  1324. vgui::DHANDLE< vgui::WizardSubPanel > hSubPanel;
  1325. pSubPanel = new CGlobalSubPanel( this, "global", "geometry" );
  1326. pSubPanel->SetVisible( false );
  1327. hSubPanel = pSubPanel;
  1328. m_hSubPanelList.AddToTail( hSubPanel );
  1329. pSubPanel = new CGeometrySubPanel( this, "geometry", "texture" );
  1330. pSubPanel->SetVisible( false );
  1331. hSubPanel = pSubPanel;
  1332. m_hSubPanelList.AddToTail( hSubPanel );
  1333. pSubPanel = new CMaterialSubPanel( this, "texture", "final" );
  1334. pSubPanel->SetVisible( false );
  1335. hSubPanel = pSubPanel;
  1336. m_hSubPanelList.AddToTail( hSubPanel );
  1337. m_pFinalSubPanel = new CFinalSubPanel( this, "final", NULL );
  1338. pSubPanel = m_pFinalSubPanel;
  1339. pSubPanel->SetVisible( false );
  1340. hSubPanel = pSubPanel;
  1341. m_hSubPanelList.AddToTail( hSubPanel );
  1342. Run();
  1343. }
  1344. //-----------------------------------------------------------------------------
  1345. //
  1346. //-----------------------------------------------------------------------------
  1347. CItemUploadWizard::~CItemUploadWizard()
  1348. {
  1349. }
  1350. //-----------------------------------------------------------------------------
  1351. //
  1352. //-----------------------------------------------------------------------------
  1353. void CItemUploadWizard::Run()
  1354. {
  1355. vgui::WizardSubPanel *pStartPanel = dynamic_cast< vgui::WizardSubPanel * >( FindChildByName( "global" ) );
  1356. if ( !pStartPanel )
  1357. {
  1358. Error( "Missing CItemUploadWizard global Panel" );
  1359. }
  1360. BaseClass::Run( pStartPanel );
  1361. MoveToCenterOfScreen();
  1362. Activate();
  1363. vgui::input()->SetAppModalSurface( GetVPanel() );
  1364. CGlobalSubPanel *pGlobalSubPanel = dynamic_cast< CGlobalSubPanel * >( pStartPanel );
  1365. if ( pGlobalSubPanel )
  1366. {
  1367. pGlobalSubPanel->UpdateStatus();
  1368. }
  1369. }
  1370. //-----------------------------------------------------------------------------
  1371. //
  1372. //-----------------------------------------------------------------------------
  1373. void CItemUploadWizard::UpdateGUI()
  1374. {
  1375. for ( int i = 0; i < m_hSubPanelList.Count(); ++i )
  1376. {
  1377. CItemUploadSubPanel *pSubPanel = dynamic_cast< CItemUploadSubPanel * >( m_hSubPanelList.Element( i ).Get() );
  1378. if ( !pSubPanel )
  1379. continue;
  1380. pSubPanel->UpdateGUI();
  1381. }
  1382. CItemUploadSubPanel *pItemUploadSubPanel = dynamic_cast< CItemUploadSubPanel * >( GetCurrentSubPanel() );
  1383. if ( pItemUploadSubPanel )
  1384. {
  1385. pItemUploadSubPanel->UpdateStatus();
  1386. }
  1387. }
  1388. //-----------------------------------------------------------------------------
  1389. //
  1390. //-----------------------------------------------------------------------------
  1391. void CItemUploadWizard::OnFinishButton()
  1392. {
  1393. m_pFinalSubPanel->OnZip();
  1394. }