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.

139 lines
3.8 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "mxtk/mx.h"
  9. #include "resource.h"
  10. #include "SoundLookup.h"
  11. #include "mdlviewer.h"
  12. #include "SoundEmitterSystem/isoundemittersystembase.h"
  13. #include "addsoundentry.h"
  14. static CSoundLookupParams g_Params;
  15. static void PopulateSoundEntryList( HWND wnd, CSoundLookupParams *params )
  16. {
  17. HWND control = GetDlgItem( wnd, IDC_SOUNDENTRYLIST );
  18. if ( !control )
  19. return;
  20. SendMessage( control, LB_RESETCONTENT, 0, 0 );
  21. SendMessage( control, WM_SETFONT, (WPARAM) (HFONT) GetStockObject (ANSI_FIXED_FONT), MAKELPARAM (TRUE, 0) );
  22. int c = params->entryList->Count();
  23. for ( int i = 0; i < c; i++ )
  24. {
  25. int soundindex = (*params->entryList)[ i ];
  26. char text[ 128 ];
  27. text[ 0 ] = 0;
  28. Q_strncpy( text, soundemitter->GetSoundName( soundindex ), sizeof( text ) );
  29. if ( text[0] )
  30. {
  31. char const *script = soundemitter->GetSourceFileForSound( soundindex );
  32. int idx = SendMessage( control, LB_ADDSTRING, 0, (LPARAM)va( "%20s: '%s'", script, text ) );
  33. SendMessage( control, LB_SETITEMDATA, idx, (LPARAM)soundindex );
  34. }
  35. }
  36. }
  37. //-----------------------------------------------------------------------------
  38. // Purpose:
  39. // Input : hwndDlg -
  40. // uMsg -
  41. // wParam -
  42. // lParam -
  43. // Output : static BOOL CALLBACK
  44. //-----------------------------------------------------------------------------
  45. static BOOL CALLBACK SoundLookupDialogProc( 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. PopulateSoundEntryList( hwndDlg, &g_Params );
  56. SetDlgItemText( hwndDlg, IDC_STATIC_PROMPT, g_Params.m_szPrompt );
  57. SetWindowText( hwndDlg, g_Params.m_szDialogTitle );
  58. SetFocus( GetDlgItem( hwndDlg, IDC_SOUNDENTRYLIST ) );
  59. }
  60. return FALSE;
  61. case WM_COMMAND:
  62. switch (LOWORD(wParam))
  63. {
  64. case IDOK:
  65. {
  66. int selindex = SendMessage( GetDlgItem( hwndDlg, IDC_SOUNDENTRYLIST ), LB_GETCURSEL, 0, 0 );
  67. if ( selindex == LB_ERR )
  68. {
  69. mxMessageBox( NULL, "You must select an entry from the list", g_appTitle, MB_OK );
  70. return TRUE;
  71. }
  72. int soundindex = SendMessage( GetDlgItem( hwndDlg, IDC_SOUNDENTRYLIST ), LB_GETITEMDATA, selindex, 0 );
  73. Assert( soundindex != LB_ERR );
  74. Q_strncpy( g_Params.m_szSoundName, soundemitter->GetSoundName( soundindex ), sizeof ( g_Params.m_szSoundName ) );
  75. EndDialog( hwndDlg, 1 );
  76. }
  77. break;
  78. case IDCANCEL:
  79. EndDialog( hwndDlg, 0 );
  80. break;
  81. case IDC_ADDENTRY:
  82. {
  83. // Create a new sound entry for this sound
  84. CAddSoundParams params;
  85. Q_memset( &params, 0, sizeof( params ) );
  86. Q_strcpy( params.m_szDialogTitle, "Add Sound Entry" );
  87. Q_strcpy( params.m_szWaveFile, g_Params.m_szWaveFile );
  88. if ( AddSound( &params, hwndDlg ) )
  89. {
  90. // Add it to soundemitter and check out script files
  91. if ( params.m_szSoundName[ 0 ] &&
  92. params.m_szScriptName[ 0 ] )
  93. {
  94. Q_strcpy( g_Params.m_szSoundName, params.m_szSoundName );
  95. // Press the OK button for the user...
  96. EndDialog( hwndDlg, 1 );
  97. }
  98. }
  99. }
  100. break;
  101. }
  102. return TRUE;
  103. }
  104. return FALSE;
  105. }
  106. //-----------------------------------------------------------------------------
  107. // Purpose:
  108. // Input : *view -
  109. // *actor -
  110. // Output : int
  111. //-----------------------------------------------------------------------------
  112. int SoundLookup( CSoundLookupParams *params, HWND parent )
  113. {
  114. g_Params = *params;
  115. int retval = DialogBox( (HINSTANCE)GetModuleHandle( 0 ),
  116. MAKEINTRESOURCE( IDD_WAVELOOKUP ),
  117. parent,
  118. (DLGPROC)SoundLookupDialogProc );
  119. *params = g_Params;
  120. return retval;
  121. }