MusicPropPage.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. // MusicPropPage.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "LevelEdit.h"
  22. #include "MusicPropPage.h"
  23. #include "AudibleSound.h"
  24. #include "FileMgr.h"
  25. #include "Phys.h"
  26. #include "SceneEditor.h"
  27. #include "SoundBuffer.h"
  28. #include "Utils.h"
  29. #ifdef _DEBUG
  30. #define new DEBUG_NEW
  31. #undef THIS_FILE
  32. static char THIS_FILE[] = __FILE__;
  33. #endif
  34. /////////////////////////////////////////////////////////////////////////////
  35. // MusicPropPage property page
  36. IMPLEMENT_DYNCREATE(MusicPropPageClass, CPropertyPage)
  37. MusicPropPageClass::MusicPropPageClass() : CPropertyPage(MusicPropPageClass::IDD)
  38. {
  39. //{{AFX_DATA_INIT(MusicPropPageClass)
  40. // NOTE: the ClassWizard will add member initialization here
  41. //}}AFX_DATA_INIT
  42. }
  43. MusicPropPageClass::~MusicPropPageClass()
  44. {
  45. }
  46. void MusicPropPageClass::DoDataExchange(CDataExchange* pDX)
  47. {
  48. CPropertyPage::DoDataExchange(pDX);
  49. //{{AFX_DATA_MAP(MusicPropPageClass)
  50. // NOTE: the ClassWizard will add DDX and DDV calls here
  51. //}}AFX_DATA_MAP
  52. }
  53. BEGIN_MESSAGE_MAP(MusicPropPageClass, CPropertyPage)
  54. //{{AFX_MSG_MAP(MusicPropPageClass)
  55. ON_BN_CLICKED(IDC_MUSIC_BROWSE, OnBrowse)
  56. //}}AFX_MSG_MAP
  57. END_MESSAGE_MAP()
  58. /////////////////////////////////////////////////////////////////////////////
  59. // MusicPropPageClass message handlers
  60. BOOL MusicPropPageClass::OnInitDialog()
  61. {
  62. CPropertyPage::OnInitDialog();
  63. //
  64. // Put the background music pathname into the edit control.
  65. //
  66. SceneEditorClass *sceneeditor = ::Get_Scene_Editor();
  67. CString filename = sceneeditor->Get_Background_Music_Filename ();
  68. if (filename.GetLength () > 0) {
  69. CString pathname = ::Get_File_Mgr()->Make_Full_Path (filename);
  70. SetDlgItemText (IDC_MUSIC_PATHNAME, pathname);
  71. }
  72. return TRUE; // return TRUE unless you set the focus to a control
  73. // EXCEPTION: OCX Property Pages should return FALSE
  74. }
  75. void MusicPropPageClass::OnBrowse()
  76. {
  77. // Determine what filename and path to initially display in the dialog.
  78. CString defaultpathname;
  79. CString pathname;
  80. if (GetDlgItemText (IDC_MUSIC_PATHNAME, defaultpathname) > 0) {
  81. defaultpathname = ::Get_File_Mgr()->Make_Full_Path (defaultpathname);
  82. pathname = ::Strip_Filename_From_Path (defaultpathname);
  83. } else {
  84. pathname = ::Get_File_Mgr()->Get_Base_Path();
  85. }
  86. CFileDialog dialog (TRUE, ".wav", defaultpathname, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_EXPLORER, "All Sound Files|*.wav;*.mp3|WAV File (*.wav)|*.wav|MP3 File (*.mp3)|*.mp3||", this);
  87. // Set the pathname so it opens in the correct directory.
  88. dialog.m_ofn.lpstrInitialDir = pathname;
  89. // Ask the user which new asset file to use.
  90. if (dialog.DoModal () == IDOK) {
  91. // Is the new path valid?
  92. if (::Get_File_Mgr ()->Is_Path_Valid (dialog.GetPathName())) {
  93. // Convert the new asset file path to a relative path and pass it onto the base.
  94. CString relativepathname = ::Get_File_Mgr ()->Make_Relative_Path (dialog.GetPathName());
  95. SetDlgItemText (IDC_MUSIC_PATHNAME, relativepathname);
  96. } else {
  97. // Let the user know that this pathname is invalid.
  98. CString message;
  99. CString title;
  100. message.Format (IDS_INVALID_MODEL_PATH_MSG, (LPCTSTR)::Get_File_Mgr()->Get_Base_Path());
  101. title.LoadString (IDS_INVALID_MODEL_PATH_TITLE);
  102. ::MessageBox (m_hWnd, message, title, MB_ICONERROR | MB_OK);
  103. }
  104. }
  105. }
  106. void MusicPropPageClass::OnOK()
  107. {
  108. // Pass the music pathname onto the scene editor.
  109. CString pathname;
  110. GetDlgItemText (IDC_MUSIC_PATHNAME, pathname);
  111. SceneEditorClass *sceneeditor = ::Get_Scene_Editor();
  112. sceneeditor->Set_Background_Music (pathname);
  113. // Check this file into VSS (if possible).
  114. if (::Get_File_Mgr()->Is_VSS_Read_Only() == false) {
  115. ::Get_File_Mgr ()->Add_File_To_Database (pathname);
  116. }
  117. CPropertyPage::OnOK();
  118. return ;
  119. }