\#perminv, 1 of 2: groundwork

Give the window-port side of *_update_inventory() an argument.
Calls in the core still omit that; invent.c's update_inventory()
is the only place that cares.
This commit is contained in:
PatR
2021-03-13 18:17:00 -08:00
parent 160344feaa
commit dd49431296
21 changed files with 235 additions and 179 deletions
+2 -1
View File
@@ -450,10 +450,11 @@ int NetHackQtBind::qt_select_menu(winid wid, int how, MENU_ITEM_P **menu_list)
return window->SelectMenu(how,menu_list);
}
void NetHackQtBind::qt_update_inventory()
void NetHackQtBind::qt_update_inventory(int arg UNUSED)
{
if (main)
main->updateInventory(); // update the paper doll inventory subset
/* doesn't work yet
if (g.program_state.something_worth_saving && iflags.perm_invent)
display_inventory(NULL, false);
+1 -1
View File
@@ -57,7 +57,7 @@ public:
const char *str, unsigned int itemflags);
static void qt_end_menu(winid wid, const char *prompt);
static int qt_select_menu(winid wid, int how, MENU_ITEM_P **menu_list);
static void qt_update_inventory();
static void qt_update_inventory(int);
static void qt_mark_synch();
static void qt_wait_synch();
+30 -8
View File
@@ -84,7 +84,7 @@ AppResources appResources;
void (*input_func)(Widget, XEvent *, String *, Cardinal *);
int click_x, click_y, click_button; /* Click position on a map window */
/* (filled by set_button_values()). */
int updated_inventory;
int updated_inventory; /* used to indicate perm_invent updating */
static int (*old_error_handler) (Display *, XErrorEvent *);
@@ -1239,8 +1239,9 @@ X11_destroy_nhwindow(winid window)
}
}
/* display persistent inventory in its own window */
void
X11_update_inventory(void)
X11_update_inventory(int arg UNUSED)
{
struct xwindow *wp = 0;
@@ -1259,6 +1260,7 @@ X11_update_inventory(void)
/* persistent inventory is up but perm_invent is off, take it down */
x11_no_perminv(wp);
}
return;
}
/* The current implementation has all of the saved lines on the screen. */
@@ -2150,19 +2152,21 @@ release_yn_widgets(void)
XtDestroyWidget(yn_popup), yn_popup = (Widget) 0;
}
/* X11-specific edition of yn_function(), the routine called by the core
to show a prompt and get a single keystroke answer, often 'y' vs 'n' */
/* guts of the X11_yn_function(), not to be confused with core code;
requires an extra argument: ynflags */
char
X11_yn_function(
X11_yn_function_core(
const char *ques, /* prompt text */
const char *choices, /* allowed response chars; any char if Null */
char def) /* default if user hits <space> or <return> */
char def, /* default if user hits <space> or <return> */
unsigned ynflags) /* flags; currently just log-it or not */
{
static XFontStruct *yn_font = 0;
static Dimension yn_minwidth = 0;
char buf[BUFSZ], buf2[BUFSZ];
Arg args[4];
Cardinal num_args;
boolean suppress_logging = (ynflags & YN_NO_LOGMESG) != 0U;
yn_choices = choices; /* set up globals for callback to use */
yn_def = def;
@@ -2341,12 +2345,28 @@ X11_yn_function(
nh_XtPopdown(yn_popup); /* this removes the event grab */
}
char *p = trimspaces(buf); /* remove !slow's extra whitespace */
pline("%s %s", p, (yn_return == '\033') ? "ESC" : visctrl(yn_return));
if (!suppress_logging) {
char *p = trimspaces(buf); /* remove !slow's extra whitespace */
pline("%s %s", p, (yn_return == '\033') ? "ESC" : visctrl(yn_return));
}
return yn_return;
}
/* X11-specific edition of yn_function(), the routine called by the core
to show a prompt and get a single key answer, often 'y' vs 'n' */
char
X11_yn_function(
const char *ques, /* prompt text */
const char *choices, /* allowed response chars; any char if Null */
char def) /* default if user hits <space> or <return> */
{
char res = X11_yn_function_core(ques, choices, def, YN_NORMAL);
return res;
}
/* used when processing window-capability-specific run-time options;
we support toggling tiles on and off via iflags.wc_tiled_map */
void
@@ -2355,6 +2375,8 @@ X11_preference_update(const char *pref)
if (!strcmp(pref, "tiled_map")) {
if (WIN_MAP != WIN_ERR)
display_map_window(&window_list[WIN_MAP]);
} else if (!strcmp(pref, "perm_invent")) {
; /* TODO... */
}
}
+2 -2
View File
@@ -234,9 +234,9 @@ const char *mesg;
}
void
chainin_update_inventory()
chainin_update_inventory(int arg)
{
(*cibase->nprocs->win_update_inventory)(cibase->ndata);
(*cibase->nprocs->win_update_inventory)(cibase->ndata, arg);
}
void
+2 -3
View File
@@ -284,12 +284,11 @@ const char *mesg;
}
void
chainout_update_inventory(vp)
void *vp;
chainout_update_inventory(void *vp, int arg)
{
struct chainout_data *tdp = vp;
(*tdp->nprocs->win_update_inventory)();
(*tdp->nprocs->win_update_inventory)(arg);
}
void
+3 -4
View File
@@ -500,15 +500,14 @@ const char *mesg;
}
void
trace_update_inventory(vp)
void *vp;
trace_update_inventory(void *vp, int arg)
{
struct trace_data *tdp = vp;
fprintf(wc_tracelogf, "%supdate_inventory()\n", INDENT);
fprintf(wc_tracelogf, "%supdate_inventory(%d)\n", INDENT, arg);
PRE;
(*tdp->nprocs->win_update_inventory)(tdp->ndata);
(*tdp->nprocs->win_update_inventory)(tdp->ndata, arg);
POST;
}
+139 -120
View File
@@ -50,14 +50,14 @@ typedef struct nhm {
const char *prompt; /* Menu prompt text */
nhmenu_item *entries; /* Menu entries */
int num_entries; /* Number of menu entries */
int num_pages; /* Number of display pages for entry */
int num_pages; /* Number of display pages for menu */
int height; /* Window height of menu */
int width; /* Window width of menu */
unsigned long mbehavior; /* menu flags */
boolean reuse_accels; /* Non-unique accelerators per page */
boolean bottom_heavy; /* display multi-page menu starting at end */
struct nhm *prev_menu; /* Pointer to previous entry */
struct nhm *next_menu; /* Pointer to next entry */
struct nhm *prev_menu; /* Pointer to previous menu */
struct nhm *next_menu; /* Pointer to next menu */
} nhmenu;
typedef enum menu_op_type {
@@ -877,7 +877,6 @@ get_menu(winid wid)
return NULL; /* Not found */
}
static char
menu_get_accel(boolean first)
{
@@ -1301,9 +1300,138 @@ menu_display_page(nhmenu *menu, WINDOW * win, int page_num, char *selectors)
wrefresh(win);
}
/* split out from menu_get_selections() so that perm_invent scrolling
can be controlled from outside the normal menu activity */
boolean
curs_nonselect_menu_action(WINDOW *win, void *menu_v, int how,
int curletter, int *curpage_p,
char selectors[256], int *num_selected_p)
{
nhmenu_item *menu_item_ptr;
nhmenu *menu = (nhmenu *) menu_v;
boolean dismiss = FALSE;
int menucmd = (curletter <= 0 || curletter >= 255) ? curletter
: (int) (uchar) map_menu_cmd(curletter);
switch (menucmd) {
case KEY_ESC:
*num_selected_p = -1;
dismiss = TRUE;
break;
case '\n':
case '\r':
dismiss = TRUE;
break;
#ifdef NCURSES_MOUSE_VERSION
case KEY_MOUSE: {
MEVENT mev;
if (getmouse(&mev) == OK && how != PICK_NONE) {
if (wmouse_trafo(win, &mev.y, &mev.x, FALSE)) {
int y = mev.y;
menu_item_ptr = get_menuitem_y(menu, win, *curpage_p, y);
if (menu_item_ptr) {
if (how == PICK_ONE) {
menu_clear_selections(menu);
menu_select_deselect(win, menu_item_ptr,
SELECT, *curpage_p);
*num_selected_p = 1;
dismiss = TRUE;
} else {
menu_select_deselect(win, menu_item_ptr,
INVERT, *curpage_p);
}
}
}
}
break;
} /* case KEY_MOUSE */
#endif /*NCURSES_MOUSE_VERSION*/
case KEY_RIGHT:
case KEY_NPAGE:
case MENU_NEXT_PAGE:
case ' ':
if (*curpage_p < menu->num_pages) {
++(*curpage_p);
menu_display_page(menu, win, *curpage_p, selectors);
} else if (menucmd == ' ') {
dismiss = TRUE;
break;
}
break;
case KEY_LEFT:
case KEY_PPAGE:
case MENU_PREVIOUS_PAGE:
if (*curpage_p > 1) {
--(*curpage_p);
menu_display_page(menu, win, *curpage_p, selectors);
}
break;
case KEY_END:
case MENU_LAST_PAGE:
if (*curpage_p != menu->num_pages) {
*curpage_p = menu->num_pages;
menu_display_page(menu, win, *curpage_p, selectors);
}
break;
case KEY_HOME:
case MENU_FIRST_PAGE:
if (*curpage_p != 1) {
*curpage_p = 1;
menu_display_page(menu, win, *curpage_p, selectors);
}
break;
case MENU_SEARCH: {
char search_key[BUFSZ];
search_key[0] = '\0';
curses_line_input_dialog("Search for:", search_key, BUFSZ);
refresh();
touchwin(win);
wrefresh(win);
if (!*search_key)
break;
menu_item_ptr = menu->entries;
while (menu_item_ptr != NULL) {
if (menu_item_ptr->identifier.a_void != NULL
&& strstri(menu_item_ptr->str, search_key)) {
if (how == PICK_ONE) {
menu_clear_selections(menu);
menu_select_deselect(win, menu_item_ptr,
SELECT, *curpage_p);
*num_selected_p = 1;
dismiss = TRUE;
break;
} else {
menu_select_deselect(win, menu_item_ptr,
INVERT, *curpage_p);
}
}
menu_item_ptr = menu_item_ptr->next_item;
}
menu_item_ptr = menu->entries;
break;
} /* case MENU_SEARCH */
default:
if (how == PICK_NONE) {
*num_selected_p = 0;
dismiss = TRUE;
break;
}
}
return dismiss;
}
static int
menu_get_selections(WINDOW * win, nhmenu *menu, int how)
menu_get_selections(WINDOW *win, nhmenu *menu, int how)
{
int curletter, menucmd;
int count = -1;
@@ -1311,7 +1439,7 @@ menu_get_selections(WINDOW * win, nhmenu *menu, int how)
int curpage = !menu->bottom_heavy ? 1 : menu->num_pages;
int num_selected = 0;
boolean dismiss = FALSE;
char search_key[BUFSZ], selectors[256];
char selectors[256];
nhmenu_item *menu_item_ptr = menu->entries;
menu_display_page(menu, win, curpage, selectors);
@@ -1379,119 +1507,11 @@ menu_get_selections(WINDOW * win, nhmenu *menu, int how)
}
if (curletter <= 0 || curletter >= 256 || !selectors[curletter]) {
menucmd = (curletter <= 0 || curletter >= 255) ? curletter
: (int) (uchar) map_menu_cmd(curletter);
switch (menucmd) {
case KEY_ESC:
num_selected = -1;
dismiss = TRUE;
break;
case '\n':
case '\r':
dismiss = TRUE;
break;
#ifdef NCURSES_MOUSE_VERSION
case KEY_MOUSE: {
MEVENT mev;
if (getmouse(&mev) == OK && how != PICK_NONE) {
if (wmouse_trafo(win, &mev.y, &mev.x, FALSE)) {
int y = mev.y;
menu_item_ptr = get_menuitem_y(menu, win, curpage, y);
if (menu_item_ptr) {
if (how == PICK_ONE) {
menu_clear_selections(menu);
menu_select_deselect(win, menu_item_ptr,
SELECT, curpage);
num_selected = 1;
dismiss = TRUE;
} else {
menu_select_deselect(win, menu_item_ptr,
INVERT, curpage);
}
}
}
}
}
break;
#endif /*NCURSES_MOUSE_VERSION*/
case KEY_RIGHT:
case KEY_NPAGE:
case MENU_NEXT_PAGE:
case ' ':
if (curpage < menu->num_pages) {
curpage++;
menu_display_page(menu, win, curpage, selectors);
} else if (curletter == ' ') {
dismiss = TRUE;
break;
}
break;
case KEY_LEFT:
case KEY_PPAGE:
case MENU_PREVIOUS_PAGE:
if (curpage > 1) {
curpage--;
menu_display_page(menu, win, curpage, selectors);
}
break;
case KEY_END:
case MENU_LAST_PAGE:
if (curpage != menu->num_pages) {
curpage = menu->num_pages;
menu_display_page(menu, win, curpage, selectors);
}
break;
case KEY_HOME:
case MENU_FIRST_PAGE:
if (curpage != 1) {
curpage = 1;
menu_display_page(menu, win, curpage, selectors);
}
break;
case MENU_SEARCH:
search_key[0] = '\0';
curses_line_input_dialog("Search for:", search_key, BUFSZ);
refresh();
touchwin(win);
wrefresh(win);
if (!*search_key)
break;
menu_item_ptr = menu->entries;
while (menu_item_ptr != NULL) {
if (menu_item_ptr->identifier.a_void != NULL
&& strstri(menu_item_ptr->str, search_key)) {
if (how == PICK_ONE) {
menu_clear_selections(menu);
menu_select_deselect(win, menu_item_ptr,
SELECT, curpage);
num_selected = 1;
dismiss = TRUE;
break;
} else {
menu_select_deselect(win, menu_item_ptr,
INVERT, curpage);
}
}
menu_item_ptr = menu_item_ptr->next_item;
}
menu_item_ptr = menu->entries;
break;
default:
if (how == PICK_NONE) {
num_selected = 0;
dismiss = TRUE;
break;
}
}
dismiss = curs_nonselect_menu_action(win, (void *) menu, how,
curletter, &curpage,
selectors, &num_selected);
if (num_selected == -1)
return -1;
}
menu_item_ptr = menu->entries;
@@ -1549,7 +1569,6 @@ menu_get_selections(WINDOW * win, nhmenu *menu, int how)
return num_selected;
}
/* 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. */
+3
View File
@@ -22,5 +22,8 @@ void curses_finalize_nhmenu(winid wid, const char *prompt);
int curses_display_nhmenu(winid wid, int how, MENU_ITEM_P **_selected);
boolean curses_menu_exists(winid wid);
void curses_del_menu(winid, boolean);
boolean curs_nonselect_menu_action(WINDOW *win, void *menu, int how,
int curletter, int *curpage_p,
char selectors[256], int *num_selected_p);
#endif /* CURSDIAL_H */
+3 -3
View File
@@ -631,10 +631,10 @@ curses_select_menu(winid wid, int how, MENU_ITEM_P ** selected)
}
void
curses_update_inventory(void)
curses_update_inventory(int arg UNUSED)
{
/* Don't do anything if perm_invent is off unless we
changed the option. */
/* Don't do anything if perm_invent is off unless it was on and
player just changed the option. */
if (!iflags.perm_invent) {
if (curses_get_nhwin(INV_WIN)) {
curs_reset_windows(TRUE, FALSE);
+6 -4
View File
@@ -67,13 +67,15 @@
struct window_procs safe_procs = {
"safe-startup", 0L, 0L,
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* color availability */
safe_init_nhwindows, safe_player_selection, safe_askname, safe_get_nh_event,
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* color availability */
safe_init_nhwindows, safe_player_selection, safe_askname,
safe_get_nh_event,
safe_exit_nhwindows, safe_suspend_nhwindows, safe_resume_nhwindows,
safe_create_nhwindow, safe_clear_nhwindow, safe_display_nhwindow,
safe_destroy_nhwindow, safe_curs, safe_putstr, safe_putmixed,
safe_display_file, safe_start_menu, safe_add_menu, safe_end_menu,
safe_select_menu, safe_message_menu, safe_update_inventory, safe_mark_synch,
safe_select_menu, safe_message_menu, safe_update_inventory,
safe_mark_synch,
safe_wait_synch,
#ifdef CLIPPING
safe_cliparound,
@@ -269,7 +271,7 @@ safe_message_menu(
}
void
safe_update_inventory(void)
safe_update_inventory(int arg UNUSED)
{
return;
}
+3 -1
View File
@@ -3151,9 +3151,11 @@ tty_message_menu(char let, int how, const char *mesg)
return ((how == PICK_ONE && morc == let) || morc == '\033') ? morc : '\0';
}
/* update persistent inventory window */
void
tty_update_inventory(void)
tty_update_inventory(int arg UNUSED)
{
/* tty doesn't support persistent inventory window */
return;
}
+9 -6
View File
@@ -1233,9 +1233,9 @@ mswin_select_menu(winid wid, int how, MENU_ITEM_P **selected)
window up, otherwise empty.
*/
void
mswin_update_inventory(void)
mswin_update_inventory(int arg)
{
logDebug("mswin_update_inventory()\n");
logDebug("mswin_update_inventory(%d)\n", arg);
if (iflags.perm_invent && g.program_state.something_worth_saving
&& iflags.window_inited && WIN_INVEN != WIN_ERR)
display_inventory(NULL, FALSE);
@@ -1303,7 +1303,8 @@ void
mswin_print_glyph(winid wid, xchar x, xchar y,
const glyph_info *glyphinfo, const glyph_info *bkglyphinfo)
{
logDebug("mswin_print_glyph(%d, %d, %d, %d, %d, %lu)\n", wid, x, y, glyphinfo->glyph, bkglyphinfo->glyph);
logDebug("mswin_print_glyph(%d, %d, %d, %d, %d, %lu)\n",
wid, x, y, glyphinfo->glyph, bkglyphinfo->glyph);
if ((wid >= 0) && (wid < MAXWINDOWS)
&& (GetNHApp()->windowlist[wid].win != NULL)) {
@@ -2058,7 +2059,7 @@ mswin_preference_update(const char *pref)
}
if (stricmp(pref, "perm_invent") == 0) {
mswin_update_inventory();
mswin_update_inventory(0);
return;
}
}
@@ -3077,14 +3078,16 @@ status_update(int fldindex, genericptr_t ptr, int chg, int percent, int color, u
DISABLE_WARNING_FORMAT_NONLITERAL
void
mswin_status_update(int idx, genericptr_t ptr, int chg, int percent, int color, unsigned long *condmasks)
mswin_status_update(int idx, genericptr_t ptr, int chg, int percent,
int color, unsigned long *condmasks)
{
long cond, *condptr = (long *) ptr;
char *text = (char *) ptr;
MSNHMsgUpdateStatus update_cmd_data;
int ochar, ci;
logDebug("mswin_status_update(%d, %p, %d, %d, %x, %p)\n", idx, ptr, chg, percent, color, condmasks);
logDebug("mswin_status_update(%d, %p, %d, %d, %x, %p)\n",
idx, ptr, chg, percent, color, condmasks);
if (idx >= 0) {
+1 -1
View File
@@ -161,7 +161,7 @@ void mswin_add_menu(winid wid, const glyph_info *glyphinfo,
const char *str, unsigned int itemflags);
void mswin_end_menu(winid wid, const char *prompt);
int mswin_select_menu(winid wid, int how, MENU_ITEM_P **selected);
void mswin_update_inventory(void);
void mswin_update_inventory(int);
void mswin_mark_synch(void);
void mswin_wait_synch(void);
void mswin_cliparound(int x, int y);