mirror of
https://github.com/dhewm/dhewm3.git
synced 2025-04-19 08:58:56 +00:00
Material Property Tree View implementation.
This commit is contained in:
parent
69d035a1b0
commit
4e36bddfb4
2 changed files with 132 additions and 180 deletions
|
@ -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<const void*>(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<MaterialProp_t*>* 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue