/*========================================================================= File Name: DIASOUND.CPP Purpose: Implements functions handling the sound characteristics Implements Following Classes: - DiaSound Author: Benoit Germain Date: May,1997 ==========================================================================*/ #include #include "stdafx.h" #include "Acp_Base.h" #define HieFriend #include "incgam.h" #include "DiaSound.hpp" #include "_interf.hpp" #include "GMatObj.hpp" #include "CopyPaste.hpp" #include "x:\cpa\main\inc\_editid.h" #include "TUT.h" extern Material_Interface *gs_p_oMaterialInterface; /*========================================================================= Function Name: Diasound::Diasound() Purpose: Diasound constructor Author: Benoit Germain Date: May 13,1997 ==========================================================================*/ IMPLEMENT_DYNCREATE(DiaSound, CFormView) DiaSound::DiaSound() : CFormView(DiaSound::IDD) { //{{AFX_DATA_INIT(DiaSound) m_ComboString = _T(""); //}}AFX_DATA_INIT m_bHasBeenInitialized=FALSE; //m_hHandleToGameMaterial=(GMT_tdxHandleToGameMaterial)GMT_C_ulInvalidHandle; m_hHandleToSoundMaterial = GMT_C_InvalidSoundMaterial; m_p_oCopyBuffer = NULL; } /*========================================================================= Function Name: Diasound::~Diasound() Purpose: Diasound destructor Author: Benoit Germain Date: May 13,1997 ==========================================================================*/ DiaSound::~DiaSound() { if ( m_p_oCopyBuffer ) delete m_p_oCopyBuffer; } /*========================================================================= Function Name: Diasound::DoDataExchange Purpose: Author: Benoit Germain Date: May 13,1997 ==========================================================================*/ void DiaSound::DoDataExchange(CDataExchange* pDX) { CFormView::DoDataExchange(pDX); //{{AFX_DATA_MAP(DiaSound) DDX_Control(pDX, IDC_CHECK_DISABLE_SOUND, m_CheckDisableSound); DDX_CBString(pDX, IDC_COMBO_TYPE, m_ComboString); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(DiaSound, CFormView) //{{AFX_MSG_MAP(DiaSound) ON_BN_CLICKED(IDC_BUTTON_COPYSOUND, OnButtonCopySoundMaterial) ON_BN_CLICKED(IDC_BUTTON_PASTESOUND, OnButtonPasteSoundMaterial) ON_BN_CLICKED(IDC_CHECK_DISABLE_SOUND, OnCheckDisableSound) ON_CBN_SELCHANGE(IDC_COMBO_TYPE, OnSelChangeComboType) //}}AFX_MSG_MAP END_MESSAGE_MAP() //================================================================================================== //================================================================================================== int DiaSound::OnToolHitTest(CPoint point, TOOLINFO * pTI) const { CString csMessage; switch ( CWnd::OnToolHitTest(point, pTI) ) { case IDC_CHECK_DISABLE_SOUND: csMessage = "enable/disable sound characteristics for the current game material"; break; case IDC_COMBO_TYPE: csMessage = "select the type of sound characteristics for the current game material"; break; case IDC_BUTTON_COPYSOUND: csMessage = "copy the sound characteristics of the current game material for further pasting"; break; case IDC_BUTTON_PASTESOUND: csMessage = "paste the contents of the last copied sound characteristics into the current game material"; break; } //output the help info in the status bar fn_vGiveProgressInfo(csMessage, -1); //there is no hit for a true tooltip return -1; } //================================================================================================== //================================================================================================== unsigned long DiaSound::m_fn_ulFindHandleFromName(CString _csName) { for ( int i = 0; i < m_wNumberOfReachableNames; i ++ ) { if ( m_csReachableName[i] == _csName ) { return m_ulReachableHandle[i]; } } return (unsigned long) -1; } //================================================================================================== //================================================================================================== CString DiaSound::m_fn_csFindNameFromHandle(unsigned long _ulHandle) { for ( int i = 0; i < m_wNumberOfReachableNames; i ++ ) { if ( m_ulReachableHandle[i] == _ulHandle ) { return m_csReachableName[i]; } } return "Not Assigned"; } /*========================================================================= Function Name: Diasound::m_fn_bGetReachablesNames() Purpose: Gets the name and handle of the reachable objects of type "SndInfo_Material" provided by the sound DLL Author: Yann Le Tensorer Date: May 13,1997 ==========================================================================*/ BOOL DiaSound::m_fn_bGetReachablesNames() { CPA_List oList; m_wNumberOfReachableNames = gs_p_oMaterialInterface->GetMainWorld()->fn_lFindObjects(&oList, "", C_szSoundInfoMaterialTypeName); if (!m_wNumberOfReachableNames) { AfxMessageBox("\"SndEventM\" Reachable objects not found"); return FALSE; } POSITION xSortedElementPos; CPA_BaseObject *p_oObject; int i=0; for ( p_oObject = oList.GetHeadElement(xSortedElementPos); xSortedElementPos; p_oObject = oList.GetNextElement(xSortedElementPos) ) { m_csReachableName[i] = p_oObject->GetName(); ((CComboBox*) GetDlgItem (IDC_COMBO_TYPE))->AddString(m_csReachableName[i]); m_ulReachableHandle[i] = (unsigned long) gs_p_oMaterialInterface->GetMainWorld()->fn_p_oFindObject(m_csReachableName[i],C_szSoundInfoMaterialTypeName)->GetData(); if (i==0) m_ulDefaultSoundHandle=m_ulReachableHandle[i]; i++; } return TRUE; } /*========================================================================= Function Name: DiaSound::m_fn_vEnableWindowFields(true/false) Purpose: Called to enable or disable all fields of dialog (except check) Parameters: True: Rend les champs actifs, False, les rend inactifs Author: Yann Le Tensorer Date: 16-04-97 ==========================================================================*/ void DiaSound::m_fn_vEnableWindowFields(BOOL bEnable) { if ( bEnable ) { //there is a target submaterial, hance paste is enabled GetDlgItem(IDC_BUTTON_PASTESOUND)->EnableWindow(m_p_oCopyBuffer ? TRUE : FALSE); //but instanciate is disabled //GetDlgItem(IDC_BUTTON_INSTANCIATESOUND)->EnableWindow(FALSE); } else { //make the combo display an empty name ((CComboBox *) GetDlgItem(IDC_COMBO_TYPE))->SetCurSel(CB_ERR); //there is no submaterial, so disable pasting GetDlgItem(IDC_BUTTON_PASTESOUND)->EnableWindow(FALSE); //instanciate only if the target game material has no submaterial //GetDlgItem(IDC_BUTTON_INSTANCIATESOUND)->EnableWindow(m_p_oCopyBuffer ? TRUE : FALSE); } GetDlgItem(IDC_COMBO_TYPE)->EnableWindow( bEnable ); GetDlgItem(IDC_STATIC_TYPE)->EnableWindow( bEnable ); GetDlgItem(IDC_BUTTON_COPYSOUND)->EnableWindow( bEnable ); } /*========================================================================= ==========================================================================*/ void DiaSound::m_fn_vShowMaterial(GMT_tdxHandleToGameMaterial _hMat) { if (m_bHasBeenInitialized == FALSE) { m_fn_bGetReachablesNames(); m_bHasBeenInitialized = TRUE; } tdoEditorGameMaterial *p_oEditedGameMaterial = gs_p_oMaterialInterface->m_p_oGetEditedMaterial(); BOOL bAGameMAterialIsEdited = p_oEditedGameMaterial ? TRUE : FALSE; /* if no material is currently selected, disable everything */ if ( !bAGameMAterialIsEdited || !GMT_fn_b_ulIsValid(_hMat) ) { m_hHandleToSoundMaterial = GMT_C_InvalidSoundMaterial; m_CheckDisableSound.SetCheck(FALSE); GetDlgItem(IDC_CHECK_DISABLE_SOUND)->EnableWindow(GMT_fn_b_ulIsValid(_hMat)); m_fn_vEnableWindowFields(FALSE); return; } GetDlgItem(IDC_CHECK_DISABLE_SOUND)->EnableWindow(TRUE); //normally, the specified engine game material must belong to the current editor game material... ASSERT(_hMat == p_oEditedGameMaterial->GetData()); // get the handle to sound material m_hHandleToSoundMaterial = GMT_fn_hGetSoundMaterial(_hMat); if ( m_hHandleToSoundMaterial == GMT_C_InvalidSoundMaterial) { m_ComboString=m_fn_csFindNameFromHandle(m_hHandleToSoundMaterial); UpdateData(FALSE); m_CheckDisableSound.SetCheck(FALSE); m_fn_vEnableWindowFields(FALSE); } else { m_ComboString = m_fn_csFindNameFromHandle(m_hHandleToSoundMaterial); UpdateData(FALSE); m_CheckDisableSound.SetCheck(TRUE); m_fn_vEnableWindowFields(TRUE); } } ///////////////////////////////////////////////////////////////////////////// // DiaSound diagnostics #ifdef _DEBUG void DiaSound::AssertValid() const { CFormView::AssertValid(); } void DiaSound::Dump(CDumpContext& dc) const { CFormView::Dump(dc); } #endif //_DEBUG /*===================================================================================== Function: DiaSound::Created Purpose: Overloaded function create of DiaSound dialog Author: Yann Le Tensorer Date: April, 1997 ====================================================================================*/ BOOL DiaSound::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) { if (CFormView::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext)) { EnableToolTips(TRUE); UpdateData(FALSE); m_fn_vEnableWindowFields(FALSE); GetDlgItem(IDC_CHECK_DISABLE_SOUND)->EnableWindow(FALSE); //control registration for tutorial and assistants, should be unregistered when view is destroyed TUT_M_vGetTutDll(); TUT_M_vRegisterControlID(IDC_CHECK_DISABLE_SOUND,"TGM_DiaSoundCheckDisableSound",TUT_e_Button); TUT_M_vRegisterControlID(IDC_COMBO_TYPE,"TGM_DiaSoundCombosoundTypes",TUT_e_ComboBox); TUT_M_vRegisterControlID(IDC_BUTTON_COPYSOUND,"TGM_DiaSoundButtonCopy",TUT_e_Button); TUT_M_vRegisterControlID(IDC_BUTTON_PASTESOUND,"TGM_DiaSoundButtonPaste",TUT_e_Button); return TRUE; } else return FALSE; } ///////////////////////////////////////////////////////////////////////////// // DiaSound message handlers void DiaSound::OnButtonCopySoundMaterial() { if ( m_p_oCopyBuffer ) delete m_p_oCopyBuffer; m_p_oCopyBuffer = new tdoCopyBuffer(m_hHandleToSoundMaterial); GetDlgItem(IDC_BUTTON_PASTESOUND)->EnableWindow(TRUE); //it is stupid to instanciate on the same material, so disable it //GetDlgItem(IDC_BUTTON_INSTANCIATESOUND)->EnableWindow(FALSE); } //================================================================================================== //================================================================================================== void DiaSound::OnButtonPasteSoundMaterial() { if ( m_p_oCopyBuffer ) M_p_oGetEditManager()->AskFor(new tdoPasteSubMaterialModif(m_p_oCopyBuffer)); } //================================================================================================== //================================================================================================== void DiaSound::OnCheckDisableSound() { if ( !gs_p_oMaterialInterface->m_p_oGetEditedMaterial() ) { m_CheckDisableSound.SetCheck(FALSE); m_fn_vEnableWindowFields(FALSE); return; } BOOL bEnabled = m_CheckDisableSound.GetCheck(); if ( bEnabled ) m_hHandleToSoundMaterial = m_ulDefaultSoundHandle; else m_hHandleToSoundMaterial = GMT_C_InvalidSoundMaterial; //controls are to be enabled while they are updated so that the change is visible //->enable before update if ( bEnabled ) m_fn_vEnableWindowFields(TRUE); //perform the update m_ComboString = m_fn_csFindNameFromHandle(m_hHandleToSoundMaterial); UpdateData(FALSE); //-> or disable after update if ( !bEnabled ) m_fn_vEnableWindowFields(FALSE); //modify the edited data accordingly GMT_fn_vSetSoundMaterial( gs_p_oMaterialInterface->m_p_oGetEditedMaterial()->m_hGetEngineMaterial(), m_hHandleToSoundMaterial ); //and notify the changes to the scripts gs_p_oMaterialInterface->m_p_oGetEditedMaterial()->fn_vNotifySave(); } //================================================================================================== //================================================================================================== void DiaSound::OnSelChangeComboType() { UpdateData(TRUE); m_hHandleToSoundMaterial = m_fn_ulFindHandleFromName(m_ComboString); GMT_fn_vSetSoundMaterial( gs_p_oMaterialInterface->m_p_oGetEditedMaterial()->m_hGetEngineMaterial(), m_hHandleToSoundMaterial ); gs_p_oMaterialInterface->m_p_oGetEditedMaterial()->fn_vNotifySave(); }