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.

217 lines
4.9 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. // EditGameConfigs.cpp : implementation file
  9. //
  10. #include "stdafx.h"
  11. #include "hammer.h"
  12. #include "EditGameConfigs.h"
  13. #include "StrDlg.h"
  14. #include "MapDoc.h"
  15. // memdbgon must be the last include file in a .cpp file!!!
  16. #include <tier0/memdbgon.h>
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CEditGameConfigs dialog
  19. CEditGameConfigs::CEditGameConfigs(BOOL bSelectOnly,
  20. CWnd* pParent /*=NULL*/)
  21. : CDialog(CEditGameConfigs::IDD, pParent)
  22. {
  23. //{{AFX_DATA_INIT(CEditGameConfigs)
  24. // NOTE: the ClassWizard will add member initialization here
  25. //}}AFX_DATA_INIT
  26. m_bSelectOnly = bSelectOnly;
  27. }
  28. void CEditGameConfigs::DoDataExchange(CDataExchange* pDX)
  29. {
  30. CDialog::DoDataExchange(pDX);
  31. //{{AFX_DATA_MAP(CEditGameConfigs)
  32. DDX_Control(pDX, IDC_CONFIGS, m_cConfigs);
  33. //}}AFX_DATA_MAP
  34. }
  35. BEGIN_MESSAGE_MAP(CEditGameConfigs, CDialog)
  36. //{{AFX_MSG_MAP(CEditGameConfigs)
  37. ON_BN_CLICKED(IDC_ADD, OnAdd)
  38. ON_BN_CLICKED(IDC_COPY, OnCopy)
  39. ON_BN_CLICKED(IDC_REMOVE, OnRemove)
  40. ON_LBN_SELCHANGE(IDC_CONFIGS, OnSelchangeConfigs)
  41. ON_LBN_DBLCLK(IDC_CONFIGS, OnDblclkConfigs)
  42. //}}AFX_MSG_MAP
  43. END_MESSAGE_MAP()
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CEditGameConfigs message handlers
  46. void CEditGameConfigs::OnAdd()
  47. {
  48. char szName[128];
  49. szName[0] = 0;
  50. CStrDlg dlg(0, szName, "Enter the game's name:", "Add a game");
  51. if(dlg.DoModal() != IDOK)
  52. return;
  53. // add a new game config
  54. CGameConfig *pConfig = Options.configs.AddConfig();
  55. strcpy(pConfig->szName, dlg.m_string);
  56. FillConfigList(pConfig->dwID);
  57. }
  58. void CEditGameConfigs::OnCopy()
  59. {
  60. int iCurSel = m_cConfigs.GetCurSel();
  61. if(iCurSel == CB_ERR)
  62. return;
  63. CGameConfig *pConfig = Options.configs.FindConfig(
  64. m_cConfigs.GetItemData(iCurSel));
  65. CGameConfig *pNewConfig = Options.configs.AddConfig();
  66. pNewConfig->CopyFrom(pConfig);
  67. FillConfigList(pNewConfig->dwID);
  68. }
  69. void CEditGameConfigs::OnRemove()
  70. {
  71. int iCurSel = m_cConfigs.GetCurSel();
  72. if(iCurSel == CB_ERR)
  73. return;
  74. int iArrayIndex;
  75. CGameConfig *pConfig = Options.configs.FindConfig(
  76. m_cConfigs.GetItemData(iCurSel), &iArrayIndex);
  77. // check to see if any docs use this game - if so, can't
  78. // delete it.
  79. for ( int i=0; i<CMapDoc::GetDocumentCount(); i++ )
  80. {
  81. CMapDoc *pDoc = CMapDoc::GetDocument(i);
  82. if(pDoc->GetGame() == pConfig)
  83. {
  84. AfxMessageBox("You can't delete this game configuration now\n"
  85. "because some loaded documents are using it.\n"
  86. "If you want to delete it, you must close those\n"
  87. "documents first.");
  88. return;
  89. }
  90. }
  91. bool bResetDefaults = false;
  92. // Check to see if this is the last configuation and prompt for the user to make a decision
  93. if ( Options.configs.nConfigs <= 1 )
  94. {
  95. if ( AfxMessageBox( "At least one configuration must be present!\n"
  96. "Would you like to reset to the default configurations?", MB_YESNO ) == IDNO )
  97. {
  98. return;
  99. }
  100. bResetDefaults = true;
  101. }
  102. // Remove selection
  103. m_cConfigs.DeleteString( iCurSel );
  104. // FIXME: This will apply the change even if you cancel the dialog. This needs to store a copy
  105. // of the data which then reconciles the two versions on OK or Apply! -- jdw
  106. Options.configs.Configs.RemoveAt(iArrayIndex);
  107. Options.configs.nConfigs--;
  108. // Reset to defaults
  109. if ( bResetDefaults )
  110. {
  111. Options.configs.ResetGameConfigs( false );
  112. FillConfigList();
  113. }
  114. // Put the selection back to the top
  115. m_cConfigs.SetCurSel( 0 );
  116. }
  117. void CEditGameConfigs::FillConfigList(DWORD dwSelectID)
  118. {
  119. // get current selection so we can keep it
  120. DWORD dwCurID = dwSelectID;
  121. int iNewIndex = -1;
  122. if(m_cConfigs.GetCurSel() != LB_ERR && dwCurID == 0xFFFFFFFF)
  123. {
  124. dwCurID = m_cConfigs.GetItemData(m_cConfigs.GetCurSel());
  125. }
  126. m_cConfigs.ResetContent();
  127. for(int i = 0; i < Options.configs.nConfigs; i++)
  128. {
  129. CGameConfig *pConfig = Options.configs.Configs[i];
  130. int iIndex = m_cConfigs.AddString(pConfig->szName);
  131. m_cConfigs.SetItemData(iIndex, pConfig->dwID);
  132. if (dwCurID == pConfig->dwID)
  133. {
  134. iNewIndex = iIndex;
  135. }
  136. }
  137. if (iNewIndex == -1)
  138. {
  139. iNewIndex = 0;
  140. }
  141. m_cConfigs.SetCurSel(iNewIndex);
  142. OnSelchangeConfigs();
  143. if (m_bSelectOnly && Options.configs.nConfigs == 1)
  144. OnOK();
  145. }
  146. void CEditGameConfigs::OnSelchangeConfigs()
  147. {
  148. int iCurSel = m_cConfigs.GetCurSel();
  149. if(iCurSel == LB_ERR)
  150. return;
  151. m_pSelectedGame = Options.configs.FindConfig(
  152. m_cConfigs.GetItemData(iCurSel));
  153. }
  154. BOOL CEditGameConfigs::OnInitDialog()
  155. {
  156. CDialog::OnInitDialog();
  157. if(m_bSelectOnly)
  158. {
  159. SetWindowText("Select a game configuration to use");
  160. GetDlgItem(IDOK)->SetWindowText("OK");
  161. GetDlgItem(IDC_REMOVE)->ShowWindow(SW_HIDE);
  162. GetDlgItem(IDC_ADD)->ShowWindow(SW_HIDE);
  163. GetDlgItem(IDC_COPY)->ShowWindow(SW_HIDE);
  164. }
  165. FillConfigList();
  166. return TRUE;
  167. }
  168. void CEditGameConfigs::OnDblclkConfigs()
  169. {
  170. OnOK();
  171. }