// SoundPropertyDlg.cpp : implementation file // #include "stdafx.h" #include "worldcreator.h" #include "SoundPropertyDlg.h" #include #include #include #include #include #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CSoundPropertyDlg dialog #define TRIGGER_IN "µé¾î°¥ ¶§¸¸" #define TRIGGER_OUT "³ª°¥¶§¸¸" #define TRIGGER_IN_OUT "µÑ ´Ù" #define ENABLE3DSOUND "Enable 3D Sound" #define DISABLE3DSOUND "Disable 3D Sound" using namespace std; CSoundPropertyDlg::CSoundPropertyDlg(CWnd* pParent /*=NULL*/) : CDialog(CSoundPropertyDlg::IDD, pParent) , m_pSoundAsset( new SSoundAsset ) { //{{AFX_DATA_INIT(CSoundPropertyDlg) //}}AFX_DATA_INIT } CSoundPropertyDlg::~CSoundPropertyDlg() { delete m_pSoundAsset; } void CSoundPropertyDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CSoundPropertyDlg) DDX_Control(pDX, IDC_NAME, m_editName); DDX_Control(pDX, IDC_COMBO_TRIGGERTYPE, m_TriggerType); DDX_Control(pDX, IDC_COMBO_STEREO, m_Stereo); DDX_Control(pDX, IDC_LIST_WAVFILELIST, m_WavFileList); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CSoundPropertyDlg, CDialog) //{{AFX_MSG_MAP(CSoundPropertyDlg) ON_BN_CLICKED(IDC_BUTTON_DELETESOUND, OnButtonDeletesound) ON_BN_CLICKED(IDC_BUTTON_INSERTSOUND, OnButtonInsertsound) ON_NOTIFY(LVN_ENDLABELEDIT, IDC_LIST_WAVFILELIST, OnEndlabeleditListWavfilelist) ON_BN_CLICKED(IDC_BUTTON_SETSOUND, OnButtonSetsound) ON_NOTIFY(NM_DBLCLK, IDC_LIST_WAVFILELIST, OnDblclkListWavfilelist) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CSoundPropertyDlg message handlers extern const char * FloatToChar( float fvalue ); float CharToFloat( const char * szStr ) { float fvalue = 0.0f; if( szStr != NULL ) sscanf( szStr, "%f", &fvalue ); return fvalue; } BOOL CSoundPropertyDlg::OnInitDialog() { CDialog::OnInitDialog(); DWORD dwStyle; dwStyle = m_WavFileList.SendMessage(LVM_GETEXTENDEDLISTVIEWSTYLE, 0 ,0); dwStyle |= LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES; m_WavFileList.SendMessage( LVM_SETEXTENDEDLISTVIEWSTYLE, 0,dwStyle ); m_TriggerType.InsertString( 0, TRIGGER_IN ); m_TriggerType.InsertString( 1, TRIGGER_OUT ); m_TriggerType.InsertString( 2, TRIGGER_IN_OUT ); m_Stereo.InsertString( 0, ENABLE3DSOUND ); m_Stereo.InsertString( 1, DISABLE3DSOUND ); m_WavFileList.InsertColumn( 0, "½Ã°£", LVCFMT_LEFT, 80 ); m_WavFileList.InsertColumn( 1, "»ç¿îµå È­ÀÏ", LVCFMT_LEFT, 300 ); m_editName.SetWindowText( m_pSoundAsset->m_Name.c_str() ); m_TriggerType.SetCurSel( m_pSoundAsset->m_eTrigger ); m_Stereo.SetCurSel( m_pSoundAsset->m_b3DSound ? 0 : 1 ); int ItemNum = m_WavFileList.GetItemCount(); if( m_pSoundAsset->m_pWaveFileList ) { WAVEFILELIST * pWaveFileList = m_pSoundAsset->m_pWaveFileList; for( WAVEFILELIST::iterator i = pWaveFileList->begin(); i != pWaveFileList->end(); i++ ) { m_WavFileList.InsertItem( ItemNum, FloatToChar( i->first ) ); m_WavFileList.SetItemText( ItemNum++, 1, i->second.c_str() ); } } return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CSoundPropertyDlg::Init( const SSoundAsset & SoundAsset ) { *m_pSoundAsset = SoundAsset; } void CSoundPropertyDlg::GetInfo( SSoundAsset & SoundAsset ) { SoundAsset = *m_pSoundAsset; } bool std::greater::operator()( const WAVEFILE & x, const WAVEFILE & y ) const { return x.first < y.first; //¿À¸§Â÷¼øÀ¸·Î Á¤·ÄµÇµµ·Ï Çϱâ À§ÇØ >ÀÇ ¹Ý´ëÀÎ <À¸·Î ÇßÀ½ } void CSoundPropertyDlg::OnOK() { CString str; m_editName.GetWindowText( str ); m_pSoundAsset->m_Name = (const char*)str; int curSel = m_TriggerType.GetCurSel(); if( curSel < 0 || curSel > 2 ) curSel = 0; SSoundAsset::eTrigger Trigger[3] = { SSoundAsset::T_IN, SSoundAsset::T_OUT, SSoundAsset::T_IN_OUT }; m_pSoundAsset->m_eTrigger = Trigger[ curSel ]; m_pSoundAsset->m_b3DSound = m_Stereo.GetCurSel() == 1 ? false : true; if( m_pSoundAsset->m_pWaveFileList ) { WAVEFILELIST * pWaveFileList = m_pSoundAsset->m_pWaveFileList; pWaveFileList->clear(); int nItem = m_WavFileList.GetItemCount(); for( int i = 0; i < nItem; i++ ) { CString Time = m_WavFileList.GetItemText( i, 0 ); CString WavFile = m_WavFileList.GetItemText( i, 1 ); float fTime = CharToFloat( Time ); pWaveFileList->push_back( WAVEFILE( fTime, WavFile.GetBuffer( 0 ) ) ); std::greater compareFunc; pWaveFileList->sort( compareFunc ); } } CDialog::OnOK(); } typedef WAVEFILELIST::iterator ITERATOR; ITERATOR GetIterator( WAVEFILELIST & WavFileList, int index ) { int c = 0; for( ITERATOR i = WavFileList.begin(); i != WavFileList.end(); i++ ) { if( c >= index ) { return i; } c++; } return WavFileList.end(); } void CSoundPropertyDlg::OnButtonInsertsound() { int Sel = m_WavFileList.GetNextItem( -1, LVNI_SELECTED ); if( Sel < 0 ) Sel = 0; ITERATOR iter = GetIterator( *m_pSoundAsset->m_pWaveFileList, Sel ); if( m_WavFileList.InsertItem( Sel, "0.0" ) == -1 ) { MessageBox( "¸®½ºÆ®¿¡¼­ WaveÈ­ÀÏÀ» »ðÀÔÇϴµ¥ ½ÇÆÐÇß½À´Ï´Ù!! ( at CSoundPropertyDlg::OnButtonInsertsound() )" ); return; } m_pSoundAsset->m_pWaveFileList->insert( iter, WAVEFILE( 0.0f, "" ) ); } void CSoundPropertyDlg::OnButtonDeletesound() { int Sel = m_WavFileList.GetNextItem( -1, LVNI_SELECTED ); if( Sel < 0 ) Sel = 0; ITERATOR iter = GetIterator( *m_pSoundAsset->m_pWaveFileList, Sel ); if( iter != m_pSoundAsset->m_pWaveFileList->end() ) { if( !m_WavFileList.DeleteItem( Sel ) ) { MessageBox( "¸®½ºÆ®¿¡¼­ WaveÈ­ÀÏÀ» Áö¿ì´Âµ¥ ½ÇÆÐÇß½À´Ï´Ù. (at CSoundPropertyDlg::OnButtonInsertsound() )" ); return; } m_pSoundAsset->m_pWaveFileList->erase( iter ); } } bool CSoundPropertyDlg::IsExist( float fTime ) { for( WAVEFILELIST::iterator i = m_pSoundAsset->m_pWaveFileList->begin(); i != m_pSoundAsset->m_pWaveFileList->end(); i++ ) { if( i->first == fTime ) return true; } return false; } void CSoundPropertyDlg::OnEndlabeleditListWavfilelist(NMHDR* pNMHDR, LRESULT* pResult) { LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR; int Sel = m_WavFileList.GetNextItem( -1, LVNI_SELECTED ); if( Sel < 0 ) return; ITERATOR iter = GetIterator( *m_pSoundAsset->m_pWaveFileList, Sel ); if( iter == m_pSoundAsset->m_pWaveFileList->end() ) return; CString Label = m_WavFileList.GetItemText( Sel, 0 ); float fTime = CharToFloat( pDispInfo->item.pszText ); if( IsExist( fTime ) ) { MessageBox( "ÀÌ¹Ì ÀÌ ½Ã°£À¸·Î ¼³Á¤µÈ °ÍÀÌ ÀÖ½À´Ï´Ù." ); *pResult = 0; return; } if( fTime < 0.0f || fTime > 24.0f ) { MessageBox( "0.0 ~ 24.0 »çÀÌÀÇ ½Ç¼ö¸¦ ÀÔ·ÂÇØÁàÀ×~" ); *pResult = 0; } else { iter->first = fTime; *pResult = 1; } } void CSoundPropertyDlg::OnButtonSetsound() { int Sel = m_WavFileList.GetNextItem( -1, LVNI_SELECTED ); if( Sel < 0 ) return; ITERATOR iter = GetIterator( *m_pSoundAsset->m_pWaveFileList, Sel ); if( iter == m_pSoundAsset->m_pWaveFileList->end() ) return; CFileDialog FileDlg( TRUE, NULL, NULL, OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST , "Ogg Files (*.ogg)|*.ogg|Wave Files (*.wav)|*.wav|All Files (*.*)|*.*||" , this ); if( FileDlg.DoModal() == IDOK ) { char szPathName[256], szSoundFilePath[256]; strcpy( szPathName, FileDlg.GetPathName() ); strlwr( szPathName ); strcpy( szSoundFilePath, SOUNDFILEPATH ); strlwr( szSoundFilePath ); char * pFinded = strstr( szPathName, szSoundFilePath ); if( pFinded == NULL ) { char szMsg[256]; sprintf( szMsg, "»ç¿îµå È­ÀÏÀº %sÀÇ ÇÏÀ§ µð·ºÅ丮¿¡ ÀÖ¾î¾ß¸¸ ÇÕ´Ï´Ù.", szSoundFilePath ); MessageBox( szMsg ); } else { pFinded += strlen( szSoundFilePath ); m_WavFileList.SetItemText( Sel, 1, pFinded ); iter->second = pFinded; } } } void CSoundPropertyDlg::OnDblclkListWavfilelist(NMHDR* pNMHDR, LRESULT* pResult) { OnButtonSetsound(); *pResult = 0; }