Merge branch 'master' into NetHack-3.7

This commit is contained in:
nhmall
2019-06-24 23:54:49 -04:00
4 changed files with 108 additions and 43 deletions

View File

@@ -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;

View File

@@ -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 "<class> of"
from "<prefix><class> of <item><suffix> 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);