| 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/TextureGrWnd.cpp $ |
| 21 | * $Revision: 1.1.1.1 $ |
| 22 | * $Date: 2003-08-26 03:57:39 $ |
| 23 | * $Author: kevinb $ |
| 24 | * |
| 25 | * Texture view of mine. |
| 26 | * |
| 27 | * $Log: not supported by cvs2svn $ |
| 28 | * |
| 29 | * 122 9/30/99 6:35p Matt |
| 30 | * Added code to scale the UVs of a texture based on the size of the |
| 31 | * texture when the texture is applied to a face. This will cause the |
| 32 | * applied texture to have the make 3D texel size at the old texture. |
| 33 | * |
| 34 | * 121 4/22/99 11:41a Jason |
| 35 | * fixed right clicking problem (temp fix) |
| 36 | * |
| 37 | * 120 4/19/99 6:55p Jason |
| 38 | * fixed satellite grabbing problem |
| 39 | * |
| 40 | * 119 4/18/99 10:55p Chris |
| 41 | * Added ignore own concussive blasts |
| 42 | * |
| 43 | * 118 4/18/99 5:42a Chris |
| 44 | * Added the FQ_IGNORE_RENDER_THROUGH_PORTALS flag |
| 45 | * |
| 46 | * 117 4/15/99 5:49p Chris |
| 47 | * Fixed a bug with rendering the BOAPath nodes |
| 48 | * |
| 49 | * 116 4/14/99 3:13p Chris |
| 50 | * Beginning to add BoaNode stuff |
| 51 | * |
| 52 | * 115 4/03/99 7:39p Matt |
| 53 | * Don't allow player objects to be given names. |
| 54 | * |
| 55 | * 114 3/27/99 7:10p Matt |
| 56 | * Strip leading & trailing spaces before check for duplicate names. |
| 57 | * |
| 58 | * 113 3/02/99 5:54p Jason |
| 59 | * fixed right mouse clicking with opengl |
| 60 | * |
| 61 | * 112 3/01/99 10:39a Matt |
| 62 | * Strip leading and trailing spaces from object, trigger, and room names |
| 63 | * on level load and when the names are entered. |
| 64 | * |
| 65 | * 111 2/28/99 10:40p Matt |
| 66 | * Check for name already in use when entering a name. |
| 67 | * |
| 68 | * 110 2/21/99 4:20p Matt |
| 69 | * Added SoundSource objects (and reformatted parts of the object header |
| 70 | * files). |
| 71 | * |
| 72 | * 109 2/19/99 12:04p Jason |
| 73 | * took out sky band |
| 74 | * |
| 75 | * 108 2/17/99 7:06p Kevin |
| 76 | * |
| 77 | * 107 2/17/99 5:47p Dan |
| 78 | * fixed dumb bug |
| 79 | * |
| 80 | * 106 2/17/99 1:05p Jason |
| 81 | * revamped object/face/terrain selection code |
| 82 | * |
| 83 | * 105 2/10/99 5:49p Dan |
| 84 | * fixed fog bug |
| 85 | * |
| 86 | * 104 2/09/99 12:25p Jason |
| 87 | * fixed dumb bug |
| 88 | * |
| 89 | * 103 2/09/99 12:16p Jason |
| 90 | * fixed postrender problem |
| 91 | * |
| 92 | * 102 2/09/99 11:36a Dan |
| 93 | * error checking (m_last_start_rooom invalid, initialized it) Samir |
| 94 | * |
| 95 | * 101 2/09/99 9:59a Chris |
| 96 | * Quick compile patch and changed code to use BOA_IsVisible() |
| 97 | * |
| 98 | * 100 2/08/99 6:39p Jason |
| 99 | * first pass at new indoor engine |
| 100 | * |
| 101 | * 99 2/03/99 1:10p Matt |
| 102 | * Changed the paletted room current faces to be stored in a seperate |
| 103 | * array, instead of in the room structure. |
| 104 | * |
| 105 | * 98 2/01/99 5:47p Nate |
| 106 | * Implemented Editing/Adding of Dallas Scripts |
| 107 | * |
| 108 | * 97 2/01/99 4:24p Matt |
| 109 | * Added Edit Script and New Script (though they don't do anything yet) to |
| 110 | * object right-click dialog, and deleted Copy UID and Properties. |
| 111 | * |
| 112 | * 96 1/27/99 1:20p Jason |
| 113 | * made r key rotate the terrain texture |
| 114 | * |
| 115 | * 95 1/24/99 12:37a Jeff |
| 116 | * removed compile warnings |
| 117 | * |
| 118 | * 94 1/22/99 8:54p Jeff |
| 119 | * added custom-default script overrides |
| 120 | * |
| 121 | * 93 1/22/99 3:59p Jason |
| 122 | * added 256x256 textures to help with terrain skies |
| 123 | * |
| 124 | * 92 1/20/99 10:50a Jason |
| 125 | * added new terrain |
| 126 | * |
| 127 | * 91 1/08/99 2:56p Samir |
| 128 | * Ripped out OSIRIS1. |
| 129 | * |
| 130 | * 90 12/22/98 2:05p Matt |
| 131 | * Mark the world as changed when an object name is changed. |
| 132 | * |
| 133 | * 89 12/21/98 11:30p Matt |
| 134 | * Added names for objects |
| 135 | * |
| 136 | * 88 10/22/98 10:33a Sean |
| 137 | * fixed windowed opengl lighting |
| 138 | * |
| 139 | * 87 10/18/98 2:06p Matt |
| 140 | * Bail out of FindRoomFace if the starting room isn't in use any more. |
| 141 | * This can happen if you click on the texture window after loading a |
| 142 | * level or doing a New but before the new level has a chance to render. |
| 143 | * |
| 144 | * 86 10/06/98 12:27p Sean |
| 145 | * More state changes |
| 146 | * |
| 147 | * 85 10/06/98 11:29a Jason |
| 148 | * fixed state limited WindowGL |
| 149 | * |
| 150 | * 84 10/02/98 5:31p Jason |
| 151 | * tweaks for statelimited stuff |
| 152 | * |
| 153 | * 83 10/02/98 4:24p Jason |
| 154 | * more attempts to fix Riva128 opengl stuttering |
| 155 | * |
| 156 | * 82 10/02/98 4:22p Jason |
| 157 | * made multipass turn off for gl rendering |
| 158 | * |
| 159 | * 81 10/01/98 10:39a Luke |
| 160 | * FROM JASON: Attempted to fix GL problem.... |
| 161 | * |
| 162 | * 80 9/30/98 10:25a Jason |
| 163 | * another attempt to the get the OpenGL window thing working reliably... |
| 164 | * |
| 165 | * 79 9/18/98 1:27p Jason |
| 166 | * cleaned up renderer initting |
| 167 | * |
| 168 | * 78 8/15/98 5:04p Matt |
| 169 | * Added code to copy a texture & UVs from one face to another |
| 170 | * |
| 171 | * 77 7/21/98 12:04p Jason |
| 172 | * V key now tells if the marked room and current room can see each other |
| 173 | * |
| 174 | * 76 6/16/98 3:04p Jason |
| 175 | * fixed framecount bug |
| 176 | * |
| 177 | * 75 6/10/98 12:23p Jason |
| 178 | * added new skies |
| 179 | * |
| 180 | * 74 6/09/98 6:16p Jason |
| 181 | * added some features for windowed opengl |
| 182 | * |
| 183 | * 73 6/09/98 4:47p Jason |
| 184 | * added windowed openGL mode |
| 185 | * |
| 186 | * 72 6/04/98 6:16p Jason |
| 187 | * added terrain occlusion system |
| 188 | * |
| 189 | * 71 5/26/98 7:01p Samir |
| 190 | * new script selection technique that knows what list of scripts to |
| 191 | * choose from for an object. |
| 192 | * |
| 193 | * 70 5/04/98 3:23p Samir |
| 194 | * only select custom scripts for right clicking. |
| 195 | * |
| 196 | * 69 5/01/98 3:51p Jason |
| 197 | * sped up terrain rendering by precaching all megacell lod bitmaps |
| 198 | * |
| 199 | * 68 5/30/98 10:16p Chris |
| 200 | * Fixed some bad spelling |
| 201 | * |
| 202 | * 67 4/21/98 2:43p Matt |
| 203 | * Added system to disable render updates while deleting large numbers of |
| 204 | * rooms, since the mine is not stable until this operation is done. |
| 205 | * |
| 206 | * 66 4/21/98 12:16a Samir |
| 207 | * Hopefully if you change script definition, it's reflected as you edit |
| 208 | * it. |
| 209 | * |
| 210 | * 65 4/16/98 10:42a Matt |
| 211 | * Made texture propagation work across rooms. |
| 212 | * |
| 213 | * 64 3/12/98 7:30p Chris |
| 214 | * Added ObjSetOrient |
| 215 | * |
| 216 | * 63 3/02/98 4:03p Samir |
| 217 | * Simplied script editing and selection code. |
| 218 | * |
| 219 | * 62 2/25/98 4:06p Samir |
| 220 | * Isolated parameter passing data functions. |
| 221 | * |
| 222 | * 61 2/24/98 1:50p Jason |
| 223 | * added V key to check distance from plane for vertices |
| 224 | * |
| 225 | * 60 2/10/98 12:25p Samir |
| 226 | * m_StartFlip should be rest when flip begins. |
| 227 | * |
| 228 | * 59 2/10/98 10:48a Matt |
| 229 | * Moved editor code from gamepath.cpp to epath.cpp |
| 230 | * |
| 231 | * 58 2/09/98 6:06p Matt |
| 232 | * Made Render_all_external_rooms not affect Room View |
| 233 | * |
| 234 | * 57 1/30/98 6:05p Matt |
| 235 | * Use new function to set current editor object |
| 236 | * |
| 237 | * 56 1/26/98 6:31p Chris |
| 238 | * User define paths now render in mine and terrain views |
| 239 | * |
| 240 | * 55 1/26/98 4:33p Samir |
| 241 | * Added ability to copy object ids. |
| 242 | * |
| 243 | * 54 1/23/98 3:06p Samir |
| 244 | * Script selection with parameters. |
| 245 | * |
| 246 | * 53 1/20/98 4:12p Samir |
| 247 | * New script housekeeping system. |
| 248 | * |
| 249 | * 52 1/19/98 6:20p Samir |
| 250 | * Rightclicking brings up menu in terrain. |
| 251 | * |
| 252 | * 51 1/16/98 12:41p Matt |
| 253 | * Took out old debug/test code |
| 254 | * |
| 255 | * 50 1/15/98 12:42p Jason |
| 256 | * big fix for terrain sky rendering |
| 257 | * |
| 258 | * 49 1/07/98 4:19p Jason |
| 259 | * added dome to terrain sky |
| 260 | * |
| 261 | * 48 1/06/98 1:27p Matt |
| 262 | * Cleaned up interfaces to rendering routines, deleted unused code, etc. |
| 263 | * |
| 264 | * 47 1/02/98 6:40p Matt |
| 265 | * User renderer library (instead of viewport) functions to draw lines and |
| 266 | * to set and read pixels. Also made FindRoomFace() work without |
| 267 | * Render_viewport. |
| 268 | * |
| 269 | * 46 12/29/97 5:44p Samir |
| 270 | * Took out references to grViewport and old 2d library. |
| 271 | * |
| 272 | * 45 12/19/97 12:29p Samir |
| 273 | * Oops. |
| 274 | * |
| 275 | * 44 12/19/97 11:25a Samir |
| 276 | * g3_StartFrame and g3_EndFrame replaced by EditorStartFrame and |
| 277 | * EditorEndFrame |
| 278 | * |
| 279 | * 43 12/17/97 5:26p Jason |
| 280 | * added support for selectable wraparound sky |
| 281 | * |
| 282 | * 42 12/01/97 4:20p Jason |
| 283 | * shadow and lighting changes |
| 284 | * |
| 285 | * 41 11/21/97 5:33p Jason |
| 286 | * print light value when clicking on terrain cell |
| 287 | * |
| 288 | * 40 11/17/97 8:33p Jason |
| 289 | * fixed bug with object selection introduced by last rev |
| 290 | * |
| 291 | * 39 11/17/97 6:13p Mark |
| 292 | * allowed object 0 to be selected |
| 293 | * |
| 294 | * 38 11/03/97 7:02p Matt |
| 295 | * Added better warning message |
| 296 | * |
| 297 | * 37 10/31/97 12:14p Jason |
| 298 | * do a texture screen update after placing a new satellite image |
| 299 | * |
| 300 | * 36 9/30/97 2:12p Samir |
| 301 | * Fully implemeted the Object Script Properties dialog. |
| 302 | * |
| 303 | * 35 9/22/97 6:18p Matt |
| 304 | * Removed include of stub.h |
| 305 | * |
| 306 | * 34 9/17/97 1:00p Samir |
| 307 | * Took out Room_engine and all segment references I could find. |
| 308 | * |
| 309 | * 33 9/16/97 6:32p Jason |
| 310 | * made texture selection on terrain print relevant info |
| 311 | * |
| 312 | * 32 9/06/97 3:21p Matt |
| 313 | * Reset cur portal when room changes |
| 314 | * |
| 315 | * 31 9/03/97 8:00p Samir |
| 316 | * Implemented most of the fixes for the object moving system. |
| 317 | * |
| 318 | * 30 9/02/97 2:17p Samir |
| 319 | * Move objects in Terrain now. |
| 320 | * |
| 321 | * 29 8/29/97 1:51p Samir |
| 322 | * When mouse down in an object, invoke ObjectMoveManager |
| 323 | * |
| 324 | * 28 8/28/97 11:53a Matt |
| 325 | * Don't try to propagate from a face to itself |
| 326 | * |
| 327 | * 27 8/27/97 5:19p Jason |
| 328 | * made ShowRadProgress fill the entire texture window |
| 329 | * |
| 330 | * 26 8/26/97 4:37p Jason |
| 331 | * added floating point hemicube rasterizer, plus "heat" visualization |
| 332 | * |
| 333 | * 25 8/22/97 10:16a Matt |
| 334 | * When change curroom & curface, reset curvert & curedge also |
| 335 | * |
| 336 | * 24 8/22/97 10:15a Jason |
| 337 | * Added error checking to ShowRadView |
| 338 | * |
| 339 | * 23 8/18/97 5:57p Jason |
| 340 | * made radiosity better |
| 341 | * |
| 342 | * 22 8/01/97 4:53p Jason |
| 343 | * made a more general PropagateTextureToFace function call |
| 344 | * |
| 345 | * 21 7/29/97 12:07p Matt |
| 346 | * Took out texturing in room view, & made selecting a face in room view |
| 347 | * not change the global current room/face |
| 348 | * |
| 349 | * 20 7/24/97 6:11p Matt |
| 350 | * Created symbolic constant for default zoom, and used it every place |
| 351 | * that specifies zoom |
| 352 | * |
| 353 | * 19 7/22/97 7:08p Matt |
| 354 | * Cleaned up D3EditState, moving some vars in and some out, and renaming |
| 355 | * and changing a few others |
| 356 | * |
| 357 | * 18 7/20/97 7:37p Jason |
| 358 | * added new sky |
| 359 | * |
| 360 | * 17 7/18/97 5:49p Jason |
| 361 | * flag room changed is you change it |
| 362 | * |
| 363 | * 16 7/17/97 3:00p Jason |
| 364 | * changed "moons" to be called satellites since we're going to have suns |
| 365 | * and other things in orbit |
| 366 | * |
| 367 | * |
| 368 | * 15 7/16/97 5:20p Jason |
| 369 | * implemented selection of moons with mouse click |
| 370 | * |
| 371 | * 14 7/16/97 4:07p Jason |
| 372 | * fixed all the remaining drop-out bugs |
| 373 | * |
| 374 | * 13 7/15/97 4:19p Jason |
| 375 | * added object focus for terrain |
| 376 | * |
| 377 | * 39 6/30/97 3:54p Jeff |
| 378 | * Add object properties dialog |
| 379 | * |
| 380 | * 38 6/30/97 2:31p Jason |
| 381 | * took out room rendering from the mine-segment rendering loop |
| 382 | * |
| 383 | * 37 6/30/97 1:30p Jason |
| 384 | * added netherspace stuff |
| 385 | * |
| 386 | * 36 6/30/97 12:33p Jeff |
| 387 | * Added message map and support for right-click popup menu |
| 388 | * |
| 389 | * 35 6/30/97 11:34a Jeff |
| 390 | * |
| 391 | * 34 6/27/97 5:19p Jeff |
| 392 | * |
| 393 | * 33 6/27/97 2:49p Jason |
| 394 | * added hacked way to change textures for rooms (temporary) |
| 395 | * |
| 396 | * 32 6/26/97 4:55p Jason |
| 397 | * fixed dumb bug |
| 398 | * |
| 399 | * 31 6/26/97 4:45p Jason |
| 400 | * added control_right_click function for box selection |
| 401 | * |
| 402 | * 30 6/26/97 4:06p Jason |
| 403 | * no collision detection if Flat_terrain is set |
| 404 | * |
| 405 | * 29 6/25/97 5:30p Jason |
| 406 | * added code to readin/display a room |
| 407 | * |
| 408 | * 28 6/06/97 4:57p Jason |
| 409 | * more nifty megacell/tmap2 features |
| 410 | * |
| 411 | * 27 6/06/97 4:33p Jason |
| 412 | * added cool stuff for megacells |
| 413 | * |
| 414 | * 26 6/05/97 6:58p Jason |
| 415 | * added more megacell functionality |
| 416 | * |
| 417 | * 25 5/22/97 5:15p Jason |
| 418 | * added tmap2 capability to the terrain |
| 419 | * |
| 420 | * 24 5/15/97 3:28a Jason |
| 421 | * tried to get subwindow clearing to work with terrain - but it won't |
| 422 | * until samir fixes lock_clear |
| 423 | * |
| 424 | * 23 5/08/97 7:46p Matt |
| 425 | * Added called_from_terrain parm for RenderMine() |
| 426 | * |
| 427 | * 22 5/08/97 6:43p Jason |
| 428 | * added support for terrain/mine reentry handling |
| 429 | * |
| 430 | * 21 5/05/97 4:47p Jason |
| 431 | * made terrain and mine rendering work without explicit calls to |
| 432 | * g3_Startframe in their main function calls |
| 433 | * This allows us to integrate mine/terrain engines nicely |
| 434 | * |
| 435 | * 20 4/09/97 2:00p Jason |
| 436 | * moved DrawAllPaths function to gamepath where it belongs |
| 437 | * |
| 438 | * 19 4/08/97 10:42a Jason |
| 439 | * implemented path following interface |
| 440 | * |
| 441 | * 18 4/02/97 3:24p Jason |
| 442 | * changed Viewer_moved back to TV_changed because it didn't do what I |
| 443 | * thought it would do, namely only update the textured view! |
| 444 | * |
| 445 | * 17 4/02/97 2:48p Jason |
| 446 | * changed TV_changed to viewer move to reforce drawing of textured view, |
| 447 | * but not wireframe |
| 448 | * |
| 449 | * 16 3/31/97 5:58p Matt |
| 450 | * Revamped mine update flags |
| 451 | * |
| 452 | * 15 3/20/97 11:55a Jason |
| 453 | * changes for terrain editing/drawing |
| 454 | * |
| 455 | * 14 3/07/97 4:18p Jason |
| 456 | * implemented terrain functionality in the editor |
| 457 | * |
| 458 | * 13 2/28/97 9:35a Matt |
| 459 | * Added code to select objects by clicking on them in the texture window. |
| 460 | * |
| 461 | * 12 2/27/97 4:26p Matt |
| 462 | * Fixed curseg selection status messages |
| 463 | * |
| 464 | * 11 2/26/97 7:35p Samir |
| 465 | * Moved TextureGrWnd.h after stdafx.h to get rid of warning and errors. |
| 466 | * |
| 467 | * 10 2/20/97 5:37p Samir |
| 468 | * SHIFT + LEFTBUTTONDOWN = Apply texture. |
| 469 | * |
| 470 | * 9 2/19/97 11:06a Samir |
| 471 | * Only flip screen if we rendered but did not hit the left button down |
| 472 | * key to prevent green screen flash. |
| 473 | * |
| 474 | * 8 2/18/97 7:57p Matt |
| 475 | * Added code to select a segment by clicking on it in the texture-mapped |
| 476 | * window |
| 477 | * |
| 478 | * 7 2/03/97 8:01p Matt |
| 479 | * New name and parms for render function |
| 480 | * |
| 481 | * 6 2/03/97 5:20p Samir |
| 482 | * Added gr.h header |
| 483 | * |
| 484 | * 5 1/30/97 6:25p Samir |
| 485 | * Implemented a non-working caption bar system and made some changes for |
| 486 | * Jason. |
| 487 | * |
| 488 | * 4 1/23/97 4:56p Samir |
| 489 | * Handles saving screen positions of windows and tileability. |
| 490 | * |
| 491 | * 3 1/21/97 12:42p Samir |
| 492 | * Floatable-resizable views |
| 493 | * |
| 494 | * $NoKeywords: $ |
| 495 | */ |
| 496 | |
| 497 | #include "stdafx.h" |
| 498 | |
| 499 | #include "TextureGrWnd.h" |
| 500 | |
| 501 | #include "application.h" |
| 502 | #include "editor.h" |
| 503 | #include "render.h" |
| 504 | #include "manage.h" |
| 505 | #include "gr.h" |
| 506 | #include "boa.h" |
| 507 | #include "gameloop.h" |
| 508 | #include "descent.h" |
| 509 | #include "terrain.h" |
| 510 | #include "HTexture.h" |
| 511 | #include "terraindialog.h" |
| 512 | #include "room.h" |
| 513 | #include "roomuvs.h" |
| 514 | #include "mainfrm.h" |
| 515 | #include <string.h> |
| 516 | #include "ObjMoveManager.h" |
| 517 | #include "lightmap_info.h" |
| 518 | #include "lightmap.h" |
| 519 | #include "EditLineDialog.h" |
| 520 | #include "CustDefaultScriptSelect.h" |
| 521 | #include "erooms.h" |
| 522 | #include "ebnode.h" |
| 523 | |
| 524 | #include <assert.h> |
| 525 | |
| 526 | #include "mono.h" |
| 527 | #include "3d.h" |
| 528 | #include "gr.h" |
| 529 | #include "ddio.h" |
| 530 | #include "epath.h" |
| 531 | #include "megacell.h" |
| 532 | #include "ObjectPropertiesDialog.h" |
| 533 | #include "ObjectClipboard.h" |
| 534 | #include "radiosity.h" |
| 535 | #include "hemicube.h" |
| 536 | #include "args.h" |
| 537 | #include "game.h" |
| 538 | #include "DallasMainDlg.h" |
| 539 | #include "postrender.h" |
| 540 | #include "SoundSourceDialog.h" |
| 541 | |
| 542 | #ifdef _DEBUG |
| 543 | #define new DEBUG_NEW |
| 544 | #undef THIS_FILE |
| 545 | static char THIS_FILE[] = __FILE__; |
| 546 | #endif |
| 547 | |
| 548 | // These defines are for the right-click popup menu |
| 549 | #define POPUP_PROPERTIES 0x60 |
| 550 | #define POPUP_DELETE 0x61 |
| 551 | #define POPUP_PASTE 0x62 |
| 552 | #define POPUP_CUT 0x63 |
| 553 | #define POPUP_COPY 0x64 |
| 554 | #define POPUP_COPYID 0x66 |
| 555 | #define POPUP_OBJNAME 0x69 |
| 556 | #define POPUP_EDITNAME 0x6a |
| 557 | #define POPUP_CUSTOMDEFAULTSCRIPT 0x6b |
| 558 | #define POPUP_EDITSCRIPT 0x6c |
| 559 | #define POPUP_NEWSCRIPT 0x6d |
| 560 | #define POPUP_SOUND 0x6e |
| 561 | |
| 562 | grViewport *rad_Viewport; |
| 563 | static int DoOpenGL = 0; |
| 564 | |
| 565 | ///////////////////////////////////////////////////////////////////////////// |
| 566 | // CTextureGrWnd |
| 567 | |
| 568 | CTextureGrWnd::CTextureGrWnd() : CGrWnd("TextureScreen") { |
| 569 | m_StartFlip = FALSE; |
| 570 | m_last_start_room = -1; |
| 571 | } |
| 572 | |
| 573 | CTextureGrWnd::~CTextureGrWnd() {} |
| 574 | |
| 575 | BEGIN_MESSAGE_MAP(CTextureGrWnd, CWnd) |
| 576 | //{{AFX_MSG_MAP(CTextureGrWnd) |
| 577 | ON_WM_SIZE() |
| 578 | ON_WM_PAINT() |
| 579 | ON_WM_DESTROY() |
| 580 | ON_WM_MOVE() |
| 581 | ON_WM_CREATE() |
| 582 | ON_WM_SYSCOMMAND() |
| 583 | ON_WM_NCACTIVATE() |
| 584 | ON_WM_NCPAINT() |
| 585 | ON_WM_LBUTTONDOWN() |
| 586 | ON_WM_MOUSEMOVE() |
| 587 | ON_WM_RBUTTONDOWN() |
| 588 | //}}AFX_MSG_MAP |
| 589 | END_MESSAGE_MAP() |
| 590 | |
| 591 | void DrawPlayerOnWireframe(); |
| 592 | |
| 593 | bool Disable_editor_rendering = 0; |
| 594 | static int first_time = 1; |
| 595 | |
| 596 | extern int Just_returned_from_game; |
| 597 | extern float Just_returned_time; |
| 598 | int Successive_count = 0; |
| 599 | |
| 600 | HWND save_wnd; |
| 601 | oeLnxApplication *app; |
| 602 | |
| 603 | void CTextureGrWnd::TexGrStartOpenGL() { |
| 604 | if (DoOpenGL) { |
| 605 | app = (oeLnxApplication *)Descent; |
| 606 | StateLimited = 1; |
| 607 | // TODO - hwnd from SDL windows |
| 608 | // save_wnd = (HWND)app->m_hWnd; |
| 609 | // app->m_hWnd = (HWnd)m_hWnd; |
| 610 | // rend_SetOpenGLWindowState (1,Descent,NULL); // LGT: not defined anymore |
| 611 | rend_ClearScreen(0); |
| 612 | StateLimited = 1; |
| 613 | UseMultitexture = 0; |
| 614 | NoLightmaps = false; |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | void CTextureGrWnd::TexGrStopOpenGL() { |
| 619 | if (DoOpenGL) { |
| 620 | // rend_SetOpenGLWindowState (0,Descent,NULL); // LGT: not defined anymore |
| 621 | // TODO - hwnd from SDL windows |
| 622 | // app->m_hWnd = (HWnd)save_wnd; |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | void CTextureGrWnd::Render() { |
| 627 | if (first_time) { |
| 628 | first_time = 0; |
| 629 | if (FindArg("-WindowGL")) |
| 630 | DoOpenGL = 1; |
| 631 | } |
| 632 | |
| 633 | if (DoOpenGL) { |
| 634 | if (Just_returned_from_game) { |
| 635 | Successive_count++; |
| 636 | if (Successive_count < 2) { |
| 637 | mprintf(0, "Not doing opengl!\n"); |
| 638 | DoOpenGL = 0; |
| 639 | first_time = 1; |
| 640 | } else { |
| 641 | Just_returned_from_game = 0; |
| 642 | Successive_count = 0; |
| 643 | } |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | if (Disable_editor_rendering) |
| 648 | return; |
| 649 | |
| 650 | FrameCount++; |
| 651 | |
| 652 | if (m_grScreen == NULL) |
| 653 | return; |
| 654 | if (m_grViewport == NULL) |
| 655 | return; |
| 656 | |
| 657 | rad_Viewport = m_grViewport; |
| 658 | |
| 659 | TexGrStartOpenGL(); |
| 660 | |
| 661 | ResetPostrenderList(); |
| 662 | // Reset fog |
| 663 | Num_fogged_rooms_this_frame = 0; |
| 664 | if (Editor_view_mode == VM_ROOM) { |
| 665 | if ((D3EditState.current_room == -1) || (Rooms[D3EditState.current_room].used < 1)) { |
| 666 | TexGrStopOpenGL(); |
| 667 | return; |
| 668 | } |
| 669 | |
| 670 | // Disable render-all-rooms in room view |
| 671 | bool save_RAER = Render_all_external_rooms; |
| 672 | Render_all_external_rooms = 0; |
| 673 | |
| 674 | // Render |
| 675 | TGWRenderMine(&Viewer_object->pos, &Viewer_object->orient, D3_DEFAULT_ZOOM, D3EditState.current_room); |
| 676 | |
| 677 | // Restore render-all-rooms state |
| 678 | Render_all_external_rooms = save_RAER; |
| 679 | } else if (Editor_view_mode == VM_TERRAIN) { |
| 680 | |
| 681 | if (GetFunctionMode() == EDITOR_MODE) { |
| 682 | DrawPlayerOnWireframe(); |
| 683 | if (!Flat_terrain && (Viewer_object->pos.y < GetTerrainGroundPoint(&Viewer_object->pos) + 5)) |
| 684 | Viewer_object->pos.y = GetTerrainGroundPoint(&Viewer_object->pos) + 5; |
| 685 | } |
| 686 | |
| 687 | StartEditorFrame(m_grViewport, &Viewer_object->pos, &Viewer_object->orient, D3_DEFAULT_ZOOM); |
| 688 | RenderTerrain(0); |
| 689 | // we need to save these for object movement. |
| 690 | g3_GetViewPosition(&m_ViewPos); |
| 691 | g3_GetViewMatrix(&m_ViewMatrix); |
| 692 | EndEditorFrame(); |
| 693 | |
| 694 | if (KEY_STATE(KEY_X)) { |
| 695 | vector pos; |
| 696 | float yval; |
| 697 | |
| 698 | ComputeTerrainSegmentCenter(&pos, (128 * TERRAIN_WIDTH) + 128); |
| 699 | yval = GetTerrainGroundPoint(&pos); |
| 700 | |
| 701 | pos.y = yval; |
| 702 | Viewer_object->pos = pos; |
| 703 | ObjSetOrient(Viewer_object, &Identity_matrix); |
| 704 | World_changed = 1; |
| 705 | } |
| 706 | } else // Mine view |
| 707 | { |
| 708 | TGWRenderMine(&Viewer_object->pos, &Viewer_object->orient, D3_DEFAULT_ZOOM, Viewer_object->roomnum); |
| 709 | } |
| 710 | |
| 711 | PostRender(Viewer_object->roomnum); |
| 712 | |
| 713 | // Draws all User Defined Paths |
| 714 | DrawAllPaths(m_grViewport, &Viewer_object->pos, &Viewer_object->orient, D3_DEFAULT_ZOOM); |
| 715 | EBNode_Draw(EBN_draw_type, m_grViewport, &Viewer_object->pos, &Viewer_object->orient, D3_DEFAULT_ZOOM); |
| 716 | |
| 717 | TexGrStopOpenGL(); |
| 718 | |
| 719 | m_StartFlip = TRUE; |
| 720 | } |
| 721 | |
| 722 | ///////////////////////////////////////////////////////////////////////////// |
| 723 | // CTextureGrWnd message handlers |
| 724 | |
| 725 | BOOL CTextureGrWnd::Create(RECT &rect, BOOL movable, CWnd *pParent) { |
| 726 | RECT new_rect; |
| 727 | DWORD dwstyle; |
| 728 | |
| 729 | dwstyle = (movable ? GRWND_STYLE : GRWND_STATIC_STYLE); |
| 730 | |
| 731 | ::CopyRect(&new_rect, &rect); |
| 732 | ::AdjustWindowRect(&new_rect, dwstyle, FALSE); |
| 733 | |
| 734 | // We want this window to start at rect.left, rect.top. |
| 735 | if (new_rect.left < rect.left) { |
| 736 | int offx; |
| 737 | offx = rect.left - new_rect.left; |
| 738 | new_rect.left += offx; |
| 739 | new_rect.right += offx; |
| 740 | } |
| 741 | if (new_rect.top < rect.top) { |
| 742 | int offy; |
| 743 | offy = rect.top - new_rect.top; |
| 744 | new_rect.top += offy; |
| 745 | new_rect.bottom += offy; |
| 746 | } |
| 747 | |
| 748 | ::CopyRect(&rect, &new_rect); |
| 749 | |
| 750 | m_grCreated = TRUE; |
| 751 | m_Movable = movable; |
| 752 | |
| 753 | lstrcpy(m_Name, "Texture"); |
| 754 | |
| 755 | ObjectInBuffer = false; |
| 756 | |
| 757 | return CWnd::Create(NULL, m_Name, dwstyle, rect, pParent, IDC_TEXTURE_WND); |
| 758 | } |
| 759 | |
| 760 | void CTextureGrWnd::OnSize(UINT nType, int cx, int cy) { |
| 761 | RECT rect; |
| 762 | char text[32]; |
| 763 | |
| 764 | CGrWnd::OnSize(nType, cx, cy); |
| 765 | |
| 766 | if (m_Movable) { // don't define these if this box is static |
| 767 | D3EditState.texscr_w = cx; |
| 768 | D3EditState.texscr_h = cy; |
| 769 | } |
| 770 | |
| 771 | GetClientRect(&rect); |
| 772 | sprintf(text, "Texture (%dx%d)", rect.right - rect.left, rect.bottom - rect.top); |
| 773 | lstrcpy(m_Name, text); |
| 774 | SetWindowText(m_Name); |
| 775 | } |
| 776 | |
| 777 | void CTextureGrWnd::OnPaint() { |
| 778 | CPaintDC dc(this); // device context for painting |
| 779 | |
| 780 | // Draw what's on the screen back page to the desktop |
| 781 | if (theApp.paused()) |
| 782 | return; |
| 783 | |
| 784 | if (m_StartFlip) { // do if a flip was signaled |
| 785 | m_StartFlip = FALSE; |
| 786 | |
| 787 | if (DoOpenGL) { |
| 788 | HWND save_wnd; |
| 789 | oeLnxApplication *app; |
| 790 | |
| 791 | app = (oeLnxApplication *)Descent; |
| 792 | |
| 793 | // save_wnd = (HWND)app->m_hWnd; |
| 794 | // app->m_hWnd = (HWnd)m_hWnd; |
| 795 | // rend_SetOpenGLWindowState (1,Descent,NULL); // LGT: not defined anymore |
| 796 | |
| 797 | rend_Flip(); |
| 798 | |
| 799 | // rend_SetOpenGLWindowState (0,Descent,NULL); // LGT: not defined anymore |
| 800 | // app->m_hWnd = (HWnd)save_wnd; |
| 801 | } else { |
| 802 | m_grScreen->flip(); |
| 803 | m_grViewport->clear(); |
| 804 | } |
| 805 | } |
| 806 | |
| 807 | // Do not call CWnd::OnPaint() for painting messages |
| 808 | if (!m_Movable) { // print out window title, since there is no caption |
| 809 | dc.SetBkMode(TRANSPARENT); |
| 810 | dc.SetTextColor(RGB(192, 192, 192)); |
| 811 | dc.TextOut(10, 10, m_Name, lstrlen(m_Name)); |
| 812 | // m_grViewport->puts(10,10, m_Name); |
| 813 | } |
| 814 | } |
| 815 | |
| 816 | void CTextureGrWnd::OnDestroy() { |
| 817 | // mprintf(0, "CTextureGrWnd::OnDestroy:: m_grScreen\n"); |
| 818 | CGrWnd::OnDestroy(); |
| 819 | theApp.textured_view = NULL; |
| 820 | } |
| 821 | |
| 822 | void CTextureGrWnd::OnMove(int x, int y) { |
| 823 | CGrWnd::OnMove(x, y); |
| 824 | |
| 825 | // Must do this to adjust window rect to view's client. |
| 826 | if (m_Movable) { |
| 827 | RECT rect; |
| 828 | GetWindowRect(&rect); |
| 829 | GetParent()->ScreenToClient(&rect); |
| 830 | D3EditState.texscr_x = rect.left; |
| 831 | D3EditState.texscr_y = rect.top; |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | int CTextureGrWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) { |
| 836 | if (CGrWnd::OnCreate(lpCreateStruct) == -1) |
| 837 | return -1; |
| 838 | |
| 839 | // TODO: Add your specialized creation code here |
| 840 | theApp.textured_view = this; |
| 841 | |
| 842 | return 0; |
| 843 | } |
| 844 | |
| 845 | void CTextureGrWnd::OnSysCommand(UINT nID, LPARAM lParam) { |
| 846 | // TODO: Add your message handler code here and/or call default |
| 847 | // take care of 'close' box for one thing |
| 848 | |
| 849 | switch (nID) { |
| 850 | case SC_CLOSE: |
| 851 | D3EditState.texscr_visible = 0; |
| 852 | break; |
| 853 | } |
| 854 | |
| 855 | CWnd::OnSysCommand(nID, lParam); |
| 856 | } |
| 857 | |
| 858 | BOOL CTextureGrWnd::OnNcActivate(BOOL bActive) { |
| 859 | // TODO: Add your message handler code here and/or call default |
| 860 | |
| 861 | return CGrWnd::OnNcActivate(bActive); |
| 862 | } |
| 863 | |
| 864 | void CTextureGrWnd::OnNcPaint() { CGrWnd::OnNcPaint(); } |
| 865 | |
| 866 | int Tracing_drops = 0; |
| 867 | int Drop_seg = 0; |
| 868 | |
| 869 | int CTextureGrWnd::TGWFindRoomFace(int x, int y, int *roomnum, int *facenum) { |
| 870 | /*if (m_last_start_room == -1) |
| 871 | return 0; |
| 872 | if (! Rooms[m_last_start_room].used) |
| 873 | return 0; |
| 874 | |
| 875 | int ret; |
| 876 | |
| 877 | StartEditorFrame(m_grViewport,&m_last_viewer_eye,&m_last_viewer_orient,m_last_zoom); |
| 878 | |
| 879 | ret = FindRoomFace(x,y,m_last_start_room,roomnum,facenum); |
| 880 | PostRender(Viewer_object->roomnum); |
| 881 | |
| 882 | EndEditorFrame();*/ |
| 883 | |
| 884 | return 0; |
| 885 | } |
| 886 | |
| 887 | int CTextureGrWnd::TGWFindLightmapFace(int x, int y, int *roomnum, int *facenum, int *lumel_num) { |
| 888 | /*if (! Rooms[m_last_start_room].used) |
| 889 | return 0; |
| 890 | |
| 891 | int ret; |
| 892 | |
| 893 | StartEditorFrame(m_grViewport,&m_last_viewer_eye,&m_last_viewer_orient,m_last_zoom); |
| 894 | |
| 895 | ret = FindLightmapFace(x,y,m_last_start_room,roomnum,facenum,lumel_num); |
| 896 | |
| 897 | EndEditorFrame();*/ |
| 898 | |
| 899 | return 0; |
| 900 | } |
| 901 | |
| 902 | void CTextureGrWnd::TGWRenderMine(vector *pos, matrix *orient, float zoom, int start_roomnum) { |
| 903 | if (start_roomnum < 0 || start_roomnum > MAX_ROOMS + MAX_PALETTE_ROOMS) |
| 904 | return; |
| 905 | |
| 906 | // save these vars for possible use by FindRoomFace() |
| 907 | m_last_viewer_eye = *pos; |
| 908 | m_last_viewer_orient = *orient; |
| 909 | m_last_zoom = zoom; |
| 910 | m_last_start_room = start_roomnum; |
| 911 | |
| 912 | StartEditorFrame(m_grViewport, pos, orient, zoom); |
| 913 | FrameCount++; |
| 914 | |
| 915 | RenderMine(start_roomnum, 0, 0); |
| 916 | PostRender(Viewer_object->roomnum); |
| 917 | |
| 918 | // we need to save these for object movement. |
| 919 | g3_GetViewPosition(&m_ViewPos); |
| 920 | g3_GetViewMatrix(&m_ViewMatrix); |
| 921 | |
| 922 | EndEditorFrame(); |
| 923 | } |
| 924 | |
| 925 | // Set the current object |
| 926 | void SelectObject(int objnum); |
| 927 | |
| 928 | void CTextureGrWnd::OnLButtonDown(UINT nFlags, CPoint point) { |
| 929 | TexGrStartOpenGL(); |
| 930 | |
| 931 | ResetPostrenderList(); |
| 932 | |
| 933 | if (Editor_view_mode == VM_ROOM) { |
| 934 | TSearch_found_type = -1; |
| 935 | TSearch_seg = -1; |
| 936 | TSearch_on = 1; |
| 937 | TSearch_x = point.x; |
| 938 | TSearch_y = point.y; |
| 939 | |
| 940 | TGWRenderMine(&Viewer_object->pos, &Viewer_object->orient, D3_DEFAULT_ZOOM, Viewer_object->roomnum); |
| 941 | |
| 942 | TSearch_on = 0; |
| 943 | |
| 944 | if (TSearch_found_type == TSEARCH_FOUND_MINE) { |
| 945 | Current_faces[TSearch_seg - FIRST_PALETTE_ROOM] = TSearch_face; |
| 946 | EditorStatus("Face %d selected.", TSearch_face); |
| 947 | State_changed = 1; |
| 948 | return; |
| 949 | } |
| 950 | } else if (Editor_view_mode == VM_TERRAIN) { |
| 951 | TSearch_found_type = -1; |
| 952 | TSearch_seg = -1; |
| 953 | TSearch_on = 1; |
| 954 | TSearch_x = point.x; |
| 955 | TSearch_y = point.y; |
| 956 | |
| 957 | StartEditorFrame(m_grViewport, &Viewer_object->pos, &Viewer_object->orient, D3_DEFAULT_ZOOM); |
| 958 | RenderTerrain(0); |
| 959 | PostRender(Viewer_object->roomnum); |
| 960 | EndEditorFrame(); |
| 961 | TSearch_on = 0; |
| 962 | if (TSearch_found_type != -1) { |
| 963 | |
| 964 | // Check for objects |
| 965 | if (TSearch_found_type == TSEARCH_FOUND_OBJECT) { |
| 966 | // Found an object |
| 967 | mprintf(0, "Found an object! objnum=%d\n", TSearch_seg); |
| 968 | SelectObject(TSearch_seg); |
| 969 | // start object moving if mouse down in an object. |
| 970 | ObjMoveManager.Start(this, m_grViewport->width(), m_grViewport->height(), &m_ViewPos, &m_ViewMatrix, point.x, |
| 971 | point.y); |
| 972 | } |
| 973 | |
| 974 | if (TSearch_found_type == TSEARCH_FOUND_SKY_DOME) { |
| 975 | if (nFlags & MK_SHIFT) { |
| 976 | Terrain_sky.dome_texture = D3EditState.texdlg_texture; |
| 977 | |
| 978 | World_changed = 1; |
| 979 | TV_changed = 1; |
| 980 | } |
| 981 | } |
| 982 | |
| 983 | // Check for satellite |
| 984 | if (TSearch_found_type == TSEARCH_FOUND_SATELLITE) { |
| 985 | if (nFlags & MK_SHIFT) { |
| 986 | Terrain_sky.satellite_texture[TSearch_seg] = D3EditState.texdlg_texture; |
| 987 | theApp.main_frame->m_TerrainDialog->SetCurrentMoon(TSearch_seg); |
| 988 | World_changed = 1; |
| 989 | TV_changed = 1; |
| 990 | } |
| 991 | |
| 992 | else { |
| 993 | theApp.main_frame->m_TerrainDialog->SetCurrentMoon(TSearch_seg); |
| 994 | if (KEY_STATE(KEY_G)) |
| 995 | D3EditState.texdlg_texture = Terrain_sky.satellite_texture[TSearch_seg]; |
| 996 | } |
| 997 | } |
| 998 | |
| 999 | if (TSearch_found_type == TSEARCH_FOUND_TERRAIN) { |
| 1000 | if (KEY_STATE(KEY_P)) { |
| 1001 | Tracing_drops = 1; |
| 1002 | Drop_seg = TSearch_seg; |
| 1003 | Terrain_tex_seg[Terrain_seg[Drop_seg].texseg_index].tex_index = 0; |
| 1004 | } else if (KEY_STATE(KEY_R)) { |
| 1005 | // Rotate this texture |
| 1006 | int val = Terrain_tex_seg[Terrain_seg[TSearch_seg].texseg_index].rotation & 0x0F; |
| 1007 | val++; |
| 1008 | val %= 4; |
| 1009 | Terrain_tex_seg[Terrain_seg[TSearch_seg].texseg_index].rotation &= ~0x0F; |
| 1010 | Terrain_tex_seg[Terrain_seg[TSearch_seg].texseg_index].rotation |= val; |
| 1011 | |
| 1012 | TV_changed = 1; |
| 1013 | } |
| 1014 | |
| 1015 | if (nFlags & MK_SHIFT) { |
| 1016 | |
| 1017 | Terrain_tex_seg[Terrain_seg[TSearch_seg].texseg_index].tex_index = D3EditState.texdlg_texture; |
| 1018 | TV_changed = 1; |
| 1019 | } else if (nFlags & MK_CONTROL) { |
| 1020 | if (TerrainSelected[TSearch_seg]) { |
| 1021 | TerrainSelected[TSearch_seg] = 0; |
| 1022 | Num_terrain_selected--; |
| 1023 | } else { |
| 1024 | TerrainSelected[TSearch_seg] = 1; |
| 1025 | Num_terrain_selected++; |
| 1026 | } |
| 1027 | TV_changed = 1; |
| 1028 | } else { |
| 1029 | memset(TerrainSelected, 0, TERRAIN_WIDTH * TERRAIN_DEPTH); |
| 1030 | EditorStatus("Cell %d selected. Light=%d Height=%.2f (%d). Texture=%s", TSearch_seg, |
| 1031 | Terrain_seg[TSearch_seg].l, Terrain_seg[TSearch_seg].y, Terrain_seg[TSearch_seg].ypos, |
| 1032 | GameTextures[Terrain_tex_seg[Terrain_seg[TSearch_seg].texseg_index].tex_index].name); |
| 1033 | TerrainSelected[TSearch_seg]++; |
| 1034 | Num_terrain_selected = 1; |
| 1035 | TV_changed = 1; |
| 1036 | } |
| 1037 | } |
| 1038 | } |
| 1039 | } else { |
| 1040 | int roomnum, facenum; |
| 1041 | |
| 1042 | // mprintf(0,"ButtonDown %d,%d\n",point.x,point.y); |
| 1043 | TSearch_found_type = -1; |
| 1044 | TSearch_seg = -1; |
| 1045 | TSearch_on = 1; |
| 1046 | TSearch_x = point.x; |
| 1047 | TSearch_y = point.y; |
| 1048 | |
| 1049 | TGWRenderMine(&Viewer_object->pos, &Viewer_object->orient, D3_DEFAULT_ZOOM, Viewer_object->roomnum); |
| 1050 | TSearch_on = 0; |
| 1051 | |
| 1052 | // this looks at the last frame rendered |
| 1053 | if (TSearch_found_type == TSEARCH_FOUND_OBJECT) { |
| 1054 | // Found a face or object |
| 1055 | m_StartFlip = FALSE; // unsignal flip. |
| 1056 | SelectObject(TSearch_seg); |
| 1057 | // start object moving if mouse down in an object. |
| 1058 | ObjMoveManager.Start(this, m_grViewport->width(), m_grViewport->height(), &m_ViewPos, &m_ViewMatrix, point.x, |
| 1059 | point.y); |
| 1060 | } else if (TSearch_found_type == TSEARCH_FOUND_MINE) { |
| 1061 | roomnum = TSearch_seg; |
| 1062 | facenum = TSearch_face; |
| 1063 | |
| 1064 | if (nFlags & MK_SHIFT) { // apply current texture to face |
| 1065 | HTextureApplyToRoomFace(&Rooms[TSearch_seg], TSearch_face, D3EditState.texdlg_texture); |
| 1066 | EditorStatus("Texture %d applied to room %d face %d\n", D3EditState.texdlg_texture, TSearch_seg, TSearch_face); |
| 1067 | World_changed = 1; |
| 1068 | } else if (KEY_STATE(KEY_J)) // apply texture, scaling UVs based on texture size |
| 1069 | { |
| 1070 | int old_width = bm_w(GetTextureBitmap(Rooms[TSearch_seg].faces[TSearch_face].tmap, 0), 0); |
| 1071 | int new_width = bm_w(GetTextureBitmap(D3EditState.texdlg_texture, 0), 0); |
| 1072 | HTextureApplyToRoomFace(&Rooms[TSearch_seg], TSearch_face, D3EditState.texdlg_texture); |
| 1073 | ScaleFaceUVs(&Rooms[TSearch_seg], TSearch_face, (float)old_width / new_width); |
| 1074 | EditorStatus("Texture %d applied to room %d face %d\n", D3EditState.texdlg_texture, TSearch_seg, TSearch_face); |
| 1075 | World_changed = 1; |
| 1076 | } else if (KEY_STATE(KEY_P)) { |
| 1077 | // P + Click = Propagate from current face |
| 1078 | if ((TSearch_seg == ROOMNUM(Curroomp)) && (TSearch_face == Curface)) |
| 1079 | EditorStatus("Cannot propagate from a face to itself."); |
| 1080 | else if (HTexturePropagateToFace(&Rooms[roomnum], facenum, Curroomp, Curface)) { |
| 1081 | EditorStatus("Texture propagated from %d:%d to %d:%d\n", ROOMNUM(Curroomp), Curface, roomnum, facenum); |
| 1082 | World_changed = 1; |
| 1083 | } else { |
| 1084 | OutrageMessageBox("Room:face %d:%d is not adjacent to Current room:face (%d:%d)", roomnum, facenum, |
| 1085 | ROOMNUM(Curroomp), Curface); |
| 1086 | return; |
| 1087 | } |
| 1088 | } else if (KEY_STATE(KEY_E)) { |
| 1089 | // C + Click = Copy uv values from marked face |
| 1090 | static int last_copy_marked_room = -1, last_copy_marked_face = -1; |
| 1091 | static int last_copy_room = -1, last_copy_face = -1; |
| 1092 | static int count; |
| 1093 | |
| 1094 | if (Markedroomp == NULL) { |
| 1095 | OutrageMessageBox("You must have a marked face for this operation."); |
| 1096 | return; |
| 1097 | } |
| 1098 | |
| 1099 | if ((roomnum == ROOMNUM(Markedroomp)) && (facenum == Markedface)) |
| 1100 | EditorStatus("Cannot copy from a face to itself."); |
| 1101 | else { |
| 1102 | if ((last_copy_marked_room == ROOMNUM(Markedroomp)) && (last_copy_marked_face == Markedface) && |
| 1103 | (last_copy_room == roomnum) && (last_copy_face == facenum)) |
| 1104 | count++; |
| 1105 | else { |
| 1106 | count = 0; |
| 1107 | last_copy_marked_room = ROOMNUM(Markedroomp); |
| 1108 | last_copy_marked_face = Markedface; |
| 1109 | last_copy_room = roomnum; |
| 1110 | last_copy_face = facenum; |
| 1111 | } |
| 1112 | |
| 1113 | if (HTextureCopyUVsToFace(&Rooms[roomnum], facenum, Markedroomp, Markedface, count)) { |
| 1114 | Rooms[roomnum].faces[facenum].tmap = Markedroomp->faces[Markedface].tmap; |
| 1115 | EditorStatus("Texture & UVs copied from %d:%d to %d:%d (rotation = %d/%d)\n", ROOMNUM(Markedroomp), |
| 1116 | Markedface, roomnum, facenum, count % Markedroomp->faces[Markedface].num_verts, |
| 1117 | Markedroomp->faces[Markedface].num_verts); |
| 1118 | World_changed = 1; |
| 1119 | } else |
| 1120 | EditorStatus("Can't copy UVs: faces don't have the same number of vertices."); |
| 1121 | } |
| 1122 | } else if (KEY_STATE(KEY_N)) { |
| 1123 | vector vec = Rooms[roomnum].verts[Rooms[roomnum].faces[facenum].face_verts[0]]; |
| 1124 | vector norm = Rooms[roomnum].faces[facenum].normal; |
| 1125 | float plane_dist = -(vec.x * norm.x + vec.y * norm.y + vec.z * norm.z); |
| 1126 | int i; |
| 1127 | for (i = 0; i < Rooms[roomnum].faces[facenum].num_verts; i++) { |
| 1128 | vec = Rooms[roomnum].verts[Rooms[roomnum].faces[facenum].face_verts[i]]; |
| 1129 | float dist = vec.x * norm.x + vec.y * norm.y + vec.z * norm.z + plane_dist; |
| 1130 | mprintf(0, "Vertex %d distance from plane=%f\n", i, dist); |
| 1131 | } |
| 1132 | } else if (KEY_STATE(KEY_V)) { |
| 1133 | // Do visibility check |
| 1134 | int rooma = (Markedroomp - Rooms); |
| 1135 | int roomb = (Curroomp - Rooms); |
| 1136 | int answer = BOA_IsVisible(rooma, roomb); |
| 1137 | |
| 1138 | mprintf(0, "Answer 1 is %d\n", answer); |
| 1139 | |
| 1140 | answer = BOA_IsVisible(roomb, rooma); |
| 1141 | |
| 1142 | mprintf(0, "Answer 2 is %d\n", answer); |
| 1143 | } else { // Just change curface |
| 1144 | State_changed = 1; |
| 1145 | EditorStatus("Current room:face set to %d:%d", roomnum, facenum); |
| 1146 | } |
| 1147 | |
| 1148 | // All clicks on face change the current face |
| 1149 | Curroomp = &Rooms[roomnum]; |
| 1150 | Curface = facenum; |
| 1151 | Curedge = Curvert = 0; |
| 1152 | Curportal = -1; |
| 1153 | } |
| 1154 | } |
| 1155 | |
| 1156 | TexGrStopOpenGL(); |
| 1157 | |
| 1158 | CWnd::OnLButtonDown(nFlags, point); |
| 1159 | } |
| 1160 | |
| 1161 | void CTextureGrWnd::OnMouseMove(UINT nFlags, CPoint point) { CWnd::OnMouseMove(nFlags, point); } |
| 1162 | |
| 1163 | void CTextureGrWnd::OnRButtonDown(UINT nFlags, CPoint point) { |
| 1164 | int n = D3EditState.current_megacell; |
| 1165 | int newobjnum = -1; |
| 1166 | bool do_popup = false; |
| 1167 | |
| 1168 | TexGrStartOpenGL(); |
| 1169 | |
| 1170 | if (Editor_view_mode == VM_TERRAIN) { |
| 1171 | TSearch_seg = -1; |
| 1172 | TSearch_on = 1; |
| 1173 | TSearch_x = point.x; |
| 1174 | TSearch_y = point.y; |
| 1175 | TSearch_found_type = -1; |
| 1176 | |
| 1177 | StartEditorFrame(m_grViewport, &Viewer_object->pos, &Viewer_object->orient, D3_DEFAULT_ZOOM); |
| 1178 | RenderTerrain(0); |
| 1179 | PostRender(Viewer_object->roomnum); |
| 1180 | EndEditorFrame(); |
| 1181 | TSearch_on = 0; |
| 1182 | if (TSearch_found_type == TSEARCH_FOUND_TERRAIN) { |
| 1183 | if (nFlags & MK_SHIFT) { |
| 1184 | int w = Megacells[n].width; |
| 1185 | int h = Megacells[n].height; |
| 1186 | |
| 1187 | for (int i = 0; i < h; i++) { |
| 1188 | for (int t = 0; t < w; t++) { |
| 1189 | int terrain_x = (TSearch_seg % TERRAIN_WIDTH) + t; |
| 1190 | int terrain_z = (TSearch_seg / TERRAIN_WIDTH) - i; |
| 1191 | int mx, my; |
| 1192 | |
| 1193 | if (terrain_x < 0 || terrain_x >= TERRAIN_WIDTH) |
| 1194 | continue; |
| 1195 | if (terrain_z < 0 || terrain_z >= TERRAIN_DEPTH) |
| 1196 | continue; |
| 1197 | |
| 1198 | if (D3EditState.randomize_megacell) { |
| 1199 | mx = rand() % w; |
| 1200 | my = rand() % h; |
| 1201 | } else { |
| 1202 | mx = t; |
| 1203 | my = i; |
| 1204 | } |
| 1205 | |
| 1206 | TV_changed = 1; |
| 1207 | } |
| 1208 | } |
| 1209 | } |
| 1210 | if (nFlags & MK_CONTROL) { |
| 1211 | int x, z, i, t; |
| 1212 | |
| 1213 | for (i = 0; i < TERRAIN_DEPTH * TERRAIN_WIDTH; i++) { |
| 1214 | if (TerrainSelected[i]) { |
| 1215 | x = i % TERRAIN_WIDTH; |
| 1216 | z = i / TERRAIN_WIDTH; |
| 1217 | |
| 1218 | break; |
| 1219 | } |
| 1220 | } |
| 1221 | |
| 1222 | if (i == TERRAIN_DEPTH * TERRAIN_WIDTH) |
| 1223 | return; // nothing to do! |
| 1224 | |
| 1225 | Num_terrain_selected = 0; |
| 1226 | memset(TerrainSelected, 0, TERRAIN_WIDTH * TERRAIN_DEPTH); |
| 1227 | |
| 1228 | int terrain_x = (TSearch_seg % TERRAIN_WIDTH); |
| 1229 | int terrain_z = (TSearch_seg / TERRAIN_WIDTH); |
| 1230 | |
| 1231 | int width = abs(terrain_x - x); |
| 1232 | int height = abs(terrain_z - z); |
| 1233 | int start_x = x; |
| 1234 | int start_z = z; |
| 1235 | |
| 1236 | if (terrain_x < x) |
| 1237 | start_x = terrain_x; |
| 1238 | if (terrain_z < z) |
| 1239 | start_z = terrain_z; |
| 1240 | |
| 1241 | for (i = 0; i <= height; i++) |
| 1242 | for (t = 0; t <= width; t++) { |
| 1243 | Num_terrain_selected++; |
| 1244 | TerrainSelected[((i + start_z) * TERRAIN_WIDTH) + start_x + t] = 1; |
| 1245 | } |
| 1246 | } |
| 1247 | } |
| 1248 | // Check for objects |
| 1249 | else if (TSearch_found_type == TSEARCH_FOUND_OBJECT) { |
| 1250 | newobjnum = TSearch_seg; |
| 1251 | do_popup = true; |
| 1252 | |
| 1253 | mprintf(0, "Found an object! objnum=%d\n", newobjnum); |
| 1254 | SelectObject(newobjnum); |
| 1255 | |
| 1256 | Render(); |
| 1257 | RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW); |
| 1258 | } |
| 1259 | } |
| 1260 | // Code to put up popup menu when right clicking |
| 1261 | else { |
| 1262 | int roomnum, facenum; |
| 1263 | |
| 1264 | TSearch_found_type = -1; |
| 1265 | TSearch_seg = -1; |
| 1266 | TSearch_on = 1; |
| 1267 | TSearch_x = point.x; |
| 1268 | TSearch_y = point.y; |
| 1269 | |
| 1270 | TGWRenderMine(&Viewer_object->pos, &Viewer_object->orient, D3_DEFAULT_ZOOM, Viewer_object->roomnum); |
| 1271 | TSearch_on = 0; |
| 1272 | |
| 1273 | // this looks at the last frame rendered |
| 1274 | if (TSearch_found_type == TSEARCH_FOUND_MINE || TSearch_found_type == TSEARCH_FOUND_OBJECT) { |
| 1275 | roomnum = TSearch_seg; |
| 1276 | facenum = TSearch_face; |
| 1277 | m_StartFlip = FALSE; // unsignal flip. |
| 1278 | mprintf(0, "found point: %d %d %d\n", roomnum, facenum); |
| 1279 | |
| 1280 | do_popup = true; |
| 1281 | |
| 1282 | if (TSearch_found_type == TSEARCH_FOUND_OBJECT) { // found an object |
| 1283 | newobjnum = (roomnum); |
| 1284 | SelectObject(newobjnum); |
| 1285 | } |
| 1286 | } |
| 1287 | |
| 1288 | Render(); |
| 1289 | RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW); |
| 1290 | } |
| 1291 | |
| 1292 | // right click popup menu |
| 1293 | if (do_popup) { |
| 1294 | CMenu popup; |
| 1295 | bool ret = true; |
| 1296 | char *title = NULL; |
| 1297 | |
| 1298 | if (newobjnum > -1) |
| 1299 | title = Objects[newobjnum].name; |
| 1300 | |
| 1301 | if (popup.CreatePopupMenu()) |
| 1302 | ret = SetupPopup(&popup, title); |
| 1303 | else { |
| 1304 | mprintf(0, "Warning: Could not create popup menu!\n"); |
| 1305 | ret = false; |
| 1306 | } |
| 1307 | |
| 1308 | if (newobjnum > -1) { |
| 1309 | object *foundobj = &Objects[newobjnum]; |
| 1310 | if (!ObjectInBuffer) |
| 1311 | popup.EnableMenuItem(POPUP_PASTE, MF_GRAYED); |
| 1312 | if (foundobj->control_type != CT_SOUNDSOURCE) |
| 1313 | popup.EnableMenuItem(POPUP_SOUND, MF_GRAYED); |
| 1314 | } else { |
| 1315 | popup.EnableMenuItem(POPUP_OBJNAME, MF_GRAYED); |
| 1316 | popup.EnableMenuItem(POPUP_EDITNAME, MF_GRAYED); |
| 1317 | popup.EnableMenuItem(POPUP_EDITSCRIPT, MF_GRAYED); |
| 1318 | popup.EnableMenuItem(POPUP_NEWSCRIPT, MF_GRAYED); |
| 1319 | popup.EnableMenuItem(POPUP_CUT, MF_GRAYED); |
| 1320 | popup.EnableMenuItem(POPUP_COPY, MF_GRAYED); |
| 1321 | popup.EnableMenuItem(POPUP_SOUND, MF_GRAYED); |
| 1322 | if (!ObjectInBuffer) |
| 1323 | popup.EnableMenuItem(POPUP_PASTE, MF_GRAYED); |
| 1324 | popup.EnableMenuItem(POPUP_DELETE, MF_GRAYED); |
| 1325 | } |
| 1326 | |
| 1327 | if (ret) |
| 1328 | if (!popup.TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y + 20, this, NULL)) |
| 1329 | mprintf(0, "TrackPopupMenu error!\n"); |
| 1330 | } |
| 1331 | |
| 1332 | TexGrStopOpenGL(); |
| 1333 | |
| 1334 | CWnd::OnRButtonDown(nFlags, point); |
| 1335 | } |
| 1336 | |
| 1337 | //================= |
| 1338 | // Sets up the popup menu for a right click |
| 1339 | // Parameters: popup: pointer to CMenu object |
| 1340 | // Returns: true if everything went ok |
| 1341 | // Notes: The CMenu object must be initialized before sent to this function (use CreatePopupMenu()) |
| 1342 | //================= |
| 1343 | bool CTextureGrWnd::SetupPopup(CMenu *popup, char *title) { |
| 1344 | bool ret; |
| 1345 | ret = true; |
| 1346 | |
| 1347 | if (!popup->AppendMenu(MF_STRING + MF_DISABLED, POPUP_OBJNAME, title ? title : "(no name)")) { |
| 1348 | ret = false; |
| 1349 | mprintf(0, "Warning: Could not add Title to popup\n"); |
| 1350 | } |
| 1351 | if (!popup->AppendMenu(MF_SEPARATOR)) { |
| 1352 | ret = false; |
| 1353 | mprintf(0, "Warning: Could not add seperator to popup\n"); |
| 1354 | } |
| 1355 | if (!popup->AppendMenu(MF_STRING, POPUP_COPY, "Copy")) { |
| 1356 | ret = false; |
| 1357 | mprintf(0, "Warning: Could not add Copy to popup\n"); |
| 1358 | } |
| 1359 | if (!popup->AppendMenu(MF_STRING, POPUP_CUT, "Cut")) { |
| 1360 | ret = false; |
| 1361 | mprintf(0, "Warning: Could not add Cut to popup\n"); |
| 1362 | } |
| 1363 | if (!popup->AppendMenu(MF_STRING, POPUP_PASTE, "Paste")) { |
| 1364 | ret = false; |
| 1365 | mprintf(0, "Warning: Could not add Paste to popup\n"); |
| 1366 | } |
| 1367 | if (!popup->AppendMenu(MF_STRING, POPUP_DELETE, "Delete")) { |
| 1368 | ret = false; |
| 1369 | mprintf(0, "Warning: Could not add Delete to popup\n"); |
| 1370 | } |
| 1371 | if (!popup->AppendMenu(MF_SEPARATOR)) { |
| 1372 | ret = false; |
| 1373 | mprintf(0, "Warning: Could not add seperator to popup\n"); |
| 1374 | } |
| 1375 | if (!popup->AppendMenu(MF_STRING, POPUP_EDITNAME, "Edit Name")) { |
| 1376 | ret = false; |
| 1377 | mprintf(0, "Warning: Could not add Edit Name to popup\n"); |
| 1378 | } |
| 1379 | if (!popup->AppendMenu(MF_STRING, POPUP_SOUND, "Sound")) { |
| 1380 | ret = false; |
| 1381 | mprintf(0, "Warning: Could not add Sound to popup\n"); |
| 1382 | } |
| 1383 | if (!popup->AppendMenu(MF_STRING, POPUP_EDITSCRIPT, "Edit Dallas Scripts")) { |
| 1384 | ret = false; |
| 1385 | mprintf(0, "Warning: Could not add Edit Script to popup\n"); |
| 1386 | } |
| 1387 | if (!popup->AppendMenu(MF_STRING, POPUP_NEWSCRIPT, "New Dallas Script")) { |
| 1388 | ret = false; |
| 1389 | mprintf(0, "Warning: Could not add New Script to popup\n"); |
| 1390 | } |
| 1391 | if (!popup->AppendMenu(MF_STRING, POPUP_CUSTOMDEFAULTSCRIPT, "Set a custom default script")) { |
| 1392 | ret = false; |
| 1393 | mprintf(0, "Warning: Could not add Set a custom default script to popup\n"); |
| 1394 | } |
| 1395 | //@@if(!popup->AppendMenu(MF_STRING,POPUP_PROPERTIES,"Properties")) |
| 1396 | //@@{ |
| 1397 | //@@ ret=false; |
| 1398 | //@@ mprintf(0,"Warning: Could not add Properties to popup\n"); |
| 1399 | //@@} |
| 1400 | //@@if(!popup->AppendMenu(MF_STRING,POPUP_COPYID,"Copy UID")) |
| 1401 | //@@{ |
| 1402 | //@@ ret=false; |
| 1403 | //@@ mprintf(0,"Warning: Could not add Copy UID to popup\n"); |
| 1404 | //@@} |
| 1405 | return ret; |
| 1406 | } |
| 1407 | |
| 1408 | void UpdateProperties(CObjectPropertiesDialog *prop_dlg) { |
| 1409 | |
| 1410 | object *curobj; |
| 1411 | curobj = &Objects[Cur_object_index]; |
| 1412 | |
| 1413 | curobj->mtype.phys_info.velocity.x = prop_dlg->m_fVelocityX; |
| 1414 | curobj->mtype.phys_info.velocity.y = prop_dlg->m_fVelocityY; |
| 1415 | curobj->mtype.phys_info.velocity.z = prop_dlg->m_fVelocityZ; |
| 1416 | |
| 1417 | curobj->mtype.phys_info.thrust.x = prop_dlg->m_fThrustX; |
| 1418 | curobj->mtype.phys_info.thrust.y = prop_dlg->m_fThrustY; |
| 1419 | curobj->mtype.phys_info.thrust.z = prop_dlg->m_fThrustZ; |
| 1420 | |
| 1421 | curobj->mtype.phys_info.rotvel.x = prop_dlg->m_fRotVelX; |
| 1422 | curobj->mtype.phys_info.rotvel.y = prop_dlg->m_fRotVelY; |
| 1423 | curobj->mtype.phys_info.rotvel.z = prop_dlg->m_fRotVelZ; |
| 1424 | |
| 1425 | curobj->mtype.phys_info.rotthrust.x = prop_dlg->m_fRotThrustX; |
| 1426 | curobj->mtype.phys_info.rotthrust.y = prop_dlg->m_fRotThrustY; |
| 1427 | curobj->mtype.phys_info.rotthrust.z = prop_dlg->m_fRotThrustZ; |
| 1428 | |
| 1429 | curobj->mtype.phys_info.turnroll = prop_dlg->m_sTurnrollAngle; |
| 1430 | curobj->mtype.phys_info.num_bounces = prop_dlg->m_iNumBounces; |
| 1431 | curobj->mtype.phys_info.mass = prop_dlg->m_fMass; |
| 1432 | curobj->mtype.phys_info.drag = prop_dlg->m_fDrag; |
| 1433 | curobj->mtype.phys_info.rotdrag = prop_dlg->m_fRotDrag; |
| 1434 | curobj->mtype.phys_info.full_thrust = prop_dlg->m_fFullThrust; |
| 1435 | curobj->mtype.phys_info.full_rotthrust = prop_dlg->m_fFullRotThrust; |
| 1436 | curobj->mtype.phys_info.max_turnroll_rate = prop_dlg->m_fMaxTurnrollrate; |
| 1437 | curobj->mtype.phys_info.turnroll_ratio = prop_dlg->m_fTurnrollRatio; |
| 1438 | curobj->mtype.phys_info.wiggle_amplitude = prop_dlg->m_fWiggleAmplitude; |
| 1439 | curobj->mtype.phys_info.wiggles_per_sec = prop_dlg->m_fWigglesPerSecond; |
| 1440 | |
| 1441 | curobj->mtype.phys_info.flags = 0; |
| 1442 | |
| 1443 | if (prop_dlg->m_bTurnroll) |
| 1444 | curobj->mtype.phys_info.flags |= PF_TURNROLL; |
| 1445 | if (prop_dlg->m_bLevelling) |
| 1446 | curobj->mtype.phys_info.flags |= PF_LEVELING; |
| 1447 | if (prop_dlg->m_bBounce) |
| 1448 | curobj->mtype.phys_info.flags |= PF_BOUNCE; |
| 1449 | if (prop_dlg->m_bWiggle) |
| 1450 | curobj->mtype.phys_info.flags |= PF_WIGGLE; |
| 1451 | if (prop_dlg->m_bSticks) |
| 1452 | curobj->mtype.phys_info.flags |= PF_STICK; |
| 1453 | if (prop_dlg->m_bPersistent) |
| 1454 | curobj->mtype.phys_info.flags |= PF_PERSISTENT; |
| 1455 | if (prop_dlg->m_bUsesThrust) |
| 1456 | curobj->mtype.phys_info.flags |= PF_USES_THRUST; |
| 1457 | if (prop_dlg->m_bGravity) |
| 1458 | curobj->mtype.phys_info.flags |= PF_GRAVITY; |
| 1459 | if (prop_dlg->m_bMagnetism) |
| 1460 | curobj->mtype.phys_info.flags |= PF_IGNORE_OWN_CONC_FORCES; |
| 1461 | if (prop_dlg->m_bWind) |
| 1462 | curobj->mtype.phys_info.flags |= PF_WIND; |
| 1463 | |
| 1464 | if ((prop_dlg->m_bUnlimitedBounce) || (!prop_dlg->m_bBounce)) { |
| 1465 | curobj->mtype.phys_info.num_bounces = -1; |
| 1466 | } |
| 1467 | } |
| 1468 | |
| 1469 | #include "osiris_predefs.h" |
| 1470 | extern bool StripLeadingTrailingSpaces(char *s); |
| 1471 | |
| 1472 | BOOL CTextureGrWnd::OnCommand(WPARAM wParam, LPARAM lParam) { |
| 1473 | // TODO: Add your specialized code here and/or call the base class |
| 1474 | if (HIWORD(wParam) == 0) { |
| 1475 | switch (LOWORD(wParam)) { |
| 1476 | case POPUP_EDITSCRIPT: { |
| 1477 | mprintf(0, "Edit script for object %d\n", Cur_object_index); |
| 1478 | // Nate: Add code here to edit/view an object's scripts |
| 1479 | |
| 1480 | // Make sure Dallas is open |
| 1481 | if (theApp.m_DallasModelessDlgPtr == NULL) { |
| 1482 | theApp.m_DallasModelessDlgPtr = new CDallasMainDlg; |
| 1483 | theApp.m_DallasModelessDlgPtr->Create(IDD_DALLAS_MAIN_DIALOG, this); |
| 1484 | theApp.m_DallasModelessDlgPtr->ShowWindow(SW_SHOW); |
| 1485 | } else |
| 1486 | theApp.m_DallasModelessDlgPtr->ShowWindow(SW_RESTORE); |
| 1487 | |
| 1488 | object *curobj = &Objects[Cur_object_index]; |
| 1489 | if (curobj->name == NULL) |
| 1490 | break; |
| 1491 | |
| 1492 | // Tell Dallas to add a new script with this object as the owner |
| 1493 | theApp.m_DallasModelessDlgPtr->m_ScriptOwnerType = OBJECT_TYPE; |
| 1494 | theApp.m_DallasModelessDlgPtr->m_ScriptOwnerHandle = curobj->handle; |
| 1495 | theApp.m_DallasModelessDlgPtr->PostMessage(WM_HIGHLIGHT_SCRIPTS); |
| 1496 | } break; |
| 1497 | |
| 1498 | case POPUP_NEWSCRIPT: { |
| 1499 | mprintf(0, "Add new script for object %d\n", Cur_object_index); |
| 1500 | // Nate: Add code here to create a new script for an object |
| 1501 | |
| 1502 | // Make sure Dallas is open |
| 1503 | if (theApp.m_DallasModelessDlgPtr == NULL) { |
| 1504 | theApp.m_DallasModelessDlgPtr = new CDallasMainDlg; |
| 1505 | theApp.m_DallasModelessDlgPtr->Create(IDD_DALLAS_MAIN_DIALOG, this); |
| 1506 | theApp.m_DallasModelessDlgPtr->ShowWindow(SW_SHOW); |
| 1507 | } else |
| 1508 | theApp.m_DallasModelessDlgPtr->ShowWindow(SW_RESTORE); |
| 1509 | |
| 1510 | object *curobj = &Objects[Cur_object_index]; |
| 1511 | if (curobj->name == NULL) |
| 1512 | break; |
| 1513 | |
| 1514 | // Tell Dallas to highlight all scripts that have this object as the owner |
| 1515 | theApp.m_DallasModelessDlgPtr->m_ScriptOwnerType = OBJECT_TYPE; |
| 1516 | theApp.m_DallasModelessDlgPtr->m_ScriptOwnerHandle = curobj->handle; |
| 1517 | theApp.m_DallasModelessDlgPtr->PostMessage(WM_ADD_SCRIPT); |
| 1518 | } break; |
| 1519 | |
| 1520 | case POPUP_EDITNAME: { |
| 1521 | if (Objects[Cur_object_index].type == OBJ_PLAYER) { |
| 1522 | EditorMessageBox("You cannot name a player object."); |
| 1523 | break; |
| 1524 | } |
| 1525 | |
| 1526 | char tempname[OBJ_NAME_LEN + 1] = ""; |
| 1527 | object *curobj = &Objects[Cur_object_index]; |
| 1528 | if (curobj->name) { |
| 1529 | ASSERT(strlen(curobj->name) <= OBJ_NAME_LEN); |
| 1530 | strcpy(tempname, curobj->name); |
| 1531 | } |
| 1532 | |
| 1533 | try_again:; |
| 1534 | if (!InputString(tempname, OBJ_NAME_LEN, "Object Name", "Enter a new name:")) |
| 1535 | break; |
| 1536 | |
| 1537 | if (StripLeadingTrailingSpaces(tempname)) |
| 1538 | EditorMessageBox("Note: Leading and/or trailing spaces have been removed from this name (\"%s\")", tempname); |
| 1539 | |
| 1540 | int handle = osipf_FindObjectName(tempname); |
| 1541 | if ((handle != OBJECT_HANDLE_NONE) && (handle != curobj->handle)) { |
| 1542 | EditorMessageBox("Object %d already has this name.", OBJNUM(ObjGet(handle))); |
| 1543 | goto try_again; |
| 1544 | } |
| 1545 | |
| 1546 | if (curobj->name) { |
| 1547 | mem_free(curobj->name); |
| 1548 | curobj->name = NULL; |
| 1549 | } |
| 1550 | |
| 1551 | if (strlen(tempname)) { |
| 1552 | curobj->name = (char *)mem_malloc(strlen(tempname) + 1); |
| 1553 | strcpy(curobj->name, tempname); |
| 1554 | } |
| 1555 | |
| 1556 | World_changed = 1; |
| 1557 | |
| 1558 | break; |
| 1559 | } |
| 1560 | |
| 1561 | case POPUP_CUSTOMDEFAULTSCRIPT: { |
| 1562 | object *curobj = &Objects[Cur_object_index]; |
| 1563 | |
| 1564 | CCustDefaultScriptSelect dlg; |
| 1565 | |
| 1566 | if (curobj->custom_default_script_name) |
| 1567 | dlg.m_Name = curobj->custom_default_script_name; |
| 1568 | else |
| 1569 | dlg.m_Name = ""; |
| 1570 | |
| 1571 | if (curobj->custom_default_module_name) |
| 1572 | dlg.m_Module = curobj->custom_default_module_name; |
| 1573 | else |
| 1574 | dlg.m_Module = ""; |
| 1575 | |
| 1576 | if (dlg.DoModal()) { |
| 1577 | |
| 1578 | if (curobj->custom_default_module_name) { |
| 1579 | mem_free(curobj->custom_default_module_name); |
| 1580 | curobj->custom_default_module_name = NULL; |
| 1581 | } |
| 1582 | |
| 1583 | if (curobj->custom_default_script_name) { |
| 1584 | mem_free(curobj->custom_default_script_name); |
| 1585 | curobj->custom_default_script_name = NULL; |
| 1586 | } |
| 1587 | |
| 1588 | if (!dlg.m_Module.IsEmpty()) { |
| 1589 | char module_name[MAX_MODULENAME_LEN]; |
| 1590 | curobj->custom_default_module_name = (char *)mem_malloc(dlg.m_Module.GetLength() + 1); |
| 1591 | |
| 1592 | ddio_SplitPath(dlg.m_Module.GetBuffer(0), NULL, module_name, NULL); |
| 1593 | strcpy(curobj->custom_default_module_name, module_name); |
| 1594 | } |
| 1595 | |
| 1596 | if (!dlg.m_Name.IsEmpty()) { |
| 1597 | curobj->custom_default_script_name = (char *)mem_malloc(dlg.m_Name.GetLength() + 1); |
| 1598 | strcpy(curobj->custom_default_script_name, dlg.m_Name.GetBuffer(0)); |
| 1599 | } |
| 1600 | } |
| 1601 | |
| 1602 | World_changed = 1; //? |
| 1603 | |
| 1604 | } break; |
| 1605 | |
| 1606 | //@@case POPUP_PROPERTIES: |
| 1607 | //@@ { |
| 1608 | //@@ CObjectPropertiesDialog prop_dlg; |
| 1609 | //@@ object *curobj=&Objects[Cur_object_index]; |
| 1610 | //@@ mprintf(0,"Properties selected\n"); |
| 1611 | //@@ if(prop_dlg.DoModal()==IDOK) UpdateProperties(&prop_dlg); |
| 1612 | //@@ break; |
| 1613 | //@@ } |
| 1614 | //@@ |
| 1615 | //@@case POPUP_COPYID: |
| 1616 | //@@ Copied_object_id = Objects[Cur_object_index].handle; |
| 1617 | //@@ break; |
| 1618 | |
| 1619 | case POPUP_DELETE: |
| 1620 | if (!ObjectDelete()) |
| 1621 | OutrageMessageBox("Could not Delete Object!"); |
| 1622 | break; |
| 1623 | case POPUP_PASTE: |
| 1624 | if (!ObjectPaste()) |
| 1625 | OutrageMessageBox("Could not Paste Object!"); |
| 1626 | break; |
| 1627 | case POPUP_CUT: |
| 1628 | if (!ObjectCut()) |
| 1629 | OutrageMessageBox("Could not Cut Object!"); |
| 1630 | break; |
| 1631 | case POPUP_COPY: |
| 1632 | if (!ObjectCopy()) |
| 1633 | OutrageMessageBox("Could not Copy Object!"); |
| 1634 | break; |
| 1635 | |
| 1636 | case POPUP_SOUND: { |
| 1637 | CSoundSourceDialog dlg(&Objects[Cur_object_index].ctype.soundsource_info); |
| 1638 | dlg.DoModal(); |
| 1639 | } |
| 1640 | } |
| 1641 | } |
| 1642 | return CWnd::OnCommand(wParam, lParam); |
| 1643 | } |
| 1644 | |
| 1645 | // Shows radiosity progress in the texture window. |
| 1646 | // This function needs to go in this file because of the stupid MFC |
| 1647 | // problems that occur if you try to access MFC member variables from a non- |
| 1648 | // MFC file |
| 1649 | void ShowRadView() { |
| 1650 | grSurface *cur_surf; |
| 1651 | int i, t; |
| 1652 | |
| 1653 | CTextureGrWnd *tview = theApp.textured_view; |
| 1654 | |
| 1655 | cur_surf = rad_Viewport->lock(); |
| 1656 | uint16_t *dest = (uint16_t *)cur_surf->data(); |
| 1657 | int rowsize = cur_surf->rowsize() / 2; |
| 1658 | |
| 1659 | int height = cur_surf->height(); |
| 1660 | int width = cur_surf->width(); |
| 1661 | |
| 1662 | fix du = IntToFix(rad_Hemicube.ff_res) / cur_surf->width(); |
| 1663 | fix dv = IntToFix(rad_Hemicube.ff_res) / cur_surf->height(); |
| 1664 | fix u, v; |
| 1665 | |
| 1666 | for (v = 0, i = 0; i < height; i++, v += dv) |
| 1667 | for (u = 0, t = 0; t < width; t++, u += du) { |
| 1668 | int x = FixToInt(u); |
| 1669 | int y = FixToInt(v); |
| 1670 | |
| 1671 | int color = rad_Hemicube.id_grid[y * rad_Hemicube.ff_res + x]; |
| 1672 | if (color == -1) |
| 1673 | dest[i * rowsize + t] = 0; |
| 1674 | else |
| 1675 | dest[i * rowsize + t] = GR_COLOR_TO_16(color); |
| 1676 | } |
| 1677 | |
| 1678 | rad_Viewport->unlock(); |
| 1679 | tview->Invalidate(); |
| 1680 | tview->SendMessage(WM_PAINT); |
| 1681 | |
| 1682 | World_changed = 1; |
| 1683 | } |