1 /* SCCS Id: @(#)gnmain.c 3.4 2000/07/16 */
2 /* Copyright (C) 1998 by Erik Andersen <andersee@debian.org> */
3 /* NetHack may be freely redistributed. See license for details. */
18 static GtkWidget* mainWindow=NULL;
19 static GtkWidget *about=NULL;
20 static GtkWidget* hBoxFirstRow;
21 static GtkWidget* vBoxMain;
24 int os_x = 0, os_y = 0, os_w = 0, os_h = 0;
27 static GnomeClient *session_id;
30 void ghack_quit_game(GtkWidget *widget, int button)
32 gtk_widget_hide(widget);
34 gnome_exit_nhwindows(0);
35 gtk_object_unref(GTK_OBJECT(session_id));
40 void ghack_quit_game_cb(GtkWidget *widget, gpointer data)
43 box = gnome_message_box_new(_("Do you really want to quit?"),
44 GNOME_MESSAGE_BOX_QUESTION, GNOME_STOCK_BUTTON_YES,
45 GNOME_STOCK_BUTTON_NO, NULL);
46 gnome_dialog_set_default( GNOME_DIALOG(box), 1);
47 gnome_dialog_set_parent (GNOME_DIALOG (box),
48 GTK_WINDOW (ghack_get_main_window ()) );
49 gnome_dialog_set_accelerator (GNOME_DIALOG(box), 1, 'n', 0);
50 gnome_dialog_set_accelerator (GNOME_DIALOG(box), 0, 'y', 0);
52 gtk_window_set_modal( GTK_WINDOW(box), TRUE);
53 gtk_signal_connect( GTK_OBJECT(box), "clicked",
54 (GtkSignalFunc)ghack_quit_game, NULL);
59 void ghack_save_game(GtkWidget *widget, int button)
61 gtk_widget_hide(widget);
64 /* make sure they see the Saving message */
65 display_nhwindow(WIN_MESSAGE, TRUE);
66 gnome_exit_nhwindows("Be seeing you...");
67 } else (void)doredraw();
71 void ghack_save_game_cb(GtkWidget *widget, gpointer data)
74 box = gnome_message_box_new(_("Quit and save the current game?"),
75 GNOME_MESSAGE_BOX_QUESTION, GNOME_STOCK_BUTTON_YES,
76 GNOME_STOCK_BUTTON_NO, NULL);
77 gnome_dialog_set_default( GNOME_DIALOG(box), 1);
78 gnome_dialog_set_parent (GNOME_DIALOG (box),
79 GTK_WINDOW (ghack_get_main_window ()) );
80 gnome_dialog_set_accelerator (GNOME_DIALOG(box), 1, 'n', 0);
81 gnome_dialog_set_accelerator (GNOME_DIALOG(box), 0, 'y', 0);
83 gtk_window_set_modal( GTK_WINDOW(box), TRUE);
84 gtk_signal_connect( GTK_OBJECT(box), "clicked",
85 (GtkSignalFunc)ghack_save_game, NULL);
90 void ghack_new_game(GtkWidget *widget, int button)
93 g_message("This feature is not yet implemented. Sorry.");
98 void ghack_new_game_cb(GtkWidget *widget, gpointer data)
101 box = gnome_message_box_new(_("Start a new game?"),
102 GNOME_MESSAGE_BOX_QUESTION, GNOME_STOCK_BUTTON_YES,
103 GNOME_STOCK_BUTTON_NO, NULL);
104 gnome_dialog_set_default( GNOME_DIALOG(box), 1);
105 gnome_dialog_set_parent (GNOME_DIALOG (box),
106 GTK_WINDOW (ghack_get_main_window ()) );
107 gnome_dialog_set_accelerator (GNOME_DIALOG(box), 1, 'n', 0);
108 gnome_dialog_set_accelerator (GNOME_DIALOG(box), 0, 'y', 0);
110 gtk_window_set_modal( GTK_WINDOW(box), TRUE);
111 gtk_signal_connect( GTK_OBJECT(box), "clicked",
112 (GtkSignalFunc)ghack_new_game, NULL);
113 gtk_widget_show(box);
117 about_destroy_callback (void)
123 ghack_about_cb(GtkWidget *widget, gpointer data)
125 char buf[BUFSZ]="\0";
126 char buf1[BUFSZ]="\0";
127 const gchar *authors[] = {"Erik Andersen", "Anthony Taylor",
128 "Jeff Garzik", "The Nethack Dev Team", NULL};
131 gdk_window_raise (about->window);
135 getversionstring(buf);
136 strcat( buf1, VERSION_STRING);
138 _("\nSend comments and bug reports to: nethack-bugs@nethack.org\n"
139 "This game is free software. See License for details."));
140 about = gnome_about_new(_("Nethack"),
141 buf1, "Copyright (C) 1985-2002 Mike Stephenson",
142 (const char **)authors, buf,
145 gtk_signal_connect (GTK_OBJECT (about), "destroy",
146 (GtkSignalFunc) about_destroy_callback, NULL);
148 gtk_widget_show(about);
152 ghack_settings_cb(GtkWidget *widget, gpointer data)
154 ghack_settings_dialog();
158 ghack_accelerator_selected (GtkWidget *widget, gpointer data)
161 int key = GPOINTER_TO_INT( data);
162 /* g_message("An accelerator for \"%c\" was selected", key); */
163 /* stuff a key directly into the keybuffer */
166 ghack_handle_key_press(NULL, &event, NULL);
171 # define M(c) (0x80 | (c))
173 # define M(c) ((c) - 128)
177 #define C(c) (0x1f & (c))
181 GnomeUIInfo game_tree[] =
184 GNOME_APP_UI_ITEM, N_ ("_Change Settings..."),
185 N_("Change Game Settings"), ghack_settings_cb, NULL, NULL,
186 GNOME_APP_PIXMAP_NONE, NULL, 0,0, NULL
188 GNOMEUIINFO_SEPARATOR,
190 GNOME_APP_UI_ITEM, N_("Version"), NULL,
191 ghack_accelerator_selected, GINT_TO_POINTER('v'), NULL,
192 GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_ABOUT, 'v',0
195 GNOME_APP_UI_ITEM, N_("History..."), NULL,
196 ghack_accelerator_selected, GINT_TO_POINTER('V'), NULL,
197 GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_ABOUT, 'V',GDK_SHIFT_MASK
200 GNOME_APP_UI_ITEM, N_("Compilation..."), NULL,
201 ghack_accelerator_selected, GINT_TO_POINTER(M('v')), NULL,
202 GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_ABOUT,'v',GDK_MOD1_MASK
205 GNOME_APP_UI_ITEM, N_("Options..."), NULL,
206 ghack_accelerator_selected, GINT_TO_POINTER('O'), NULL,
207 GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_PREF, 'O', GDK_SHIFT_MASK
210 GNOME_APP_UI_ITEM, N_("Explore Mode..."), NULL,
211 ghack_accelerator_selected, GINT_TO_POINTER('X'), NULL,
212 GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_QUIT, 'X', GDK_SHIFT_MASK
214 GNOMEUIINFO_SEPARATOR,
215 GNOMEUIINFO_MENU_NEW_GAME_ITEM(ghack_new_game_cb, NULL),
216 GNOMEUIINFO_MENU_SAVE_ITEM(ghack_save_game_cb, NULL),
218 GNOME_APP_UI_ITEM, N_("Exit"), NULL,
219 ghack_quit_game_cb, GINT_TO_POINTER(M('Q')), NULL,
220 GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_ABOUT, 'Q', GDK_MOD1_MASK
227 GnomeUIInfo edit_menu[] = {
229 GNOME_APP_UI_ITEM, N_("Inventory"),
230 N_("Edit/View your Inventory"), ghack_accelerator_selected,
231 GINT_TO_POINTER('i'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'i', 0
234 GNOME_APP_UI_ITEM, N_("Discoveries"),
235 N_("Edit/View your Discoveries"),
236 ghack_accelerator_selected,
237 GINT_TO_POINTER('\\'), NULL, GNOME_APP_PIXMAP_NONE, NULL, '\\',0
240 GNOME_APP_UI_ITEM, N_("List/reorder your spells"),
241 N_("List/reorder your spells"), ghack_accelerator_selected,
242 GINT_TO_POINTER('x'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'x', 0
245 GNOME_APP_UI_ITEM, N_("Adjust letters"),
246 N_("Adjust letter for items in your Inventory"), ghack_accelerator_selected,
247 GINT_TO_POINTER(M('a')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'a', GDK_MOD1_MASK
249 GNOMEUIINFO_SEPARATOR,
251 GNOME_APP_UI_ITEM, N_("Name object"),
252 N_("Assign a name to an object"), ghack_accelerator_selected,
253 GINT_TO_POINTER(M('n')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'n', GDK_MOD1_MASK
256 GNOME_APP_UI_ITEM, N_("Name creature"),
257 N_("Assign a name to a creature"), ghack_accelerator_selected,
258 GINT_TO_POINTER('C'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'C', GDK_SHIFT_MASK
260 GNOMEUIINFO_SEPARATOR,
262 GNOME_APP_UI_ITEM, N_("Qualifications"),
263 N_("Edit your Qualifications"), ghack_accelerator_selected,
264 GINT_TO_POINTER(M('e')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'e',GDK_MOD1_MASK
270 GnomeUIInfo apparel_menu[] = {
272 GNOME_APP_UI_ITEM, N_("Wield Weapon"),
273 N_("Select a weapon to fight with"),
274 ghack_accelerator_selected,
275 GINT_TO_POINTER('w'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'w',0
278 GNOME_APP_UI_ITEM, N_("Remove Apparel..."),
279 N_("Remove apparel dialog bog"), ghack_accelerator_selected,
280 GINT_TO_POINTER('A'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'A',GDK_SHIFT_MASK
282 GNOMEUIINFO_SEPARATOR,
284 GNOME_APP_UI_ITEM, N_("Wear Armor"),
285 N_("Put on armor"), ghack_accelerator_selected,
286 GINT_TO_POINTER('W'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'W',GDK_SHIFT_MASK
289 GNOME_APP_UI_ITEM, N_("Take off Armor"),
290 N_("Take off armor you are wearing"), ghack_accelerator_selected,
291 GINT_TO_POINTER('T'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'T',GDK_SHIFT_MASK
293 GNOMEUIINFO_SEPARATOR,
295 GNOME_APP_UI_ITEM, N_("Put on non-armor"),
296 N_("Put on non-armor apparel"), ghack_accelerator_selected,
297 GINT_TO_POINTER('P'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'P',GDK_SHIFT_MASK
300 GNOME_APP_UI_ITEM, N_("Remove non-armor"),
301 N_("Remove non-armor apparel you are wearing"), ghack_accelerator_selected,
302 GINT_TO_POINTER('R'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'R',GDK_SHIFT_MASK
307 GnomeUIInfo action_menu[] = {
309 GNOME_APP_UI_ITEM, N_("Get"),
310 N_("Pick up things at the current location"),
311 ghack_accelerator_selected,
312 GINT_TO_POINTER(','), NULL, GNOME_APP_PIXMAP_NONE, NULL, ',',0
315 GNOME_APP_UI_ITEM, N_("Loot"),
316 N_("loot a box on the floor"),
317 ghack_accelerator_selected,
318 GINT_TO_POINTER(M('l')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'l',GDK_MOD1_MASK
321 GNOME_APP_UI_ITEM, N_("Sit"),
323 ghack_accelerator_selected,
324 GINT_TO_POINTER(M('s')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 's',GDK_MOD1_MASK
327 GNOME_APP_UI_ITEM, N_("Force"),
329 ghack_accelerator_selected,
330 GINT_TO_POINTER(M('f')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'f',GDK_MOD1_MASK
333 GNOME_APP_UI_ITEM, N_("Kick"),
334 N_("kick something (usually a door)"),
335 ghack_accelerator_selected,
336 GINT_TO_POINTER(C('d')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'd',GDK_CONTROL_MASK
339 GNOME_APP_UI_ITEM, N_("Jump"),
340 N_("jump to another location"),
341 ghack_accelerator_selected,
342 GINT_TO_POINTER(M('j')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'j',GDK_MOD1_MASK
346 GNOME_APP_UI_ITEM, N_("Ride"),
347 N_("Ride (or stop riding) a monster"),
349 GINT_TO_POINTER(M('r')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'R',GDK_MOD1_MASK
353 GNOME_APP_UI_ITEM, N_("Wipe face"),
354 N_("wipe off your face"),
355 ghack_accelerator_selected,
356 GINT_TO_POINTER(M('w')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'w',GDK_MOD1_MASK
359 GNOME_APP_UI_ITEM, N_("Throw/Shoot"),
360 N_("throw or shoot a weapon"),
361 ghack_accelerator_selected,
362 GINT_TO_POINTER('t'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 't',0
365 GNOME_APP_UI_ITEM, N_("Quiver/Ready"),
366 N_("ready or quiver some ammunition"),
367 ghack_accelerator_selected,
368 GINT_TO_POINTER('Q'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'Q',GDK_SHIFT_MASK,
371 GNOME_APP_UI_ITEM, N_("Open Door"),
373 ghack_accelerator_selected,
374 GINT_TO_POINTER('o'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'o',0
377 GNOME_APP_UI_ITEM, N_("Close Door"),
379 ghack_accelerator_selected,
380 GINT_TO_POINTER('c'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'c',0
382 GNOMEUIINFO_SEPARATOR,
384 GNOME_APP_UI_ITEM, N_("Drop"),
385 N_("drop an object"),
386 ghack_accelerator_selected,
387 GINT_TO_POINTER('d'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'd',0
390 GNOME_APP_UI_ITEM, N_("Drop Many"),
391 N_("drop selected types of objects"),
392 ghack_accelerator_selected,
393 GINT_TO_POINTER('D'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'D',GDK_SHIFT_MASK
396 GNOME_APP_UI_ITEM, N_("Eat"),
398 ghack_accelerator_selected,
399 GINT_TO_POINTER('e'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'e',0
402 GNOME_APP_UI_ITEM, N_("Engrave"),
403 N_("write a message in the dust on the floor"),
404 ghack_accelerator_selected,
405 GINT_TO_POINTER('E'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'E',GDK_SHIFT_MASK
408 GNOME_APP_UI_ITEM, N_("Apply"),
409 N_("apply or use a tool (pick-axe, key, camera, etc.)"),
410 ghack_accelerator_selected,
411 GINT_TO_POINTER('a'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'a',0
413 GNOMEUIINFO_SEPARATOR,
415 GNOME_APP_UI_ITEM, N_("Up"),
416 N_("go up the stairs"),
417 ghack_accelerator_selected,
418 GINT_TO_POINTER('<'), NULL, GNOME_APP_PIXMAP_NONE, NULL, '<',0
421 GNOME_APP_UI_ITEM, N_("Down"),
422 N_("go down the stairs"),
423 ghack_accelerator_selected,
424 GINT_TO_POINTER('>'), NULL, GNOME_APP_PIXMAP_NONE, NULL, '>',0
427 GNOME_APP_UI_ITEM, N_("Rest"),
428 N_("wait for a moment"),
429 ghack_accelerator_selected,
430 GINT_TO_POINTER('.'), NULL, GNOME_APP_PIXMAP_NONE, NULL, '.',0
433 GNOME_APP_UI_ITEM, N_("Search"),
434 N_("search for secret doors, hidden traps and monsters"),
435 ghack_accelerator_selected,
436 GINT_TO_POINTER('s'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 's',0
438 GNOMEUIINFO_SEPARATOR,
440 GNOME_APP_UI_ITEM, N_("Chat"),
441 N_("talk to someone"),
442 ghack_accelerator_selected,
443 GINT_TO_POINTER(M('c')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'c',GDK_MOD1_MASK
446 GNOME_APP_UI_ITEM, N_("Pay"),
447 N_("pay your bill to the shopkeeper"),
448 ghack_accelerator_selected,
449 GINT_TO_POINTER('p'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'p',0
454 GnomeUIInfo magic_menu[] = {
456 GNOME_APP_UI_ITEM, N_("Quaff potion"),
457 N_("drink a potion"),
458 ghack_accelerator_selected,
459 GINT_TO_POINTER('q'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'q',0
462 GNOME_APP_UI_ITEM, N_("Read Book/Scroll"),
463 N_("read a spell book or a scroll"),
464 ghack_accelerator_selected,
465 GINT_TO_POINTER('r'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'r',0
468 GNOME_APP_UI_ITEM, N_("Zap Wand"),
470 ghack_accelerator_selected,
471 GINT_TO_POINTER('z'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'z',0
474 GNOME_APP_UI_ITEM, N_("Zap Spell"),
476 ghack_accelerator_selected,
477 GINT_TO_POINTER('Z'), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'Z',GDK_SHIFT_MASK
479 GNOMEUIINFO_SEPARATOR,
481 GNOME_APP_UI_ITEM, N_("Dip"),
482 N_("dip an object into something"),
483 ghack_accelerator_selected,
484 GINT_TO_POINTER(M('d')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'd',GDK_MOD1_MASK
487 GNOME_APP_UI_ITEM, N_("Rub"),
488 N_("Rub something (i.e. a lamp)"),
489 ghack_accelerator_selected,
490 GINT_TO_POINTER(M('r')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'r',GDK_MOD1_MASK
493 GNOME_APP_UI_ITEM, N_("Invoke"),
494 N_("invoke an object's special powers"),
495 ghack_accelerator_selected,
496 GINT_TO_POINTER(M('i')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'i',GDK_MOD1_MASK
498 GNOMEUIINFO_SEPARATOR,
500 GNOME_APP_UI_ITEM, N_("Offer"),
501 N_("offer a sacrifice to the gods"),
502 ghack_accelerator_selected,
503 GINT_TO_POINTER(M('o')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'o',GDK_MOD1_MASK
506 GNOME_APP_UI_ITEM, N_("Pray"),
507 N_("pray to the gods for help"),
508 ghack_accelerator_selected,
509 GINT_TO_POINTER(M('p')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'p',GDK_MOD1_MASK
511 GNOMEUIINFO_SEPARATOR,
513 GNOME_APP_UI_ITEM, N_("Teleport"),
514 N_("teleport (if you can)"),
515 ghack_accelerator_selected,
516 GINT_TO_POINTER(C('t')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 't',GDK_CONTROL_MASK
519 GNOME_APP_UI_ITEM, N_("Monster Action"),
520 N_("use a monster's special ability"),
521 ghack_accelerator_selected,
522 GINT_TO_POINTER(M('m')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 'm',GDK_MOD1_MASK
525 GNOME_APP_UI_ITEM, N_("Turn Undead"),
527 ghack_accelerator_selected,
528 GINT_TO_POINTER(M('t')), NULL, GNOME_APP_PIXMAP_NONE, NULL, 't',GDK_MOD1_MASK
533 GnomeUIInfo help_menu[] = {
535 GNOME_APP_UI_ITEM, N_("About..."),
536 N_("About GnomeHack"), ghack_about_cb, NULL, NULL,
537 GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_ABOUT, 0, 0, NULL
540 GNOME_APP_UI_ITEM, N_("Help"), NULL,
541 ghack_accelerator_selected,
542 GINT_TO_POINTER('?'), NULL, GNOME_APP_PIXMAP_STOCK,
543 GNOME_STOCK_MENU_ABOUT, '?', 0
545 GNOMEUIINFO_SEPARATOR,
547 GNOME_APP_UI_ITEM, N_("What is here"),
548 N_("Check what items occupy the current location"),
549 ghack_accelerator_selected,
550 GINT_TO_POINTER(':'), NULL, GNOME_APP_PIXMAP_STOCK,
551 GNOME_STOCK_MENU_ABOUT, ':',0
554 GNOME_APP_UI_ITEM, N_("What is that"),
555 N_("Identify an object"),
556 ghack_accelerator_selected,
557 GINT_TO_POINTER(';'), NULL, GNOME_APP_PIXMAP_STOCK,
558 GNOME_STOCK_MENU_ABOUT, ';',0
561 GNOME_APP_UI_ITEM, N_("Identify a map symbol"),
562 N_("Identify a map symbol"),
563 ghack_accelerator_selected,
564 GINT_TO_POINTER('/'), NULL, GNOME_APP_PIXMAP_STOCK,
565 GNOME_STOCK_MENU_ABOUT, '/',0
570 GnomeUIInfo mainmenu[] = {
571 GNOMEUIINFO_MENU_GAME_TREE(game_tree),
572 GNOMEUIINFO_MENU_EDIT_TREE(edit_menu),
573 { GNOME_APP_UI_SUBTREE, N_("Apparel"), NULL, apparel_menu, NULL,
574 NULL, 0, NULL, 0, 0, NULL },
575 { GNOME_APP_UI_SUBTREE, N_("Action"), NULL, action_menu, NULL,
576 NULL, 0, NULL, 0, 0, NULL },
577 { GNOME_APP_UI_SUBTREE, N_("Magic"), NULL, magic_menu, NULL,
578 NULL, 0, NULL, 0, 0, NULL },
579 GNOMEUIINFO_MENU_HELP_TREE(help_menu),
584 ghack_main_window_key_press(GtkWidget *widget, GdkEventKey *event,
587 /* First, turn off the key press propogation. We've got the
588 * key, but we don't wan't the underlying Gtk widgets to get it,
589 * since they do the wrong thing with the arrow keys (shift focus)... */
590 gtk_signal_emit_stop_by_name( GTK_OBJECT(mainWindow), "key_press_event");
592 /* stuff the key event into the keybuffer */
593 ghack_handle_key_press(widget, event, data);
599 parse_args (int argc, char *argv[])
603 struct option options[] = {
605 { "help", no_argument, NULL, 'h' },
606 { "version", no_argument, NULL, 'v' },
613 /* initialize getopt */
618 while( (ch = getopt_long(argc, argv, "hv", options, NULL)) != EOF )
624 _("%s: A gnomified 'Hello World' program\n\n"
625 "Usage: %s [--help] [--version]\n\n"
627 " --help display this help and exit\n"
628 " --version output version information and exit\n"),
633 g_print (_("NetHack %s.\n"), VERSION_STRING);
638 g_print (_("Options error\n"));
645 session_id = gnome_client_new ();
647 session_id = gnome_client_new (
648 /* callback to save the state and parameter for it */
650 /* callback to die and parameter for it */
652 /* id from the previous session if restarted, NULL otherwise */
655 /* set the program name */
656 gnome_client_set_program (session_id, argv[0]);
663 * [ALI] Gnome installs its own handler(s) for SIGBUS, SIGFPE and SIGSEGV.
664 * These handlers will fork and exec a helper program. When that helper
665 * comes to initialize GTK+, it may fail if setuid/setgid. We solve this
666 * by dropping privileges before passing the signal along the chain.
667 * Note: We don't need to either drop or mask the saved ID since this
668 * will be reset when the child process performs the execve() anyway.
673 void (*handler)(int);
678 {SIGILL} /* Not currently handled by Gnome */
681 static void ghack_sig_handler(int signum)
694 for(i = SIZE(ghack_chain) - 1; i >= 0; i--)
695 if (ghack_chain[i].signum == signum) {
696 ghack_chain[i].handler(signum);
700 impossible("Unhandled ghack signal");
707 /* initialize gnome and fir up the main window */
708 void ghack_init_main_window( int argc, char** argv)
714 /* It seems that the authors of gnome_score_init() drop group
715 * priveledges. We need group priveledges, so until we change the
716 * way we save games to do things the gnome way(???), this stays
717 * commented out. (after hours of frusteration...)
720 /* gnome_score_init("gnomehack"); */
722 gettimeofday(&tv, NULL);
729 hide_privileges(TRUE);
730 /* XXX gnome_init must print nethack options for --help, but does not */
731 gnome_init ("nethack", VERSION_STRING, argc, argv);
732 hide_privileges(FALSE);
733 parse_args (argc, argv);
735 /* Initialize the i18n stuff (not that gnomehack supperts it yet...) */
737 textdomain (PACKAGE);
742 mainWindow = gnome_app_new((char *) "nethack",
743 (char *) N_("Nethack for Gnome"));
744 gtk_widget_realize(mainWindow);
746 gtk_widget_set_uposition (mainWindow, os_x, os_y);
747 gtk_widget_set_usize (mainWindow, os_w, os_h);
749 gtk_window_set_default_size( GTK_WINDOW(mainWindow), 800, 600);
750 gtk_window_set_policy(GTK_WINDOW(mainWindow), FALSE, TRUE, TRUE);
751 gnome_app_create_menus(GNOME_APP(mainWindow), mainmenu);
752 gtk_signal_connect(GTK_OBJECT(mainWindow), "key_press_event",
753 GTK_SIGNAL_FUNC(ghack_main_window_key_press), NULL);
754 gtk_signal_connect(GTK_OBJECT(mainWindow), "delete_event",
755 GTK_SIGNAL_FUNC(ghack_quit_game_cb), NULL);
757 /* Put some stuff into our main window */
758 vBoxMain = gtk_vbox_new (FALSE, 0);
759 hBoxFirstRow = gtk_hbox_new (FALSE, 0);
761 /* pack Boxes into other boxes to produce the right structure */
762 gtk_box_pack_start (GTK_BOX (vBoxMain), hBoxFirstRow, FALSE, TRUE, 0);
764 /* pack vBoxMain which contains all our widgets into the main window. */
765 gnome_app_set_contents(GNOME_APP(mainWindow), vBoxMain);
767 /* DONT show the main window yet, due to a Gtk bug that causes it
768 * to not refresh the window when adding widgets after the window
769 * has already been shown */
772 for(i = 0; i < SIZE(ghack_chain); i++)
773 ghack_chain[i].handler =
774 signal(ghack_chain[i].signum, ghack_sig_handler);
777 void ghack_main_window_add_map_window(GtkWidget* win)
781 vBox= gtk_vbox_new (TRUE, 0);
782 gtk_box_pack_start (GTK_BOX (vBox), win, TRUE, TRUE, 2);
783 gtk_box_pack_start (GTK_BOX (vBoxMain), vBox, TRUE, TRUE, 2);
784 gtk_widget_show_all(vBox);
785 /* Ok, now show the main window -- now that we have added in
786 * all the windows (relys on nethack displaying the map window last
787 * (This is an ugly kludge, BTW)
789 gtk_widget_show_all(mainWindow);
793 ghack_main_window_add_message_window(GtkWidget* win)
795 gtk_box_pack_start (GTK_BOX (hBoxFirstRow), win, TRUE, TRUE, 2);
796 gtk_widget_show_all(win);
800 ghack_main_window_add_status_window(GtkWidget* win)
802 gtk_box_pack_start (GTK_BOX (hBoxFirstRow), win, FALSE, TRUE, 2);
803 gtk_widget_show_all(win);
807 ghack_main_window_add_worn_window(GtkWidget* win)
809 gtk_box_pack_end (GTK_BOX (hBoxFirstRow), win, FALSE, TRUE, 2);
810 gtk_widget_show_all(win);
814 ghack_main_window_add_text_window(GtkWidget *win)
816 g_warning("Fixme!!! AddTextWindow is not yet implemented");
820 ghack_main_window_remove_window(GtkWidget *win)
822 g_warning("Fixme!!! RemoveWindow is not yet implemented");
826 ghack_main_window_update_inventory()
828 /* For now, do very little. Eventually we may allow the inv. window
829 to stay active. When we do this, we'll need to implement this...
830 g_warning("Fixme!!! updateInventory is not yet implemented");
832 gnome_display_nhwindow(WIN_WORN, FALSE);
836 ghack_get_main_window()
838 return( GTK_WIDGET(mainWindow) );