示例#1
0
/**
* 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();
}
void MaterialPreviewPropView::AddLight(void)
{
	int i, count, lightShaderIndex = 0;
	const idMaterial *mat;

	CPropTreeItemButton	*pRoot;
	CPropTreeItemCombo		*pCombo;
	CPropTreeItemColor		*pColor;
	CPropTreeItemCheck		*pCheck;
	CPropTreeItemEdit		*pEdit;

	//Increase the number of lights
	numLights++;

	pRoot = (CPropTreeItemButton *)m_Tree.InsertItem(new CPropTreeItemButton());
	pRoot->SetLabelText(_T(va("Light #%d", numLights)));
	pRoot->SetInfoText(_T(va("Parameters for light number %d.", numLights)));
	pRoot->SetButtonText("Remove");
	pRoot->SetCtrlID(numLights - 1);
	pRoot->Expand();

	pCombo = (CPropTreeItemCombo *)m_Tree.InsertItem(new CPropTreeItemCombo(), pRoot);
	pCombo->SetLabelText(_T("Shader"));
	pCombo->SetInfoText(_T("Set the light shader."));
	pCombo->SetDropDownHeight(200);
	pCombo->CreateComboBox();
	// Add all light shaders to the combo box
	count = declManager->GetNumDecls(DECL_MATERIAL);

	for (i = 0; i < count; i++) {
		mat = declManager->MaterialByIndex(i, false);

		idStr materialName = mat->GetName();
		materialName.ToLower();

		if (materialName.Left(7) == "lights/" || materialName.Left(5) == "fogs/") {
			pCombo->InsertString(lightShaderIndex, materialName);
			pCombo->SetItemData(lightShaderIndex, lightShaderIndex);

			if (materialName == "lights/defaultpointlight") {
				pCombo->SetCurSel(lightShaderIndex);
			}

			lightShaderIndex++;
		}
	}

	pColor = (CPropTreeItemColor *)m_Tree.InsertItem(new CPropTreeItemColor(), pRoot);
	pColor->SetLabelText(_T("Color"));
	pColor->SetInfoText(_T("Color of the light."));
	pColor->SetItemValue((LPARAM)RGB(0xff, 0xff, 0xff)); // default as color white

	pEdit = (CPropTreeItemEdit *)m_Tree.InsertItem(new CPropTreeItemEdit(), pRoot);
	pEdit->SetLabelText(_T("Radius"));
	pEdit->SetInfoText(_T("Radius of the light."));
	pEdit->SetItemValue((LPARAM)_T("300.0"));

	pCheck = (CPropTreeItemCheck *)m_Tree.InsertItem(new CPropTreeItemCheck(), pRoot);
	pCheck->SetLabelText(_T("Move light"));
	pCheck->SetInfoText(_T("When checked, allow light to move."));
	pCheck->CreateCheckBox();
	pCheck->SetCheckState(BST_CHECKED);

	if (materialPreview) {
		materialPreview->OnAddLight();
	}
}
//Create sample data for the preview properties
void MaterialPreviewPropView::InitializePropTree(void)
{
	int i;
	CPropTreeItem		*pRoot;
	CPropTreeItem		*pParmRoot;
	CPropTreeItemCheck	*pCheck;
	CPropTreeItemEdit	*pEdit;

	pRoot = m_Tree.InsertItem(new CPropTreeItem());
	pRoot->SetLabelText(_T("Preview Properties"));
	pRoot->SetInfoText(_T("Properties for the preview window."));
	pRoot->Expand(); // have this item expanded by default

	CPropTreeItemCombo *pCombo;
	pCombo = (CPropTreeItemCombo *)m_Tree.InsertItem(new CPropTreeItemCombo(), pRoot);
	pCombo->SetLabelText(_T("Model Type"));
	pCombo->SetInfoText(_T("Select the type of model on which to preview the material."));
	pCombo->CreateComboBox();
	pCombo->InsertString(0, "Cube");
	pCombo->InsertString(1, "Box - 2:1");
	pCombo->InsertString(2, "Box - 4:1");
	pCombo->InsertString(3, "Box - 1:2");
	pCombo->InsertString(4, "Box - 1:4");
	pCombo->InsertString(5, "Cylinder - V");
	pCombo->InsertString(6, "Cylinder - H");
	pCombo->InsertString(7, "Sphere");
	pCombo->SetItemData(0, 0);
	pCombo->SetItemData(1, 1);
	pCombo->SetItemData(2, 2);
	pCombo->SetItemData(3, 3);
	pCombo->SetItemData(4, 4);
	pCombo->SetItemData(5, 5);
	pCombo->SetItemData(6, 6);
	pCombo->SetItemData(7, 7);

	pCombo->SetCurSel(0);

	// Custom model entry
	/*pEdit = (CPropTreeItemEdit*)m_Tree.InsertItem( new CPropTreeItemEdit(), pRoot );
	pEdit->SetLabelText(_T("Custom Model"));
	pEdit->SetInfoText(_T("Specify any model to display the current material."));
	pEdit->SetItemValue((LPARAM)_T(""));*/
	CPropTreeItemEditButton *pCutomButton;
	pCutomButton = (CPropTreeItemEditButton *)m_Tree.InsertItem(new CPropTreeItemEditButton(), pRoot);
	pCutomButton->SetButtonText(_T("..."));
	pCutomButton->SetLabelText(_T("Custom Model"));
	pCutomButton->SetInfoText(_T("Specify any model to display the current material."));
	pCutomButton->SetItemValue((LPARAM)_T(""));

	// Checkbox for showing debug light spheres
	pCheck = (CPropTreeItemCheck *)m_Tree.InsertItem(new CPropTreeItemCheck(), pRoot);
	pCheck->SetLabelText(_T("Show Lights"));
	pCheck->SetInfoText(_T("Show the light origin sphere and number in the preview."));
	pCheck->CreateCheckBox();
	pCheck->SetCheckState(BST_CHECKED);

	// Local and Global shader parms
	pParmRoot = m_Tree.InsertItem(new CPropTreeItem());
	pParmRoot->SetLabelText(_T("Local Parms"));
	pParmRoot->SetInfoText(_T("Local shaderparms for the model being displayed."));
	pParmRoot->Expand(FALSE);   // have this item NOT expanded by default

	for (i = 0; i < MAX_ENTITY_SHADER_PARMS; i++) {
		pEdit = (CPropTreeItemEdit *)m_Tree.InsertItem(new CPropTreeItemEdit(), pParmRoot);
		pEdit->SetLabelText(_T(va("parm%d", i)));
		pEdit->SetInfoText(_T("Set the local shaderparm for the model"));

		if (i < 4) {
			pEdit->SetItemValue((LPARAM)_T("1"));
		} else {
			pEdit->SetItemValue((LPARAM)_T("0"));
		}
	}

	pParmRoot = m_Tree.InsertItem(new CPropTreeItem());
	pParmRoot->SetLabelText(_T("Global Parms"));
	pParmRoot->SetInfoText(_T("Global shaderparms for the renderworld being displayed."));
	pParmRoot->Expand(FALSE);   // have this item NOT expanded by default

	for (i = 0; i < MAX_GLOBAL_SHADER_PARMS; i++) {
		pEdit = (CPropTreeItemEdit *)m_Tree.InsertItem(new CPropTreeItemEdit(), pParmRoot);
		pEdit->SetLabelText(_T(va("global%d", i)));
		pEdit->SetInfoText(_T("Set the global shaderparm for the renderworld"));

		if (i < 4) {
			pEdit->SetItemValue((LPARAM)_T("1"));
		} else {
			pEdit->SetItemValue((LPARAM)_T("0"));
		}
	}

	// Lights

	pRoot = m_Tree.InsertItem(new CPropTreeItem());
	pRoot->SetLabelText(_T(""));
	pRoot->SetInfoText(_T(""));

	CPropTreeItemButton *pButton;
	pButton = (CPropTreeItemButton *)m_Tree.InsertItem(new CPropTreeItemButton());
	pButton->SetButtonText(_T(" Add Light "));
	pButton->SetLabelText(_T("Preview Lights"));
	pButton->SetInfoText(_T("Test the button."));

	pRoot = m_Tree.InsertItem(new CPropTreeItem());
	pRoot->SetLabelText(_T(""));
	pRoot->SetInfoText(_T(""));

	AddLight();
}