File: TableFileFilter.cpp

package info (click to toggle)
descent3 1.5.0%2Bds-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 35,256 kB
  • sloc: cpp: 416,147; ansic: 3,233; sh: 10; makefile: 8
file content (327 lines) | stat: -rw-r--r-- 9,528 bytes parent folder | download | duplicates (2)
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
/*
* Descent 3
* Copyright (C) 2024 Parallax Software
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.

--- HISTORICAL COMMENTS FOLLOW ---

 * $Logfile: /DescentIII/Main/editor/TableFileFilter.cpp $
 * $Revision: 1.1.1.1 $
 * $Date: 2003-08-26 03:57:39 $
 * $Author: kevinb $
 *
 *
 *
 * $Log: not supported by cvs2svn $
 *
 * 8     2/09/99 4:19p Nate
 * Added to the TableFileFilter interface
 *
 * 7     10/09/98 3:16a Jason
 * more changes for demo
 *
 * 6     10/08/98 10:48p Nate
 *
 * 5     10/08/98 10:30a Nate
 * Initial version
 *
 * $NoKeywords: $
 */

// TableFileFilter.cpp : implementation file
//

#include "stdafx.h"
#include "editor.h"
#include "TableFileFilter.h"
#include "TableFileFilterMng.h"
#include "TableFileFilterAddDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTableFileFilter dialog

TableFileFilter::TableFileFilter(CWnd *pParent /*=NULL*/) : CDialog(TableFileFilter::IDD, pParent) {
  //{{AFX_DATA_INIT(TableFileFilter)
  m_NumPagesText = _T("");
  m_StatusText = _T("");
  //}}AFX_DATA_INIT
}

void TableFileFilter::DoDataExchange(CDataExchange *pDX) {
  CDialog::DoDataExchange(pDX);
  //{{AFX_DATA_MAP(TableFileFilter)
  DDX_Control(pDX, IDC_OUTPUTFILE_EDIT, m_OutputFileEdit);
  DDX_Control(pDX, IDC_TABLEFILTER_LEVEL_LIST, m_LevelList);
  DDX_Control(pDX, IDC_TABLEFILTER_DATA_LIST, m_DataList);
  DDX_Text(pDX, IDC_TABLEFILTER_NUMPAGESTEXT, m_NumPagesText);
  DDX_Text(pDX, IDC_TABLEFILTER_STATUSTEXT, m_StatusText);
  //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(TableFileFilter, CDialog)
//{{AFX_MSG_MAP(TableFileFilter)
ON_COMMAND(ID_TABLEFILTER_FILE_EXIT, OnFileExit)
ON_COMMAND(ID_TABLEFILTER_FILE_SAVE, OnFileSave)
ON_COMMAND(ID_TABLEFILTER_FILE_SAVEAS, OnFileSaveAs)
ON_COMMAND(ID_TABLEFILTER_FILE_LOAD, OnFileLoad)
ON_WM_CLOSE()
ON_BN_CLICKED(IDC_TABLEFILTER_BTN_ADDLEVEL, OnBtnAddLevel)
ON_BN_CLICKED(IDC_TABLEFILTER_BTN_ADDPAGE, OnBtnAddPage)
ON_BN_CLICKED(IDC_TABLEFILTER_BTN_CREATENEWTABLEFILE, OnBtnCreateNewTableFile)
ON_BN_CLICKED(IDC_TABLEFILTER_BTN_REMOVELEVEL, OnBtnRemoveLevel)
ON_BN_CLICKED(IDC_TABLEFILTER_BTN_REMOVEPAGE, OnBtnRemovePage)
ON_COMMAND(ID_TABLEFILTER_FILE_NEW, OnFileNew)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// TableFileFilter message handlers
void TableFileFilter::OnClose() {
  // TODO: Add your message handler code here and/or call default
  if (m_PageList.ModifiedPrompt() == IDYES)
    CDialog::OnClose();
}

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

  // TODO: Add extra initialization here

  // Setup the data list columns
  CString column_name;
  column_name = "Page Name";
  m_DataList.InsertColumn(PAGE_NAME_COLUMN, column_name.GetBuffer(0), LVCFMT_LEFT, -1, PAGE_NAME_COLUMN);
  column_name = "Page Type";
  m_DataList.InsertColumn(PAGE_TYPE_COLUMN, column_name.GetBuffer(0), LVCFMT_LEFT, -1, PAGE_TYPE_COLUMN);
  SetColumnWidths();

  // Set the default file path for the edit box
  char *d3dir = getenv("D3_LOCAL");
  char LocalD3Dir[_MAX_PATH];

  strcpy(LocalD3Dir, d3dir);

  if (d3dir[strlen(d3dir) - 1] != '\\') {
    strcat(LocalD3Dir, "\\");
  }
  strcat(LocalD3Dir, DEFAULT_TABLEPARSE_FNAME);

  m_OutputFileEdit.SetWindowText(LocalD3Dir);

  // Link the page data control to the data list
  m_PageList.BindDlg(this);
  m_PageList.BindOutputFileEdit(&m_OutputFileEdit);
  m_PageList.BindPageDataListCtrl(&m_DataList);
  m_PageList.BindLevelListBox(&m_LevelList);
  m_PageList.BindNumPagesText(&m_NumPagesText);
  m_PageList.BindStatusText(&m_StatusText);

  // Wipe out the list
  OnFileNew();

  return TRUE; // return TRUE unless you set the focus to a control
               // EXCEPTION: OCX Property Pages should return FALSE
}

