summaryrefslogtreecommitdiff
path: root/tools/vmt/vmtdoc.h
blob: 8b9d8769ba98740b4a72b14c138ead6ed32823f5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//
//===========================================================================//

#ifndef VMTDOC_H
#define VMTDOC_H

#ifdef _WIN32
#pragma once
#endif


#include "dme_controls/inotifyui.h"
#include "datamodel/dmehandle.h"
#include "materialsystem/MaterialSystemUtil.h"
#include "tier1/utlstring.h"


//-----------------------------------------------------------------------------
// Forward declarations 
//-----------------------------------------------------------------------------
class IVMTDocCallback;
class IShader;
enum ShaderParamType_t;
class IMaterial;
class IShader;


//-----------------------------------------------------------------------------
// Contains all editable state 
//-----------------------------------------------------------------------------
class CVMTDoc : public IDmNotify
{
public:
	CVMTDoc( IVMTDocCallback *pCallback );
	~CVMTDoc();

	// Inherited from INotifyUI
	virtual void NotifyDataChanged( const char *pReason, int nNotifySource, int nNotifyFlags );

	// Sets/Gets the file name
	const char *GetFileName();
	void SetFileName( const char *pFileName );

	// Dirty bits (has it changed since the last time it was saved?)
	void	SetDirty( bool bDirty );
	bool	IsDirty() const;

	// Creates a new act busy list
	void	CreateNew();

	// Saves/loads from file
	bool	LoadFromFile( const char *pFileName );
	bool	SaveToFile( );

	// Returns the root object
	CDmElement *GetRootObject();

	// Called when data changes (see INotifyUI for flags)
	void	OnDataChanged( const char *pReason, int nNotifySource, int nNotifyFlags );

	// Sets the shader in the material
	void	SetShader( const char *pShaderName );

	// Gets the preview material
	IMaterial *GetPreviewMaterial();

	// Sets shader parameters to the default for that shader
	void	SetParamsToDefault();

private:
	// Creates the root element
	bool CreateRootElement();

	// Add attribute for shader parameter
	CDmAttribute* AddAttributeForShaderParameter( CDmElement *pMaterial, const char *pParamName, ShaderParamType_t paramType );

	// Add a single shader parameter if it doesn't exist
	void AddNewShaderParam( CDmElement *pMaterial, const char *pParamName, ShaderParamType_t paramType, const char *pValue );

	// Add all shader parameters that don't currently exist
	void AddNewShaderParams( CDmElement *pMaterial, IShader *pShader );

	// Is this attribute a shader parameter?
	bool IsShaderParam( CDmAttribute* pAttribute );

	// Remove all shader parameters that don't exist in the new shader
	void RemoveUnusedShaderParams( CDmElement *pMaterial, IShader *pShader, IShader *pOldShader );

	// Remove all shader parameters 
	void RemoveAllShaderParams( CDmElement *pMaterial );

	// Finds a shader
	IShader *FindShader( const char *pShaderName );

	// Updates the preview material
	void UpdatePreviewMaterial();

	// Copies VMT parameters into the root
	void CopyParamsFromVMT( CDmElement *pVMT );

	// A couple methods to set param values from strings (OLD METHOD!)
	bool SetVMatrixParamValue( CDmAttribute *pAttribute, const char *pValue );
	bool SetVector2DParamValue( CDmAttribute *pAttribute, const char *pValue );
	bool SetVector3DParamValue( CDmAttribute *pAttribute, const char *pValue );
	bool SetVector4DParamValue( CDmAttribute *pAttribute, const char *pValue );
	bool SetColorParamValue( CDmAttribute *pAttribute, const char *pValue );

	// Sets an attribute value from the shader param default
	void SetAttributeValueFromDefault( CDmElement *pMaterial, CDmAttribute *pAttribute, const char *pValue );

	// Hooks the preview to an existing material, if there is one
	void SetupPreviewMaterial( );

	// Prior to saving to disk, extract all shader parameters which == the default
	CDmElement* ExtractDefaultParameters( );

	IVMTDocCallback *m_pCallback;
	CMaterialReference m_pScratchMaterial;
	CMaterialReference m_pPreviewMaterial;
	CDmeHandle< CDmElement > m_hRoot;
	CUtlString m_CurrentShader;
	IShader *m_pCurrentIShader;
	char m_pFileName[512];
	bool m_bDirty;
};


#endif // VMTDOC_H