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.

297 lines
7.2 KiB

  1. //========= Copyright 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(void)
  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 = 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. CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
  174. if (pDoc != NULL)
  175. {
  176. int nCount = pDoc->VisGroups_GetCount();
  177. for (int i = 0; i < nCount; i++)
  178. {
  179. CVisGroup *pGroup = pDoc->VisGroups_GetVisGroup(i);
  180. if (!pGroup->GetParent())
  181. {
  182. m_cGroups.AddVisGroup(pGroup);
  183. }
  184. }
  185. }
  186. m_cGroups.ExpandAll();
  187. m_cGroups.SetRedraw(true);
  188. m_cGroups.Invalidate();
  189. }
  190. //-----------------------------------------------------------------------------
  191. // Purpose:
  192. //-----------------------------------------------------------------------------
  193. void COP_Groups::OnEditgroups()
  194. {
  195. CEditGroups dlg;
  196. dlg.DoModal();
  197. UpdateGroupList();
  198. // dvs: TODO: update the check state for all groups
  199. }
  200. //-----------------------------------------------------------------------------
  201. // Purpose:
  202. //-----------------------------------------------------------------------------
  203. BOOL COP_Groups::OnInitDialog()
  204. {
  205. CObjectPage::OnInitDialog();
  206. m_cGroups.SubclassDlgItem(IDC_GROUPS, this);
  207. m_cGroups.EnableChecks();
  208. CAnchorDef anchorDefs[] =
  209. {
  210. CAnchorDef( IDC_GROUPS, k_eSimpleAnchorAllSides ),
  211. CAnchorDef( IDC_EDITGROUPS, k_eSimpleAnchorBottomRight )
  212. };
  213. m_AnchorMgr.Init( GetSafeHwnd(), anchorDefs, ARRAYSIZE( anchorDefs ) );
  214. return TRUE;
  215. }
  216. //-----------------------------------------------------------------------------
  217. // Purpose: Called when the check state of a group is toggled in the groups list.
  218. // Input : wParam - Index of item in the groups list that was toggled.
  219. // lParam - New check state.
  220. // Output : Returns zero.
  221. //-----------------------------------------------------------------------------
  222. LRESULT COP_Groups::OnListToggleState(WPARAM wParam, LPARAM lParam)
  223. {
  224. CVisGroup *pVisGroup = (CVisGroup *)wParam;
  225. // Don't let users edit Auto VisGroup membership!
  226. if ( pVisGroup->IsAutoVisGroup() )
  227. return 0;
  228. m_cGroups.SetCheck(pVisGroup, (int)lParam);
  229. return 0;
  230. }
  231. //-----------------------------------------------------------------------------
  232. // Purpose:
  233. // Input : *pOld -
  234. //-----------------------------------------------------------------------------
  235. void COP_Groups::OnSetFocus(CWnd *pOld)
  236. {
  237. // fixme:
  238. //UpdateGrouplist();
  239. CPropertyPage::OnSetFocus(pOld);
  240. }
  241. void COP_Groups::OnSize( UINT nType, int cx, int cy )
  242. {
  243. m_AnchorMgr.OnSize();
  244. }