#include "precompiled.h" #include "stdafx.h" #define _IGNORE_WGL_H_ #include "UserConfig.h" #include "MainFrm.h" #include "Model.h" #include "Unit.h" #include "UnitManager.h" #include "ObjectManager.h" #include "UnitPropertiesDlgBar.h" #include "EditorData.h" #include "UIGlobals.h" #undef _IGNORE_WGL_H_ #undef CRect // because it was redefined to PS_Rect in Overlay.h BEGIN_MESSAGE_MAP(CUnitPropertiesDlgBar, CDialogBar) //{{AFX_MSG_MAP(CUnitPropertiesDlgBar) // NOTE - the ClassWizard will add and remove mapping macros here. //}}AFX_MSG_MAP ON_BN_CLICKED(IDC_BUTTON_BACK, OnButtonBack) ON_BN_CLICKED(IDC_BUTTON_REFRESH, OnButtonRefresh) ON_BN_CLICKED(IDC_BUTTON_MODELBROWSE, OnButtonModelBrowse) ON_BN_CLICKED(IDC_BUTTON_TEXTUREBROWSE, OnButtonTextureBrowse) ON_BN_CLICKED(IDC_BUTTON_ANIMATIONBROWSE, OnButtonAnimationBrowse) END_MESSAGE_MAP() ////////////////////////////////////////////////////////////////////////////////// // MakeRelativeFileName: adjust the given filename to return the filename // relative to the mods/official directory - also swizzle backslashes // to forward slashes // TODO, RC: need to make this work with other root directories static CStr MakeRelativeFileName(const char* fname) { CStr result; const char* ptr=strstr(fname,"mods\\official\\"); if (!ptr) { result=fname; } else { result=ptr+strlen("mods\\official\\"); } size_t len=result.Length(); for (size_t i=0;iInsertItem(0, "Tab 1", 0); // add some test pages to the tab tabCtrl->InsertItem(1, "Tab 2", 1); tabCtrl->InsertItem(2, "Tab 3", 2); tabCtrl->InsertItem(3, "Tab 4", 3); */ // initialise data from editor data UpdatePropertiesDlg(); return TRUE; } void CUnitPropertiesDlgBar::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler) { bDisableIfNoHndler = FALSE; CDialogBar::OnUpdateCmdUI(pTarget,bDisableIfNoHndler); } void CUnitPropertiesDlgBar::OnButtonBack() { // // save current object (if we've got one) before going back // if (m_Object) { // // CStr filename("art/actors/"); // filename+=g_ObjMan.m_ObjectTypes[m_Object->m_Type].m_Name; // filename+="/"; // filename+=m_Object->m_Name; // filename+=".xml"; // if (! m_Object->Save((const char*) filename)) // ::MessageBox(0,"Error saving actor file","Error",MB_OK|MB_TASKMODAL); // // // and rebuild the model // UpdateEditorData(); // } // // CMainFrame* mainfrm=(CMainFrame*) AfxGetMainWnd(); // mainfrm->OnUnitTools(); } void CUnitPropertiesDlgBar::OnButtonRefresh() { UpdateEditorData(); } void CUnitPropertiesDlgBar::OnButtonTextureBrowse() { const char* filter="DDS Files|*.dds|PNG Files|*.png||"; CFileDialog dlg(TRUE,g_UserCfg.GetOptionString(CFG_TEXTUREEXT),0,OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR,filter,0); dlg.m_ofn.lpstrInitialDir=g_UserCfg.GetOptionString(CFG_MODELTEXLOADDIR); if (dlg.DoModal()==IDOK) { CStr filename=MakeRelativeFileName(dlg.m_ofn.lpstrFile); CStr dir(dlg.m_ofn.lpstrFile); dir=dir.Left(dlg.m_ofn.nFileOffset-1); g_UserCfg.SetOptionString(CFG_MODELTEXLOADDIR,(const char*) dir); CWnd* texture=GetDlgItem(IDC_EDIT_TEXTURE); texture->SetWindowText(filename); } } void CUnitPropertiesDlgBar::OnButtonAnimationBrowse() { const char* filter="PSA Files|*.psa||"; CFileDialog dlg(TRUE,"psa",0,OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR,filter,0); dlg.m_ofn.lpstrInitialDir=g_UserCfg.GetOptionString(CFG_MODELANIMATIONDIR); if (dlg.DoModal()==IDOK) { CStr filename=MakeRelativeFileName(dlg.m_ofn.lpstrFile); CStr dir(dlg.m_ofn.lpstrFile); dir=dir.Left(dlg.m_ofn.nFileOffset-1); g_UserCfg.SetOptionString(CFG_MODELANIMATIONDIR,(const char*) dir); CWnd* animation=GetDlgItem(IDC_EDIT_ANIMATION); animation->SetWindowText(filename); } } void CUnitPropertiesDlgBar::OnButtonModelBrowse() { const char* filter="PMD Files|*.pmd|0ADM Files|*.0adm||"; CFileDialog dlg(TRUE,"pmd",0,OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR,filter,0); dlg.m_ofn.lpstrInitialDir=g_UserCfg.GetOptionString(CFG_MODELLOADDIR); if (dlg.DoModal()==IDOK) { CStr filename=MakeRelativeFileName(dlg.m_ofn.lpstrFile); CStr dir(dlg.m_ofn.lpstrFile); dir=dir.Left(dlg.m_ofn.nFileOffset-1); g_UserCfg.SetOptionString(CFG_MODELLOADDIR,(const char*) dir); CWnd* texture=GetDlgItem(IDC_EDIT_MODEL); texture->SetWindowText(filename); } } void CUnitPropertiesDlgBar::UpdateEditorData() { // if (!m_Object) { // g_ObjMan.SetSelectedObject(0); // return; // } // // CString str; // // CWnd* name=GetDlgItem(IDC_EDIT_NAME); // name->GetWindowText(str); // m_Object->m_Name=(const char*)str; // // CWnd* model=GetDlgItem(IDC_EDIT_MODEL); // model->GetWindowText(str); // m_Object->m_ModelName=(const char*)str; // // CWnd* texture=GetDlgItem(IDC_EDIT_TEXTURE); // texture->GetWindowText(str); // m_Object->m_TextureName=(const char*)str; // // CWnd* animation=GetDlgItem(IDC_EDIT_ANIMATION); // animation->GetWindowText(str); // if (m_Object->m_Animations.size()==0) { // m_Object->m_Animations.resize(1); // m_Object->m_Animations[0].m_AnimName="Idle"; // } // m_Object->m_Animations[0].m_FileName=(const char*)str; // // std::vector animupdatelist; // const std::vector& units=g_UnitMan.GetUnits(); // for (uint i=0;iGetModel()->GetModelDef()==m_Object->m_Model->GetModelDef()) { // animupdatelist.push_back(units[i]); // } // } // if (m_Object->BuildModel()) { // g_ObjMan.SetSelectedObject(m_Object); // CSkeletonAnim* anim=m_Object->m_Model->GetAnimation(); // if (anim) { // for (uint i=0;iGetModel()->SetAnimation(anim); // } // } // } else { // g_ObjMan.SetSelectedObject(0); // } } void CUnitPropertiesDlgBar::UpdatePropertiesDlg() { // if (!m_Object) return; // // CWnd* name=GetDlgItem(IDC_EDIT_NAME); // if (name) { // name->SetWindowText(m_Object->m_Name); // } // // CWnd* model=GetDlgItem(IDC_EDIT_MODEL); // if (model) { // model->SetWindowText(m_Object->m_ModelName); // } // // CWnd* texture=GetDlgItem(IDC_EDIT_TEXTURE); // if (texture) { // texture->SetWindowText(m_Object->m_TextureName); // } // // CWnd* animation=GetDlgItem(IDC_EDIT_ANIMATION); // if (animation) { // if (m_Object->m_Animations.size()>0) { // animation->SetWindowText(m_Object->m_Animations[0].m_FileName); // } // } } void CUnitPropertiesDlgBar::SetObject(CObjectEntry* obj) { // m_Object=obj; // if (m_Object) { // if (m_Object->BuildModel()) { // g_ObjMan.SetSelectedObject(m_Object); // } else { // g_ObjMan.SetSelectedObject(0); // } // } // UpdatePropertiesDlg(); }