Fix: SE067 Problem: A number of niggles with the GTK windowing interface: * yn_function assumes that all calls with NULL resp are asking for a direction and does not honour ESC in response strings. Finally, the list of possible responses is not being displayed to the user. * Strength should be shown as, eg., 18/xx rather than 118. * showweight option is not supported. * delay function is not implemented (making animations too fast). * Can generate X server authentication errors if setuid. * Male/Female buttons on options dialog are not properly supported (eg., interaction with player selection) and should be removed. * keypresses from radar windows (and others?) are not checked for keyboard accelerators so that Shift-O and Alt-key combinations don't work as expected. * Does not honour color option in text mode. * Option dialog allows lit_corridor to be toggled before initialization, which the core code doesn't yet support. Bang. * Double clicking on a non-selectable menu option attempts to select it anyway. Bang. * "Gtk-Critical" errors when closing some dialogs (eg., discoveries) using the window manager controls. * Score option (in file menu) doesn't work properly. Mea culpa. * Tombstone window waits for a keypress. If you close the window instead (using the window manager controls), then nothing appears to happen (it is still waiting for the keypress). Compatible with: Slash'EM 0.0.6E1F1 Author: J. Ali Harlow, ali@avrc.city.ac.uk Date: 4 May 2000 diff -Nacrd ../slashem-0.0.6E1F1/include/extern.h ./include/extern.h *** ../slashem-0.0.6E1F1/include/extern.h Wed Apr 26 18:49:27 2000 --- ./include/extern.h Thu May 4 20:18:22 2000 *************** *** 1938,1943 **** --- 1938,1946 ---- E void FDECL(topten, (int)); E void FDECL(prscore, (int,char **)); E struct obj *FDECL(tt_oname, (struct obj *)); + #ifdef GTK_GRAPHICS + E winid NDECL(create_toptenwin); + #endif /* ### track.c ### */ diff -Nacrd ../slashem-0.0.6E1F1/src/options.c ./src/options.c *** ../slashem-0.0.6E1F1/src/options.c Wed Apr 26 18:49:32 2000 --- ./src/options.c Thu May 4 20:18:22 2000 *************** *** 1636,1643 **** * initializing the options --- the vision system * isn't set up yet. */ ! vision_recalc(2); /* shut down vision */ ! vision_full_recalc = 1; /* delayed recalc */ } #ifdef TEXTCOLOR --- 1636,1646 ---- * initializing the options --- the vision system * isn't set up yet. */ ! if (u.uz.dlevel) ! { ! vision_recalc(2); /* shut down vision */ ! vision_full_recalc = 1; /* delayed recalc */ ! } } #ifdef TEXTCOLOR diff -Nacrd ../slashem-0.0.6E1F1/src/topten.c ./src/topten.c *** ../slashem-0.0.6E1F1/src/topten.c Wed Apr 26 18:49:33 2000 --- ./src/topten.c Thu May 4 20:18:22 2000 *************** *** 940,943 **** --- 940,952 ---- } #endif /* NO_SCAN_BRACK */ + #ifdef GTK_GRAPHICS + winid + create_toptenwin() + { + toptenwin = create_nhwindow(NHW_TEXT); + + return toptenwin; + } + #endif /*topten.c*/ diff -Nacrd ../slashem-0.0.6E1F1/sys/unix/Makefile.top ./sys/unix/Makefile.top *** ../slashem-0.0.6E1F1/sys/unix/Makefile.top Wed Apr 26 18:49:40 2000 --- ./sys/unix/Makefile.top Thu May 4 20:18:22 2000 *************** *** 77,83 **** CNF_SHARE_X11ND = x11bigtiles x11tiles pet_mark.xbm # CNF_SHARE_X11ND = x11bigtiles x11tiles pet_mark.xbm rip.xpm ! CNF_SHARE_GTKND = x11bigtiles x11tiles rip.xpm credit.xpm # CNF_SHARE_DATND = $(CNF_SHARE_X11ND) # CNF_SHARE_DATND = $(CNF_SHARE_QTND) --- 77,83 ---- CNF_SHARE_X11ND = x11bigtiles x11tiles pet_mark.xbm # CNF_SHARE_X11ND = x11bigtiles x11tiles pet_mark.xbm rip.xpm ! CNF_SHARE_GTKND = x11bigtiles x11tiles rip.xpm credit.xpm gtkrc # CNF_SHARE_DATND = $(CNF_SHARE_X11ND) # CNF_SHARE_DATND = $(CNF_SHARE_QTND) *************** *** 186,191 **** --- 186,194 ---- rip.xpm: ( cd dat ; $(MAKE) rip.xpm ) + + gtkrc: win/gtk/GTKRC + cp win/gtk/GTKRC dat/gtkrc check-dlb: ( cd dat; $(MAKE) options ) diff -Nacrd ../slashem-0.0.6E1F1/win/gtk/Install.GTK ./win/gtk/Install.GTK *** ../slashem-0.0.6E1F1/win/gtk/Install.GTK Wed Apr 26 18:49:44 2000 --- ./win/gtk/Install.GTK Thu May 4 20:18:22 2000 *************** *** 6,12 **** interface found in ../win/X11. You can download GTK+ from http://www.gtk.org/. You need GTK+ 1.2 or later to use this code. ! The GTK interface comes from JNetHack version 1.1.4 and was written by Issei Numata (issei@guru.gr.jp). JNetHack can be downloaded from http://www.jnethack.org/. --- 6,12 ---- interface found in ../win/X11. You can download GTK+ from http://www.gtk.org/. You need GTK+ 1.2 or later to use this code. ! The GTK interface comes from JNetHack version 1.1.5 and was written by Issei Numata (issei@guru.gr.jp). JNetHack can be downloaded from http://www.jnethack.org/. *************** *** 55,60 **** 5. Follow all the instructions in ../../sys/unix/Install.unx for the remainder of the installation process. ! 6. Copy GTKRC to GAMEDIR/gtkrc after you've done "make install". J. Ali Harlow, ali@avrc.city.ac.uk --- 55,62 ---- 5. Follow all the instructions in ../../sys/unix/Install.unx for the remainder of the installation process. ! 6. Look at GAMEDIR/gtkrc (or FILE_AREA_SHARE/gtkrc if using file areas) ! and overide the styles in your local gtkrc (~/.gtkrc by default) ! if so desired. J. Ali Harlow, ali@avrc.city.ac.uk diff -Nacrd ../slashem-0.0.6E1F1/win/gtk/gtk.c ./win/gtk/gtk.c *** ../slashem-0.0.6E1F1/win/gtk/gtk.c Wed Apr 26 18:49:44 2000 --- ./win/gtk/gtk.c Thu May 4 20:18:22 2000 *************** *** 39,44 **** --- 39,48 ---- NHWindow gtkWindows[MAXWIN]; + static winid rawprint_win = WIN_ERR; + + GtkAccelGroup *accel_group=NULL; + static GtkWidget *credit_window; static GtkWidget *credit_vbox; static GtkWidget *credit_credit; *************** *** 132,138 **** GTK_getlin, GTK_get_ext_cmd, hook, /*tty_number_pad,*/ ! hook, /*tty_delay_output,*/ #ifdef CHANGE_COLOR/* only a Mac option currently */ hook, hook, --- 136,142 ---- GTK_getlin, GTK_get_ext_cmd, hook, /*tty_number_pad,*/ ! GTK_delay_output, #ifdef CHANGE_COLOR/* only a Mac option currently */ hook, hook, *************** *** 430,439 **** "-sall", }; ! id = create_nhwindow(NHW_TEXT); prscore(2, argv); GTK_display_nhwindow(id, TRUE); GTK_destroy_nhwindow(id); keysym = '\0'; } --- 434,444 ---- "-sall", }; ! id = rawprint_win = create_toptenwin(); prscore(2, argv); GTK_display_nhwindow(id, TRUE); GTK_destroy_nhwindow(id); + rawprint_win = WIN_ERR; keysym = '\0'; } *************** *** 537,544 **** static gint default_destroy(GtkWidget *widget, gpointer data) { ! guint *hid = (guint *)data; ! *hid = 0; keysym = '\033'; quit_hook(); --- 542,549 ---- static gint default_destroy(GtkWidget *widget, gpointer data) { ! GtkWindow **w = (GtkWindow **)data; ! *w = NULL; keysym = '\033'; quit_hook(); *************** *** 580,586 **** --- 585,598 ---- static void nh_rc(void) { + #ifndef FILE_AREAS gtk_rc_parse("gtkrc"); + #else + char *rc_file; + rc_file = make_file_name(FILE_AREA_SHARE, "gtkrc"); + gtk_rc_parse(rc_file); + free(rc_file); + #endif } /* *************** *** 1037,1050 **** --- 1049,1075 ---- GTK_init_nhwindows(int *argc, char **argv) { char *credit_file; + uid_t savuid; if(initialized2) goto selection; gtk_set_locale(); nh_rc(); + /* + * setuid hack: make sure that if nethack is setuid, to use real uid + * when opening X11 connections, in case the user is using xauth, since + * the "games" or whatever user probably doesn't have permission to open + * a window on the user's display. This code is harmless if the binary + * is not installed setuid. See include/system.h on compilation failures. + */ + savuid = geteuid(); + (void) seteuid(getuid()); + gtk_init(argc, &argv); + (void) seteuid(savuid); + init_select_player(); /* *************** *** 1133,1140 **** int nplaymenu_items = sizeof(playmenu_items) / sizeof(playmenu_items[0]); int nhelpmenu_items = sizeof(helpmenu_items) / sizeof(helpmenu_items[0]); - GtkAccelGroup *accel_group; - accel_group = gtk_accel_group_new(); main_item_factory = gtk_item_factory_new( --- 1158,1163 ---- *************** *** 1377,1383 **** GTK_SIGNAL_FUNC(default_key_press), NULL); w->hid = gtk_signal_connect( GTK_OBJECT(w->w), "destroy", ! GTK_SIGNAL_FUNC(default_destroy), &w->hid); w->frame = nh_gtk_new_and_add( gtk_frame_new(NULL), w->w, ""); --- 1400,1406 ---- GTK_SIGNAL_FUNC(default_key_press), NULL); w->hid = gtk_signal_connect( GTK_OBJECT(w->w), "destroy", ! GTK_SIGNAL_FUNC(default_destroy), &w->w); w->frame = nh_gtk_new_and_add( gtk_frame_new(NULL), w->w, ""); *************** *** 1509,1515 **** GTK_SIGNAL_FUNC(default_key_press), NULL); hid = gtk_signal_connect( GTK_OBJECT(w), "destroy", ! GTK_SIGNAL_FUNC(default_destroy), &hid); vbox = nh_gtk_new_and_add(gtk_vbox_new(FALSE, 0), w, ""); --- 1532,1538 ---- GTK_SIGNAL_FUNC(default_key_press), NULL); hid = gtk_signal_connect( GTK_OBJECT(w), "destroy", ! GTK_SIGNAL_FUNC(default_destroy), &w); vbox = nh_gtk_new_and_add(gtk_vbox_new(FALSE, 0), w, ""); *************** *** 1587,1592 **** --- 1610,1635 ---- ; } + volatile int delay_finished; + + static gint delay_timeout(gpointer data) + { + delay_finished++; + return FALSE; + } + + void + GTK_delay_output() + { + if (initialized) + { + delay_finished = 0; + gtk_timeout_add(50L, delay_timeout, 0); + while (!delay_finished) + gtk_main_iteration(); + } + } + #define NAME_LINE 0 /* line # for player name */ #define GOLD_LINE 1 /* line # for amount of gold */ #define DEATH_LINE 2 /* line # for death description */ *************** *** 1626,1631 **** --- 1669,1677 ---- gtk_signal_connect( GTK_OBJECT(w), "key_press_event", GTK_SIGNAL_FUNC(default_key_press), NULL); + gtk_signal_connect( + GTK_OBJECT(w), "destroy", + GTK_SIGNAL_FUNC(default_destroy), &w); gtk_widget_realize(w); *************** *** 1729,1749 **** void GTK_raw_print(const char *str) { ! /* ! if(initialized) ! GTK_putstr(NHW_MESSAGE, 0, str); else - */ tty_raw_print(str); } void GTK_raw_print_bold(const char *str) { ! /* ! if(initialized) ! GTK_putstr(NHW_MESSAGE, ATR_BOLD, str); else - */ tty_raw_print_bold(str); } --- 1775,1791 ---- void GTK_raw_print(const char *str) { ! if(rawprint_win != WIN_ERR) ! GTK_putstr(rawprint_win, 0, str); else tty_raw_print(str); } void GTK_raw_print_bold(const char *str) { ! if(rawprint_win != WIN_ERR) ! GTK_putstr(rawprint_win, ATR_BOLD, str); else tty_raw_print_bold(str); } diff -Nacrd ../slashem-0.0.6E1F1/win/gtk/gtkmap.c ./win/gtk/gtkmap.c *** ../slashem-0.0.6E1F1/win/gtk/gtkmap.c Wed Apr 26 18:49:44 2000 --- ./win/gtk/gtkmap.c Thu May 4 20:18:22 2000 *************** *** 50,55 **** --- 50,56 ---- */ static GdkPixmap *radar_pixmap; static GdkPixmap *radar_pixmap2; + extern GtkAccelGroup *accel_group; #define RADAR_MONSTER MAP_YELLOW #define RADAR_HUMAN MAP_WHITE *************** *** 775,780 **** --- 776,782 ---- nh_radar_new() { radar = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_accel_group_attach(accel_group, GTK_OBJECT(radar)); gtk_widget_realize(radar); radar_is_created = 1; *************** *** 929,950 **** #ifdef TEXTCOLOR gdk_draw_rectangle( ! map_pixmap, map_color_gc[MAP_BACKGROUND], TRUE, x * c_width, y * c_height - map_font->ascent, c_width, c_height); gdk_draw_text( map_pixmap, map_font, ! map_color_gc[color], x * c_width, y * c_height, &ch, 1); ! if(glyph_is_pet(glyph) ! #ifdef TEXTCOLOR ! && iflags.hilite_pet ! #endif ! ){ gdk_draw_rectangle( map_pixmap, ! map_color_gc[MAP_RED], FALSE, x * c_width, y * c_height - map_font->ascent, c_width - 1, c_height - 1 --- 931,948 ---- #ifdef TEXTCOLOR gdk_draw_rectangle( ! map_pixmap, map_color_gc[iflags.use_color?MAP_BACKGROUND:MAP_BLACK], TRUE, x * c_width, y * c_height - map_font->ascent, c_width, c_height); gdk_draw_text( map_pixmap, map_font, ! map_color_gc[iflags.use_color?color:MAP_WHITE], x * c_width, y * c_height, &ch, 1); ! if(glyph_is_pet(glyph) && iflags.hilite_pet){ gdk_draw_rectangle( map_pixmap, ! map_color_gc[iflags.use_color?MAP_RED:MAP_WHITE], FALSE, x * c_width, y * c_height - map_font->ascent, c_width - 1, c_height - 1 diff -Nacrd ../slashem-0.0.6E1F1/win/gtk/gtkmenu.c ./win/gtk/gtkmenu.c *** ../slashem-0.0.6E1F1/win/gtk/gtkmenu.c Wed Apr 26 18:49:44 2000 --- ./win/gtk/gtkmenu.c Thu May 4 20:18:22 2000 *************** *** 385,391 **** return 0; for(i=0 ; i 0){ --- 385,391 ---- return 0; for(i=0 ; i 0){ *************** *** 393,399 **** n = 0; for(i=0 ; i 18) { + if (ACURR(A_STR) > STR18(100)) + Sprintf(buf,"%2d",ACURR(A_STR)-100); + else if (ACURR(A_STR) < STR18(100)) + Sprintf(buf, "18/%02d",ACURR(A_STR)-18); + else + Sprintf(buf,"18/**"); + } else + Sprintf(buf, "%-1d",ACURR(A_STR)); + return buf; + } + #ifdef SCORE_ON_BOTL static int f_score() *************** *** 127,132 **** --- 146,171 ---- } #endif + #ifdef SHOW_WEIGHT + static int + f_weight() + { + return flags.showweight; + } + + static char * + stat_weight(void *data) + { + static char buf[50]; + if (flags.showweight) + Sprintf(buf, "%ld/%ld", (long)(inv_weight()+weight_cap()), + (long)weight_cap()); + else + buf[0] = '\0'; + return buf; + } + #endif + #ifdef EXP_ON_BOTL static int f_exp() *************** *** 175,181 **** char *name; void *v; /* pointer for value or function */ void *arg; ! } stat_tab[2][7] = { { {NOVALUE, STAT_TYPE_CHAR_P, NULL, "AC", (void *)&u.uac}, {NOVALUE, STAT_TYPE_INT_P, NULL, "GOLD", (void *)&u.ugold}, --- 214,220 ---- char *name; void *v; /* pointer for value or function */ void *arg; ! } stat_tab[STAT_COLS][STAT_ROWS] = { { {NOVALUE, STAT_TYPE_CHAR_P, NULL, "AC", (void *)&u.uac}, {NOVALUE, STAT_TYPE_INT_P, NULL, "GOLD", (void *)&u.ugold}, *************** *** 192,200 **** #else {NOVALUE, STAT_TYPE_NULL}, #endif }, { ! {NOVALUE, STAT_TYPE_F_INT, NULL, "STR", stat_stat, (void *)A_STR}, {NOVALUE, STAT_TYPE_F_INT, NULL, "DEX", stat_stat, (void *)A_DEX}, {NOVALUE, STAT_TYPE_F_INT, NULL, "CON", stat_stat, (void *)A_CON}, {NOVALUE, STAT_TYPE_F_INT, NULL, "INT", stat_stat, (void *)A_CON}, --- 231,244 ---- #else {NOVALUE, STAT_TYPE_NULL}, #endif + #ifdef SHOW_WEIGHT + {NOVALUE, STAT_TYPE_F_CHAR_P, f_weight, "WEIGHT", stat_weight}, + #else + {NOVALUE, STAT_TYPE_NULL}, + #endif }, { ! {NOVALUE, STAT_TYPE_F_CHAR_P, NULL, "STR", stat_str}, {NOVALUE, STAT_TYPE_F_INT, NULL, "DEX", stat_stat, (void *)A_DEX}, {NOVALUE, STAT_TYPE_F_INT, NULL, "CON", stat_stat, (void *)A_CON}, {NOVALUE, STAT_TYPE_F_INT, NULL, "INT", stat_stat, (void *)A_CON}, *************** *** 276,283 **** if(buf[0]) gtk_label_set_text(GTK_LABEL(dlvl), buf); ! for(i=0 ; i<7 ; ++i) ! for(j=0 ; j<2 ; ++j){ struct nh_stat_tab *t; t = &stat_tab[j][i]; --- 320,327 ---- if(buf[0]) gtk_label_set_text(GTK_LABEL(dlvl), buf); ! for(i=0 ; i