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.

294 lines
8.6 KiB

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