//********************************************************************************* // BRBDialog.cpp : implementation file // //********************************************************************************* // // Who When What // BDB 10/08/98 Generate MFC Code // //********************************************************************************* #include "stdafx.h" #include "resource.h" // main symbols #if !defined(STUFF_STUFF_HPP) #include "Stuff\Stuff.hpp" #endif #if !defined(MAXPROXIES_MAXPROXIES_HPP) #include "MAXProxies\MAXProxies.hpp" #endif #if !defined(MIDLEVELRENDERER_HPP) #include "MLR\MLR.hpp" #endif #if !defined(ELEMENTPROXIES_ELEMENTPROXIES_HPP) #include "ElementProxies\ElementProxies.hpp" #endif #if !defined(ELEMENTRENDERER_ELEMENTRENDERER_HPP) #include "ElementRenderer\ElementRenderer.hpp" #endif #if !defined(GOSFX_GOSFX_HPP) #include #endif #if !defined(TOOLOS_HPP) #include #endif #include "MAXProxies\MAXProxyHeaders.hpp" Stuff::Point3D ConvertMaxToMW(Point3 &pnt); Stuff::UnitQuaternion ConvertMaxToMW(Quat &quat); #undef Max #undef Min #include "BRBDialog.h" #include #define RAD2DEG(x) ((x)*(180/PI)) #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif void DeleteDirectory(CString dir); void ClearDirectory(CString dir); ///////////////////////////////////////////////////////////////////////////// // BRBDialog dialog BRBDialog::BRBDialog(Interface *i, CString *file_names,CWnd* pParent /*=NULL*/) : CDialog(BRBDialog::IDD, pParent) { //{{AFX_DATA_INIT(BRBDialog) //}}AFX_DATA_INIT // // set up the radio buttons // exportCharacter = -1; exportShape = 0; for (int w=0;wSetEntry("path",tstr); if (0 == exportCharacter) { // Need to specify the skeleton file CStr skelfile = maxFiles[0]; CStr p,f,f1; SplitPathFile(skelfile,&p,&f); p+= "\\skeleton\\"; for (int i=0;iSetEntry("LODSkel",f1); } } for (int w=0;wSetEntry(tag,maxFiles[w]); tag.Format("LODDist%i",w); page->SetEntry(tag,(int)m_lodFar[w]); } } note_file.SaveAs(batchfilename); /* FileStream *batch_file = Stuff::FileStream::MakeFileStream(batchfilename, FileStream::WriteOnly); Register_Object(batch_file); note_file->Write(batch_file); Unregister_Object(note_file); delete note_file; Unregister_Object(batch_file); delete batch_file; */ if (maxInterface->ExportToFile(batchfilename,false)) { if(exportCharacter==0) WriteBrbPropFile(EXPORT_CHARACTER); else WriteBrbPropFile(EXPORT_SHAPE); CDialog::OnOK(); return; } CDialog::OnCancel(); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // bool BRBDialog::AddPreferences(INode *node) { INode *data_node = node; if (node->IsRootNode()) { int i = node->NumberOfChildren(); if (i>0) { data_node = node->GetChildNode(0); } else { return false; } } // // Allocate memory for this chunk // size_t size = sizeof(ExportInfo); BYTE *data = new BYTE[size]; Mem_Copy(data, &exportInfo, sizeof(ExportInfo), size); // // Add a chunk // data_node->AddAppDataChunk( BRBDATA_CLASS_ID, BRBDATA_SUPER_CLASS_ID, PERM_DATA_ID, size,data); return true; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // bool BRBDialog::RemovePreferences(INode *node) { INode *data_node = node; if (node->IsRootNode()) { int i = node->NumberOfChildren(); if (i>0) { data_node = node->GetChildNode(0); } else { return false; } } // // Remove the chunk if it exists // data_node->RemoveAppDataChunk( BRBDATA_CLASS_ID, BRBDATA_SUPER_CLASS_ID, PERM_DATA_ID ); return true; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // void BRBDialog::GetGameDir() { TSTR ini_file = maxInterface->GetDir(APP_PLUGCFG_DIR); ini_file += "\\Plugins.ini"; Check_Pointer(Stuff::FileStreamManager::Instance); /* Stuff::FileStream *file_stream = Stuff::FileStream::MakeFileStream(); Register_Object(file_stream); file_stream->Open(ini_file); if (!file_stream->IsFileOpened()) { AFX_MANAGE_STATE(AfxGetStaticModuleState( )); AfxMessageBox("ERROR: Must have the PlugIns.ini file in : " + ini_file, MB_OK); Unregister_Object(file_stream); delete file_stream; brbGamePath = "C:\\MW4\\"; erfPath = "erf\\"; }*/ Stuff::NotationFile data_file(ini_file); //Register_Object(data_file); const char* read_dir; Page *page = data_file.FindPage("BRBData"); if (page && page->GetEntry("GameDir", &read_dir)) { brbGamePath = read_dir; } /*file_stream->Close(); Unregister_Object(data_file); delete data_file; Unregister_Object(file_stream); delete file_stream;*/ } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // method writes the BRBProps.contents file to point the brb game to the exported data // int BRBDialog::WriteBrbPropFile(ETYPE etype) { TSTR ini_file = brbGamePath + "\\Content\\Games\\BRB\\Data\\BRBProps.contents"; Stuff::NotationFile note_file; /*note_file = new Stuff::NotationFile(); Register_Object(note_file); */ Page *page = note_file.SetPage("brb_vehicle"); Check_Object(page); switch(etype) { case EXPORT_SHAPE: page->SetEntry("Model","BRBTestExport.data"); page->SetEntry("ExecutionState","NeverExecuteState"); break; case EXPORT_CHARACTER: page->SetEntry("Model","BRBVehicle.data"); page->SetEntry("Armature","BRBTestExport.contents"); page->SetEntry("ExecutionState","AnimatedMotionState"); break; case EXPORT_ANIM: page->SetEntry("Model","BRBMech.data"); page->SetEntry("Armature","BRBTestExport.contents"); page->SetEntry("ExecutionState","AnimatedMotionState"); break; } page->SetEntry("Translation","300.0 0.0 300.0"); page = note_file.SetPage("PlayerStart"); Check_Object(page); page->SetEntry("Model","Content\\Misc\\DropZone.data"); page->SetEntry("ExecutionState","NeverExecuteState"); page->SetEntry("Translation","150.0 0.0 150.0"); /*Model=Content\Misc\DropZone.data ExecutionState=NeverExecuteState Translation=150.0 0.0 150.0 */ note_file.SaveAs(ini_file); /* FileStream *prop_file = Stuff::FileStream::MakeFileStream(ini_file, FileStream::WriteOnly); Register_Object(prop_file); note_file->Write(prop_file); Unregister_Object(note_file); delete note_file; Unregister_Object(prop_file); delete prop_file; */ return 0; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // upon exiting a edit dialog save the data // void BRBDialog::OnKillfocus() { // TODO: Add your control notification handler code here UpdateData(true); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // upon exiting a edit dialog save the data // void BRBDialog::OnLod1Far() { UpdateData(true); m_lodNear[1] = m_lodFar[0]; UpdateData(false); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // upon exiting a edit dialog save the data // void BRBDialog::OnLod2Far() { UpdateData(true); m_lodNear[2] = m_lodFar[1]; UpdateData(false); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // upon exiting a edit dialog save the data // void BRBDialog::OnLod3Far() { UpdateData(true); m_lodNear[3] = m_lodFar[2]; UpdateData(false); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // upon exiting a edit dialog save the data // void BRBDialog::OnLod4Far() { UpdateData(true); m_lodNear[4] = m_lodFar[3]; UpdateData(false); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // upon exiting a edit dialog save the data // void BRBDialog::OnLod5Far() { UpdateData(true); m_lodNear[5] = m_lodFar[4]; UpdateData(false); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // upon exiting a edit dialog save the data // void BRBDialog::OnLod6Far() { UpdateData(true); m_lodNear[6] = m_lodFar[5]; UpdateData(false); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // upon exiting a edit dialog save the data // void BRBDialog::OnLod7Far() { UpdateData(true); m_lodNear[7] = m_lodFar[6]; UpdateData(false); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // upon exiting a edit dialog save the data // void BRBDialog::OnLod8Far() { UpdateData(true); } void DeleteDirectory(CString dir) { ClearDirectory(dir); RemoveDirectory(dir); } void ClearDirectory(CString dir) { HANDLE hfl; WIN32_FIND_DATA fd; if(dir[dir.GetLength()-1]=='\\') { dir=dir.Left(dir.GetLength()-1); } fd.dwFileAttributes=NULL; hfl=FindFirstFile(dir+"\\*.*",&fd); if(INVALID_HANDLE_VALUE!=hfl) { do { if (fd.dwFileAttributes&FILE_ATTRIBUTE_READONLY) { fd.dwFileAttributes &= ~FILE_ATTRIBUTE_READONLY; ::SetFileAttributes(dir+"\\"+fd.cFileName,fd.dwFileAttributes); } if(fd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) { if(strcmp(fd.cFileName,".") && strcmp(fd.cFileName,"..") ) { DeleteDirectory(dir+"\\"+fd.cFileName); } } else { DeleteFile(dir+"\\"+fd.cFileName); } } while(FindNextFile(hfl,&fd)); } } bool BRBDialog::PreviewAnimation() { GetGameDir(); CString tstr; tstr=brbGamePath + "\\Content\\Games\\Brb\\Data\\"; ClearDirectory(tstr); gos_CreateDirectory((LPCSTR)tstr); CString opath; TSTR fullpath,path,filename,extension; fullpath = maxInterface->GetCurFilePath(); if (fullpath.Length() == 0) return false; SplitFilename(fullpath,&path,&filename,&extension); opath=brbGamePath + "\\Content\\Games\\Brb\\Data\\"; if (!maxInterface->ExportToFile(opath+"BRBTestExport.armature",false)) return false; if (!maxInterface->ExportToFile(opath+"BRBTestExport.mw4anim",false)) return false; WriteBrbPropFile(EXPORT_ANIM); Stuff::NotationFile ans_file; /* ans_file = new Stuff::NotationFile(); Register_Object(ans_file); */ Page *page = ans_file.SetPage("Test1State"); Check_Object(page); page->SetEntry("AnimType","Cycletype"); page->SetEntry("Start","0.0"); page->SetEntry("Position","0.0"); page->SetEntry("Anim","Content\\Games\\BRB\\DATA\\BRBTestExport"); CString spath=opath+"BRBTestExport.AnimScript"; ans_file.SaveAs(spath); /*FileStream *out_file = Stuff::FileStream::MakeFileStream(spath, FileStream::WriteOnly); Register_Object(out_file); ans_file->Write(out_file); Unregister_Object(ans_file); delete ans_file; Unregister_Object(out_file); delete out_file;*/ return true; } BOOL BRBDialog::OnInitDialog() { CDialog::OnInitDialog(); CString fpath = maxFiles[0]; return true; /* if (fpath.GetLength()) { char drive[MAX_PATH],path[MAX_PATH],filename[MAX_PATH],ext[MAX_PATH]; _splitpath(fpath,drive,path,filename,ext); CString name; // name.Format("%s%s\\Skeleton\\%s maxInterface->LoadFromFile(name); if (maxInterface->GetINodeByName("joint_WORLD")) { // This is an armatured object, set the default export type to Character this->m_ctrlCharacter.SetCheck(1); } } */ return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }