From 301a558a9c183bbe69623ef43e41ad48eb157081 Mon Sep 17 00:00:00 2001 From: PatR Date: Sat, 31 Aug 2019 23:51:59 -0700 Subject: [PATCH 1/2] curses menu coloring Have the 'menucolors' option control menu color pattern matching (instead of curses-specific 'guicolor') for all menus, not just for the persistent inventory window. --- doc/fixes36.3 | 6 +++--- include/wincurs.h | 1 + win/curses/cursdial.c | 30 ++++++++++++++++-------------- win/curses/cursinvt.c | 13 ++----------- win/curses/cursmisc.c | 16 ++++++++++++++++ win/curses/cursmisc.h | 3 ++- 6 files changed, 40 insertions(+), 29 deletions(-) diff --git a/doc/fixes36.3 b/doc/fixes36.3 index 58e792bad..14df3035f 100644 --- a/doc/fixes36.3 +++ b/doc/fixes36.3 @@ -1,4 +1,4 @@ -$NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.106 $ $NHDT-Date: 1567273590 2019/08/31 17:46:30 $ +$NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.107 $ $NHDT-Date: 1567302620 2019/09/01 01:50:20 $ This fixes36.3 file is here to capture information about updates in the 3.6.x lineage following the release of 3.6.2 in May 2019. Please note, however, @@ -219,6 +219,8 @@ curses: disable the attempt to support Ctrl+Left_click as an alternate way to generate Right_click for systems with one-button mouse or trackpad; the mouse data passed to nethack didn't match the curses (ncurses on OSX 10.11) documentation and things didn't work as intended +curses: menu coloring required that both 'menucolors' and 'guicolor' be On; + for menus, override guicolor with more-specific menucolors curses+'perm_invent': entries were wrapping without any control; usually not noticeable because next entry overwrote, but visible for final entry when whole inventory fit within the available height; looked ok with @@ -232,8 +234,6 @@ curses+'perm_invent': don't highlight inventory letters since nothing is curses+'perm_invent': could crash during restore if game was saved while hero was swallowed (invalid u.ustuck pointer; suppressing attempts to update persistent inventory window during restore hides the problem) -curses+'perm_invent': menu coloring required that both 'menucolors' and - 'guicolor' be On; override guicolor with more-specific menucolors curses+'popup_dialog': show the text cursor at the end of prompts for single character input curses+DUMPLOG: pass along old messages from save file and quest message diff --git a/include/wincurs.h b/include/wincurs.h index 127cd0faf..8ae45e10e 100644 --- a/include/wincurs.h +++ b/include/wincurs.h @@ -143,6 +143,7 @@ extern boolean curses_map_borders(int *sx, int *sy, int *ex, int *ey, extern int curses_read_char(void); extern void curses_toggle_color_attr(WINDOW *win, int color, int attr, int onoff); +extern void curses_menu_color_attr(WINDOW *, int, int, int); extern void curses_bail(const char *mesg); extern winid curses_get_wid(int type); extern char *curses_copy_of(const char *s); diff --git a/win/curses/cursdial.c b/win/curses/cursdial.c index cb65610f5..0df4921fb 100644 --- a/win/curses/cursdial.c +++ b/win/curses/cursdial.c @@ -1185,21 +1185,20 @@ menu_display_page(nhmenu *menu, WINDOW * win, int page_num, char *selectors) start_col += 2; } #endif - if (iflags.use_menu_color - && (menu_color = get_menu_coloring(menu_item_ptr->str, - &color, &attr)) != 0) { - if (color != NO_COLOR) { - curses_toggle_color_attr(win, color, NONE, ON); - } + color = NO_COLOR; + menu_color = iflags.use_menu_color + && get_menu_coloring(menu_item_ptr->str, &color, &attr); + if (menu_color) { attr = curses_convert_attr(attr); - if (attr != A_NORMAL) { - menu_item_ptr->attr = menu_item_ptr->attr | attr; - } + if (color != NO_COLOR || attr != A_NORMAL) + curses_menu_color_attr(win, color, attr, ON); + } else { + attr = menu_item_ptr->attr; + if (color != NO_COLOR || attr != A_NORMAL) + curses_toggle_color_attr(win, color, attr, ON); } - curses_toggle_color_attr(win, NONE, menu_item_ptr->attr, ON); num_lines = curses_num_lines(menu_item_ptr->str, entry_cols); - for (count = 0; count < num_lines; count++) { if (menu_item_ptr->str && *menu_item_ptr->str) { tmpstr = curses_break_str(menu_item_ptr->str, @@ -1209,10 +1208,13 @@ menu_display_page(nhmenu *menu, WINDOW * win, int page_num, char *selectors) free(tmpstr); } } - if (menu_color && (color != NO_COLOR)) { - curses_toggle_color_attr(win, color, NONE, OFF); + if (color != NO_COLOR || attr != A_NORMAL) { + if (menu_color) + curses_menu_color_attr(win, color, attr, OFF); + else + curses_toggle_color_attr(win, color, attr, OFF); } - curses_toggle_color_attr(win, NONE, menu_item_ptr->attr, OFF); + menu_item_ptr = menu_item_ptr->next_item; } diff --git a/win/curses/cursinvt.c b/win/curses/cursinvt.c index 59b473fcb..c31effe48 100644 --- a/win/curses/cursinvt.c +++ b/win/curses/cursinvt.c @@ -60,7 +60,6 @@ curses_add_inv(int y, CHAR_P accelerator, attr_t attr, const char *str) { WINDOW *win = curses_get_nhwin(INV_WIN); - boolean save_guicolor; int color = NO_COLOR; int x = 0, width, height, available_width, stroffset = 0, border = curses_window_has_border(INV_WIN) ? 1 : 0; @@ -142,16 +141,8 @@ curses_add_inv(int y, } if (color == NO_COLOR) color = NONE; - /* curses_toggle_color_attr() uses 'guicolor' to decide whether to - honor specified color, but persistent inventory window has its own - more-specific control, 'menucolors', so override with that here */ - save_guicolor = iflags.wc2_guicolor; - iflags.wc2_guicolor = iflags.use_menu_color; - curses_toggle_color_attr(win, color, attr, ON); - /* wattron(win, attr); */ + curses_menu_color_attr(win, color, attr, ON); wprintw(win, "%.*s", available_width, str + stroffset); - /* wattroff(win, attr); */ - curses_toggle_color_attr(win, color, attr, OFF); - iflags.wc2_guicolor = save_guicolor; + curses_menu_color_attr(win, color, attr, OFF); wclrtoeol(win); } diff --git a/win/curses/cursmisc.c b/win/curses/cursmisc.c index 3768e53bd..1eb42fa1e 100644 --- a/win/curses/cursmisc.c +++ b/win/curses/cursmisc.c @@ -163,6 +163,22 @@ curses_toggle_color_attr(WINDOW *win, int color, int attr, int onoff) #endif /* TEXTCOLOR */ } +/* call curses_toggle_color_attr() with 'menucolors' instead of 'guicolor' + as the control flag */ + +void +curses_menu_color_attr(WINDOW *win, int color, int attr, int onoff) +{ + boolean save_guicolor = iflags.wc2_guicolor; + + /* curses_toggle_color_attr() uses 'guicolor' to decide whether to + honor specified color, but menu windows have their own + more-specific control, 'menucolors', so override with that here */ + iflags.wc2_guicolor = iflags.use_menu_color; + curses_toggle_color_attr(win, color, attr, onoff); + iflags.wc2_guicolor = save_guicolor; +} + /* clean up and quit - taken from tty port */ diff --git a/win/curses/cursmisc.h b/win/curses/cursmisc.h index 0c871e35f..d76346184 100644 --- a/win/curses/cursmisc.h +++ b/win/curses/cursmisc.h @@ -9,7 +9,8 @@ /* Global declarations */ int curses_read_char(void); -void curses_toggle_color_attr(WINDOW * win, int color, int attr, int onoff); +void curses_toggle_color_attr(WINDOW *win, int color, int attr, int onoff); +void curses_menu_color_attr(WINDOW *win, int color, int attr, int onoff); void curses_bail(const char *mesg); winid curses_get_wid(int type); char *curses_copy_of(const char *s); From 8cf70f77710e73c400bec5bb4a4aa8f6719b446d Mon Sep 17 00:00:00 2001 From: PatR Date: Mon, 2 Sep 2019 02:59:09 -0700 Subject: [PATCH 2/2] fix github issue 217 - monster spellcasting feedback Fixes #217 Feedback when spellcasting monster aimed at the wrong spot due to not being able to see an invisible hero only gave the intended message if hero couldn't see self. The code was using 'if (Invisible)' which checks whether the hero is invisible and can't see invisible, when it should have been using 'if (Invis)' which just tests whether the hero is invisible. It wouldn't surprise if the same problem occurs elsewhere. Those macros are rather error prone. The issue report mentions that one of the affected messages might be unreachable. I didn't investigate that. --- doc/fixes36.3 | 5 ++++- src/mcastu.c | 26 +++++++++++++------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/doc/fixes36.3 b/doc/fixes36.3 index 14df3035f..f51350117 100644 --- a/doc/fixes36.3 +++ b/doc/fixes36.3 @@ -1,4 +1,4 @@ -$NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.107 $ $NHDT-Date: 1567302620 2019/09/01 01:50:20 $ +$NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.108 $ $NHDT-Date: 1567418344 2019/09/02 09:59:04 $ This fixes36.3 file is here to capture information about updates in the 3.6.x lineage following the release of 3.6.2 in May 2019. Please note, however, @@ -133,6 +133,9 @@ have 'O' update persistent inventory window if 'implicit_uncursed', 'O's "set