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.

192 lines
4.8 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 "WaveProperties.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 "multiplerequest.h"
  18. static CWaveParams g_Params;
  19. static bool WaveLessFunc( const char *const& name1, const char *const& name2 )
  20. {
  21. if ( stricmp( name1, name2 ) < 0 )
  22. return true;
  23. return false;
  24. }
  25. static void WaveProperties_OnOK( HWND hwndDlg )
  26. {
  27. // Gather info and make changes
  28. CWaveFile *item = g_Params.items[ 0 ];
  29. char sentencetext[ 512 ];
  30. GetDlgItemText( hwndDlg, IDC_SENTENCETEXT, sentencetext, sizeof( sentencetext ) );
  31. bool voiceduck = SendMessage( GetDlgItem( hwndDlg, IDC_VOICEDUCK ), BM_GETCHECK, 0, 0 ) == BST_CHECKED ? true : false;
  32. MultipleRequestChangeContext();
  33. // Update ducking on wav files
  34. item->SetVoiceDuck( voiceduck );
  35. item->SetSentenceText( sentencetext );
  36. // Repopulate things
  37. GetWorkspaceManager()->RefreshBrowsers();
  38. }
  39. char *Q_stristr_slash( char const *pStr, char const *pSearch );
  40. //-----------------------------------------------------------------------------
  41. // Purpose:
  42. // Input : hwndDlg -
  43. //-----------------------------------------------------------------------------
  44. static void WaveProperties_ExportSentence()
  45. {
  46. int c = g_Params.items.Count();
  47. if ( c <= 0 )
  48. return;
  49. MultipleRequestChangeContext();
  50. int i;
  51. for ( i = 0; i < c; i++ )
  52. {
  53. CWaveFile *item = g_Params.items[ i ];
  54. Assert( item );
  55. char relative[ 512 ];
  56. item->GetPhonemeExportFile( relative, sizeof( relative ) );
  57. if ( filesystem->FileExists( relative ) )
  58. {
  59. int retval = MultipleRequest( va( "Overwrite '%s'?", relative ) );
  60. if ( retval != 0 )
  61. continue;
  62. filesystem->RemoveFile( relative );
  63. }
  64. item->ExportValveDataChunk( relative );
  65. }
  66. }
  67. //-----------------------------------------------------------------------------
  68. // Purpose:
  69. // Input : hwndDlg -
  70. //-----------------------------------------------------------------------------
  71. static void WaveProperties_ImportSentence()
  72. {
  73. int c = g_Params.items.Count();
  74. if ( c <= 0 )
  75. return;
  76. int i;
  77. for ( i = 0; i < c; i++ )
  78. {
  79. CWaveFile *item = g_Params.items[ i ];
  80. Assert( item );
  81. char relative[ 512 ];
  82. item->GetPhonemeExportFile( relative, sizeof( relative ) );
  83. if ( filesystem->FileExists( relative ) )
  84. {
  85. item->ImportValveDataChunk( relative );
  86. }
  87. }
  88. }
  89. //-----------------------------------------------------------------------------
  90. // Purpose:
  91. // Input : hwndDlg -
  92. // Output : static
  93. //-----------------------------------------------------------------------------
  94. static void WaveProperties_InitSentenceData( HWND hwndDlg )
  95. {
  96. CWaveFile *item = g_Params.items[ 0 ];
  97. SetDlgItemText( hwndDlg, IDC_WAVENAME, item->GetName() );
  98. SetDlgItemText( hwndDlg, IDC_SENTENCETEXT, item->GetSentenceText() );
  99. SendMessage( GetDlgItem( hwndDlg, IDC_VOICEDUCK ), BM_SETCHECK,
  100. ( WPARAM ) item->GetVoiceDuck() ? BST_CHECKED : BST_UNCHECKED,
  101. ( LPARAM )0 );
  102. }
  103. //-----------------------------------------------------------------------------
  104. // Purpose:
  105. // Input : hwndDlg -
  106. // uMsg -
  107. // wParam -
  108. // lParam -
  109. // Output : static BOOL CALLBACK
  110. //-----------------------------------------------------------------------------
  111. static BOOL CALLBACK WavePropertiesDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  112. {
  113. switch(uMsg)
  114. {
  115. case WM_INITDIALOG:
  116. {
  117. g_Params.PositionSelf( hwndDlg );
  118. WaveProperties_InitSentenceData( hwndDlg );
  119. SetWindowText( hwndDlg, g_Params.m_szDialogTitle );
  120. SetFocus( GetDlgItem( hwndDlg, IDC_WAVENAME ) );
  121. }
  122. return FALSE;
  123. case WM_COMMAND:
  124. switch (LOWORD(wParam))
  125. {
  126. case IDOK:
  127. {
  128. WaveProperties_OnOK( hwndDlg );
  129. EndDialog( hwndDlg, 1 );
  130. }
  131. break;
  132. case IDCANCEL:
  133. EndDialog( hwndDlg, 0 );
  134. break;
  135. case IDC_EXPORTSENTENCE:
  136. WaveProperties_ExportSentence();
  137. break;
  138. case IDC_IMPORTSENTENCE:
  139. WaveProperties_ImportSentence();
  140. WaveProperties_InitSentenceData( hwndDlg );
  141. break;
  142. }
  143. return FALSE;
  144. }
  145. return FALSE;
  146. }
  147. //-----------------------------------------------------------------------------
  148. // Purpose:
  149. // Input : *view -
  150. // *actor -
  151. // Output : int
  152. //-----------------------------------------------------------------------------
  153. int WaveProperties( CWaveParams *params )
  154. {
  155. g_Params = *params;
  156. int retval = DialogBox( (HINSTANCE)GetModuleHandle( 0 ),
  157. MAKEINTRESOURCE( IDD_WAVEPROPERTIES ),
  158. (HWND)GetWorkspaceManager()->getHandle(),
  159. (DLGPROC)WavePropertiesDialogProc );
  160. *params = g_Params;
  161. return retval;
  162. }