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.

317 lines
7.7 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Implements the groups page of the Object Properties dialog. This
  4. // allows the user to edit which visgroups the selected objects belong to.
  5. //
  6. //=============================================================================//
  7. #include "stdafx.h"
  8. #include "hammer.h"
  9. #include "MapWorld.h"
  10. #include "OP_Groups.h"
  11. #include "EditGroups.h"
  12. #include "GlobalFunctions.h"
  13. #include "CustomMessages.h"
  14. #include "ObjectProperties.h"
  15. #include "VisGroup.h"
  16. // memdbgon must be the last include file in a .cpp file!!!
  17. #include <tier0/memdbgon.h>
  18. const char *NO_GROUP_STRING = "(no group)";
  19. const DWORD NO_GROUP_ID = 0xffff;
  20. const DWORD VALUE_DIFFERENT_ID = 0xfffe;
  21. static const unsigned int g_uToggleStateMsg = ::RegisterWindowMessage(GROUPLIST_MSG_TOGGLE_STATE);
  22. BEGIN_MESSAGE_MAP(COP_Groups, CObjectPage)
  23. //{{AFX_MSG_MAP(COP_Groups)
  24. ON_BN_CLICKED(IDC_EDITGROUPS, OnEditgroups)
  25. ON_REGISTERED_MESSAGE(g_uToggleStateMsg, OnListToggleState)
  26. ON_WM_SIZE()
  27. //}}AFX_MSG_MAP
  28. ON_WM_SETFOCUS()
  29. END_MESSAGE_MAP()
  30. IMPLEMENT_DYNCREATE(COP_Groups, CObjectPage)
  31. //-----------------------------------------------------------------------------
  32. // Purpose:
  33. //-----------------------------------------------------------------------------
  34. COP_Groups::COP_Groups()
  35. : CObjectPage(COP_Groups::IDD)
  36. {
  37. //{{AFX_DATA_INIT(COP_Groups)
  38. //}}AFX_DATA_INIT
  39. m_pEditObjectRuntimeClass = RUNTIME_CLASS(editCMapClass);
  40. }
  41. //-----------------------------------------------------------------------------
  42. // Purpose:
  43. //-----------------------------------------------------------------------------
  44. COP_Groups::~COP_Groups()
  45. {
  46. }
  47. //-----------------------------------------------------------------------------
  48. // Purpose:
  49. // Input : pDX -
  50. //-----------------------------------------------------------------------------
  51. void COP_Groups::DoDataExchange(CDataExchange* pDX)
  52. {
  53. CObjectPage::DoDataExchange(pDX);
  54. //{{AFX_DATA_MAP(COP_Model)
  55. DDX_Control(pDX, IDC_EDITGROUPS, m_EditGroupsControl);
  56. //}}AFX_DATA_MAP
  57. }
  58. //-----------------------------------------------------------------------------
  59. // Purpose:
  60. // Input : b -
  61. //-----------------------------------------------------------------------------
  62. void COP_Groups::SetMultiEdit(bool b)
  63. {
  64. CObjectPage::SetMultiEdit(b);
  65. }
  66. //-----------------------------------------------------------------------------
  67. // Purpose:
  68. // Output : Returns true on success, false on failure.
  69. //-----------------------------------------------------------------------------
  70. bool COP_Groups::SaveData( SaveData_Reason_t reason )
  71. {
  72. if (!IsWindow(m_hWnd))
  73. {
  74. return false;
  75. }
  76. int nCount = m_cGroups.GetVisGroupCount();
  77. for (int i = 0; i < nCount; i++)
  78. {
  79. CVisGroup *pVisGroup = m_cGroups.GetVisGroup(i);
  80. // Don't let users edit Auto VisGroup membership!
  81. if ( pVisGroup->IsAutoVisGroup() )
  82. continue;
  83. int nCheck = m_cGroups.GetCheck(pVisGroup);
  84. if (nCheck != -1)
  85. {
  86. FOR_EACH_OBJ( *m_pObjectList, pos )
  87. {
  88. CMapClass *pObject = (CUtlReference< CMapClass >)m_pObjectList->Element(pos);
  89. if (nCheck)
  90. {
  91. pObject->AddVisGroup(pVisGroup);
  92. }
  93. else
  94. {
  95. pObject->RemoveVisGroup(pVisGroup);
  96. }
  97. }
  98. }
  99. }
  100. return true;
  101. }
  102. //-----------------------------------------------------------------------------
  103. // Purpose:
  104. // Input : Mode -
  105. // pData -
  106. //-----------------------------------------------------------------------------
  107. void COP_Groups::UpdateData( int Mode, void *pData, bool bCanEdit )
  108. {
  109. __super::UpdateData( Mode, pData, bCanEdit );
  110. if ( !IsWindow(m_hWnd) )
  111. {
  112. return;
  113. }
  114. static int s_checkState[128];
  115. if (Mode == LoadData || Mode == LoadFirstData)
  116. {
  117. CMapClass *pObject = (CMapClass *)pData;
  118. if (Mode == LoadFirstData)
  119. {
  120. UpdateGroupList();
  121. //
  122. // Loading the first object. check each group this object is in.
  123. //
  124. int nCount = m_cGroups.GetVisGroupCount();
  125. for (int i = 0; i < nCount; i++)
  126. {
  127. CVisGroup *pVisGroup = m_cGroups.GetVisGroup(i);
  128. s_checkState[i] = pObject->IsInVisGroup(pVisGroup);
  129. }
  130. }
  131. else
  132. {
  133. //
  134. // Loading subsequent objects.
  135. //
  136. int nCount = m_cGroups.GetVisGroupCount();
  137. for (int i = 0; i < nCount; i++)
  138. {
  139. if ( s_checkState[i] != -1)
  140. {
  141. CVisGroup *pVisGroup = m_cGroups.GetVisGroup(i);
  142. if ( pObject->IsInVisGroup(pVisGroup) != s_checkState[i] )
  143. {
  144. s_checkState[i] = -1;
  145. }
  146. }
  147. }
  148. }
  149. }
  150. else if ( Mode == LoadFinished )
  151. {
  152. int nCount = m_cGroups.GetVisGroupCount();
  153. for (int i = 0; i < nCount; i++)
  154. {
  155. CVisGroup *pVisGroup = m_cGroups.GetVisGroup(i);
  156. m_cGroups.SetCheck(pVisGroup, s_checkState[i]);
  157. }
  158. }
  159. m_cGroups.EnableWindow( ( m_bCanEdit ? TRUE : FALSE ) );
  160. m_EditGroupsControl.EnableWindow( ( m_bCanEdit ? TRUE : FALSE ) );
  161. }
  162. //-----------------------------------------------------------------------------
  163. // Purpose:
  164. //-----------------------------------------------------------------------------
  165. void COP_Groups::UpdateGroupList(void)
  166. {
  167. if (!IsWindow(m_hWnd))
  168. {
  169. return;
  170. }
  171. m_cGroups.SetRedraw(false);
  172. m_cGroups.DeleteAllItems();
  173. CVisGroup *pAuto = NULL;
  174. CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
  175. if (pDoc != NULL)
  176. {
  177. int nCount = pDoc->VisGroups_GetRootCount();
  178. for (int i = 0; i < nCount; i++)
  179. {
  180. CVisGroup *pGroup = pDoc->VisGroups_GetRootVisGroup(i);
  181. if (stricmp(pGroup->GetName(), "Auto") != 0)
  182. {
  183. m_cGroups.AddVisGroup(pGroup);
  184. }
  185. else
  186. {
  187. pAuto = pGroup;
  188. }
  189. }
  190. // We can't reassign membership to auto visgroups, and rarely need to check membership,
  191. // so add the "Auto" visgroup last so that it doesn't get in the way.
  192. if (pAuto)
  193. {
  194. m_cGroups.AddVisGroup(pAuto);
  195. }
  196. }
  197. m_cGroups.ExpandAll();
  198. // If this ever gets slow we could pass a param into ExpandAll to not expand "Auto"
  199. if (pAuto)
  200. {
  201. m_cGroups.CollapseItem(pAuto);
  202. }
  203. m_cGroups.SetRedraw(true);
  204. m_cGroups.Invalidate();
  205. }
  206. //-----------------------------------------------------------------------------
  207. // Purpose:
  208. //-----------------------------------------------------------------------------
  209. void COP_Groups::OnEditgroups()
  210. {
  211. CEditGroups dlg;
  212. dlg.DoModal();
  213. UpdateGroupList();
  214. // dvs: TODO: update the check state for all groups
  215. }
  216. //-----------------------------------------------------------------------------
  217. // Purpose:
  218. //-----------------------------------------------------------------------------
  219. BOOL COP_Groups::OnInitDialog()
  220. {
  221. CObjectPage::OnInitDialog();
  222. m_cGroups.SubclassDlgItem(IDC_GROUPS, this);
  223. m_cGroups.EnableChecks();
  224. CAnchorDef anchorDefs[] =
  225. {
  226. CAnchorDef( IDC_GROUPS, k_eSimpleAnchorAllSides ),
  227. CAnchorDef( IDC_EDITGROUPS, k_eSimpleAnchorBottomRight )
  228. };
  229. m_AnchorMgr.Init( GetSafeHwnd(), anchorDefs, ARRAYSIZE( anchorDefs ) );
  230. return TRUE;
  231. }
  232. //-----------------------------------------------------------------------------
  233. // Purpose: Called when the check state of a group is toggled in the groups list.
  234. // Input : wParam - Index of item in the groups list that was toggled.
  235. // lParam - New check state.
  236. // Output : Returns zero.
  237. //-----------------------------------------------------------------------------
  238. LRESULT COP_Groups::OnListToggleState(WPARAM wParam, LPARAM lParam)
  239. {
  240. CVisGroup *pVisGroup = (CVisGroup *)wParam;
  241. // Don't let users edit Auto VisGroup membership!
  242. if ( pVisGroup->IsAutoVisGroup() )
  243. return 0;
  244. m_cGroups.SetCheck(pVisGroup, (int)lParam);
  245. return 0;
  246. }
  247. //-----------------------------------------------------------------------------
  248. // Purpose:
  249. // Input : *pOld -
  250. //-----------------------------------------------------------------------------
  251. void COP_Groups::OnSetFocus(CWnd *pOld)
  252. {
  253. // fixme:
  254. //UpdateGrouplist();
  255. CPropertyPage::OnSetFocus(pOld);
  256. }
  257. void COP_Groups::OnSize( UINT nType, int cx, int cy )
  258. {
  259. m_AnchorMgr.OnSize();
  260. }