summaryrefslogtreecommitdiff
path: root/hammer/runmapcfgdlg.cpp
blob: 70f940df345cb0c5ff3ff1fa5d0a733dcb4722df (plain) (blame)
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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//
//=============================================================================//
// RunMapCfgDlg.cpp : implementation file
//

#include "stdafx.h"
#include "hammer.h"
#include "RunMapCfgDlg.h"
#include "StrDlg.h"

// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>

/////////////////////////////////////////////////////////////////////////////
// CRunMapCfgDlg dialog


CRunMapCfgDlg::CRunMapCfgDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CRunMapCfgDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CRunMapCfgDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT

	m_pApp = (CHammer*) AfxGetApp();
}


void CRunMapCfgDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CRunMapCfgDlg)
	DDX_Control(pDX, IDC_CONFIGURATIONS, m_cConfigurations);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CRunMapCfgDlg, CDialog)
	//{{AFX_MSG_MAP(CRunMapCfgDlg)
	ON_BN_CLICKED(IDC_NEW, OnNew)
	ON_BN_CLICKED(IDC_REMOVE, OnRemove)
	ON_BN_CLICKED(IDC_RENAME, OnRename)
	ON_BN_CLICKED(IDC_COPY, OnCopy)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRunMapCfgDlg message handlers

void CRunMapCfgDlg::AddSequenceToList(int iIndex, CCommandSequence *pSeq)
{
	iIndex = m_cConfigurations.InsertString(iIndex, pSeq->m_szName);
	m_cConfigurations.SetItemDataPtr(iIndex, PVOID(pSeq));
	m_cConfigurations.SetCurSel(iIndex);
}

void CRunMapCfgDlg::OnNew() 
{
	// add a new sequence
	CStrDlg dlg(0, "", "Name:", "New Configuration");
	if(dlg.DoModal() == IDCANCEL)
		return;

	// add it to the list in the app
	CCommandSequence *pSeq = new CCommandSequence;
	strcpy(pSeq->m_szName, dlg.m_string);
	m_pApp->m_CmdSequences.Add(pSeq);

	AddSequenceToList(-1, pSeq);
}

void CRunMapCfgDlg::OnRemove() 
{
	int iSel = m_cConfigurations.GetCurSel();
	if(iSel == LB_ERR)
		return;	// nothing selected
	if(AfxMessageBox("Do you want to remove this configuration?",
		MB_YESNO) == IDNO)
		return;	// don't want to
	CCommandSequence *pSeq = (CCommandSequence*) 
		m_cConfigurations.GetItemDataPtr(iSel);

	// find it in the app's array
	for(int i = 0; i < m_pApp->m_CmdSequences.GetSize(); i++)
	{
		if(pSeq == m_pApp->m_CmdSequences[i])
		{
			delete pSeq;
			m_pApp->m_CmdSequences.RemoveAt(i);
			m_cConfigurations.DeleteString(iSel);
			return;	// done
		}
	}

	// shouldn't reach here -
	Assert(0);
}

void CRunMapCfgDlg::OnRename() 
{
	int iSel = m_cConfigurations.GetCurSel();
	if(iSel == LB_ERR)
		return;	// nothing selected
	CCommandSequence *pSeq = (CCommandSequence*) 
		m_cConfigurations.GetItemDataPtr(iSel);

	CStrDlg dlg(0, pSeq->m_szName, "Name:", "Rename Configuration");
	if(dlg.DoModal() == IDCANCEL)
		return;

	strcpy(pSeq->m_szName, dlg.m_string);

	m_cConfigurations.DeleteString(iSel);
	AddSequenceToList(iSel, pSeq);
}

BOOL CRunMapCfgDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();

	// add the configurations into the list
	int iSize = m_pApp->m_CmdSequences.GetSize();
	for(int i = 0; i < iSize; i++)
	{
		CCommandSequence *pSeq = m_pApp->m_CmdSequences[i];
		int iIndex = m_cConfigurations.AddString(pSeq->m_szName);
		m_cConfigurations.SetItemDataPtr(iIndex, PVOID(pSeq));
	}

	return TRUE;
}

void CRunMapCfgDlg::OnCopy() 
{
	int iSel = m_cConfigurations.GetCurSel();
	if(iSel == LB_ERR)
		return;	// nothing selected

	// add a new sequence
	CStrDlg dlg(0, "", "Name:", "Copy Configuration");
	if(dlg.DoModal() == IDCANCEL)
		return;

	// add it to the list in the app
	CCommandSequence *pSeq = new CCommandSequence;
	strcpy(pSeq->m_szName, dlg.m_string);
	m_pApp->m_CmdSequences.Add(pSeq);

	CCommandSequence *pSrcSeq = (CCommandSequence*) 
		m_cConfigurations.GetItemDataPtr(iSel);

	pSeq->m_Commands.Append(pSrcSeq->m_Commands);

	AddSequenceToList(-1, pSeq);
}