Merge branch 'master' into NetHack-3.7

This commit is contained in:
nhmall
2019-06-28 18:30:47 -04:00
9 changed files with 103 additions and 39 deletions

View File

@@ -135,7 +135,7 @@ curses_line_input_dialog(const char *prompt, char *answer, int buffer)
curses_got_input();
if (buffer > (int) sizeof input)
buffer = (int) sizeof input;
buffer = (int) sizeof input;
maxwidth = term_cols - 2;
if (iflags.window_inited) {
@@ -264,7 +264,8 @@ curses_character_input_dialog(const char *prompt, const char *choices,
any_choice = TRUE;
}
prompt_width = (int) strlen(askstr);
/* +1: room for a trailing space where the cursor will rest */
prompt_width = (int) strlen(askstr) + 1;
if ((prompt_width + 2) > maxwidth) {
prompt_height = curses_num_lines(askstr, maxwidth);
@@ -284,11 +285,11 @@ curses_character_input_dialog(const char *prompt, const char *choices,
/* TODO: add SUPPRESS_HISTORY flag, then after getting a response,
append it and use put_msghistory() on combined prompt+answer */
custompline(OVERRIDE_MSGTYPE, "%s", askstr);
curs_set(1);
}
/*curses_stupid_hack = 0; */
curs_set(1);
while (1) {
#ifdef PDCURSES
answer = wgetch(message_window);
@@ -342,6 +343,7 @@ curses_character_input_dialog(const char *prompt, const char *choices,
if (choices != NULL && answer != '\0' && index(choices, answer))
break;
}
curs_set(0);
if (iflags.wc_popup_dialog) {
/* Kludge to make prompt visible after window is dismissed
@@ -354,7 +356,6 @@ curses_character_input_dialog(const char *prompt, const char *choices,
curses_destroy_win(askwin);
} else {
curses_clear_unhighlight_message_window();
curs_set(0);
}
return answer;
@@ -388,7 +389,8 @@ curses_ext_cmd()
getbegyx(extwin2, y0, x0);
getmaxyx(extwin2, h, w);
extwin = newwin(1, w - 2, y0 + 1, x0 + 1);
if (w - 4 < maxlen) maxlen = w - 4;
if (w - 4 < maxlen)
maxlen = w - 4;
} else {
curses_get_window_xy(MESSAGE_WIN, &winx, &winy);
curses_get_window_size(MESSAGE_WIN, &messageh, &messagew);
@@ -985,14 +987,24 @@ menu_determine_pages(nhmenu *menu)
static void
menu_win_size(nhmenu *menu)
{
int width, height, maxwidth, maxheight, curentrywidth, lastline;
int maxwidth, maxheight, curentrywidth, lastline;
int maxentrywidth = (int) strlen(menu->prompt);
int maxheaderwidth = 0;
nhmenu_item *menu_item_ptr;
maxwidth = 38; /* Reasonable minimum usable width */
if ((term_cols / 2) > maxwidth) {
maxwidth = (term_cols / 2); /* Half the screen */
if (program_state.gameover) {
/* for final inventory disclosure, use full width */
maxwidth = term_cols - 2;
} else {
/* this used to be 38, which is 80/2 - 2 (half a 'normal' sized
screen minus room for a border box), but some data files
have been manually formatted for 80 columns (usually limited
to 78 but sometimes 79, rarely 80 itself) and using a value
less that 40 meant that a full line would wrap twice:
1..38, 39..76, and 77..80 */
maxwidth = 40; /* Reasonable minimum usable width */
if ((term_cols / 2) > maxwidth)
maxwidth = (term_cols / 2); /* Half the screen */
}
maxheight = menu_max_height();
@@ -1017,7 +1029,8 @@ menu_win_size(nhmenu *menu)
}
}
/* If widest entry is smaller than maxwidth, reduce maxwidth accordingly */
/* If widest entry is smaller than maxwidth, reduce maxwidth
accordingly (but not too far; minimum width will be applied below) */
if (maxentrywidth < maxwidth) {
maxwidth = maxentrywidth;
}
@@ -1032,8 +1045,6 @@ menu_win_size(nhmenu *menu)
maxwidth = term_cols - 2;
}
width = maxwidth;
/* Possibly reduce height if only 1 page */
if (!menu_is_multipage(menu, maxwidth, maxheight)) {
menu_item_ptr = menu->entries;
@@ -1047,16 +1058,16 @@ menu_win_size(nhmenu *menu)
if (lastline < maxheight) {
maxheight = lastline;
}
} else { /* If multipage, make sure we have enough width for page footer */
if (width < 20) {
width = 20;
}
}
height = maxheight;
menu->width = width;
menu->height = height;
/* avoid a tiny popup window; when it's shown over the endings of
old messsages rather than over the map, it is fairly easy for
the player to overlook it, particularly when walking around and
stepping on a pile of 2 items; also, multi-page menus need enough
room for "(Page M of N) => " even if all entries are narrower
than that; we specify same minimum width even when single page */
menu->width = max(maxwidth, 25);
menu->height = max(maxheight, 5);
}

View File

@@ -838,8 +838,10 @@ curses_init_options()
#ifdef NCURSES_MOUSE_VERSION
if (iflags.wc_mouse_support) {
mousemask(BUTTON1_CLICKED, NULL);
curses_mouse_support(iflags.wc_mouse_support);
}
#else
iflags.wc_mouse_support = 0;
#endif
}

