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.

218 lines
6.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef ASSETBUILDER_H
  7. #define ASSETBUILDER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "vgui_controls/Frame.h"
  12. #include "vgui_controls/FileOpenStateMachine.h"
  13. #include "vgui_controls/PHandle.h"
  14. #include "datamodel/dmehandle.h"
  15. #include "tier1/utlstack.h"
  16. //-----------------------------------------------------------------------------
  17. // Forward declarations
  18. //-----------------------------------------------------------------------------
  19. namespace vgui
  20. {
  21. class IScheme;
  22. class ListPanel;
  23. class Menu;
  24. class MenuButton;
  25. class Splitter;
  26. class FileOpenStateMachine;
  27. class PropertySheet;
  28. class PropertyPage;
  29. }
  30. class CDmePanel;
  31. class CCompileStatusBar;
  32. class CDmeMakefile;
  33. class CDmeSource;
  34. struct DmeMakefileType_t;
  35. enum CompilationState_t;
  36. //-----------------------------------------------------------------------------
  37. // Purpose: Asset builder
  38. //-----------------------------------------------------------------------------
  39. class CAssetBuilder : public vgui::EditablePanel
  40. {
  41. DECLARE_CLASS_SIMPLE( CAssetBuilder, EditablePanel );
  42. public:
  43. CAssetBuilder( vgui::Panel *pParent, const char *pPanelName );
  44. virtual ~CAssetBuilder();
  45. // Inherited from vgui::Frame
  46. virtual void OnCommand( const char *pCommand );
  47. virtual void OnKeyCodeTyped( vgui::KeyCode code );
  48. virtual void OnTick();
  49. void SetRootMakefile( CDmeMakefile *pMakeFile );
  50. void SetCurrentMakefile( CDmeMakefile *pMakeFile );
  51. void SetDmeElement( CDmeMakefile *pMakeFile );
  52. CDmeMakefile *GetMakeFile();
  53. CDmeMakefile *GetRootMakeFile();
  54. void Refresh();
  55. // Default behavior is to destroy the makefile when we close
  56. void DestroyMakefileOnClose( bool bEnable );
  57. /*
  58. messages sent:
  59. "DmeElementChanged" The makefile has been changed
  60. */
  61. private:
  62. MESSAGE_FUNC_PARAMS( OnItemSelected, "ItemSelected", kv );
  63. MESSAGE_FUNC_PARAMS( OnItemDeselected, "ItemDeselected", kv );
  64. MESSAGE_FUNC_PARAMS( OnFileSelected, "FileSelected", kv );
  65. MESSAGE_FUNC_PARAMS( OnOpenContextMenu, "OpenContextMenu", kv );
  66. MESSAGE_FUNC_PARAMS( OnPicked, "Picked", kv );
  67. MESSAGE_FUNC( SetDirty, "DmeElementChanged" );
  68. MESSAGE_FUNC( OnAddSource, "AddSource" );
  69. MESSAGE_FUNC( OnNewSourceFile, "NewSourceFile" );
  70. MESSAGE_FUNC( OnLoadSourceFile, "LoadSourceFile" );
  71. MESSAGE_FUNC( OnEditSourceFile, "EditSourceFile" );
  72. MESSAGE_FUNC( OnRemoveSource, "RemoveSource" );
  73. MESSAGE_FUNC( OnBrowseSourceFile, "BrowseSourceFile" );
  74. MESSAGE_FUNC( OnZoomInSource, "ZoomInSource" );
  75. MESSAGE_FUNC( OnZoomOutSource, "ZoomOutSource" );
  76. void OnCompile();
  77. void OnAbortCompile();
  78. void OnPublish();
  79. // Called to create a new makefile
  80. void OnNewSourceFileSelected( const char *pFileName, KeyValues *pDialogKeys );
  81. // Called when a list panel's selection changes
  82. void OnSourceItemSelectionChanged( );
  83. // Refresh the source list
  84. void RefreshSourceList( );
  85. // Refreshes the output list
  86. void RefreshOutputList();
  87. // Selects a particular source
  88. void SelectSource( CDmeSource *pSource );
  89. // Called when the source file name changes
  90. void OnSourceFileNameChanged( const char *pFileName );
  91. // Called when we're browsing for a source file and one was selected
  92. void OnSourceFileAdded( const char *pFileName, const char *pTypeName );
  93. // Shows the source file browser
  94. void ShowSourceFileBrowser( const char *pTitle, DmeMakefileType_t *pSourceType, KeyValues *pDialogKeys );
  95. // Make all outputs writeable
  96. void MakeOutputsWriteable( );
  97. // Cleans up the context menu
  98. void CleanupContextMenu();
  99. // Removes a makefile from memory
  100. void CleanupMakefile();
  101. // Builds a unique list of file IDs
  102. void BuildFileIDList( CDmeMakefile *pMakeFile, CUtlVector<DmFileId_t> &fileIds );
  103. // Selects a particular row of the source list
  104. void SelectSourceListRow( int nRow );
  105. // Returns the curerntly selected row
  106. int GetSelectedRow( );
  107. // Finishes compilation
  108. void FinishCompilation( CompilationState_t state );
  109. // Returns the selected source (if there's only 1 source selected)
  110. CDmeSource *GetSelectedSource( );
  111. KeyValues *GetSelectedSourceKeyvalues( );
  112. vgui::PropertySheet *m_pInputOutputSheet;
  113. vgui::PropertyPage *m_pInputPage;
  114. vgui::PropertyPage *m_pOutputPage;
  115. vgui::PropertyPage *m_pCompilePage;
  116. vgui::PropertyPage *m_pOutputPreviewPage;
  117. vgui::Splitter *m_pPropertiesSplitter;
  118. vgui::ListPanel *m_pSourcesList;
  119. vgui::ListPanel *m_pOutputList;
  120. CDmePanel *m_pDmePanel;
  121. CDmePanel *m_pOututPreviewPanel;
  122. vgui::TextEntry *m_pCompileOutput;
  123. vgui::Button *m_pCompile;
  124. vgui::Button *m_pPublish;
  125. vgui::Button *m_pAbortCompile;
  126. vgui::DHANDLE< vgui::Menu > m_hContextMenu;
  127. CCompileStatusBar *m_pCompileStatusBar;
  128. CDmeHandle< CDmeMakefile > m_hRootMakefile;
  129. CDmeHandle< CDmeMakefile > m_hMakefile;
  130. CUtlStack< CDmeHandle< CDmeMakefile > > m_hMakefileStack;
  131. bool m_bIsCompiling : 1;
  132. bool m_bDestroyMakefileOnClose : 1;
  133. };
  134. //-----------------------------------------------------------------------------
  135. // Purpose: Asset builder frame
  136. //-----------------------------------------------------------------------------
  137. class CAssetBuilderFrame : public vgui::Frame, public vgui::IFileOpenStateMachineClient
  138. {
  139. DECLARE_CLASS_SIMPLE( CAssetBuilderFrame, vgui::Frame );
  140. public:
  141. CAssetBuilderFrame( vgui::Panel *pParent, const char *pTitle );
  142. virtual ~CAssetBuilderFrame();
  143. // Inherited from IFileOpenStateMachineClient
  144. virtual void SetupFileOpenDialog( vgui::FileOpenDialog *pDialog, bool bOpenFile, const char *pFileFormat, KeyValues *pContextKeyValues );
  145. virtual bool OnReadFileFromDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues );
  146. virtual bool OnWriteFileToDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues );
  147. protected:
  148. // Call to change the makefile
  149. void Reset( CDmeMakefile *pMakefile );
  150. CAssetBuilder *m_pAssetBuilder;
  151. private:
  152. MESSAGE_FUNC( OnDmeElementChanged, "DmeElementChanged" );
  153. MESSAGE_FUNC( OnFileNew, "FileNew" );
  154. MESSAGE_FUNC( OnFileOpen, "FileOpen" );
  155. MESSAGE_FUNC( OnFileSave, "FileSave" );
  156. MESSAGE_FUNC( OnFileSaveAs, "FileSaveAs" );
  157. MESSAGE_FUNC_PARAMS( OnPicked, "Picked", kv );
  158. MESSAGE_FUNC_PARAMS( OnFileSelected, "FileSelected", kv );
  159. MESSAGE_FUNC_PARAMS( OnFileStateMachineFinished, "FileStateMachineFinished", kv );
  160. MESSAGE_FUNC_PARAMS( OnPerformFileNew, "PerformFileNew", kv );
  161. // Updates the file name
  162. MESSAGE_FUNC( UpdateFileName, "UpdateFileName" );
  163. // Shows a picker for creating a new asset
  164. void ShowNewAssetPicker( );
  165. // Marks the file dirty ( or not )
  166. void SetDirty( bool bDirty );
  167. bool IsDirty() const;
  168. vgui::FileOpenStateMachine *m_pFileOpenStateMachine;
  169. CUtlString m_TitleString;
  170. };
  171. #endif // ASSETBUILDER_H