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.

171 lines
4.3 KiB

  1. // MapDiffDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "GlobalFunctions.h"
  5. #include "History.h"
  6. #include "MainFrm.h"
  7. #include "MapDiffDlg.h"
  8. #include "MapDoc.h"
  9. #include "MapEntity.h"
  10. #include "MapSolid.h"
  11. #include "MapView2D.h"
  12. #include "MapWorld.h"
  13. #include "ObjectProperties.h" // For ObjectProperties::RefreshData
  14. #include "Options.h"
  15. #include "ToolManager.h"
  16. #include "VisGroup.h"
  17. #include "hammer.h"
  18. #include "MapOverlay.h"
  19. #include "GameConfig.h"
  20. // memdbgon must be the last include file in a .cpp file!!!
  21. #include <tier0/memdbgon.h>
  22. #include ".\mapdiffdlg.h"
  23. CMapDiffDlg *s_pDlg = NULL;
  24. CMapDoc *s_pCurrentMap = NULL;
  25. // MapDiffDlg dialog
  26. CMapDiffDlg::CMapDiffDlg(CWnd* pParent )
  27. : CDialog(CMapDiffDlg::IDD, pParent)
  28. {
  29. m_bCheckSimilar = true;
  30. }
  31. void CMapDiffDlg::DoDataExchange(CDataExchange* pDX)
  32. {
  33. CDialog::DoDataExchange(pDX);
  34. DDX_Check(pDX, IDC_SIMILARCHECK, m_bCheckSimilar);
  35. DDX_Control(pDX, IDC_MAPNAME, m_mapName);
  36. }
  37. BEGIN_MESSAGE_MAP(CMapDiffDlg, CDialog)
  38. ON_BN_CLICKED(IDC_SIMILARCHECK, OnBnClickedSimilarcheck)
  39. ON_BN_CLICKED(IDC_MAPBROWSE, OnBnClickedMapbrowse)
  40. ON_BN_CLICKED(IDOK, OnBnClickedOk)
  41. ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
  42. ON_WM_DESTROY()
  43. END_MESSAGE_MAP()
  44. void CMapDiffDlg::MapDiff(CWnd *pwndParent, CMapDoc *pCurrentMapDoc)
  45. {
  46. if (!s_pDlg)
  47. {
  48. s_pDlg = new CMapDiffDlg;
  49. s_pDlg->Create(IDD, pwndParent);
  50. s_pDlg->ShowWindow(SW_SHOW);
  51. s_pCurrentMap = pCurrentMapDoc;
  52. }
  53. }
  54. // MapDiffDlg message handlers
  55. void CMapDiffDlg::OnBnClickedSimilarcheck()
  56. {
  57. // TODO: Add your control notification handler code here
  58. m_bCheckSimilar = !m_bCheckSimilar;
  59. }
  60. void CMapDiffDlg::OnBnClickedMapbrowse()
  61. {
  62. CString m_pszFilename;
  63. // TODO: Add your control notification handler code here
  64. static char szInitialDir[MAX_PATH] = "";
  65. if (szInitialDir[0] == '\0')
  66. {
  67. strcpy(szInitialDir, g_pGameConfig->szMapDir);
  68. }
  69. // TODO: need to prevent (or handle) opening VMF files when using old map file formats
  70. CFileDialog dlg(TRUE, NULL, NULL, OFN_LONGNAMES | OFN_HIDEREADONLY | OFN_NOCHANGEDIR, "Valve Map Files (*.vmf)|*.vmf|Valve Map Files Autosaves (*.vmf_autosave)|*.vmf_autosave|Worldcraft RMFs (*.rmf)|*.rmf|Worldcraft Maps (*.map)|*.map||");
  71. dlg.m_ofn.lpstrInitialDir = szInitialDir;
  72. int iRvl = dlg.DoModal();
  73. if (iRvl == IDCANCEL)
  74. {
  75. return;
  76. }
  77. //
  78. // Get the directory they browsed to for next time.
  79. //
  80. m_pszFilename = dlg.GetPathName();
  81. m_mapName.SetWindowText( m_pszFilename );
  82. }
  83. void CMapDiffDlg::OnBnClickedOk()
  84. {
  85. // TODO: Add your control notification handler code here
  86. OnOK();
  87. }
  88. //-----------------------------------------------------------------------------
  89. // Purpose:
  90. //-----------------------------------------------------------------------------
  91. void CMapDiffDlg::OnOK()
  92. {
  93. CString strFilename;
  94. m_mapName.GetWindowText( strFilename );
  95. CHammer *pApp = (CHammer*) AfxGetApp();
  96. CMapDoc *pDoc = (CMapDoc*) pApp->pMapDocTemplate->OpenDocumentFile( strFilename );
  97. CUtlVector <int> IDList;
  98. const CMapObjectList *pChildren = pDoc->GetMapWorld()->GetChildren();
  99. FOR_EACH_OBJ( *pChildren, pos )
  100. {
  101. int nID = pChildren->Element(pos)->GetID();
  102. IDList.AddToTail( nID );
  103. }
  104. pDoc->OnCloseDocument();
  105. CVisGroup *resultsVisGroup = NULL;
  106. pChildren = s_pCurrentMap->GetMapWorld()->GetChildren();
  107. int nTotalSimilarities = 0;
  108. if ( m_bCheckSimilar )
  109. {
  110. FOR_EACH_OBJ( *pChildren, pos )
  111. {
  112. CMapClass *pChild = (CUtlReference< CMapClass >)pChildren->Element(pos) ;
  113. int ID = pChild->GetID();
  114. if ( IDList.Find( ID ) != -1 )
  115. {
  116. if ( resultsVisGroup == NULL )
  117. {
  118. resultsVisGroup = s_pCurrentMap->VisGroups_AddGroup( "Similar" );
  119. nTotalSimilarities++;
  120. }
  121. pChild->AddVisGroup( resultsVisGroup );
  122. }
  123. }
  124. }
  125. if ( nTotalSimilarities > 0 )
  126. {
  127. GetMainWnd()->MessageBox( "Similarities were found and placed into the \"Similar\" visgroup.", "Map Similarities Found", MB_OK | MB_ICONEXCLAMATION);
  128. }
  129. s_pCurrentMap->VisGroups_UpdateAll();
  130. DestroyWindow();
  131. }
  132. //-----------------------------------------------------------------------------
  133. // Purpose: Called when our window is being destroyed.
  134. //-----------------------------------------------------------------------------
  135. void CMapDiffDlg::OnDestroy()
  136. {
  137. delete this;
  138. s_pDlg = NULL;
  139. s_pCurrentMap = NULL;
  140. }
  141. void CMapDiffDlg::OnBnClickedCancel()
  142. {
  143. // TODO: Add your control notification handler code here
  144. DestroyWindow();
  145. }