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.

305 lines
6.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 "GameConfig.h"
  9. #include "OPTBuild.h"
  10. #include "Options.h"
  11. #include "shlobj.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include <tier0/memdbgon.h>
  14. void UpdateConfigList(CComboBox &combo);
  15. void SelectActiveConfig(CComboBox &combo);
  16. // dvs: this is duplicated in RunMapExpertDlg.cpp!!
  17. enum
  18. {
  19. id_InsertParmMapFileNoExt = 0x100,
  20. id_InsertParmMapFile,
  21. id_InsertParmMapPath,
  22. id_InsertParmBspDir,
  23. id_InsertParmExeDir,
  24. id_InsertParmGameDir,
  25. id_InsertParmEnd
  26. };
  27. void EditorUtil_ConvertPath(CString &str, bool bSave);
  28. void EditorUtil_TransferPath(CDialog *pDlg, int nIDC, char *szDest, bool bSave);
  29. COPTBuild::COPTBuild()
  30. : CPropertyPage(COPTBuild::IDD)
  31. {
  32. //{{AFX_DATA_INIT(COPTBuild)
  33. //}}AFX_DATA_INIT
  34. m_pConfig = NULL;
  35. }
  36. void COPTBuild::DoDataExchange(CDataExchange* pDX)
  37. {
  38. CPropertyPage::DoDataExchange(pDX);
  39. //{{AFX_DATA_MAP(COPTBuild)
  40. DDX_Control(pDX, IDC_BSPDIR, m_cBSPDir);
  41. DDX_Control(pDX, IDC_VIS, m_cVIS);
  42. DDX_Control(pDX, IDC_LIGHT, m_cLIGHT);
  43. DDX_Control(pDX, IDC_GAME, m_cGame);
  44. DDX_Control(pDX, IDC_BSP, m_cBSP);
  45. DDX_Control(pDX, IDC_CONFIGS, m_cConfigs);
  46. //}}AFX_DATA_MAP
  47. }
  48. BEGIN_MESSAGE_MAP(COPTBuild, CPropertyPage)
  49. //{{AFX_MSG_MAP(COPTBuild)
  50. ON_BN_CLICKED(IDC_BROWSE_BSP, OnBrowseBsp)
  51. ON_BN_CLICKED(IDC_BROWSE_GAME, OnBrowseGame)
  52. ON_BN_CLICKED(IDC_BROWSE_LIGHT, OnBrowseLight)
  53. ON_BN_CLICKED(IDC_BROWSE_VIS, OnBrowseVis)
  54. ON_CBN_SELCHANGE(IDC_CONFIGS, OnSelchangeConfigs)
  55. ON_BN_CLICKED(IDC_PARMS_BSP, OnParmsBsp)
  56. ON_BN_CLICKED(IDC_PARMS_GAME, OnParmsGame)
  57. ON_BN_CLICKED(IDC_PARMS_LIGHT, OnParmsLight)
  58. ON_BN_CLICKED(IDC_PARMS_VIS, OnParmsVis)
  59. ON_BN_CLICKED(IDC_BROWSE_BSPDIR, OnBrowseBspdir)
  60. ON_COMMAND_EX_RANGE(id_InsertParmMapFileNoExt, id_InsertParmEnd, HandleInsertParm)
  61. //}}AFX_MSG_MAP
  62. END_MESSAGE_MAP()
  63. //-----------------------------------------------------------------------------
  64. // Purpose:
  65. //-----------------------------------------------------------------------------
  66. void COPTBuild::DoBrowse(CWnd *pWnd)
  67. {
  68. // Convert $Steam tokens to the real paths.
  69. CString str;
  70. pWnd->GetWindowText(str);
  71. EditorUtil_ConvertPath(str, true);
  72. CFileDialog dlg(TRUE, ".exe", str, OFN_NOCHANGEDIR | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, "Programs (*.exe)|*.exe||", this);
  73. if (dlg.DoModal() == IDCANCEL)
  74. return;
  75. // Convert back to $Steam tokens.
  76. str = dlg.GetPathName();
  77. EditorUtil_ConvertPath(str, false);
  78. pWnd->SetWindowText(str);
  79. }
  80. void COPTBuild::OnBrowseBsp()
  81. {
  82. DoBrowse(&m_cBSP);
  83. }
  84. void COPTBuild::OnBrowseGame()
  85. {
  86. DoBrowse(&m_cGame);
  87. }
  88. void COPTBuild::OnBrowseLight()
  89. {
  90. DoBrowse(&m_cLIGHT);
  91. }
  92. void COPTBuild::OnBrowseVis()
  93. {
  94. DoBrowse(&m_cVIS);
  95. }
  96. void COPTBuild::OnSelchangeConfigs()
  97. {
  98. SaveInfo(m_pConfig);
  99. m_pConfig = NULL;
  100. int iCurSel = m_cConfigs.GetCurSel();
  101. BOOL bKillFields = (iCurSel == CB_ERR) ? FALSE : TRUE;
  102. m_cBSP.EnableWindow(bKillFields);
  103. m_cLIGHT.EnableWindow(bKillFields);
  104. m_cVIS.EnableWindow(bKillFields);
  105. m_cGame.EnableWindow(bKillFields);
  106. m_cBSPDir.EnableWindow(bKillFields);
  107. if(iCurSel == CB_ERR)
  108. return;
  109. // get pointer to the configuration
  110. m_pConfig = Options.configs.FindConfig(m_cConfigs.GetItemData(iCurSel));
  111. // update dialog data
  112. EditorUtil_TransferPath(this, IDC_BSP, m_pConfig->szBSP, false);
  113. EditorUtil_TransferPath(this, IDC_LIGHT, m_pConfig->szLIGHT, false);
  114. EditorUtil_TransferPath(this, IDC_VIS, m_pConfig->szVIS, false);
  115. EditorUtil_TransferPath(this, IDC_GAME, m_pConfig->szExecutable, false);
  116. EditorUtil_TransferPath(this, IDC_BSPDIR, m_pConfig->szBSPDir, false);
  117. }
  118. void COPTBuild::SaveInfo(CGameConfig *pConfig)
  119. {
  120. if (!pConfig)
  121. {
  122. return;
  123. }
  124. EditorUtil_TransferPath(this, IDC_BSP, m_pConfig->szBSP, true);
  125. EditorUtil_TransferPath(this, IDC_LIGHT, m_pConfig->szLIGHT, true);
  126. EditorUtil_TransferPath(this, IDC_VIS, m_pConfig->szVIS, true);
  127. EditorUtil_TransferPath(this, IDC_GAME, m_pConfig->szExecutable, true);
  128. EditorUtil_TransferPath(this, IDC_BSPDIR, m_pConfig->szBSPDir, true);
  129. }
  130. void COPTBuild::UpdateConfigList()
  131. {
  132. m_pConfig = NULL;
  133. ::UpdateConfigList(m_cConfigs);
  134. ::SelectActiveConfig(m_cConfigs);
  135. OnSelchangeConfigs();
  136. SetModified();
  137. }
  138. BOOL COPTBuild::OnInitDialog()
  139. {
  140. CPropertyPage::OnInitDialog();
  141. UpdateConfigList();
  142. SetModified(TRUE);
  143. return TRUE;
  144. }
  145. BOOL COPTBuild::OnApply()
  146. {
  147. SaveInfo(m_pConfig);
  148. return CPropertyPage::OnApply();
  149. }
  150. BOOL COPTBuild::HandleInsertParm(UINT nID)
  151. // insert a parm at the current cursor location into the parameters
  152. // edit control
  153. {
  154. LPCTSTR pszInsert = 0;
  155. switch (nID)
  156. {
  157. case id_InsertParmMapFileNoExt:
  158. pszInsert = "$file";
  159. break;
  160. case id_InsertParmMapFile:
  161. pszInsert = "$file.$ext";
  162. break;
  163. case id_InsertParmMapPath:
  164. pszInsert = "$path";
  165. break;
  166. case id_InsertParmExeDir:
  167. pszInsert = "$exedir";
  168. break;
  169. case id_InsertParmBspDir:
  170. pszInsert = "$bspdir";
  171. break;
  172. case id_InsertParmGameDir:
  173. pszInsert = "$gamedir";
  174. break;
  175. }
  176. Assert(pszInsert != NULL);
  177. if (!pszInsert)
  178. {
  179. return TRUE;
  180. }
  181. m_pAddParmWnd->ReplaceSel(pszInsert);
  182. return TRUE;
  183. }
  184. void COPTBuild::InsertParm(UINT nID, CEdit *pEdit)
  185. {
  186. m_pAddParmWnd = pEdit;
  187. // two stages - name/description OR data itself
  188. CMenu menu;
  189. menu.CreatePopupMenu();
  190. menu.AppendMenu(MF_STRING, id_InsertParmMapFileNoExt, "Map Filename (no extension)");
  191. menu.AppendMenu(MF_STRING, id_InsertParmMapFile, "Map Filename (with extension)");
  192. menu.AppendMenu(MF_STRING, id_InsertParmMapPath, "Map Path (no filename)");
  193. menu.AppendMenu(MF_SEPARATOR);
  194. menu.AppendMenu(MF_STRING, id_InsertParmExeDir, "Game Executable Directory");
  195. menu.AppendMenu(MF_STRING, id_InsertParmBspDir, "BSP Directory");
  196. menu.AppendMenu(MF_STRING, id_InsertParmGameDir, "Game Directory");
  197. // track menu
  198. CWnd *pButton = GetDlgItem(nID);
  199. CRect r;
  200. pButton->GetWindowRect(r);
  201. menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, r.left, r.bottom, this, NULL);
  202. }
  203. void COPTBuild::OnParmsBsp()
  204. {
  205. InsertParm(IDC_PARMS_BSP, &m_cBSP);
  206. }
  207. void COPTBuild::OnParmsGame()
  208. {
  209. InsertParm(IDC_PARMS_GAME, &m_cGame);
  210. }
  211. void COPTBuild::OnParmsLight()
  212. {
  213. InsertParm(IDC_PARMS_LIGHT, &m_cLIGHT);
  214. }
  215. void COPTBuild::OnParmsVis()
  216. {
  217. InsertParm(IDC_PARMS_VIS, &m_cVIS);
  218. }
  219. void COPTBuild::OnBrowseBspdir()
  220. {
  221. CString str;
  222. m_cBSPDir.GetWindowText(str);
  223. EditorUtil_ConvertPath(str, true);
  224. char szTemp[MAX_PATH];
  225. Q_strncpy(szTemp, str, MAX_PATH);
  226. BROWSEINFO bi;
  227. memset(&bi, 0, sizeof bi);
  228. bi.hwndOwner = m_hWnd;
  229. bi.pszDisplayName = szTemp;
  230. bi.lpszTitle = "Select BSP file directory";
  231. bi.ulFlags = BIF_RETURNONLYFSDIRS;
  232. LPITEMIDLIST idl = SHBrowseForFolder(&bi);
  233. if (idl == NULL)
  234. return;
  235. SHGetPathFromIDList(idl, szTemp);
  236. CoTaskMemFree(idl);
  237. // Convert back to %STEAM%.
  238. str = szTemp;
  239. EditorUtil_ConvertPath(str, false);
  240. m_cBSPDir.SetWindowText(str);
  241. }