// Calculates column widths and sets them
void TableFileFilter::SetColumnWidths(void) {
  uint32_t w0, w1;

  RECT rect;
  m_DataList.GetClientRect(&rect);

  w0 = uint32_t(rect.right * PAGE_NAME_COLUMN_WIDTH);
  w1 = uint32_t(rect.right * PAGE_TYPE_COLUMN_WIDTH);

  m_DataList.SetColumnWidth(PAGE_NAME_COLUMN, w0);
  m_DataList.SetColumnWidth(PAGE_TYPE_COLUMN, w1);
}

/////////////////////////////////////////////////////
// Menu Command Handlers
void TableFileFilter::OnFileExit() {
  // TODO: Add your command handler code here
  if (m_PageList.ModifiedPrompt() == IDYES)
    EndDialog(0);
}

void TableFileFilter::OnFileNew() {
  // TODO: Add your command handler code here
  if (m_PageList.ModifiedPrompt() == IDNO)
    return;

  CWaitCursor wc;
  m_PageList.ClearList();
  // m_PageList.AddAllGamefilePages();
  m_PageList.SetTitleString();
}

void TableFileFilter::OnFileSave() {
  // TODO: Add your command handler code here
  if (!m_PageList.FilenameSpecified()) {
    OnFileSaveAs();
    return;
  }

  CWaitCursor wc;
  if (!m_PageList.SaveList(NULL)) {
    MessageBox("The save was unsuccessfull", "Save Table Error!");
    return;
  }
  m_PageList.SetTitleString();
}

void TableFileFilter::OnFileSaveAs() {
  // TODO: Add your command handler code here
  CString filters = "Page Data List File (*.pdl)|*.pdl|All Files (*.*)|*.*||";

  CFileDialog dlg_open(FALSE, ".pdl", NULL, 0, (LPCTSTR)filters, this);
  if (dlg_open.DoModal() == IDCANCEL) {
    return;
  }

  CWaitCursor wc;
  if (!m_PageList.SaveList(dlg_open.GetPathName().GetBuffer(0))) {
    MessageBox("The save was unsuccessfull", "Save Data List Error!");
    return;
  }

  m_PageList.SetTitleString();
}

