| 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/editor.cpp $ |
| 21 | * $Revision: 1.1.1.1 $ |
| 22 | * $Date: 2003-08-26 03:57:37 $ |
| 23 | * $Author: kevinb $ |
| 24 | * |
| 25 | * The main editor MFC file. |
| 26 | * |
| 27 | * $Log: not supported by cvs2svn $ |
| 28 | * |
| 29 | * 73 4/17/99 2:46p Matt |
| 30 | * Implemented viewer properties dialog functions. |
| 31 | * |
| 32 | * 72 4/16/99 3:54p Nate |
| 33 | * Added Viewer Properties Dialog |
| 34 | * |
| 35 | * 71 4/04/99 6:21p Matt |
| 36 | * Added hack to pause the app and keep it paused. |
| 37 | * |
| 38 | * 69 3/15/99 5:38p Matt |
| 39 | * Changed idle loop back to old way because Sean says the new code made |
| 40 | * slewing chunky. |
| 41 | * |
| 42 | * 68 3/15/99 4:15p Matt |
| 43 | * Changed the idle handler to not always return true. Hopefully this |
| 44 | * will keep the editor from eating up all the processor time when it's |
| 45 | * not doing anything. |
| 46 | * |
| 47 | * 67 2/25/99 10:45p Matt |
| 48 | * Don't redraw wireframe if view has rotated but not moved |
| 49 | * |
| 50 | * 66 2/21/99 6:38p Samir |
| 51 | * mouse and key input better. buffered mouse. |
| 52 | * |
| 53 | * 65 1/29/99 12:48p Matt |
| 54 | * Rewrote the doorway system |
| 55 | * |
| 56 | * 64 1/27/99 10:35a Samir |
| 57 | * suspend resume keys added. |
| 58 | * |
| 59 | * 63 1/20/99 10:50a Jason |
| 60 | * added new terrain |
| 61 | * |
| 62 | * 62 1/19/99 6:53p Matt |
| 63 | * Fixed a problem when the viewer was instantaneously moved from inside |
| 64 | * to ourside or vise-versa. |
| 65 | * |
| 66 | * 61 1/08/99 2:56p Samir |
| 67 | * Ripped out OSIRIS1. |
| 68 | * |
| 69 | * 60 1/07/99 12:27p Samir |
| 70 | * took out parse command line info call. |
| 71 | * |
| 72 | * 59 12/23/98 3:35p Nate |
| 73 | * Added DallasModelessDlgPtr data member |
| 74 | * |
| 75 | * 58 12/01/98 11:17p Matt |
| 76 | * Added menu option to disable drawing objects in the wireframe view |
| 77 | * |
| 78 | * 57 11/01/98 1:58a Jeff |
| 79 | * converted the vsprintf calls to use the Pvsprintf, which is a safe |
| 80 | * vsprintf, no buffer overflows allowed |
| 81 | * |
| 82 | * 56 10/17/98 1:25p Sean |
| 83 | * Made PrintToDlgItem work with long strings |
| 84 | * |
| 85 | * 55 10/16/98 1:02p Samir |
| 86 | * no ddio_KeyFrame. |
| 87 | * |
| 88 | * 54 10/13/98 12:03p Kevin |
| 89 | * Changed use of preprocessors for debug, etc. |
| 90 | * |
| 91 | * 53 9/22/98 1:55p Matt |
| 92 | * Change the registry path to "Outrage\Descent3". |
| 93 | * |
| 94 | * 52 9/08/98 11:37a Samir |
| 95 | * added key to toggle joystick slewing. |
| 96 | * |
| 97 | * 51 9/04/98 3:16p Samir |
| 98 | * control whether to allow joystick slewing. |
| 99 | * |
| 100 | * 50 8/04/98 2:32p Chris |
| 101 | * Improved attach code added more fixes to the AABB partial computation |
| 102 | * patch |
| 103 | * |
| 104 | * 49 7/10/98 2:12p Jeff |
| 105 | * added a flag for inventory information in objinfo |
| 106 | * |
| 107 | * 48 6/17/98 12:30p Samir |
| 108 | * don't draw wireframe when moving an object. |
| 109 | * |
| 110 | * 47 6/15/98 4:00p Jason |
| 111 | * replaced monochromatic polymodel lighting with rgb lighting |
| 112 | * |
| 113 | * 46 6/10/98 12:20p Matt |
| 114 | * Revamped system that controls what textures are displayed on the |
| 115 | * texture tab. Should work correctly now, and will now save the settings |
| 116 | * to the registry. Also, textures now default to no type set, not all |
| 117 | * types set. |
| 118 | * |
| 119 | * 45 6/08/98 6:13p Matt |
| 120 | * Update the wireframe view when the viewer has stopped slewing |
| 121 | * |
| 122 | * 44 5/20/98 6:59p Samir |
| 123 | * added slew speed slider. |
| 124 | * |
| 125 | * 43 5/20/98 1:43p Matt |
| 126 | * Shift-T now moves a placed building up and down. |
| 127 | * |
| 128 | * 42 2/25/98 6:11p Samir |
| 129 | * Added functions to better deal with key flushing. |
| 130 | * |
| 131 | * 41 2/18/98 2:39a Matt |
| 132 | * Don't update the wireframe view if the only change is that the viewer |
| 133 | * moved |
| 134 | * |
| 135 | * 40 2/10/98 1:59p Chris |
| 136 | * Improved the path system |
| 137 | * |
| 138 | * 39 2/05/98 2:58p Matt |
| 139 | * Cleaned up slew code, and made view mode switch when slewing between |
| 140 | * mine and terrain happen in editor, not slew. |
| 141 | * |
| 142 | * 38 1/28/98 5:07p Samir |
| 143 | * Object modeless settings added. |
| 144 | * |
| 145 | * 37 12/01/97 5:32p Samir |
| 146 | * Argh, more housekeeping for FileDialog function. |
| 147 | * |
| 148 | * 36 12/01/97 5:23p Samir |
| 149 | * When initialdir is empty for FileDialog, then don't use it as a search |
| 150 | * path. |
| 151 | * |
| 152 | * 35 12/01/97 5:17p Samir |
| 153 | * New functions to open a file dialog. |
| 154 | * |
| 155 | * 34 11/13/97 6:16p Matt |
| 156 | * Changed some vars (such as current_powerup) to initialize to 0 instead |
| 157 | * of -1 |
| 158 | * |
| 159 | * 33 10/27/97 5:45p Jason |
| 160 | * added prelim networking stuff, just to get it started |
| 161 | * |
| 162 | * 32 10/16/97 2:31p Samir |
| 163 | * Added keyboard handler to idle loop. |
| 164 | * |
| 165 | * 31 10/01/97 7:52p Matt |
| 166 | * Added code for external rooms |
| 167 | * |
| 168 | * 30 9/29/97 12:09p Jason |
| 169 | * added functionality to doorway system |
| 170 | * |
| 171 | * 29 9/23/97 3:04p Jason |
| 172 | * added tmap2 rotation key (KEY_EQUAL) |
| 173 | * |
| 174 | * 28 9/17/97 11:40a Matt |
| 175 | * Ripped out segment code |
| 176 | * |
| 177 | * 27 9/16/97 1:04p Samir |
| 178 | * Added include of AppDatabase.h |
| 179 | * |
| 180 | * 26 9/09/97 6:07p Matt |
| 181 | * If 't' key pressed when no placed room or group, do nothing |
| 182 | * |
| 183 | * 25 9/08/97 4:05p Samir |
| 184 | * Fixed some warnings and took out extranneous includes to windows.h in |
| 185 | * important headers. |
| 186 | * |
| 187 | * 24 9/06/97 3:15p Matt |
| 188 | * Removed old trigger stuff from registry load/save |
| 189 | * Added function PrintToDlgItem() |
| 190 | * |
| 191 | * 23 8/29/97 1:50p Samir |
| 192 | * Added object moving mouse polling and registry entry for axis mode. |
| 193 | * |
| 194 | * 22 8/26/97 11:38a Samir |
| 195 | * Added Editor_active global to determine whether editor is currently |
| 196 | * active (useful for any window using the gr library.) |
| 197 | * |
| 198 | * 21 8/19/97 5:58p Samir |
| 199 | * OLE additions |
| 200 | * |
| 201 | * 20 8/18/97 6:59p Matt |
| 202 | * Implemented Place Room/Attach room system |
| 203 | * |
| 204 | * 19 8/13/97 9:55a Matt |
| 205 | * Allow sliding & rotating textures with the mouse |
| 206 | * |
| 207 | * 18 8/12/97 7:06p Chris |
| 208 | * Made AABB work in the editor. |
| 209 | * |
| 210 | * 17 8/12/97 5:26p Matt |
| 211 | * Read/write new vars from/to registry |
| 212 | * |
| 213 | * 16 8/11/97 1:53p Matt |
| 214 | * Ripped out robot & powerup pages, and added generic page |
| 215 | * |
| 216 | * 15 8/01/97 11:59a Samir |
| 217 | * Added a preference for debugging in fullscreen. |
| 218 | * |
| 219 | * 14 7/28/97 1:23p Jeff |
| 220 | * Set default external editor to Notepad |
| 221 | * |
| 222 | * 13 7/28/97 10:51a Jeff |
| 223 | * Changed cha *DefaultExternalEditor to what it should be called, char |
| 224 | * Default_external_editor[256] |
| 225 | * |
| 226 | * 12 7/27/97 11:07p Matt |
| 227 | * Save/load external editor string to/from registry. |
| 228 | * |
| 229 | * 11 7/25/97 6:17p Samir |
| 230 | * When floating keypad values are loaded from database, mark keypad as |
| 231 | * moved. |
| 232 | * |
| 233 | * 10 7/24/97 2:58p Matt |
| 234 | * Added functions to load and save D3EditState variables from/to the |
| 235 | * registry |
| 236 | * |
| 237 | * 9 7/22/97 7:07p Matt |
| 238 | * Cleaned up D3EditState, moving some vars in and some out, and renaming |
| 239 | * and changing a few others |
| 240 | * |
| 241 | * 8 7/21/97 1:18p Samir |
| 242 | * You can now type stuff in keypads. |
| 243 | * |
| 244 | * 47 6/09/97 12:07p Samir |
| 245 | * for edit boxes, don't automatically switch focus to main view. |
| 246 | * |
| 247 | * 46 6/04/97 3:08p Jason |
| 248 | * changed backspace key to lshift+backspace |
| 249 | * |
| 250 | * 45 5/13/97 4:36p Samir |
| 251 | * call main-frame's onidle function |
| 252 | * |
| 253 | * 44 4/02/97 5:20p Jason |
| 254 | * made wireframe not update when player moves in the terrain view |
| 255 | * |
| 256 | * 43 4/02/97 3:25p Jason |
| 257 | * got rid of WV_changed and made TV_changed update the textured view and |
| 258 | * flag "World_changed" |
| 259 | * |
| 260 | * 42 4/02/97 11:16a Matt |
| 261 | * Update the wireframe view when the viewer moves, because the viewer is |
| 262 | * drawn as a sphere in that view |
| 263 | * |
| 264 | * 41 4/01/97 11:00p Matt |
| 265 | * Changed editor to keep a viewer object (type camera) seperate from the |
| 266 | * player object. This camera, and not the player, is now moved by |
| 267 | * slewing, the C key, etc. When going into the game, the viewer position |
| 268 | * & orientation are copied to the player. When going back to the editor, |
| 269 | * the player position is copied to the viewer, and the player object is |
| 270 | * reset to its start location. |
| 271 | * |
| 272 | * 40 3/31/97 5:57p Matt |
| 273 | * Revamped mine update flags |
| 274 | * |
| 275 | * 39 3/31/97 3:13p Jason |
| 276 | * added ship,weapon,and sounds to d3edit and zeroed it out upon startup |
| 277 | * |
| 278 | * 38 3/24/97 12:13p Samir |
| 279 | * Set initial trigger type. |
| 280 | * |
| 281 | * 37 3/20/97 4:57p Samir |
| 282 | * Adding IsSelecting to editorSelectorManager if we are curring drawing a |
| 283 | * selection box, say in the wireframe window. |
| 284 | * |
| 285 | * 36 3/20/97 4:22p Samir |
| 286 | * Added Segment Sizing mode and side sizing. |
| 287 | * |
| 288 | * 35 3/20/97 2:56p Samir |
| 289 | * Moved SelManager var to SelManager.cpp |
| 290 | * |
| 291 | * 34 3/20/97 12:06p Samir |
| 292 | * Added Selection Box manager. |
| 293 | * |
| 294 | * 33 3/20/97 11:20a Samir |
| 295 | * Accelerator keys should work when focus is in keypad. |
| 296 | * |
| 297 | * 32 3/13/97 5:12p Samir |
| 298 | * Call WinApp::OnIdle also in our idle loop. |
| 299 | * |
| 300 | * 31 3/07/97 4:18p Jason |
| 301 | * implemented terrain functionality in the editor |
| 302 | * |
| 303 | * 30 3/05/97 12:16p Jason |
| 304 | * added code to support our new 3d doors |
| 305 | * |
| 306 | * 29 3/03/97 11:23a Matt |
| 307 | * Set/clear MFC's modified flag every time through the loop, not just if |
| 308 | * the mine was changed |
| 309 | * Don't prompt user about discarding changes if the level hasn't been |
| 310 | * changed |
| 311 | * |
| 312 | * 28 2/20/97 4:41p Samir |
| 313 | * You can now use keypad functions even if input focus is in keypad |
| 314 | * dialog. |
| 315 | * |
| 316 | * 27 2/20/97 4:30p Samir |
| 317 | * Slewing works a lot better when input focus is in keypad or any other |
| 318 | * window other than the texture window. |
| 319 | * |
| 320 | * 26 2/20/97 1:03p Samir |
| 321 | * Control + slew key will not slew the mine. |
| 322 | * |
| 323 | * 25 2/18/97 12:46p Samir |
| 324 | * Initialized current object type to powerup. |
| 325 | * |
| 326 | * 24 2/17/97 6:09p Samir |
| 327 | * made initial powerup be the shield powerup. |
| 328 | * |
| 329 | * 23 2/13/97 12:16p Jason |
| 330 | * changes for powerup remapping |
| 331 | * |
| 332 | * 22 2/12/97 3:07p Samir |
| 333 | * pause and resume now flush keyboard queue to stop backspace from |
| 334 | * Int3ing. |
| 335 | * |
| 336 | * 21 2/11/97 1:42p Samir |
| 337 | * Added document variable and set modification flag. |
| 338 | * |
| 339 | * 20 2/11/97 10:31a Jason |
| 340 | * changed keystate checking for backspace |
| 341 | * |
| 342 | * 19 2/05/97 11:45a Samir |
| 343 | * Initialized D3windowed editor state |
| 344 | * |
| 345 | * 18 2/03/97 7:56p Matt |
| 346 | * Calculate Frame_time in editor loop |
| 347 | * |
| 348 | * 17 1/31/97 12:06p Jason |
| 349 | * added support for animations in Dialogs |
| 350 | * Also added more powerup functionality |
| 351 | * |
| 352 | * 16 1/23/97 4:00p Samir |
| 353 | * More D3EditState vars with respect to floating keypads. |
| 354 | * |
| 355 | * 15 1/21/97 12:48p Samir |
| 356 | * Added InitEditorState to define D3EditState info |
| 357 | * |
| 358 | * 14 1/20/97 4:13p Samir |
| 359 | * Added backspace debug key. |
| 360 | * |
| 361 | * $NoKeywords: $ |
| 362 | */ |
| 363 | |
| 364 | // editor.cpp : Defines the class behaviors for the application. |
| 365 | // |
| 366 | |
| 367 | #include <cstdarg> |
| 368 | #include <cstdio> |
| 369 | |
| 370 | #include "stdafx.h" |
| 371 | #include "editor.h" |
| 372 | #include "MainFrm.h" |
| 373 | #include "IpFrame.h" // OLE |
| 374 | #include "editorDoc.h" |
| 375 | #include "editorView.h" |
| 376 | #include "slew.h" |
| 377 | #include "object.h" |
| 378 | #include "descent.h" |
| 379 | #include "moveworld.h" |
| 380 | #include "d3edit.h" |
| 381 | #include "pserror.h" |
| 382 | #include "args.h" |
| 383 | #include "game.h" |
| 384 | #include "trigger.h" |
| 385 | #include "HTexture.h" |
| 386 | #include "HRoom.h" |
| 387 | #include "erooms.h" |
| 388 | #include "AppDatabase.h" |
| 389 | |
| 390 | #include "TextureGrWnd.h" |
| 391 | #include "WireframeGrWnd.h" |
| 392 | #include "SelManager.h" |
| 393 | #include "ObjMoveManager.h" |
| 394 | #include "ViewerPropDlg.h" |
| 395 | |
| 396 | #include "mono.h" |
| 397 | #include "ddio.h" |
| 398 | |
| 399 | #include "boa.h" |
| 400 | #include "terrain.h" |
| 401 | |
| 402 | #ifdef _DEBUG |
| 403 | #define new DEBUG_NEW |
| 404 | #undef THIS_FILE |
| 405 | static char THIS_FILE[] = __FILE__; |
| 406 | #endif |
| 407 | |
| 408 | d3edit_state D3EditState; |
| 409 | grSurface *Desktop_surf = NULL; |
| 410 | bool Editor_active = true; |
| 411 | |
| 412 | // ADDED FOR OLE SUPPORT |
| 413 | // This identifier was generated to be statistically unique for your app. |
| 414 | // You may change it if you prefer to choose a specific identifier. |
| 415 | |
| 416 | // {949F57CE-189E-11D1-BD9B-00A0C96ED595} |
| 417 | static const CLSID clsid = {0x949f57ce, 0x189e, 0x11d1, {0xbd, 0x9b, 0x0, 0xa0, 0xc9, 0x6e, 0xd5, 0x95}}; |
| 418 | // ADDED FOR OLE SUPPORT |
| 419 | |
| 420 | ///////////////////////////////////////////////////////////////////////////// |
| 421 | // CEditorApp |
| 422 | |
| 423 | BEGIN_MESSAGE_MAP(CEditorApp, CWinApp) |
| 424 | //{{AFX_MSG_MAP(CEditorApp) |
| 425 | ON_COMMAND(ID_APP_ABOUT, OnAppAbout) |
| 426 | // NOTE - the ClassWizard will add and remove mapping macros here. |
| 427 | // DO NOT EDIT what you see in these blocks of generated code! |
| 428 | //}}AFX_MSG_MAP |
| 429 | // Standard file based document commands |
| 430 | ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew) |
| 431 | ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen) |
| 432 | // Standard print setup command |
| 433 | ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup) |
| 434 | END_MESSAGE_MAP() |
| 435 | |
| 436 | ///////////////////////////////////////////////////////////////////////////// |
| 437 | // CEditorApp construction |
| 438 | |
| 439 | CEditorApp::CEditorApp() { |
| 440 | // TODO: add construction code here, |
| 441 | // Place all significant initialization in InitInstance |
| 442 | |
| 443 | textured_view = NULL; |
| 444 | wireframe_view = NULL; |
| 445 | main_view = NULL; |
| 446 | main_doc = NULL; |
| 447 | main_frame = NULL; |
| 448 | m_Paused = FALSE; |
| 449 | |
| 450 | m_DallasModelessDlgPtr = NULL; |
| 451 | m_ViewerPropDlgPtr = NULL; |
| 452 | } |
| 453 | |
| 454 | ///////////////////////////////////////////////////////////////////////////// |
| 455 | // The one and only CEditorApp object |
| 456 | |
| 457 | CEditorApp theApp; |
| 458 | |
| 459 | // icecoldduke: these arent defined in code anywhere |
| 460 | #define MAX_TEXTURE_SHADES 32 |
| 461 | uint8_t TexShadeTable8[MAX_TEXTURE_SHADES][256]; |
| 462 | uint64_t TexShadeTable16[MAX_TEXTURE_SHADES][256]; |
| 463 | uint8_t TexRevShadeTable8[MAX_TEXTURE_SHADES][256]; |
| 464 | uint64_t TexRevShadeTable16[MAX_TEXTURE_SHADES][256]; |
| 465 | |
| 466 | ///////////////////////////////////////////////////////////////////////////// |
| 467 | // CEditorApp initialization |
| 468 | |
| 469 | BOOL CEditorApp::InitInstance() { |
| 470 | // ADDED BY SAMIR FOR OLE SUPPORT. |
| 471 | // Initialize OLE libraries |
| 472 | if (!AfxOleInit()) { |
| 473 | AfxMessageBox(IDP_OLE_INIT_FAILED); |
| 474 | return FALSE; |
| 475 | } |
| 476 | AfxEnableControlContainer(); |
| 477 | // ADDED BY SAMIR FOR OLE SUPPORT. |
| 478 | |
| 479 | // Standard initialization |
| 480 | // If you are not using these features and wish to reduce the size |
| 481 | // of your final executable, you should remove from the following |
| 482 | // the specific initialization routines you do not need. |
| 483 | |
| 484 | #ifdef _AFXDLL |
| 485 | Enable3dControls(); // Call this when using MFC in a shared DLL |
| 486 | #else |
| 487 | Enable3dControlsStatic(); // Call this when linking to MFC statically |
| 488 | #endif |
| 489 | |
| 490 | // ADDED TO UPGRADE TO MFC 5.0 |
| 491 | // This registry area is really just for the editor. No game settings or UI specifics |
| 492 | // except those strictly managed by MFC will be put here. |
| 493 | // Change the registry key under which our settings are stored. |
| 494 | // You should modify this string to be something appropriate |
| 495 | // such as the name of your company or organization. |
| 496 | SetRegistryKey(_T("Outrage\\Descent3\\editor\\mfc")); |
| 497 | // ADDED TO UPGRADE TO MFC 5.0 |
| 498 | |
| 499 | LoadStdProfileSettings(); // Load standard INI file options (including MRU) |
| 500 | |
| 501 | // Initialize editor state |
| 502 | InitEditorState(); |
| 503 | |
| 504 | // Register the application's document templates. Document templates |
| 505 | // serve as the connection between documents, frame windows and views. |
| 506 | |
| 507 | CSingleDocTemplate *pDocTemplate; |
| 508 | pDocTemplate = new CSingleDocTemplate(IDR_MAINFRAME, RUNTIME_CLASS(CEditorDoc), |
| 509 | RUNTIME_CLASS(CMainFrame), // main SDI frame window |
| 510 | RUNTIME_CLASS(CEditorView)); |
| 511 | |
| 512 | // ADDED BY SAMIR FOR OLE SUPPORT. |
| 513 | pDocTemplate->SetServerInfo(IDR_SRVR_EMBEDDED, IDR_SRVR_INPLACE, RUNTIME_CLASS(CInPlaceFrame)); |
| 514 | // ADDED BY SAMIR FOR OLE SUPPORT. |
| 515 | |
| 516 | AddDocTemplate(pDocTemplate); |
| 517 | |
| 518 | // ADDED BY SAMIR FOR OLE SUPPORT. |
| 519 | // Connect the COleTemplateServer to the document template. |
| 520 | // The COleTemplateServer creates new documents on behalf |
| 521 | // of requesting OLE containers by using information |
| 522 | // specified in the document template. |
| 523 | m_server.ConnectTemplate(clsid, pDocTemplate, TRUE); |
| 524 | // Note: SDI applications register server objects only if /Embedding |
| 525 | // or /Automation is present on the command line. |
| 526 | // ADDED BY SAMIR FOR OLE SUPPORT. |
| 527 | |
| 528 | // Parse command line for standard shell commands, DDE, file open |
| 529 | GatherArgs(m_lpCmdLine); |
| 530 | |
| 531 | CCommandLineInfo cmdInfo; |
| 532 | // ParseCommandLine(cmdInfo); |
| 533 | |
| 534 | // ADDED BY SAMIR FOR OLE SUPPORT. |
| 535 | // Check to see if launched as OLE server |
| 536 | if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated) { |
| 537 | // Register all OLE server (factories) as running. This enables the |
| 538 | // OLE libraries to create objects from other applications. |
| 539 | COleTemplateServer::RegisterAll(); |
| 540 | |
| 541 | // Application was run with /Embedding or /Automation. Don't show the |
| 542 | // main window in this case. |
| 543 | return TRUE; |
| 544 | } |
| 545 | // When a server application is launched stand-alone, it is a good idea |
| 546 | // to update the system registry in case it has been damaged. |
| 547 | m_server.UpdateRegistry(OAT_INPLACE_SERVER); |
| 548 | // ADDED BY SAMIR FOR OLE SUPPORT. |
| 549 | |
| 550 | // Dispatch commands specified on the command line |
| 551 | if (!ProcessShellCommand(cmdInfo)) |
| 552 | return FALSE; |
| 553 | |
| 554 | // ADDED TO UPGRADE TO MFC 5.0 |
| 555 | // The one and only window has been initialized, so show and update it. |
| 556 | m_pMainWnd->ShowWindow(SW_SHOW); |
| 557 | m_pMainWnd->UpdateWindow(); |
| 558 | // ADDED TO UPGRADE TO MFC 5.0 |
| 559 | |
| 560 | // Enable rich edits |
| 561 | AfxInitRichEdit(); |
| 562 | return TRUE; |
| 563 | } |
| 564 | |
| 565 | ///////////////////////////////////////////////////////////////////////////// |
| 566 | // CAboutDlg dialog used for App About |
| 567 | |
| 568 | class CAboutDlg : public CDialog { |
| 569 | public: |
| 570 | CAboutDlg(); |
| 571 | |
| 572 | // Dialog Data |
| 573 | //{{AFX_DATA(CAboutDlg) |
| 574 | enum { IDD = IDD_ABOUTBOX }; |
| 575 | //}}AFX_DATA |
| 576 | |
| 577 | // ClassWizard generated virtual function overrides |
| 578 | //{{AFX_VIRTUAL(CAboutDlg) |
| 579 | protected: |
| 580 | virtual void DoDataExchange(CDataExchange *pDX); // DDX/DDV support |
| 581 | //}}AFX_VIRTUAL |
| 582 | |
| 583 | // Implementation |
| 584 | protected: |
| 585 | //{{AFX_MSG(CAboutDlg) |
| 586 | // No message handlers |
| 587 | //}}AFX_MSG |
| 588 | DECLARE_MESSAGE_MAP() |
| 589 | }; |
| 590 | |
| 591 | CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { |
| 592 | //{{AFX_DATA_INIT(CAboutDlg) |
| 593 | //}}AFX_DATA_INIT |
| 594 | } |
| 595 | |
| 596 | void CAboutDlg::DoDataExchange(CDataExchange *pDX) { |
| 597 | CDialog::DoDataExchange(pDX); |
| 598 | //{{AFX_DATA_MAP(CAboutDlg) |
| 599 | //}}AFX_DATA_MAP |
| 600 | } |
| 601 | |
| 602 | BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) |
| 603 | //{{AFX_MSG_MAP(CAboutDlg) |
| 604 | // No message handlers |
| 605 | //}}AFX_MSG_MAP |
| 606 | END_MESSAGE_MAP() |
| 607 | |
| 608 | // App command to run the dialog |
| 609 | void CEditorApp::OnAppAbout() { |
| 610 | CAboutDlg aboutDlg; |
| 611 | |
| 612 | theApp.pause(); |
| 613 | aboutDlg.DoModal(); |
| 614 | theApp.resume(); |
| 615 | } |
| 616 | |
| 617 | ///////////////////////////////////////////////////////////////////////////// |
| 618 | // CEditorApp commands |
| 619 | |
| 620 | // this is bad place to put this |
| 621 | int Slew_limitations = 0; |
| 622 | |
| 623 | BOOL CEditorApp::OnIdle(LONG lCount) { |
| 624 | static bool Dirty_wireframe = 0; |
| 625 | bool viewer_rotated = 0; |
| 626 | int key; |
| 627 | |
| 628 | // determine if we should process idle messages |
| 629 | if (m_Paused) |
| 630 | return TRUE; |
| 631 | |
| 632 | // do our own input and output! |
| 633 | ddio_Frame(); |
| 634 | |
| 635 | ///////////////////////////////////////////////////////////////////////////// |
| 636 | // all mouse button/drag functions go in this big if statement. this |
| 637 | // ensures that there are no conflicts between mouse drag operations |
| 638 | if (!SelManager.IsSelecting() && !ObjMoveManager.IsMoving()) { |
| 639 | // slide current texture |
| 640 | if (KEY_STATE(KEY_Y)) { // slide with mouse |
| 641 | int x, y, dx, dy; |
| 642 | ddio_MouseGetState(&x, &y, &dx, &dy); |
| 643 | |
| 644 | if (KEY_STATE(KEY_LCTRL) || KEY_STATE(KEY_RCTRL)) |
| 645 | HTextureRotate(Curroomp, Curface, (float)dx * 50.0); |
| 646 | else |
| 647 | HTextureSlide(Curroomp, Curface, (float)dx / 2.0, (float)-dy / 2.0); |
| 648 | } |
| 649 | // attaching rooms. |
| 650 | else if (KEY_STATE(KEY_T)) { |
| 651 | if ((Placed_room != -1) || (Placed_group != NULL)) { |
| 652 | int x, y, dx, dy; |
| 653 | ddio_MouseGetState(&x, &y, &dx, &dy); |
| 654 | |
| 655 | if (KEY_STATE(KEY_LCTRL) || KEY_STATE(KEY_RCTRL)) |
| 656 | Placed_room_attachpoint += |
| 657 | (Placed_room_orient.rvec * (float)dx / 20.0) + (Placed_room_orient.uvec * (float)dy / 20.0); |
| 658 | else if ((Placed_baseroomp == NULL) && |
| 659 | (KEY_STATE(KEY_LSHIFT) || KEY_STATE(KEY_RSHIFT))) // If on terrain, slide up/down |
| 660 | Placed_room_attachpoint += (Placed_room_orient.fvec * (float)dx / 20.0); |
| 661 | else { |
| 662 | Placed_room_angle += (float)dx * 20.0; |
| 663 | ComputePlacedRoomMatrix(); |
| 664 | } |
| 665 | |
| 666 | State_changed = 1; |
| 667 | } |
| 668 | } else { |
| 669 | MoveWorld(); |
| 670 | } |
| 671 | } |
| 672 | |
| 673 | // very temorary key handler |
| 674 | // Slew the texture view |
| 675 | bool was_outside = (OBJECT_OUTSIDE(Viewer_object) != 0); |
| 676 | int slew_flags = SlewFrame(Viewer_object, Slew_limitations); |
| 677 | |
| 678 | if (slew_flags & SLEW_MOVE) { |
| 679 | Viewer_moved = 1; |
| 680 | |
| 681 | if (OBJECT_OUTSIDE(Viewer_object) && !was_outside) |
| 682 | SetViewMode(VM_TERRAIN); |
| 683 | if (!OBJECT_OUTSIDE(Viewer_object) && was_outside) |
| 684 | SetViewMode(VM_MINE); |
| 685 | } |
| 686 | |
| 687 | if (slew_flags & SLEW_ROTATE) |
| 688 | viewer_rotated = 1; |
| 689 | |
| 690 | // Update the viewer properties dialog |
| 691 | if (Viewer_moved && theApp.m_ViewerPropDlgPtr) |
| 692 | theApp.m_ViewerPropDlgPtr->UpdatePosition(); |
| 693 | if ((Viewer_moved || viewer_rotated) && theApp.m_ViewerPropDlgPtr) |
| 694 | theApp.m_ViewerPropDlgPtr->UpdateOrientation(); |
| 695 | |
| 696 | if (slew_flags & SLEW_KEY) { |
| 697 | // note that if a slew key was pressed, the main view is out of keyboard focus, set |
| 698 | // keyboard focus to the main_view. |
| 699 | if (main_view && main_view != CWnd::GetFocus()) { |
| 700 | mprintf(0, "Restoring focus to main view.\n"); |
| 701 | main_view->SetFocus(); |
| 702 | } |
| 703 | } else if (KEY_STATE(KEY_LCTRL) || KEY_STATE(KEY_RCTRL)) { |
| 704 | // this is done to support CTRL-KEYPAD functions if input focus is not in main view |
| 705 | if (main_view && main_view != CWnd::GetFocus()) { |
| 706 | mprintf(0, "Restoring focus to main view.\n"); |
| 707 | main_view->SetFocus(); |
| 708 | } |
| 709 | } |
| 710 | /*else if (ddio_KeyInKey()) { |
| 711 | // this is done if you press any other key while in a keypad, to use wireframe stuff |
| 712 | if (main_view && main_view != CWnd::GetFocus()) { |
| 713 | CRuntimeClass *wndtype = CWnd::GetFocus()->GetRuntimeClass(); |
| 714 | if (strcmp(wndtype->m_lpszClassName, "CEdit")) { |
| 715 | mprintf(0,"Restoring focus to main view.\n"); |
| 716 | main_view->SetFocus(); |
| 717 | } |
| 718 | } |
| 719 | } |
| 720 | */ |
| 721 | |
| 722 | key = ddio_KeyInKey(); |
| 723 | |
| 724 | // toggle joystick slewing |
| 725 | if (key == (KEY_ALTED + KEY_J)) { |
| 726 | D3EditState.joy_slewing = !D3EditState.joy_slewing; |
| 727 | SlewControlInit(); |
| 728 | } |
| 729 | |
| 730 | // Check if something in the world has changed, and if so set global changed flag |
| 731 | if (World_changed) { |
| 732 | Mine_changed = 1; |
| 733 | |
| 734 | // Create room objects |
| 735 | CreateRoomObjects(); |
| 736 | } |
| 737 | |
| 738 | // See if there's a new mine, and set/clear flags as appropriate |
| 739 | if (New_mine) { |
| 740 | World_changed = 1; // force redraws |
| 741 | Mine_changed = 0; // clear global changed flag |
| 742 | } |
| 743 | |
| 744 | if (New_mine || World_changed) { |
| 745 | ComputeAABB(false); |
| 746 | } |
| 747 | |
| 748 | // for old code |
| 749 | |
| 750 | int suppress_wireframe_redraw = 0; |
| 751 | |
| 752 | if (TV_changed) { |
| 753 | World_changed = 1; |
| 754 | suppress_wireframe_redraw = 1; |
| 755 | } |
| 756 | |
| 757 | // Redraw the textured view if the world changed or the viewer moved |
| 758 | if (textured_view && (World_changed || State_changed || Viewer_moved || viewer_rotated || Object_moved)) { |
| 759 | textured_view->Render(); |
| 760 | textured_view->InvalidateRect(NULL, FALSE); |
| 761 | } |
| 762 | |
| 763 | // Keep track of whether viewer moved for next frame, since we only redraw the |
| 764 | // wireframe after the viewer has stopped slewing |
| 765 | Dirty_wireframe |= (Viewer_moved != 0); |
| 766 | |
| 767 | // Redraw the wireframe view if the world changed or the view was changed |
| 768 | if (wireframe_view && !suppress_wireframe_redraw && |
| 769 | ((World_changed || State_changed || Edview_changed) || |
| 770 | (!Viewer_moved && !viewer_rotated && Dirty_wireframe && !(Editor_view_mode == VM_TERRAIN)))) { |
| 771 | if (!Object_moved) { |
| 772 | wireframe_view->Render(); |
| 773 | wireframe_view->InvalidateRect(NULL, FALSE); |
| 774 | Dirty_wireframe = 0; |
| 775 | } |
| 776 | } |
| 777 | |
| 778 | // Check to stop slew. (Why is this here?) |
| 779 | if (ddio_KeyDownTime(KEY_PAD5) > 0) |
| 780 | SlewStop(Viewer_object); |
| 781 | |
| 782 | // Check for debugger break |
| 783 | if (KEY_STATE(KEY_BACKSP) > 0 && KEY_STATE(KEY_LSHIFT) > 0) { |
| 784 | Int3(); |
| 785 | ddio_KeyFlush(); |
| 786 | } |
| 787 | |
| 788 | // What does this do? |
| 789 | if (main_frame) |
| 790 | main_frame->OnIdle(); |
| 791 | |
| 792 | // Reset all flags |
| 793 | World_changed = State_changed = Viewer_moved = Edview_changed = New_mine = TV_changed = 0; |
| 794 | |
| 795 | // Compute Frame_time |
| 796 | CalcFrameTime(); |
| 797 | |
| 798 | // Tell MFC whether or not our document has been changed |
| 799 | if (main_doc) |
| 800 | main_doc->SetModifiedFlag(Mine_changed); |
| 801 | |
| 802 | // this is done to allow selection boxes in the main frame. |
| 803 | SelManager.Defer(); |
| 804 | |
| 805 | // this is done to allow object moving |
| 806 | ObjMoveManager.Defer(); |
| 807 | |
| 808 | // defer to MFC |
| 809 | CWinApp::OnIdle(lCount); |
| 810 | |
| 811 | return TRUE; |
| 812 | } |
| 813 | |
| 814 | // Save current editor settings to the registry |
| 815 | void SaveEditorSettings() { |
| 816 | oeLnxAppDatabase Editor_database((oeLnxAppDatabase *)Database); |
| 817 | bool res; |
| 818 | int speed; |
| 819 | |
| 820 | res = Editor_database.lookup_record("editor"); |
| 821 | if (!res) { |
| 822 | mprintf(0, "Can't get editor registry path\n"); |
| 823 | Int3(); |
| 824 | return; |
| 825 | } |
| 826 | |
| 827 | Editor_database.write("texdlg_texture", D3EditState.texdlg_texture); |
| 828 | Editor_database.write("current_obj_type", D3EditState.current_obj_type); |
| 829 | Editor_database.write("current_powerup", D3EditState.current_powerup); |
| 830 | Editor_database.write("current_door", D3EditState.current_door); |
| 831 | Editor_database.write("current_robot", D3EditState.current_robot); |
| 832 | Editor_database.write("current_ship", D3EditState.current_ship); |
| 833 | Editor_database.write("current_sound", D3EditState.current_sound); |
| 834 | Editor_database.write("current_weapon", D3EditState.current_weapon); |
| 835 | Editor_database.write("current_path", D3EditState.current_path); |
| 836 | Editor_database.write("current_node", D3EditState.current_node); |
| 837 | Editor_database.write("current_megacell", D3EditState.current_megacell); |
| 838 | Editor_database.write("current_clutter", D3EditState.current_clutter); |
| 839 | Editor_database.write("current_building", D3EditState.current_building); |
| 840 | Editor_database.write("texscr_visible", D3EditState.texscr_visible); |
| 841 | Editor_database.write("texscr_x", D3EditState.texscr_x); |
| 842 | Editor_database.write("texscr_y", D3EditState.texscr_y); |
| 843 | Editor_database.write("texscr_w", D3EditState.texscr_w); |
| 844 | Editor_database.write("texscr_h", D3EditState.texscr_h); |
| 845 | Editor_database.write("wirescr_visible", D3EditState.wirescr_visible); |
| 846 | Editor_database.write("wirescr_x", D3EditState.wirescr_x); |
| 847 | Editor_database.write("wirescr_y", D3EditState.wirescr_y); |
| 848 | Editor_database.write("wirescr_w", D3EditState.wirescr_w); |
| 849 | Editor_database.write("wirescr_h", D3EditState.wirescr_h); |
| 850 | Editor_database.write("keypad_visible", D3EditState.keypad_visible); |
| 851 | Editor_database.write("keypad_current", D3EditState.keypad_current); |
| 852 | Editor_database.write("float_keypad_x", D3EditState.float_keypad_x); |
| 853 | Editor_database.write("float_keypad_y", D3EditState.float_keypad_y); |
| 854 | Editor_database.write("float_keypad_w", D3EditState.float_keypad_w); |
| 855 | Editor_database.write("float_keypad_h", D3EditState.float_keypad_h); |
| 856 | Editor_database.write("objmodeless_x", D3EditState.objmodeless_x); |
| 857 | Editor_database.write("objmodeless_y", D3EditState.objmodeless_y); |
| 858 | Editor_database.write("objmodeless_on", D3EditState.objmodeless_on); |
| 859 | Editor_database.write("tile_views", D3EditState.tile_views); |
| 860 | Editor_database.write("game_render_mode", D3EditState.game_render_mode); |
| 861 | Editor_database.write("terrain_dots", D3EditState.terrain_dots); |
| 862 | Editor_database.write("terrain_flat_shade", D3EditState.terrain_flat_shade); |
| 863 | Editor_database.write("randomize_megacell", D3EditState.randomize_megacell); |
| 864 | Editor_database.write("box_selection_mode", D3EditState.box_selection_mode); |
| 865 | Editor_database.write("object_move_mode", D3EditState.object_move_mode); |
| 866 | Editor_database.write("fullscreen_debug", D3EditState.fullscreen_debug_state); |
| 867 | Editor_database.write("object_move_axis", D3EditState.object_move_axis); |
| 868 | Editor_database.write("texture_display_flags", D3EditState.texture_display_flags); |
| 869 | |
| 870 | speed = ((Slew_key_speed - 0.5) / 0.5); |
| 871 | Editor_database.write("slew_key_speed", speed); |
| 872 | Editor_database.write("joy_slewing", D3EditState.joy_slewing); |
| 873 | } |
| 874 | |
| 875 | // Load editor settings from the registry |
| 876 | void LoadEditorSettings() { |
| 877 | oeLnxAppDatabase Editor_database((oeLnxAppDatabase *)Database); |
| 878 | bool res; |
| 879 | int speed = (int)((Slew_key_speed - 0.5) / 0.5); |
| 880 | |
| 881 | res = Editor_database.lookup_record("editor"); |
| 882 | if (!res) { |
| 883 | mprintf(0, "Can't get editor registry path\n"); |
| 884 | Int3(); |
| 885 | return; |
| 886 | } |
| 887 | |
| 888 | Editor_database.read_int("texdlg_texture", &D3EditState.texdlg_texture); |
| 889 | Editor_database.read_int("current_obj_type", &D3EditState.current_obj_type); |
| 890 | Editor_database.read_int("current_powerup", &D3EditState.current_powerup); |
| 891 | Editor_database.read_int("current_door", &D3EditState.current_door); |
| 892 | Editor_database.read_int("current_robot", &D3EditState.current_robot); |
| 893 | Editor_database.read_int("current_clutter", &D3EditState.current_clutter); |
| 894 | Editor_database.read_int("current_building", &D3EditState.current_building); |
| 895 | Editor_database.read_int("current_ship", &D3EditState.current_ship); |
| 896 | Editor_database.read_int("current_sound", &D3EditState.current_sound); |
| 897 | Editor_database.read_int("current_weapon", &D3EditState.current_weapon); |
| 898 | Editor_database.read_int("current_path", &D3EditState.current_path); |
| 899 | Editor_database.read_int("current_node", &D3EditState.current_node); |
| 900 | Editor_database.read_int("current_megacell", &D3EditState.current_megacell); |
| 901 | Editor_database.read("texscr_visible", &D3EditState.texscr_visible); |
| 902 | Editor_database.read_int("texscr_x", &D3EditState.texscr_x); |
| 903 | Editor_database.read_int("texscr_y", &D3EditState.texscr_y); |
| 904 | Editor_database.read_int("texscr_w", &D3EditState.texscr_w); |
| 905 | Editor_database.read_int("texscr_h", &D3EditState.texscr_h); |
| 906 | Editor_database.read("wirescr_visible", &D3EditState.wirescr_visible); |
| 907 | Editor_database.read_int("wirescr_x", &D3EditState.wirescr_x); |
| 908 | Editor_database.read_int("wirescr_y", &D3EditState.wirescr_y); |
| 909 | Editor_database.read_int("wirescr_w", &D3EditState.wirescr_w); |
| 910 | Editor_database.read_int("wirescr_h", &D3EditState.wirescr_h); |
| 911 | Editor_database.read("keypad_visible", &D3EditState.keypad_visible); |
| 912 | Editor_database.read_int("keypad_current", &D3EditState.keypad_current); |
| 913 | Editor_database.read_int("float_keypad_x", &D3EditState.float_keypad_x); |
| 914 | Editor_database.read_int("float_keypad_y", &D3EditState.float_keypad_y); |
| 915 | Editor_database.read_int("float_keypad_w", &D3EditState.float_keypad_w); |
| 916 | Editor_database.read_int("float_keypad_h", &D3EditState.float_keypad_h); |
| 917 | Editor_database.read_int("objmodeless_x", &D3EditState.objmodeless_x); |
| 918 | Editor_database.read_int("objmodeless_y", &D3EditState.objmodeless_y); |
| 919 | Editor_database.read("objmodeless_on", &D3EditState.objmodeless_on); |
| 920 | Editor_database.read("tile_views", &D3EditState.tile_views); |
| 921 | Editor_database.read_int("game_render_mode", &D3EditState.game_render_mode); |
| 922 | Editor_database.read("terrain_dots", &D3EditState.terrain_dots); |
| 923 | Editor_database.read("terrain_flat_shade", &D3EditState.terrain_flat_shade); |
| 924 | Editor_database.read("randomize_megacell", &D3EditState.randomize_megacell); |
| 925 | Editor_database.read_int("box_selection_mode", &D3EditState.box_selection_mode); |
| 926 | Editor_database.read_int("object_move_mode", &D3EditState.object_move_mode); |
| 927 | Editor_database.read("fullscreen_debug", &D3EditState.fullscreen_debug_state); |
| 928 | Editor_database.read_int("object_move_axis", &D3EditState.object_move_axis); |
| 929 | Editor_database.read_int("slew_key_speed", &speed); |
| 930 | Editor_database.read_int("texture_display_flags", &D3EditState.texture_display_flags); |
| 931 | Editor_database.read_int("joy_slewing", &D3EditState.joy_slewing); |
| 932 | |
| 933 | Slew_key_speed = ((float)speed * 0.5) + 0.5; |
| 934 | |
| 935 | // Since we are loading in the values of the floating keypad's position, it has moved. |
| 936 | // If the values for the floating keypad position haven't been set, then don't specify |
| 937 | // the keypad as having moved. - Samir |
| 938 | if (D3EditState.float_keypad_x != -1) |
| 939 | D3EditState.float_keypad_moved = 1; |
| 940 | } |
| 941 | |
| 942 | // InitEditorState |
| 943 | // loads in editor state values and sets them |
| 944 | void CEditorApp::InitEditorState() { |
| 945 | float scr_aspect_x, scr_aspect_y; |
| 946 | |
| 947 | scr_aspect_x = ((float)GetSystemMetrics(SM_CXSCREEN)) / ((float)EDITOR_RESOLUTION_X); |
| 948 | scr_aspect_y = ((float)GetSystemMetrics(SM_CYSCREEN)) / ((float)EDITOR_RESOLUTION_Y); |
| 949 | |
| 950 | // Initialize all variables to zero |
| 951 | memset(&D3EditState, 0, sizeof(d3edit_state)); |
| 952 | |
| 953 | // Initialize a bunch of non-zero variables in case there are no variables in the registry |
| 954 | |
| 955 | D3EditState.texscr_visible = 1; |
| 956 | D3EditState.texscr_x = 0; |
| 957 | D3EditState.texscr_y = 0; |
| 958 | D3EditState.texscr_w = (int)(scr_aspect_x * ((float)TEXSCREEN_WIDTH)); |
| 959 | D3EditState.texscr_h = (int)(scr_aspect_y * ((float)TEXSCREEN_HEIGHT)); |
| 960 | |
| 961 | D3EditState.wirescr_visible = 1; |
| 962 | D3EditState.wirescr_x = 20; |
| 963 | D3EditState.wirescr_y = 20; |
| 964 | D3EditState.wirescr_w = (int)(scr_aspect_x * ((float)WIRESCREEN_WIDTH)); |
| 965 | D3EditState.wirescr_h = (int)(scr_aspect_y * ((float)WIRESCREEN_HEIGHT)); |
| 966 | |
| 967 | D3EditState.keypad_visible = 1; |
| 968 | D3EditState.keypad_current = TAB_TEXTURE_KEYPAD; |
| 969 | |
| 970 | D3EditState.float_keypad_moved = 0; |
| 971 | D3EditState.float_keypad_x = -1; |
| 972 | D3EditState.float_keypad_y = -1; |
| 973 | D3EditState.float_keypad_w = -1; |
| 974 | D3EditState.float_keypad_h = -1; |
| 975 | |
| 976 | D3EditState.objmodeless_x = GetSystemMetrics(SM_CXSCREEN) / 2; |
| 977 | D3EditState.objmodeless_y = GetSystemMetrics(SM_CYSCREEN) / 2; |
| 978 | D3EditState.objmodeless_on = false; |
| 979 | |
| 980 | D3EditState.tile_views = 1; |
| 981 | |
| 982 | D3EditState.current_obj_type = OBJ_POWERUP; |
| 983 | D3EditState.current_powerup = 0; |
| 984 | D3EditState.current_building = 0; |
| 985 | D3EditState.current_clutter = 0; |
| 986 | D3EditState.current_door = 0; |
| 987 | |
| 988 | D3EditState.current_room = -1; |
| 989 | |
| 990 | D3EditState.node_movement_inc = 1.0f; |
| 991 | |
| 992 | // preferences |
| 993 | D3EditState.game_render_mode = GM_WINDOWED; |
| 994 | D3EditState.fullscreen_debug_state = false; |
| 995 | D3EditState.object_move_axis = OBJMOVEAXIS_XY; |
| 996 | D3EditState.texscale = 1.0; |
| 997 | D3EditState.joy_slewing = true; |
| 998 | D3EditState.objects_in_wireframe = true; |
| 999 | |
| 1000 | Editor_active = true; |
| 1001 | } |
| 1002 | |
| 1003 | CDocument *CEditorApp::OpenDocumentFile(LPCTSTR lpszFileName) { |
| 1004 | // TODO: Add your specialized code here and/or call the base class |
| 1005 | if (main_doc) |
| 1006 | if (main_doc->GetPathName() == lpszFileName) |
| 1007 | if (Mine_changed) { |
| 1008 | // we are trying to revert to on-disk level, so we should prompt the user if he wants |
| 1009 | // this, and then if so to close the current document |
| 1010 | if (AfxMessageBox("This will discard all changes made to the level.\nDo you want to continue?", MB_YESNO) == |
| 1011 | IDYES) { |
| 1012 | mprintf(0, "Restoring %s...\n", lpszFileName); |
| 1013 | main_doc->OnOpenDocument(lpszFileName); |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | return CWinApp::OpenDocumentFile(lpszFileName); |
| 1018 | } |
| 1019 | |
| 1020 | // pause and resume |
| 1021 | |
| 1022 | void CEditorApp::pause() { |
| 1023 | m_Paused = TRUE; |
| 1024 | ddio_KeyFlush(); |
| 1025 | ddio_Suspend(); |
| 1026 | } |
| 1027 | |
| 1028 | bool Stay_paused = 0; |
| 1029 | |
| 1030 | void CEditorApp::resume() { |
| 1031 | if (Stay_paused) |
| 1032 | return; |
| 1033 | |
| 1034 | m_Paused = FALSE; |
| 1035 | ddio_Resume(); |
| 1036 | ddio_KeyFlush(); |
| 1037 | } |
| 1038 | |
| 1039 | /////////////////////////////////////////////////////////////////////////////// |
| 1040 | // |
| 1041 | // Supplementary editor functions |
| 1042 | // |
| 1043 | /////////////////////////////////////////////////////////////////////////////// |
| 1044 | |
| 1045 | bool FileDialog(CWnd *wnd, BOOL open, LPCTSTR filter, char *pathname, char *initialdir, int dirlen); |
| 1046 | |
| 1047 | // Function to print to an edit box |
| 1048 | // Parameters: dlg - the dialog that the edit box is in |
| 1049 | // id - the ID of the edit box |
| 1050 | // fmt - printf-style text & arguments |
| 1051 | void PrintToDlgItem(CDialog *dlg, int id, char *fmt, ...) { |
| 1052 | std::va_list arglist; |
| 1053 | char str[3000]; |
| 1054 | int len; |
| 1055 | CEdit *ebox; |
| 1056 | |
| 1057 | va_start(arglist, fmt); |
| 1058 | len = std::vsnprintf(str, 3000, fmt, arglist); |
| 1059 | va_end(arglist); |
| 1060 | ASSERT(len < 3000); |
| 1061 | |
| 1062 | ebox = (CEdit *)dlg->GetDlgItem(id); |
| 1063 | if (ebox == NULL) { |
| 1064 | Int3(); |
| 1065 | return; |
| 1066 | } |
| 1067 | ebox->SetWindowText(str); |
| 1068 | } |
| 1069 | |
| 1070 | // A quick way to use an openfiledialog/savefiledialog. |
| 1071 | // wnd = parent window |
| 1072 | // filter = a C string containing the extensions to look for in filenames when browsing (in MFC format) |
| 1073 | // pathname = buffer where full pathname will be stored of file opened/saved |
| 1074 | // initialdir = what directory to start browsing from. will also contain the new browsing directory if |
| 1075 | // user changed directories. |
| 1076 | // dirlen = max length of initialdir buffer including terminating null. |
| 1077 | bool OpenFileDialog(CWnd *wnd, LPCTSTR filter, char *pathname, char *initialdir, int dirlen) { |
| 1078 | return FileDialog(wnd, TRUE, filter, pathname, initialdir, dirlen); |
| 1079 | } |
| 1080 | |
| 1081 | bool SaveFileDialog(CWnd *wnd, LPCTSTR filter, char *pathname, char *initialdir, int dirlen) { |
| 1082 | return FileDialog(wnd, FALSE, filter, pathname, initialdir, dirlen); |
| 1083 | } |
| 1084 | |
| 1085 | bool FileDialog(CWnd *wnd, BOOL open, LPCTSTR filter, char *pathname, char *initialdir, int dirlen) { |
| 1086 | CFileDialog *dlg; |
| 1087 | char saved_path[_MAX_PATH]; |
| 1088 | char search_path[_MAX_PATH]; |
| 1089 | |
| 1090 | theApp.pause(); |
| 1091 | |
| 1092 | if (open) |
| 1093 | dlg = new CFileDialog(TRUE, 0, 0, OFN_FILEMUSTEXIST, filter, wnd); |
| 1094 | else |
| 1095 | dlg = new CFileDialog(FALSE, 0, 0, OFN_OVERWRITEPROMPT, filter, wnd); |
| 1096 | |
| 1097 | // save current directory and set new directory. |
| 1098 | if (initialdir) { |
| 1099 | ASSERT(dirlen > 0); |
| 1100 | ddio_GetWorkingDir(saved_path, _MAX_PATH); |
| 1101 | if (initialdir[0]) { |
| 1102 | lstrcpy(search_path, initialdir); |
| 1103 | dlg->m_ofn.lpstrInitialDir = search_path; |
| 1104 | } |
| 1105 | } |
| 1106 | |
| 1107 | if (dlg->DoModal() == IDCANCEL) { |
| 1108 | if (initialdir) |
| 1109 | ddio_SetWorkingDir(saved_path); |
| 1110 | theApp.resume(); |
| 1111 | delete dlg; |
| 1112 | return false; |
| 1113 | } |
| 1114 | |
| 1115 | // we have a filename now. |
| 1116 | lstrcpy(pathname, dlg->GetPathName()); |
| 1117 | |
| 1118 | // restore old current directory and save current directory into initialdir. |
| 1119 | if (initialdir) { |
| 1120 | ddio_GetWorkingDir(initialdir, dirlen); |
| 1121 | ddio_SetWorkingDir(saved_path); |
| 1122 | } |
| 1123 | |
| 1124 | theApp.resume(); |
| 1125 | |
| 1126 | delete dlg; |
| 1127 | return true; |
| 1128 | } |
| 1129 | |
| 1130 | int CALC_PIXELS_WITH_ASPECTX(int pixels) { |
| 1131 | float scr_aspect_x = ((float)GetSystemMetrics(SM_CXSCREEN)) / ((float)EDITOR_RESOLUTION_X); |
| 1132 | return (int)(scr_aspect_x * (float)(pixels)); |
| 1133 | } |
| 1134 | |
| 1135 | int CALC_PIXELS_WITH_ASPECTY(int pixels) { |
| 1136 | float scr_aspect_y = ((float)GetSystemMetrics(SM_CYSCREEN)) / ((float)EDITOR_RESOLUTION_Y); |
| 1137 | return (int)(scr_aspect_y * (float)(pixels)); |
| 1138 | } |
| 1139 | |
| 1140 | // Move the viewer object. This should be called whenever the viewer object is moved |
| 1141 | void MoveViewer(vector *pos, int roomnum, matrix *orient) { |
| 1142 | bool was_outside = (OBJECT_OUTSIDE(Viewer_object) != 0); |
| 1143 | |
| 1144 | ObjSetPos(Viewer_object, pos, roomnum, orient, false); |
| 1145 | |
| 1146 | if (OBJECT_OUTSIDE(Viewer_object) && !was_outside) |
| 1147 | SetViewMode(VM_TERRAIN); |
| 1148 | |
| 1149 | if (!OBJECT_OUTSIDE(Viewer_object) && was_outside) |
| 1150 | SetViewMode(VM_MINE); |
| 1151 | } |