Debian Codegraph @

editor/TriggerDialog.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/TriggerDialog.cpp $
21 * $Revision: 1.1.1.1 $
22 * $Date: 2003-08-26 03:57:39 $
23 * $Author: kevinb $
24 *
25 * Trigger keypad dialog.
26 *
27 * $Log: not supported by cvs2svn $
28 *
29 * 31 6/15/99 5:33p Matt
30 * Fixed small stupid bug.
31 *
32 * 30 4/03/99 7:55p Matt
33 * Use new keypad update system instead of timer to update.
34 *
35 * 29 4/03/99 3:41p Kevin
36 * Put in code for "Edit Script" button
37 *
38 * 28 3/30/99 4:11p Matt
39 * Set world changed flag when trigger deleted.
40 *
41 * 27 3/27/99 7:10p Matt
42 * Strip leading & trailing spaces before check for duplicate names.
43 *
44 * 26 3/23/99 5:52p Matt
45 * Added clutter activators for triggers
46 *
47 * 25 3/22/99 6:59p Matt
48 * Fixed stupid bug: was assigning UVs to floating trigger face before
49 * computing normal.
50 *
51 * 24 3/01/99 10:39a Matt
52 * Strip leading and trailing spaces from object, trigger, and room names
53 * on level load and when the names are entered.
54 *
55 * 23 2/28/99 10:40p Matt
56 * Check for name already in use when entering a name.
57 *
58 * 22 2/11/99 8:30p Matt
59 *
60 * 21 2/02/99 11:54p Luke
61 * Fixed small bug (MattT on Luke's machine)
62 *
63 * 20 1/21/99 11:34a Matt
64 * Got rid of portal triggers. Since we don't have multi-face portals, a
65 * face trigger works fine for a portal. Also fixed a few editor/trigger
66 * bugs.
67 *
68 * 19 1/15/99 10:51a Matt
69 * Disable rename button if no current trigger
70 *
71 * 18 1/14/99 11:06a Matt
72 * Added names to triggers
73 *
74 * 17 1/08/99 2:56p Samir
75 * Ripped out OSIRIS1.
76 *
77 * 16 10/13/98 3:23p Matt
78 * Fixed a problem with the add portal trigger button being enabled when
79 * there was already a trigger on the portal's face. Also, fixed and
80 * added some asserts.
81 *
82 * 15 9/01/98 12:04p Matt
83 * Ripped out multi-face portal code
84 *
85 * 14 6/23/98 2:43p Matt
86 * Changed calls to OutrageMessageBox() & Debug_MessageBox() to deal with
87 * int return value (instead of bool).
88 *
89 * 13 2/04/98 6:23p Matt
90 * Changed object room number to indicate a terrain cell via a flag. Got
91 * rid of the object flag which used to indicate terrain.
92 *
93 * 12 1/23/98 5:54p Samir
94 * Added new style script support to triggers.
95 *
96 * 11 1/20/98 4:12p Samir
97 * New script housekeeping system.
98 *
99 * 10 1/15/98 7:34p Matt
100 * Revamped error checking when computing face normals
101 *
102 * 9 9/24/97 6:18p Samir
103 * Use script names instead of script id values to identify scripts.
104 *
105 * 8 9/24/97 2:58p Samir
106 * New ScriptSelect.
107 *
108 * 7 9/15/97 11:51a Matt
109 * Disable 'select by number' if no triggers
110 *
111 * 6 9/15/97 11:38a Matt
112 * Added better trigger selection functions
113 *
114 * 5 9/14/97 11:07p Matt
115 * Use new InputNumber() function
116 *
117 * 4 9/12/97 3:59p Matt
118 * Lots of changes to trigger dialog
119 *
120 * 3 9/08/97 10:01a Matt
121 * Ripped out old trigger code
122 *
123 * $NoKeywords: $
124 */
125
126 #include <stdlib.h>
127
128 #include "stdafx.h"
129 #include "editor.h"
130 #include "TriggerDialog.h"
131 #include "trigger.h"
132 #include "EditLineDialog.h"
133 #include "render.h"
134 #include "trigger.h"
135 #include "HView.h"
136 #include "FindIntersection.h"
137 #include "erooms.h"
138 //@@#include "d3x.h"
139
140 #include "DallasMainDlg.h"
141
142 #ifdef _DEBUG
143 #define new DEBUG_NEW
144 #undef THIS_FILE
145 static char THIS_FILE[] = __FILE__;
146 #endif
147
148 int Current_trigger = -1; // current editing trigger
149
150 /////////////////////////////////////////////////////////////////////////////
151 // CTriggerDialog dialog
152
153 CTriggerDialog::CTriggerDialog(CWnd *pParent /*=NULL*/) : CKeypadDialog(CTriggerDialog::IDD, pParent) {
154 //{{AFX_DATA_INIT(CTriggerDialog)
155 // NOTE: the ClassWizard will add member initialization here
156 //}}AFX_DATA_INIT
157 }
158
159 void CTriggerDialog::DoDataExchange(CDataExchange *pDX) {
160 CDialog::DoDataExchange(pDX);
161 //{{AFX_DATA_MAP(CTriggerDialog)
162 // NOTE: the ClassWizard will add DDX and DDV calls here
163 //}}AFX_DATA_MAP
164 }
165
166 BEGIN_MESSAGE_MAP(CTriggerDialog, CDialog)
167 //{{AFX_MSG_MAP(CTriggerDialog)
168 ON_WM_SIZE()
169 ON_WM_VSCROLL()
170 ON_WM_HSCROLL()
171 ON_WM_PAINT()
172 ON_WM_HELPINFO()
173 ON_BN_CLICKED(IDC_TRIG_ADD_TO_CURFACE, OnTrigAddToCurface)
174 ON_BN_CLICKED(IDC_TRIG_GOTO, OnTrigGoto)
175 ON_BN_CLICKED(IDC_TRIG_DELETE, OnTrigDelete)
176 ON_BN_CLICKED(IDC_TRIG_ADD_TO_CURPORTAL, OnTrigAddToCurportal)
177 ON_BN_CLICKED(IDC_TRIG_ADD_FLOATING, OnTrigAddFloating)
178 ON_BN_CLICKED(IDC_TRIG_RENDER_FLOATING, OnTrigRenderFloating)
179 ON_BN_CLICKED(IDC_TRIG_ACTIV_PLAYER, OnTrigActivPlayer)
180 ON_BN_CLICKED(IDC_TRIG_ACTIV_PLAYER_WEAPONS, OnTrigActivPlayerWeapons)
181 ON_BN_CLICKED(IDC_TRIG_ACTIV_ROBOT_WEAPONS, OnTrigActivRobotWeapons)
182 ON_BN_CLICKED(IDC_TRIG_ACTIV_ROBOTS, OnTrigActivRobots)
183 ON_BN_CLICKED(IDC_TRIG_FLOAT_NARROWER, OnTrigFloatNarrower)
184 ON_BN_CLICKED(IDC_TRIG_FLOAT_SHORTER, OnTrigFloatShorter)
185 ON_BN_CLICKED(IDC_TRIG_FLOAT_TALLER, OnTrigFloatTaller)
186 ON_BN_CLICKED(IDC_TRIG_FLOAT_WIDER, OnTrigFloatWider)
187 ON_BN_CLICKED(IDC_TRIG_ONESHOT, OnTrigOneShot)
188 ON_BN_CLICKED(IDC_TRIG_NEXT_PORTAL, OnTrigNextPortal)
189 ON_BN_CLICKED(IDC_TRIG_NEXT_IN_MINE, OnTrigNextInMine)
190 ON_BN_CLICKED(IDC_TRIG_NEXT_IN_ROOM, OnTrigNextInRoom)
191 ON_BN_CLICKED(IDC_TRIG_PREV_IN_MINE, OnTrigPrevInMine)
192 ON_BN_CLICKED(IDC_TRIG_PREV_IN_ROOM, OnTrigPrevInRoom)
193 ON_BN_CLICKED(IDC_TRIG_EDIT_NAME, OnTrigEditName)
194 ON_BN_CLICKED(IDC_TRIG_EDIT_SCRIPT, OnTrigEditScript)
195 ON_BN_CLICKED(IDC_TRIG_ACTIV_CLUTTER, OnTrigActivClutter)
196 //}}AFX_MSG_MAP
197 END_MESSAGE_MAP()
198
199 /////////////////////////////////////////////////////////////////////////////
200 // CTriggerDialog message handlers
201
202 void CTriggerDialog::OnSize(UINT nType, int cx, int cy) {
203 CKeypadDialog::OnSize(nType, cx, cy);
204
205 // make sure we can see a few items in the combo box when we drop it down.
206 RECT rect;
207
208 CComboBox *box = (CComboBox *)GetDlgItem(IDC_TRIGGERTYPE);
209 if (box) {
210 box->GetClientRect(&rect);
211 box->SetWindowPos(NULL, 0, 0, rect.right - rect.left, box->GetItemHeight(0) * 10, SWP_NOMOVE | SWP_NOZORDER);
212 }
213 }
214
215 void CTriggerDialog::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar *pScrollBar) {
216 // TODO: Add your message handler code here and/or call default
217
218 CKeypadDialog::OnVScroll(nSBCode, nPos, pScrollBar);
219 }
220
221 void CTriggerDialog::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar *pScrollBar) {
222 // TODO: Add your message handler code here and/or call default
223
224 CKeypadDialog::OnHScroll(nSBCode, nPos, pScrollBar);
225 }
226
227 trigger *FindTrigger(int roomnum, int facenum);
228
229 int FindNextTrigInRoom(int roomnum, int start) {
230 if ((start == -1) || (Triggers[start].roomnum != roomnum))
231 start = 0;
232 else
233 start++;
234
235 for (int i = 0; i < Num_triggers; i++) {
236 int n = (start + i) % Num_triggers;
237
238 if (Triggers[n].roomnum == roomnum)
239 return n;
240 }
241
242 // Couldn't find one
243 return -1;
244 }
245
246 int FindPrevTrigInRoom(int roomnum, int start) {
247 if (Triggers[start].roomnum != roomnum)
248 start = 0;
249 else
250 start--;
251
252 for (int i = Num_triggers; i > 0; i--) {
253 int n = (start + i) % Num_triggers;
254
255 if (Triggers[n].roomnum == roomnum)
256 return n;
257 }
258
259 // Couldn't find one
260 return -1;
261 }
262
263 void CTriggerDialog::UpdateDialog() {
264 bool portal = 0, floating = 0;
265 static int last_curroom = -1, last_curface = -1, last_curportal = -1;
266
267 if (Current_trigger >= Num_triggers)
268 Current_trigger--;
269
270 // If current room/face/portal change, select current trigger from current room/face/portal
271 if ((ROOMNUM(Curroomp) != last_curroom) || (Curface != last_curface)) {
272 if (Curroomp->faces[Curface].flags & FF_HAS_TRIGGER)
273 Current_trigger = (FindTrigger(ROOMNUM(Curroomp), Curface) - Triggers);
274 } else if ((Curportal != -1) && (Curportal != last_curportal))
275 if (Curroomp->portals[Curportal].flags & FF_HAS_TRIGGER)
276 Current_trigger = (FindTrigger(ROOMNUM(Curroomp), Curroomp->portals[Curportal].portal_face) - Triggers);
277 last_curroom = ROOMNUM(Curroomp);
278 last_curface = Curface, last_curportal = Curportal;
279
280 // Enable/Disable some buttons, etc.
281 ((CButton *)GetDlgItem(IDC_TRIG_NEXT_IN_MINE))->EnableWindow(Num_triggers > 1);
282 ((CButton *)GetDlgItem(IDC_TRIG_PREV_IN_MINE))->EnableWindow(Num_triggers > 1);
283 ((CButton *)GetDlgItem(IDC_TRIG_GOTO))->EnableWindow(Num_triggers > 0);
284 ((CButton *)GetDlgItem(IDC_TRIG_DELETE))->EnableWindow(Current_trigger != -1);
285 ((CButton *)GetDlgItem(IDC_TRIG_EDIT_SCRIPT))->EnableWindow(Current_trigger != -1);
286 ((CButton *)GetDlgItem(IDC_TRIG_EDIT_NAME))->EnableWindow(Current_trigger != -1);
287 ((CButton *)GetDlgItem(IDC_TRIG_ADD_TO_CURFACE))->EnableWindow(!(Curroomp->faces[Curface].flags & FF_HAS_TRIGGER));
288 ((CButton *)GetDlgItem(IDC_TRIG_ADD_TO_CURPORTAL))
289 ->EnableWindow((Curportal != -1) &&
290 !(Curroomp->faces[Curroomp->portals[Curportal].portal_face].flags & FF_HAS_TRIGGER) &&
291 !(Curroomp->faces[Curroomp->portals[Curportal].portal_face].flags & FF_HAS_TRIGGER));
292 ((CButton *)GetDlgItem(IDC_TRIG_CURRENT_NUM))->EnableWindow(Current_trigger != -1);
293 ((CButton *)GetDlgItem(IDC_TRIG_CURRENT_TYPE))->EnableWindow(Current_trigger != -1);
294 ((CButton *)GetDlgItem(IDC_TRIG_CURRENT_ROOM))->EnableWindow(Current_trigger != -1);
295 ((CButton *)GetDlgItem(IDC_TRIG_CURRENT_FACE))->EnableWindow(Current_trigger != -1);
296 ((CButton *)GetDlgItem(IDC_TRIG_CURRENT_FACE))->EnableWindow(Current_trigger != -1);
297 ((CButton *)GetDlgItem(IDC_TRIG_CURRENT_TRIG_PORTAL))->EnableWindow(Current_trigger != -1);
298 ((CButton *)GetDlgItem(IDC_TRIG_ACTIVATORS))->EnableWindow(Current_trigger != -1);
299 ((CButton *)GetDlgItem(IDC_TRIG_ACTIV_PLAYER))->EnableWindow(Current_trigger != -1);
300 ((CButton *)GetDlgItem(IDC_TRIG_ACTIV_PLAYER_WEAPONS))->EnableWindow(Current_trigger != -1);
301 ((CButton *)GetDlgItem(IDC_TRIG_ACTIV_ROBOT_WEAPONS))->EnableWindow(Current_trigger != -1);
302 ((CButton *)GetDlgItem(IDC_TRIG_ACTIV_ROBOTS))->EnableWindow(Current_trigger != -1);
303 ((CButton *)GetDlgItem(IDC_TRIG_ONESHOT))->EnableWindow(Current_trigger != -1);
304
305 int n = FindNextTrigInRoom(ROOMNUM(Curroomp), Current_trigger);
306 ((CButton *)GetDlgItem(IDC_TRIG_NEXT_IN_ROOM))->EnableWindow((n != -1) && (n != Current_trigger));
307 ((CButton *)GetDlgItem(IDC_TRIG_PREV_IN_ROOM))->EnableWindow((n != -1) && (n != Current_trigger));
308
309 // Update current trigger info
310 if (Current_trigger > -1) {
311 trigger *tp = &Triggers[Current_trigger];
312 room *rp = &Rooms[tp->roomnum];
313 face *fp = &rp->faces[tp->facenum];
314
315 portal = (fp->portal_num != -1);
316 floating = ((fp->flags & FF_FLOATING_TRIG) != 0);
317 ASSERT(!(portal && floating)); // Shouldn't be both portal and floating
318
319 PrintToDlgItem(this, IDC_TRIG_CURRENT_NAME, "Name:\t %s", tp->name[0] ? tp->name : "<none>");
320 PrintToDlgItem(this, IDC_TRIG_CURRENT_NUM, "Number:\t %d", Current_trigger);
321 PrintToDlgItem(this, IDC_TRIG_CURRENT_TYPE, "Type:\t %s", portal ? "PORTAL" : (floating ? "FLOATING" : "FACE"));
322 PrintToDlgItem(this, IDC_TRIG_CURRENT_ROOM, "Room:\t%d", tp->roomnum);
323 PrintToDlgItem(this, IDC_TRIG_CURRENT_FACE, "Face:\t%d", tp->facenum);
324 PrintToDlgItem(this, IDC_TRIG_CURRENT_TRIG_PORTAL, (portal) ? "Portal:\t%d" : "", fp->portal_num);
325
326 ((CButton *)GetDlgItem(IDC_TRIG_ACTIV_PLAYER))->SetCheck(tp->activator & AF_PLAYER);
327 ((CButton *)GetDlgItem(IDC_TRIG_ACTIV_PLAYER_WEAPONS))->SetCheck(tp->activator & AF_PLAYER_WEAPON);
328 ((CButton *)GetDlgItem(IDC_TRIG_ACTIV_ROBOT_WEAPONS))->SetCheck(tp->activator & AF_ROBOT_WEAPON);
329 ((CButton *)GetDlgItem(IDC_TRIG_ACTIV_ROBOTS))->SetCheck(tp->activator & AF_ROBOT);
330 ((CButton *)GetDlgItem(IDC_TRIG_ACTIV_CLUTTER))->SetCheck(tp->activator & AF_CLUTTER);
331
332 ((CButton *)GetDlgItem(IDC_TRIG_ONESHOT))->SetCheck(tp->flags & TF_ONESHOT);
333 } else {
334 PrintToDlgItem(this, IDC_TRIG_CURRENT_NAME, "Name:");
335 PrintToDlgItem(this, IDC_TRIG_CURRENT_NUM, "Number:");
336 PrintToDlgItem(this, IDC_TRIG_CURRENT_TYPE, "Type:");
337 PrintToDlgItem(this, IDC_TRIG_CURRENT_ROOM, "Room:");
338 PrintToDlgItem(this, IDC_TRIG_CURRENT_FACE, "Face:");
339 PrintToDlgItem(this, IDC_TRIG_CURRENT_TRIG_PORTAL, "");
340
341 ((CButton *)GetDlgItem(IDC_TRIG_ACTIV_PLAYER))->SetCheck(0);
342 ((CButton *)GetDlgItem(IDC_TRIG_ACTIV_PLAYER_WEAPONS))->SetCheck(0);
343 ((CButton *)GetDlgItem(IDC_TRIG_ACTIV_ROBOT_WEAPONS))->SetCheck(0);
344 ((CButton *)GetDlgItem(IDC_TRIG_ACTIV_ROBOTS))->SetCheck(0);
345
346 ((CButton *)GetDlgItem(IDC_TRIG_ONESHOT))->SetCheck(0);
347 }
348
349 // Enable/disable floating trig items
350 ((CButton *)GetDlgItem(IDC_TRIG_FLOAT_BORDER))->EnableWindow(floating);
351 ((CButton *)GetDlgItem(IDC_TRIG_FLOAT_WIDER))->EnableWindow(floating);
352 ((CButton *)GetDlgItem(IDC_TRIG_FLOAT_NARROWER))->EnableWindow(floating);
353 ((CButton *)GetDlgItem(IDC_TRIG_FLOAT_TALLER))->EnableWindow(floating);
354 ((CButton *)GetDlgItem(IDC_TRIG_FLOAT_SHORTER))->EnableWindow(floating);
355
356 // Enable/disable the portal items
357 ((CButton *)GetDlgItem(IDC_TRIG_CURRENT_PORTAL))->EnableWindow(Curportal != -1);
358 ((CButton *)GetDlgItem(IDC_TRIG_NEXT_PORTAL))
359 ->EnableWindow(((Curportal == -1) && (Curroomp->num_portals > 0)) || (Curroomp->num_portals > 1));
360
361 // Update the portal number
362 if (Curportal != -1)
363 PrintToDlgItem(this, IDC_TRIG_CURRENT_PORTAL, "Current Portal:\t%d", Curportal);
364 else
365 PrintToDlgItem(this, IDC_TRIG_CURRENT_PORTAL, "Current Portal:");
366 }
367
368 void CTriggerDialog::OnPaint() {
369 CPaintDC dc(this); // device context for painting
370
371 UpdateDialog();
372 }
373
374 BOOL CTriggerDialog::OnInitDialog() {
375 CDialog::OnInitDialog();
376
377 // Check current trigger
378 if (Current_trigger >= Num_triggers)
379 Current_trigger = Num_triggers - 1;
380
381 // Update global checkboxes
382 (((CButton *)GetDlgItem(IDC_TRIG_RENDER_FLOATING))->SetCheck(Render_floating_triggers));
383
384 return TRUE; // return TRUE unless you set the focus to a control
385 // EXCEPTION: OCX Property Pages should return FALSE
386 }
387
388 void CTriggerDialog::OnOK() {
389 CWnd *focus = CWnd::GetFocus();
390 if (focus)
391 focus->GetNextWindow()->SetFocus();
392 }
393
394 BOOL CTriggerDialog::OnHelpInfo(HELPINFO *pHelpInfo) {
395 // TODO: Add your message handler code here and/or call default
396 WinHelp(HID_TRIGGERTAB, HELP_CONTEXT);
397 return TRUE;
398 // return CDialog::OnHelpInfo(pHelpInfo);
399 }
400
401 void CTriggerDialog::OnTrigAddToCurface() {
402 ASSERT(!(Curroomp->faces[Curface].flags & FF_HAS_TRIGGER));
403
404 char name[TRIG_NAME_LEN + 1] = "";
405
406 if (!InputString(name, sizeof(name), "Trigger Name", "Enter a name for this trigger"))
407 return;
408
409 int activator = (Curroomp->faces[Curface].portal_num != -1) ? AF_PLAYER : AF_PLAYER_WEAPON;
410
411 Current_trigger = AddTrigger(name, ROOMNUM(Curroomp), Curface, activator, NULL);
412 UpdateDialog();
413 }
414
415 void SetCurroomFromTrigger() {
416 if (ROOMNUM(Curroomp) != Triggers[Current_trigger].roomnum) {
417
418 Curroomp = &Rooms[Triggers[Current_trigger].roomnum];
419
420 Curface = Curedge = Curvert = 0;
421 Curportal = -1;
422 }
423
424 Curface = Triggers[Current_trigger].facenum;
425
426 if (Curroomp->faces[Curface].portal_num != -1)
427 Curportal = Curroomp->faces[Curface].portal_num;
428
429 State_changed = 1;
430 }
431
432 void CTriggerDialog::OnTrigGoto() {
433 int n;
434
435 if (InputNumber(&n, "Select Trigger", "Enter trigger number to select", this)) {
436
437 if (n >= Num_triggers) {
438 OutrageMessageBox("Invalid trigger number.");
439 return;
440 }
441
442 Current_trigger = n;
443
444 SetCurroomFromTrigger();
445
446 UpdateDialog();
447 }
448 }
449
450 void CTriggerDialog::OnTrigDelete() {
451 ASSERT(Current_trigger != -1);
452
453 if (OutrageMessageBox(MBOX_YESNO, "Are you sure you want to delete the current trigger?") != IDYES)
454 return;
455
456 trigger *tp = &Triggers[Current_trigger];
457 room *rp = &Rooms[tp->roomnum];
458 int facenum = tp->facenum;
459
460 // Delete the trigger
461 DeleteTrigger(Current_trigger);
462
463 // Delete face if this was a floating trigger
464 if (rp->faces[facenum].flags & FF_FLOATING_TRIG) {
465 DeleteRoomFace(rp, facenum);
466 if (Curface == facenum)
467 Curface = (facenum + 1) % rp->num_faces;
468 }
469
470 if (Current_trigger == Num_triggers)
471 Current_trigger--;
472
473 UpdateDialog();
474
475 World_changed = 1;
476 }
477
478 void CTriggerDialog::OnTrigAddToCurportal() {
479 ASSERT(Curportal != -1);
480 ASSERT(!(Curroomp->faces[Curroomp->portals[Curportal].portal_face].flags & FF_HAS_TRIGGER));
481
482 char name[TRIG_NAME_LEN + 1] = "";
483
484 if (!InputString(name, sizeof(name), "Trigger Name", "Enter a name for this trigger"))
485 return;
486
487 Current_trigger = AddTrigger(name, ROOMNUM(Curroomp), Curroomp->portals[Curportal].portal_face, AF_PLAYER, NULL);
488 UpdateDialog();
489 }
490
491 void CTriggerDialog::UpdateKeypad(int mask) {
492 if (mask & (KUF_CURROOM_CHANGED + KUF_CURFACE_CHANGED + KUF_CURPORTAL_CHANGED))
493 UpdateDialog();
494 }
495
496 #include "erooms.h"
497
498 #define TRIG_PLACE_DIST 5.0
499 #define TRIG_DEFAULT_SIZE 10.0
500
501 void CTriggerDialog::OnTrigAddFloating() {
502 int facenum, vertnum;
503 room *rp;
504 face *fp;
505 vector center;
506 fvi_query fq;
507 fvi_info hit_info;
508 int fate;
509
510 if (OBJECT_OUTSIDE(Viewer_object)) {
511 OutrageMessageBox("Sorry, this operation does not yet work in the terrain.");
512 return;
513 }
514
515 char name[TRIG_NAME_LEN + 1] = "";
516
517 if (!InputString(name, sizeof(name), "Trigger Name", "Enter a name for this trigger"))
518 return;
519
520 // Get center point of new face
521 center = Viewer_object->pos + (Viewer_object->orient.fvec * TRIG_PLACE_DIST);
522
523 // Make sure the viewer in in the mine
524 if (Viewer_object->flags & OF_OUTSIDE_MINE)
525 goto bad_place;
526
527 // Check if position ok
528 fq.p0 = &Viewer_object->pos;
529 fq.startroom = Viewer_object->roomnum;
530 fq.p1 = &center;
531 fq.rad = 0;
532 fq.thisobjnum = -1;
533 fq.ignore_obj_list = NULL;
534 fq.flags = 0;
535 fate = fvi_FindIntersection(&fq, &hit_info);
536
537 // Bail if there's something in the way, or if the center point is outside
538 if ((fate != HIT_NONE) || ROOMNUM_OUTSIDE(hit_info.hit_room)) {
539
540 bad_place:;
541 OutrageMessageBox("You cannot place a floating trigger here.");
542 return;
543 }
544
545 // Get pointer to room the trigger is in
546 rp = &Rooms[hit_info.hit_room];
547
548 // Create a new face & new verts
549 facenum = RoomAddFaces(rp, 1);
550 vertnum = RoomAddVertices(rp, 4);
551 fp = &rp->faces[facenum];
552 InitRoomFace(fp, 4);
553
554 // Set the vertices for the new face
555 rp->verts[vertnum] =
556 center - (Viewer_object->orient.rvec * TRIG_DEFAULT_SIZE) + (Viewer_object->orient.uvec * TRIG_DEFAULT_SIZE);
557 rp->verts[vertnum + 1] =
558 center + (Viewer_object->orient.rvec * TRIG_DEFAULT_SIZE) + (Viewer_object->orient.uvec * TRIG_DEFAULT_SIZE);
559 rp->verts[vertnum + 2] =
560 center + (Viewer_object->orient.rvec * TRIG_DEFAULT_SIZE) - (Viewer_object->orient.uvec * TRIG_DEFAULT_SIZE);
561 rp->verts[vertnum + 3] =
562 center - (Viewer_object->orient.rvec * TRIG_DEFAULT_SIZE) - (Viewer_object->orient.uvec * TRIG_DEFAULT_SIZE);
563
564 // Set vertnums for new face
565 for (int i = 0; i < 4; i++)
566 fp->face_verts[i] = vertnum + i;
567
568 // Assign UVs and normal to new face
569 if (!ComputeFaceNormal(rp, facenum))
570 Int3(); // Get Matt
571 AssignDefaultUVsToRoomFace(rp, facenum);
572
573 // Set floating trig flag
574 fp->flags |= FF_FLOATING_TRIG;
575
576 // Add the trigger for the new face
577 Current_trigger = AddTrigger(name, ROOMNUM(rp), facenum, AF_PLAYER, NULL);
578
579 // Set the current room:face to the new face
580 SetCurroomFromTrigger();
581
582 // We're done
583 UpdateDialog();
584 }
585
586 void CTriggerDialog::OnTrigRenderFloating() {
587 Render_floating_triggers = (((CButton *)GetDlgItem(IDC_TRIG_RENDER_FLOATING))->GetCheck() != 0);
588 State_changed = 1;
589 }
590
591 void CTriggerDialog::OnTrigActivPlayer() {
592 trigger *tp = &Triggers[Current_trigger];
593
594 if (((CButton *)GetDlgItem(IDC_TRIG_ACTIV_PLAYER))->GetCheck())
595 tp->activator |= AF_PLAYER;
596 else
597 tp->activator &= ~AF_PLAYER;
598
599 World_changed = 1;
600 }
601
602 void CTriggerDialog::OnTrigActivPlayerWeapons() {
603 trigger *tp = &Triggers[Current_trigger];
604
605 if (((CButton *)GetDlgItem(IDC_TRIG_ACTIV_PLAYER_WEAPONS))->GetCheck())
606 tp->activator |= AF_PLAYER_WEAPON;
607 else
608 tp->activator &= ~AF_PLAYER_WEAPON;
609
610 World_changed = 1;
611 }
612
613 void CTriggerDialog::OnTrigActivRobotWeapons() {
614 trigger *tp = &Triggers[Current_trigger];
615
616 if (((CButton *)GetDlgItem(IDC_TRIG_ACTIV_ROBOT_WEAPONS))->GetCheck())
617 tp->activator |= AF_ROBOT_WEAPON;
618 else
619 tp->activator &= ~AF_ROBOT_WEAPON;
620
621 World_changed = 1;
622 }
623
624 void CTriggerDialog::OnTrigActivRobots() {
625 trigger *tp = &Triggers[Current_trigger];
626
627 if (((CButton *)GetDlgItem(IDC_TRIG_ACTIV_ROBOTS))->GetCheck())
628 tp->activator |= AF_ROBOT;
629 else
630 tp->activator &= ~AF_ROBOT;
631
632 World_changed = 1;
633 }
634
635 void ScaleFloatingTrigEdge(int roomnum, int facenum, int v0, int v1, float delta) {
636 room *rp = &Rooms[roomnum];
637 face *fp = &rp->faces[facenum];
638 vector *vv0, *vv1;
639 vector deltav;
640 float mag;
641
642 // Get pointers to verts
643 vv0 = &rp->verts[fp->face_verts[v0]];
644 vv1 = &rp->verts[fp->face_verts[v1]];
645
646 // Get delta vec
647 deltav = *vv1 - *vv0;
648 mag = vm_NormalizeVector(&deltav);
649
650 // Check for min size
651 if (mag <= delta)
652 return;
653
654 // Now add
655 *vv0 -= deltav * delta;
656 *vv1 += deltav * delta;
657 }
658
659 #define SCALE_DELTA 1.0
660
661 void CTriggerDialog::OnTrigFloatNarrower() {
662 ASSERT(Current_trigger != -1);
663
664 trigger *tp = &Triggers[Current_trigger];
665
666 ScaleFloatingTrigEdge(tp->roomnum, tp->facenum, 0, 1, -SCALE_DELTA);
667 ScaleFloatingTrigEdge(tp->roomnum, tp->facenum, 2, 3, -SCALE_DELTA);
668
669 World_changed = 1;
670 }
671
672 void CTriggerDialog::OnTrigFloatShorter() {
673 ASSERT(Current_trigger != -1);
674
675 trigger *tp = &Triggers[Current_trigger];
676
677 ScaleFloatingTrigEdge(tp->roomnum, tp->facenum, 1, 2, -SCALE_DELTA);
678 ScaleFloatingTrigEdge(tp->roomnum, tp->facenum, 3, 0, -SCALE_DELTA);
679
680 World_changed = 1;
681 }
682
683 void CTriggerDialog::OnTrigFloatTaller() {
684 ASSERT(Current_trigger != -1);
685
686 trigger *tp = &Triggers[Current_trigger];
687
688 ScaleFloatingTrigEdge(tp->roomnum, tp->facenum, 1, 2, SCALE_DELTA);
689 ScaleFloatingTrigEdge(tp->roomnum, tp->facenum, 3, 0, SCALE_DELTA);
690
691 World_changed = 1;
692 }
693
694 void CTriggerDialog::OnTrigFloatWider() {
695 ASSERT(Current_trigger != -1);
696
697 trigger *tp = &Triggers[Current_trigger];
698
699 ScaleFloatingTrigEdge(tp->roomnum, tp->facenum, 0, 1, SCALE_DELTA);
700 ScaleFloatingTrigEdge(tp->roomnum, tp->facenum, 2, 3, SCALE_DELTA);
701
702 World_changed = 1;
703 }
704
705 void CTriggerDialog::OnTrigOneShot() {
706 trigger *tp = &Triggers[Current_trigger];
707
708 if (((CButton *)GetDlgItem(IDC_TRIG_ONESHOT))->GetCheck())
709 tp->flags |= TF_ONESHOT;
710 else
711 tp->flags &= ~TF_ONESHOT;
712
713 World_changed = 1;
714 }
715
716 void CTriggerDialog::OnTrigNextPortal() {
717 if (Curroomp->num_portals) {
718 Curportal = (Curportal + 1) % Curroomp->num_portals;
719 State_changed = 1;
720 UpdateDialog();
721 }
722 }
723
724 void CTriggerDialog::OnTrigNextInMine() {
725 ASSERT(Current_trigger != -1);
726
727 Current_trigger = (Current_trigger + 1) % Num_triggers;
728
729 SetCurroomFromTrigger();
730
731 UpdateDialog();
732 }
733
734 void CTriggerDialog::OnTrigNextInRoom() {
735 int n = FindNextTrigInRoom(ROOMNUM(Curroomp), Current_trigger);
736
737 ASSERT(n != -1);
738
739 Current_trigger = n;
740
741 SetCurroomFromTrigger();
742 }
743
744 void CTriggerDialog::OnTrigPrevInMine() {
745 ASSERT(Current_trigger != -1);
746
747 if (--Current_trigger < 0)
748 Current_trigger += Num_triggers;
749
750 SetCurroomFromTrigger();
751
752 UpdateDialog();
753 }
754
755 void CTriggerDialog::OnTrigPrevInRoom() {
756 int n = FindPrevTrigInRoom(ROOMNUM(Curroomp), Current_trigger);
757
758 ASSERT(n != -1);
759
760 Current_trigger = n;
761
762 SetCurroomFromTrigger();
763 }
764
765 #include "osiris_predefs.h"
766 extern bool StripLeadingTrailingSpaces(char *s);
767
768 void CTriggerDialog::OnTrigEditName() {
769 ASSERT(Current_trigger != -1);
770
771 trigger *tp = &Triggers[Current_trigger];
772
773 char name[TRIG_NAME_LEN + 1];
774
775 strcpy(name, tp->name);
776
777 try_again:;
778 if (!InputString(name, sizeof(name), "Trigger Name", "Enter a new name:"))
779 return;
780
781 if (StripLeadingTrailingSpaces(name))
782 EditorMessageBox("Note: Leading and/or trailing spaces have been removed from this name (\"%s\")", name);
783
784 int n = osipf_FindTriggerName(name);
785 if ((n != -1) && (n != Current_trigger)) {
786 EditorMessageBox("Trigger %d already has this name.", n);
787 goto try_again;
788 }
789
790 strcpy(tp->name, name);
791
792 UpdateDialog();
793 }
794
795 void CTriggerDialog::OnTrigEditScript() {
796
797 mprintf(0, "Edit script for trigger %d\n", Current_trigger);
798
799 // Make sure Dallas is open
800 if (theApp.m_DallasModelessDlgPtr == NULL) {
801 theApp.m_DallasModelessDlgPtr = new CDallasMainDlg;
802 theApp.m_DallasModelessDlgPtr->Create(IDD_DALLAS_MAIN_DIALOG, this);
803 theApp.m_DallasModelessDlgPtr->ShowWindow(SW_SHOW);
804 } else
805 theApp.m_DallasModelessDlgPtr->ShowWindow(SW_RESTORE);
806
807 // make sure a trigger was selected
808 if (Current_trigger == -1)
809 return;
810
811 // Tell Dallas to add a new script with this trigger as the owner
812 theApp.m_DallasModelessDlgPtr->m_ScriptOwnerType = TRIGGER_TYPE;
813 theApp.m_DallasModelessDlgPtr->m_ScriptOwnerHandle = Current_trigger;
814 theApp.m_DallasModelessDlgPtr->PostMessage(WM_HIGHLIGHT_SCRIPTS);
815 }
816
817 void CTriggerDialog::OnTrigActivClutter() {
818 trigger *tp = &Triggers[Current_trigger];
819
820 if (((CButton *)GetDlgItem(IDC_TRIG_ACTIV_CLUTTER))->GetCheck())
821 tp->activator |= AF_CLUTTER;
822 else
823 tp->activator &= ~AF_CLUTTER;
824
825 World_changed = 1;
826 }