From e3af33c9db313d288f6b86a35b8ee705376aebfb Mon Sep 17 00:00:00 2001 From: PatR Date: Mon, 24 Jun 2019 18:39:24 -0700 Subject: [PATCH 1/3] curses 'perm_invent' fixes I noticed the wrapping issue while testing out the 'bad fruit' fix, then the other things while fixing it. 1) inventory entries too wide for narrow persistent inventory window wrapped without any control; normally can't be seen except for the last entry when the list is short enough to leave at least one line available; it looked fairly reasonable with window borders Off, but when On the last char of the first line and first char of second line were clobbered by the border box; 2) when there were too many entries to fit within the height, those after the last one which fit were appended to it for borders Off (or written on bottom line and then overwritten by the border box for borders On); noticed because the selector letter is highlighted with inverse video, even when written at an unexpected place; 3) suppress the inverse video hightlighting of inventory letters since they can't be selected from that 'menu'; 4) for borders Off, the top line was left blank as if a border was going to be drawn there; 5) since the entries are truncated due to the narrow window (on a modest sized display), strip off leading "a", "an", or "the" prefix for inventory entries (written to curses perm_invent window only); lets a couple more characters of more interesting stuff be seen. --- doc/fixes36.3 | 15 ++++++++++- win/curses/cursinvt.c | 62 ++++++++++++++++++++++++++++++++++--------- 2 files changed, 63 insertions(+), 14 deletions(-) diff --git a/doc/fixes36.3 b/doc/fixes36.3 index 98a1c79f3..45975b85c 100644 --- a/doc/fixes36.3 +++ b/doc/fixes36.3 @@ -1,4 +1,4 @@ -$NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.66 $ $NHDT-Date: 1561414302 2019/06/24 22:11:42 $ +$NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.67 $ $NHDT-Date: 1561426762 2019/06/25 01:39:22 $ 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, @@ -144,6 +144,16 @@ curses: don't convert ^M (or or key) into ^J; both ^J and ^M cause the hero to try to move curses: draw map in screen columns 1..79 like tty, rather than in 2..80 curses: make text windows wider so that help feedback is more readable +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 + borders Off but clearly wrong for borders On +curses+'perm_invent': if too many entries for window height, last one which + fit had the next one appended (including hightlighted selector letter) + when window borders were Off +curses+'perm_invent': top line was wasted (left blank) when borders Off +curses+'perm_invent': don't highlight inventory letters since nothing is + selectable from the menu comprising the persistent inventory window curses+EDIT_GETLIN: when a prompt's answer was preloaded, using ESC to discard it deleted it from the answer buffer but didn't erase it from screen tty: re-do one optimization used when status conditions have all been removed @@ -163,6 +173,9 @@ classify sources as released, beta, or work-in-progress via NH_DEVEL_STATUS if you reach the edge of a level (relatively uncommon) and try to move off, report that you can't go farther if the 'mention_walls' option is set wizard-mode: display effect to show where an unseen wished-for monster landed +curses+'perm_invent': since persistent inventory is narrow, strip off "a", + "an", or "the" prefix on inventory entries shown there so that a tiny + bit more of the interesting portion is visible NetHack Community Patches (or Variation) Included diff --git a/win/curses/cursinvt.c b/win/curses/cursinvt.c index 17af0381b..6cb8cd67c 100644 --- a/win/curses/cursinvt.c +++ b/win/curses/cursinvt.c @@ -53,7 +53,7 @@ curses_update_inv(void) wnoutrefresh(win); } -/* Adds an inventory item. */ +/* Adds an inventory item. 'y' is 1 rather than 0 for the first item. */ void curses_add_inv(int y, int glyph UNUSED, @@ -61,21 +61,59 @@ curses_add_inv(int y, { WINDOW *win = curses_get_nhwin(INV_WIN); int color = NO_COLOR; - int x = 0; + int x = 0, width, height, available_width, + border = curses_window_has_border(INV_WIN) ? 1 : 0; /* Figure out where to draw the line */ - if (curses_window_has_border(INV_WIN)) { - x++; - } + x += border; /* x starts at 0 and is incremented for border */ + y -= 1 - border; /* y starts at 1 and is decremented for non-border */ + + curses_get_window_size(INV_WIN, &height, &width); + /* + * TODO: + * If border is On and 'y' is too big, turn border Off in order to + * get two more lines of perm_invent. + * + * And/or implement a way to switch focus from map to inventory + * so that the latter can be scrolled. Must not require use of a + * mouse. + * + * Also, when entries are omitted due to lack of space, mark the + * last line to indicate "there's more that you can't see" (like + * horizontal status window does for excess status conditions). + * Normal menu does this via 'page M of N'. + */ + if (y - border >= height) /* 'height' is already -2 for Top+Btm borders */ + return; + available_width = width; /* 'width' also already -2 for Lft+Rgt borders */ wmove(win, y, x); if (accelerator) { +#if 0 attr_t bold = A_BOLD; wattron(win, bold); waddch(win, accelerator); wattroff(win, bold); wprintw(win, ") "); +#else + /* despite being shown as a menu, nothing is selectable from the + persistent inventory window so don't highlight inventory letters */ + wprintw(win, "%c) ", accelerator); +#endif + available_width -= 3; + + /* narrow the entries to fit more of the interesting text; do so + unconditionally rather than trying to figure whether it's needed; + when 'sortpack' is enabled we could also strip out " of" + from " of but if that's to be done, + core ought to do it */ + if (!strncmpi(str, "a ", 2)) + str += 2; + else if (!strncmpi(str, "an ", 3)) + str += 3; + else if (!strncmpi(str, "the ", 4)) + str +=4; } #if 0 /* FIXME: MENU GLYPHS */ if (accelerator && glyph != NO_GLYPH && iflags.use_menu_glyphs) { @@ -84,27 +122,25 @@ curses_add_inv(int y, int symbol = 0; attr_t glyphclr; - mapglyph(glyph, &symbol, &color, &dummy, - u.ux, u.uy); + mapglyph(glyph, &symbol, &color, &dummy, u.ux, u.uy); glyphclr = curses_color_attr(color, 0); wattron(win, glyphclr); wprintw(win, "%c ", symbol); wattroff(win, glyphclr); + available_width -= 2; } #endif if (accelerator /* Don't colorize categories */ && iflags.use_menu_color) { - char str_mutable[BUFSZ]; - - Strcpy(str_mutable, str); attr = 0; - get_menu_coloring(str_mutable, &color, (int *) &attr); + get_menu_coloring(str, &color, (int *) &attr); attr = curses_convert_attr(attr); } - if (color == NO_COLOR) color = NONE; + if (color == NO_COLOR) + color = NONE; curses_toggle_color_attr(win, color, attr, ON); /* wattron(win, attr); */ - wprintw(win, "%s", str); + wprintw(win, "%.*s", available_width, str); /* wattroff(win, attr); */ curses_toggle_color_attr(win, color, attr, OFF); wclrtoeol(win); From 8a9c06f5c150017fdea69a1ce99edef3185d93eb Mon Sep 17 00:00:00 2001 From: PatR Date: Mon, 24 Jun 2019 18:54:38 -0700 Subject: [PATCH 2/3] 'sortpack' vs 'perm_invent' The persistent inventory window wasn't being updated if you toggled the 'sortpack' option interactively. (The new setting was honored once something else triggered a 'perm_invent' update.) The logic for toggling 'fixinv' seemed backwards. I hope this "fix" for that hasn't actually broken it. --- doc/fixes36.3 | 3 ++- src/options.c | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/doc/fixes36.3 b/doc/fixes36.3 index 45975b85c..91e5d7f12 100644 --- a/doc/fixes36.3 +++ b/doc/fixes36.3 @@ -1,4 +1,4 @@ -$NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.67 $ $NHDT-Date: 1561426762 2019/06/25 01:39:22 $ +$NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.68 $ $NHDT-Date: 1561427671 2019/06/25 01:54:31 $ 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, @@ -88,6 +88,7 @@ wizard mode ^I menu could list "Not carrying anything" after inventory items if perm_invent option was On (even on tty where that's not supported) change #adjust to treat carrying only gold as not having anything to adjust saving bones with 'perm_invent' On could result in "Bad fruit #N" warnings +update persistent inventory window immediately if 'sortpack' option is toggled Fixes to Post-3.6.2 Problems that Were Exposed Via git Repository diff --git a/src/options.c b/src/options.c index 20c82ba4e..ef1081172 100644 --- a/src/options.c +++ b/src/options.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 options.c $NHDT-Date: 1561022792 2019/06/20 09:26:32 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.365 $ */ +/* NetHack 3.6 options.c $NHDT-Date: 1561427671 2019/06/25 01:54:31 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.366 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Michael Allison, 2008. */ /* NetHack may be freely redistributed. See license for details. */ @@ -4051,12 +4051,12 @@ boolean tinitial, tfrom_file; if (VIA_WINDOWPORT()) status_initialize(REASSESS_ONLY); context.botl = TRUE; - } else if (boolopt[i].addr == &flags.invlet_constant) { - if (flags.invlet_constant) { + } else if (boolopt[i].addr == &flags.invlet_constant + || boolopt[i].addr == &flags.sortpack) { + if (!flags.invlet_constant) reassign(); - if (iflags.perm_invent) - need_redraw = TRUE; - } + if (iflags.perm_invent) + update_inventory(); } else if (boolopt[i].addr == &flags.lit_corridor || boolopt[i].addr == &flags.dark_room) { /* From 6506f769a692ba246400dd5a4f57c3b52336c65d Mon Sep 17 00:00:00 2001 From: PatR Date: Mon, 24 Jun 2019 19:28:50 -0700 Subject: [PATCH 3/3] fix #H7840 - curses ':' menu search+toggle Using ':' to have search string matching toggle items chosen for selection would show selection highlighting on the current page for items matched off-page. --- doc/fixes36.3 | 5 +++- win/curses/cursdial.c | 58 ++++++++++++++++++++++++++----------------- 2 files changed, 39 insertions(+), 24 deletions(-) diff --git a/doc/fixes36.3 b/doc/fixes36.3 index 91e5d7f12..fcfafe0ab 100644 --- a/doc/fixes36.3 +++ b/doc/fixes36.3 @@ -1,4 +1,4 @@ -$NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.68 $ $NHDT-Date: 1561427671 2019/06/25 01:54:31 $ +$NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.69 $ $NHDT-Date: 1561429723 2019/06/25 02:28:43 $ 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, @@ -145,6 +145,9 @@ curses: don't convert ^M (or or key) into ^J; both ^J and ^M cause the hero to try to move curses: draw map in screen columns 1..79 like tty, rather than in 2..80 curses: make text windows wider so that help feedback is more readable +curses: using ':' for search string matching to toggle menu items in a multple + page menu would highlight arbitrary items on the currently visible + page in sync with the lines that matching items had on other pages 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 diff --git a/win/curses/cursdial.c b/win/curses/cursdial.c index 656d3b6a7..a1058d802 100644 --- a/win/curses/cursdial.c +++ b/win/curses/cursdial.c @@ -101,7 +101,7 @@ static void menu_display_page(nhmenu *menu, WINDOW * win, int page_num, char *); static int menu_get_selections(WINDOW * win, nhmenu *menu, int how); static void menu_select_deselect(WINDOW * win, nhmenu_item *item, - menu_op operation); + menu_op operation, int); static int menu_operation(WINDOW * win, nhmenu *menu, menu_op operation, int page_num); static void menu_clear_selections(nhmenu *menu); @@ -1257,7 +1257,6 @@ menu_get_selections(WINDOW * win, nhmenu *menu, int how) num_selected = -1; } else { num_selected = 0; - } dismiss = TRUE; break; @@ -1361,12 +1360,14 @@ menu_get_selections(WINDOW * win, nhmenu *menu, int how) && strstri(menu_item_ptr->str, search_key)) { if (how == PICK_ONE) { menu_clear_selections(menu); - menu_select_deselect(win, menu_item_ptr, SELECT); + menu_select_deselect(win, menu_item_ptr, + SELECT, curpage); num_selected = 1; dismiss = TRUE; break; } else { - menu_select_deselect(win, menu_item_ptr, INVERT); + menu_select_deselect(win, menu_item_ptr, + INVERT, curpage); } } @@ -1399,19 +1400,22 @@ menu_get_selections(WINDOW * win, nhmenu *menu, int how) if (how == PICK_ONE) { menu_clear_selections(menu); - menu_select_deselect(win, menu_item_ptr, SELECT); + menu_select_deselect(win, menu_item_ptr, + SELECT, curpage); if (count) menu_item_ptr->count = count; num_selected = 1; dismiss = TRUE; break; } else if (how == PICK_ANY && curletter == count_letter) { - menu_select_deselect(win, menu_item_ptr, SELECT); + menu_select_deselect(win, menu_item_ptr, + SELECT, curpage); menu_item_ptr->count = count; count = 0; count_letter = '\0'; } else { - menu_select_deselect(win, menu_item_ptr, INVERT); + menu_select_deselect(win, menu_item_ptr, + INVERT, curpage); } } } @@ -1437,30 +1441,38 @@ menu_get_selections(WINDOW * win, nhmenu *menu, int how) } -/* Select, deselect, or toggle selected for the given menu entry */ +/* Select, deselect, or toggle selected for the given menu entry. + For search operations, the toggled entry might be on a different + page than the one currently shown. */ static void -menu_select_deselect(WINDOW * win, nhmenu_item *item, menu_op operation) +menu_select_deselect(WINDOW *win, nhmenu_item *item, + menu_op operation, int current_page) { int curletter = item->accelerator; + boolean visible = (item->page_num == current_page); - if ((operation == DESELECT) || (item->selected && (operation == INVERT))) { + if (operation == DESELECT || (item->selected && operation == INVERT)) { item->selected = FALSE; - mvwaddch(win, item->line_num + 1, 1, ' '); - curses_toggle_color_attr(win, HIGHLIGHT_COLOR, NONE, ON); - mvwaddch(win, item->line_num + 1, 2, curletter); - curses_toggle_color_attr(win, HIGHLIGHT_COLOR, NONE, OFF); - mvwaddch(win, item->line_num + 1, 3, ')'); + if (visible) { + mvwaddch(win, item->line_num + 1, 1, ' '); + curses_toggle_color_attr(win, HIGHLIGHT_COLOR, NONE, ON); + mvwaddch(win, item->line_num + 1, 2, curletter); + curses_toggle_color_attr(win, HIGHLIGHT_COLOR, NONE, OFF); + mvwaddch(win, item->line_num + 1, 3, ')'); + } } else { item->selected = TRUE; - curses_toggle_color_attr(win, HIGHLIGHT_COLOR, A_REVERSE, ON); - mvwaddch(win, item->line_num + 1, 1, '<'); - mvwaddch(win, item->line_num + 1, 2, curletter); - mvwaddch(win, item->line_num + 1, 3, '>'); - curses_toggle_color_attr(win, HIGHLIGHT_COLOR, A_REVERSE, OFF); + if (visible) { + curses_toggle_color_attr(win, HIGHLIGHT_COLOR, A_REVERSE, ON); + mvwaddch(win, item->line_num + 1, 1, '<'); + mvwaddch(win, item->line_num + 1, 2, curletter); + mvwaddch(win, item->line_num + 1, 3, '>'); + curses_toggle_color_attr(win, HIGHLIGHT_COLOR, A_REVERSE, OFF); + } } - - wrefresh(win); + if (visible) + wrefresh(win); } @@ -1513,7 +1525,7 @@ menu_operation(WINDOW * win, nhmenu *menu, menu_op } if (menu_item_ptr->identifier.a_void != NULL) { - menu_select_deselect(win, menu_item_ptr, operation); + menu_select_deselect(win, menu_item_ptr, operation, current_page); } menu_item_ptr = menu_item_ptr->next_item;