Change menu_headings to accept color and attribute
Instead of just accepting an attribute, it's now possible to use a color, or both color and attribute, for example: OPTIONS=menu_headings:inverse OPTIONS=menu_headings:red OPTIONS=menu_headings:red&underline Default is still just inverse. This lets the player change the menu heading color without needing to use menu colors for them. Also makes it so the core uses NO_COLOR instead of 0, for all the menu lines which don't have any prefedefined color. Tested for tty, curses, x11, qt, and win32
This commit is contained in:
@@ -34,6 +34,7 @@ typedef struct nhmi {
|
||||
char accelerator; /* Character used to select item from menu */
|
||||
char group_accel; /* Group accelerator for menu item, if any */
|
||||
int attr; /* Text attributes for item */
|
||||
int color; /* Color for item */
|
||||
const char *str; /* Text of menu item */
|
||||
boolean presel; /* Whether menu item should be preselected */
|
||||
boolean selected; /* Whether item is currently selected */
|
||||
@@ -585,7 +586,8 @@ curs_new_menu_item(winid wid, const char *str)
|
||||
new_item->identifier = cg.zeroany;
|
||||
new_item->accelerator = '\0';
|
||||
new_item->group_accel = '\0';
|
||||
new_item->attr = 0;
|
||||
new_item->attr = ATR_NONE;
|
||||
new_item->color = NO_COLOR;
|
||||
new_item->str = new_str;
|
||||
new_item->presel = FALSE;
|
||||
new_item->selected = FALSE;
|
||||
@@ -607,6 +609,7 @@ curses_add_nhmenu_item(
|
||||
char accelerator,
|
||||
char group_accel,
|
||||
int attr,
|
||||
int clr,
|
||||
const char *str,
|
||||
unsigned itemflags)
|
||||
{
|
||||
@@ -630,6 +633,7 @@ curses_add_nhmenu_item(
|
||||
new_item->accelerator = accelerator;
|
||||
new_item->group_accel = group_accel;
|
||||
new_item->attr = attr;
|
||||
new_item->color = clr;
|
||||
new_item->presel = presel;
|
||||
new_item->itemflags = itemflags;
|
||||
current_items = current_menu->entries;
|
||||
@@ -1204,7 +1208,9 @@ menu_display_page(
|
||||
|
||||
for (count = 0; count < num_lines; count++) {
|
||||
tmpstr = curses_break_str(menu->prompt, menu->width, count + 1);
|
||||
curses_toggle_color_attr(win, NO_COLOR, A_NORMAL, ON);
|
||||
mvwprintw(win, count + 1, 1, "%s", tmpstr);
|
||||
curses_toggle_color_attr(win, NO_COLOR, A_NORMAL, OFF);
|
||||
free(tmpstr);
|
||||
}
|
||||
}
|
||||
@@ -1284,6 +1290,7 @@ menu_display_page(
|
||||
curses_menu_color_attr(win, color, attr, ON);
|
||||
} else {
|
||||
attr = menu_item_ptr->attr;
|
||||
color = menu_item_ptr->color;
|
||||
if (color != NONE || attr != A_NORMAL)
|
||||
curses_toggle_color_attr(win, color, attr, ON);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ int curses_ext_cmd(void);
|
||||
void curses_create_nhmenu(winid wid, unsigned long);
|
||||
void curses_add_nhmenu_item(winid wid, const glyph_info *glyphinfo,
|
||||
const ANY_P *identifier, char accelerator,
|
||||
char group_accel, int attr,
|
||||
char group_accel, int attr, int clr,
|
||||
const char *str, unsigned itemflags);
|
||||
void curs_menu_set_bottom_heavy(winid);
|
||||
void curses_finalize_nhmenu(winid wid, const char *prompt);
|
||||
|
||||
@@ -689,7 +689,7 @@ curses_character_dialog(const char **choices, const char *prompt)
|
||||
anything identifier;
|
||||
menu_item *selected = NULL;
|
||||
winid wid = curses_get_wid(NHW_MENU);
|
||||
int clr = 0;
|
||||
int clr = NO_COLOR;
|
||||
|
||||
identifier.a_void = 0;
|
||||
curses_start_menu(wid, MENU_BEHAVE_STANDARD);
|
||||
|
||||
@@ -22,6 +22,7 @@ static void curs_show_invt(WINDOW *);
|
||||
struct pi_line {
|
||||
char *invtxt; /* class header or inventory item without letter prefix */
|
||||
attr_t c_attr; /* attribute for class headers */
|
||||
int color;
|
||||
char letter; /* inventory letter; accelerator if this was really a menu;
|
||||
* used to distinguish item lines from header lines and for
|
||||
* display (no selection possible) */
|
||||
@@ -290,6 +291,7 @@ curs_add_invt(
|
||||
int linenum, /* line index; 1..n rather than 0..n-1 */
|
||||
char accelerator, /* selector letter for items, 0 for class headers */
|
||||
attr_t attr, /* curses attribute for headers, 0 for items */
|
||||
int clr, /* NetHack color for headers, NO_COLOR for items */
|
||||
const char *str) /* formatted inventory item, without invlet prefix,
|
||||
* or class header text */
|
||||
{
|
||||
@@ -309,6 +311,7 @@ curs_add_invt(
|
||||
newelement.invtxt = dupstr(str);
|
||||
newelement.c_attr = attr; /* note: caller has already converted 'attr'
|
||||
* from tty-style attribute to curses one */
|
||||
newelement.color = clr;
|
||||
newelement.letter = accelerator;
|
||||
aptr[pi.inuseindx++] = newelement;
|
||||
|
||||
@@ -373,7 +376,7 @@ curs_show_invt(WINDOW *win)
|
||||
str = pi.array[lineno].invtxt;
|
||||
accelerator = pi.array[lineno].letter;
|
||||
attr = pi.array[lineno].c_attr;
|
||||
color = NO_COLOR;
|
||||
color = pi.array[lineno].color;
|
||||
|
||||
if (accelerator)
|
||||
++item_count;
|
||||
@@ -413,7 +416,6 @@ curs_show_invt(WINDOW *win)
|
||||
|
||||
/* only perform menu coloring on item entries, not subtitles */
|
||||
if (iflags.use_menu_color) {
|
||||
attr = 0;
|
||||
get_menu_coloring(str, &color, (int *) &attr);
|
||||
attr = curses_convert_attr(attr);
|
||||
}
|
||||
|
||||
@@ -682,7 +682,7 @@ void
|
||||
curses_add_menu(winid wid, const glyph_info *glyphinfo,
|
||||
const ANY_P *identifier,
|
||||
char accelerator, char group_accel, int attr,
|
||||
int clr UNUSED, const char *str, unsigned itemflags)
|
||||
int clr, const char *str, unsigned itemflags)
|
||||
{
|
||||
int curses_attr;
|
||||
|
||||
@@ -694,14 +694,14 @@ curses_add_menu(winid wid, const glyph_info *glyphinfo,
|
||||
/* persistent inventory window; nothing is selectable;
|
||||
omit glyphinfo because perm_invent is to the side of
|
||||
the map so usually cramped for horizontal space */
|
||||
curs_add_invt(inv_update, accelerator, curses_attr, str);
|
||||
curs_add_invt(inv_update, accelerator, curses_attr, clr, str);
|
||||
inv_update++;
|
||||
return;
|
||||
}
|
||||
|
||||
curses_add_nhmenu_item(wid, glyphinfo, identifier,
|
||||
accelerator, group_accel,
|
||||
curses_attr, str, itemflags);
|
||||
curses_attr, clr, str, itemflags);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -488,7 +488,7 @@ curses_prev_mesg(void)
|
||||
boolean do_lifo = (iflags.prevmsg_window != 'f');
|
||||
#ifdef DEBUG
|
||||
static int showturn = 0; /* 1: show hero_seq value in separators */
|
||||
int clr = 0;
|
||||
int clr = NO_COLOR;
|
||||
|
||||
/*
|
||||
* Set DEBUGFILES=MesgTurn in environment or sysconf to decorate
|
||||
|
||||
@@ -78,6 +78,10 @@ curses_read_char(void)
|
||||
void
|
||||
curses_toggle_color_attr(WINDOW *win, int color, int attr, int onoff)
|
||||
{
|
||||
if (color == NO_COLOR)
|
||||
color = NONE;
|
||||
if (attr == ATR_NONE)
|
||||
attr = NONE;
|
||||
#ifdef TEXTCOLOR
|
||||
int curses_color;
|
||||
|
||||
@@ -661,7 +665,7 @@ curses_view_file(const char *filename, boolean must_exist)
|
||||
char buf[BUFSZ];
|
||||
menu_item *selected = NULL;
|
||||
dlb *fp = dlb_fopen(filename, "r");
|
||||
int clr = 0;
|
||||
int clr = NO_COLOR;
|
||||
|
||||
if (fp == NULL) {
|
||||
if (must_exist)
|
||||
|
||||
@@ -534,7 +534,7 @@ curses_puts(winid wid, int attr, const char *text)
|
||||
}
|
||||
Id = cg.zeroany;
|
||||
curses_add_nhmenu_item(wid, &nul_glyphinfo, &Id, 0, 0,
|
||||
attr, text, MENU_ITEMFLAGS_NONE);
|
||||
attr, NO_COLOR, text, MENU_ITEMFLAGS_NONE);
|
||||
} else {
|
||||
waddstr(win, text);
|
||||
wnoutrefresh(win);
|
||||
|
||||
Reference in New Issue
Block a user