2 * $Logfile: /Freespace2/code/FRED2/WaypointPathDlg.cpp $
10 * Revision 1.2 2002/05/07 03:16:44 theoddone33
11 * The Great Newline Fix
13 * Revision 1.1.1.1 2002/05/03 03:28:09 root
17 * 2 10/07/98 6:28p Dave
18 * Initial checkin. Renamed all relevant stuff to be Fred2 instead of
19 * Fred. Globalized mission and campaign file extensions. Removed Silent
20 * Threat specific code.
22 * 1 10/07/98 3:02p Dave
24 * 1 10/07/98 3:00p Dave
26 * 12 3/21/98 7:36p Lawrance
27 * Move jump nodes to own lib.
29 * 11 3/10/98 6:11p Hoffoss
30 * Added jump node renaming abilities to Fred.
32 * 10 8/12/97 1:55a Hoffoss
33 * Made extensive changes to object reference checking and handling for
34 * object deletion call.
36 * 9 5/23/97 1:53p Hoffoss
37 * Fixed problems with modeless dialog updating. It won't get caught in
38 * an infinate loop anymore, but still gives an error warning 3 times when
39 * using cancel and trying to switch window focus to main window. Don't
40 * know if I can fix that, but it's not too critical right now.
42 * 8 5/14/97 4:08p Lawrance
43 * removing my_index from game arrays
45 * 7 4/28/97 4:14p Hoffoss
46 * Fixed several bugs involving waypoints.
48 * 6 3/13/97 12:09p Hoffoss
49 * Waypoint path editor finished (apparently I didn't get around to
50 * completing it before).
52 * 5 2/28/97 11:31a Hoffoss
53 * Implemented modeless dialog saving and restoring, and changed some
56 * 4 2/21/97 5:34p Hoffoss
57 * Added extensive modification detection and fixed a bug in initial
60 * 3 2/12/97 5:50p Hoffoss
61 * Expanded on error checking.
63 * 2 2/12/97 12:26p Hoffoss
64 * Expanded on global error checker, added initial orders conflict
65 * checking and warning, added waypoint editor dialog and code.
72 #include "waypointpathdlg.h"
73 #include "management.h"
79 #include "starfield.h"
82 #define ID_JUMP_NODE_MENU 8000
83 #define ID_WAYPOINT_MENU 9000
88 static char THIS_FILE[] = __FILE__;
91 /////////////////////////////////////////////////////////////////////////////
92 // waypoint_path_dlg dialog
94 waypoint_path_dlg::waypoint_path_dlg(CWnd* pParent /*=NULL*/)
95 : CDialog(waypoint_path_dlg::IDD, pParent)
97 //{{AFX_DATA_INIT(waypoint_path_dlg)
103 void waypoint_path_dlg::DoDataExchange(CDataExchange* pDX)
105 CDialog::DoDataExchange(pDX);
106 //{{AFX_DATA_MAP(waypoint_path_dlg)
107 DDX_Text(pDX, IDC_NAME, m_name);
111 BEGIN_MESSAGE_MAP(waypoint_path_dlg, CDialog)
112 //{{AFX_MSG_MAP(waypoint_path_dlg)
118 /////////////////////////////////////////////////////////////////////////////
119 // waypoint_path_dlg message handlers
121 BOOL waypoint_path_dlg::Create()
124 r = CDialog::Create(IDD, Fred_main_wnd);
129 void waypoint_path_dlg::OnInitMenu(CMenu* pMenu)
134 m = pMenu->GetSubMenu(0);
136 for (i=0; i<Num_waypoint_lists; i++)
137 if (Waypoint_lists[i].count)
138 m->AppendMenu(MF_ENABLED | MF_STRING, ID_WAYPOINT_MENU + i, Waypoint_lists[i].name);
140 for (i=0; i<Num_jump_nodes; i++)
141 m->AppendMenu(MF_ENABLED | MF_STRING, ID_JUMP_NODE_MENU + i, Jump_nodes[i].name);
143 m->DeleteMenu(ID_PLACEHOLDER, MF_BYCOMMAND);
144 if (cur_waypoint_list != -1)
145 m->CheckMenuItem(ID_WAYPOINT_MENU + cur_waypoint_list, MF_BYCOMMAND | MF_CHECKED);
147 if (cur_object_index >= 0)
148 if (Objects[cur_object_index].type == OBJ_JUMP_NODE)
149 m->CheckMenuItem(ID_JUMP_NODE_MENU + Objects[cur_object_index].instance, MF_BYCOMMAND | MF_CHECKED);
151 CDialog::OnInitMenu(pMenu);
154 void waypoint_path_dlg::OnOK()
158 void waypoint_path_dlg::OnClose()
161 SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
166 SetWindowPos(Fred_main_wnd, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_HIDEWINDOW);
167 Fred_main_wnd->SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
170 void waypoint_path_dlg::initialize_data(int full_update)
177 if (query_valid_object() && Objects[cur_object_index].type == OBJ_WAYPOINT)
178 Assert(cur_waypoint_list == (Objects[cur_object_index].instance / 65536));
180 if (cur_waypoint_list >= 0) {
181 m_name = _T(Waypoint_lists[cur_waypoint_list].name);
183 } else if (Objects[cur_object_index].type == OBJ_JUMP_NODE) {
184 m_name = _T(Jump_nodes[Objects[cur_object_index].instance].name);
194 GetDlgItem(IDC_NAME)->EnableWindow(enable);
197 int waypoint_path_dlg::update_data(int redraw)
199 char *str, old_name[255];
209 if (query_valid_object() && Objects[cur_object_index].type == OBJ_WAYPOINT)
210 Assert(cur_waypoint_list == (Objects[cur_object_index].instance / 65536));
212 if (cur_waypoint_list >= 0) {
213 if (!strnicmp(m_name, "player ", 7)) {
218 z = MessageBox("Waypoint path names can't start with the word 'player'\n"
219 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
224 m_name = _T(Waypoint_lists[cur_waypoint_list].name);
228 for (i=0; i<MAX_WINGS; i++)
229 if (!stricmp(Wings[i].name, m_name)) {
234 z = MessageBox("This waypoint path name is already being used by a wing\n"
235 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
240 m_name = _T(Waypoint_lists[cur_waypoint_list].name);
244 ptr = GET_FIRST(&obj_used_list);
245 while (ptr != END_OF_LIST(&obj_used_list)) {
246 if (ptr->type == OBJ_SHIP) {
247 if (!stricmp(m_name, Ships[ptr->instance].ship_name)) {
252 z = MessageBox("This waypoint path name is already being used by a ship\n"
253 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
258 m_name = _T(Waypoint_lists[cur_waypoint_list].name);
266 for (i=0; i<MAX_WAYPOINT_LISTS; i++)
267 if (Waypoint_lists[i].count && !stricmp(Waypoint_lists[i].name, m_name) && (i != cur_waypoint_list)) {
272 z = MessageBox("This waypoint path name is already being used by another waypoint path\n"
273 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
278 m_name = _T(Waypoint_lists[cur_waypoint_list].name);
282 for (i=0; i<Num_jump_nodes; i++)
283 if (!stricmp(Jump_nodes[i].name, m_name)) {
288 z = MessageBox("This waypoint path name is already being used by a jump node\n"
289 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
294 m_name = _T(Waypoint_lists[cur_waypoint_list].name);
298 strcpy(old_name, Waypoint_lists[cur_waypoint_list].name);
299 string_copy(Waypoint_lists[cur_waypoint_list].name, m_name, NAME_LENGTH, 1);
301 str = (char *) (LPCTSTR) m_name;
302 if (stricmp(old_name, str)) {
303 update_sexp_references(old_name, str);
304 ai_update_goal_references(REF_TYPE_WAYPOINT, old_name, str);
307 } else if (Objects[cur_object_index].type == OBJ_JUMP_NODE) {
308 inst = Objects[cur_object_index].instance;
309 if (!strnicmp(m_name, "player ", 7)) {
314 z = MessageBox("Jump node names can't start with the word 'player'\n"
315 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
320 m_name = _T(Jump_nodes[inst].name);
324 for (i=0; i<MAX_WINGS; i++)
325 if (!stricmp(Wings[i].name, m_name)) {
330 z = MessageBox("This jump node name is already being used by a wing\n"
331 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
336 m_name = _T(Jump_nodes[inst].name);
340 ptr = GET_FIRST(&obj_used_list);
341 while (ptr != END_OF_LIST(&obj_used_list)) {
342 if (ptr->type == OBJ_SHIP) {
343 if (!stricmp(m_name, Ships[ptr->instance].ship_name)) {
348 z = MessageBox("This jump node name is already being used by a ship\n"
349 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
354 m_name = _T(Jump_nodes[inst].name);
362 for (i=0; i<MAX_WAYPOINT_LISTS; i++)
363 if (Waypoint_lists[i].count && !stricmp(Waypoint_lists[i].name, m_name)) {
368 z = MessageBox("This jump node name is already being used by a waypoint path\n"
369 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
374 m_name = _T(Jump_nodes[inst].name);
378 for (i=0; i<Num_jump_nodes; i++)
379 if ((i != inst) && !stricmp(Jump_nodes[i].name, m_name)) {
384 z = MessageBox("This jump node name is already being used by another jump node\n"
385 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
390 m_name = _T(Jump_nodes[inst].name);
394 strcpy(old_name, Jump_nodes[inst].name);
395 string_copy(Jump_nodes[inst].name, m_name, NAME_LENGTH, 1);
397 str = (char *) (LPCTSTR) m_name;
398 if (stricmp(old_name, str)) {
399 update_sexp_references(old_name, str);
409 BOOL waypoint_path_dlg::OnCommand(WPARAM wParam, LPARAM lParam)
415 if ((id >= ID_WAYPOINT_MENU) && (id < ID_WAYPOINT_MENU + MAX_WAYPOINT_LISTS)) {
416 if (!update_data()) {
417 point = id - ID_WAYPOINT_MENU;
419 ptr = GET_FIRST(&obj_used_list);
420 while (ptr != END_OF_LIST(&obj_used_list)) {
421 if (ptr->type == OBJ_WAYPOINT)
422 if ((ptr->instance / 65536) == point)
423 mark_object(OBJ_INDEX(ptr));
432 if ((id >= ID_JUMP_NODE_MENU) && (id < ID_JUMP_NODE_MENU + Num_jump_nodes)) {
433 if (!update_data()) {
434 point = id - ID_JUMP_NODE_MENU;
436 ptr = GET_FIRST(&obj_used_list);
437 while (ptr != END_OF_LIST(&obj_used_list)) {
438 if (ptr->type == OBJ_JUMP_NODE)
439 if (ptr->instance == point)
440 mark_object(OBJ_INDEX(ptr));
449 return CDialog::OnCommand(wParam, lParam);