View File

@@ -26,6 +26,9 @@ extern long curs_mesg_suppress_turn; /* from cursmesg.c */
struct window_procs curses_procs = {
"curses",
(WC_ALIGN_MESSAGE | WC_ALIGN_STATUS | WC_COLOR | WC_HILITE_PET
#ifdef NCURSES_MOUSE_VERSION /* (this macro name works for PDCURSES too) */
| WC_MOUSE_SUPPORT
#endif
| WC_PERM_INVENT | WC_POPUP_DIALOG | WC_SPLASH_SCREEN),
(WC2_DARKGRAY | WC2_HITPOINTBAR
#if defined(STATUS_HILITES)
@@ -906,6 +909,8 @@ curses_preference_update(const char *pref)
redo_status = TRUE;
else if (!strcmp(pref, "align_message"))
redo_main = TRUE;
else if (!strcmp(pref, "mouse_support"))
curses_mouse_support(iflags.wc_mouse_support);
if (redo_main || redo_status)
curs_reset_windows(redo_main, redo_status);

View File

@@ -870,6 +870,13 @@ curses_convert_keys(int key)
return ret;
}
/* we treat buttons 2 and 3 as equivalent so that it doesn't matter which
one is for right-click and which for middle-click; the core uses CLICK_2
for right-click ("not left" click) even though 2 might be middle button;
we also support Ctrl+left-click as another way to get "not left" click
since Mac is traditionally saddled with a one button mouse or trackpad */
#define MOUSEBUTTONS ((BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED) \
| BUTTON_CTRL)
/* Process mouse events. Mouse movement is processed until no further
mouse movement events are available. Returns 0 for a mouse click
@@ -884,12 +891,21 @@ curses_get_mouse(int *mousex, int *mousey, int *mod)
#ifdef NCURSES_MOUSE_VERSION
MEVENT event;
if (getmouse(&event) == OK) { /* When the user clicks left mouse button */
if (event.bstate & BUTTON1_CLICKED) {
if (getmouse(&event) == OK) { /* True if user has clicked */
if ((event.bstate & MOUSEBUTTONS) != 0) {
/*
* The ncurses man page documents wmouse_trafo() incorrectly.
* It says that last argument 'TRUE' translates from screen
* to window and 'FALSE' translates from window to screen,
* but those are backwards. The mouse_trafo() macro calls
* last argument 'to_screen', suggesting that the backwards
* implementation is the intended behavior and the man page
* is describing it wrong.
*/
/* See if coords are in map window & convert coords */
if (wmouse_trafo(mapwin, &event.y, &event.x, TRUE)) {
key = 0; /* Flag mouse click */
*mousex = event.x;
if (wmouse_trafo(mapwin, &event.y, &event.x, FALSE)) {
key = '\0'; /* core uses this to detect a mouse click */
*mousex = event.x + 1; /* +1: screen 0..78 is map 1..79 */
*mousey = event.y;
if (curses_window_has_border(MAP_WIN)) {
@@ -897,7 +913,8 @@ curses_get_mouse(int *mousex, int *mousey, int *mod)
(*mousey)--;
}
*mod = CLICK_1;
*mod = ((event.bstate & (BUTTON1_CLICKED | BUTTON_CTRL))
== BUTTON1_CLICKED) ? CLICK_1 : CLICK_2;
}
}
}
@@ -906,6 +923,24 @@ curses_get_mouse(int *mousex, int *mousey, int *mod)
return key;
}
void
curses_mouse_support(mode)
int mode; /* 0: off, 1: on, 2: alternate on */
{
#ifdef NCURSES_MOUSE_VERSION
mmask_t result, oldmask, newmask;
if (!mode)
newmask = 0;
else
newmask = MOUSEBUTTONS; /* buttons 1, 2, and 3 */
result = mousemask(newmask, &oldmask);
nhUse(result);
#else
nhUse(mode);
#endif
}
static int
parse_escape_sequence(void)

View File

@@ -30,5 +30,6 @@ int curses_read_attrs(const char *attrs);
char *curses_fmt_attrs(char *);
int curses_convert_keys(int key);
int curses_get_mouse(int *mousex, int *mousey, int *mod);
void curses_mouse_support(int);
#endif /* CURSMISC_H */