SaveSettingsDialog.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. // SaveSettingsDialog.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "W3DView.h"
  22. #include "SaveSettingsDialog.h"
  23. #include "W3DViewDoc.H"
  24. #include "Utils.H"
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CSaveSettingsDialog dialog
  32. ///////////////////////////////////////////////////////////////
  33. //
  34. // CSaveSettingsDialog
  35. //
  36. CSaveSettingsDialog::CSaveSettingsDialog (CWnd* pParent /*=NULL*/)
  37. : CDialog(CSaveSettingsDialog::IDD, pParent)
  38. {
  39. //{{AFX_DATA_INIT(CSaveSettingsDialog)
  40. // NOTE: the ClassWizard will add member initialization here
  41. //}}AFX_DATA_INIT
  42. return ;
  43. }
  44. ///////////////////////////////////////////////////////////////
  45. //
  46. // DoDataExchange
  47. //
  48. void
  49. CSaveSettingsDialog::DoDataExchange (CDataExchange* pDX)
  50. {
  51. // Allow the base class to process this message
  52. CDialog::DoDataExchange(pDX);
  53. //{{AFX_DATA_MAP(CSaveSettingsDialog)
  54. // NOTE: the ClassWizard will add DDX and DDV calls here
  55. //}}AFX_DATA_MAP
  56. return ;
  57. }
  58. BEGIN_MESSAGE_MAP(CSaveSettingsDialog, CDialog)
  59. //{{AFX_MSG_MAP(CSaveSettingsDialog)
  60. ON_BN_CLICKED(IDC_BROWSE_BUTTON, OnBrowseButton)
  61. ON_EN_UPDATE(IDC_FILENAME_EDIT, OnUpdateFilenameEdit)
  62. //}}AFX_MSG_MAP
  63. END_MESSAGE_MAP()
  64. ///////////////////////////////////////////////////////////////
  65. //
  66. // OnInitDialog
  67. //
  68. BOOL
  69. CSaveSettingsDialog::OnInitDialog (void)
  70. {
  71. // Allow the base class to process this message
  72. CDialog::OnInitDialog ();
  73. // Check everything by default
  74. SendDlgItemMessage (IDC_LIGHTING_CHECKBOX, BM_SETCHECK, (WPARAM)TRUE);
  75. SendDlgItemMessage (IDC_BACKGROUND_CHECKBOX, BM_SETCHECK, (WPARAM)TRUE);
  76. SendDlgItemMessage (IDC_CAMERA_CHECKBOX, BM_SETCHECK, (WPARAM)TRUE);
  77. // Put the default filename into the edit control
  78. SetDlgItemText (IDC_FILENAME_EDIT, "Default.dat");
  79. return TRUE;
  80. }
  81. ///////////////////////////////////////////////////////////////
  82. //
  83. // OnBrowseButton
  84. //
  85. void
  86. CSaveSettingsDialog::OnBrowseButton (void)
  87. {
  88. TCHAR szFileName[MAX_PATH];
  89. ::GetModuleFileName (NULL, szFileName, sizeof (szFileName));
  90. LPTSTR pszPath = ::strrchr (szFileName, '\\');
  91. if (pszPath)
  92. {
  93. ::SetCurrentDirectory (pszPath);
  94. pszPath[0] = 0;
  95. }
  96. // Get the current filename
  97. CString stringCurrentFile;
  98. GetDlgItemText (IDC_FILENAME_EDIT, stringCurrentFile);
  99. CFileDialog saveFileDialog (FALSE,
  100. ".dat",
  101. stringCurrentFile,
  102. OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_EXPLORER,
  103. "Setting data files(*.dat)|*.dat||",
  104. this);
  105. // Ask the user what filename to save under
  106. if (saveFileDialog.DoModal () == IDOK)
  107. {
  108. // Put the path into the filename edit control
  109. SetDlgItemText (IDC_FILENAME_EDIT, saveFileDialog.GetPathName ());
  110. }
  111. return ;
  112. }
  113. ///////////////////////////////////////////////////////////////
  114. //
  115. // OnUpdateFilenameEdit
  116. //
  117. void
  118. CSaveSettingsDialog::OnUpdateFilenameEdit (void)
  119. {
  120. // Set the enabled state of the OK button
  121. // based on the values of the control
  122. FixOKEnableState ();
  123. return ;
  124. }
  125. ///////////////////////////////////////////////////////////////
  126. //
  127. // OnUpdateFilenameEdit
  128. //
  129. void
  130. CSaveSettingsDialog::OnOK (void)
  131. {
  132. // Assume we want to allow the base class to process this message
  133. BOOL bAllowDefaultProcessing = TRUE;
  134. // Get a pointer to the doc so we can get at the current scene
  135. // pointer.
  136. CW3DViewDoc *pCDoc = ::GetCurrentDocument ();
  137. if (pCDoc)
  138. {
  139. DWORD dwSettingsMask = 0L;
  140. // Did the user want to save lighting?
  141. if (SendDlgItemMessage (IDC_LIGHTING_CHECKBOX, BM_GETCHECK))
  142. {
  143. dwSettingsMask |= SAVE_SETTINGS_LIGHT;
  144. }
  145. // Did the user want to save the background?
  146. if (SendDlgItemMessage (IDC_BACKGROUND_CHECKBOX, BM_GETCHECK))
  147. {
  148. dwSettingsMask |= SAVE_SETTINGS_BACK;
  149. }
  150. // Did the user want to save camera settings?
  151. if (SendDlgItemMessage (IDC_CAMERA_CHECKBOX, BM_GETCHECK))
  152. {
  153. dwSettingsMask |= SAVE_SETTINGS_CAMERA;
  154. }
  155. // Get the current filename
  156. CString stringCurrentFile;
  157. GetDlgItemText (IDC_FILENAME_EDIT, stringCurrentFile);
  158. // Save the settings to the selected file
  159. bAllowDefaultProcessing = pCDoc->SaveSettings (stringCurrentFile,
  160. dwSettingsMask);
  161. }
  162. if (bAllowDefaultProcessing)
  163. {
  164. // Allow the base class to process this message
  165. CDialog::OnOK ();
  166. }
  167. return ;
  168. }
  169. ///////////////////////////////////////////////////////////////
  170. //
  171. // OnCommand
  172. //
  173. BOOL
  174. CSaveSettingsDialog::OnCommand
  175. (
  176. WPARAM wParam,
  177. LPARAM lParam
  178. )
  179. {
  180. // Did the user check/uncheck one of the checkboxes?
  181. if ((HIWORD (wParam) == BN_CLICKED) &&
  182. ((LOWORD (wParam) == IDC_LIGHTING_CHECKBOX) ||
  183. (LOWORD (wParam) == IDC_BACKGROUND_CHECKBOX) ||
  184. (LOWORD (wParam) == IDC_CAMERA_CHECKBOX)))
  185. {
  186. // Set the enabled state of the OK button
  187. // based on the values of the control
  188. FixOKEnableState ();
  189. }
  190. // Allow the base class to process this message
  191. return CDialog::OnCommand (wParam, lParam);
  192. }
  193. ///////////////////////////////////////////////////////////////
  194. //
  195. // FixOKEnableState
  196. //
  197. void
  198. CSaveSettingsDialog::FixOKEnableState (void)
  199. {
  200. // Determine which (if any) checkboxes are checked
  201. int iValidSel = 0;
  202. iValidSel += SendDlgItemMessage (IDC_LIGHTING_CHECKBOX, BM_GETCHECK);
  203. iValidSel += SendDlgItemMessage (IDC_BACKGROUND_CHECKBOX, BM_GETCHECK);
  204. iValidSel += SendDlgItemMessage (IDC_CAMERA_CHECKBOX, BM_GETCHECK);
  205. // Is the dialog in a valid state?
  206. if ((iValidSel > 0) &&
  207. (::GetWindowTextLength (::GetDlgItem (m_hWnd, IDC_FILENAME_EDIT)) > 0))
  208. {
  209. // Enable the OK button
  210. ::EnableWindow (::GetDlgItem (m_hWnd, IDOK), TRUE);
  211. }
  212. else
  213. {
  214. // Disable the OK button
  215. ::EnableWindow (::GetDlgItem (m_hWnd, IDOK), FALSE);
  216. }
  217. return ;
  218. }