]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/tools/materialeditor/MaterialPropTreeView.cpp
hello world
[icculus/iodoom3.git] / neo / tools / materialeditor / MaterialPropTreeView.cpp
1 /*
2 ===========================================================================
3
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. 
6
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).  
8
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code.  If not, see <http://www.gnu.org/licenses/>.
21
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code.  If not, please request a copy in writing from id Software at the address below.
23
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25
26 ===========================================================================
27 */
28 #include "../../idlib/precompiled.h"
29 #pragma hdrstop
30
31 #include "MaterialPropTreeView.h"
32
33 #define PROP_TREE_VIEW "PropTreeView"
34
35
36 IMPLEMENT_DYNCREATE(MaterialPropTreeView, CPropTreeView)
37
38 BEGIN_MESSAGE_MAP(MaterialPropTreeView, CPropTreeView)
39         ON_NOTIFY( PTN_ITEMCHANGED, IDC_PROPERTYTREE, OnPropertyChangeNotification )
40         ON_NOTIFY( PTN_ITEMEXPANDING, IDC_PROPERTYTREE, OnPropertyItemExpanding )
41 END_MESSAGE_MAP()
42
43
44 /**
45 * Constructor for MaterialPropTreeView.
46 */
47 MaterialPropTreeView::MaterialPropTreeView() {
48         registry.Init("Software\\id Software\\DOOM3\\Tools\\MaterialEditor\\PropertySettings");
49         internalChange = false;
50 }
51
52 /**
53 * Destructor for MaterialPropTreeView.
54 */
55 MaterialPropTreeView::~MaterialPropTreeView() {
56 }
57
58 /**
59 * Initializes the list of properties based on the type (material, stage, special stage).
60 * @param listType The type of list (material, stage, special stage)
61 * @param stageNum The stage from which to get the attributes.
62 */
63 void MaterialPropTreeView::SetPropertyListType(int listType, int stageNum) {
64
65         currentListType = listType;
66         currentStage = stageNum;
67
68         m_Tree.DeleteAllItems();
69
70         //idList<MaterialProp_t*>* propList = NULL;
71         MaterialDefList* propList = MaterialDefManager::GetMaterialDefs(currentListType);
72         currentPropDefs = propList;
73
74         if(!propList)
75                 return;
76
77         CPropTreeItem* pCurrentGroup = NULL;
78         CPropTreeItem* pCurrentNode = NULL;
79
80         for(int i = 0; i < propList->Num(); i++) {
81                 switch((*propList)[i]->type) {
82                         case MaterialDef::MATERIAL_DEF_TYPE_GROUP:
83                                 {
84                                         pCurrentGroup = m_Tree.InsertItem(new CPropTreeItem());
85                                         pCurrentNode = pCurrentGroup;
86
87                                         if(!registry.GetBool(va("Expand%d%s", currentListType, (*propList)[i]->displayName.c_str())))
88                                                 pCurrentGroup->Expand();
89                                 }
90                                 break;
91                         case MaterialDef::MATERIAL_DEF_TYPE_BOOL:
92                                 {
93                                         CPropTreeItemCheck* pCheck;
94                                         pCheck = (CPropTreeItemCheck*)m_Tree.InsertItem(new CPropTreeItemCheck(), pCurrentGroup);
95                                         pCheck->CreateCheckBox();
96                                         pCurrentNode = pCheck;
97                                 }
98                                 break;
99                         case MaterialDef::MATERIAL_DEF_TYPE_STRING:
100                                 {
101                                         //pCurrentNode = m_Tree.InsertItem(new CPropTreeItemEdit(), pCurrentGroup);     
102                                         pCurrentNode = m_Tree.InsertItem(new CPropTreeItemFileEdit(), pCurrentGroup);
103
104                                 }
105                                 break;
106                 }
107
108                 if(pCurrentNode) {
109                         (*propList)[i]->SetViewData(PROP_TREE_VIEW, pCurrentNode->GetCtrlID());
110                         pCurrentNode->SetLabelText((*propList)[i]->displayName);
111                         pCurrentNode->SetInfoText((*propList)[i]->displayInfo);
112                 }
113         }
114
115         RefreshProperties();
116 }
117
118 /**
119 * Loads the property view settings from the registry.
120 */
121 void MaterialPropTreeView::LoadSettings() {
122         registry.Load();
123 }
124
125 /**
126 * Saves the property view settings to the registry.
127 */
128 void MaterialPropTreeView::SaveSettings() {
129         registry.Save();
130 }
131
132 /**
133 * Called when the material has changed but not applied.
134 * @param pMaterial The selected material.
135 */
136 void MaterialPropTreeView::MV_OnMaterialChange(MaterialDoc* pMaterial) {
137         
138         if(materialDocManager->GetCurrentMaterialDoc()) {
139                 idStr currentName = materialDocManager->GetCurrentMaterialDoc()->name;
140                 if(!internalChange && !pMaterial->name.Icmp(currentName)) {
141                         RefreshProperties();
142                 }
143         }
144 }
145
146 /**
147 * Updated the material when an attribute has been changed.
148 */
149 void MaterialPropTreeView::OnPropertyChangeNotification( NMHDR *nmhdr, LRESULT *lresult ) {
150
151         NMPROPTREE      *nmProp = (NMPROPTREE *)nmhdr;
152         CPropTreeItem   *item = nmProp->pItem;
153
154         internalChange = true;
155
156         MaterialDef* propItem = FindDefForTreeID(item->GetCtrlID());
157         if(propItem) {
158                 MaterialDoc* materialDoc = materialDocManager->GetCurrentMaterialDoc();
159
160                 switch(propItem->type) {
161                         case MaterialDef::MATERIAL_DEF_TYPE_BOOL:
162                                 {
163                                         BOOL val = item->GetItemValue();
164                                         materialDoc->SetAttributeBool(currentStage, propItem->dictName, val ? true : false);
165                                 }
166                                 break;
167                         case MaterialDef::MATERIAL_DEF_TYPE_STRING:
168                                 {
169                                         idStr val = (LPCTSTR)item->GetItemValue();                                                              
170                                         materialDoc->SetAttribute(currentStage, propItem->dictName, val);
171                                 }
172                                 break;
173                 }
174         }
175
176         internalChange = false;
177
178         *lresult = 0;
179 }
180
181 /**
182 * Changes the property setting of a group when is expanding.
183 */
184 void MaterialPropTreeView::OnPropertyItemExpanding( NMHDR *nmhdr, LRESULT *lresult ) {
185
186         NMPROPTREE      *nmProp = (NMPROPTREE *)nmhdr;
187         CPropTreeItem   *item = nmProp->pItem;
188
189         //The item isn't toggled till after this returns so use the opposite of the current state.
190         registry.SetBool(va("Expand%d%s", currentListType, item->GetLabelText()), item->IsExpanded() ? true : false);
191         registry.Save();
192
193         *lresult = 0;
194 }
195
196 /**
197 * Returns the MeterialDef for a given property tree item.
198 * @param treeID The id of the tree item in question.
199 */
200 MaterialDef* MaterialPropTreeView::FindDefForTreeID(UINT treeID) {
201
202         int c = currentPropDefs->Num();
203         for(int i = 0; i < c; i++) {
204                 if((*currentPropDefs)[i]->GetViewData(PROP_TREE_VIEW) == treeID)
205                         return (*currentPropDefs)[i];
206         }
207
208         return NULL;
209 }
210
211 /**
212 * Initializes the property tree with the data from the currently selected material.
213 */
214 void MaterialPropTreeView::RefreshProperties() {
215         
216         MaterialDefList* propList = MaterialDefManager::GetMaterialDefs(currentListType);
217
218         if(!propList)
219                 return;
220
221         MaterialDoc* materialDoc = materialDocManager->GetCurrentMaterialDoc();
222
223         for(int i = 0; i < propList->Num(); i++) {
224                 switch((*propList)[i]->type) {
225                         case MaterialDef::MATERIAL_DEF_TYPE_BOOL:
226                                 {
227                                         bool val = materialDoc->GetAttributeBool(currentStage, (*propList)[i]->dictName);
228                                         CPropTreeItemCheck* item = (CPropTreeItemCheck*)m_Tree.FindItem((*propList)[i]->GetViewData(PROP_TREE_VIEW));
229                                         item->SetCheckState(val ? TRUE:FALSE);
230                                 }
231                                 break;
232                         case MaterialDef::MATERIAL_DEF_TYPE_STRING:
233                                 {
234                                         idStr val = materialDoc->GetAttribute(currentStage, (*propList)[i]->dictName);
235                                         CPropTreeItemEdit* item = (CPropTreeItemEdit*)m_Tree.FindItem((*propList)[i]->GetViewData(PROP_TREE_VIEW));
236                                         item->SetItemValue((LPARAM)val.c_str());
237                                 }
238                                 break;
239                 }
240         }
241
242         Invalidate();
243 }
244
245
246
247
248