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
|
/*
* 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/editorDoc.cpp $
* $Revision: 1.1.1.1 $
* $Date: 2003-08-26 03:57:37 $
* $Author: kevinb $
*
* Editor Document (Level/Mission)
*
* $Log: not supported by cvs2svn $
*
* 13 4/09/99 11:59a Samir
* lock keypad updates out if loading level.
*
* 12 3/22/99 6:26p Matt
* Cleaned up error handling in cfile and editor level loads.
*
* 11 3/11/99 10:51a Nate
* Added deletion of "Untitled" Dallas files when doing a New from editor
*
* 10 2/02/99 3:43p Josh
*
* 9 2/01/99 2:41p Nate
* Added Dallas handling to New, Open, and Save
*
* 8 9/02/98 4:08p Matt
* Don't reset the active texture when creating a new "document"
*
* 7 2/18/98 2:02p Samir
* Fixed editor open and new/close problems.
*
* 6 2/17/98 8:38p Samir
* Commented out OleDocuement code.
*
* 5 1/29/98 2:15p Samir
* Implemented ObjectListModeless and Toolbar button.
*
* 4 11/06/97 2:48p Matt
* Check for error when saving, and put up large message box
*
* 3 10/16/97 2:32p Samir
* Fixed up some timing problems.
*
* 2 8/19/97 5:58p Samir
* OLE additions
*
* 3 2/11/97 1:42p Samir
* Moved file opening and closing to editorDoc where it should be.
*
* $NoKeywords: $
*/
// editorDoc.cpp : implementation of the CEditorDoc class
//
#include "stdafx.h"
#include "editor.h"
#include "SrvrItem.h" // ADDED FOR OLE SUPPORT
#include "editorDoc.h"
#include "ObjectListDialog.h"
#include "keypaddialog.h"
#include "MainFrm.h"
#include <string.h>
#include "d3edit.h"
#include "mono.h"
#include "game.h"
#include "HFile.h"
#include "cfile.h"
#include "ddio.h"
#include "manage.h"
#include "DallasMainDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// Function to copy a Dallas script file
int CopyScriptFile(char *old_file, char *new_file) {
char old_fullpath[_MAX_PATH];
char new_fullpath[_MAX_PATH];
ddio_MakePath(old_fullpath, LocalScriptDir, old_file, NULL);
ddio_MakePath(new_fullpath, LocalScriptDir, new_file, NULL);
return (cf_CopyFile(new_fullpath, old_fullpath));
}
/////////////////////////////////////////////////////////////////////////////
// CEditorDoc
IMPLEMENT_DYNCREATE(CEditorDoc, COleServerDoc)
BEGIN_MESSAGE_MAP(CEditorDoc, COleServerDoc)
//{{AFX_MSG_MAP(CEditorDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEditorDoc construction/destruction
CEditorDoc::CEditorDoc() {
// Use OLE compound files
EnableCompoundFile();
}
CEditorDoc::~CEditorDoc() {}
/////////////////////////////////////////////////////////////////////////////
// CEditorDoc server implementation
COleServerItem *CEditorDoc::OnGetEmbeddedItem() {
// OnGetEmbeddedItem is called by the framework to get the COleServerItem
// that is associated with the document. It is only called when necessary.
CEditorSrvrItem *pItem = new CEditorSrvrItem(this);
ASSERT_VALID(pItem);
return pItem;
}
/////////////////////////////////////////////////////////////////////////////
// CEditorDoc serialization
void CEditorDoc::Serialize(CArchive &ar) {
if (ar.IsStoring()) {
// TODO: add storing code here
} else {
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CEditorDoc diagnostics
#ifdef _DEBUG
void CEditorDoc::AssertValid() const { COleServerDoc::AssertValid(); }
void CEditorDoc::Dump(CDumpContext &dc) const { COleServerDoc::Dump(dc); }
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CEditorDoc commands
BOOL CEditorDoc::OnNewDocument() {
// If Dallas is running, don't create a new document
if (theApp.m_DallasModelessDlgPtr != NULL) {
OutrageMessageBox("The Dallas Script Editor is open!\n\n"
"You must close down Dallas before creating a New Level...");
return FALSE;
}
if (!COleServerDoc::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
// Reinitialize Editor State.
mprintf(0, "Creating new level...\n");
// D3EditState.texdlg_texture = 0;
// Create new mine
CreateNewMine();
SetModifiedFlag(FALSE);
theApp.main_doc = this;
// Remove any "Untitled" dallas script files
char fullpath[_MAX_PATH];
ddio_MakePath(fullpath, LocalScriptDir, "Untitled.cpp", NULL);
ddio_DeleteFile(fullpath);
ddio_MakePath(fullpath, LocalScriptDir, "Untitled.dll", NULL);
ddio_DeleteFile(fullpath);
ddio_MakePath(fullpath, LocalScriptDir, "Untitled.msg", NULL);
ddio_DeleteFile(fullpath);
return TRUE;
}
BOOL CEditorDoc::OnOpenDocument(LPCTSTR lpszPathName) {
BOOL opened;
// If Dallas is running, don't open the document
if (theApp.m_DallasModelessDlgPtr != NULL) {
OutrageMessageBox("The Dallas Script Editor is open!\n\n"
"You must close down Dallas before loading a new level...");
return FALSE;
}
// if (!COleServerDoc::OnOpenDocument(lpszPathName))
// return FALSE;
// TODO: Add your specialized creation code here
// does the level always load correctly?
mprintf(0, "Opening level %s...\n", lpszPathName);
theApp.pause();
CKeypadDialog::Deactivate();
opened = EditorLoadLevel((char *)lpszPathName);
CKeypadDialog::Activate();
theApp.resume();
if (!opened) {
SetModifiedFlag(TRUE); // say that the old level was trashed
return FALSE;
}
if (D3EditState.objmodeless_on)
theApp.main_frame->m_ObjModeless->Refresh();
SetModifiedFlag(FALSE);
theApp.main_doc = this;
return true;
}
BOOL CEditorDoc::OnSaveDocument(LPCTSTR lpszPathName) {
// TODO: Add your specialized code here and/or call the base class
char filename[256];
BOOL retval;
strcpy(filename, lpszPathName);
if (strchr(filename, '.') == 0)
strcat(filename, ".d3l"); // check for extension
mprintf(0, "Saving level %s...\n", lpszPathName);
retval = (BOOL)EditorSaveLevel((char *)lpszPathName);
if (retval)
SetModifiedFlag(FALSE);
else
OutrageMessageBox("Error saving level -- Level not saved.\n\n"
"If you get this error trying to save a file you loaded from the network, "
"here's a workaround you can use to save your file:\n\n"
" 1. Use File/Save As to save the file with a temporary name.\n"
" 2. Use File/New to clear out the level.\n"
" 3. Load the level from the temporary file.\n"
" 4. Use File/Save As to save with the real name.\n\n"
"Matt & Samir are working on this problem.");
// If the Save was successfull, handle the Dallas coordination
if (retval) {
// If Dallas is up, change its filenames
if (theApp.m_DallasModelessDlgPtr != NULL) {
theApp.m_DallasModelessDlgPtr->SetAllFilenamesToThis((char *)lpszPathName);
}
// Copy Dallas files (if doing a 'Save As')
char old_filename[_MAX_PATH + 1];
char new_filename[_MAX_PATH + 1];
CString old_level_fname, new_level_fname;
old_level_fname = GetPathName();
new_level_fname = (char *)lpszPathName;
if (old_level_fname.IsEmpty())
strcpy(old_filename, "Untitled");
else
ddio_SplitPath(old_level_fname.GetBuffer(0), NULL, old_filename, NULL);
if (new_level_fname.IsEmpty())
strcpy(new_filename, "Untitled");
else
ddio_SplitPath(new_level_fname.GetBuffer(0), NULL, new_filename, NULL);
// Make sure names are different (ie 'Save As')
if (stricmp(old_filename, new_filename) != 0) {
CString old_file, new_file;
old_file.Format("%s.cpp", old_filename);
new_file.Format("%s.cpp", new_filename);
CopyScriptFile(old_file.GetBuffer(0), new_file.GetBuffer(0));
old_file.Format("%s.msg", old_filename);
new_file.Format("%s.msg", new_filename);
CopyScriptFile(old_file.GetBuffer(0), new_file.GetBuffer(0));
old_file.Format("%s.dll", old_filename);
new_file.Format("%s.dll", new_filename);
CopyScriptFile(old_file.GetBuffer(0), new_file.GetBuffer(0));
}
}
return retval;
}
void CEditorDoc::OnCloseDocument() {
// TODO: Add your specialized code here and/or call the base class
COleServerDoc::OnCloseDocument();
mprintf(0, "Closing current level...\n");
theApp.main_doc = NULL;
}
BOOL CEditorDoc::SaveModified() {
BOOL return_val; // tells system what to do (save, no, etc)
return_val = COleServerDoc::SaveModified();
return return_val;
}
|