2 * $Logfile: /Freespace2/code/FRED2/WaypointPathDlg.cpp $
10 * Revision 1.1 2002/05/03 03:28:09 root
14 * 2 10/07/98 6:28p Dave
15 * Initial checkin. Renamed all relevant stuff to be Fred2 instead of
16 * Fred. Globalized mission and campaign file extensions. Removed Silent
17 * Threat specific code.
19 * 1 10/07/98 3:02p Dave
21 * 1 10/07/98 3:00p Dave
23 * 12 3/21/98 7:36p Lawrance
24 * Move jump nodes to own lib.
26 * 11 3/10/98 6:11p Hoffoss
27 * Added jump node renaming abilities to Fred.
29 * 10 8/12/97 1:55a Hoffoss
30 * Made extensive changes to object reference checking and handling for
31 * object deletion call.
33 * 9 5/23/97 1:53p Hoffoss
34 * Fixed problems with modeless dialog updating. It won't get caught in
35 * an infinate loop anymore, but still gives an error warning 3 times when
36 * using cancel and trying to switch window focus to main window. Don't
37 * know if I can fix that, but it's not too critical right now.
39 * 8 5/14/97 4:08p Lawrance
40 * removing my_index from game arrays
42 * 7 4/28/97 4:14p Hoffoss
43 * Fixed several bugs involving waypoints.
45 * 6 3/13/97 12:09p Hoffoss
46 * Waypoint path editor finished (apparently I didn't get around to
47 * completing it before).
49 * 5 2/28/97 11:31a Hoffoss
50 * Implemented modeless dialog saving and restoring, and changed some
53 * 4 2/21/97 5:34p Hoffoss
54 * Added extensive modification detection and fixed a bug in initial
57 * 3 2/12/97 5:50p Hoffoss
58 * Expanded on error checking.
60 * 2 2/12/97 12:26p Hoffoss
61 * Expanded on global error checker, added initial orders conflict
62 * checking and warning, added waypoint editor dialog and code.
69 #include "waypointpathdlg.h"
70 #include "management.h"
76 #include "starfield.h"
79 #define ID_JUMP_NODE_MENU 8000
80 #define ID_WAYPOINT_MENU 9000
85 static char THIS_FILE[] = __FILE__;
88 /////////////////////////////////////////////////////////////////////////////
89 // waypoint_path_dlg dialog
91 waypoint_path_dlg::waypoint_path_dlg(CWnd* pParent /*=NULL*/)
92 : CDialog(waypoint_path_dlg::IDD, pParent)
94 //{{AFX_DATA_INIT(waypoint_path_dlg)
100 void waypoint_path_dlg::DoDataExchange(CDataExchange* pDX)
102 CDialog::DoDataExchange(pDX);
103 //{{AFX_DATA_MAP(waypoint_path_dlg)
104 DDX_Text(pDX, IDC_NAME, m_name);
108 BEGIN_MESSAGE_MAP(waypoint_path_dlg, CDialog)
109 //{{AFX_MSG_MAP(waypoint_path_dlg)
115 /////////////////////////////////////////////////////////////////////////////
116 // waypoint_path_dlg message handlers
118 BOOL waypoint_path_dlg::Create()
121 r = CDialog::Create(IDD, Fred_main_wnd);
126 void waypoint_path_dlg::OnInitMenu(CMenu* pMenu)
131 m = pMenu->GetSubMenu(0);
133 for (i=0; i<Num_waypoint_lists; i++)
134 if (Waypoint_lists[i].count)
135 m->AppendMenu(MF_ENABLED | MF_STRING, ID_WAYPOINT_MENU + i, Waypoint_lists[i].name);
137 for (i=0; i<Num_jump_nodes; i++)
138 m->AppendMenu(MF_ENABLED | MF_STRING, ID_JUMP_NODE_MENU + i, Jump_nodes[i].name);
140 m->DeleteMenu(ID_PLACEHOLDER, MF_BYCOMMAND);
141 if (cur_waypoint_list != -1)
142 m->CheckMenuItem(ID_WAYPOINT_MENU + cur_waypoint_list, MF_BYCOMMAND | MF_CHECKED);
144 if (cur_object_index >= 0)
145 if (Objects[cur_object_index].type == OBJ_JUMP_NODE)
146 m->CheckMenuItem(ID_JUMP_NODE_MENU + Objects[cur_object_index].instance, MF_BYCOMMAND | MF_CHECKED);
148 CDialog::OnInitMenu(pMenu);
151 void waypoint_path_dlg::OnOK()
155 void waypoint_path_dlg::OnClose()
158 SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
163 SetWindowPos(Fred_main_wnd, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_HIDEWINDOW);
164 Fred_main_wnd->SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
167 void waypoint_path_dlg::initialize_data(int full_update)
174 if (query_valid_object() && Objects[cur_object_index].type == OBJ_WAYPOINT)
175 Assert(cur_waypoint_list == (Objects[cur_object_index].instance / 65536));
177 if (cur_waypoint_list >= 0) {
178 m_name = _T(Waypoint_lists[cur_waypoint_list].name);
180 } else if (Objects[cur_object_index].type == OBJ_JUMP_NODE) {
181 m_name = _T(Jump_nodes[Objects[cur_object_index].instance].name);
191 GetDlgItem(IDC_NAME)->EnableWindow(enable);
194 int waypoint_path_dlg::update_data(int redraw)
196 char *str, old_name[255];
206 if (query_valid_object() && Objects[cur_object_index].type == OBJ_WAYPOINT)
207 Assert(cur_waypoint_list == (Objects[cur_object_index].instance / 65536));
209 if (cur_waypoint_list >= 0) {
210 if (!strnicmp(m_name, "player ", 7)) {
215 z = MessageBox("Waypoint path names can't start with the word 'player'\n"
216 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
221 m_name = _T(Waypoint_lists[cur_waypoint_list].name);
225 for (i=0; i<MAX_WINGS; i++)
226 if (!stricmp(Wings[i].name, m_name)) {
231 z = MessageBox("This waypoint path name is already being used by a wing\n"
232 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
237 m_name = _T(Waypoint_lists[cur_waypoint_list].name);
241 ptr = GET_FIRST(&obj_used_list);
242 while (ptr != END_OF_LIST(&obj_used_list)) {
243 if (ptr->type == OBJ_SHIP) {
244 if (!stricmp(m_name, Ships[ptr->instance].ship_name)) {
249 z = MessageBox("This waypoint path name is already being used by a ship\n"
250 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
255 m_name = _T(Waypoint_lists[cur_waypoint_list].name);
263 for (i=0; i<MAX_WAYPOINT_LISTS; i++)
264 if (Waypoint_lists[i].count && !stricmp(Waypoint_lists[i].name, m_name) && (i != cur_waypoint_list)) {
269 z = MessageBox("This waypoint path name is already being used by another waypoint path\n"
270 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
275 m_name = _T(Waypoint_lists[cur_waypoint_list].name);
279 for (i=0; i<Num_jump_nodes; i++)
280 if (!stricmp(Jump_nodes[i].name, m_name)) {
285 z = MessageBox("This waypoint path name is already being used by a jump node\n"
286 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
291 m_name = _T(Waypoint_lists[cur_waypoint_list].name);
295 strcpy(old_name, Waypoint_lists[cur_waypoint_list].name);
296 string_copy(Waypoint_lists[cur_waypoint_list].name, m_name, NAME_LENGTH, 1);
298 str = (char *) (LPCTSTR) m_name;
299 if (stricmp(old_name, str)) {
300 update_sexp_references(old_name, str);
301 ai_update_goal_references(REF_TYPE_WAYPOINT, old_name, str);
304 } else if (Objects[cur_object_index].type == OBJ_JUMP_NODE) {
305 inst = Objects[cur_object_index].instance;
306 if (!strnicmp(m_name, "player ", 7)) {
311 z = MessageBox("Jump node names can't start with the word 'player'\n"
312 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
317 m_name = _T(Jump_nodes[inst].name);
321 for (i=0; i<MAX_WINGS; i++)
322 if (!stricmp(Wings[i].name, m_name)) {
327 z = MessageBox("This jump node name is already being used by a wing\n"
328 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
333 m_name = _T(Jump_nodes[inst].name);
337 ptr = GET_FIRST(&obj_used_list);
338 while (ptr != END_OF_LIST(&obj_used_list)) {
339 if (ptr->type == OBJ_SHIP) {
340 if (!stricmp(m_name, Ships[ptr->instance].ship_name)) {
345 z = MessageBox("This jump node name is already being used by a ship\n"
346 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
351 m_name = _T(Jump_nodes[inst].name);
359 for (i=0; i<MAX_WAYPOINT_LISTS; i++)
360 if (Waypoint_lists[i].count && !stricmp(Waypoint_lists[i].name, m_name)) {
365 z = MessageBox("This jump node name is already being used by a waypoint path\n"
366 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
371 m_name = _T(Jump_nodes[inst].name);
375 for (i=0; i<Num_jump_nodes; i++)
376 if ((i != inst) && !stricmp(Jump_nodes[i].name, m_name)) {
381 z = MessageBox("This jump node name is already being used by another jump node\n"
382 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
387 m_name = _T(Jump_nodes[inst].name);
391 strcpy(old_name, Jump_nodes[inst].name);
392 string_copy(Jump_nodes[inst].name, m_name, NAME_LENGTH, 1);
394 str = (char *) (LPCTSTR) m_name;
395 if (stricmp(old_name, str)) {
396 update_sexp_references(old_name, str);
406 BOOL waypoint_path_dlg::OnCommand(WPARAM wParam, LPARAM lParam)
412 if ((id >= ID_WAYPOINT_MENU) && (id < ID_WAYPOINT_MENU + MAX_WAYPOINT_LISTS)) {
413 if (!update_data()) {
414 point = id - ID_WAYPOINT_MENU;
416 ptr = GET_FIRST(&obj_used_list);
417 while (ptr != END_OF_LIST(&obj_used_list)) {
418 if (ptr->type == OBJ_WAYPOINT)
419 if ((ptr->instance / 65536) == point)
420 mark_object(OBJ_INDEX(ptr));
429 if ((id >= ID_JUMP_NODE_MENU) && (id < ID_JUMP_NODE_MENU + Num_jump_nodes)) {
430 if (!update_data()) {
431 point = id - ID_JUMP_NODE_MENU;
433 ptr = GET_FIRST(&obj_used_list);
434 while (ptr != END_OF_LIST(&obj_used_list)) {
435 if (ptr->type == OBJ_JUMP_NODE)
436 if (ptr->instance == point)
437 mark_object(OBJ_INDEX(ptr));
446 return CDialog::OnCommand(wParam, lParam);