2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
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.
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.
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/>.
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.
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.
26 ===========================================================================
28 #include "../../idlib/precompiled.h"
31 #include "MaterialPropTreeView.h"
33 #define PROP_TREE_VIEW "PropTreeView"
36 IMPLEMENT_DYNCREATE(MaterialPropTreeView, CPropTreeView)
38 BEGIN_MESSAGE_MAP(MaterialPropTreeView, CPropTreeView)
39 ON_NOTIFY( PTN_ITEMCHANGED, IDC_PROPERTYTREE, OnPropertyChangeNotification )
40 ON_NOTIFY( PTN_ITEMEXPANDING, IDC_PROPERTYTREE, OnPropertyItemExpanding )
45 * Constructor for MaterialPropTreeView.
47 MaterialPropTreeView::MaterialPropTreeView() {
48 registry.Init("Software\\id Software\\DOOM3\\Tools\\MaterialEditor\\PropertySettings");
49 internalChange = false;
53 * Destructor for MaterialPropTreeView.
55 MaterialPropTreeView::~MaterialPropTreeView() {
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.
63 void MaterialPropTreeView::SetPropertyListType(int listType, int stageNum) {
65 currentListType = listType;
66 currentStage = stageNum;
68 m_Tree.DeleteAllItems();
70 //idList<MaterialProp_t*>* propList = NULL;
71 MaterialDefList* propList = MaterialDefManager::GetMaterialDefs(currentListType);
72 currentPropDefs = propList;
77 CPropTreeItem* pCurrentGroup = NULL;
78 CPropTreeItem* pCurrentNode = NULL;
80 for(int i = 0; i < propList->Num(); i++) {
81 switch((*propList)[i]->type) {
82 case MaterialDef::MATERIAL_DEF_TYPE_GROUP:
84 pCurrentGroup = m_Tree.InsertItem(new CPropTreeItem());
85 pCurrentNode = pCurrentGroup;
87 if(!registry.GetBool(va("Expand%d%s", currentListType, (*propList)[i]->displayName.c_str())))
88 pCurrentGroup->Expand();
91 case MaterialDef::MATERIAL_DEF_TYPE_BOOL:
93 CPropTreeItemCheck* pCheck;
94 pCheck = (CPropTreeItemCheck*)m_Tree.InsertItem(new CPropTreeItemCheck(), pCurrentGroup);
95 pCheck->CreateCheckBox();
96 pCurrentNode = pCheck;
99 case MaterialDef::MATERIAL_DEF_TYPE_STRING:
101 //pCurrentNode = m_Tree.InsertItem(new CPropTreeItemEdit(), pCurrentGroup);
102 pCurrentNode = m_Tree.InsertItem(new CPropTreeItemFileEdit(), pCurrentGroup);
109 (*propList)[i]->SetViewData(PROP_TREE_VIEW, pCurrentNode->GetCtrlID());
110 pCurrentNode->SetLabelText((*propList)[i]->displayName);
111 pCurrentNode->SetInfoText((*propList)[i]->displayInfo);
119 * Loads the property view settings from the registry.
121 void MaterialPropTreeView::LoadSettings() {
126 * Saves the property view settings to the registry.
128 void MaterialPropTreeView::SaveSettings() {
133 * Called when the material has changed but not applied.
134 * @param pMaterial The selected material.
136 void MaterialPropTreeView::MV_OnMaterialChange(MaterialDoc* pMaterial) {
138 if(materialDocManager->GetCurrentMaterialDoc()) {
139 idStr currentName = materialDocManager->GetCurrentMaterialDoc()->name;
140 if(!internalChange && !pMaterial->name.Icmp(currentName)) {
147 * Updated the material when an attribute has been changed.
149 void MaterialPropTreeView::OnPropertyChangeNotification( NMHDR *nmhdr, LRESULT *lresult ) {
151 NMPROPTREE *nmProp = (NMPROPTREE *)nmhdr;
152 CPropTreeItem *item = nmProp->pItem;
154 internalChange = true;
156 MaterialDef* propItem = FindDefForTreeID(item->GetCtrlID());
158 MaterialDoc* materialDoc = materialDocManager->GetCurrentMaterialDoc();
160 switch(propItem->type) {
161 case MaterialDef::MATERIAL_DEF_TYPE_BOOL:
163 BOOL val = item->GetItemValue();
164 materialDoc->SetAttributeBool(currentStage, propItem->dictName, val ? true : false);
167 case MaterialDef::MATERIAL_DEF_TYPE_STRING:
169 idStr val = (LPCTSTR)item->GetItemValue();
170 materialDoc->SetAttribute(currentStage, propItem->dictName, val);
176 internalChange = false;
182 * Changes the property setting of a group when is expanding.
184 void MaterialPropTreeView::OnPropertyItemExpanding( NMHDR *nmhdr, LRESULT *lresult ) {
186 NMPROPTREE *nmProp = (NMPROPTREE *)nmhdr;
187 CPropTreeItem *item = nmProp->pItem;
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);
197 * Returns the MeterialDef for a given property tree item.
198 * @param treeID The id of the tree item in question.
200 MaterialDef* MaterialPropTreeView::FindDefForTreeID(UINT treeID) {
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];
212 * Initializes the property tree with the data from the currently selected material.
214 void MaterialPropTreeView::RefreshProperties() {
216 MaterialDefList* propList = MaterialDefManager::GetMaterialDefs(currentListType);
221 MaterialDoc* materialDoc = materialDocManager->GetCurrentMaterialDoc();
223 for(int i = 0; i < propList->Num(); i++) {
224 switch((*propList)[i]->type) {
225 case MaterialDef::MATERIAL_DEF_TYPE_BOOL:
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);
232 case MaterialDef::MATERIAL_DEF_TYPE_STRING:
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());