/** * Gets the source of the current document and populates the * source edit control. */ void MaterialEditView::GetMaterialSource() { //Clear it sourceInit = true; m_textView.SetText(""); sourceInit = false; if(materialDocManager) { MaterialDoc* material = materialDocManager->GetCurrentMaterialDoc(); if(material) { idStr text = material->GetEditSourceText(); // clean up new-line crapola text.Replace( "\r", "" ); text.Replace( "\n", "\r" ); text.Replace( "\v", "\r" ); text.StripLeading( '\r' ); text.Append( "\r" ); sourceInit = true; m_textView.SetText(text); sourceInit = false; } } }
/** * Handles all of the little problems associated with renaming a folder. */ void MaterialTreeView::RenameMaterial( HTREEITEM item, const char *originalName ) { CTreeCtrl &tree = GetTreeCtrl(); const idMaterial *material = declManager->FindMaterial( originalName ); MaterialDoc *pMaterial; //pMaterial = materialDocManager->GetInProgressDoc(material); //if(!pMaterial) { pMaterial = materialDocManager->CreateMaterialDoc( const_cast<idMaterial *>( material ) ); //} //Remove our old quick lookup value materialToTree.Remove( originalName ); //Generate the new name idStr materialName; HTREEITEM parent = tree.GetParentItem( item ); DWORD parentType = tree.GetItemData( parent ); if( parentType == TYPE_MATERIAL_FOLDER ) { //Need to include the material folder materialName = GetMediaPath( parent, TYPE_MATERIAL_FOLDER ); materialName += "/"; } materialName += tree.GetItemText( item ); //Add it to our quick lookup materialToTree.Set( materialName, item ); //Finally make the change internalChange = true; pMaterial->SetMaterialName( materialName, false ); internalChange = false; }
/** * 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(); }
/** * Performs an undo operation of a deleted stage. */ void StageDeleteModifier::Undo() { MaterialDoc* material = manager->CreateMaterialDoc(materialName); material->InsertStage(stageNum, stageData.GetInt("stagetype"), stageData.GetString("name"), false); material->SetData(stageNum, &stageData); }
/** * Updated the material when an attribute has been changed. */ void MaterialPropTreeView::OnPropertyChangeNotification( NMHDR *nmhdr, LRESULT *lresult ) { 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; }
/** * Performs the stage move when the user has dragged and dropped a stage. */ void StageView::DropItemOnList() { CListCtrl& list = GetListCtrl(); int toStage; //Get and adjust the drop index based on the direction of the move dropIndex = list.HitTest(dropPoint); if(dropIndex < 0) dropIndex = list.GetItemCount()-1; //Ignore the drop if the index is the same or they are droping on the material if(dropIndex == dragIndex || dropIndex == 0) return; //Move the stage data MaterialDoc* material = materialDocManager->GetCurrentMaterialDoc(); internalChange = true; toStage = dropIndex-1; material->MoveStage(dragIndex-1, dropIndex-1); internalChange = false; if(dragIndex < dropIndex) { dropIndex++; } //Get the item char szLabel[256]; LV_ITEM lvi; ZeroMemory(&lvi, sizeof(LV_ITEM)); lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE | LVIF_PARAM; lvi.stateMask = LVIS_DROPHILITED | LVIS_FOCUSED | LVIS_SELECTED; lvi.pszText = szLabel; lvi.iItem = dragIndex; lvi.cchTextMax = 255; list.GetItem(&lvi); //Insert the item lvi.iItem = dropIndex; list.InsertItem(&lvi); //Adjust the drag index if the move was up in the list if(dragIndex > dropIndex) { dragIndex++; } //Delete the original item list.DeleteItem(dragIndex); int type = -1; int stageType = currentMaterial->GetAttributeInt(toStage, "stagetype"); switch(stageType) { case MaterialDoc::STAGE_TYPE_NORMAL: type = MaterialDefManager::MATERIAL_DEF_STAGE; break; case MaterialDoc::STAGE_TYPE_SPECIALMAP: type = MaterialDefManager::MATERIAL_DEF_SPECIAL_STAGE; break; } m_propView->SetPropertyListType(type, toStage); }
/** * Determines is a label edit can be performed on the selected stage. */ void StageView::OnLvnBeginlabeledit(NMHDR *pNMHDR, LRESULT *pResult) { NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR); //if this is a special stage then don't allow edit int index = pDispInfo->item.iItem; MaterialDoc* material = materialDocManager->GetCurrentMaterialDoc(); if(index <= 0 || material->GetAttributeInt(index-1, "stagetype") != MaterialDoc::STAGE_TYPE_NORMAL) { *pResult = 1; return; } //ToDo: Can we move the edit box /*HWND edit = ListView_GetEditControl(m_hWnd); CWnd* editWnd = CWnd::FromHandle(edit); CRect rect; editWnd->GetWindowRect(rect); rect.left += 22; rect.right += 22; editWnd->MoveWindow(rect);*/ *pResult = 0; }
/** * Conforms the user wants to delete all stages and then performs the operation. */ void StageView::OnDeleteAllStages() { int result = MessageBox("Are you sure you want to delete all stages?", "Delete?", MB_ICONQUESTION | MB_YESNO); if(result == IDYES) { MaterialDoc* material = materialDocManager->GetCurrentMaterialDoc(); material->ClearStages(); } }
/** * Called when the user changes text in the edit control */ void MaterialEditView::OnEnChangeEdit( NMHDR *pNMHDR, LRESULT *pResult ) { if(materialDocManager && !sourceInit) { MaterialDoc* material = materialDocManager->GetCurrentMaterialDoc(); if(material && !material->IsSourceModified()) { sourceChanged = true; material->SourceModify(this); } } }
/** * Called by the ToggleListView when the toggle state has changed. */ void StageView::OnStateChanged(int index, int toggleState) { MaterialDoc* material = materialDocManager->GetCurrentMaterialDoc(); if(material && index > 0) { if (toggleState == ToggleListView::TOGGLE_STATE_ON) { material->EnableStage(index-1, true); } else if (toggleState == ToggleListView::TOGGLE_STATE_OFF) { material->EnableStage(index-1, false); } } }
/** * Performs the stage name change after the label edit is done. */ void StageView::OnLvnEndlabeledit( NMHDR *pNMHDR, LRESULT *pResult ) { NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO *>( pNMHDR ); if( pDispInfo->item.pszText ) { MaterialDoc *material = materialDocManager->GetCurrentMaterialDoc(); internalChange = true; material->SetAttribute( pDispInfo->item.iItem - 1, "name", pDispInfo->item.pszText ); internalChange = false; *pResult = 1; } else { *pResult = 0; } }
/** * Makes sure that a rename operation can be performed after a label edit is complete and * performs the folder or material rename. */ void MaterialTreeView::OnTvnEndlabeledit( NMHDR *pNMHDR, LRESULT *pResult ) { LPNMTVDISPINFO pTVDispInfo = reinterpret_cast<LPNMTVDISPINFO>( pNMHDR ); *pResult = 0; if( pTVDispInfo->item.pszText ) { //Convert any edited text to lower case to keep the name canonical idStr newLabel = pTVDispInfo->item.pszText; newLabel.ToLower(); strncpy( pTVDispInfo->item.pszText, newLabel.c_str(), pTVDispInfo->item.cchTextMax ); CTreeCtrl &tree = GetTreeCtrl(); DWORD type = tree.GetItemData( pTVDispInfo->item.hItem ); if( type == TYPE_MATERIAL ) { MaterialDoc *pMaterial = materialDocManager->GetCurrentMaterialDoc(); //Remove our old quick lookup value materialToTree.Remove( pMaterial->name.c_str() ); //Generate the new name idStr material; HTREEITEM parent = tree.GetParentItem( pTVDispInfo->item.hItem ); DWORD parentType = tree.GetItemData( parent ); if( parentType == TYPE_MATERIAL_FOLDER ) { //Need to include the material folder material = GetMediaPath( parent, TYPE_MATERIAL_FOLDER ); material += "/"; } material += pTVDispInfo->item.pszText; if( declManager->FindMaterial( material, false ) ) { //Can't rename because it conflicts with an existing file MessageBox( "Unable to rename material because it conflicts with another material", "Error" ); } else { //Add it to our quick lookup materialToTree.Set( material, pTVDispInfo->item.hItem ); //Finally make the change internalChange = true; pMaterial->SetMaterialName( material ); internalChange = false; renamedFolder = pTVDispInfo->item.hItem; PostMessage( MSG_RENAME_MATERIAL_COMPLETE ); *pResult = 1; } } else if( type == TYPE_MATERIAL_FOLDER ) { //Clean up the quicktree with the current tree before we allow the edit to commit CleanLookupTrees( pTVDispInfo->item.hItem ); //Store some data so the we can make the appropriate changes after the commit renamedFolder = pTVDispInfo->item.hItem; affectedMaterials.Clear(); GetMaterialPaths( renamedFolder, &affectedMaterials ); PostMessage( MSG_RENAME_FOLDER_COMPLETE ); RenameMaterialFolderModifier *mod = new RenameMaterialFolderModifier( materialDocManager, pTVDispInfo->item.pszText, this, pTVDispInfo->item.hItem, tree.GetItemText( pTVDispInfo->item.hItem ) ); materialDocManager->AddMaterialUndoModifier( mod ); *pResult = 1; } } }
/** * Takes the source out of the edit control and applies it * to the material. */ void MaterialEditView::ApplyMaterialSource() { if(!sourceChanged) return; MaterialDoc* material = materialDocManager->CreateMaterialDoc(currentMaterialName); if(material) { idStr text = GetSourceText(); material->ApplySourceModify(text); } sourceChanged = false; }
/** * Deletes the selected stage when the user selects the delete menu option. */ void StageView::OnDeleteStage() { CListCtrl &list = GetListCtrl(); POSITION pos = list.GetFirstSelectedItemPosition(); int nItem = -1; if( pos ) { nItem = list.GetNextSelectedItem( pos ); if( nItem > 0 ) { int result = MessageBox( "Are you sure you want to delete this stage?", "Delete?", MB_ICONQUESTION | MB_YESNO ); if( result == IDYES ) { MaterialDoc *material = materialDocManager->GetCurrentMaterialDoc(); material->RemoveStage( nItem - 1 ); } } } }
/** * Returns true if the current state of the stage view will allow a rename operation */ bool StageView::CanRename() { CListCtrl &list = GetListCtrl(); POSITION pos = list.GetFirstSelectedItemPosition(); int nItem = -1; if( pos ) { nItem = list.GetNextSelectedItem( pos ); } if( nItem > 0 ) { MaterialDoc *material = materialDocManager->GetCurrentMaterialDoc(); if( nItem > 0 && material->GetAttributeInt( nItem - 1, "stagetype" ) == MaterialDoc::STAGE_TYPE_NORMAL ) { return true; } } return false; }
/** * Performs a paste operation when the user selects the menu option. */ void StageView::OnPaste() { if( materialDocManager->IsCopyStage() ) { MaterialDoc *material = materialDocManager->GetCurrentMaterialDoc(); int type; idStr name; materialDocManager->GetCopyStageInfo( type, name ); int existingIndex = material->FindStage( type, name ); if( type != MaterialDoc::STAGE_TYPE_SPECIALMAP || existingIndex == -1 ) { materialDocManager->PasteStage( material ); } else { if( MessageBox( va( "Do you want to replace '%s' stage?", name.c_str() ), "Replace?", MB_ICONQUESTION | MB_YESNO ) == IDYES ) { material->RemoveStage( existingIndex ); materialDocManager->PasteStage( material ); } } } }
/** * Dispalys the popup menu with the appropriate menu items enabled. */ void StageView::PopupMenu(CPoint* pt) { //Determine the type of object clicked on CListCtrl& list = GetListCtrl(); ClientToScreen (pt); CMenu FloatingMenu; VERIFY(FloatingMenu.LoadMenu(IDR_ME_STAGELIST_POPUP)); CMenu* pPopupMenu = FloatingMenu.GetSubMenu (0); ASSERT(pPopupMenu != NULL); POSITION pos = list.GetFirstSelectedItemPosition(); int nItem = -1; if(pos) nItem = list.GetNextSelectedItem(pos); if(nItem <= 0) { pPopupMenu->EnableMenuItem(ID_STAGEPOPUP_RENAMESTAGE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); pPopupMenu->EnableMenuItem(ID_STAGEPOPUP_DELETESTAGE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); pPopupMenu->EnableMenuItem(ID_STAGEPOPUP_CUT, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); pPopupMenu->EnableMenuItem(ID_STAGEPOPUP_COPY, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); } else { MaterialDoc* material = materialDocManager->GetCurrentMaterialDoc(); if(material->GetAttributeInt(nItem-1, "stagetype") != MaterialDoc::STAGE_TYPE_NORMAL) { pPopupMenu->EnableMenuItem(ID_STAGEPOPUP_RENAMESTAGE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); } } MaterialDoc* material = materialDocManager->GetCurrentMaterialDoc(); if(material->FindStage(MaterialDoc::STAGE_TYPE_SPECIALMAP, "bumpmap") >= 0) { pPopupMenu->EnableMenuItem(ID_STAGEPOPUP_ADDBUMPMAP, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); } if(material->FindStage(MaterialDoc::STAGE_TYPE_SPECIALMAP, "diffusemap") >= 0) { pPopupMenu->EnableMenuItem(ID_STAGEPOPUP_ADDDIFFUSEMAP, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); } if(material->FindStage(MaterialDoc::STAGE_TYPE_SPECIALMAP, "specularmap") >= 0) { pPopupMenu->EnableMenuItem(ID_STAGEPOPUP_ADDSPECULAR, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); } if(materialDocManager->IsCopyStage()) { pPopupMenu->EnableMenuItem(ID_STAGEPOPUP_PASTE, MF_BYCOMMAND | MF_ENABLED); } else { pPopupMenu->EnableMenuItem(ID_STAGEPOPUP_PASTE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); } pPopupMenu->TrackPopupMenu (TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt->x, pt->y, &list); }
/** * Performs a redo operation of an inserted stage. */ void StageInsertModifier::Redo() { MaterialDoc *material = manager->CreateMaterialDoc(materialName); material->InsertStage(stageNum, stageType, stageName, false); }
/** * Performs an undo operation of an inserted stage. */ void StageInsertModifier::Undo() { MaterialDoc *material = manager->CreateMaterialDoc(materialName); material->RemoveStage(stageNum, false); }
/** * Performs a redo operation of a deleted stage. */ void StageDeleteModifier::Redo() { MaterialDoc *material = manager->CreateMaterialDoc(materialName); material->RemoveStage(stageNum, false); }
/** * Performs a redo operation of a moved stage. */ void StageMoveModifier::Redo() { MaterialDoc *material = manager->CreateMaterialDoc(materialName); material->MoveStage(from, to, false); }
/** * Performs an undo operation of a boolean attribute change. */ void AttributeMaterialModifierBool::Undo() { MaterialDoc *material = manager->CreateMaterialDoc(materialName); material->SetAttributeBool(stage, key, oldValue, false); }
/** * Performs a redo operation of a renamed material. */ void RenameMaterialModifier::Redo() { MaterialDoc *material = manager->CreateMaterialDoc(oldName); material->SetMaterialName(materialName, false); }
/** * Adds a new diffusemap stage when the user selects the menu option. */ void StageView::OnAddDiffuseStage() { MaterialDoc* material = materialDocManager->GetCurrentMaterialDoc(); material->AddStage(MaterialDoc::STAGE_TYPE_SPECIALMAP, "diffusemap"); }
/** * Adds a new specularmap stage when the user selects the menu option. */ void StageView::OnAddSpecualarStage() { MaterialDoc* material = materialDocManager->GetCurrentMaterialDoc(); material->AddStage(MaterialDoc::STAGE_TYPE_SPECIALMAP, "specularmap"); }
/** * Performs a redo operation of a string attribute change. */ void AttributeMaterialModifierString::Redo() { MaterialDoc *material = manager->CreateMaterialDoc(materialName); material->SetAttribute(stage, key, value, false); }
/** * Adds a new stage when the user selects the menu option. */ void StageView::OnAddStage() { MaterialDoc* material = materialDocManager->GetCurrentMaterialDoc(); idStr name = va("Stage %d", material->GetStageCount()+1); material->AddStage(MaterialDoc::STAGE_TYPE_NORMAL, name.c_str()); }