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.

172 lines
4.4 KiB

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