Counter Strike : Global Offensive Source Code
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.

300 lines
8.8 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "stdafx.h"
  7. #include "hammer.h"
  8. #include "OPTGeneral.h"
  9. #include "Options.h"
  10. #pragma warning(disable:4244)
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include <tier0/memdbgon.h>
  13. void EditorUtil_ConvertPath(CString &str, bool bSave);
  14. IMPLEMENT_DYNCREATE(COPTGeneral, CPropertyPage)
  15. BEGIN_MESSAGE_MAP(COPTGeneral, CPropertyPage)
  16. //{{AFX_MSG_MAP(COPTGeneral)
  17. ON_BN_CLICKED(IDC_INDEPENDENTWINDOWS, OnIndependentwindows)
  18. // ON_BN_CLICKED(IDC_ENABLE_PERFORCE_INTEGRATION, OnEnablePerforceIntegration)
  19. ON_BN_CLICKED(IDC_BROWSEAUTOSAVEDIR, OnBrowseAutosaveDir)
  20. ON_BN_CLICKED(IDC_ENABLEAUTOSAVE, OnEnableAutosave)
  21. //}}AFX_MSG_MAP
  22. END_MESSAGE_MAP()
  23. //-----------------------------------------------------------------------------
  24. // Purpose:
  25. //-----------------------------------------------------------------------------
  26. COPTGeneral::COPTGeneral(void) : CPropertyPage(COPTGeneral::IDD)
  27. {
  28. //{{AFX_DATA_INIT(COPTGeneral)
  29. m_iMaxAutosavesPerMap = 0;
  30. m_iUndoLevels = 0;
  31. m_nMaxCameras = 5;
  32. //}}AFX_DATA_INIT
  33. }
  34. //-----------------------------------------------------------------------------
  35. // Purpose:
  36. //-----------------------------------------------------------------------------
  37. COPTGeneral::~COPTGeneral(void)
  38. {
  39. }
  40. //-----------------------------------------------------------------------------
  41. // Purpose: Ensures that our undo levels are at least 5.
  42. //-----------------------------------------------------------------------------
  43. void PASCAL DDV_UndoLevels(CDataExchange *pDX, int value)
  44. {
  45. if (value < 5)
  46. {
  47. AfxMessageBox("Undo levels must be at least 5.", MB_ICONEXCLAMATION | MB_OK);
  48. pDX->Fail();
  49. }
  50. }
  51. void PASCAL DDV_MaxCameras(CDataExchange *pDX, int value)
  52. {
  53. if (value < 1 || value > 100)
  54. {
  55. AfxMessageBox("Max cameras must be between 1 and 1000.", MB_ICONEXCLAMATION | MB_OK);
  56. pDX->Fail();
  57. }
  58. }
  59. void PASCAL DDV_AutosaveSpace(CDataExchange *pDX, int value)
  60. {
  61. if ( value > 10000 )
  62. {
  63. AfxMessageBox("You have selected too much space for autosaving. The maximum value is 10000.", MB_ICONEXCLAMATION | MB_OK);
  64. pDX->Fail();
  65. }
  66. }
  67. void PASCAL DDV_NumberAutosaves(CDataExchange *pDX, int value)
  68. {
  69. if ( value > 999 )
  70. {
  71. AfxMessageBox("Number of autosaves must be 0-999.", MB_ICONEXCLAMATION | MB_OK);
  72. pDX->Fail();
  73. }
  74. }
  75. void PASCAL DDV_AutosaveTimer(CDataExchange *pDX, int value)
  76. {
  77. if ( value < 1 || value > 120 )
  78. {
  79. AfxMessageBox("Time must be between 1 - 120 minutes.", MB_ICONEXCLAMATION | MB_OK);
  80. pDX->Fail();
  81. }
  82. }
  83. //-----------------------------------------------------------------------------
  84. // Purpose:
  85. // Input : pDX -
  86. //-----------------------------------------------------------------------------
  87. void COPTGeneral::DoDataExchange(CDataExchange* pDX)
  88. {
  89. CPropertyPage::DoDataExchange(pDX);
  90. //{{AFX_DATA_MAP(COPTGeneral)
  91. DDX_Control(pDX, IDC_LOADWINPOSITIONS, m_cLoadWinPos);
  92. DDX_Control(pDX, IDC_INDEPENDENTWINDOWS, m_cIndependentWin);
  93. // DDX_Control(pDX, IDC_ENABLE_PERFORCE_INTEGRATION, m_cEnablePerforceIntegration);
  94. DDX_Control(pDX, IDC_UNDOSPIN, m_UndoSpin);
  95. DDX_Text(pDX, IDC_UNDO, m_iUndoLevels);
  96. DDX_Text(pDX, IDC_MAX_CAMERAS, m_nMaxCameras);
  97. DDX_Check(pDX, IDC_STRETCH_ARCH, Options.general.bStretchArches);
  98. DDX_Check(pDX, IDC_GROUPWHILEIGNOREGROUPS, Options.general.bGroupWhileIgnore);
  99. DDX_Check(pDX, IDC_INDEPENDENTWINDOWS, Options.general.bIndependentwin);
  100. DDX_Check(pDX, IDC_ENABLE_PERFORCE_INTEGRATION, Options.general.bEnablePerforceIntegration);
  101. DDX_Check(pDX, IDC_LOADWINPOSITIONS, Options.general.bLoadwinpos);
  102. DDV_UndoLevels( pDX, m_iUndoLevels );
  103. DDV_MaxCameras( pDX, m_nMaxCameras );
  104. DDX_Control(pDX, IDC_ENABLEAUTOSAVE, m_cEnableAutosave);
  105. DDX_Check(pDX, IDC_ENABLEAUTOSAVE, Options.general.bEnableAutosave);
  106. DDX_Text(pDX, IDC_MAPITERATIONS, m_iMaxAutosavesPerMap);
  107. DDX_Text(pDX, IDC_AUTOSAVESPACE, m_iMaxAutosaveSpace);
  108. DDX_Text(pDX, IDC_SAVETIME, m_iTimeBetweenSaves);
  109. DDX_Control(pDX, IDC_AUTOSAVEDIR, m_cAutosaveDir);
  110. DDX_Control(pDX, IDC_AUTOSAVETIMELABEL, m_cAutosaveTimeLabel);
  111. DDX_Control(pDX, IDC_SAVETIME, m_cAutosaveTime);
  112. DDX_Control(pDX, IDC_AUTOSAVESPACELABEL, m_cAutosaveSpaceLabel);
  113. DDX_Control(pDX, IDC_AUTOSAVESPACE, m_cAutosaveSpace);
  114. DDX_Control(pDX, IDC_AUTOSAVEITERATIONLABEL, m_cAutosaveIterationLabel);
  115. DDX_Control(pDX, IDC_MAPITERATIONS, m_cAutosaveIterations);
  116. DDX_Control(pDX, IDC_AUTOSAVEDIRECTORYLABEL, m_cAutosaveDirectoryLabel);
  117. DDX_Control(pDX, IDC_BROWSEAUTOSAVEDIR, m_cAutosaveBrowseButton);
  118. DDV_AutosaveSpace( pDX, m_iMaxAutosaveSpace );
  119. DDV_NumberAutosaves( pDX, m_iMaxAutosavesPerMap );
  120. DDV_AutosaveTimer( pDX, m_iTimeBetweenSaves );
  121. //}}AFX_DATA_MAP
  122. }
  123. //-----------------------------------------------------------------------------
  124. // Purpose:
  125. // Output : Returns TRUE on success, FALSE on failure.
  126. //-----------------------------------------------------------------------------
  127. BOOL COPTGeneral::OnInitDialog(void)
  128. {
  129. char szAutosaveDir[MAX_PATH];
  130. APP()->GetDirectory( DIR_AUTOSAVE, szAutosaveDir );
  131. CString str( szAutosaveDir );
  132. m_nMaxCameras = Options.general.nMaxCameras;
  133. m_iUndoLevels = Options.general.iUndoLevels;
  134. m_iMaxAutosavesPerMap = Options.general.iMaxAutosavesPerMap;
  135. m_iMaxAutosaveSpace = Options.general.iMaxAutosaveSpace;
  136. m_iTimeBetweenSaves = Options.general.iTimeBetweenSaves;
  137. CPropertyPage::OnInitDialog();
  138. m_cEnableAutosave.SetCheck( Options.general.bEnableAutosave );
  139. m_cAutosaveDir.SetWindowText( str );
  140. // set undo range
  141. m_UndoSpin.SetRange(5, 999);
  142. OnEnableAutosave();
  143. OnIndependentwindows();
  144. return TRUE;
  145. }
  146. //-----------------------------------------------------------------------------
  147. // Purpose:
  148. // Output : Returns TRUE on success, FALSE on failure.
  149. //-----------------------------------------------------------------------------
  150. BOOL COPTGeneral::OnApply(void)
  151. {
  152. BOOL bResetTimer = FALSE;
  153. if( Options.general.iTimeBetweenSaves != m_iTimeBetweenSaves )
  154. {
  155. //if the time value has changed, the timer needs to be reset so autosaves
  156. //happen at the new interval in this instance of hammer
  157. bResetTimer = TRUE;
  158. }
  159. if( ( Options.general.iMaxAutosavesPerMap != 0 && m_iMaxAutosavesPerMap == 0 ) ||
  160. ( Options.general.iMaxAutosavesPerMap == 0 && m_iMaxAutosavesPerMap != 0 ) )
  161. {
  162. //if the number of autosaves per map has changed to or away from 0 then
  163. //the timer needs to be reset
  164. bResetTimer = TRUE;
  165. }
  166. Options.general.iUndoLevels = m_iUndoLevels;
  167. Options.general.nMaxCameras = m_nMaxCameras;
  168. Options.general.iMaxAutosavesPerMap = m_iMaxAutosavesPerMap;
  169. Options.general.iMaxAutosaveSpace = m_iMaxAutosaveSpace;
  170. Options.general.iTimeBetweenSaves = m_iTimeBetweenSaves;
  171. Options.general.bEnableAutosave = m_cEnableAutosave.GetCheck();
  172. CString str;
  173. m_cAutosaveDir.GetWindowText(str);
  174. if ( strcmp( Options.general.szAutosaveDir, str ) )
  175. {
  176. strcpy( Options.general.szAutosaveDir, str );
  177. bResetTimer = TRUE;
  178. }
  179. if( bResetTimer == TRUE )
  180. {
  181. APP()->ResetAutosaveTimer();
  182. }
  183. Options.PerformChanges(COptions::secGeneral);
  184. if ( Options.general.bEnableAutosave )
  185. {
  186. if ( !APP()->VerifyAutosaveDirectory( Options.general.szAutosaveDir ) )
  187. {
  188. Options.general.bEnableAutosave = false;
  189. m_cEnableAutosave.SetCheck( Options.general.bEnableAutosave );
  190. OnEnableAutosave();
  191. return FALSE;
  192. }
  193. }
  194. return(CPropertyPage::OnApply());
  195. }
  196. //-----------------------------------------------------------------------------
  197. // Purpose:
  198. //-----------------------------------------------------------------------------
  199. void COPTGeneral::OnIndependentwindows(void)
  200. {
  201. m_cLoadWinPos.EnableWindow(m_cIndependentWin.GetCheck());
  202. }
  203. void COPTGeneral::OnEnablePerforceIntegration(void)
  204. {
  205. }
  206. void COPTGeneral::OnEnableAutosave(void)
  207. {
  208. int iEnabled = m_cEnableAutosave.GetCheck();
  209. m_cAutosaveDir.EnableWindow( iEnabled );
  210. m_cAutosaveTime.EnableWindow( iEnabled );
  211. m_cAutosaveTimeLabel.EnableWindow( iEnabled );
  212. m_cAutosaveSpaceLabel.EnableWindow( iEnabled );
  213. m_cAutosaveSpace.EnableWindow( iEnabled );
  214. m_cAutosaveIterationLabel.EnableWindow( iEnabled );
  215. m_cAutosaveIterations.EnableWindow( iEnabled );
  216. m_cAutosaveDirectoryLabel.EnableWindow( iEnabled );
  217. m_cAutosaveBrowseButton.EnableWindow( iEnabled );
  218. }
  219. void COPTGeneral::OnBrowseAutosaveDir(void)
  220. {
  221. char szTmp[MAX_PATH];
  222. if (!BrowseForFolder("Select Autosave Directory", szTmp))
  223. {
  224. return;
  225. }
  226. CString str(szTmp);
  227. EditorUtil_ConvertPath(str, false);
  228. m_cAutosaveDir.SetWindowText(str);
  229. }
  230. BOOL COPTGeneral::BrowseForFolder(char *pszTitle, char *pszDirectory)
  231. {
  232. char szTmp[MAX_PATH];
  233. BROWSEINFO bi;
  234. memset(&bi, 0, sizeof bi);
  235. bi.hwndOwner = m_hWnd;
  236. bi.pszDisplayName = szTmp;
  237. bi.lpszTitle = pszTitle;
  238. bi.ulFlags = BIF_RETURNONLYFSDIRS;
  239. LPITEMIDLIST idl = SHBrowseForFolder(&bi);
  240. if(idl == NULL)
  241. return FALSE;
  242. SHGetPathFromIDList(idl, pszDirectory);
  243. CoTaskMemFree(idl);
  244. return TRUE;
  245. }