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.

173 lines
5.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: A dialog that is invoked when a new visgroup is created.
  4. // It lets the user pick an existing visgroup or create a new one.
  5. //
  6. //=============================================================================//
  7. #include "stdafx.h"
  8. #include "MapDoc.h"
  9. #include "NewVisGroupDlg.h"
  10. #include "hammer.h"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include <tier0/memdbgon.h>
  13. static const unsigned int g_uSelChangeMsg = ::RegisterWindowMessage(GROUPLIST_MSG_SEL_CHANGE);
  14. static BOOL s_bLastHideObjects = TRUE;
  15. BEGIN_MESSAGE_MAP(CNewVisGroupDlg, CDialog)
  16. //{{AFX_MSG_MAP(CNewVisGroupDlg)
  17. ON_REGISTERED_MESSAGE(g_uSelChangeMsg, OnSelChangeGroupList)
  18. ON_COMMAND(IDC_PLACE_IN_EXISTING_VISGROUP, OnPlaceInExistingVisGroup)
  19. ON_COMMAND(IDC_CREATE_NEW_VISGROUP, OnCreateNewVisGroup)
  20. //}}AFX_MSG_MAP
  21. END_MESSAGE_MAP()
  22. //-----------------------------------------------------------------------------
  23. // Purpose:
  24. // Input : pParent -
  25. //-----------------------------------------------------------------------------
  26. CNewVisGroupDlg::CNewVisGroupDlg(CString &str, CWnd *pParent)
  27. : CDialog(CNewVisGroupDlg::IDD, pParent)
  28. {
  29. m_pPickedVisGroup = NULL;
  30. //{{AFX_DATA_INIT(CNewVisGroupDlg)
  31. m_strName = str;
  32. //}}AFX_DATA_INIT
  33. }
  34. //-----------------------------------------------------------------------------
  35. // Purpose:
  36. // Input : pDX -
  37. //-----------------------------------------------------------------------------
  38. void CNewVisGroupDlg::DoDataExchange(CDataExchange* pDX)
  39. {
  40. CDialog::DoDataExchange(pDX);
  41. //{{AFX_DATA_MAP(CNewVisGroupDlg)
  42. DDX_Check(pDX, IDC_REMOVE_FROM_ALL, m_bRemoveFromOtherGroups);
  43. DDX_Check(pDX, IDC_HIDE_OBJECTS, m_bHideObjects);
  44. DDX_Text(pDX, IDC_VISGROUP_NAME, m_strName);
  45. //}}AFX_DATA_MAP
  46. }
  47. //-----------------------------------------------------------------------------
  48. // Purpose:
  49. //-----------------------------------------------------------------------------
  50. BOOL CNewVisGroupDlg::OnInitDialog(void)
  51. {
  52. m_bHideObjects = s_bLastHideObjects;
  53. CDialog::OnInitDialog();
  54. CButton *pButton = (CButton *)GetDlgItem(IDC_CREATE_NEW_VISGROUP);
  55. pButton->SetCheck(1);
  56. m_cGroupList.SubclassDlgItem(IDC_GROUP_LIST, this);
  57. UpdateGroupList();
  58. CEdit *pEdit = (CEdit *)GetDlgItem(IDC_GROUP_LIST);
  59. pEdit->EnableWindow(FALSE);
  60. return TRUE;
  61. }
  62. //-----------------------------------------------------------------------------
  63. // Purpose: Returns the visgroup name that was entered in the dialog.
  64. //-----------------------------------------------------------------------------
  65. void CNewVisGroupDlg::GetName(CString &str)
  66. {
  67. str = m_strName;
  68. }
  69. //-----------------------------------------------------------------------------
  70. // Purpose:
  71. //-----------------------------------------------------------------------------
  72. void CNewVisGroupDlg::OnOK()
  73. {
  74. CDialog::OnOK();
  75. s_bLastHideObjects = m_bHideObjects;
  76. }
  77. //-----------------------------------------------------------------------------
  78. // Purpose: Switches the mode of the dialog to pick an existing visgroup rather than
  79. // create a new one.
  80. //-----------------------------------------------------------------------------
  81. void CNewVisGroupDlg::OnPlaceInExistingVisGroup()
  82. {
  83. CEdit *pEdit = (CEdit *)GetDlgItem(IDC_VISGROUP_NAME);
  84. pEdit->EnableWindow(FALSE);
  85. pEdit = (CEdit *)GetDlgItem(IDC_GROUP_LIST);
  86. pEdit->EnableWindow(TRUE);
  87. }
  88. //-----------------------------------------------------------------------------
  89. // Purpose: Switches the mode of the dialog to create a new visgroup rather than
  90. // pick an existing one.
  91. //-----------------------------------------------------------------------------
  92. void CNewVisGroupDlg::OnCreateNewVisGroup()
  93. {
  94. CEdit *pEdit = (CEdit *)GetDlgItem(IDC_VISGROUP_NAME);
  95. pEdit->EnableWindow(TRUE);
  96. pEdit = (CEdit *)GetDlgItem(IDC_GROUP_LIST);
  97. pEdit->EnableWindow(FALSE);
  98. m_pPickedVisGroup = NULL;
  99. }
  100. //-----------------------------------------------------------------------------
  101. // Purpose: Handles selection change in the visgroup list.
  102. //-----------------------------------------------------------------------------
  103. LRESULT CNewVisGroupDlg::OnSelChangeGroupList(WPARAM wParam, LPARAM lParam)
  104. {
  105. m_pPickedVisGroup = m_cGroupList.GetSelectedVisGroup();
  106. return 0;
  107. }
  108. //-----------------------------------------------------------------------------
  109. // Purpose:
  110. //-----------------------------------------------------------------------------
  111. void CNewVisGroupDlg::UpdateGroupList(void)
  112. {
  113. m_cGroupList.SetRedraw(false);
  114. m_cGroupList.DeleteAllItems();
  115. CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
  116. if (pDoc != NULL)
  117. {
  118. int nCount = pDoc->VisGroups_GetRootCount();
  119. for (int i = 0; i < nCount; i++)
  120. {
  121. CVisGroup *pGroup = pDoc->VisGroups_GetRootVisGroup(i);
  122. m_cGroupList.AddVisGroup(pGroup);
  123. }
  124. }
  125. m_cGroupList.ExpandAll();
  126. m_cGroupList.SetRedraw(true);
  127. m_cGroupList.Invalidate();
  128. }
  129. //-----------------------------------------------------------------------------
  130. // Purpose:
  131. //-----------------------------------------------------------------------------
  132. CVisGroup *CNewVisGroupDlg::GetPickedVisGroup(void)
  133. {
  134. return m_pPickedVisGroup;
  135. }