Team Fortress 2 Source Code as on 22/4/2020
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.

239 lines
7.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include <mxtk/mx.h>
  8. #include <stdio.h>
  9. #include "resource.h"
  10. #include "SoundProperties_Multiple.h"
  11. #include "SoundEmitterSystem/isoundemittersystembase.h"
  12. #include "soundentry.h"
  13. #include "cmdlib.h"
  14. #include "workspacemanager.h"
  15. #include "wavebrowser.h"
  16. #include "wavefile.h"
  17. #include "waveproperties.h"
  18. static CSoundParams g_Params;
  19. static void PopulateChannelList( HWND wnd, CSoundParametersInternal *p )
  20. {
  21. HWND control = GetDlgItem( wnd, IDC_CHANNEL );
  22. if ( !control )
  23. {
  24. return;
  25. }
  26. SendMessage( control, CB_RESETCONTENT, 0, 0 );
  27. SendMessage( control, WM_SETTEXT , 0, (LPARAM)p->ChannelToString() );
  28. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"CHAN_VOICE" );
  29. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"CHAN_AUTO" );
  30. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"CHAN_WEAPON" );
  31. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"CHAN_ITEM" );
  32. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"CHAN_BODY" );
  33. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"CHAN_STREAM" );
  34. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"CHAN_STATIC" );
  35. }
  36. static void PopulateVolumeList( HWND wnd, CSoundParametersInternal *p )
  37. {
  38. HWND control = GetDlgItem( wnd, IDC_VOLUME );
  39. if ( !control )
  40. {
  41. return;
  42. }
  43. SendMessage( control, CB_RESETCONTENT, 0, 0 );
  44. SendMessage( control, WM_SETTEXT , 0, (LPARAM)p->VolumeToString() );
  45. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"VOL_NORM" );
  46. }
  47. static void PopulateSoundlevelList( HWND wnd, CSoundParametersInternal *p )
  48. {
  49. HWND control = GetDlgItem( wnd, IDC_SOUNDLEVEL );
  50. if ( !control )
  51. {
  52. return;
  53. }
  54. SendMessage( control, CB_RESETCONTENT, 0, 0 );
  55. SendMessage( control, WM_SETTEXT , 0, (LPARAM)p->SoundLevelToString() );
  56. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"SNDLVL_NORM" );
  57. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"SNDLVL_NONE" );
  58. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"SNDLVL_IDLE" );
  59. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"SNDLVL_TALKING" );
  60. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"SNDLVL_STATIC" );
  61. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"SNDLVL_GUNFIRE" );
  62. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"SNDLVL_25dB" );
  63. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"SNDLVL_30dB" );
  64. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"SNDLVL_35dB" );
  65. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"SNDLVL_40dB" );
  66. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"SNDLVL_45dB" );
  67. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"SNDLVL_50dB" );
  68. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"SNDLVL_55dB" );
  69. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"SNDLVL_60dB" );
  70. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"SNDLVL_65dB" );
  71. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"SNDLVL_70dB" );
  72. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"SNDLVL_75dB" );
  73. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"SNDLVL_80dB" );
  74. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"SNDLVL_85dB" );
  75. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"SNDLVL_90dB" );
  76. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"SNDLVL_95dB" );
  77. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"SNDLVL_100dB" );
  78. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"SNDLVL_105dB" );
  79. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"SNDLVL_120dB" );
  80. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"SNDLVL_130dB" );
  81. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"SNDLVL_140dB" );
  82. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"SNDLVL_150dB" );
  83. }
  84. static void PopulatePitchList( HWND wnd, CSoundParametersInternal *p )
  85. {
  86. HWND control = GetDlgItem( wnd, IDC_PITCH );
  87. if ( !control )
  88. {
  89. return;
  90. }
  91. SendMessage( control, CB_RESETCONTENT, 0, 0 );
  92. SendMessage( control, WM_SETTEXT , 0, (LPARAM)p->PitchToString() );
  93. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"PITCH_NORM" );
  94. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"PITCH_LOW" );
  95. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"PITCH_HIGH" );
  96. }
  97. static void SoundProperties_Multiple_OnOK( HWND hwndDlg )
  98. {
  99. int c = g_Params.items.Count();
  100. for ( int i = 0; i < c; i++ )
  101. {
  102. // Gather info and make changes
  103. CSoundEntry *item = g_Params.items[ i ];
  104. Assert( item );
  105. if ( !item )
  106. continue;
  107. int idx = g_pSoundEmitterSystem->GetSoundIndex( item->GetName() );
  108. if ( !g_pSoundEmitterSystem->IsValidIndex( idx ) )
  109. {
  110. continue;
  111. }
  112. CSoundParametersInternal *baseparams = g_pSoundEmitterSystem->InternalGetParametersForSound( idx );
  113. if ( !baseparams )
  114. return;
  115. // Start with old settings
  116. CSoundParametersInternal outparams;
  117. outparams.CopyFrom( *baseparams );
  118. char sz[ 128 ];
  119. GetDlgItemText( hwndDlg, IDC_CHANNEL, sz, sizeof( sz ) );
  120. outparams.ChannelFromString( sz );
  121. GetDlgItemText( hwndDlg, IDC_VOLUME, sz, sizeof( sz ) );
  122. outparams.VolumeFromString( sz );
  123. GetDlgItemText( hwndDlg, IDC_SOUNDLEVEL, sz, sizeof( sz ) );
  124. outparams.SoundLevelFromString( sz );
  125. GetDlgItemText( hwndDlg, IDC_PITCH, sz, sizeof( sz ) );
  126. outparams.PitchFromString( sz );
  127. bool owneronly = SendMessage( GetDlgItem( hwndDlg, IDC_OWNERONLY ), BM_GETCHECK, 0, 0 ) == BST_CHECKED ? true : false;
  128. outparams.SetOnlyPlayToOwner( owneronly );
  129. g_pSoundEmitterSystem->UpdateSoundParameters( item->GetName(), outparams );
  130. }
  131. // Repopulate things
  132. GetWorkspaceManager()->RefreshBrowsers();
  133. }
  134. //-----------------------------------------------------------------------------
  135. // Purpose:
  136. // Input : hwndDlg -
  137. // uMsg -
  138. // wParam -
  139. // lParam -
  140. // Output : static BOOL CALLBACK
  141. //-----------------------------------------------------------------------------
  142. static BOOL CALLBACK SoundProperties_MultipleDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  143. {
  144. switch(uMsg)
  145. {
  146. case WM_INITDIALOG:
  147. {
  148. g_Params.PositionSelf( hwndDlg );
  149. CSoundEntry *entry = g_Params.items[ 0 ];
  150. Assert( entry );
  151. CSoundParametersInternal *p = entry->GetSoundParameters();
  152. Assert( p );
  153. SendMessage( GetDlgItem( hwndDlg, IDC_OWNERONLY ), BM_SETCHECK,
  154. ( WPARAM ) p->OnlyPlayToOwner() ? BST_CHECKED : BST_UNCHECKED,
  155. ( LPARAM )0 );
  156. PopulateChannelList( hwndDlg, p );
  157. PopulateVolumeList( hwndDlg, p );
  158. PopulateSoundlevelList( hwndDlg, p );
  159. PopulatePitchList( hwndDlg, p );
  160. SetWindowText( hwndDlg, g_Params.m_szDialogTitle );
  161. SetFocus( GetDlgItem( hwndDlg, IDC_CHANNEL ) );
  162. }
  163. return FALSE;
  164. case WM_COMMAND:
  165. switch (LOWORD(wParam))
  166. {
  167. case IDOK:
  168. {
  169. SoundProperties_Multiple_OnOK( hwndDlg );
  170. EndDialog( hwndDlg, 1 );
  171. }
  172. break;
  173. case IDCANCEL:
  174. EndDialog( hwndDlg, 0 );
  175. break;
  176. }
  177. return FALSE;
  178. }
  179. return FALSE;
  180. }
  181. //-----------------------------------------------------------------------------
  182. // Purpose:
  183. // Input : *view -
  184. // *actor -
  185. // Output : int
  186. //-----------------------------------------------------------------------------
  187. int SoundProperties_Multiple( CSoundParams *params )
  188. {
  189. g_Params = *params;
  190. int retval = DialogBox( (HINSTANCE)GetModuleHandle( 0 ),
  191. MAKEINTRESOURCE( IDD_SOUNDPROPERTIES_MULTIPLE ),
  192. (HWND)GetWorkspaceManager()->getHandle(),
  193. (DLGPROC)SoundProperties_MultipleDialogProc );
  194. *params = g_Params;
  195. return retval;
  196. }