2024-12-21 10:04:04 +08:00
// EtViewerDoc.cpp : CEtViewerDoc Ŭ<> <C5AC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
//
# include "stdafx.h"
# include "EtViewer.h"
# include "EtViewerDoc.h"
# include "GlobalValue.h"
# include "RenderBase.h"
# include "MainFrm.h"
# include "PaneDefine.h"
# include "UserMessage.h"
# include "SkinPrevDlg.h"
# include "EtResourceMng.h"
# ifdef _DEBUG
# define new DEBUG_NEW
# endif
// CEtViewerDoc
IMPLEMENT_DYNCREATE ( CEtViewerDoc , CDocument )
BEGIN_MESSAGE_MAP ( CEtViewerDoc , CDocument )
ON_COMMAND ( ID_FILE_OPEN , & CEtViewerDoc : : OnFileOpen )
ON_COMMAND ( ID_FILE_SAVE , & CEtViewerDoc : : OnFileSave )
ON_COMMAND ( ID_FILE_NEW , & CEtViewerDoc : : OnFileNew )
ON_COMMAND ( ID_FILE_EXPORTSCENE , & CEtViewerDoc : : OnFileExportscene )
END_MESSAGE_MAP ( )
// CEtViewerDoc <20> <> <EFBFBD> <EFBFBD> /<2F> Ҹ<EFBFBD>
CEtViewerDoc : : CEtViewerDoc ( )
{
// TODO: <20> <> <EFBFBD> <20> <> ȸ<EFBFBD> <C8B8> <20> <> <EFBFBD> <EFBFBD> <20> ڵ带 <20> ߰<EFBFBD> <DFB0> մϴ<D5B4> .
}
CEtViewerDoc : : ~ CEtViewerDoc ( )
{
}
BOOL CEtViewerDoc : : OnNewDocument ( )
{
if ( ! CDocument : : OnNewDocument ( ) )
return FALSE ;
// TODO: <20> <> <EFBFBD> <20> <> <EFBFBD> ʱ<EFBFBD> ȭ <20> ڵ带 <20> ߰<EFBFBD> <DFB0> մϴ<D5B4> .
// SDI <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> ٽ<EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> մϴ<D5B4> .
return TRUE ;
}
// CEtViewerDoc serialization
void CEtViewerDoc : : Serialize ( CArchive & ar )
{
if ( ar . IsStoring ( ) )
{
// TODO: <20> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> ڵ带 <20> ߰<EFBFBD> <DFB0> մϴ<D5B4> .
}
else
{
// TODO: <20> <> <EFBFBD> <20> ε<EFBFBD> <20> ڵ带 <20> ߰<EFBFBD> <DFB0> մϴ<D5B4> .
CFile * pFile = ar . GetFile ( ) ;
CString szFileName = pFile - > GetFilePath ( ) ;
char szTemp [ 512 ] = { 0 , } , szExt [ 32 ] = { 0 , } , szPath [ 512 ] = { 0 , } ;
_GetExt ( szExt , _countof ( szExt ) , szFileName ) ;
_GetFullFileName ( szTemp , _countof ( szTemp ) , szFileName ) ;
_GetPath ( szPath , _countof ( szTemp ) , szFileName ) ;
SetCurrentDirectory ( szPath ) ;
CEtResourceMng : : GetInstance ( ) . AddResourcePath ( szPath ) ;
if ( _stricmp ( szExt , " skn " ) = = NULL ) {
if ( CGlobalValue : : GetInstance ( ) . GetView ( ) = = NULL ) {
CGlobalValue : : GetInstance ( ) . m_szVecInitLoadFile = szTemp ;
return ;
}
// CGlobalValue::GetInstance().ResetObject();
CObjectBase * pParent = CGlobalValue : : GetInstance ( ) . GetOneObject ( CObjectBase : : SCENE ) ;
if ( pParent = = NULL ) return ;
CObjectBase * pBase = new CObjectSkin ;
pBase - > SetName ( CString ( szTemp ) ) ;
( ( CObjectSkin * ) pBase ) - > LoadSkin ( szFileName , true ) ;
CGlobalValue : : GetInstance ( ) . AddObject ( pParent - > GetName ( ) , pBase ) ;
DWORD dwAttr = GetFileAttributes ( szFileName ) ;
if ( dwAttr & FILE_ATTRIBUTE_READONLY ) {
CString szStr ;
szStr . Format ( " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> ϵ<EFBFBD> <CFB5> <EFBFBD> <20> б <EFBFBD> <D0B1> <EFBFBD> <EFBFBD> <EFBFBD> <20> Ӽ<EFBFBD> <D3BC> Դϴ<D4B4> .\n \n %s " , szFileName ) ;
MessageBox ( ( ( CMainFrame * ) AfxGetMainWnd ( ) ) - > m_hWnd , szStr , " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> " , MB_OK ) ;
}
}
else if ( _stricmp ( szExt , " ani " ) = = NULL ) {
int nCount = CGlobalValue : : GetInstance ( ) . GetObjectCount ( CObjectBase : : SKIN ) ;
if ( nCount ! = 1 ) return ;
CObjectBase * pParent = CGlobalValue : : GetInstance ( ) . GetOneObject ( CObjectBase : : SKIN ) ;
CObjectBase * pBase = new CObjectAnimation ;
if ( ( ( CObjectAnimation * ) pBase ) - > LoadAnimation ( szFileName ) = = false ) {
SAFE_DELETE ( pBase ) ;
}
else
CGlobalValue : : GetInstance ( ) . AddObject ( pParent - > GetName ( ) , pBase ) ;
}
else if ( _stricmp ( szExt , " scn " ) = = NULL ) {
CGlobalValue : : GetInstance ( ) . ImportScene ( CString ( szTemp ) ) ;
}
}
}
// CEtViewerDoc <20> <> <EFBFBD> <EFBFBD>
# ifdef _DEBUG
void CEtViewerDoc : : AssertValid ( ) const
{
CDocument : : AssertValid ( ) ;
}
void CEtViewerDoc : : Dump ( CDumpContext & dc ) const
{
CDocument : : Dump ( dc ) ;
}
# endif //_DEBUG
// CEtViewerDoc <20> <> <EFBFBD> <EFBFBD>
void CEtViewerDoc : : OnFileOpen ( )
{
CString szFileList ;
TCHAR szFilter [ ] = _T ( " Eternity Support File (*.skn;*.ani;*.scn;*.txt)|*.skn;*.ani;*.scn;*.txt|Eternity Skin File (*.skn)|*.skn|Eternity Animation File (*.ani)|*.ani|Eternity Scene File (*.scn)|*.scn|Eternity Simulation File (*.txt)|*.txt|All Files (*.*)|*.*|| " ) ;
CSkinPrevDlg dlg ( TRUE , _T ( " skn;ani;scn;txt " ) , _T ( " *.skn;*.ani;*.scn;*.txt " ) , OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_ALLOWMULTISELECT | OFN_ENABLESIZING , szFilter , CGlobalValue : : GetInstance ( ) . GetView ( ) ) ;
dlg . GetOFN ( ) . lpstrFile = szFileList . GetBuffer ( 100000 ) ;
dlg . GetOFN ( ) . nMaxFile = 100000 ;
dlg . m_ofn . lpstrTitle = " Open Eternity Engine File " ;
if ( IDOK ! = dlg . DoModal ( ) ) {
szFileList . ReleaseBuffer ( ) ;
return ;
}
// <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> ½<EFBFBD> <20> <> Ģ
// Scene <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
// skn<6B> <6E> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> skn <20> ε<EFBFBD>
// skn<6B> ϳ <EFBFBD> & ani <20> Ѱ<EFBFBD> <20> ̻<EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> ε<EFBFBD>
// skn<6B> <6E> <EFBFBD> <EFBFBD> <EFBFBD> Կ<EFBFBD> ani <20> Ѱ<EFBFBD> <20> ̻<EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
// ani<6E> <69> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
// Scene <20> <> skn<6B> ϳ <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
// ani <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> ε<EFBFBD>
// skn <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> Scene reset <20> <> <20> ε<EFBFBD>
// skn<6B> ϳ <EFBFBD> & ani <20> Ѱ<EFBFBD> <20> ̻<EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Scene Reset <20> <> <20> ε<EFBFBD>
std : : vector < CString > szVecSkinList ;
std : : vector < CString > szVecAniList ;
std : : vector < CString > szVecSceneList ;
std : : vector < CString > szVecSimList ;
CGlobalValue : : GetInstance ( ) . ParseFileList ( szFileList , " skn " , szVecSkinList ) ;
CGlobalValue : : GetInstance ( ) . ParseFileList ( szFileList , " ani " , szVecAniList ) ;
CGlobalValue : : GetInstance ( ) . ParseFileList ( szFileList , " scn " , szVecSceneList ) ;
CGlobalValue : : GetInstance ( ) . ParseFileList ( szFileList , " txt " , szVecSimList ) ;
szFileList . ReleaseBuffer ( ) ;
bool bResetScene = true ;
if ( szVecSceneList . size ( ) > 0 ) {
bResetScene = false ;
CGlobalValue : : GetInstance ( ) . ImportScene ( szVecSceneList [ 0 ] ) ;
}
if ( szVecSkinList . size ( ) = = 0 ) {
if ( szVecSimList . size ( ) > 0 )
{
CObjectSkin * pBase = ( CObjectSkin * ) CGlobalValue : : GetInstance ( ) . GetOneObject ( CObjectBase : : SKIN ) ;
if ( pBase ) {
char szTemp [ 512 ] ;
strcpy_s ( szTemp , szVecSimList [ 0 ] . GetBuffer ( ) ) ;
pBase - > LoadSimulation ( szTemp ) ;
}
}
if ( szVecAniList . size ( ) > 0 ) {
if ( CGlobalValue : : GetInstance ( ) . GetObjectCount ( CObjectBase : : SKIN ) ! = 1 ) return ;
CObjectBase * pBase = CGlobalValue : : GetInstance ( ) . GetOneObject ( CObjectBase : : SKIN ) ;
float fPer = 100 / ( float ) szVecAniList . size ( ) + 1.f ;
CGlobalValue : : GetInstance ( ) . UpdateProgress ( 0 ) ;
// <20> <> <EFBFBD> <EFBFBD> <20> ε<EFBFBD>
for ( DWORD i = 0 ; i < szVecAniList . size ( ) ; i + + ) {
char szTemp [ 512 ] ;
_GetFullFileName ( szTemp , _countof ( szTemp ) , szVecAniList [ i ] ) ;
CObjectBase * pBaseAni = new CObjectAnimation ;
if ( ( ( CObjectAnimation * ) pBaseAni ) - > LoadAnimation ( szVecAniList [ i ] ) = = false ) {
SAFE_DELETE ( pBaseAni ) ;
continue ;
}
CGlobalValue : : GetInstance ( ) . AddObject ( pBase - > GetTreeItemID ( ) , pBaseAni ) ;
CGlobalValue : : GetInstance ( ) . UpdateProgress ( ( int ) ( fPer * ( i + 1 ) ) ) ;
}
CGlobalValue : : GetInstance ( ) . UpdateProgress ( 0 ) ;
}
}
else if ( szVecSkinList . size ( ) = = 1 ) {
if ( bResetScene ) CGlobalValue : : GetInstance ( ) . ResetObject ( ) ;
float fPer = 100 / ( float ) szVecAniList . size ( ) + 1.f ;
CGlobalValue : : GetInstance ( ) . UpdateProgress ( 0 ) ;
char szTemp [ 512 ] ;
_GetFullFileName ( szTemp , _countof ( szTemp ) , szVecSkinList [ 0 ] ) ;
CObjectBase * pBase = new CObjectSkin ;
pBase - > SetName ( CString ( szTemp ) ) ;
( ( CObjectSkin * ) pBase ) - > LoadSkin ( szVecSkinList [ 0 ] , true ) ;
DWORD dwAttr = GetFileAttributes ( szVecSkinList [ 0 ] ) ;
if ( dwAttr & FILE_ATTRIBUTE_READONLY ) {
CString szStr ;
szStr . Format ( " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> ϵ<EFBFBD> <CFB5> <EFBFBD> <20> б <EFBFBD> <D0B1> <EFBFBD> <EFBFBD> <EFBFBD> <20> Ӽ<EFBFBD> <D3BC> Դϴ<D4B4> .\n \n %s " , szVecSkinList [ 0 ] ) ;
MessageBox ( ( ( CMainFrame * ) AfxGetMainWnd ( ) ) - > m_hWnd , szStr , " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> " , MB_OK ) ;
}
CObjectBase * pParent = CGlobalValue : : GetInstance ( ) . GetOneObject ( CObjectBase : : SCENE ) ;
CGlobalValue : : GetInstance ( ) . AddObject ( pParent , pBase ) ;
CGlobalValue : : GetInstance ( ) . UpdateProgress ( ( int ) ( fPer * 1.f ) ) ;
// <20> <> <EFBFBD> <EFBFBD> <20> ε<EFBFBD>
for ( DWORD i = 0 ; i < szVecAniList . size ( ) ; i + + ) {
char szTemp [ 512 ] ;
_GetFullFileName ( szTemp , _countof ( szTemp ) , szVecAniList [ i ] ) ;
CObjectBase * pBaseAni = new CObjectAnimation ;
if ( ( ( CObjectAnimation * ) pBaseAni ) - > LoadAnimation ( szVecAniList [ i ] ) = = false ) {
SAFE_DELETE ( pBaseAni ) ;
continue ;
}
CGlobalValue : : GetInstance ( ) . AddObject ( pBase - > GetTreeItemID ( ) , pBaseAni ) ;
CGlobalValue : : GetInstance ( ) . UpdateProgress ( ( int ) ( fPer * ( i + 2 ) ) ) ;
}
CGlobalValue : : GetInstance ( ) . UpdateProgress ( 0 ) ;
}
else if ( szVecSkinList . size ( ) > 1 ) {
if ( szVecAniList . size ( ) > 0 ) return ;
if ( bResetScene ) CGlobalValue : : GetInstance ( ) . ResetObject ( ) ;
float fPer = 100 / ( float ) szVecSkinList . size ( ) + 1.f ;
CGlobalValue : : GetInstance ( ) . UpdateProgress ( 0 ) ;
for ( DWORD i = 0 ; i < szVecSkinList . size ( ) ; i + + ) {
char szTemp [ 512 ] ;
_GetFullFileName ( szTemp , _countof ( szTemp ) , szVecSkinList [ i ] ) ;
CObjectBase * pBase = new CObjectSkin ;
pBase - > SetName ( CString ( szTemp ) ) ;
( ( CObjectSkin * ) pBase ) - > LoadSkin ( szVecSkinList [ i ] , true ) ;
CObjectBase * pParent = CGlobalValue : : GetInstance ( ) . GetOneObject ( CObjectBase : : SCENE ) ;
CGlobalValue : : GetInstance ( ) . AddObject ( pParent , pBase ) ;
CGlobalValue : : GetInstance ( ) . UpdateProgress ( ( int ) ( fPer * ( i + 1 ) ) ) ;
}
CGlobalValue : : GetInstance ( ) . UpdateProgress ( 0 ) ;
}
}
void CEtViewerDoc : : OnFileSave ( )
{
// TODO: <20> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> ó<> <C3B3> <EFBFBD> <EFBFBD> <20> ڵ带 <20> ߰<EFBFBD> <DFB0> մϴ<D5B4> .
CObjectBase * pBase = CGlobalValue : : GetInstance ( ) . GetRootObject ( ) ;
if ( pBase - > IsChildModify ( ) = = true ) {
CGlobalValue : : GetInstance ( ) . SaveSkinObject ( pBase ) ;
}
}
void CEtViewerDoc : : OnFileNew ( )
{
CDocument : : OnNewDocument ( ) ;
CGlobalValue : : GetInstance ( ) . ResetObject ( ) ;
}
void CEtViewerDoc : : OnFileExportscene ( )
{
// TODO: <20> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> ó<> <C3B3> <EFBFBD> <EFBFBD> <20> ڵ带 <20> ߰<EFBFBD> <DFB0> մϴ<D5B4> .
CString szFileList ;
TCHAR szFilter [ ] = _T ( " Eternity Scene File (*.scn)|*.scn|All Files (*.*)|*.*|| " ) ;
CFileDialog dlg ( FALSE , _T ( " scn " ) , _T ( " *.scn " ) , OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_ENABLESIZING , szFilter , CGlobalValue : : GetInstance ( ) . GetView ( ) ) ;
dlg . m_ofn . lpstrTitle = " Save Eternity Scene File " ;
if ( IDOK ! = dlg . DoModal ( ) ) return ;
CGlobalValue : : GetInstance ( ) . ExportScene ( dlg . GetPathName ( ) ) ;
}