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.

160 lines
3.9 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. // RunMapCfgDlg.cpp : implementation file
  9. //
  10. #include "stdafx.h"
  11. #include "hammer.h"
  12. #include "RunMapCfgDlg.h"
  13. #include "StrDlg.h"
  14. // memdbgon must be the last include file in a .cpp file!!!
  15. #include <tier0/memdbgon.h>
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CRunMapCfgDlg dialog
  18. CRunMapCfgDlg::CRunMapCfgDlg(CWnd* pParent /*=NULL*/)
  19. : CDialog(CRunMapCfgDlg::IDD, pParent)
  20. {
  21. //{{AFX_DATA_INIT(CRunMapCfgDlg)
  22. // NOTE: the ClassWizard will add member initialization here
  23. //}}AFX_DATA_INIT
  24. m_pApp = (CHammer*) AfxGetApp();
  25. }
  26. void CRunMapCfgDlg::DoDataExchange(CDataExchange* pDX)
  27. {
  28. CDialog::DoDataExchange(pDX);
  29. //{{AFX_DATA_MAP(CRunMapCfgDlg)
  30. DDX_Control(pDX, IDC_CONFIGURATIONS, m_cConfigurations);
  31. //}}AFX_DATA_MAP
  32. }
  33. BEGIN_MESSAGE_MAP(CRunMapCfgDlg, CDialog)
  34. //{{AFX_MSG_MAP(CRunMapCfgDlg)
  35. ON_BN_CLICKED(IDC_NEW, OnNew)
  36. ON_BN_CLICKED(IDC_REMOVE, OnRemove)
  37. ON_BN_CLICKED(IDC_RENAME, OnRename)
  38. ON_BN_CLICKED(IDC_COPY, OnCopy)
  39. //}}AFX_MSG_MAP
  40. END_MESSAGE_MAP()
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CRunMapCfgDlg message handlers
  43. void CRunMapCfgDlg::AddSequenceToList(int iIndex, CCommandSequence *pSeq)
  44. {
  45. iIndex = m_cConfigurations.InsertString(iIndex, pSeq->m_szName);
  46. m_cConfigurations.SetItemDataPtr(iIndex, PVOID(pSeq));
  47. m_cConfigurations.SetCurSel(iIndex);
  48. }
  49. void CRunMapCfgDlg::OnNew()
  50. {
  51. // add a new sequence
  52. CStrDlg dlg(0, "", "Name:", "New Configuration");
  53. if(dlg.DoModal() == IDCANCEL)
  54. return;
  55. // add it to the list in the app
  56. CCommandSequence *pSeq = new CCommandSequence;
  57. strcpy(pSeq->m_szName, dlg.m_string);
  58. m_pApp->m_CmdSequences.Add(pSeq);
  59. AddSequenceToList(-1, pSeq);
  60. }
  61. void CRunMapCfgDlg::OnRemove()
  62. {
  63. int iSel = m_cConfigurations.GetCurSel();
  64. if(iSel == LB_ERR)
  65. return; // nothing selected
  66. if(AfxMessageBox("Do you want to remove this configuration?",
  67. MB_YESNO) == IDNO)
  68. return; // don't want to
  69. CCommandSequence *pSeq = (CCommandSequence*)
  70. m_cConfigurations.GetItemDataPtr(iSel);
  71. // find it in the app's array
  72. for(int i = 0; i < m_pApp->m_CmdSequences.GetSize(); i++)
  73. {
  74. if(pSeq == m_pApp->m_CmdSequences[i])
  75. {
  76. delete pSeq;
  77. m_pApp->m_CmdSequences.RemoveAt(i);
  78. m_cConfigurations.DeleteString(iSel);
  79. return; // done
  80. }
  81. }
  82. // shouldn't reach here -
  83. Assert(0);
  84. }
  85. void CRunMapCfgDlg::OnRename()
  86. {
  87. int iSel = m_cConfigurations.GetCurSel();
  88. if(iSel == LB_ERR)
  89. return; // nothing selected
  90. CCommandSequence *pSeq = (CCommandSequence*)
  91. m_cConfigurations.GetItemDataPtr(iSel);
  92. CStrDlg dlg(0, pSeq->m_szName, "Name:", "Rename Configuration");
  93. if(dlg.DoModal() == IDCANCEL)
  94. return;
  95. strcpy(pSeq->m_szName, dlg.m_string);
  96. m_cConfigurations.DeleteString(iSel);
  97. AddSequenceToList(iSel, pSeq);
  98. }
  99. BOOL CRunMapCfgDlg::OnInitDialog()
  100. {
  101. CDialog::OnInitDialog();
  102. // add the configurations into the list
  103. int iSize = m_pApp->m_CmdSequences.GetSize();
  104. for(int i = 0; i < iSize; i++)
  105. {
  106. CCommandSequence *pSeq = m_pApp->m_CmdSequences[i];
  107. int iIndex = m_cConfigurations.AddString(pSeq->m_szName);
  108. m_cConfigurations.SetItemDataPtr(iIndex, PVOID(pSeq));
  109. }
  110. return TRUE;
  111. }
  112. void CRunMapCfgDlg::OnCopy()
  113. {
  114. int iSel = m_cConfigurations.GetCurSel();
  115. if(iSel == LB_ERR)
  116. return; // nothing selected
  117. // add a new sequence
  118. CStrDlg dlg(0, "", "Name:", "Copy Configuration");
  119. if(dlg.DoModal() == IDCANCEL)
  120. return;
  121. // add it to the list in the app
  122. CCommandSequence *pSeq = new CCommandSequence;
  123. strcpy(pSeq->m_szName, dlg.m_string);
  124. m_pApp->m_CmdSequences.Add(pSeq);
  125. CCommandSequence *pSrcSeq = (CCommandSequence*)
  126. m_cConfigurations.GetItemDataPtr(iSel);
  127. pSeq->m_Commands.Append(pSrcSeq->m_Commands);
  128. AddSequenceToList(-1, pSeq);
  129. }