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.

409 lines
11 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. //=============================================================================
  4. // Valve includes
  5. #include "itemtest/itemtest_controls.h"
  6. #include "vgui_controls/ComboBox.h"
  7. #include "vgui_controls/MenuItem.h"
  8. #include "vgui_controls/PanelListPanel.h"
  9. #include "vgui/ISystem.h"
  10. #include "vgui_controls/MessageBox.h"
  11. #include "tier1/fmtstr.h"
  12. // Last include
  13. #include <tier0/memdbgon.h>
  14. //-----------------------------------------------------------------------------
  15. //
  16. //-----------------------------------------------------------------------------
  17. CFinalSubPanel::CFinalSubPanel( vgui::Panel *pParent, const char *pszName, const char *pszNextName )
  18. : BaseClass( pParent, pszName, pszNextName )
  19. {
  20. CItemUploadWizard *pItemUploadWizard = dynamic_cast< CItemUploadWizard * >( GetWizardPanel() );
  21. if ( !pItemUploadWizard )
  22. return;
  23. {
  24. m_pHLMVButton = new vgui::Button( this, "hlmvButton", "#hlmvButton", this, "Hlmv" );
  25. m_pHLMVLabel = new vgui::Label( this, "hlmvLabel", "#hlmvLabel" );
  26. CFmtStrMax sCmd;
  27. if ( GetHlmvCmd( sCmd ) )
  28. {
  29. m_pHLMVLabel->SetText( sCmd.Access() );
  30. }
  31. m_pPanelListPanel->AddItem( m_pHLMVButton, m_pHLMVLabel );
  32. m_pHLMVButton->AddActionSignalTarget( this );
  33. }
  34. {
  35. m_pExploreMaterialContentButton = new vgui::Button( this, "exploreMaterialContentButton", "#exploreMaterialContentButton", this, "ExploreMaterialContent" );
  36. m_pExploreMaterialContentLabel = new vgui::Label( this, "exploreMaterialContentLabel", "#exploreMaterialContentLabel" );
  37. m_pPanelListPanel->AddItem( m_pExploreMaterialContentButton, m_pExploreMaterialContentLabel );
  38. }
  39. {
  40. m_pExploreModelContentButton = new vgui::Button( this, "exploreModelContentButton", "#exploreModelContentButton", this, "ExploreModelContent" );
  41. m_pExploreModelContentLabel = new vgui::Label( this, "exploreModelContentLabel", "#exploreModelContentLabel" );
  42. m_pPanelListPanel->AddItem( m_pExploreModelContentButton, m_pExploreModelContentLabel );
  43. }
  44. {
  45. m_pExploreMaterialGameButton = new vgui::Button( this, "exploreMaterialGameButton", "#exploreMaterialGameButton", this, "ExploreMaterialGame" );
  46. m_pExploreMaterialGameLabel = new vgui::Label( this, "exploreMaterialGameLabel", "#exploreMaterialGameLabel" );
  47. m_pPanelListPanel->AddItem( m_pExploreMaterialGameButton, m_pExploreMaterialGameLabel );
  48. }
  49. {
  50. m_pExploreModelGameButton = new vgui::Button( this, "exploreModelGameButton", "#exploreModelGameButton", this, "ExploreModelGame" );
  51. m_pExploreModelGameLabel = new vgui::Label( this, "exploreModelGameLabel", "#exploreModelGameLabel" );
  52. m_pPanelListPanel->AddItem( m_pExploreModelGameButton, m_pExploreModelGameLabel );
  53. }
  54. UpdateStatus();
  55. }
  56. //-----------------------------------------------------------------------------
  57. //
  58. //-----------------------------------------------------------------------------
  59. void CFinalSubPanel::PerformLayout()
  60. {
  61. BaseClass::PerformLayout();
  62. m_pPanelListPanel->SetFirstColumnWidth( 256 );
  63. }
  64. //-----------------------------------------------------------------------------
  65. //
  66. //-----------------------------------------------------------------------------
  67. void CFinalSubPanel::UpdateGUI()
  68. {
  69. UpdateStatus();
  70. }
  71. //-----------------------------------------------------------------------------
  72. //
  73. //-----------------------------------------------------------------------------
  74. void CFinalSubPanel::OnCommand( const char *command )
  75. {
  76. if ( !V_strcmp( command, "Gather" ) )
  77. {
  78. OnGather();
  79. }
  80. else if ( !V_strcmp( command, "StudioMDL" ) )
  81. {
  82. OnStudioMDL();
  83. }
  84. else if ( !V_strcmp( command, "Zip" ) )
  85. {
  86. OnZip();
  87. }
  88. else if ( !V_strcmp( command, "Hlmv" ) )
  89. {
  90. OnHlmv();
  91. }
  92. else if ( !V_strcmp( command, "ExploreMaterialContent" ) )
  93. {
  94. OnExplore( true, true );
  95. }
  96. else if ( !V_strcmp( command, "ExploreModelContent" ) )
  97. {
  98. OnExplore( false, true );
  99. }
  100. else if ( !V_strcmp( command, "ExploreMaterialGame" ) )
  101. {
  102. OnExplore( true, false );
  103. }
  104. else if ( !V_strcmp( command, "ExploreModelGame" ) )
  105. {
  106. OnExplore( false, false );
  107. }
  108. else
  109. {
  110. BaseClass::OnCommand( command );
  111. }
  112. }
  113. //-----------------------------------------------------------------------------
  114. //
  115. //-----------------------------------------------------------------------------
  116. bool CFinalSubPanel::UpdateStatus()
  117. {
  118. CItemUploadWizard *pItemUploadWizard = dynamic_cast< CItemUploadWizard * >( GetWizardPanel() );
  119. if ( !pItemUploadWizard )
  120. return false;
  121. SetStatus( true, "", NULL, true );
  122. CAsset &asset = pItemUploadWizard->Asset();
  123. {
  124. char szBuf[ MAX_PATH ];
  125. CUtlString sDir;
  126. asset.GetAbsoluteDir( sDir, "materialsrc", true );
  127. V_FixupPathName( szBuf, ARRAYSIZE( szBuf ), sDir.Get() );
  128. m_pExploreMaterialContentLabel->SetText( szBuf );
  129. asset.GetAbsoluteDir( sDir, "materials", false );
  130. V_FixupPathName( szBuf, ARRAYSIZE( szBuf ), sDir.Get() );
  131. m_pExploreMaterialGameLabel->SetText( szBuf );
  132. asset.GetAbsoluteDir( sDir, NULL, true );
  133. V_FixupPathName( szBuf, ARRAYSIZE( szBuf ), sDir.Get() );
  134. m_pExploreModelContentLabel->SetText( szBuf );
  135. asset.GetAbsoluteDir( sDir, NULL, false );
  136. V_FixupPathName( szBuf, ARRAYSIZE( szBuf ), sDir.Get() );
  137. m_pExploreModelGameLabel->SetText( szBuf );
  138. CFmtStrMax sCmd;
  139. if ( GetHlmvCmd( sCmd ) )
  140. {
  141. m_pHLMVLabel->SetText( sCmd.Access() );
  142. }
  143. }
  144. return BaseClass::UpdateStatus();
  145. return true;
  146. }
  147. //-----------------------------------------------------------------------------
  148. //
  149. //-----------------------------------------------------------------------------
  150. void CFinalSubPanel::OnGather()
  151. {
  152. CItemUploadWizard *pItemUploadWizard = dynamic_cast< CItemUploadWizard * >( GetWizardPanel() );
  153. if ( !pItemUploadWizard )
  154. {
  155. // m_pGatherLabel->SetText( "Gather Failed" );
  156. return;
  157. }
  158. // m_pGatherLabel->SetText( "OnGather" );
  159. m_pExploreMaterialContentButton->SetEnabled( true );
  160. m_pExploreModelContentButton->SetEnabled( true );
  161. }
  162. //-----------------------------------------------------------------------------
  163. //
  164. //-----------------------------------------------------------------------------
  165. void CFinalSubPanel::OnStudioMDL()
  166. {
  167. CItemUploadWizard *pItemUploadWizard = dynamic_cast< CItemUploadWizard * >( GetWizardPanel() );
  168. if ( !pItemUploadWizard )
  169. {
  170. // m_pStudioMDLLabel->SetText( "StudioMDL Failed" );
  171. return;
  172. }
  173. OnGather();
  174. // m_pStudioMDLLabel->SetText( "OnStudioMDL" );
  175. }
  176. //-----------------------------------------------------------------------------
  177. //
  178. // The idea is that there could be three steps...
  179. // 1. Gather data from user specified sources into properly named & organized content, make VMT's & QC
  180. // 2. Run StudioMDL on the gathered content
  181. // 3. Zip the results
  182. //
  183. // Right now all three steps are combined
  184. //-----------------------------------------------------------------------------
  185. void CFinalSubPanel::OnZip()
  186. {
  187. CItemUploadWizard *pItemUploadWizard = dynamic_cast< CItemUploadWizard * >( GetWizardPanel() );
  188. CAsset &asset = pItemUploadWizard->Asset();
  189. const bool bOk = asset.Compile();
  190. vgui::MessageBox *pMsgDialog = NULL;
  191. if ( bOk )
  192. {
  193. pMsgDialog = new vgui::MessageBox( "Compile Ok", "Compile Ok", this );
  194. }
  195. else
  196. {
  197. pMsgDialog = new vgui::MessageBox( "Compile Failed", "Compile Failed", this );
  198. }
  199. pMsgDialog->SetOKButtonVisible( true );
  200. pMsgDialog->SetOKButtonText( "Quit ItemTest" );
  201. pMsgDialog->SetCommand( new KeyValues( "QuitApp" ) );
  202. pMsgDialog->SetCancelButtonVisible( true );
  203. pMsgDialog->SetCancelButtonText( "Dismiss And Continue" );
  204. pMsgDialog->AddActionSignalTarget( this );
  205. pMsgDialog->DoModal();
  206. }
  207. //-----------------------------------------------------------------------------
  208. //
  209. //-----------------------------------------------------------------------------
  210. void CFinalSubPanel::OnHlmv()
  211. {
  212. CUtlString sBinDir;
  213. if ( !CItemUpload::GetBinDirectory( sBinDir ) )
  214. {
  215. m_pHLMVLabel->SetText( "Cannot determine bin directory" );
  216. return;
  217. }
  218. char szBinLaunchDir[ MAX_PATH ];
  219. V_ExtractFilePath( sBinDir.String(), szBinLaunchDir, ARRAYSIZE( szBinLaunchDir ) );
  220. CFmtStrMax sCmd;
  221. if ( !GetHlmvCmd( sCmd ) )
  222. return;
  223. if ( CItemUpload::RunCommandLine( sCmd.Access(), szBinLaunchDir, false ) )
  224. {
  225. m_pHLMVLabel->SetText( sCmd.Access() );
  226. }
  227. else
  228. {
  229. m_pHLMVLabel->SetText( "Hlmv launch failed" );
  230. }
  231. }
  232. //-----------------------------------------------------------------------------
  233. //
  234. //-----------------------------------------------------------------------------
  235. void CFinalSubPanel::OnExplore( bool bMaterial, bool bContent )
  236. {
  237. vgui::Label *pLabel = NULL;
  238. if ( bMaterial )
  239. {
  240. if ( bContent )
  241. {
  242. pLabel = m_pExploreMaterialContentLabel;
  243. }
  244. else
  245. {
  246. pLabel = m_pExploreMaterialGameLabel;
  247. }
  248. }
  249. else
  250. {
  251. if ( bContent )
  252. {
  253. pLabel = m_pExploreModelContentLabel;
  254. }
  255. else
  256. {
  257. pLabel = m_pExploreModelGameLabel;
  258. }
  259. }
  260. CItemUploadWizard *pItemUploadWizard = dynamic_cast< CItemUploadWizard * >( GetWizardPanel() );
  261. if ( !pItemUploadWizard )
  262. {
  263. pLabel->SetText( "Explore game failed" );
  264. return;
  265. }
  266. CAsset &asset = pItemUploadWizard->Asset();
  267. CUtlString sDir;
  268. const char *pszPrefix = bMaterial ? ( bContent ? "materialsrc" : "materials" ) : NULL;
  269. asset.GetAbsoluteDir( sDir, pszPrefix, bContent );
  270. char szBuf[ MAX_PATH ];
  271. V_FixupPathName( szBuf, ARRAYSIZE( szBuf ), sDir.Get() );
  272. vgui::system()->ShellExecute( "open", szBuf );
  273. pLabel->SetText( szBuf );
  274. }
  275. //-----------------------------------------------------------------------------
  276. //
  277. //-----------------------------------------------------------------------------
  278. void CFinalSubPanel::OnQuitApp()
  279. {
  280. CItemUploadWizard *pItemUploadWizard = dynamic_cast< CItemUploadWizard * >( GetWizardPanel() );
  281. if ( !pItemUploadWizard )
  282. return;
  283. pItemUploadWizard->Close();
  284. }
  285. //-----------------------------------------------------------------------------
  286. //
  287. //-----------------------------------------------------------------------------
  288. bool CFinalSubPanel::GetHlmvCmd( CFmtStrMax &sHlmvCmd )
  289. {
  290. CItemUploadWizard *pItemUploadWizard = dynamic_cast< CItemUploadWizard * >( GetWizardPanel() );
  291. if ( !pItemUploadWizard )
  292. {
  293. m_pHLMVLabel->SetText( "Hlmv Failed" );
  294. return false;
  295. }
  296. CUtlString sBinDir;
  297. if ( !CItemUpload::GetBinDirectory( sBinDir ) )
  298. {
  299. m_pHLMVLabel->SetText( "Cannot determine bin directory" );
  300. return false;
  301. }
  302. CAsset &asset = pItemUploadWizard->Asset();
  303. CSmartPtr< CTargetMDL > pTargetMDL = asset.GetTargetMDL();
  304. if ( !pTargetMDL.IsValid() )
  305. {
  306. m_pHLMVLabel->SetText( "No TargetMDL" );
  307. return false;
  308. }
  309. CUtlString sMdlPath;
  310. if ( !pTargetMDL->GetOutputPath( sMdlPath ) )
  311. {
  312. m_pHLMVLabel->SetText( "Cannot determine path to MDL" );
  313. return false;
  314. }
  315. if ( CItemUpload::GetDevMode() )
  316. {
  317. sHlmvCmd.sprintf( "\"%s\\hlmv.exe\" \"%s\"", sBinDir.Get(), sMdlPath.Get() );
  318. }
  319. else
  320. {
  321. CUtlString sVProjectDir;
  322. if ( CItemUpload::GetVProjectDir( sVProjectDir ) )
  323. {
  324. sHlmvCmd.sprintf( "\"%s\\hlmv.exe\" -allowdebug -game \"%s\" -nop4 \"%s\"", sBinDir.Get(), sVProjectDir.Get(), sMdlPath.Get() );
  325. }
  326. else
  327. {
  328. m_pHLMVLabel->SetText( "Cannot determine VPROJECT (gamedir)" );
  329. return false;
  330. }
  331. }
  332. return true;
  333. }