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.

133 lines
4.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #ifndef VMTDOC_H
  9. #define VMTDOC_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "dme_controls/inotifyui.h"
  14. #include "datamodel/dmehandle.h"
  15. #include "materialsystem/MaterialSystemUtil.h"
  16. #include "tier1/utlstring.h"
  17. //-----------------------------------------------------------------------------
  18. // Forward declarations
  19. //-----------------------------------------------------------------------------
  20. class IVMTDocCallback;
  21. class IShader;
  22. enum ShaderParamType_t;
  23. class IMaterial;
  24. class IShader;
  25. //-----------------------------------------------------------------------------
  26. // Contains all editable state
  27. //-----------------------------------------------------------------------------
  28. class CVMTDoc : public IDmNotify
  29. {
  30. public:
  31. CVMTDoc( IVMTDocCallback *pCallback );
  32. ~CVMTDoc();
  33. // Inherited from INotifyUI
  34. virtual void NotifyDataChanged( const char *pReason, int nNotifySource, int nNotifyFlags );
  35. // Sets/Gets the file name
  36. const char *GetFileName();
  37. void SetFileName( const char *pFileName );
  38. // Dirty bits (has it changed since the last time it was saved?)
  39. void SetDirty( bool bDirty );
  40. bool IsDirty() const;
  41. // Creates a new act busy list
  42. void CreateNew();
  43. // Saves/loads from file
  44. bool LoadFromFile( const char *pFileName );
  45. bool SaveToFile( );
  46. // Returns the root object
  47. CDmElement *GetRootObject();
  48. // Called when data changes (see INotifyUI for flags)
  49. void OnDataChanged( const char *pReason, int nNotifySource, int nNotifyFlags );
  50. // Sets the shader in the material
  51. void SetShader( const char *pShaderName );
  52. // Gets the preview material
  53. IMaterial *GetPreviewMaterial();
  54. // Sets shader parameters to the default for that shader
  55. void SetParamsToDefault();
  56. private:
  57. // Creates the root element
  58. bool CreateRootElement();
  59. // Add attribute for shader parameter
  60. CDmAttribute* AddAttributeForShaderParameter( CDmElement *pMaterial, const char *pParamName, ShaderParamType_t paramType );
  61. // Add a single shader parameter if it doesn't exist
  62. void AddNewShaderParam( CDmElement *pMaterial, const char *pParamName, ShaderParamType_t paramType, const char *pValue );
  63. // Add all shader parameters that don't currently exist
  64. void AddNewShaderParams( CDmElement *pMaterial, IShader *pShader );
  65. // Is this attribute a shader parameter?
  66. bool IsShaderParam( CDmAttribute* pAttribute );
  67. // Remove all shader parameters that don't exist in the new shader
  68. void RemoveUnusedShaderParams( CDmElement *pMaterial, IShader *pShader, IShader *pOldShader );
  69. // Remove all shader parameters
  70. void RemoveAllShaderParams( CDmElement *pMaterial );
  71. // Finds a shader
  72. IShader *FindShader( const char *pShaderName );
  73. // Updates the preview material
  74. void UpdatePreviewMaterial();
  75. // Copies VMT parameters into the root
  76. void CopyParamsFromVMT( CDmElement *pVMT );
  77. // A couple methods to set param values from strings (OLD METHOD!)
  78. bool SetVMatrixParamValue( CDmAttribute *pAttribute, const char *pValue );
  79. bool SetVector2DParamValue( CDmAttribute *pAttribute, const char *pValue );
  80. bool SetVector3DParamValue( CDmAttribute *pAttribute, const char *pValue );
  81. bool SetVector4DParamValue( CDmAttribute *pAttribute, const char *pValue );
  82. bool SetColorParamValue( CDmAttribute *pAttribute, const char *pValue );
  83. // Sets an attribute value from the shader param default
  84. void SetAttributeValueFromDefault( CDmElement *pMaterial, CDmAttribute *pAttribute, const char *pValue );
  85. // Hooks the preview to an existing material, if there is one
  86. void SetupPreviewMaterial( );
  87. // Prior to saving to disk, extract all shader parameters which == the default
  88. CDmElement* ExtractDefaultParameters( );
  89. IVMTDocCallback *m_pCallback;
  90. CMaterialReference m_pScratchMaterial;
  91. CMaterialReference m_pPreviewMaterial;
  92. CDmeHandle< CDmElement > m_hRoot;
  93. CUtlString m_CurrentShader;
  94. IShader *m_pCurrentIShader;
  95. char m_pFileName[512];
  96. bool m_bDirty;
  97. };
  98. #endif // VMTDOC_H