From 4e36bddfb4c85b3e0056dd6c515e855fb88efe15 Mon Sep 17 00:00:00 2001 From: Artyom Shalkhakov Date: Wed, 26 Mar 2025 01:21:55 -0600 Subject: [PATCH] Material Property Tree View implementation. --- .../materialeditor/MaterialPropTreeView.cpp | 288 ++++++++---------- .../materialeditor/MaterialPropTreeView.h | 24 +- 2 files changed, 132 insertions(+), 180 deletions(-) diff --git a/neo/tools/imgui/materialeditor/MaterialPropTreeView.cpp b/neo/tools/imgui/materialeditor/MaterialPropTreeView.cpp index a34d9ba0..66eedb8c 100644 --- a/neo/tools/imgui/materialeditor/MaterialPropTreeView.cpp +++ b/neo/tools/imgui/materialeditor/MaterialPropTreeView.cpp @@ -27,7 +27,7 @@ If you have questions concerning this license or the applicable additional terms */ #include "tools/edit_gui_common.h" #include "sys/sys_imgui.h" - +#include "../util/ImGui_IdWidgets.h" #include "MaterialPropTreeView.h" @@ -35,19 +35,15 @@ If you have questions concerning this license or the applicable additional terms namespace ImGuiTools { -/* -IMPLEMENT_DYNCREATE(MaterialPropTreeView, CPropTreeView) - -BEGIN_MESSAGE_MAP(MaterialPropTreeView, CPropTreeView) - ON_NOTIFY( PTN_ITEMCHANGED, IDC_PROPERTYTREE, OnPropertyChangeNotification ) - ON_NOTIFY( PTN_ITEMEXPANDING, IDC_PROPERTYTREE, OnPropertyItemExpanding ) -END_MESSAGE_MAP() -*/ - /** * Constructor for MaterialPropTreeView. */ -MaterialPropTreeView::MaterialPropTreeView() { +MaterialPropTreeView::MaterialPropTreeView() + : currentMaterial(NULL) + , currentListType(0) + , currentStage(-1) + , currentPropDefs(NULL) +{ //registry.Init("Software\\id Software\\DOOM3\\Tools\\MaterialEditor\\PropertySettings"); internalChange = false; } @@ -60,14 +56,132 @@ MaterialPropTreeView::~MaterialPropTreeView() { bool MaterialPropTreeView::Draw( const ImVec2 &size ) { if ( ImGui::BeginChild( "###MaterialPropTreeView", size, ImGuiChildFlags_Borders ) ) { + MaterialDoc *materialDoc = materialDocManager->GetCurrentMaterialDoc(); - ImGui::Text( "MaterialPropTreeView" ); + if ( currentPropDefs ) + { + for ( int i = 0; i < currentPropDefs->Num(); ) { + MaterialDef *propItem = (*currentPropDefs)[i]; + ImGuiTreeNodeFlags flags = 0; + int j; + + switch ( (*currentPropDefs)[i]->type ) { + case MaterialDef::MATERIAL_DEF_TYPE_GROUP: + { + //if(!registry.GetBool(va("Expand%d%s", currentListType, (*propList)[i]->displayName.c_str()))) + // pCurrentGroup->Expand(); + + if ( ImGui::TreeNodeEx( static_cast(propItem), flags, "%s", propItem->displayName.c_str() ) ) { + if ( ImGui::IsItemClicked() && !ImGui::IsItemToggledOpen() ) { + /* + //The item isn't toggled till after this returns so use the opposite of the current state. + registry.SetBool(va("Expand%d%s", currentListType, item->GetLabelText()), item->IsExpanded() ? true : false); + registry.Save(); + */ + } + + j = DrawGroup( i + 1 ); + + ImGui::TreePop(); + } else { + // skip until next group + j = i + 1; + while ( j < currentPropDefs->Num() && (*currentPropDefs)[j]->type != MaterialDef::MATERIAL_DEF_TYPE_GROUP ) { + j++; + } + } + + if ( ImGui::IsItemHovered() && !propItem->displayInfo.IsEmpty() ) { + ImGui::BeginTooltip(); + ImGui::TextUnformatted( propItem->displayInfo.c_str() ); + ImGui::EndTooltip(); + } + } + break; + default: + j = DrawGroup( i ); + break; + } + + i = j; + } + } } ImGui::EndChild(); return false; } +int MaterialPropTreeView::DrawGroup( int startGroupNum ) { + if ( !currentPropDefs ) { + return startGroupNum + 1; + } + + MaterialDoc* materialDoc = materialDocManager->GetCurrentMaterialDoc(); + + int i = startGroupNum; + + for ( ; i < currentPropDefs->Num(); i++ ) { + MaterialDef* propItem = (*currentPropDefs)[i]; + + switch ( propItem->type ) { + case MaterialDef::MATERIAL_DEF_TYPE_GROUP: + return i; + case MaterialDef::MATERIAL_DEF_TYPE_BOOL: + { + bool val = materialDoc->GetAttributeBool( currentStage, propItem->dictName ); + + if ( ImGui::Checkbox( propItem->displayName.c_str(), &val ) ) { + internalChange = true; + materialDoc->SetAttributeBool(currentStage, propItem->dictName, val ? true : false); + internalChange = false; + } + } + break; + case MaterialDef::MATERIAL_DEF_TYPE_STRING: + { + idStr val = materialDoc->GetAttribute( currentStage, propItem->dictName ); + + if ( ImGui::InputTextStr( propItem->displayName, &val ) ) { + internalChange = true; + materialDoc->SetAttribute( currentStage, propItem->dictName, val ); + internalChange = false; + } + } + break; + case MaterialDef::MATERIAL_DEF_TYPE_FLOAT: + { + float val = materialDoc->GetAttributeFloat( currentStage, propItem->dictName ); + + if ( ImGui::InputFloat( propItem->displayName, &val ) ) { + internalChange = true; + materialDoc->SetAttributeFloat( currentStage, propItem->dictName, val ); + internalChange = false; + } + } + case MaterialDef::MATERIAL_DEF_TYPE_INT: + { + int val = materialDoc->GetAttributeInt( currentStage, propItem->dictName ); + + if ( ImGui::InputInt( propItem->displayName, &val ) ) { + internalChange = true; + materialDoc->SetAttributeInt( currentStage, propItem->dictName, val ); + internalChange = false; + } + } + break; + } + + if ( ImGui::IsItemHovered() && !propItem->displayInfo.IsEmpty() ) { + ImGui::BeginTooltip(); + ImGui::TextUnformatted( propItem->displayInfo.c_str() ); + ImGui::EndTooltip(); + } + } + + return i; +} + /** * Initializes the list of properties based on the type (material, stage, special stage). * @param listType The type of list (material, stage, special stage) @@ -78,53 +192,8 @@ void MaterialPropTreeView::SetPropertyListType(int listType, int stageNum) { currentListType = listType; currentStage = stageNum; - //m_Tree.DeleteAllItems(); - - //idList* propList = NULL; MaterialDefList* propList = MaterialDefManager::GetMaterialDefs(currentListType); currentPropDefs = propList; - - if(!propList) - return; - - //CPropTreeItem* pCurrentGroup = NULL; - //CPropTreeItem* pCurrentNode = NULL; - - for(int i = 0; i < propList->Num(); i++) { - switch((*propList)[i]->type) { - case MaterialDef::MATERIAL_DEF_TYPE_GROUP: - { - //pCurrentGroup = m_Tree.InsertItem(new CPropTreeItem()); - //pCurrentNode = pCurrentGroup; - - //if(!registry.GetBool(va("Expand%d%s", currentListType, (*propList)[i]->displayName.c_str()))) - //pCurrentGroup->Expand(); - } - break; - case MaterialDef::MATERIAL_DEF_TYPE_BOOL: - { - //CPropTreeItemCheck* pCheck; - //pCheck = (CPropTreeItemCheck*)m_Tree.InsertItem(new CPropTreeItemCheck(), pCurrentGroup); - //pCheck->CreateCheckBox(); - //pCurrentNode = pCheck; - } - break; - case MaterialDef::MATERIAL_DEF_TYPE_STRING: - { - //pCurrentNode = m_Tree.InsertItem(new CPropTreeItemFileEdit(), pCurrentGroup); - - } - break; - } - - /*if (pCurrentNode) { - (*propList)[i]->SetViewData(PROP_TREE_VIEW, pCurrentNode->GetCtrlID()); - pCurrentNode->SetLabelText((*propList)[i]->displayName); - pCurrentNode->SetInfoText((*propList)[i]->displayInfo); - }*/ - } - - RefreshProperties(); } /** @@ -147,111 +216,6 @@ void MaterialPropTreeView::SaveSettings() { */ void MaterialPropTreeView::MV_OnMaterialChange(MaterialDoc* pMaterial) { - if(materialDocManager->GetCurrentMaterialDoc()) { - idStr currentName = materialDocManager->GetCurrentMaterialDoc()->name; - if(!internalChange && !pMaterial->name.Icmp(currentName)) { - RefreshProperties(); - } - } -} - -/** -* Updated the material when an attribute has been changed. -*/ -void MaterialPropTreeView::OnPropertyChangeNotification() { - /* - NMPROPTREE *nmProp = (NMPROPTREE *)nmhdr; - CPropTreeItem *item = nmProp->pItem; - - internalChange = true; - - MaterialDef* propItem = FindDefForTreeID(item->GetCtrlID()); - if(propItem) { - MaterialDoc* materialDoc = materialDocManager->GetCurrentMaterialDoc(); - - switch(propItem->type) { - case MaterialDef::MATERIAL_DEF_TYPE_BOOL: - { - BOOL val = item->GetItemValue(); - materialDoc->SetAttributeBool(currentStage, propItem->dictName, val ? true : false); - } - break; - case MaterialDef::MATERIAL_DEF_TYPE_STRING: - { - idStr val = (LPCTSTR)item->GetItemValue(); - materialDoc->SetAttribute(currentStage, propItem->dictName, val); - } - break; - } - } - - internalChange = false; - - *lresult = 0;*/ -} - -/** -* Changes the property setting of a group when is expanding. -*/ -void MaterialPropTreeView::OnPropertyItemExpanding() { - /* - NMPROPTREE *nmProp = (NMPROPTREE *)nmhdr; - CPropTreeItem *item = nmProp->pItem; - - //The item isn't toggled till after this returns so use the opposite of the current state. - registry.SetBool(va("Expand%d%s", currentListType, item->GetLabelText()), item->IsExpanded() ? true : false); - registry.Save(); - - *lresult = 0;*/ -} - -/** -* Returns the MeterialDef for a given property tree item. -* @param treeID The id of the tree item in question. -*/ -MaterialDef* MaterialPropTreeView::FindDefForTreeID(UINT treeID) { - - int c = currentPropDefs->Num(); - for(int i = 0; i < c; i++) { - if((*currentPropDefs)[i]->GetViewData(PROP_TREE_VIEW) == treeID) - return (*currentPropDefs)[i]; - } - - return NULL; -} - -/** -* Initializes the property tree with the data from the currently selected material. -*/ -void MaterialPropTreeView::RefreshProperties() { - - MaterialDefList* propList = MaterialDefManager::GetMaterialDefs(currentListType); - - if(!propList) - return; - - MaterialDoc* materialDoc = materialDocManager->GetCurrentMaterialDoc(); - - for(int i = 0; i < propList->Num(); i++) { - switch((*propList)[i]->type) { - case MaterialDef::MATERIAL_DEF_TYPE_BOOL: - { - bool val = materialDoc->GetAttributeBool(currentStage, (*propList)[i]->dictName); - //CPropTreeItemCheck* item = (CPropTreeItemCheck*)m_Tree.FindItem((*propList)[i]->GetViewData(PROP_TREE_VIEW)); - //item->SetCheckState(val ? TRUE:FALSE); - } - break; - case MaterialDef::MATERIAL_DEF_TYPE_STRING: - { - idStr val = materialDoc->GetAttribute(currentStage, (*propList)[i]->dictName); - //CPropTreeItemEdit* item = (CPropTreeItemEdit*)m_Tree.FindItem((*propList)[i]->GetViewData(PROP_TREE_VIEW)); - //item->SetItemValue((LPARAM)val.c_str()); - } - break; - } - } - - //Invalidate(); } } diff --git a/neo/tools/imgui/materialeditor/MaterialPropTreeView.h b/neo/tools/imgui/materialeditor/MaterialPropTreeView.h index 00c25404..937ffb1f 100644 --- a/neo/tools/imgui/materialeditor/MaterialPropTreeView.h +++ b/neo/tools/imgui/materialeditor/MaterialPropTreeView.h @@ -28,10 +28,7 @@ If you have questions concerning this license or the applicable additional terms #ifndef MATERIALPROPTREEVIEW_H_ #define MATERIALPROPTREEVIEW_H_ -//#include "../common/PropTree/PropTreeView.h" #include "MaterialView.h" - -//#include "../common/registryoptions.h" #include "MaterialDef.h" namespace ImGuiTools { @@ -48,30 +45,21 @@ public: bool Draw( const ImVec2 &size ); - void SetPropertyListType(int listType, int stageNum = -1); + void SetPropertyListType( int listType, int stageNum = -1 ); void LoadSettings(); void SaveSettings(); //Material Interface - virtual void MV_OnMaterialChange(MaterialDoc* pMaterial); + virtual void MV_OnMaterialChange( MaterialDoc *pMaterial ); -protected: - //DECLARE_DYNCREATE(MaterialPropTreeView) +private: + int DrawGroup( int startGroupNum ); - void OnPropertyChangeNotification(); - void OnPropertyItemExpanding(); - //DECLARE_MESSAGE_MAP() - - MaterialDef* FindDefForTreeID(UINT treeID); - void RefreshProperties(); - -protected: - - MaterialDoc* currentMaterial; + MaterialDoc * currentMaterial; int currentListType; int currentStage; - MaterialDefList* currentPropDefs; + MaterialDefList * currentPropDefs; //rvRegistryOptions registry; bool internalChange; };