AnimatedSoundOptionsDialog.cpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. // AnimatedSoundOptionsDialog.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "w3dview.h"
  22. #include "globals.h"
  23. #include "animatedsoundoptionsdialog.h"
  24. #include "ffactory.h"
  25. #include "animatedsoundmgr.h"
  26. #include "wwsaveload.h"
  27. #include "definitionmgr.h"
  28. #include "wwfile.h"
  29. #include "chunkio.h"
  30. #include "wwdebug.h"
  31. #include "restrictedfiledialog.h"
  32. #include "utils.h"
  33. #ifdef _DEBUG
  34. #define new DEBUG_NEW
  35. #undef THIS_FILE
  36. static char THIS_FILE[] = __FILE__;
  37. #endif
  38. /////////////////////////////////////////////////////////////////////////////
  39. // AnimatedSoundOptionsDialogClass dialog
  40. AnimatedSoundOptionsDialogClass::AnimatedSoundOptionsDialogClass(CWnd* pParent /*=NULL*/)
  41. : CDialog(AnimatedSoundOptionsDialogClass::IDD, pParent)
  42. {
  43. //{{AFX_DATA_INIT(AnimatedSoundOptionsDialogClass)
  44. // NOTE: the ClassWizard will add member initialization here
  45. //}}AFX_DATA_INIT
  46. }
  47. void AnimatedSoundOptionsDialogClass::DoDataExchange(CDataExchange* pDX)
  48. {
  49. CDialog::DoDataExchange(pDX);
  50. //{{AFX_DATA_MAP(AnimatedSoundOptionsDialogClass)
  51. // NOTE: the ClassWizard will add DDX and DDV calls here
  52. //}}AFX_DATA_MAP
  53. }
  54. BEGIN_MESSAGE_MAP(AnimatedSoundOptionsDialogClass, CDialog)
  55. //{{AFX_MSG_MAP(AnimatedSoundOptionsDialogClass)
  56. ON_BN_CLICKED(IDC_SOUND_DEFINITION_LIBRARY_BROWSE_BUTTON, OnSoundDefinitionLibraryBrowseButton)
  57. ON_BN_CLICKED(IDC_SOUND_INI_BROWSE_BUTTON, OnSoundIniBrowseButton)
  58. ON_BN_CLICKED(IDC_SOUND_PATH_BROWSE_BUTTON, OnSoundPathBrowseButton)
  59. //}}AFX_MSG_MAP
  60. END_MESSAGE_MAP()
  61. /////////////////////////////////////////////////////////////////////////////
  62. //
  63. // OnSoundDefinitionLibraryBrowseButton
  64. //
  65. /////////////////////////////////////////////////////////////////////////////
  66. void
  67. AnimatedSoundOptionsDialogClass::OnSoundDefinitionLibraryBrowseButton (void)
  68. {
  69. CFileDialog dialog ( TRUE,
  70. ".ddb",
  71. "20480.ddb",
  72. OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_EXPLORER,
  73. "Definition Database Files(*.ddb)|*.ddb||",
  74. this);
  75. //
  76. // Prompt the user
  77. //
  78. if (dialog.DoModal () == IDOK) {
  79. SetDlgItemText (IDC_SOUND_DEFINITION_LIBRARY_EDIT, dialog.GetPathName ());
  80. }
  81. return ;
  82. }
  83. /////////////////////////////////////////////////////////////////////////////
  84. //
  85. // OnSoundIniBrowseButton
  86. //
  87. /////////////////////////////////////////////////////////////////////////////
  88. void
  89. AnimatedSoundOptionsDialogClass::OnSoundIniBrowseButton (void)
  90. {
  91. CFileDialog dialog ( TRUE,
  92. ".ini",
  93. "w3danimsound.ini",
  94. OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_EXPLORER,
  95. "INI Files (*.ini)|*.ini||",
  96. this);
  97. //
  98. // Prompt the user
  99. //
  100. if (dialog.DoModal () == IDOK) {
  101. SetDlgItemText (IDC_SOUND_INI_EDIT, dialog.GetPathName ());
  102. }
  103. return ;
  104. }
  105. /////////////////////////////////////////////////////////////////////////////
  106. //
  107. // OnOK
  108. //
  109. /////////////////////////////////////////////////////////////////////////////
  110. void
  111. AnimatedSoundOptionsDialogClass::OnOK (void)
  112. {
  113. CDialog::OnOK ();
  114. //
  115. // Get the user's response
  116. //
  117. CString sound_def_lib_path;
  118. CString sound_ini_path;
  119. CString sound_data_path;
  120. GetDlgItemText (IDC_SOUND_DEFINITION_LIBRARY_EDIT, sound_def_lib_path);
  121. GetDlgItemText (IDC_SOUND_INI_EDIT, sound_ini_path);
  122. GetDlgItemText (IDC_SOUND_FILE_PATH_EDIT, sound_data_path);
  123. //
  124. // Store this information in the registry
  125. //
  126. theApp.WriteProfileString ("Config", "SoundDefLibPath", sound_def_lib_path);
  127. theApp.WriteProfileString ("Config", "AnimSoundINIPath", sound_ini_path);
  128. theApp.WriteProfileString ("Config", "AnimSoundDataPath", sound_data_path);
  129. Load_Animated_Sound_Settings ();
  130. return ;
  131. }
  132. /////////////////////////////////////////////////////////////////////////////
  133. //
  134. // OnInitDialog
  135. //
  136. /////////////////////////////////////////////////////////////////////////////
  137. BOOL
  138. AnimatedSoundOptionsDialogClass::OnInitDialog (void)
  139. {
  140. CDialog::OnInitDialog ();
  141. StringClass sound_def_lib_path = theApp.GetProfileString ("Config", "SoundDefLibPath");
  142. StringClass sound_ini_path = theApp.GetProfileString ("Config", "AnimSoundINIPath");
  143. StringClass sound_data_path = theApp.GetProfileString ("Config", "AnimSoundDataPath");
  144. //
  145. // Fill in the default values
  146. //
  147. SetDlgItemText (IDC_SOUND_DEFINITION_LIBRARY_EDIT, sound_def_lib_path);
  148. SetDlgItemText (IDC_SOUND_INI_EDIT, sound_ini_path);
  149. SetDlgItemText (IDC_SOUND_FILE_PATH_EDIT, sound_data_path);
  150. return TRUE;
  151. }
  152. /////////////////////////////////////////////////////////////////////////////
  153. //
  154. // Load_Animated_Sound_Settings
  155. //
  156. /////////////////////////////////////////////////////////////////////////////
  157. void
  158. AnimatedSoundOptionsDialogClass::Load_Animated_Sound_Settings (void)
  159. {
  160. //
  161. // Start fresh
  162. //
  163. DefinitionMgrClass::Free_Definitions ();
  164. //
  165. // Get the data from the registry
  166. //
  167. StringClass sound_def_lib_path = theApp.GetProfileString ("Config", "SoundDefLibPath");
  168. StringClass sound_ini_path = theApp.GetProfileString ("Config", "AnimSoundINIPath");
  169. StringClass sound_data_path = theApp.GetProfileString ("Config", "AnimSoundDataPath");
  170. //
  171. // Try to load the definitions into the definition mgr
  172. //
  173. FileClass *file = _TheFileFactory->Get_File (sound_def_lib_path);
  174. if (file != NULL) {
  175. file->Open (FileClass::READ);
  176. ChunkLoadClass cload (file);
  177. SaveLoadSystemClass::Load (cload);
  178. file->Close ();
  179. _TheFileFactory->Return_File (file);
  180. } else {
  181. WWDEBUG_SAY (("Failed to load file %s\n", sound_def_lib_path.Peek_Buffer ()));
  182. }
  183. //
  184. // Load the sound settings from the ini file
  185. //
  186. AnimatedSoundMgrClass::Shutdown ();
  187. AnimatedSoundMgrClass::Initialize (sound_ini_path);
  188. //
  189. // Add a sub-directory to the file factory for audio use
  190. //
  191. _TheSimpleFileFactory->Append_Sub_Directory (sound_data_path);
  192. return ;
  193. }
  194. /////////////////////////////////////////////////////////////////////////////
  195. //
  196. // OnSoundPathBrowseButton
  197. //
  198. /////////////////////////////////////////////////////////////////////////////
  199. void
  200. AnimatedSoundOptionsDialogClass::OnSoundPathBrowseButton (void)
  201. {
  202. RestrictedFileDialogClass dialog ( TRUE,
  203. ".wav",
  204. "test.wav",
  205. OFN_HIDEREADONLY | OFN_EXPLORER,
  206. "Directories|*.wav||",
  207. AfxGetMainWnd ());
  208. dialog.m_ofn.lpstrTitle = "Pick Sound Path";
  209. //
  210. // Prompt the user
  211. //
  212. if (dialog.DoModal () == IDOK) {
  213. CString path = ::Strip_Filename_From_Path (dialog.GetPathName ());
  214. SetDlgItemText (IDC_SOUND_FILE_PATH_EDIT, path);
  215. }
  216. return ;
  217. }