Debian Codegraph @

editor/TableFileFilter.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/editor/TableFileFilter.cpp $
21 * $Revision: 1.1.1.1 $
22 * $Date: 2003-08-26 03:57:39 $
23 * $Author: kevinb $
24 *
25 *
26 *
27 * $Log: not supported by cvs2svn $
28 *
29 * 8 2/09/99 4:19p Nate
30 * Added to the TableFileFilter interface
31 *
32 * 7 10/09/98 3:16a Jason
33 * more changes for demo
34 *
35 * 6 10/08/98 10:48p Nate
36 *
37 * 5 10/08/98 10:30a Nate
38 * Initial version
39 *
40 * $NoKeywords: $
41 */
42
43 // TableFileFilter.cpp : implementation file
44 //
45
46 #include "stdafx.h"
47 #include "editor.h"
48 #include "TableFileFilter.h"
49 #include "TableFileFilterMng.h"
50 #include "TableFileFilterAddDlg.h"
51
52 #ifdef _DEBUG
53 #define new DEBUG_NEW
54 #undef THIS_FILE
55 static char THIS_FILE[] = __FILE__;
56 #endif
57
58 /////////////////////////////////////////////////////////////////////////////
59 // CTableFileFilter dialog
60
61 TableFileFilter::TableFileFilter(CWnd *pParent /*=NULL*/) : CDialog(TableFileFilter::IDD, pParent) {
62 //{{AFX_DATA_INIT(TableFileFilter)
63 m_NumPagesText = _T("");
64 m_StatusText = _T("");
65 //}}AFX_DATA_INIT
66 }
67
68 void TableFileFilter::DoDataExchange(CDataExchange *pDX) {
69 CDialog::DoDataExchange(pDX);
70 //{{AFX_DATA_MAP(TableFileFilter)
71 DDX_Control(pDX, IDC_OUTPUTFILE_EDIT, m_OutputFileEdit);
72 DDX_Control(pDX, IDC_TABLEFILTER_LEVEL_LIST, m_LevelList);
73 DDX_Control(pDX, IDC_TABLEFILTER_DATA_LIST, m_DataList);
74 DDX_Text(pDX, IDC_TABLEFILTER_NUMPAGESTEXT, m_NumPagesText);
75 DDX_Text(pDX, IDC_TABLEFILTER_STATUSTEXT, m_StatusText);
76 //}}AFX_DATA_MAP
77 }
78
79 BEGIN_MESSAGE_MAP(TableFileFilter, CDialog)
80 //{{AFX_MSG_MAP(TableFileFilter)
81 ON_COMMAND(ID_TABLEFILTER_FILE_EXIT, OnFileExit)
82 ON_COMMAND(ID_TABLEFILTER_FILE_SAVE, OnFileSave)
83 ON_COMMAND(ID_TABLEFILTER_FILE_SAVEAS, OnFileSaveAs)
84 ON_COMMAND(ID_TABLEFILTER_FILE_LOAD, OnFileLoad)
85 ON_WM_CLOSE()
86 ON_BN_CLICKED(IDC_TABLEFILTER_BTN_ADDLEVEL, OnBtnAddLevel)
87 ON_BN_CLICKED(IDC_TABLEFILTER_BTN_ADDPAGE, OnBtnAddPage)
88 ON_BN_CLICKED(IDC_TABLEFILTER_BTN_CREATENEWTABLEFILE, OnBtnCreateNewTableFile)
89 ON_BN_CLICKED(IDC_TABLEFILTER_BTN_REMOVELEVEL, OnBtnRemoveLevel)
90 ON_BN_CLICKED(IDC_TABLEFILTER_BTN_REMOVEPAGE, OnBtnRemovePage)
91 ON_COMMAND(ID_TABLEFILTER_FILE_NEW, OnFileNew)
92 //}}AFX_MSG_MAP
93 END_MESSAGE_MAP()
94
95 /////////////////////////////////////////////////////////////////////////////
96 // TableFileFilter message handlers
97 void TableFileFilter::OnClose() {
98 // TODO: Add your message handler code here and/or call default
99 if (m_PageList.ModifiedPrompt() == IDYES)
100 CDialog::OnClose();
101 }
102
103 BOOL TableFileFilter::OnInitDialog() {
104 CDialog::OnInitDialog();
105
106 // TODO: Add extra initialization here
107
108 // Setup the data list columns
109 CString column_name;
110 column_name = "Page Name";
111 m_DataList.InsertColumn(PAGE_NAME_COLUMN, column_name.GetBuffer(0), LVCFMT_LEFT, -1, PAGE_NAME_COLUMN);
112 column_name = "Page Type";
113 m_DataList.InsertColumn(PAGE_TYPE_COLUMN, column_name.GetBuffer(0), LVCFMT_LEFT, -1, PAGE_TYPE_COLUMN);
114 SetColumnWidths();
115
116 // Set the default file path for the edit box
117 char *d3dir = getenv("D3_LOCAL");
118 char LocalD3Dir[_MAX_PATH];
119
120 strcpy(LocalD3Dir, d3dir);
121
122 if (d3dir[strlen(d3dir) - 1] != '\\') {
123 strcat(LocalD3Dir, "\\");
124 }
125 strcat(LocalD3Dir, DEFAULT_TABLEPARSE_FNAME);
126
127 m_OutputFileEdit.SetWindowText(LocalD3Dir);
128
129 // Link the page data control to the data list
130 m_PageList.BindDlg(this);
131 m_PageList.BindOutputFileEdit(&m_OutputFileEdit);
132 m_PageList.BindPageDataListCtrl(&m_DataList);
133 m_PageList.BindLevelListBox(&m_LevelList);
134 m_PageList.BindNumPagesText(&m_NumPagesText);
135 m_PageList.BindStatusText(&m_StatusText);
136
137 // Wipe out the list
138 OnFileNew();
139
140 return TRUE; // return TRUE unless you set the focus to a control
141 // EXCEPTION: OCX Property Pages should return FALSE
142 }
143
144 // Calculates column widths and sets them
145 void TableFileFilter::SetColumnWidths(void) {
146 uint32_t w0, w1;
147
148 RECT rect;
149 m_DataList.GetClientRect(&rect);
150
151 w0 = uint32_t(rect.right * PAGE_NAME_COLUMN_WIDTH);
152 w1 = uint32_t(rect.right * PAGE_TYPE_COLUMN_WIDTH);
153
154 m_DataList.SetColumnWidth(PAGE_NAME_COLUMN, w0);
155 m_DataList.SetColumnWidth(PAGE_TYPE_COLUMN, w1);
156 }
157
158 /////////////////////////////////////////////////////
159 // Menu Command Handlers
160 void TableFileFilter::OnFileExit() {
161 // TODO: Add your command handler code here
162 if (m_PageList.ModifiedPrompt() == IDYES)
163 EndDialog(0);
164 }
165
166 void TableFileFilter::OnFileNew() {
167 // TODO: Add your command handler code here
168 if (m_PageList.ModifiedPrompt() == IDNO)
169 return;
170
171 CWaitCursor wc;
172 m_PageList.ClearList();
173 // m_PageList.AddAllGamefilePages();
174 m_PageList.SetTitleString();
175 }
176
177 void TableFileFilter::OnFileSave() {
178 // TODO: Add your command handler code here
179 if (!m_PageList.FilenameSpecified()) {
180 OnFileSaveAs();
181 return;
182 }
183
184 CWaitCursor wc;
185 if (!m_PageList.SaveList(NULL)) {
186 MessageBox("The save was unsuccessfull", "Save Table Error!");
187 return;
188 }
189 m_PageList.SetTitleString();
190 }
191
192 void TableFileFilter::OnFileSaveAs() {
193 // TODO: Add your command handler code here
194 CString filters = "Page Data List File (*.pdl)|*.pdl|All Files (*.*)|*.*||";
195
196 CFileDialog dlg_open(FALSE, ".pdl", NULL, 0, (LPCTSTR)filters, this);
197 if (dlg_open.DoModal() == IDCANCEL) {
198 return;
199 }
200
201 CWaitCursor wc;
202 if (!m_PageList.SaveList(dlg_open.GetPathName().GetBuffer(0))) {
203 MessageBox("The save was unsuccessfull", "Save Data List Error!");
204 return;
205 }
206
207 m_PageList.SetTitleString();
208 }
209
210 void TableFileFilter::OnFileLoad() {
211 // TODO: Add your command handler code here
212 if (m_PageList.ModifiedPrompt() == IDNO)
213 return;
214
215 CString filters = "Page Data List File (*.pdl)|*.pdl|All Files (*.*)|*.*||";
216
217 CFileDialog dlg_open(TRUE, ".pdl", NULL, OFN_FILEMUSTEXIST, (LPCTSTR)filters, this);
218 if (dlg_open.DoModal() == IDCANCEL) {
219 return;
220 }
221
222 CWaitCursor wc;
223 if (!m_PageList.LoadList(dlg_open.GetPathName().GetBuffer(0))) {
224 MessageBox("The load was unsuccessfull", "Load Data List Error!");
225 m_PageList.ClearList();
226 return;
227 }
228
229 m_PageList.SetTitleString();
230 }
231
232 ///////////////////////////////////////////////////////////
233 // Button Command Handlers
234 #define MAX_FILENAME_BUFFER 4096
235 void TableFileFilter::OnBtnAddLevel() {
236 // TODO: Add your control notification handler code here
237 char title[] = "Add Level Files";
238 char filename_buffer[MAX_FILENAME_BUFFER + 1];
239 CString path;
240
241 CString filter = "Outrage Level Files (*.d3l)|*.d3l|All Files (*.*)|*.*||";
242 CFileDialog dlg_open(TRUE, NULL, NULL, OFN_ALLOWMULTISELECT | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST,
243 filter.GetBuffer(0), this);
244
245 memset(filename_buffer, '\0', MAX_FILENAME_BUFFER);
246
247 dlg_open.m_ofn.lpstrTitle = title;
248 dlg_open.m_ofn.lpstrFileTitle = NULL;
249 dlg_open.m_ofn.lpstrFile = filename_buffer;
250 dlg_open.m_ofn.nMaxFile = MAX_FILENAME_BUFFER;
251
252 if (dlg_open.DoModal() == IDCANCEL) {
253 return;
254 }
255
256 CWaitCursor wc;
257
258 // iterate through and add selected level filenames.
259 POSITION pos;
260 pos = dlg_open.GetStartPosition();
261 while (pos != NULL) {
262 path = dlg_open.GetNextPathName(pos);
263
264 if (!m_PageList.AddLevelFilename(path.GetBuffer(0))) {
265 // MessageBox("Error: Could not add level!\n","Add Level Error!");
266 // m_PageList.ClearList();
267 // return;
268 }
269 }
270
271 m_PageList.SetTitleString();
272 }
273
274 void TableFileFilter::OnBtnAddPage() {
275 // TODO: Add your control notification handler code here
276 CTableFileFilterAddDlg dlg;
277
278 int nResponse = dlg.DoModal();
279 if (nResponse == IDCANCEL) {
280 // TODO: Place code here to handle when the dialog is
281 // dismissed with Cancel
282 return;
283 }
284
285 // Add the new page to the list
286 if (dlg.page_name.IsEmpty())
287 return;
288
289 if (!m_PageList.AddPageFromUser(dlg.page_name.GetBuffer(0), dlg.page_type))
290 MessageBox("This page was not added!", "Page Add Error!");
291
292 m_PageList.SetTitleString();
293 }
294
295 void TableFileFilter::OnBtnCreateNewTableFile() {
296 // TODO: Add your control notification handler code here
297 CString filters = "D3 Table File (*.gam)|*.gam|All Files (*.*)|*.*||";
298 char title[] = "Save New Table File As";
299
300 CFileDialog dlg_open(FALSE, ".gam", NULL, 0, (LPCTSTR)filters, this);
301 dlg_open.m_ofn.lpstrTitle = title;
302 if (dlg_open.DoModal() == IDCANCEL) {
303 return;
304 }
305
306 CWaitCursor wc;
307 if (!m_PageList.CreateNewTableFile(dlg_open.GetPathName().GetBuffer(0), SOURCE_TABLE_FILENAME)) {
308 MessageBox("The save was unsuccessfull", "Save Table File Error!");
309 return;
310 }
311
312 m_PageList.SetTitleString();
313 }
314
315 void TableFileFilter::OnBtnRemoveLevel() {
316 // TODO: Add your control notification handler code here
317 m_PageList.RemoveSelLevelFilename();
318
319 m_PageList.SetTitleString();
320 }
321
322 void TableFileFilter::OnBtnRemovePage() {
323 // TODO: Add your control notification handler code here
324 m_PageList.RemoveSelFromListCtrl();
325
326 m_PageList.SetTitleString();
327 }