Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

163 lines
4.3 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "mxtk/mx.h"
  8. #include "resource.h"
  9. #include "AddSoundEntry.h"
  10. #include "mdlviewer.h"
  11. #include "SoundEmitterSystem/isoundemittersystembase.h"
  12. #include "filesystem.h"
  13. static CAddSoundParams g_Params;
  14. static void PopulateScriptList( HWND wnd )
  15. {
  16. HWND control = GetDlgItem( wnd, IDC_SOUNDSCRIPT );
  17. if ( !control )
  18. {
  19. return;
  20. }
  21. SendMessage( control, CB_RESETCONTENT, 0, 0 );
  22. int c = soundemitter->GetNumSoundScripts();
  23. for ( int i = 0; i < c; i++ )
  24. {
  25. // add text to combo box
  26. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)soundemitter->GetSoundScriptName( i ) );
  27. if ( i == 0 && !g_Params.m_szScriptName[ 0 ] )
  28. {
  29. SendMessage( control, WM_SETTEXT , 0, (LPARAM)soundemitter->GetSoundScriptName( i ) );
  30. }
  31. }
  32. if ( g_Params.m_szScriptName[ 0 ] )
  33. {
  34. SendMessage( control, WM_SETTEXT , 0, (LPARAM)g_Params.m_szScriptName );
  35. }
  36. }
  37. //-----------------------------------------------------------------------------
  38. // Purpose:
  39. // Input : hwndDlg -
  40. // uMsg -
  41. // wParam -
  42. // lParam -
  43. // Output : static BOOL CALLBACK
  44. //-----------------------------------------------------------------------------
  45. static BOOL CALLBACK AddSoundPropertiesDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  46. {
  47. switch(uMsg)
  48. {
  49. case WM_INITDIALOG:
  50. // Insert code here to put the string (to find and replace with)
  51. // into the edit controls.
  52. // ...
  53. {
  54. g_Params.PositionSelf( hwndDlg );
  55. PopulateScriptList( hwndDlg );
  56. SetDlgItemText( hwndDlg, IDC_SOUNDNAME, g_Params.m_szSoundName );
  57. if ( g_Params.m_bReadOnlySoundName )
  58. {
  59. HWND ctrl = GetDlgItem( hwndDlg, IDC_SOUNDNAME );
  60. if ( ctrl )
  61. {
  62. SendMessage( ctrl, EM_SETREADONLY, (WPARAM)TRUE, 0 );
  63. }
  64. }
  65. SetWindowText( hwndDlg, g_Params.m_szDialogTitle );
  66. SetFocus( GetDlgItem( hwndDlg, IDC_SOUNDNAME ) );
  67. }
  68. return FALSE;
  69. case WM_COMMAND:
  70. switch (LOWORD(wParam))
  71. {
  72. case IDOK:
  73. {
  74. g_Params.m_szSoundName[ 0 ] = 0;
  75. g_Params.m_szScriptName[ 0 ] = 0;
  76. GetDlgItemText( hwndDlg, IDC_SOUNDNAME, g_Params.m_szSoundName, sizeof( g_Params.m_szSoundName ) );
  77. GetDlgItemText( hwndDlg, IDC_SOUNDSCRIPT, g_Params.m_szScriptName, sizeof( g_Params.m_szScriptName ) );
  78. // Don't exit...
  79. if ( !g_Params.m_szSoundName[ 0 ] || !g_Params.m_szScriptName[ 0 ] )
  80. return TRUE;
  81. // Don't stompt existing sounds
  82. int idx = soundemitter->GetSoundIndex( g_Params.m_szSoundName );
  83. if ( soundemitter->IsValidIndex( idx ) )
  84. {
  85. if ( !g_Params.m_bAllowExistingSound )
  86. {
  87. mxMessageBox( NULL, va( "Sound '%s' already exists",
  88. g_Params.m_szSoundName ), g_appTitle, MX_MB_OK );
  89. }
  90. else
  91. {
  92. EndDialog( hwndDlg, 1 );
  93. }
  94. return TRUE;
  95. }
  96. // Check out script
  97. if ( !filesystem->FileExists( g_Params.m_szScriptName ) )
  98. {
  99. mxMessageBox( NULL, va( "Script '%s' does not exist",
  100. g_Params.m_szScriptName ), g_appTitle, MX_MB_OK );
  101. return TRUE;
  102. }
  103. if ( !filesystem->IsFileWritable( g_Params.m_szScriptName ) )
  104. {
  105. mxMessageBox( NULL, va( "Script '%s' is read-only, you need to check it out of VSS",
  106. g_Params.m_szScriptName ), g_appTitle, MX_MB_OK );
  107. return TRUE;
  108. }
  109. // Add the entry
  110. CSoundParametersInternal params;
  111. params.SetChannel( CHAN_VOICE );
  112. params.SetSoundLevel( SNDLVL_TALKING );
  113. soundemitter->ExpandSoundNameMacros( params, g_Params.m_szWaveFile );
  114. soundemitter->AddSound( g_Params.m_szSoundName, g_Params.m_szScriptName, params );
  115. EndDialog( hwndDlg, 1 );
  116. }
  117. break;
  118. case IDCANCEL:
  119. EndDialog( hwndDlg, 0 );
  120. break;
  121. }
  122. return TRUE;
  123. }
  124. return FALSE;
  125. }
  126. //-----------------------------------------------------------------------------
  127. // Purpose:
  128. // Input : *view -
  129. // *actor -
  130. // Output : int
  131. //-----------------------------------------------------------------------------
  132. int AddSound( CAddSoundParams *params, HWND parent )
  133. {
  134. g_Params = *params;
  135. int retval = DialogBox( (HINSTANCE)GetModuleHandle( 0 ),
  136. MAKEINTRESOURCE( IDD_ADDSOUNDENTRY ),
  137. parent,
  138. (DLGPROC)AddSoundPropertiesDialogProc );
  139. *params = g_Params;
  140. return retval;
  141. }