mirror of
https://codeberg.org/noisytoot/notnotdnethack.git
synced 2025-07-31 09:52:25 +01:00
Add inventory sidebar if perm_invent is enabled
This commit is contained in:
parent
9bc85c04b9
commit
770a678ea8
11 changed files with 218 additions and 27 deletions
|
@ -243,7 +243,9 @@ extern int curses_character_input_dialog(const char *prompt, const char *choices
|
|||
extern int curses_ext_cmd(void);
|
||||
|
||||
extern void curses_create_nhmenu(winid wid);
|
||||
|
||||
#ifdef MENU_COLOR
|
||||
extern boolean get_menu_coloring(char *, int *, int *);
|
||||
#endif
|
||||
extern void curses_add_nhmenu_item(winid wid, int glyph, const ANY_P *identifier,
|
||||
CHAR_P accelerator, CHAR_P group_accel, int attr, const char *str,
|
||||
BOOLEAN_P presel);
|
||||
|
@ -259,10 +261,16 @@ extern void curses_del_menu(winid wid);
|
|||
|
||||
/* cursstat.c */
|
||||
|
||||
extern attr_t curses_color_attr(int nh_color, int bg_color);
|
||||
extern void curses_update_stats(void);
|
||||
|
||||
extern void curses_decrement_highlight(void);
|
||||
|
||||
/* cursinvt.c */
|
||||
|
||||
extern void curses_update_inv(void);
|
||||
extern void curses_add_inv(int, int, CHAR_P, attr_t, const char *,
|
||||
const ANY_P *);
|
||||
|
||||
/* cursinit.c */
|
||||
|
||||
|
|
|
@ -179,9 +179,9 @@ WINTTYOBJ = getline.o termcap.o topl.o wintty.o tile.o
|
|||
WINCURSESSRC = ../win/curses/cursmain.c ../win/curses/curswins.c \
|
||||
../win/curses/cursmisc.c ../win/curses/cursdial.c \
|
||||
../win/curses/cursstat.c ../win/curses/cursinit.c \
|
||||
../win/curses/cursmesg.c
|
||||
../win/curses/cursmesg.c ../win/curses/cursinvt.c
|
||||
WINCURSESOBJ = cursmain.o curswins.o cursmisc.o cursdial.o cursstat.o \
|
||||
cursinit.o cursmesg.o
|
||||
cursinit.o cursmesg.o cursinvt.o
|
||||
#
|
||||
#
|
||||
# files for an X11 port
|
||||
|
@ -637,6 +637,9 @@ cursinit.o: ../win/curses/cursinit.c $(HACK_H) ../include/wincurs.h \
|
|||
cursmesg.o: ../win/curses/cursmesg.c $(HACK_H) ../include/wincurs.h \
|
||||
../win/curses/cursmesg.h
|
||||
$(CC) $(CFLAGS) -c ../win/curses/cursmesg.c
|
||||
cursinvt.o: ../win/curses/cursinvt.c $(HACK_H) ../include/wincurs.h \
|
||||
../win/curses/cursinvt.h
|
||||
$(CC) $(CFLAGS) -c ../win/curses/cursinvt.c
|
||||
Window.o: ../win/X11/Window.c ../include/xwindowp.h ../include/xwindow.h \
|
||||
$(CONFIG_H)
|
||||
$(CC) $(CFLAGS) -c ../win/X11/Window.c
|
||||
|
|
|
@ -65,7 +65,6 @@ static void menu_select_deselect(WINDOW * win, nhmenu_item *item,
|
|||
static int menu_operation(WINDOW * win, nhmenu *menu, menu_op operation,
|
||||
int page_num);
|
||||
static void menu_clear_selections(nhmenu *menu);
|
||||
static boolean get_menu_coloring(char *str, int *color, int *attr);
|
||||
static int menu_max_height(void);
|
||||
|
||||
static nhmenu *nhmenus = NULL; /* NetHack menu array */
|
||||
|
@ -1367,7 +1366,7 @@ menu_clear_selections(nhmenu *menu)
|
|||
applied */
|
||||
|
||||
#ifdef MENU_COLOR
|
||||
static boolean
|
||||
boolean
|
||||
get_menu_coloring(char *str, int *color, int *attr)
|
||||
{
|
||||
struct menucoloring *tmpmc;
|
||||
|
|
|
@ -20,6 +20,9 @@ void curses_create_nhmenu(winid wid);
|
|||
void curses_add_nhmenu_item(winid wid, int glyph, const ANY_P * identifier,
|
||||
CHAR_P accelerator, CHAR_P group_accel, int attr,
|
||||
const char *str, BOOLEAN_P presel);
|
||||
# ifdef MENU_COLOR
|
||||
boolean get_menu_coloring(char *, int *, int *);
|
||||
# endif
|
||||
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);
|
||||
|
|
|
@ -268,6 +268,8 @@ curses_create_main_windows()
|
|||
int message_y = 0;
|
||||
int status_x = 0;
|
||||
int status_y = 0;
|
||||
int inv_x = 0;
|
||||
int inv_y = 0;
|
||||
int map_x = 0;
|
||||
int map_y = 0;
|
||||
|
||||
|
@ -275,28 +277,67 @@ curses_create_main_windows()
|
|||
int message_width = 0;
|
||||
int status_height = 0;
|
||||
int status_width = 0;
|
||||
int inv_height = 0;
|
||||
int inv_width = 0;
|
||||
int map_height = (term_rows - border_space);
|
||||
int map_width = (term_cols - border_space);
|
||||
|
||||
set_window_position(&status_x, &status_y, &status_width, &status_height,
|
||||
status_orientation, &map_x, &map_y, &map_width, &map_height,
|
||||
border_space, 2, 26);
|
||||
set_window_position(&message_x, &message_y, &message_width, &message_height,
|
||||
message_orientation, &map_x, &map_y, &map_width, &map_height,
|
||||
border_space, -1, -25);
|
||||
boolean status_vertical = FALSE;
|
||||
boolean msg_vertical = FALSE;
|
||||
if (status_orientation == ALIGN_LEFT ||
|
||||
status_orientation == ALIGN_RIGHT)
|
||||
status_vertical = TRUE;
|
||||
if (message_orientation == ALIGN_LEFT ||
|
||||
message_orientation == ALIGN_RIGHT)
|
||||
msg_vertical = TRUE;
|
||||
|
||||
if (map_width > COLNO) {
|
||||
/* Vertical windows have priority. Otherwise, priotity is:
|
||||
status > inv > msg */
|
||||
if (status_vertical)
|
||||
set_window_position(&status_x, &status_y, &status_width, &status_height,
|
||||
status_orientation, &map_x, &map_y, &map_width, &map_height,
|
||||
border_space, 2, 26);
|
||||
|
||||
if (flags.perm_invent) {
|
||||
/* Take up all width unless msgbar is also vertical. */
|
||||
int width = -25;
|
||||
if (msg_vertical)
|
||||
width = 25;
|
||||
|
||||
set_window_position(&inv_x, &inv_y, &inv_width, &inv_height,
|
||||
ALIGN_RIGHT, &map_x, &map_y, &map_width, &map_height,
|
||||
border_space, -1, width);
|
||||
}
|
||||
|
||||
if (msg_vertical)
|
||||
set_window_position(&message_x, &message_y, &message_width, &message_height,
|
||||
message_orientation, &map_x, &map_y, &map_width, &map_height,
|
||||
border_space, -1, -25);
|
||||
|
||||
/* Now draw horizontal windows */
|
||||
if (!status_vertical)
|
||||
set_window_position(&status_x, &status_y, &status_width, &status_height,
|
||||
status_orientation, &map_x, &map_y, &map_width, &map_height,
|
||||
border_space, 2, 26);
|
||||
|
||||
if (!msg_vertical)
|
||||
set_window_position(&message_x, &message_y, &message_width, &message_height,
|
||||
message_orientation, &map_x, &map_y, &map_width, &map_height,
|
||||
border_space, -1, -25);
|
||||
|
||||
if (map_width > COLNO)
|
||||
map_width = COLNO;
|
||||
}
|
||||
|
||||
if (map_height > ROWNO) {
|
||||
if (map_height > ROWNO)
|
||||
map_height = ROWNO;
|
||||
}
|
||||
|
||||
if (curses_window_exists(STATUS_WIN)) {
|
||||
curses_del_nhwin(STATUS_WIN);
|
||||
curses_del_nhwin(MESSAGE_WIN);
|
||||
curses_del_nhwin(MAP_WIN);
|
||||
if (flags.perm_invent)
|
||||
curses_del_nhwin(INV_WIN);
|
||||
|
||||
clear();
|
||||
}
|
||||
|
||||
|
@ -306,6 +347,9 @@ curses_create_main_windows()
|
|||
curses_add_nhwin(MESSAGE_WIN, message_height, message_width, message_y,
|
||||
message_x, message_orientation, borders);
|
||||
|
||||
curses_add_nhwin(INV_WIN, inv_height, inv_width, inv_y, inv_x,
|
||||
ALIGN_RIGHT, borders);
|
||||
|
||||
curses_add_nhwin(MAP_WIN, map_height, map_width, map_y, map_x, 0, borders);
|
||||
|
||||
refresh();
|
||||
|
@ -314,6 +358,7 @@ curses_create_main_windows()
|
|||
|
||||
if (iflags.window_inited) {
|
||||
curses_update_stats();
|
||||
curses_update_inventory();
|
||||
} else {
|
||||
iflags.window_inited = TRUE;
|
||||
}
|
||||
|
|
95
win/curses/cursinvt.c
Normal file
95
win/curses/cursinvt.c
Normal file
|
@ -0,0 +1,95 @@
|
|||
/* vim:set cin ft=c sw=4 sts=4 ts=8 et ai cino=Ls\:0t0(0 : -*- mode:c;fill-column:80;tab-width:8;c-basic-offset:4;indent-tabs-mode:nil;c-file-style:"k&r" -*-*/
|
||||
|
||||
#include "curses.h"
|
||||
#include "hack.h"
|
||||
#include "wincurs.h"
|
||||
#include "cursinvt.h"
|
||||
|
||||
/* Permanent inventory for curses interface */
|
||||
|
||||
/* Runs when the game indicates that the inventory has been updated */
|
||||
void
|
||||
curses_update_inv(void)
|
||||
{
|
||||
WINDOW *win = curses_get_nhwin(INV_WIN);
|
||||
|
||||
/* Check if the inventory window is enabled in first place */
|
||||
if (!win)
|
||||
return;
|
||||
|
||||
boolean border = curses_window_has_border(INV_WIN);
|
||||
|
||||
/* Figure out drawing area */
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
if (border) {
|
||||
x++;
|
||||
y++;
|
||||
}
|
||||
|
||||
/* Clear the window as it is at the moment. */
|
||||
werase(win);
|
||||
|
||||
display_inventory(NULL, FALSE);
|
||||
|
||||
if (border)
|
||||
box(win, 0, 0);
|
||||
|
||||
wrefresh(win);
|
||||
}
|
||||
|
||||
/* Adds an inventory item. */
|
||||
void
|
||||
curses_add_inv(int y, int glyph, CHAR_P accelerator, attr_t attr,
|
||||
const char *str, const ANY_P *identifier)
|
||||
{
|
||||
WINDOW *win = curses_get_nhwin(INV_WIN);
|
||||
|
||||
/* Figure out where to draw the line */
|
||||
int x = 0;
|
||||
y--;
|
||||
if (curses_window_has_border(INV_WIN)) {
|
||||
x++;
|
||||
y++;
|
||||
}
|
||||
|
||||
wmove(win, y, x);
|
||||
if (accelerator) {
|
||||
attr_t bold = A_BOLD;
|
||||
wattron(win, bold);
|
||||
waddch(win, accelerator);
|
||||
wattroff(win, bold);
|
||||
wprintw(win, ") ");
|
||||
}
|
||||
|
||||
if (accelerator && glyph != NO_GLYPH && iflags.use_menu_glyphs) {
|
||||
unsigned dummy = 0; /* Not used */
|
||||
int color = 0;
|
||||
int curletter = 0;
|
||||
mapglyph_obj(glyph, &curletter, &color, &dummy,
|
||||
u.ux, u.uy, identifier->a_obj);
|
||||
attr = curses_color_attr(color, 0);
|
||||
wattron(win, attr);
|
||||
wprintw(win, "%c ", curletter);
|
||||
wattroff(win, attr);
|
||||
}
|
||||
|
||||
#ifdef MENU_COLOR
|
||||
if (accelerator && /* Don't colorize categories */
|
||||
iflags.use_menu_color) {
|
||||
int color = NO_COLOR;
|
||||
boolean menu_color = FALSE;
|
||||
char str_mutable[BUFSZ];
|
||||
Strcpy(str_mutable, str);
|
||||
attr = 0;
|
||||
get_menu_coloring(str_mutable, &color, &attr);
|
||||
if (color != NO_COLOR)
|
||||
attr |= curses_color_attr(color, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
wattron(win, attr);
|
||||
wprintw(win, "%s", str);
|
||||
wattroff(win, attr);
|
||||
wclrtoeol(win);
|
||||
}
|
11
win/curses/cursinvt.h
Normal file
11
win/curses/cursinvt.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
/* vim:set cin ft=c sw=4 sts=4 ts=8 et ai cino=Ls\:0t0(0 : -*- mode:c;fill-column:80;tab-width:8;c-basic-offset:4;indent-tabs-mode:nil;c-file-style:"k&r" -*-*/
|
||||
|
||||
#ifndef CURSINVT_H
|
||||
# define CURSINVT_H
|
||||
|
||||
|
||||
/* Global declarations */
|
||||
|
||||
void curses_update_inv(void);
|
||||
|
||||
#endif /* CURSINVT_H */
|
|
@ -65,6 +65,11 @@ struct window_procs curses_procs = {
|
|||
curses_preference_update,
|
||||
};
|
||||
|
||||
/* Track if we're performing an update to the permanent window.
|
||||
Needed since we aren't using the normal menu functions to handle
|
||||
the inventory window. */
|
||||
static int inv_update = 0;
|
||||
|
||||
/*
|
||||
init_nhwindows(int* argcp, char** argv)
|
||||
-- Initialize the windows used by NetHack. This can also
|
||||
|
@ -153,7 +158,6 @@ curses_init_nhwindows(int *argcp, char **argv)
|
|||
curses_display_splash_window();
|
||||
}
|
||||
|
||||
|
||||
/* Do a window-port specific player type selection. If player_selection()
|
||||
offers a Quit option, it is its responsibility to clean up and terminate
|
||||
the process. You need to fill in pl_character[0].
|
||||
|
@ -366,6 +370,9 @@ curses_display_file(const char *filename, BOOLEAN_P must_exist)
|
|||
void
|
||||
curses_start_menu(winid wid)
|
||||
{
|
||||
if (inv_update)
|
||||
return;
|
||||
|
||||
curses_create_nhmenu(wid);
|
||||
}
|
||||
|
||||
|
@ -407,6 +414,13 @@ curses_add_menu(winid wid, int glyph, const ANY_P * identifier,
|
|||
{
|
||||
int curses_attr = curses_convert_attr(attr);
|
||||
|
||||
if (inv_update) {
|
||||
curses_add_inv(inv_update, glyph, accelerator, curses_attr,
|
||||
str, identifier);
|
||||
inv_update++;
|
||||
return;
|
||||
}
|
||||
|
||||
curses_add_nhmenu_item(wid, glyph, identifier, accelerator, group_accel,
|
||||
curses_attr, str, presel);
|
||||
}
|
||||
|
@ -423,6 +437,9 @@ end_menu(window, prompt)
|
|||
void
|
||||
curses_end_menu(winid wid, const char *prompt)
|
||||
{
|
||||
if (inv_update)
|
||||
return;
|
||||
|
||||
curses_finalize_nhmenu(wid, prompt);
|
||||
}
|
||||
|
||||
|
@ -454,17 +471,25 @@ int select_menu(winid window, int how, menu_item **selected)
|
|||
int
|
||||
curses_select_menu(winid wid, int how, MENU_ITEM_P ** selected)
|
||||
{
|
||||
if (inv_update)
|
||||
return 0;
|
||||
|
||||
return curses_display_nhmenu(wid, how, selected);
|
||||
}
|
||||
|
||||
/*
|
||||
-- Indicate to the window port that the inventory has been changed.
|
||||
-- Merely calls display_inventory() for window-ports that leave the
|
||||
window up, otherwise empty.
|
||||
*/
|
||||
void
|
||||
curses_update_inventory()
|
||||
curses_update_inventory(void)
|
||||
{
|
||||
if (!flags.perm_invent)
|
||||
return;
|
||||
|
||||
/* Update inventory sidebar. NetHack uses normal menu functions
|
||||
when drawing the inventory, and we don't want to change the
|
||||
underlying code. So instead, track if an inventory update is
|
||||
being performed with a static variable. */
|
||||
inv_update = 1;
|
||||
curses_update_inv();
|
||||
inv_update = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -20,7 +20,6 @@ static attr_t get_trouble_color(const char *);
|
|||
static void draw_trouble_str(const char *);
|
||||
static void print_statdiff(const char *append, nhstat *, int, int);
|
||||
static void get_playerrank(char *);
|
||||
static attr_t curses_color_attr(int nh_color, int bg_color);
|
||||
static int hpen_color(boolean, int, int);
|
||||
static void draw_bar(boolean, int, int, const char *);
|
||||
static void draw_horizontal(int, int, int, int);
|
||||
|
@ -217,7 +216,7 @@ draw_trouble_str(const char *str)
|
|||
|
||||
/* Returns a ncurses attribute for foreground and background.
|
||||
This should probably be in cursinit.c or something. */
|
||||
static attr_t
|
||||
attr_t
|
||||
curses_color_attr(int nh_color, int bg_color)
|
||||
{
|
||||
int color = nh_color + 1;
|
||||
|
@ -432,7 +431,7 @@ curses_update_stats(void)
|
|||
int y = 0;
|
||||
|
||||
/* Don't start at border position if applicable */
|
||||
if (curses_window_has_border(STATUS_WIN)) {
|
||||
if (border) {
|
||||
x++;
|
||||
y++;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,6 @@
|
|||
|
||||
void curses_update_stats();
|
||||
void curses_decrement_highlights(boolean);
|
||||
|
||||
attr_t curses_color_attr(int nh_color, int bg_color);
|
||||
|
||||
#endif /* CURSSTAT_H */
|
||||
|
|
|
@ -459,6 +459,9 @@ curses_puts(winid wid, int attr, const char *text)
|
|||
|
||||
if (wid == STATUS_WIN) {
|
||||
curses_update_stats(); /* We will do the write ourselves */
|
||||
/* Inventory updating isn't performed on redraws, so
|
||||
also update inventory here... */
|
||||
curses_update_inventory();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -527,7 +530,7 @@ curses_alert_main_borders(boolean onoff)
|
|||
static boolean
|
||||
is_main_window(winid wid)
|
||||
{
|
||||
if ((wid == MESSAGE_WIN) || (wid == MAP_WIN) || (wid == STATUS_WIN)) {
|
||||
if ((wid == MESSAGE_WIN) || (wid == MAP_WIN) || (wid == STATUS_WIN) || wid == INV_WIN) {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue