Debian Codegraph @

editor/WorldObjectsDoorDialog.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/editor/WorldObjectsDoorDialog.cpp $
21 * $Revision: 1.1.1.1 $
22 * $Date: 2003-08-26 03:57:39 $
23 * $Author: kevinb $
24 *
25 * WorldObjectsDoorDialog.cpp : implementation file
26 *
27 * $Log: not supported by cvs2svn $
28 *
29 * 26 2/04/99 2:05p Matt
30 * Added blastable doors
31 *
32 * 25 1/21/99 11:15p Jeff
33 * pulled out some structs and defines from header files and moved them
34 * into seperate header files so that multiplayer dlls don't require major
35 * game headers, just those new headers. Side effect is a shorter build
36 * time. Also cleaned up some header file #includes that weren't needed.
37 * This affected polymodel.h, object.h, player.h, vecmat.h, room.h,
38 * manage.h and multi.h
39 *
40 * 24 1/08/99 2:56p Samir
41 * Ripped out OSIRIS1.
42 *
43 * 23 12/21/98 5:27p Jeff
44 * added osiris module information to door page. Fixed up dialogs for
45 * objects and doors for script interface (added a browse button)
46 *
47 * 22 11/06/98 12:34p Jason
48 * more speedups for manage system
49 *
50 * 21 10/14/98 12:08p Jason
51 * fixed some long standing name problems
52 *
53 * 20 10/08/98 4:24p Kevin
54 * Changed code to comply with memory library usage. Always use mem_malloc
55 * , mem_free and mem_strdup
56 *
57 * 19 6/23/98 2:43p Matt
58 * Changed calls to OutrageMessageBox() & Debug_MessageBox() to deal with
59 * int return value (instead of bool).
60 *
61 * 18 6/15/98 4:00p Jason
62 * replaced monochromatic polymodel lighting with rgb lighting
63 *
64 * 17 5/22/98 8:50p Matt
65 * Added sounds for doors
66 *
67 * 16 4/17/98 1:53p Matt
68 * Reinitialize all objects when leaving the editor dialogs for generic
69 * objects (robots, powerps), doors, and player ships.
70 *
71 * 15 4/06/98 4:53p Jason
72 * got pageable polymodels working correctly with editor
73 *
74 * 14 4/02/98 3:54p Jason
75 * first pass in getting polymodel paging to work
76 *
77 * 13 2/02/98 7:07p Matt
78 * Added support for doors that can be seen through even when closed
79 *
80 * 12 1/25/98 5:17p Matt
81 * Changed the door dialog to be more like the generic dialog
82 *
83 * 11 1/23/98 5:39p Matt
84 * Added validity checking for door models.
85 *
86 * 10 12/19/97 11:25a Samir
87 * g3_StartFrame and g3_EndFrame replaced by EditorStartFrame and
88 * EditorEndFrame
89 *
90 * 9 12/01/97 6:06p Samir
91 * Implemented new FileDialog tracker system.
92 *
93 * 8 10/06/97 3:24p Jason
94 * fixed checkin problem
95 *
96 * 7 10/06/97 1:01p Jason
97 * made doors work with scripts (sort of)
98 *
99 * 6 9/11/97 5:38p Jason
100 * initial door coding for room engine
101 *
102 * 5 8/08/97 2:25p Matt
103 * Took out error messages which are now handled by mng_MakeLocker()
104 *
105 * 4 8/07/97 12:42p Jason
106 * fixed potential memory problem
107 *
108 * 3 7/24/97 6:11p Matt
109 * Created symbolic constant for default zoom, and used it every place
110 * that specifies zoom
111 *
112 * $NoKeywords: $
113 */
114
115 #include <filesystem>
116
117 #include "mfc_compatibility.h"
118 #include "editor.h"
119 #include "WorldObjectsDoorDialog.h"
120 #include "manage.h"
121 #include "doorpage.h"
122 #include "mono.h"
123 #include "vclip.h"
124 #include "polymodel.h"
125 #include "door.h"
126 #include "ddio.h"
127 #include "EditLineDialog.h"
128 #include "objinit.h"
129 #include "soundload.h"
130 #include "mem.h"
131
132 #ifdef _DEBUG
133 #define new DEBUG_NEW
134 #undef THIS_FILE
135 static char THIS_FILE[] = __FILE__;
136 #endif
137
138 /////////////////////////////////////////////////////////////////////////////
139 // CWorldObjectsDoorDialog dialog
140
141 CWorldObjectsDoorDialog::CWorldObjectsDoorDialog(CWnd *pParent /*=NULL*/)
142 : CDialog(CWorldObjectsDoorDialog::IDD, pParent) {
143 //{{AFX_DATA_INIT(CWorldObjectsDoorDialog)
144 // NOTE: the ClassWizard will add member initialization here
145 //}}AFX_DATA_INIT
146 }
147
148 void CWorldObjectsDoorDialog::DoDataExchange(CDataExchange *pDX) {
149 CDialog::DoDataExchange(pDX);
150 //{{AFX_DATA_MAP(CWorldObjectsDoorDialog)
151 // NOTE: the ClassWizard will add DDX and DDV calls here
152 //}}AFX_DATA_MAP
153 }
154
155 BEGIN_MESSAGE_MAP(CWorldObjectsDoorDialog, CDialog)
156 //{{AFX_MSG_MAP(CWorldObjectsDoorDialog)
157 ON_BN_CLICKED(IDC_ADD_DOOR, OnAddDoor)
158 ON_BN_CLICKED(IDC_CHECKIN_DOOR, OnCheckinDoor)
159 ON_EN_KILLFOCUS(IDC_CLOSE_TIME, OnKillfocusCloseTime)
160 ON_BN_CLICKED(IDC_DELETE_DOOR, OnDeleteDoor)
161 ON_BN_CLICKED(IDC_DOOR_NEXT, OnDoorNext)
162 ON_EN_KILLFOCUS(IDC_DOOR_OPEN_TIME, OnKillfocusDoorOpenTime)
163 ON_BN_CLICKED(IDC_DOOR_PREV, OnDoorPrev)
164 ON_EN_KILLFOCUS(IDC_DOOR_STAYS_OPEN, OnKillfocusDoorStaysOpen)
165 ON_BN_CLICKED(IDC_DOORS_OUT, OnDoorsOut)
166 ON_BN_CLICKED(IDC_LOAD_DOOR_MODEL, OnLoadDoorModel)
167 ON_BN_CLICKED(IDC_LOCK_DOOR, OnLockDoor)
168 ON_WM_TIMER()
169 ON_CBN_SELENDOK(IDC_DOOR_PULLDOWN, OnSelendokDoorPulldown)
170 ON_WM_HELPINFO()
171 ON_BN_CLICKED(IDC_DOOR_CHANGE_NAME, OnDoorChangeName)
172 ON_BN_CLICKED(IDC_TRANSPARENCY, OnTransparency)
173 ON_WM_DESTROY()
174 ON_CBN_SELENDOK(IDC_DOOR_CLOSE_SOUND, OnSelendokDoorCloseSound)
175 ON_CBN_SELENDOK(IDC_DOOR_OPEN_SOUND, OnSelendokDoorOpenSound)
176 ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
177 ON_EN_KILLFOCUS(IDC_SCRIPTNAME, OnKillfocusScriptname)
178 ON_BN_CLICKED(IDC_DOOR_BLASTABLE, OnDoorBlastable)
179 ON_EN_KILLFOCUS(IDC_DOOR_HITPOINTS_EDIT, OnKillfocusDoorHitpointsEdit)
180 //}}AFX_MSG_MAP
181 END_MESSAGE_MAP()
182
183 /////////////////////////////////////////////////////////////////////////////
184 // CWorldObjectsDoorDialog message handlers
185
186 #include "room.h"
187
188 // Makes sure a door model is ok. If not ok, brings up messagebox to tell the user
189 // Parameter: handle - the handle for the polymodel
190 // Returns: true if ok, else false
191 bool VerifyDoorModel(int handle) {
192 poly_model *pm = GetPolymodelPointer(handle);
193 int s;
194 bool found_frontface = 0, found_shell = 0;
195
196 for (s = 0; s < pm->n_models; s++) {
197 bsp_info *sm = &pm->submodel[s];
198
199 if (sm->flags & SOF_FRONTFACE) {
200
201 if (sm->num_faces != 1) {
202 OutrageMessageBox("Invalid door model: Frontface has %d faces; must have 1.", sm->num_faces);
203 return 0;
204 }
205
206 if (sm->num_children != 0) {
207 OutrageMessageBox("Invalid door model: Frontface cannot have submodels.");
208 return 0;
209 }
210
211 found_frontface = 1;
212 }
213
214 if (sm->flags & SOF_SHELL) {
215
216 if (sm->num_children != 0) {
217 OutrageMessageBox("Invalid door model: Shell cannot have submodels.");
218 return 0;
219 }
220
221 // check polygons in the shell. we do this by copying the poly face into a room
222 room check_room;
223 face check_face;
224
225 check_room.verts = sm->verts;
226 check_room.faces = &check_face;
227
228 for (int f = 0; f < sm->num_faces; f++) {
229 polyface *polyface = &sm->faces[f];
230
231 // copy polygon face into the room face
232 check_face.num_verts = polyface->nverts;
233 check_face.face_verts = polyface->vertnums;
234
235 if (!ComputeFaceNormal(&check_room, 0)) {
236 OutrageMessageBox("Invalid door model: Face %d in shell has bad normal.", f);
237 return 0;
238 }
239 }
240
241 found_shell = 1;
242 }
243 }
244
245 if (!found_frontface) {
246 OutrageMessageBox("Invalid door model: Missing Frontface.");
247 return 0;
248 }
249
250 if (!found_shell) {
251 OutrageMessageBox("Invalid door model: Missing Shell.");
252 return 0;
253 }
254
255 return 1;
256 }
257
258 void CWorldObjectsDoorDialog::OnAddDoor() {
259 char filename[256], pathname[256], dir[256], ext[32];
260 char cur_name[100];
261 int img_handle;
262 int door_handle;
263 int c = 1, finding_name = 1;
264
265 if (!Network_up) {
266 OutrageMessageBox("Sorry babe, the network is down. This action is a no-no.\n");
267 return;
268 }
269
270 // Get the filename of the representing image
271
272 CString filter = "Descent III files (*.pof,*.oof)|*.pof;*.oof||";
273
274 if (!OpenFileDialog(this, (LPCSTR)filter, pathname, Current_model_dir, sizeof(Current_model_dir)))
275 return;
276
277 // Okay, we selected a file. Lets do what needs to be done here.
278 img_handle = LoadDoorImage(pathname, 0);
279 ddio_SplitPath(pathname, dir, filename, ext);
280
281 if (!VerifyDoorModel(img_handle)) {
282 FreePolyModel(img_handle);
283 return;
284 }
285
286 if (img_handle < 0) {
287 OutrageMessageBox("Couldn't open that model file.");
288 return;
289 }
290
291 // Alloc a door and give a name not already taken by some other door
292
293 door_handle = AllocDoor();
294
295 while (finding_name) {
296 if (c == 1)
297 sprintf(cur_name, "%s", filename);
298 else
299 sprintf(cur_name, "%s%d", filename, c);
300 if (FindDoorName(cur_name) != -1)
301 c++;
302 else
303 finding_name = 0;
304 }
305
306 strcpy(Doors[door_handle].name, cur_name);
307
308 Doors[door_handle].model_handle = img_handle;
309
310 // Finally, save a local copy of the model/anim and alloc a tracklock
311 mprintf(0, "Making a copy of this model locally...\n");
312
313 std::filesystem::path destname = LocalModelsDir / Poly_models[Doors[door_handle].model_handle].name;
314 cf_CopyFile(destname, pathname);
315
316 mng_AllocTrackLock(cur_name, PAGETYPE_DOOR);
317
318 D3EditState.current_door = door_handle;
319
320 UpdateDialog();
321 }
322
323 #define NULL_NAME "<none>"
324
325 void CWorldObjectsDoorDialog::UpdateDialog() {
326 CEdit *ebox;
327 CButton *bbox;
328 int n = D3EditState.current_door;
329 char str[50];
330
331 if (Num_doors < 1) {
332 bbox = (CButton *)GetDlgItem(IDC_DOOR_NEXT);
333 bbox->EnableWindow(FALSE);
334 bbox = (CButton *)GetDlgItem(IDC_DOOR_PREV);
335 bbox->EnableWindow(FALSE);
336
337 return;
338 } else {
339 bbox = (CButton *)GetDlgItem(IDC_DOOR_NEXT);
340 bbox->EnableWindow(TRUE);
341 bbox = (CButton *)GetDlgItem(IDC_DOOR_PREV);
342 bbox->EnableWindow(TRUE);
343 }
344
345 if (!Doors[n].used)
346 n = D3EditState.current_door = GetNextDoor(n);
347
348 // ebox=(CEdit *) GetDlgItem (IDC_DOOR_NAME_EDIT);
349 // ebox->SetWindowText (Doors[n].name);
350
351 bbox = (CButton *)GetDlgItem(IDC_TRANSPARENCY);
352 bbox->SetCheck(Doors[n].flags & DF_SEETHROUGH);
353
354 bool blastable = ((Doors[n].flags & DF_BLASTABLE) != 0);
355 bbox = (CButton *)GetDlgItem(IDC_DOOR_BLASTABLE);
356 bbox->SetCheck(blastable);
357
358 ebox = (CEdit *)GetDlgItem(IDC_DOOR_MODEL_NAME_EDIT);
359 ebox->SetWindowText(Poly_models[Doors[n].model_handle].name);
360
361 ebox = (CEdit *)GetDlgItem(IDC_DOOR_OPEN_TIME);
362 sprintf(str, "%f", Doors[n].total_open_time);
363 ebox->SetWindowText(str);
364
365 ebox = (CEdit *)GetDlgItem(IDC_DOOR_STAYS_OPEN);
366 sprintf(str, "%f", Doors[n].total_time_open);
367 ebox->SetWindowText(str);
368
369 ebox = (CEdit *)GetDlgItem(IDC_CLOSE_TIME);
370 sprintf(str, "%f", Doors[n].total_close_time);
371 ebox->SetWindowText(str);
372
373 // Update hitpoint editing controls
374 GetDlgItem(IDC_DOOR_HITPOINTS_TEXT)->EnableWindow(blastable);
375 ebox = (CEdit *)GetDlgItem(IDC_DOOR_HITPOINTS_EDIT);
376 sprintf(str, "%d", Doors[n].hit_points);
377 ebox->SetWindowText(str);
378 ebox->EnableWindow(blastable);
379
380 bbox = (CButton *)GetDlgItem(IDC_CHECKIN_DOOR);
381 if (mng_FindTrackLock(Doors[n].name, PAGETYPE_DOOR) == -1) {
382 bbox->EnableWindow(FALSE);
383 bbox = (CButton *)GetDlgItem(IDC_LOCK_DOOR);
384 bbox->EnableWindow(TRUE);
385 } else {
386 bbox->EnableWindow(TRUE);
387 bbox = (CButton *)GetDlgItem(IDC_LOCK_DOOR);
388 bbox->EnableWindow(FALSE);
389 }
390
391 SendDlgItemMessage(IDC_DOOR_PULLDOWN, CB_RESETCONTENT, 0, 0);
392
393 for (int i = 0; i < MAX_DOORS; i++) {
394 if (Doors[i].used)
395 SendDlgItemMessage(IDC_DOOR_PULLDOWN, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)Doors[i].name);
396 }
397 SendDlgItemMessage(IDC_DOOR_PULLDOWN, CB_SELECTSTRING, 0, (LPARAM)(LPCTSTR)Doors[n].name);
398
399 // Update script
400 ebox = (CEdit *)GetDlgItem(IDC_SCRIPTNAME);
401
402 if (!Doors[n].module_name[0])
403 ebox->SetWindowText("null");
404 else
405 ebox->SetWindowText(Doors[n].module_name);
406
407 // Update sounds lists
408 SendDlgItemMessage(IDC_DOOR_OPEN_SOUND, CB_RESETCONTENT, 0, 0);
409 SendDlgItemMessage(IDC_DOOR_OPEN_SOUND, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)NULL_NAME);
410 for (int i = 0; i < MAX_SOUNDS; i++) {
411 if (Sounds[i].used)
412 SendDlgItemMessage(IDC_DOOR_OPEN_SOUND, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)Sounds[i].name);
413 }
414 if (Doors[n].open_sound == -1)
415 SendDlgItemMessage(IDC_DOOR_OPEN_SOUND, CB_SELECTSTRING, 0, (LPARAM)(LPCTSTR)NULL_NAME);
416 else
417 SendDlgItemMessage(IDC_DOOR_OPEN_SOUND, CB_SELECTSTRING, 0, (LPARAM)(LPCTSTR)Sounds[Doors[n].open_sound].name);
418
419 SendDlgItemMessage(IDC_DOOR_CLOSE_SOUND, CB_RESETCONTENT, 0, 0);
420 SendDlgItemMessage(IDC_DOOR_CLOSE_SOUND, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)NULL_NAME);
421 for (int i = 0; i < MAX_SOUNDS; i++) {
422 if (Sounds[i].used)
423 SendDlgItemMessage(IDC_DOOR_CLOSE_SOUND, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)Sounds[i].name);
424 }
425 if (Doors[n].close_sound == -1)
426 SendDlgItemMessage(IDC_DOOR_CLOSE_SOUND, CB_SELECTSTRING, 0, (LPARAM)(LPCTSTR)NULL_NAME);
427 else
428 SendDlgItemMessage(IDC_DOOR_CLOSE_SOUND, CB_SELECTSTRING, 0, (LPARAM)(LPCTSTR)Sounds[Doors[n].close_sound].name);
429
430 UpdateDoorView();
431 }
432
433 #define NUM_ANIM_FRAMES 30
434
435 void CWorldObjectsDoorDialog::UpdateDoorView(void) {
436 int n = D3EditState.current_door;
437 CWnd *doorwnd;
438 RECT rect;
439 int x, y, bm_handle, w, h;
440 static int frame = 0, spin_frame = 0;
441 static int last_door = -1;
442 static int last_model_handle = -1;
443 static int door_dir = 0;
444
445 if (Num_doors < 1)
446 return;
447
448 if (door_dir == 0) {
449 frame++;
450 if (frame == NUM_ANIM_FRAMES) {
451 frame = NUM_ANIM_FRAMES - 1;
452 door_dir = 1;
453 }
454 } else {
455 frame--;
456 if (frame == -1) {
457 frame = 0;
458 door_dir = 0;
459 }
460 }
461
462 doorwnd = GetDlgItem(IDC_DOORVIEW);
463 doorwnd->GetWindowRect(&rect);
464 ScreenToClient(&rect);
465
466 Desktop_surf->attach_to_window((unsigned)m_hWnd);
467
468 w = rect.right - rect.left;
469 h = rect.bottom - rect.top;
470
471 if (last_door != n || last_model_handle != Doors[n].model_handle) {
472 Desktop_surf->clear(rect.left, rect.top, w, h);
473 last_door = n;
474 last_model_handle = Doors[n].model_handle;
475 }
476
477 bm_handle = GetDoorImage(n);
478
479 vector zero_vector;
480 vector view_vector = {0, 0, -20};
481 matrix id_matrix, rot_matrix;
482 poly_model *pm = GetPolymodelPointer(bm_handle);
483
484 vm_MakeZero(&zero_vector);
485 vm_MakeIdentity(&id_matrix);
486
487 float norm_angles[30];
488
489 for (int i = 0; i < 30; i++)
490 norm_angles[i] = (float)frame / (float)NUM_ANIM_FRAMES;
491
492 spin_frame++;
493
494 vm_AnglesToMatrix(&rot_matrix, 0, spin_frame * 400, 0);
495
496 m_DoorSurf.create(128, 128, BPP_16);
497 grViewport *vport = new grViewport(&m_DoorSurf);
498 StartEditorFrame(vport, &view_vector, &id_matrix, D3_DEFAULT_ZOOM);
499 DrawPolygonModel(&zero_vector, &rot_matrix, bm_handle, norm_angles, 0, 1.0, 1.0, 1.0);
500 EndEditorFrame();
501
502 x = rect.left + ((rect.right - rect.left) / 2) - m_DoorSurf.width() / 2;
503 y = rect.top + ((rect.bottom - rect.top) / 2) - m_DoorSurf.height() / 2;
504 Desktop_surf->blt(x, y, &m_DoorSurf);
505
506 delete vport;
507 m_DoorSurf.free();
508 }
509
510 void CWorldObjectsDoorDialog::OnCheckinDoor() {
511 int n = D3EditState.current_door;
512 mngs_Pagelock temp_pl;
513 int r;
514
515 if (Num_doors < 1)
516 return;
517
518 if (!mng_MakeLocker())
519 return;
520
521 // Make sure we own this door
522 strcpy(temp_pl.name, Doors[n].name);
523 temp_pl.pagetype = PAGETYPE_DOOR;
524
525 r = mng_CheckIfPageOwned(&temp_pl, TableUser);
526 if (r < 0)
527 OutrageMessageBox(ErrorString);
528 else if (r == 0)
529 OutrageMessageBox(InfoString);
530 else {
531 // Change the pagelock state to UNLOCKED
532 strcpy(temp_pl.holder, "UNLOCKED");
533 if (!mng_ReplacePagelock(temp_pl.name, &temp_pl)) {
534 MessageBox(ErrorString, "Error!");
535 mng_EraseLocker();
536 return;
537 } else {
538 // Now actually replace the copy on the net with our local one
539
540 if (!mng_ReplacePage(Doors[n].name, Doors[n].name, n, PAGETYPE_DOOR, 0))
541 OutrageMessageBox(ErrorString);
542 else {
543 // Save this door anim/model to the network for all
544 std::filesystem::path srcname = LocalModelsDir / Poly_models[Doors[n].model_handle].name;
545 std::filesystem::path destname = NetModelsDir / Poly_models[Doors[n].model_handle].name;
546
547 cf_CopyFile(destname, srcname);
548
549 OutrageMessageBox("Door checked in.");
550
551 // Delete it from local pagefile if its there
552 int dret = mng_DeletePage(Doors[n].name, PAGETYPE_DOOR, 1);
553
554 ASSERT(dret == 1);
555 mng_EraseLocker();
556
557 // Free the tracklock
558 int p = mng_FindTrackLock(Doors[n].name, PAGETYPE_DOOR);
559 ASSERT(p != -1);
560 mng_FreeTrackLock(p);
561 UpdateDialog();
562 }
563 }
564 }
565
566 mng_EraseLocker();
567 }
568
569 void CWorldObjectsDoorDialog::OnKillfocusCloseTime() {
570 CEdit *ebox;
571 char str[20];
572 int n = D3EditState.current_door;
573
574 ebox = (CEdit *)GetDlgItem(IDC_CLOSE_TIME);
575 ebox->GetWindowText(str, 20);
576
577 Doors[n].total_close_time = atof(str);
578 }
579
580 void CWorldObjectsDoorDialog::OnDeleteDoor() {
581 int answer, tl;
582 mngs_Pagelock pl;
583 int n = D3EditState.current_door;
584
585 if (Num_doors < 1)
586 return;
587
588 // Check to see if we even have it locked
589 if ((tl = mng_FindTrackLock(Doors[n].name, PAGETYPE_DOOR)) == -1) {
590 OutrageMessageBox("This door is not yours to delete. Lock first.");
591 return;
592 }
593
594 // Make sure its to be deleted
595 answer = MessageBox("Are you sure you want to delete this door?", Doors[n].name, MB_YESNO);
596 if (answer == IDNO)
597 return;
598
599 if (!mng_MakeLocker())
600 return;
601
602 strcpy(pl.name, Doors[n].name);
603 pl.pagetype = PAGETYPE_DOOR;
604
605 // Check to see if this is a local door only. If so, only delete it locally
606 if (mng_CheckIfPageOwned(&pl, TableUser) != 1) {
607 mng_FreeTrackLock(tl);
608 if (!mng_DeletePage(Doors[n].name, PAGETYPE_DOOR, 1)) {
609 mprintf(0, ErrorString);
610 Int3();
611 }
612 } else // if its network, delete it from both the net and local drives
613 {
614
615 mng_FreeTrackLock(tl);
616 mng_DeletePage(Doors[n].name, PAGETYPE_DOOR, 1);
617 mng_DeletePage(Doors[n].name, PAGETYPE_DOOR, 0);
618
619 mng_DeletePagelock(Doors[n].name, PAGETYPE_DOOR);
620 }
621
622 // Advance to the next door
623 D3EditState.current_door = GetNextDoor(n);
624
625 FreePolyModel(Doors[n].model_handle);
626 FreeDoor(n);
627 mng_EraseLocker();
628
629 OutrageMessageBox("Door deleted.");
630 UpdateDialog();
631 }
632
633 // Gets a name from the user, making sure it's unique
634 // Returns true if got new name, false if cancelled.
635 // the data in buf not changed if cancel is pressed
636 bool InputDoorName(char *buf, int len, char *title, char *prompt, CWnd *wnd) {
637 char *tempbuf = (char *)mem_malloc(len);
638
639 strcpy(tempbuf, buf);
640
641 try_again:
642
643 if (!InputString(tempbuf, len, title, prompt, wnd)) {
644 mem_free(tempbuf);
645 return 0;
646 }
647
648 if (FindDoorName(tempbuf) != -1) {
649 OutrageMessageBox("The name you specified is already in use. Enter another name.");
650 goto try_again;
651 }
652
653 strcpy(buf, tempbuf);
654 mem_free(tempbuf);
655
656 return 1;
657 }
658
659 void CWorldObjectsDoorDialog::OnDoorChangeName() {
660 int n = D3EditState.current_door;
661 char name[PAGENAME_LEN];
662 mngs_Pagelock pl;
663
664 // Make sure we have this door locked, if not reset name and bail
665 int p = mng_FindTrackLock(Doors[n].name, PAGETYPE_DOOR);
666 if (p == -1) {
667 OutrageMessageBox("You must lock this door if you wish to change its name.");
668 return;
669 }
670
671 // Get new name
672 strcpy(name, Doors[n].name);
673 if (!InputDoorName(name, sizeof(name), "Door name", "Enter a new name for this door:", this))
674 return;
675
676 if (!mng_MakeLocker())
677 return;
678
679 // Check to see if this page exists on the network. If so, we have to
680 // rename it so we can prevent havoc
681 strcpy(pl.name, Doors[n].name);
682 pl.pagetype = PAGETYPE_DOOR;
683
684 int ret = mng_CheckIfPageOwned(&pl, TableUser);
685 if (ret < 0)
686 OutrageMessageBox(ErrorString);
687 else if (ret == 1)
688 mng_RenamePage(Doors[n].name, name, PAGETYPE_DOOR);
689 else if (ret == 2) {
690 // This page has never been checked in, replace only local copy
691
692 char oldname[PAGENAME_LEN];
693 strcpy(oldname, Doors[n].name);
694 strcpy(Doors[n].name, name);
695 mng_ReplacePage(oldname, Doors[n].name, n, PAGETYPE_DOOR, 1);
696 } else if (ret == 0) {
697 OutrageMessageBox("You don't own this page. Get Jason now!");
698 mng_FreeTrackLock(p);
699 return;
700 }
701
702 // Finally, copy our new name to the appropriate arrays
703 strcpy(GlobalTrackLocks[p].name, name);
704 strcpy(Doors[n].name, name);
705 UpdateDialog();
706 mng_EraseLocker();
707 }
708
709 void CWorldObjectsDoorDialog::OnDoorNext() {
710 D3EditState.current_door = GetNextDoor(D3EditState.current_door);
711 UpdateDialog();
712 }
713
714 void CWorldObjectsDoorDialog::OnKillfocusDoorOpenTime() {
715 CEdit *ebox;
716 char str[20];
717 int n = D3EditState.current_door;
718
719 ebox = (CEdit *)GetDlgItem(IDC_DOOR_OPEN_TIME);
720 ebox->GetWindowText(str, 20);
721
722 Doors[n].total_open_time = atof(str);
723 }
724
725 void CWorldObjectsDoorDialog::OnDoorPrev() {
726 D3EditState.current_door = GetPrevDoor(D3EditState.current_door);
727 UpdateDialog();
728 }
729
730 void CWorldObjectsDoorDialog::OnKillfocusDoorStaysOpen() {
731 // TODO: Add your control notification handler code here
732 CEdit *ebox;
733 char str[20];
734 int n = D3EditState.current_door;
735
736 ebox = (CEdit *)GetDlgItem(IDC_DOOR_STAYS_OPEN);
737 ebox->GetWindowText(str, 20);
738
739 Doors[n].total_time_open = atof(str);
740 }
741
742 void CWorldObjectsDoorDialog::OnDoorsOut() {
743 char str[10000];
744 int total = 0;
745
746 mng_DisplayLockList(TableUser);
747
748 sprintf(str, "User %s has these doors held locally:\n\n", TableUser);
749 for (int i = 0; i < MAX_TRACKLOCKS; i++) {
750
751 if (GlobalTrackLocks[i].used && GlobalTrackLocks[i].pagetype == PAGETYPE_DOOR) {
752 char temp[90];
753
754 sprintf(temp, "%s", GlobalTrackLocks[i].name);
755 strcat(str, temp);
756 strcat(str, "\n");
757 total++;
758 }
759 }
760
761 if (total != 0) {
762 // Display that string
763 MessageBox(str, "Doors", MB_OK);
764 }
765 }
766
767 void CWorldObjectsDoorDialog::OnLoadDoorModel() {
768 char filename[255];
769 int img_handle;
770 int door_handle;
771 int c = 1, finding_name = 1;
772 int model = 0;
773
774 // Get the filename of the representing image
775
776 CString filter = "Descent III files (*.pof,*.oof)|*.pof;*.oof||";
777
778 if (!OpenFileDialog(this, (LPCSTR)filter, filename, Current_model_dir, sizeof(Current_model_dir)))
779 return;
780
781 // Okay, we selected a file. Lets do what needs to be done here.
782 img_handle = LoadDoorImage(filename, 0);
783
784 if (img_handle < 0) {
785 OutrageMessageBox("Couldn't open that animation/model file.");
786 return;
787 }
788
789 door_handle = D3EditState.current_door;
790
791 Doors[door_handle].model_handle = img_handle;
792
793 // Finally, save a local copy of the model
794 std::filesystem::path curname = LocalModelsDir / Poly_models[Doors[door_handle].model_handle].name;
795 cf_CopyFile(curname, filename);
796
797 UpdateDialog();
798 }
799
800 void CWorldObjectsDoorDialog::OnLockDoor() {
801 int n = D3EditState.current_door;
802 mngs_Pagelock temp_pl;
803 mngs_door_page doorpage;
804 int r;
805
806 if (Num_doors < 1)
807 return;
808
809 if (!mng_MakeLocker())
810 return;
811
812 // Make sure it can be locked
813 strcpy(temp_pl.name, Doors[n].name);
814 temp_pl.pagetype = PAGETYPE_DOOR;
815
816 r = mng_CheckIfPageLocked(&temp_pl);
817 if (r == 2) {
818 int answer;
819 answer = OutrageMessageBox(MBOX_YESNO, "This page is not even in the table file, or the database maybe corrupt. "
820 "Override to 'Unlocked'? (Select NO if you don't know what you're doing)");
821 if (answer == IDYES) {
822 strcpy(temp_pl.holder, "UNLOCKED");
823 if (!mng_ReplacePagelock(temp_pl.name, &temp_pl))
824 MessageBox(ErrorString, "Error!");
825 }
826
827 } else if (r < 0)
828 OutrageMessageBox(ErrorString);
829 else if (r == 1)
830 OutrageMessageBox(InfoString);
831 else {
832
833 // Everything is ok. Tell the network we're locking it and get a copy to
834 // our local drive
835
836 strcpy(temp_pl.holder, TableUser);
837 if (!mng_ReplacePagelock(temp_pl.name, &temp_pl)) {
838 MessageBox(ErrorString, "Error!");
839 mng_EraseLocker();
840 return;
841 } else {
842 // Search thru the net pagefile and get a new copy in RAM in case anyone
843 // changed it since we started the editor
844 if (mng_FindSpecificDoorPage(temp_pl.name, &doorpage)) {
845 if (mng_AssignDoorPageToDoor(&doorpage, n)) {
846 if (!mng_ReplacePage(Doors[n].name, Doors[n].name, n, PAGETYPE_DOOR, 1)) {
847 OutrageMessageBox("There was problem writing that page locally!");
848 mng_EraseLocker();
849 return;
850 }
851 OutrageMessageBox("Door locked.");
852 } else
853 OutrageMessageBox(
854 "There was a problem loading this door. You might encounter problems in dealing with it. Good luck!");
855
856 mng_AllocTrackLock(Doors[n].name, PAGETYPE_DOOR);
857
858 UpdateDialog();
859 } else
860 OutrageMessageBox("Couldn't find that door in the table file!");
861 }
862 }
863 mng_EraseLocker();
864 }
865
866 BOOL CWorldObjectsDoorDialog::OnInitDialog() {
867 CDialog::OnInitDialog();
868
869 CWnd::SetTimer(1, 50, NULL);
870
871 UpdateDialog();
872
873 return TRUE; // return TRUE unless you set the focus to a control
874 // EXCEPTION: OCX Property Pages should return FALSE
875 }
876
877 void CWorldObjectsDoorDialog::OnTimer(UINT nIDEvent) {
878 UpdateDoorView();
879
880 CDialog::OnTimer(nIDEvent);
881 }
882
883 // When closing, save all our checked out doors locally so we know
884 // what stuff to flag as "checked out" the next time we start up
885 void CWorldObjectsDoorDialog::SaveDoorsOnClose() {
886 int i, t;
887
888 if (!Network_up)
889 return; // don't save a damn thing if the network is down
890
891 for (i = 0; i < MAX_TRACKLOCKS; i++) {
892 if (GlobalTrackLocks[i].used == 1 && GlobalTrackLocks[i].pagetype == PAGETYPE_DOOR) {
893 t = FindDoorName(GlobalTrackLocks[i].name);
894 ASSERT(t != -1);
895 mng_ReplacePage(Doors[t].name, Doors[t].name, t, PAGETYPE_DOOR, 1);
896 }
897 }
898 }
899
900 BOOL CWorldObjectsDoorDialog::DestroyWindow() {
901 SaveDoorsOnClose();
902 return CDialog::DestroyWindow();
903 }
904
905 void CWorldObjectsDoorDialog::OnSelendokDoorPulldown() {
906 int i, cur;
907 char name[200];
908
909 cur = SendDlgItemMessage(IDC_DOOR_PULLDOWN, CB_GETCURSEL, 0, 0);
910 SendDlgItemMessage(IDC_DOOR_PULLDOWN, CB_GETLBTEXT, cur, (LPARAM)(LPCTSTR)name);
911
912 i = FindDoorName(name);
913
914 if (i == -1) {
915 mprintf(0, "Possible corrupted door list, but probably nothing.");
916 UpdateDialog();
917 }
918
919 D3EditState.current_door = i;
920 UpdateDialog();
921 }
922
923 BOOL CWorldObjectsDoorDialog::OnHelpInfo(HELPINFO *pHelpInfo) {
924 // TODO: Add your message handler code here and/or call default
925 WinHelp(HID_DOORSDLG, HELP_CONTEXT);
926 return TRUE;
927 // return CDialog::OnHelpInfo(pHelpInfo);
928 }
929
930 void CWorldObjectsDoorDialog::OnTransparency() {
931 int n = D3EditState.current_door;
932 CButton *btn;
933
934 btn = (CButton *)GetDlgItem(IDC_TRANSPARENCY);
935
936 if (btn->GetCheck())
937 Doors[n].flags |= DF_SEETHROUGH;
938 else
939 Doors[n].flags &= ~DF_SEETHROUGH;
940 }
941
942 void CWorldObjectsDoorDialog::OnDestroy() {
943 CDialog::OnDestroy();
944
945 ObjReInitAll();
946 }
947
948 void CWorldObjectsDoorDialog::OnSelendokDoorOpenSound() {
949 int cur;
950 char name[200];
951 int n = D3EditState.current_door;
952
953 cur = SendDlgItemMessage(IDC_DOOR_OPEN_SOUND, CB_GETCURSEL, 0, 0);
954 SendDlgItemMessage(IDC_DOOR_OPEN_SOUND, CB_GETLBTEXT, cur, (LPARAM)(LPCTSTR)name);
955
956 Doors[n].open_sound = FindSoundName(name);
957 }
958
959 void CWorldObjectsDoorDialog::OnSelendokDoorCloseSound() {
960 int cur;
961 char name[200];
962 int n = D3EditState.current_door;
963
964 cur = SendDlgItemMessage(IDC_DOOR_CLOSE_SOUND, CB_GETCURSEL, 0, 0);
965 SendDlgItemMessage(IDC_DOOR_CLOSE_SOUND, CB_GETLBTEXT, cur, (LPARAM)(LPCTSTR)name);
966
967 Doors[n].close_sound = FindSoundName(name);
968 }
969
970 void CWorldObjectsDoorDialog::OnBrowse() {
971 CString filter = "D3 Compiled Scripts (*.dll)|*.dll||";
972
973 char filename[_MAX_PATH];
974 char pathname[_MAX_PATH], name[_MAX_PATH];
975 strcpy(pathname, LocalScriptDir);
976
977 if (!OpenFileDialog(this, (LPCTSTR)filter, filename, pathname, sizeof(pathname)))
978 return;
979
980 ddio_SplitPath(filename, NULL, name, NULL);
981 sprintf(filename, "%s.dll", name);
982
983 int n = D3EditState.current_door;
984
985 strcpy(Doors[n].module_name, filename);
986
987 UpdateDialog();
988 }
989
990 void CWorldObjectsDoorDialog::OnKillfocusScriptname() {
991 char str[MAX_MODULENAME_LEN];
992
993 ((CEdit *)GetDlgItem(IDC_SCRIPTNAME))->GetWindowText(str, MAX_MODULENAME_LEN);
994
995 strcpy(Doors[D3EditState.current_door].module_name, str);
996 UpdateDialog();
997 }
998
999 void CWorldObjectsDoorDialog::OnDoorBlastable() {
1000 int n = D3EditState.current_door;
1001 CButton *btn;
1002
1003 btn = (CButton *)GetDlgItem(IDC_DOOR_BLASTABLE);
1004
1005 if (btn->GetCheck())
1006 Doors[n].flags |= DF_BLASTABLE;
1007 else
1008 Doors[n].flags &= ~DF_BLASTABLE;
1009
1010 UpdateDialog();
1011 }
1012
1013 void CWorldObjectsDoorDialog::OnKillfocusDoorHitpointsEdit() {
1014 char str[256];
1015
1016 int n = D3EditState.current_door;
1017 CEdit *ebox = (CEdit *)GetDlgItem(IDC_DOOR_HITPOINTS_EDIT);
1018
1019 ebox->GetWindowText(str, sizeof(str));
1020
1021 Doors[n].hit_points = atoi(str);
1022
1023 UpdateDialog();
1024 }