void TableFileFilter::OnFileLoad() {
  // TODO: Add your command handler code here
  if (m_PageList.ModifiedPrompt() == IDNO)
    return;

  CString filters = "Page Data List File (*.pdl)|*.pdl|All Files (*.*)|*.*||";

  CFileDialog dlg_open(TRUE, ".pdl", NULL, OFN_FILEMUSTEXIST, (LPCTSTR)filters, this);
  if (dlg_open.DoModal() == IDCANCEL) {
    return;
  }

  CWaitCursor wc;
  if (!m_PageList.LoadList(dlg_open.GetPathName().GetBuffer(0))) {
    MessageBox("The load was unsuccessfull", "Load Data List Error!");
    m_PageList.ClearList();
    return;
  }

  m_PageList.SetTitleString();
}

///////////////////////////////////////////////////////////
// Button Command Handlers
#define MAX_FILENAME_BUFFER 4096
void TableFileFilter::OnBtnAddLevel() {
  // TODO: Add your control notification handler code here
  char title[] = "Add Level Files";
  char filename_buffer[MAX_FILENAME_BUFFER + 1];
  CString path;

  CString filter = "Outrage Level Files (*.d3l)|*.d3l|All Files (*.*)|*.*||";
  CFileDialog dlg_open(TRUE, NULL, NULL, OFN_ALLOWMULTISELECT | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST,
                       filter.GetBuffer(0), this);

  memset(filename_buffer, '\0', MAX_FILENAME_BUFFER);

  dlg_open.m_ofn.lpstrTitle = title;
  dlg_open.m_ofn.lpstrFileTitle = NULL;
  dlg_open.m_ofn.lpstrFile = filename_buffer;
  dlg_open.m_ofn.nMaxFile = MAX_FILENAME_BUFFER;

  if (dlg_open.DoModal() == IDCANCEL) {
    return;
  }

  CWaitCursor wc;

  //	iterate through and add selected level filenames.
  POSITION pos;
  pos = dlg_open.GetStartPosition();
  while (pos != NULL) {
    path = dlg_open.GetNextPathName(pos);

    if (!m_PageList.AddLevelFilename(path.GetBuffer(0))) {
      // MessageBox("Error: Could not add level!\n","Add Level Error!");
      // m_PageList.ClearList();
      // return;
    }
  }

  m_PageList.SetTitleString();
}

void TableFileFilter::OnBtnAddPage() {
  // TODO: Add your control notification handler code here
  CTableFileFilterAddDlg dlg;

  int nResponse = dlg.DoModal();
  if (nResponse == IDCANCEL) {
    // TODO: Place code here to handle when the dialog is
    //  dismissed with Cancel
    return;
  }

  // Add the new page to the list
  if (dlg.page_name.IsEmpty())
    return;

  if (!m_PageList.AddPageFromUser(dlg.page_name.GetBuffer(0), dlg.page_type))
    MessageBox("This page was not added!", "Page Add Error!");

  m_PageList.SetTitleString();
}

void TableFileFilter::OnBtnCreateNewTableFile() {
  // TODO: Add your control notification handler code here
  CString filters = "D3 Table File (*.gam)|*.gam|All Files (*.*)|*.*||";
  char title[] = "Save New Table File As";

  CFileDialog dlg_open(FALSE, ".gam", NULL, 0, (LPCTSTR)filters, this);
  dlg_open.m_ofn.lpstrTitle = title;
  if (dlg_open.DoModal() == IDCANCEL) {
    return;
  }

  CWaitCursor wc;
  if (!m_PageList.CreateNewTableFile(dlg_open.GetPathName().GetBuffer(0), SOURCE_TABLE_FILENAME)) {
    MessageBox("The save was unsuccessfull", "Save Table File Error!");
    return;
  }

  m_PageList.SetTitleString();
}

void TableFileFilter::OnBtnRemoveLevel() {
  // TODO: Add your control notification handler code here
  m_PageList.RemoveSelLevelFilename();

  m_PageList.SetTitleString();
}

void TableFileFilter::OnBtnRemovePage() {
  // TODO: Add your control notification handler code here
  m_PageList.RemoveSelFromListCtrl();

  m_PageList.SetTitleString();
}