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